use user
This commit is contained in:
parent
a719e78001
commit
c35b9604d1
2 changed files with 7 additions and 6 deletions
|
@ -52,7 +52,7 @@ pub async fn websocket(stream: WebSocket, state: Arc<AppState>, who: User) {
|
||||||
// handle new incoming messages
|
// handle new incoming messages
|
||||||
let mut recv_task = tokio::spawn(async move {
|
let mut recv_task = tokio::spawn(async move {
|
||||||
while let Some(Ok(message)) = receiver.next().await {
|
while let Some(Ok(message)) = receiver.next().await {
|
||||||
message_handler(message, &state, who.addr).await
|
message_handler(message, &state, &who).await
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::api::{greeting, Message, SocketAddr};
|
use crate::api::{greeting, Message, User};
|
||||||
use crate::AppState;
|
use crate::AppState;
|
||||||
use crate::Arc;
|
use crate::Arc;
|
||||||
use crate::CAHGame;
|
use crate::CAHGame;
|
||||||
|
@ -32,7 +32,7 @@ pub struct UserLoginRequest {
|
||||||
pub token: String,
|
pub token: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn message_handler(message: Message, state: &Arc<AppState>, who: SocketAddr) {
|
pub async fn message_handler(message: Message, state: &Arc<AppState>, who: &User) {
|
||||||
let tx = &state.tx;
|
let tx = &state.tx;
|
||||||
|
|
||||||
match message {
|
match message {
|
||||||
|
@ -49,7 +49,7 @@ pub async fn message_handler(message: Message, state: &Arc<AppState>, who: Socke
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// just echo
|
// just echo
|
||||||
let msg = format! {"{who}: {text}"};
|
let msg = format! {"{0}: {1}", who.name, text};
|
||||||
tracing::debug!("{msg}");
|
tracing::debug!("{msg}");
|
||||||
let _res = tx.send(msg);
|
let _res = tx.send(msg);
|
||||||
}
|
}
|
||||||
|
@ -62,14 +62,15 @@ pub async fn message_handler(message: Message, state: &Arc<AppState>, who: Socke
|
||||||
Message::Close(c) => {
|
Message::Close(c) => {
|
||||||
if let Some(cf) = c {
|
if let Some(cf) = c {
|
||||||
tracing::debug!(
|
tracing::debug!(
|
||||||
"Close received from {who} with code: {} and reason: {}",
|
"Close received from {0} with code: {1} and reason: {2}",
|
||||||
|
who.addr,
|
||||||
cf.code,
|
cf.code,
|
||||||
cf.reason
|
cf.reason
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
tracing::debug!("close received without close frame")
|
tracing::debug!("close received without close frame")
|
||||||
}
|
}
|
||||||
let msg = format!("{who} left.");
|
let msg = format!("{0} left.", who.name);
|
||||||
tracing::debug!("{msg}");
|
tracing::debug!("{msg}");
|
||||||
let _ = tx.send(msg);
|
let _ = tx.send(msg);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue