From 5f63670043c2db3cdd358987cd359db8f5210837 Mon Sep 17 00:00:00 2001 From: Maurizio Porrato Date: Wed, 25 Aug 2010 10:10:43 +0200 Subject: [PATCH] Fix client disconnection from server on unmute. Fix html handling inside text messages in server. --- frn/clienttracker.py | 3 +++ frn/protocol/server.py | 6 +++++- frn/utility.py | 22 +++++++++++++++++----- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/frn/clienttracker.py b/frn/clienttracker.py index 5bbfa5e..9dfb87a 100644 --- a/frn/clienttracker.py +++ b/frn/clienttracker.py @@ -39,6 +39,9 @@ class ClientTracker(object): s['admin'] = self._admin s.close() + def isLoggedIn(self, clientId): + return clientId in self._clientData + def getClient(self, clientId): return self._clientData[clientId].user diff --git a/frn/protocol/server.py b/frn/protocol/server.py index 14df61a..52efc91 100644 --- a/frn/protocol/server.py +++ b/frn/protocol/server.py @@ -17,6 +17,8 @@ from frn.utility import * class FRNServer(BufferingLineReceiver, TimeoutMixin): + PING_PERIOD = 0.5 + def connectionMade(self): BufferingLineReceiver.connectionMade(self) log.msg("Connection from %s" % self.transport.getPeer().host) @@ -131,7 +133,7 @@ class FRNServer(BufferingLineReceiver, TimeoutMixin): def startPinging(self): if not self.pingTimer.running: - self.pingTimer.start(0.5, True) + self.pingTimer.start(self.PING_PERIOD, True) def stopPinging(self): if self.pingTimer.running: @@ -171,6 +173,8 @@ class FRNServer(BufferingLineReceiver, TimeoutMixin): def decodeMC(self, body): if self.role in ["OWNER","ADMIN"]: self.factory.tracker.mute(self.user, body['ip']) + if self.factory.tracker.isLoggedIn(body['ip']): + self.factory.tracker.getClientProtocol(body['ip']).decodeRX('0') def decodeUM(self, body): if self.role in ["OWNER","ADMIN"]: diff --git a/frn/utility.py b/frn/utility.py index 9738161..b4b5968 100644 --- a/frn/utility.py +++ b/frn/utility.py @@ -20,19 +20,31 @@ def makeRandomChallange(): class SimpleXMLParser(HTMLParser): + """Dirty FRN-specific hack to handle bogus one-level nesting only + XML-like syntax""" def handle_starttag(self, tag, attrs): if not hasattr(self, 'fields'): self.fields = {} - self.next_field = tag - self.next_data = '' + self.next_field = None + self.next_data = '' + if self.next_field is None: + self.next_field = tag + self.next_data = '' + else: + self.next_data += "<%s>" % tag def handle_data(self, data): - self.next_data += data + if self.next_field is not None: + self.next_data += data def handle_endtag(self, tag): - self.fields[self.next_field] = self.next_data - self.next_field = self.next_data = None + if tag == self.next_field: + self.fields[self.next_field] = self.next_data + self.next_field = None + self.next_data = '' + else: + self.next_data += "" % tag def get_fields(self): return self.fields