actually check the event type (facepalm)

This commit is contained in:
griffi-gh 2023-03-08 22:21:19 +01:00
parent 45c9b20ede
commit 51f113d162
2 changed files with 22 additions and 12 deletions

View file

@ -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<UniqueViewMut<UdpServer>>,
server: NonSendSync<UniqueView<UdpServer>>,
events: UniqueView<ServerEvents>,
config: UniqueView<ConfigTable>
) {
@ -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 {

View file

@ -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,15 +87,25 @@ fn check_server_hello_response(
mut join_state: UniqueViewMut<ClientJoinState>
) {
for event in network_events.iter() {
if let ClientEvent::Receive(data) = &event.0 {
log::info!("Joined the server!");
let ClientEvent::Receive(data) = &event.0 else {
continue
};
if !event.is_message_of_type::<S_SERVER_HELLO>() {
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;
}
}
}
pub fn update_networking() -> Workload {
(
@ -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")