diff --git a/server/src/lib.rs b/server/src/lib.rs index 1baa1d3..a9e38bb 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -17,10 +17,7 @@ pub fn escape_characters(x: &str) -> String { x } -#[derive(Clone, Debug, Serialize, PartialEq)] -pub struct Player { - pub name: String, -} +pub type Player = String; #[derive(Clone, Serialize, Debug)] pub struct PartyInfo { diff --git a/server/src/main.rs b/server/src/main.rs index 64636e8..187308e 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -53,7 +53,7 @@ async fn incoming_message_handler( .party_info .players .iter() - .filter(|p| !p.name.eq(&player.name)) + .filter(|p| !p.eq(&player)) .map(|p| p.clone()) .collect_vec(); room.party_info.players = new_vec; @@ -77,7 +77,7 @@ async fn incoming_message_handler( let message: ClientToServerMessage = serde_json::from_str(message).unwrap(); // TODO - println!("Received {message:#?} from client {}", player.name); + println!("Received {message:#?} from client {player}"); match message { ClientToServerMessage::Load => { return !game_load(player, None, room, stream).await @@ -87,7 +87,7 @@ async fn incoming_message_handler( if room.game.is_some() { eprintln!( "Player {} is trying to start an already started game", - player.name + player ); } else { let rng = SmallRng::from_entropy(); @@ -96,7 +96,7 @@ async fn incoming_message_handler( .party_info .players .iter() - .map(|p| p.name.clone()) + .map(|p| p.clone()) .collect_vec(); let game = Game::new_specific( rng, @@ -116,23 +116,23 @@ async fn incoming_message_handler( let mut room = room.write().await; if room.game.is_none() { let event = ServerToClientMessage::Invalid { - reason: format!("Game hasn't been started yet"), + reason: "Game hasn't been started yet".to_string(), }; let event = serde_json::to_string(&event).unwrap(); let _ = stream.send(event.into()).await; } else { let game = room.game.as_mut().unwrap(); let result = match r#move { - GameMove::Pass => game.pass(&player.name), + GameMove::Pass => game.pass(&player), GameMove::Exchange { tiles } => { - game.exchange(&player.name, tiles) + game.exchange(&player, tiles) } GameMove::Play { played_tiles, commit_move, } => { let result = - game.play(&player.name, played_tiles, commit_move); + game.play(&player, played_tiles, commit_move); if result.is_ok() & !commit_move { let event = ServerToClientMessage::GameEvent { event: GameEvent::TurnAction { @@ -147,7 +147,7 @@ async fn incoming_message_handler( result } GameMove::AddToDictionary { word } => { - game.add_to_dictionary(&player.name, &word) + game.add_to_dictionary(&player, &word) } }; match result { @@ -216,7 +216,7 @@ async fn game_load( // The game object was modified; we need to trigger a load from this player's perspective let mut room = room.write().await; - let mut state = room.game.as_mut().unwrap().load(&player.name).unwrap(); + let mut state = room.game.as_mut().unwrap().load(&player).unwrap(); state.update = update; let event = ServerToClientMessage::GameEvent { event: GameEvent::TurnAction { @@ -261,15 +261,13 @@ async fn room( ws: ws::WebSocket, rooms: &State>, ) -> ws::Channel<'static> { - let id = escape_characters(id); + let id = escape_characters(id).to_lowercase(); let player_name = escape_characters(player_name); let mut rooms = rooms.lock().await; let room = rooms.get(&id); - let player = Player { - name: player_name.to_string(), - }; + let player = player_name.to_string(); fn make_join_event(room: &Room, player: &Player) -> ServerToClientMessage { ServerToClientMessage::RoomChange { @@ -310,11 +308,11 @@ async fn room( let mut room = d.write().await; // check if player is already in the room. If they are, don't allow the new connection - if room.party_info.players.contains(&player) { + if room.party_info.players.iter().map(|f| f.to_lowercase()).contains(&player.to_lowercase()) { return reject_websocket_with_reason( ws, CloseCode::Protocol, - format!("{} is already in the room", player.name), + format!("{player} is already in the room"), ); } @@ -322,7 +320,7 @@ async fn room( if game .0 .player_states - .get_player_state(&player.name) + .get_player_state(&player) .is_none() { // Game is in progress and our new player isn't a member diff --git a/ui/src/Game.tsx b/ui/src/Game.tsx index 4918963..370032d 100644 --- a/ui/src/Game.tsx +++ b/ui/src/Game.tsx @@ -404,7 +404,7 @@ export function Game(props: { const playerAndScores = api_state.public_information.players; const remainingTiles = api_state.public_information.remaining_tiles; - const isPlayersTurn = api_state.public_information.current_player == props.settings.playerName; + const isPlayersTurn = api_state.public_information.current_player.toLowerCase() == props.settings.playerName.toLowerCase(); return <>

Connecting to {roomName}

} else if (partyInfo != null) { const players = partyInfo.players.map((x) => { - return
  • {x.name}
  • ; + return
  • {x}
  • ; }); const ais = partyInfo.ais.map((x, i) => { return
  • diff --git a/ui/src/ws_api.tsx b/ui/src/ws_api.tsx index e7697d4..7c39096 100644 --- a/ui/src/ws_api.tsx +++ b/ui/src/ws_api.tsx @@ -1,8 +1,6 @@ import {API, APIState, Difficulty, PlayedTile} from "./api"; -export interface Player { - name: string -} +export type Player = string; export interface AI { proportion: number diff --git a/wordgrid/src/api.rs b/wordgrid/src/api.rs index 86f7ccd..54013f3 100644 --- a/wordgrid/src/api.rs +++ b/wordgrid/src/api.rs @@ -58,7 +58,7 @@ impl APIGame { } fn is_players_turn(&self, player: &str) -> bool { - self.0.current_player_name().eq(player) + self.0.current_player_name().eq_ignore_ascii_case(player) } fn player_exists(&self, player: &str) -> bool { diff --git a/wordgrid/src/dictionary.rs b/wordgrid/src/dictionary.rs index a21af5c..ebdf0a8 100644 --- a/wordgrid/src/dictionary.rs +++ b/wordgrid/src/dictionary.rs @@ -84,7 +84,7 @@ mod tests { fn test_dictionary() { let dictionary = HashMap::create_from_path("../resources/dictionary.csv"); - assert_eq!(dictionary.len(), 279429); + assert_eq!(dictionary.len(), 279426); assert!(dictionary.contains_key("AA")); assert!(dictionary.contains_key("AARDVARK")); diff --git a/wordgrid/src/game.rs b/wordgrid/src/game.rs index 5329a73..b6d5824 100644 --- a/wordgrid/src/game.rs +++ b/wordgrid/src/game.rs @@ -158,14 +158,14 @@ impl PlayerStates { pub fn get_player_state(&self, name: &str) -> Option<&PlayerState> { self.0 .iter() - .filter(|state| state.player.get_name().eq(name)) + .filter(|state| state.player.get_name().eq_ignore_ascii_case(name)) .nth(0) } pub fn get_player_state_mut(&mut self, name: &str) -> Option<&mut PlayerState> { self.0 .iter_mut() - .filter(|state| state.player.get_name().eq(name)) + .filter(|state| state.player.get_name().eq_ignore_ascii_case(name)) .nth(0) }