From 51f113d162b23115c1a817fe0fd9487c7a6b42e4 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Wed, 8 Mar 2023 22:21:19 +0100 Subject: [PATCH] actually check the event type (facepalm) --- kubi-server/src/auth.rs | 8 ++++---- kubi/src/networking.rs | 26 ++++++++++++++++++-------- 2 files changed, 22 insertions(+), 12 deletions(-) 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")