防止chat
This commit is contained in:
parent
4724ca3bcc
commit
12da2b4414
5
CS3.1.py
5
CS3.1.py
@ -142,7 +142,7 @@ def handle_socket_message(data, addr, conn):
|
|||||||
"message": data['message']
|
"message": data['message']
|
||||||
}
|
}
|
||||||
broadcast_message(message)
|
broadcast_message(message)
|
||||||
return {"type": "chat", "status": "success"}
|
#return {"type": "chat", "status": "success"}
|
||||||
return {"type": "chat", "status": "error", "message": "Not logged in"}
|
return {"type": "chat", "status": "error", "message": "Not logged in"}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {"status": "error", "message": str(e)}
|
return {"status": "error", "message": str(e)}
|
||||||
@ -165,7 +165,8 @@ def run_socket_server():
|
|||||||
try:
|
try:
|
||||||
json_data = json.loads(data.decode())
|
json_data = json.loads(data.decode())
|
||||||
response = handle_socket_message(json_data, addr, conn)
|
response = handle_socket_message(json_data, addr, conn)
|
||||||
conn.sendall(json.dumps(response).encode())
|
if response != None:
|
||||||
|
conn.sendall(json.dumps(response).encode())
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
conn.sendall(json.dumps(
|
conn.sendall(json.dumps(
|
||||||
{"type": "register_0", "status": "error", "message": "Invalid JSON"}
|
{"type": "register_0", "status": "error", "message": "Invalid JSON"}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user