limit accepted text input length
This commit is contained in:
parent
d490086793
commit
7cb2d14c01
3 changed files with 7 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -26,7 +26,7 @@ impl MessageHandler {
|
|||
Message::Text(text) => match 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
|
||||
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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue