diff --git a/server/src/game_handler.rs b/server/src/game_handler.rs index ed0421a..cb20f55 100644 --- a/server/src/game_handler.rs +++ b/server/src/game_handler.rs @@ -330,7 +330,7 @@ impl GameHandler { if let Some(host) = self.state.online_users.read().unwrap().get(&addr) { // Create manifest let manifest = NewGameManifest { - name: new_game.name, + name: new_game.name[..64].to_string(), // Limit name length to 64 host: host.clone(), packs: new_game .packs diff --git a/server/src/message_handler.rs b/server/src/message_handler.rs index d2460d0..0aa727c 100644 --- a/server/src/message_handler.rs +++ b/server/src/message_handler.rs @@ -26,7 +26,7 @@ impl MessageHandler { Message::Text(text) => match text { _chat_message if let Ok(chat_message) = from_str::(&text) => { // TODO: This should be delegated to user handler and an outgoing message and/or chat handler - let msg = format! {"{0}: {1}", self.state.online_users.read().unwrap().get(&addr).unwrap().read().unwrap().name, chat_message.text}; + let msg = format! {"{0}: {1}", self.state.online_users.read().unwrap().get(&addr).unwrap().read().unwrap().name, chat_message.text[..1024].to_string()}; tracing::debug!("{msg}"); self.state .broadcast_tx diff --git a/server/src/user_handler.rs b/server/src/user_handler.rs index 1a2ad87..670118b 100644 --- a/server/src/user_handler.rs +++ b/server/src/user_handler.rs @@ -140,8 +140,9 @@ impl UserHandler { /// Handle user login async fn login(&self, request: UserLogInRequest, addr: SocketAddr) { + let username_max_len = 66; // This is the longest name the generator may produce right now let broadcast_tx = self.state.broadcast_tx.clone(); - let new_name = request.username.clone(); + let new_name = request.username[..username_max_len].to_string(); let old_name; if let Some(user) = self.state.online_users.read().unwrap().get(&addr) { @@ -221,7 +222,9 @@ impl UserHandler { // Change user's name if let Some(user) = self.state.online_users.write().unwrap().get_mut(&addr) { - user.write().unwrap().change_name(request.username); + user.write() + .unwrap() + .change_name(request.username[..username_max_len].to_string()); } else { tracing::error!("Error updating username: Can't find user!"); return;