diff --git a/kubi-server/src/auth.rs b/kubi-server/src/auth.rs index 303f6fd..7d6dfae 100644 --- a/kubi-server/src/auth.rs +++ b/kubi-server/src/auth.rs @@ -1,4 +1,4 @@ -use shipyard::{UniqueView, UniqueViewMut, NonSendSync}; +use shipyard::{UniqueView, NonSendSync}; use uflow::{server::Event as ServerEvent, SendMode}; use kubi_shared::networking::messages::{ ClientToServerMessage, @@ -8,11 +8,11 @@ use kubi_shared::networking::messages::{ }; use crate::{ server::{ServerEvents, UdpServer, IsMessageOfType}, - config::ConfigTable, util::log_error + config::ConfigTable }; pub fn authenticate_players( - mut server: NonSendSync>, + server: NonSendSync>, events: UniqueView, config: UniqueView ) { @@ -36,7 +36,7 @@ pub fn authenticate_players( continue } let Ok(parsed_message) = postcard::from_bytes(data) else { - log::error!("Malformed message 00"); + log::error!("Malformed message"); continue }; let ClientToServerMessage::ClientHello { username, password } = parsed_message else { diff --git a/kubi/src/networking.rs b/kubi/src/networking.rs index 04462b6..31450ac 100644 --- a/kubi/src/networking.rs +++ b/kubi/src/networking.rs @@ -3,7 +3,7 @@ use glium::glutin::event_loop::ControlFlow; use std::net::SocketAddr; use uflow::client::{Client, Config as ClientConfig, Event as ClientEvent}; use kubi_shared::networking::{ - messages::{ClientToServerMessage, ServerToClientMessage}, + messages::{ClientToServerMessage, ServerToClientMessage, S_SERVER_HELLO}, state::ClientJoinState }; use crate::{events::EventComponent, control_flow::SetControlFlow}; @@ -87,13 +87,23 @@ fn check_server_hello_response( mut join_state: UniqueViewMut ) { for event in network_events.iter() { - if let ClientEvent::Receive(data) = &event.0 { - - log::info!("Joined the server!"); - //TODO handle init data - *join_state = ClientJoinState::Joined; - return; + let ClientEvent::Receive(data) = &event.0 else { + continue + }; + if !event.is_message_of_type::() { + continue } + let Ok(parsed_message) = postcard::from_bytes(data) else { + log::error!("Malformed message"); + continue + }; + let ServerToClientMessage::ServerHello { init } = parsed_message else { + unreachable!() + }; + //TODO handle init data + *join_state = ClientJoinState::Joined; + log::info!("Joined the server!"); + return; } } @@ -119,7 +129,7 @@ pub fn disconnect_on_exit( if client.0.is_active() { client.0.flush(); client.0.disconnect(); - while client.0.is_active() { client.0.step(); } + while client.0.is_active() { client.0.step().for_each(|_|()); } log::info!("Client disconnected"); } else { log::info!("Client inactive")