From e382cdbc6eac3bf5c5ccccf1eb4d8f0cda71b096 Mon Sep 17 00:00:00 2001 From: Maurizio Porrato Date: Sat, 4 Sep 2010 14:22:23 +0200 Subject: [PATCH] Add client list sorting in server. Minor changes to client list formatting in crosslink. --- frn/clienttracker.py | 30 +++++++++++++++++++++++++++++- twisted/plugins/frncrosslink.py | 15 ++++++++------- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/frn/clienttracker.py b/frn/clienttracker.py index d970540..d8ee5df 100644 --- a/frn/clienttracker.py +++ b/frn/clienttracker.py @@ -6,6 +6,29 @@ import shelve from twisted.python import log +CLIENTS_ORDER = ['Crosslink', 'Parrot', 'Gateway', 'PC Only'] + +def client_cmp(a, b): + try: + ta = CLIENTS_ORDER.index(a.BC) + except: + ta = CLIENTS_ORDER.index('Gateway') + try: + tb = CLIENTS_ORDER.index(b.BC) + except: + tb = CLIENTS_ORDER.index('Gateway') + if ta < tb: + return -1 + elif ta > tb: + return 1 + else: + if a.ON < b.ON: + return -1 + elif a.ON > b.ON: + return 1 + else: + return 0 + class ClientTracker(object): @@ -93,7 +116,12 @@ class ClientTracker(object): self._clientData[clientId] = client net = client.user.NT nc = self._net.get(net, []) - nc.append(clientId) + ni = 0 + for i, c in enumerate(nc): + if client_cmp(client.user, self._clientData[c]) > 0: + ni = i + break + nc.insert(ni, clientId) self._net[net] = nc if clientId in self._mute: client.user.M = 1 diff --git a/twisted/plugins/frncrosslink.py b/twisted/plugins/frncrosslink.py index 052287f..f40b9c8 100755 --- a/twisted/plugins/frncrosslink.py +++ b/twisted/plugins/frncrosslink.py @@ -16,8 +16,7 @@ from twisted.python import log from os.path import curdir, join as pjoin cType = {'PC Only': 'O', 'Crosslink': 'C', 'Parrot': 'P'} -cStatus = {'0': 'A', '1': 'N', '2': 'X'} -cMute = {'0': ' ', '1': 'M'} +cStatus = {'0': 'T', '1': 'R', '2': 'N'} clients = [] talking = None @@ -52,15 +51,17 @@ class FRNCrosslinkClient(FRNClient): if cmd == "who": for server, port, u, factory in clients: cl = [] - cl.append("[%s@%s:%d]" % (u.NT,server,port)) + cl.append("%s@%s:%d" % (u.NT,server,port)) for c in factory.connection.clients: - cl.append("(%s%s%s %s)" % ( + ss = cStatus.get(c['s'], '?') + if c['m'] != '0': + ss = ss.lower() + cl.append(" %s%s %s " % ( cType.get(c['bc'], 'G'), - cStatus.get(c['s'], '?'), - cMute.get(c['m'], '?'), + ss, c['on'], )) - reply = '
'.join(cl) + reply = '
'.join(cl) self.sendTextMessage(client, reply) def decodeTX(self, my_id):