feat: print addr in log
This commit is contained in:
16
src/main.rs
16
src/main.rs
@@ -130,7 +130,7 @@ fn handle_text_message(handle_context: &mut HandleContext, tx: &Tx, addr: Socket
|
|||||||
warning!("Not in room: {:?} - {:?}", room_id, client_id);
|
warning!("Not in room: {:?} - {:?}", room_id, client_id);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
client_not_in_room(&tx);
|
client_not_in_room(&tx, addr);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
RoomMessageType::Destroy => {
|
RoomMessageType::Destroy => {
|
||||||
@@ -146,7 +146,7 @@ fn handle_text_message(handle_context: &mut HandleContext, tx: &Tx, addr: Socket
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
client_not_in_room(&tx);
|
client_not_in_room(&tx, addr);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
RoomMessageType::ListPeers => {
|
RoomMessageType::ListPeers => {
|
||||||
@@ -172,7 +172,7 @@ fn handle_text_message(handle_context: &mut HandleContext, tx: &Tx, addr: Socket
|
|||||||
m.send(&tx);
|
m.send(&tx);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
client_not_in_room(&tx);
|
client_not_in_room(&tx, addr);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
RoomMessageType::Broadcast => {
|
RoomMessageType::Broadcast => {
|
||||||
@@ -204,7 +204,7 @@ fn handle_text_message(handle_context: &mut HandleContext, tx: &Tx, addr: Socket
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
client_not_in_room(&tx);
|
client_not_in_room(&tx, addr);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
RoomMessageType::Peer => {
|
RoomMessageType::Peer => {
|
||||||
@@ -236,7 +236,7 @@ fn handle_text_message(handle_context: &mut HandleContext, tx: &Tx, addr: Socket
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
client_not_in_room(&tx);
|
client_not_in_room(&tx, addr);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -290,15 +290,15 @@ async fn inner_handle_connection(
|
|||||||
pin_mut!(broadcast_incoming, receive_from_others);
|
pin_mut!(broadcast_incoming, receive_from_others);
|
||||||
future::select(broadcast_incoming, receive_from_others).await;
|
future::select(broadcast_incoming, receive_from_others).await;
|
||||||
|
|
||||||
information!("{} disconnected", &addr);
|
information!("Client disconnected: {}", &addr);
|
||||||
client_exit(&handle_context.room_map, &handle_context.room_id, &handle_context.client_id);
|
client_exit(&handle_context.room_map, &handle_context.room_id, &handle_context.client_id);
|
||||||
handle_context.peer_map.lock().unwrap().remove(&addr);
|
handle_context.peer_map.lock().unwrap().remove(&addr);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn client_not_in_room(tx: &Tx) {
|
fn client_not_in_room(tx: &Tx, addr: SocketAddr) {
|
||||||
information!("Client is not in room");
|
information!("Client is not in room: {}", addr);
|
||||||
RoomMessageDown::create_error_reply("Client is not in room").send(tx);
|
RoomMessageDown::create_error_reply("Client is not in room").send(tx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use tungstenite::Message;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use crate::types::Tx;
|
use crate::types::{Tx, TxSendMessage};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
||||||
pub enum RoomMessageType {
|
pub enum RoomMessageType {
|
||||||
@@ -79,7 +78,7 @@ impl RoomMessageDown {
|
|||||||
|
|
||||||
pub fn send(&self, tx: &Tx) {
|
pub fn send(&self, tx: &Tx) {
|
||||||
if let Ok(mm) = serde_json::to_string(self) {
|
if let Ok(mm) = serde_json::to_string(self) {
|
||||||
tx.unbounded_send(Message::Text(mm)).ok();
|
tx.send_text(mm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user