Forward client-to-client pings
This commit is contained in:
parent
c764c20ae7
commit
b74f76fb45
1 changed files with 11 additions and 2 deletions
|
|
@ -104,6 +104,16 @@ class Client(threading.Thread):
|
||||||
data = data.encode()
|
data = data.encode()
|
||||||
client.send(data.decode('utf-8'))
|
client.send(data.decode('utf-8'))
|
||||||
|
|
||||||
|
|
||||||
|
def _handle_ping(self, xml, data):
|
||||||
|
if(xml.get('to').find('@') == -1):
|
||||||
|
# Ping to server - respond
|
||||||
|
self.send('<iq type="result" id="{}" from="{}" />'.format(xml.get('id'), xml.get('to')))
|
||||||
|
else:
|
||||||
|
for client in XMPPServer.clients:
|
||||||
|
if client.address != self.address and client.state == client.READY:
|
||||||
|
client.send(data.decode('utf-8'))
|
||||||
|
|
||||||
def _handle_result(self, data):
|
def _handle_result(self, data):
|
||||||
# forward
|
# forward
|
||||||
for client in XMPPServer.clients:
|
for client in XMPPServer.clients:
|
||||||
|
|
@ -144,8 +154,7 @@ class Client(threading.Thread):
|
||||||
elif child == 'query':
|
elif child == 'query':
|
||||||
self._handle_ctl(xml, data)
|
self._handle_ctl(xml, data)
|
||||||
elif child == 'ping':
|
elif child == 'ping':
|
||||||
# respond to ping request
|
self._handle_ping(xml, data)
|
||||||
res = '<iq type="result" id="{}" from="{}" />'.format(last_id, xml.get('to'))
|
|
||||||
elif xml.get('type') == 'result':
|
elif xml.get('type') == 'result':
|
||||||
self._handle_result(data)
|
self._handle_result(data)
|
||||||
if res:
|
if res:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue