From 59477c3ea7dc0edc7e435f314fdb7081cc7ae66b Mon Sep 17 00:00:00 2001 From: KeshavAnandCode Date: Thu, 14 May 2026 18:58:30 -0500 Subject: [PATCH] added python files and fixed logs, gitignore --- .gitignore | 2 ++ python/admin.py | 12 ++++++++++++ python/team.py | 30 ++++++++++++++++++++++++++++++ src/main.rs | 4 ---- 4 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 python/admin.py create mode 100644 python/team.py diff --git a/.gitignore b/.gitignore index ea8c4bf..d792c30 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /target +**/.venv/** + diff --git a/python/admin.py b/python/admin.py new file mode 100644 index 0000000..cc0573d --- /dev/null +++ b/python/admin.py @@ -0,0 +1,12 @@ +import socket + +SERVER_IP = "127.0.0.1" +PORT = 5901 + +# Manually set the starting "input" for the first team +s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +s.connect((SERVER_IP, PORT)) +# Using "0" as the ID for the very first team's source +s.send("ADMIN SET 0 80".encode()) # Sets the first clue as 80 +print(s.recv(1024).decode()) +s.close() diff --git a/python/team.py b/python/team.py new file mode 100644 index 0000000..65a6a8f --- /dev/null +++ b/python/team.py @@ -0,0 +1,30 @@ +import socket + +# Config +SERVER_IP = "127.0.0.1" # Change to master server's IP +PORT = 5901 +MY_ID = "1" # Team Number +PREV_ID = "0" # Team Number of Team Sending Clue (should be previous team, but in case of abscences) + +# 1. GET: Wait for input +print(f"Waiting for Team {PREV_ID}...") +while True: + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.connect((SERVER_IP, PORT)) + s.send(f"GET {PREV_ID}".encode()) + input = s.recv(1024).decode().strip() + s.close() + + if input != "-1": # -1 Means Clue Is Not Yet Sent + print(f"Received input: {input}") + break + +# 2. TRANSFORM: Do your logic to convert input to output clue, which should also be an integer Number +output = int(input) + 42 + +# 3. PUT: Send output +s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +s.connect((SERVER_IP, PORT)) +s.send(f"PUT {MY_ID} {output}".encode()) +s.close() +print(f"Sent output: {output}") diff --git a/src/main.rs b/src/main.rs index 004ee89..fd75308 100644 --- a/src/main.rs +++ b/src/main.rs @@ -71,10 +71,6 @@ async fn handle_connection(mut socket: TcpStream, db: Db) -> std::io::Result<()> .cloned() .unwrap_or_else(|| "-1".to_string()); - if response == "-1" { - println!("[WAIT] Team requested {}, but no data yet.", target_id); - } - socket.write_all(response.as_bytes()).await?; } }