allow input less than max lol

This commit is contained in:
Adam 2024-10-07 21:19:27 -04:00
parent 7cb2d14c01
commit 310bec01eb
3 changed files with 26 additions and 6 deletions

View file

@ -328,9 +328,18 @@ impl GameHandler {
} }
if let Some(host) = self.state.online_users.read().unwrap().get(&addr) { if let Some(host) = self.state.online_users.read().unwrap().get(&addr) {
let new_game_name;
let max_game_name_len = 32;
if new_game.name.len() > max_game_name_len {
new_game_name = new_game.name[..max_game_name_len].to_string()
} else {
new_game_name = new_game.name
}
// Create manifest // Create manifest
let manifest = NewGameManifest { let manifest = NewGameManifest {
name: new_game.name[..64].to_string(), // Limit name length to 64 name: new_game_name,
host: host.clone(), host: host.clone(),
packs: new_game packs: new_game
.packs .packs

View file

@ -26,7 +26,13 @@ impl MessageHandler {
Message::Text(text) => match text { Message::Text(text) => match text {
_chat_message if let Ok(chat_message) = from_str::<ChatMessage>(&text) => { _chat_message if let Ok(chat_message) = from_str::<ChatMessage>(&text) => {
// TODO: This should be delegated to user handler and an outgoing message and/or chat handler // 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[..1024].to_string()}; let msg;
if chat_message.text.len() > 1024 {
msg = format! {"{0}: {1}", self.state.online_users.read().unwrap().get(&addr).unwrap().read().unwrap().name, chat_message.text[..1024].to_string()};
} else {
msg = format! {"{0}: {1}", self.state.online_users.read().unwrap().get(&addr).unwrap().read().unwrap().name, chat_message.text};
}
tracing::debug!("{msg}"); tracing::debug!("{msg}");
self.state self.state
.broadcast_tx .broadcast_tx

View file

@ -142,7 +142,14 @@ impl UserHandler {
async fn login(&self, request: UserLogInRequest, addr: SocketAddr) { 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 username_max_len = 66; // This is the longest name the generator may produce right now
let broadcast_tx = self.state.broadcast_tx.clone(); let broadcast_tx = self.state.broadcast_tx.clone();
let new_name = request.username[..username_max_len].to_string(); let new_name;
if request.username.len() > username_max_len {
new_name = request.username[..username_max_len].to_string();
} else {
new_name = request.username;
}
let old_name; let old_name;
if let Some(user) = self.state.online_users.read().unwrap().get(&addr) { if let Some(user) = self.state.online_users.read().unwrap().get(&addr) {
@ -222,9 +229,7 @@ impl UserHandler {
// Change user's name // Change user's name
if let Some(user) = self.state.online_users.write().unwrap().get_mut(&addr) { if let Some(user) = self.state.online_users.write().unwrap().get_mut(&addr) {
user.write() user.write().unwrap().change_name(new_name.clone());
.unwrap()
.change_name(request.username[..username_max_len].to_string());
} else { } else {
tracing::error!("Error updating username: Can't find user!"); tracing::error!("Error updating username: Can't find user!");
return; return;