From e3b60103bf373b83982e47982c725e8eeb307a5b Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 5 Jun 2012 22:06:53 +0100 Subject: [PATCH 1/3] Added a command "/ping" which can test the latency between two people. --- torchat/src/tc_gui.py | 47 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/torchat/src/tc_gui.py b/torchat/src/tc_gui.py index 5b4baa6d..d1f7139c 100644 --- a/torchat/src/tc_gui.py +++ b/torchat/src/tc_gui.py @@ -25,10 +25,13 @@ import time import subprocess import textwrap +import random import version import dlg_settings import translations import tc_notification +import string +import array lang = translations.lang_en tb = config.tb tb1 = config.tb1 @@ -1095,6 +1098,12 @@ def setStatus(self, status): class ChatWindow(wx.Frame): + pings = {} + + def pid(self, sizestr=6, charstouse=string.ascii_uppercase + string.digits): + return ''.join(random.choice(charstouse) for x in range(sizestr)) + + def __init__(self, main_window, buddy, message="", hidden=False, notify_offline_sent=False): @@ -1326,8 +1335,30 @@ def process(self, message): name = self.buddy.name else: name = self.buddy.address - self.writeColored(config.get("gui", "color_nick_buddy"), name, message) - self.notify(name, message) + + if message.startswith("/ping ") and len(message) == 12: + #This was a triumph + #I'm making a note here, huge success + #It's hard to overstate my satisfaction + randchars = message.split(" ") + self.buddy.sendChatMessage("/PONG " + randchars[1]) + self.writeColored(config.get("gui", "color_actions"), "", "[PING]") + elif message.startswith("/PONG") and len(message) == 12: + timeg = time.time() + randchars = message.split(" ") + onetimepid = randchars[1] + gtimefdict = self.pings[onetimepid][0] + self.pings[onetimepid] = [gtimefdict, timeg] + timetotal = self.pings[onetimepid][1] - self.pings[onetimepid][0] + #print "Time sent[PING]: " + str(self.pings[onetimepid][0]) + #print "Time received[PONG]: " + str(self.pings[onetimepid][1]) + #print "Total Time: " + str(timetotal) + #print "Total Time / 2(One msg?)" + str(timetotal / 2) + self.buddy.sendChatMessage("[PONG] (" + str(round(timetotal / 2, 2)) + "s)") + self.writeColored(config.get("gui", "color_actions"), "", "[PONG] (" + str(round(timetotal / 2, 2)) + "s)") + else: + self.writeColored(config.get("gui", "color_nick_buddy"), name, message) + self.notify(name, message) def onActivate(self, evt): self.unread = 0 @@ -1370,8 +1401,16 @@ def onSend(self, evt): self.txt_out.SetValue("") if self.buddy.status not in [tc_client.STATUS_OFFLINE, tc_client.STATUS_HANDSHAKE]: - self.buddy.sendChatMessage(text) - self.writeColored(config.get("gui", "color_nick_myself"), + if text == "/ping": + onetimepid = self.pid() + self.buddy.sendChatMessage("/ping " + str(onetimepid)) + self.pings[onetimepid] = [time.time()] + self.writeColored(config.get("gui", "color_actions"), + "", + "[PING]") + else: + self.buddy.sendChatMessage(text) + self.writeColored(config.get("gui", "color_nick_myself"), "myself", text) else: From 0edf536ad8366d5b93f4a234d0bacf56e47bd6b3 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 5 Jun 2012 22:07:17 +0100 Subject: [PATCH 2/3] Added color_actions for actions like /ping and such. --- torchat/src/config.py | 1 + 1 file changed, 1 insertion(+) diff --git a/torchat/src/config.py b/torchat/src/config.py index bb289ad1..7c3942a2 100644 --- a/torchat/src/config.py +++ b/torchat/src/config.py @@ -54,6 +54,7 @@ def isWindows(): ("gui", "color_nick_buddy") : "#c00000", ("gui", "color_text_back") : "#ffffff", ("gui", "color_text_fore") : "#000000", + ("gui", "color_actions") : "#220000", ("gui", "color_text_use_system_colors") : 1, ("gui", "chat_font_name") : "Arial", ("gui", "chat_font_size") : 10, From 34469f38b8f1c3ced6680dc19c8c86daa4946342 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 5 Jun 2012 22:11:53 +0100 Subject: [PATCH 3/3] Added command "/ping" to test latency between two(2) people. --- torchat/src/tc_gui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torchat/src/tc_gui.py b/torchat/src/tc_gui.py index d1f7139c..7ebef7e9 100644 --- a/torchat/src/tc_gui.py +++ b/torchat/src/tc_gui.py @@ -1406,7 +1406,7 @@ def onSend(self, evt): self.buddy.sendChatMessage("/ping " + str(onetimepid)) self.pings[onetimepid] = [time.time()] self.writeColored(config.get("gui", "color_actions"), - "", + ", "[PING]") else: self.buddy.sendChatMessage(text)