From aaeca932b80f8542ca4a9317f48f2346c5fb2c35 Mon Sep 17 00:00:00 2001 From: Maurizio Porrato Date: Sun, 22 Aug 2010 10:57:39 +0200 Subject: [PATCH] Fix client index in audio frames from server. Add incomplete crosslink implementation. --- crosslink.py | 102 +++++++++++++++++++++++++++++++++++++++++ frn/protocol/server.py | 2 +- 2 files changed, 103 insertions(+), 1 deletion(-) create mode 100755 crosslink.py diff --git a/crosslink.py b/crosslink.py new file mode 100755 index 0000000..feba3b1 --- /dev/null +++ b/crosslink.py @@ -0,0 +1,102 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright 2010 Maurizio Porrato +# See LICENSE.txt for copyright info + +from twisted.internet import reactor +from frn.protocol.client import FRNClient, FRNClientFactory +from frn.user import FRNUser +from twisted.python import log + +clients = [] + +class FRNCrosslinkClient(FRNClient): + + def getClientName(self, client_id): + if self.clientsById.has_key(client_id): + return self.clientsById[client_id]['on'] + else: + return client_id + + def textMessageReceived(self, client, message, target): + if target == 'A': + for _, _, _, factory in clients: + if factory != self.factory: + factory.connection.sendTextMessage('', message) + else: + if message.startswith('!'): + cmd = message[1:] + if cmd == "who": + for server, port, _, factory in clients: + cl = [] + cl.append("[%s:%d]" % (server,port)) + for c in factory.connection.clients: + cl.append("(%s)" % (c['on'],)) + reply = ' '.join(cl) + factory.connection.sendTextMessage(client, reply) + + def stopTransmission(self): + FRNClient.stopTransmission(self) + log.msg("Stopped playback.") + + def audioFrameReceived(self, from_id, frames): + self.pong() + + def loginResponse(self, info): + log.msg("Login: %s" % info['al']) + + def clientsListUpdated(self, clients): + self.clients = clients + self.clientsById = dict([(i['id'], i) for i in clients]) + + +class FRNCrosslinkClientFactory(FRNClientFactory): + protocol = FRNCrosslinkClient + reactor = reactor + + def buildProtocol(self, addr): + p = FRNClientFactory.buildProtocol(self, addr) + self.connection = p + return p + + +if __name__ == '__main__': + import sys + from os.path import dirname, join as pjoin + from ConfigParser import ConfigParser + + log.startLogging(sys.stderr) + + basedir = dirname(__file__) + + acfg = ConfigParser() + acfg.read(['/etc/grn/accounts.conf', + pjoin(basedir,'accounts.conf'), 'accounts.conf']) + + scfg = ConfigParser() + scfg.read(['/etc/grn/servers.conf', + pjoin(basedir,'servers.conf'), 'servers.conf']) + + argc = len(sys.argv) + if argc > 1: + for client_data in sys.argv[1:]: + account_name, server_name, network_name = client_data.split(':',2) + account_cfg = acfg.items(account_name)+[('network', network_name)] + server_cfg = scfg.items(server_name) + server = scfg.get(server_name, 'server') + port = scfg.getint(server_name, 'port') + d = dict(account_cfg) + user = FRNUser( + EA=d['email'], + PW=d['password'], ON=d['operator'], +# BC=d['transmission'], DS=d['description'], + BC="Crosslink", DS=d['description'], + NN=d['country'], CT=d['city'], NT=d['network']) + factory = FRNCrosslinkClientFactory(user) + clients.append((server, port, user, factory)) + reactor.connectTCP(server, port, factory) + reactor.run() + + +# vim: set et ai sw=4 ts=4 sts=4: diff --git a/frn/protocol/server.py b/frn/protocol/server.py index 7993619..866011f 100644 --- a/frn/protocol/server.py +++ b/frn/protocol/server.py @@ -90,7 +90,7 @@ class FRNServer(BufferingLineReceiver, TimeoutMixin): log.err("Unimplemented message: %s: %s" % (command, body)) def getIndex(self): - return self.factory.tracker.getClientIndex(self.user.ID)+1 + return self.factory.tracker.getClientIndex(self.user.ID) def authenticate(self, user): def loginReturned(userId):