diff --git a/src/lib.rs b/src/lib.rs index bdcbdc3..48697f2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,15 +10,17 @@ use uuid::Uuid; pub struct GameServer { name: String, ip: IpAddr, + tls: bool, port: u16, pub players: u32, } impl GameServer { - pub fn new(name: String, ip: IpAddr, port: u16) -> GameServer { + pub fn new(name: String, ip: IpAddr, tls: bool, port: u16) -> GameServer { GameServer { name, ip, + tls, port, players: 0, } @@ -28,7 +30,7 @@ impl GameServer { #[derive(Debug, Serialize, Deserialize)] #[serde(untagged)] pub enum GameMessage { - Connect { name: String, port: u16 }, + Connect { name: String, tls: bool, port: u16 }, Status { players: u32 }, } @@ -110,6 +112,7 @@ mod tests { let server = GameServer::new( String::from("Test"), IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), + false, 12345, ); let mut server_list = ServerList::new(); @@ -123,6 +126,7 @@ mod tests { let server = GameServer::new( String::from("Test"), IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), + false, 12345, ); let mut server_list = ServerList::new(); @@ -137,6 +141,7 @@ mod tests { let server = GameServer::new( String::from("Test"), IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), + false, 12345, ); let expected = server.clone(); @@ -152,6 +157,7 @@ mod tests { let server = GameServer::new( String::from("Test"), IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), + false, 12345, ); let mut server_list = ServerList::new(); diff --git a/src/main.rs b/src/main.rs index 79694f2..13650c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -153,16 +153,17 @@ async fn handle_socket( // loop until the first message is received, which should be the name while let Some(Ok(msg)) = socket.recv().await { + tracing::debug!("got msg: {:?}", msg); match msg { Message::Text(txt) => { - if let Ok(GameMessage::Connect { name, port }) = + if let Ok(GameMessage::Connect { name, tls, port }) = serde_json::from_str::(&txt) { // if this IP is local then it's on the same host so // replace the it with the server's public IP let ip = if is_local_ipv4(ip) { server_ip } else { ip }; - let server = GameServer::new(name, ip, port); + let server = GameServer::new(name, ip, tls, port); tracing::info!("created new game server: {:?}", server); game_id = server_list.add(server); break; @@ -224,8 +225,13 @@ fn remove_server(mut server_list: ServerList, game_id: &Uuid) { fn parse_game_message(server_list: &ServerList, server_id: &Uuid, msg: &str) { if let Ok(json) = serde_json::from_str::(msg) { match json { - GameMessage::Connect { name, port } => { - tracing::info!("new game connected with name: {} port: {}", name, port) + GameMessage::Connect { name, tls, port } => { + tracing::info!( + "new game connected with name: {} tls: {} port: {}", + name, + tls, + port + ) } GameMessage::Status { players } => { server_list.update(server_id, |game_server| {