From 06839ae02b473ec9abaf5e342790b760b4e06429 Mon Sep 17 00:00:00 2001 From: Maurizio Porrato Date: Sun, 5 Sep 2010 16:43:05 +0200 Subject: [PATCH] Add new "last" command to crosslink --- twisted/plugins/frncrosslink.py | 55 +++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/twisted/plugins/frncrosslink.py b/twisted/plugins/frncrosslink.py index 997e2c3..237f52f 100755 --- a/twisted/plugins/frncrosslink.py +++ b/twisted/plugins/frncrosslink.py @@ -20,6 +20,7 @@ cStatus = {'0': 'T', '1': 'R', '2': 'N'} clients = [] talking = None +lastMessages = [] class FRNCrosslinkClient(FRNClient): @@ -37,8 +38,15 @@ class FRNCrosslinkClient(FRNClient): else: return client_id + def sendMultiLineTextMessage(self, client, lines, maxLen=15): + chunks = [lines[i*maxLen:(i+1)*maxLen] + for i in range((len(lines)+maxLen-1)/maxLen)] + for m in chunks: + reply = '
'.join(m) + self.sendTextMessage(client, reply) + def textMessageReceived(self, client, message, target): - global clients + global clients, talking, lastMessages if target == 'A': msg = "[%s] %s" % (self.getClientName(client), message) if client != self.clientId: @@ -52,20 +60,30 @@ class FRNCrosslinkClient(FRNClient): for server, port, u, factory in clients: cl = [] cl.append("%s@%s:%d" % (u.NT,server,port)) - for c in factory.connection.clients: - ss = cStatus.get(c['s'], '?') - if c['m'] != '0': - ss = ss.lower() - cl.append(" %s%s %s " % ( - cType.get(c['bc'], 'G'), - ss, - c['on'].replace('<', '<'), - )) - sm = [cl[i*15:(i+1)*15] - for i in range((len(cl)+14)/15)] - for m in sm: - reply = '
'.join(m) - self.sendTextMessage(client, reply) + role = factoy.connection.serverdata.get('al', None) + if role in ['OK', 'ADMIN', 'OWNER']: + for c in factory.connection.clients: + ss = cStatus.get(c['s'], '?') + if c['m'] != '0': + ss = ss.lower() + cl.append(" %s%s %s " % ( + cType.get(c['bc'], 'G'), + ss, + c['on'].replace('<', '<'), + )) + else: + cl.append(" :!: DISCONNECTED :!: ") + self.sendMultiLineTextMessage(client, cl) + elif cmd == "last": + ml = [] + if talking is not None: + ml.append("No client talking now") + else: + ml.append("%s is talking now" % talking.user.ON) + ml.append("Last active talkers (most recent first):") + for n in lastMessages: + ml.append(n) + self.sendMultiLineTextMessage(client, ml) def decodeTX(self, my_id): log.msg("Got TX ack for %s" % self.user.ON) @@ -76,9 +94,12 @@ class FRNCrosslinkClient(FRNClient): log.msg("Stopped TX on %s" % self.user.ON) def goIdle(self): - global talking + global talking, lastMessages self.txReq = False self.txOk = False + if talking == self: + lastMessages.insert(0, self.user.ON) + lastMessages = lastMessages[:5] talking = None self.stopTransmission() @@ -90,7 +111,7 @@ class FRNCrosslinkClient(FRNClient): conn = factory.connection if conn != self: role = conn.serverdata.get('al', None) - if role in ['OK', 'ADMIN', 'OWNER']: + if role in ['OK', 'ADMIN', 'OWNER']: if conn.txOk: conn.txReq = False conn.sendAudioFrame(frames)