From dffadb65da6e8e2cbbcdb85d85199e4d6bb8c9f8 Mon Sep 17 00:00:00 2001 From: tcsenpai Date: Wed, 19 Feb 2025 11:36:32 +0100 Subject: [PATCH] better console support --- libs/broadcast.py | 6 +++++- main.py | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/libs/broadcast.py b/libs/broadcast.py index 4a62ed2..6797110 100644 --- a/libs/broadcast.py +++ b/libs/broadcast.py @@ -12,8 +12,12 @@ def broadcast_message( else (room.users if room else connections.keys()) ) + # Always show to console + print(formatted_message) + + # Send to other recipients for addr in recipients: - if addr not in connections: + if addr not in connections or addr == ("console", 0): continue try: if sender_addr and addr == sender_addr: diff --git a/main.py b/main.py index 088b653..dcaad01 100644 --- a/main.py +++ b/main.py @@ -117,8 +117,10 @@ def process_complete_line(line, addr, active_connections, conn): room, ) - # For console, print locally instead of sending - if not conn: + # Send back to sender (if not console) + if conn: + conn.sendall(f"\r\n{message_with_user}\r\n".encode("ascii")) + else: print(f"\r\n{message_with_user}\r\n") except UnicodeDecodeError: