trying to protect against spam a little

main
_ 2021-10-25 00:58:53 +00:00
parent 36176ef200
commit 119ec04d0c
1 changed files with 8 additions and 1 deletions

View File

@ -49,6 +49,10 @@ async fn read_input <R: AsyncReadExt + Unpin, W: AsyncWrite + Unpin> (
}
}
if ! buffer.contains (&b'\n') {
anyhow::bail! ("No newline. User might be spamming us or something.");
}
let buffer = String::from_utf8 (buffer)?;
// I don't know why I need the type annotation here, but I do.
@ -101,13 +105,16 @@ async fn process_socket (socket: TcpStream, id: &str)
}
},
Response::Sleep (x) => sleep (x).await,
Response::PlayerVictory => tracing::info! ("Connection {} beat the game", id),
Response::PlayerVictory => tracing::info! ("Connection {} PlayerVictory", id),
Response::JokeEnding => tracing::info! ("Connection {} JokeEnding", id),
Response::Quit => break 'main_loop,
_ => (),
}
}
}
tracing::info! ("Connection {} ending gracefully", id);
Ok (())
}