@@ 31,7 31,9 @@ pub struct RuntimeTemp {
}
#[derive(Resource)]
-pub struct Global {}
+pub struct Global {
+ pub user_to_session_map: HashMap<UserKey, String>,
+}
fn main() {
let mut server = App::new();
@@ 57,6 59,10 @@ fn main() {
.insert_resource(RuntimeTemp {
afterauth_details: HashMap::new(),
})
+ // global data
+ .insert_resource(Global {
+ user_to_session_map: HashMap::new(),
+ })
// init system
.add_startup_system(systems::init::init)
// events
@@ 23,7 23,7 @@ use naia_bevy_server::{
Server,
};
-use crate::{Config, RuntimeTemp};
+use crate::{Config, Global, RuntimeTemp};
pub(crate) fn auth_events(
mut ev: EventReader<AuthEvents>,
@@ 72,6 72,7 @@ pub(crate) fn connect_events(
mut ev: EventReader<ConnectEvent>,
mut server: Server,
mut temp: ResMut<RuntimeTemp>,
+ mut global: ResMut<Global>,
) {
for ConnectEvent(user_key) in ev.iter() {
let address = server.user(user_key).address();
@@ 86,13 87,20 @@ pub(crate) fn connect_events(
cookie: aa_details.1.clone(),
},
);
+
+ global
+ .user_to_session_map
+ .insert(*user_key, aa_details.1.clone());
+
temp.afterauth_details.remove(&user_key);
}
}
-pub(crate) fn disconnect_events(mut ev: EventReader<DisconnectEvent>) {
- for DisconnectEvent(_user_key, user) in ev.iter() {
+pub(crate) fn disconnect_events(mut ev: EventReader<DisconnectEvent>, mut global: ResMut<Global>) {
+ for DisconnectEvent(user_key, user) in ev.iter() {
info!("Naia Server disconnected from: {:?}", user.address);
+
+ global.user_to_session_map.remove(user_key);
}
}