mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-25 08:18:43 -06:00
actually check the event type (facepalm)
This commit is contained in:
parent
45c9b20ede
commit
51f113d162
|
@ -1,4 +1,4 @@
|
||||||
use shipyard::{UniqueView, UniqueViewMut, NonSendSync};
|
use shipyard::{UniqueView, NonSendSync};
|
||||||
use uflow::{server::Event as ServerEvent, SendMode};
|
use uflow::{server::Event as ServerEvent, SendMode};
|
||||||
use kubi_shared::networking::messages::{
|
use kubi_shared::networking::messages::{
|
||||||
ClientToServerMessage,
|
ClientToServerMessage,
|
||||||
|
@ -8,11 +8,11 @@ use kubi_shared::networking::messages::{
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
server::{ServerEvents, UdpServer, IsMessageOfType},
|
server::{ServerEvents, UdpServer, IsMessageOfType},
|
||||||
config::ConfigTable, util::log_error
|
config::ConfigTable
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn authenticate_players(
|
pub fn authenticate_players(
|
||||||
mut server: NonSendSync<UniqueViewMut<UdpServer>>,
|
server: NonSendSync<UniqueView<UdpServer>>,
|
||||||
events: UniqueView<ServerEvents>,
|
events: UniqueView<ServerEvents>,
|
||||||
config: UniqueView<ConfigTable>
|
config: UniqueView<ConfigTable>
|
||||||
) {
|
) {
|
||||||
|
@ -36,7 +36,7 @@ pub fn authenticate_players(
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
let Ok(parsed_message) = postcard::from_bytes(data) else {
|
let Ok(parsed_message) = postcard::from_bytes(data) else {
|
||||||
log::error!("Malformed message 00");
|
log::error!("Malformed message");
|
||||||
continue
|
continue
|
||||||
};
|
};
|
||||||
let ClientToServerMessage::ClientHello { username, password } = parsed_message else {
|
let ClientToServerMessage::ClientHello { username, password } = parsed_message else {
|
||||||
|
|
|
@ -3,7 +3,7 @@ use glium::glutin::event_loop::ControlFlow;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use uflow::client::{Client, Config as ClientConfig, Event as ClientEvent};
|
use uflow::client::{Client, Config as ClientConfig, Event as ClientEvent};
|
||||||
use kubi_shared::networking::{
|
use kubi_shared::networking::{
|
||||||
messages::{ClientToServerMessage, ServerToClientMessage},
|
messages::{ClientToServerMessage, ServerToClientMessage, S_SERVER_HELLO},
|
||||||
state::ClientJoinState
|
state::ClientJoinState
|
||||||
};
|
};
|
||||||
use crate::{events::EventComponent, control_flow::SetControlFlow};
|
use crate::{events::EventComponent, control_flow::SetControlFlow};
|
||||||
|
@ -87,15 +87,25 @@ fn check_server_hello_response(
|
||||||
mut join_state: UniqueViewMut<ClientJoinState>
|
mut join_state: UniqueViewMut<ClientJoinState>
|
||||||
) {
|
) {
|
||||||
for event in network_events.iter() {
|
for event in network_events.iter() {
|
||||||
if let ClientEvent::Receive(data) = &event.0 {
|
let ClientEvent::Receive(data) = &event.0 else {
|
||||||
|
continue
|
||||||
log::info!("Joined the server!");
|
};
|
||||||
|
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
|
//TODO handle init data
|
||||||
*join_state = ClientJoinState::Joined;
|
*join_state = ClientJoinState::Joined;
|
||||||
|
log::info!("Joined the server!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update_networking() -> Workload {
|
pub fn update_networking() -> Workload {
|
||||||
(
|
(
|
||||||
|
@ -119,7 +129,7 @@ pub fn disconnect_on_exit(
|
||||||
if client.0.is_active() {
|
if client.0.is_active() {
|
||||||
client.0.flush();
|
client.0.flush();
|
||||||
client.0.disconnect();
|
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");
|
log::info!("Client disconnected");
|
||||||
} else {
|
} else {
|
||||||
log::info!("Client inactive")
|
log::info!("Client inactive")
|
||||||
|
|
Loading…
Reference in a new issue