Fix client index in audio frames from server. Add incomplete crosslink implementation.
This commit is contained in:
parent
05894bb136
commit
aaeca932b8
|
@ -0,0 +1,102 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright 2010 Maurizio Porrato <maurizio.porrato@gmail.com>
|
||||
# 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:
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue