fix: sending double pong messages

This commit is contained in:
2025-12-12 11:45:15 -05:00
Unverified
parent 8444bb70f4
commit b27f978ea9
2 changed files with 9 additions and 8 deletions

View File

@@ -12,7 +12,7 @@ In order to run your AI, you'll need:
- `pip install websockets` (Windows) or `pip3 install websockets` (Linux/macOS) - `pip install websockets` (Windows) or `pip3 install websockets` (Linux/macOS)
- `pip install pip-system-certs` (Windows) or `pip3 install pip-system-certs` (Linux/macOS) - `pip install pip-system-certs` (Windows) or `pip3 install pip-system-certs` (Linux/macOS)
To run the example, run `python gameloop.py`. To run the example, run `python gameloop.py` (Windows) or `python3 gameloop.py` (Linux/macOS).
# To Watch Games # To Watch Games
The visual client for observing games/tournaments as well as managing games can be found at [`connect4-moderator-observer`](https://github.com/joshuafhiggins/connect4-moderator-observer). The visual client for observing games/tournaments as well as managing games can be found at [`connect4-moderator-observer`](https://github.com/joshuafhiggins/connect4-moderator-observer).
@@ -23,15 +23,15 @@ The visual client for observing games/tournaments as well as managing games can
- `cd connect4-moderator-server` - `cd connect4-moderator-server`
- `cargo run --release demo` - `cargo run --release demo`
In this mode, you'll play against a player named `demo` who makes moves at random. If your AI makes invalid moves then your match is terminated and kicked from the server. If during the tournament you make an invalid move, you will instead immediately lose your game. In this mode, you'll play against a player named `demo` who makes moves at random. If your AI makes invalid moves then your match is terminated and you are kicked from the server. If during the tournament you make an invalid move, you will instead immediately lose your game.
To connect to this server, use the address `ws://localhost:8080` To connect to this server, use the address `ws://localhost:8080`
# For Future Maintainers: # For Future Maintainers:
The Google Sheet outlining the communication protocol can be found [here](https://docs.google.com/spreadsheets/d/1qPrNvB4-1jzvkaQXJcA1Z2OllpSQYmtMRfbOgSi4Yhw), for those of you who'd prefer to not write their AI in python The Google Sheet outlining the communication protocol can be found [here](https://docs.google.com/spreadsheets/d/1qPrNvB4-1jzvkaQXJcA1Z2OllpSQYmtMRfbOgSi4Yhw).
A JavaScript debug client that text raw text as input and prints responses is provided, A JavaScript debug client that takes raw text as input and prints responses is provided,
- `npm i` - `npm i`
- `node debug_client.js` - `node debug_client.js`
I also apologize in advance. I also apologize in advance for the code you'll go on to read.

View File

@@ -17,7 +17,9 @@ use tracing::{error, info, warn};
// TODO: Allow random "player1" in demo mode // TODO: Allow random "player1" in demo mode
// TODO: Support reconnecting behaviors // TODO: Support reconnecting behaviors
// TODO: Other tournament types // TODO: Other tournament types
// TODO: Move timeouts // TODO: Max move wait time
// TODO: Show tournament scoreboard after every round of games
// TODO: Tiebreakers, guarantee some amount of going first
// TODO: Send moves instantly, sleep only till waiting time // TODO: Send moves instantly, sleep only till waiting time
#[tokio::main] #[tokio::main]
@@ -626,9 +628,8 @@ async fn handle_connection(
info!("Client {} disconnected", addr); info!("Client {} disconnected", addr);
break; break;
} }
Ok(Message::Ping(b)) => { let _ = tx.send(Message::Pong(b)); }
Ok(Message::Binary(_)) => { let _ = send(&tx, "ERROR:UNKNOWN"); } Ok(Message::Binary(_)) => { let _ = send(&tx, "ERROR:UNKNOWN"); }
Ok(_) => { info!("Received pong/frame? Something fishy is happening") }, Ok(_) => {}, // Ping packets, we can ignore, they get handled for us
Err(e) => { Err(e) => {
error!("WebSocket error for {}: {}", addr, e); error!("WebSocket error for {}: {}", addr, e);
break; break;