Fix server issue on client TX/RX detection. Fix sending network messages to sender.
This commit is contained in:
parent
9540837e7a
commit
009ce3734a
21
crosslink.py
21
crosslink.py
|
@ -17,6 +17,7 @@ class FRNCrosslinkClient(FRNClient):
|
|||
def connectionMade(self):
|
||||
self.txOk = False
|
||||
self.txReq = False
|
||||
self.clientId = None
|
||||
FRNClient.connectionMade(self)
|
||||
|
||||
def getClientName(self, client_id):
|
||||
|
@ -28,16 +29,17 @@ class FRNCrosslinkClient(FRNClient):
|
|||
def textMessageReceived(self, client, message, target):
|
||||
global clients
|
||||
if target == 'A':
|
||||
for _, _, _, factory in clients:
|
||||
if factory != self.factory:
|
||||
factory.connection.sendTextMessage('', message)
|
||||
if client != self.clientId:
|
||||
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:
|
||||
for server, port, u, factory in clients:
|
||||
cl = []
|
||||
cl.append("[%s:%d]" % (server,port))
|
||||
cl.append("[%s@%s:%d]" % (u.NT,server,port))
|
||||
for c in factory.connection.clients:
|
||||
cl.append("(%s)" % (c['on'],))
|
||||
reply = ' '.join(cl)
|
||||
|
@ -68,14 +70,14 @@ class FRNCrosslinkClient(FRNClient):
|
|||
if conn.txOk:
|
||||
conn.txReq = False
|
||||
conn.sendAudioFrame(frames)
|
||||
conn.busyTimer.reset(5.0)
|
||||
conn.busyTimer.reset(2.0)
|
||||
else:
|
||||
if not conn.txReq:
|
||||
log.msg("Requesting TX for %s" % conn.user.ON)
|
||||
conn.startTransmission()
|
||||
conn.txReq = True
|
||||
conn.busyTimer = conn.factory.reactor.callLater(
|
||||
7.0, conn.goIdle)
|
||||
5.0, conn.goIdle)
|
||||
self.pong()
|
||||
|
||||
def loginResponse(self, info):
|
||||
|
@ -84,7 +86,10 @@ class FRNCrosslinkClient(FRNClient):
|
|||
def clientsListUpdated(self, clients):
|
||||
self.clients = clients
|
||||
self.clientsById = dict([(i['id'], i) for i in clients])
|
||||
|
||||
if self.clientId is None:
|
||||
for c in clients:
|
||||
if c['on'] == self.user.ON and c['bc'] == self.user.BC:
|
||||
self.clientId = c['id']
|
||||
|
||||
class FRNCrosslinkClientFactory(FRNClientFactory):
|
||||
protocol = FRNCrosslinkClient
|
||||
|
|
|
@ -31,9 +31,7 @@ class FRNServer(BufferingLineReceiver, TimeoutMixin):
|
|||
|
||||
def connectionLost(self, reason):
|
||||
log.msg("Client disconnected: %s" % self.clientAddress.host)
|
||||
try:
|
||||
self.pingTimer.stop()
|
||||
except AssertionError: pass
|
||||
self.stopPinging()
|
||||
if self.user is not None:
|
||||
if self.user.ID:
|
||||
log.msg("Logging out client %s" % self.user.ID)
|
||||
|
@ -58,7 +56,7 @@ class FRNServer(BufferingLineReceiver, TimeoutMixin):
|
|||
self.sendAccessFlags(None)
|
||||
self.sendAccessList([])
|
||||
self.pingCount += 1
|
||||
self.pingTimer.start(0.5)
|
||||
self.startPinging()
|
||||
self.setTimeout(10.0)
|
||||
return
|
||||
if sline == 'P': # Pong
|
||||
|
@ -126,13 +124,24 @@ class FRNServer(BufferingLineReceiver, TimeoutMixin):
|
|||
self.factory.serverAuth.asXML('MT','SV','AL','BN','BP','KP'))
|
||||
if self.role not in ['OK', 'OWNER', 'ADMIN']:
|
||||
self.transport.loseConnection()
|
||||
else:
|
||||
self.startPinging()
|
||||
return self.authenticate(FRNUser(**body)).addCallback(
|
||||
authReturned)
|
||||
|
||||
def startPinging(self):
|
||||
if not self.pingTimer.running:
|
||||
self.pingTimer.start(0.5, True)
|
||||
|
||||
def stopPinging(self):
|
||||
if self.pingTimer.running:
|
||||
self.pingTimer.stop()
|
||||
|
||||
def decodeRX(self, body):
|
||||
log.msg("RX%d" % int(body))
|
||||
if not self.pingTimer.running:
|
||||
self.pingTimer.start(0.5)
|
||||
self.startPinging()
|
||||
for c in self.factory.tracker.getClientList(self.user.NT):
|
||||
cp = self.factory.tracker.getClientProtocol(c.ID).startPinging()
|
||||
|
||||
def decodeST(self, body):
|
||||
log.msg("Set status = %d" % int(body))
|
||||
|
@ -146,7 +155,7 @@ class FRNServer(BufferingLineReceiver, TimeoutMixin):
|
|||
msgtype = 'P'
|
||||
for c in self.factory.tracker.getClientList(self.user.NT):
|
||||
if msgtype == 'A' or c.ID == body['id']:
|
||||
if c.ID != self.user.ID:
|
||||
if c.ID != self.user.ID or msgtype == 'A':
|
||||
client = self.factory.tracker.getClientProtocol(c.ID)
|
||||
client.sendTextMessage(self.user.ID, body['ms'], msgtype)
|
||||
|
||||
|
@ -156,8 +165,7 @@ class FRNServer(BufferingLineReceiver, TimeoutMixin):
|
|||
ih,il = divmod(self.getIndex(), 256)
|
||||
self.transport.write(chr(1)+chr(ih)+chr(il))
|
||||
elif body == '1':
|
||||
if self.pingTimer.running:
|
||||
self.pingTimer.stop()
|
||||
self.stopPinging()
|
||||
self.expectRawData(325)
|
||||
|
||||
def decodeMC(self, body):
|
||||
|
@ -262,8 +270,9 @@ class FRNServer(BufferingLineReceiver, TimeoutMixin):
|
|||
self.pingCount += 1
|
||||
|
||||
def sendAudioFrame(self, clientIdx, frame):
|
||||
self.transport.write(chr(2))
|
||||
self.stopPinging()
|
||||
ih,il = divmod(clientIdx, 256)
|
||||
self.transport.write(chr(2))
|
||||
self.transport.write(chr(ih)+chr(il))
|
||||
self.transport.write(frame)
|
||||
|
||||
|
|
Loading…
Reference in New Issue