From d1920d2ccae05354f02782c3442298b197a21365 Mon Sep 17 00:00:00 2001 From: Kiooeht Date: Thu, 23 Jun 2011 09:02:20 -0700 Subject: [PATCH] Test connection by pinging server if no recent pings from server --- CHANGELOG.mkdn | 1 + irc.py | 12 ++++++++++++ pesterchum.py | 15 +++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/CHANGELOG.mkdn b/CHANGELOG.mkdn index 616137f..e2f2fe6 100644 --- a/CHANGELOG.mkdn +++ b/CHANGELOG.mkdn @@ -48,6 +48,7 @@ CHANGELOG * Third beep sound for when your initials are mentioned in memos - Kiooeht [evacipatedBox] (Idea: Lexi [lexicalNuance]) * Ctrl + click to copy links - Kiooeht [evacipatedBox] * Say something when server is full - Kiooeht [evacipatedBox] +* Ping server if no ping from server to test connection - Kiooeht [evacipatedBox] (Idea: Lexi [lexicalNuance]) * Bug fixes * Logviewer updates - Kiooeht [evacipatedBox] * Memo scrollbar thing - Kiooeht [evacipatedBox] diff --git a/irc.py b/irc.py index fcbea3c..b74eac5 100644 --- a/irc.py +++ b/irc.py @@ -5,6 +5,7 @@ from oyoyo import helpers import logging import random import socket +from time import time from dataobjs import Mood, PesterProfile from generic import PesterList @@ -266,6 +267,13 @@ class PesterIRC(QtCore.QThread): except socket.error: self.setConnectionBroken() + @QtCore.pyqtSlot() + def pingServer(self): + try: + self.cli.send("PING %s" % int(time())) + except socket.error: + self.setConnectionBroken() + moodUpdated = QtCore.pyqtSignal(QtCore.QString, Mood) colorUpdated = QtCore.pyqtSignal(QtCore.QString, QtGui.QColor) messageReceived = QtCore.pyqtSignal(QtCore.QString, QtCore.QString) @@ -471,6 +479,10 @@ class PesterHandler(DefaultCommandHandler): def toomanypeeps(self, *stuff): self.parent.tooManyPeeps.emit() + def ping(self, prefix, server): + self.parent.mainwindow.lastping = int(time()) + self.client.send('PONG', server) + def getMood(self, *chums): chumglub = "GETMOOD " for c in chums: diff --git a/pesterchum.py b/pesterchum.py index 5da6356..6f7cd1a 100644 --- a/pesterchum.py +++ b/pesterchum.py @@ -1641,6 +1641,12 @@ class PesterWindow(MovingWindow): self.connect(self, QtCore.SIGNAL('pcUpdate(QString, QString)'), self, QtCore.SLOT('updateMsg(QString, QString)')) + self.pingtimer = QtCore.QTimer() + self.connect(self.pingtimer, QtCore.SIGNAL('timeout()'), + self, QtCore.SLOT('checkPing()')) + self.lastping = int(time()) + self.pingtimer.start(1000*10) + @QtCore.pyqtSlot(QtCore.QString, QtCore.QString) def updateMsg(self, ver, url): if not hasattr(self, 'updatemenu'): @@ -1663,6 +1669,12 @@ class PesterWindow(MovingWindow): def noUpdatePC(self): self.updatemenu = None + @QtCore.pyqtSlot() + def checkPing(self): + curtime = int(time()) + if curtime - self.lastping > 300: + self.pingServer.emit() + def profile(self): return self.userprofile.chat def closeConversations(self, switch=False): @@ -2880,6 +2892,7 @@ class PesterWindow(MovingWindow): closeSignal = QtCore.pyqtSignal() reconnectIRC = QtCore.pyqtSignal() gainAttention = QtCore.pyqtSignal(QtGui.QWidget) + pingServer = QtCore.pyqtSignal() class PesterTray(QtGui.QSystemTrayIcon): def __init__(self, icon, mainwindow, parent): @@ -3038,6 +3051,8 @@ class MainProgram(QtCore.QObject): 'channelNames(QString)'), ('inviteChum(QString, QString)', 'inviteChum(QString, QString)'), + ('pingServer()', + 'pingServer()'), ('reconnectIRC()', 'reconnectIRC()') ] # IRC --> Main window