Compare commits

..

No commits in common. "c1938347a28edafd27595744dc9d9accced983f8" and "9701e4dcc0620afc05fcbb89831cca0abef7ad24" have entirely different histories.

4 changed files with 14 additions and 31 deletions

20
Cargo.lock generated
View file

@ -1715,9 +1715,9 @@ dependencies = [
[[package]]
name = "serde_spanned"
version = "0.6.7"
version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d"
checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0"
dependencies = [
"serde",
]
@ -2052,9 +2052,9 @@ dependencies = [
[[package]]
name = "toml"
version = "0.8.16"
version = "0.8.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81967dd0dd2c1ab0bc3468bd7caecc32b8a4aa47d0c8c695d8c2b2108168d62c"
checksum = "ac2caab0bf757388c6c0ae23b3293fdb463fee59434529014f85e3263b995c28"
dependencies = [
"serde",
"serde_spanned",
@ -2064,18 +2064,18 @@ dependencies = [
[[package]]
name = "toml_datetime"
version = "0.6.7"
version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8fb9f64314842840f1d940ac544da178732128f1c78c21772e876579e0da1db"
checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf"
dependencies = [
"serde",
]
[[package]]
name = "toml_edit"
version = "0.22.17"
version = "0.22.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d9f8729f5aea9562aac1cc0441f5d6de3cff1ee0c5d67293eeca5eb36ee7c16"
checksum = "278f3d518e152219c994ce877758516bca5e118eaed6996192a774fb9fbf0788"
dependencies = [
"indexmap",
"serde",
@ -2566,9 +2566,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "winnow"
version = "0.6.16"
version = "0.6.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b480ae9340fc261e6be3e95a1ba86d54ae3f9171132a73ce8d4bbaf68339507c"
checksum = "557404e450152cd6795bb558bca69e43c585055f4606e3bcae5894fc6dac9ba0"
dependencies = [
"memchr",
]

View file

@ -21,18 +21,12 @@ pub struct ServerStateSummary {
}
/// User
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
#[derive(Clone, Eq, PartialEq, Hash)]
pub struct User {
pub name: String,
pub addr: SocketAddr,
}
impl User {
pub fn change_name(&mut self, new_name: String) {
self.name = new_name;
}
}
/// New game request structure
#[derive(Debug, Serialize, Deserialize)]
pub struct NewGameRequest {

View file

@ -27,7 +27,7 @@ fn server_sum_update(state: &Arc<AppState>) -> ServerStateSummary {
}
}
pub async fn on_websocket_connection(stream: WebSocket, state: Arc<AppState>, mut who: User) {
pub async fn on_websocket_connection(stream: WebSocket, state: Arc<AppState>, who: User) {
// Add user to users
//if doesn't exist
let _true_if_not_exist = &state.users.lock().unwrap().insert(who.clone());
@ -73,7 +73,7 @@ pub async fn on_websocket_connection(stream: WebSocket, state: Arc<AppState>, mu
// handle new incoming messages
let mut recv_task = tokio::spawn(async move {
while let Some(Ok(message)) = receiver.next().await {
message_handler(message, &state, &mut who).await
message_handler(message, &state, &who).await
}
});

View file

@ -4,7 +4,7 @@ use crate::api::*;
use crate::AppState;
use crate::Arc;
pub async fn message_handler(message: Message, state: &Arc<AppState>, who: &mut User) {
pub async fn message_handler(message: Message, state: &Arc<AppState>, who: &User) {
let tx = &state.tx;
match message {
@ -30,17 +30,6 @@ pub async fn message_handler(message: Message, state: &Arc<AppState>, who: &mut
let msg = format! {"{0}: {1}", who.name, chat_message.text};
tracing::debug!("{msg}");
let _res = tx.send(to_string::<ChatMessage>(&ChatMessage { text: msg }).unwrap());
} else if let Ok(user_log_in) = serde_json::from_str::<UserLogIn>(&text) {
let old_name = who.name.clone();
let new_name = user_log_in.username.clone();
who.change_name(user_log_in.username);
let msg = format!{
"{0} changed name to {1}.",
old_name,
new_name
};
tracing::debug!("{msg}");
let _res = tx.send(to_string::<ChatMessage>(&ChatMessage { text: msg }).unwrap());
} else {
tracing::debug!("Unhandled message: {}", &text);
}