@@ 16,6 16,7 @@ impl Plugin for NetworkingPlugin {
fn build(&self, app: &mut App) {
app.add_system_to_stage(CoreStage::PreUpdate, systems::events::connect_events)
.add_system_to_stage(CoreStage::PreUpdate, systems::events::reject_events)
- .add_system_to_stage(CoreStage::PreUpdate, systems::events::disconnect_events);
+ .add_system_to_stage(CoreStage::PreUpdate, systems::events::disconnect_events)
+ .add_system_to_stage(CoreStage::PreUpdate, systems::events::message_events);
}
}
@@ 8,14 8,18 @@
use bevy::prelude::*;
use iyes_loopless::state::NextState;
+use laurelin_shared::server::{channels::AfterAuthChannel, messages::AfterAuth};
use naia_bevy_client::{
- events::{ConnectEvent, DisconnectEvent, RejectEvent},
+ events::{ConnectEvent, DisconnectEvent, MessageEvents, RejectEvent},
Client,
};
-use crate::plugins::menu::{
- ui::connect::{ConnectScreenData, ConnectState},
- MenuState,
+use crate::{
+ cfg::CfgUser,
+ plugins::menu::{
+ ui::connect::{ConnectScreenData, ConnectState},
+ MenuState,
+ },
};
pub fn connect_events(
@@ 52,3 56,13 @@ pub fn disconnect_events(mut ev: EventReader<DisconnectEvent>) {
info!("Laurelin client disconnected from server.");
}
}
+
+pub fn message_events(mut ev: EventReader<MessageEvents>, mut cfg_user: ResMut<CfgUser>) {
+ for events in ev.iter() {
+ for aa_message in events.read::<AfterAuthChannel, AfterAuth>() {
+ // TODO: move handling to a separate function?
+ cfg_user.username = aa_message.username;
+ cfg_user.cookie = aa_message.cookie;
+ }
+ }
+}