added python files and fixed logs, gitignore
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1 +1,3 @@
|
||||
/target
|
||||
**/.venv/**
|
||||
|
||||
|
||||
12
python/admin.py
Normal file
12
python/admin.py
Normal file
@@ -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()
|
||||
30
python/team.py
Normal file
30
python/team.py
Normal file
@@ -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}")
|
||||
@@ -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?;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user