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
|
||||
let mut recv_task = tokio::spawn(async move {
|
||||
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::Arc;
|
||||
use crate::CAHGame;
|
||||
|
@ -32,7 +32,7 @@ pub struct UserLoginRequest {
|
|||
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;
|
||||
|
||||
match message {
|
||||
|
@ -49,7 +49,7 @@ pub async fn message_handler(message: Message, state: &Arc<AppState>, who: Socke
|
|||
}
|
||||
} else {
|
||||
// just echo
|
||||
let msg = format! {"{who}: {text}"};
|
||||
let msg = format! {"{0}: {1}", who.name, text};
|
||||
tracing::debug!("{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) => {
|
||||
if let Some(cf) = c {
|
||||
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.reason
|
||||
)
|
||||
} else {
|
||||
tracing::debug!("close received without close frame")
|
||||
}
|
||||
let msg = format!("{who} left.");
|
||||
let msg = format!("{0} left.", who.name);
|
||||
tracing::debug!("{msg}");
|
||||
let _ = tx.send(msg);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue