Commit ba3cd5e4 by Owo Sugiana

Client ID yang sama ditolak

1 parent 6c90ccc2
......@@ -91,8 +91,15 @@ def main(argv=sys.argv[1:]):
@app.route('/ws', protocol='websocket')
async def main_websocket(scope, receive, send):
def log_info(msg):
if client_id:
msg = f'{ip} {mem_id} Client {client_id} {msg}'
else:
msg = f'{ip} {mem_id} {msg}'
log.info(msg)
async def kirim(d: dict):
log.info(f'{ip} {mem_id} Send {d}')
log_info(f'Send {d}')
await send(d)
async def kirim_pesan(d: dict):
......@@ -111,14 +118,20 @@ def main(argv=sys.argv[1:]):
try:
d = module.login(d)
client_id = d['client_id']
ws_data[client_id] = []
if client_id in ws_data:
d = dict(
code=91,
message=f'Client {client_id} masih terhubung')
client_id = None
else:
ws_data[client_id] = []
except BaseError as e:
d = dict(code=e.code, message=e.message)
except Exception:
msg = exception_message()
log.error(msg)
d = dict(code=91, message='Login gagal')
log.info(f'{ip} {mem_id} Encode JSON {d}')
log_info(f'Encode JSON {d}')
await kirim_pesan(d)
return client_id
......@@ -133,13 +146,13 @@ def main(argv=sys.argv[1:]):
except asyncio.TimeoutError:
await run_queue()
continue
log.info(f'{ip} {mem_id} Receive {message}')
log_info(f'Receive {message}')
if message['type'] == 'websocket.connect':
await kirim({'type': 'websocket.accept'})
elif message['type'] == 'websocket.receive':
text = message.get('text')
d = json.loads(text)
log.info(f'{ip} {mem_id} Decode JSON {d}')
log_info(f'Decode JSON {d}')
if first:
first = False
client_id = await login(d)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!