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, diff --git a/torchat/src/tc_gui.py b/torchat/src/tc_gui.py index 5b4baa6d..7ebef7e9 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: