diff --git a/src/services/game/manager.rs b/src/services/game/manager.rs index d6804bc..7aecb55 100644 --- a/src/services/game/manager.rs +++ b/src/services/game/manager.rs @@ -178,7 +178,7 @@ impl GameManager { } // Update the player current game - session.set_game(game_id, Arc::downgrade(&game_ref)); + session.data.set_game(game_id, Arc::downgrade(&game_ref)); } pub async fn add_from_matchmaking(&self, game_ref: GameRef, player: GamePlayer) { diff --git a/src/services/game/mod.rs b/src/services/game/mod.rs index 41509e8..48f1961 100644 --- a/src/services/game/mod.rs +++ b/src/services/game/mod.rs @@ -3,6 +3,7 @@ use crate::{ config::RuntimeConfig, database::entities::Player, session::{ + data::NetData, models::{ game_manager::{ AdminListChange, AdminListOperation, AttributesChange, GameSettings, @@ -15,7 +16,7 @@ use crate::{ }, packet::Packet, router::RawBlaze, - NetData, SessionNotifyHandle, WeakSessionLink, + SessionNotifyHandle, WeakSessionLink, }, utils::{ components::game_manager, @@ -131,19 +132,19 @@ impl GamePlayer { pub fn try_clear_game(&self) { if let Some(link) = self.link.upgrade() { - link.clear_game(); + link.data.clear_game(); } } pub fn try_subscribe(&self, player_id: PlayerID, subscriber: SessionNotifyHandle) { if let Some(link) = self.link.upgrade() { - link.add_subscriber(player_id, subscriber); + link.data.add_subscriber(player_id, subscriber); } } pub fn try_unsubscribe(&self, player_id: PlayerID) { if let Some(link) = self.link.upgrade() { - link.remove_subscriber(player_id); + link.data.remove_subscriber(player_id); } } diff --git a/src/session/data.rs b/src/session/data.rs new file mode 100644 index 0000000..f5fb20e --- /dev/null +++ b/src/session/data.rs @@ -0,0 +1,339 @@ +use std::sync::Arc; + +use parking_lot::{Mutex, MutexGuard}; +use serde::Serialize; + +use crate::{ + database::entities::Player, + services::{ + game::{GameRef, WeakGameRef}, + sessions::SessionPlayerAssociation, + }, + utils::{ + components::user_sessions, + types::{GameID, PlayerID}, + }, +}; + +use super::{ + models::{ + game_manager::RemoveReason, + user_sessions::{ + HardwareFlags, LookupResponse, NotifyUserAdded, NotifyUserRemoved, NotifyUserUpdated, + UserDataFlags, UserIdentification, UserSessionExtendedData, + UserSessionExtendedDataUpdate, + }, + NetworkAddress, QosNetworkData, + }, + packet::Packet, + SessionNotifyHandle, +}; + +#[derive(Default)] +pub struct SessionData { + inner: Mutex>, +} + +impl SessionData { + /// Clears the underlying session data + pub fn clear(&self) { + self.inner.lock().take(); + } + + // Read from the underlying session data + pub fn read(&self) -> MutexGuard<'_, Option> { + self.inner.lock() + } + + /// Writes to the underlying session data without publishing the changes + pub fn write_silent(&self, update: F) -> Option + where + F: FnOnce(&mut SessionDataInner) -> O, + { + self.inner.lock().as_mut().map(update) + } + + /// Writes to the underlying session data, publishes changes to + /// subscribers + #[inline] + pub fn write_publish(&self, update: F) -> Option + where + F: FnOnce(&mut SessionDataInner) -> O, + { + self.inner.lock().as_mut().map(|data| { + let value = update(data); + data.publish_update(); + value + }) + } + + /// Starts a session from the provided player association + pub fn start_session(&self, player: SessionPlayerAssociation) -> Arc { + self.inner + .lock() + .insert(SessionDataInner::new(player)) + // Obtain the player to return + .player_assoc + .player + .clone() + } + + /// Gets the currently authenticated player + pub fn get_player(&self) -> Option> { + self.read() + .as_ref() + .map(|value| value.player_assoc.player.clone()) + } + + /// Updates the session hardware flags + pub fn set_hardware_flags(&self, value: HardwareFlags) { + self.write_publish(|data| data.net = Arc::new(data.net.with_hardware_flags(value))); + } + + /// Sets the current session network information + pub fn set_network_info( + &self, + address: NetworkAddress, + qos: QosNetworkData, + ping_site_latency: Vec, + ) { + self.write_publish(|data| { + data.net = Arc::new(data.net.with_basic(address, qos, ping_site_latency)) + }); + } + + /// Obtains the network data for the session + pub fn network_info(&self) -> Option> { + self.read().as_ref().map(|value| value.net.clone()) + } + + /// Sets the game the session is currently apart of + pub fn set_game(&self, game_id: GameID, game_ref: WeakGameRef) { + // Set the current game + self.write_publish(|data| { + data.game = Some(SessionGameData { + player_id: data.player_assoc.player.id, + game_id, + game_ref, + }); + }); + } + + /// Clears the game the session is apart of + pub fn clear_game(&self) { + self.write_publish(|data| data.game = None); + } + + /// Obtains the ID and reference to the game the session is currently apart of + pub fn get_game(&self) -> Option<(GameID, GameRef)> { + let guard = self.read(); + + let data = guard.as_ref()?; + let game_data = data.game.as_ref()?; + + let game_ref = match game_data.game_ref.upgrade() { + Some(value) => value, + // We have a dangling game ref, clean it up + None => { + // Drop the guard before writing + drop(guard); + + // Clear the dangling game ref + self.clear_game(); + return None; + } + }; + + Some((game_data.game_id, game_ref)) + } + + pub fn get_lookup_response(&self) -> Option { + self.read().as_ref().map(|data| LookupResponse { + player: data.player_assoc.player.clone(), + extended_data: data.ext_data(), + }) + } + + /// Adds a subscriber to the session + pub fn add_subscriber(&self, player_id: PlayerID, subscriber: SessionNotifyHandle) { + self.write_silent(|data| data.add_subscriber(player_id, subscriber)); + } + + /// Removes a subscriber from the session + pub fn remove_subscriber(&self, player_id: PlayerID) { + self.write_silent(|data| data.remove_subscriber(player_id)); + } +} + +pub struct SessionDataInner { + /// Session -> Player association, currently authenticated player + pub player_assoc: Arc, + /// Networking information for current session + pub net: Arc, + /// Currently connected game for the session + game: Option, + /// Subscribers listening for changes to this session + subscribers: Vec, +} + +impl SessionDataInner { + fn new(player: SessionPlayerAssociation) -> Self { + Self { + player_assoc: Arc::new(player), + net: Default::default(), + game: Default::default(), + subscribers: Default::default(), + } + } + + pub fn ext_data(&self) -> UserSessionExtendedData { + UserSessionExtendedData { + net: self.net.clone(), + game: self.game.as_ref().map(|game| game.game_id), + } + } + + /// Adds a new subscriber to this session `player_id` is the ID of the player who is + /// subscribing and `notify_handle` is the handle for sending messages to them + pub fn add_subscriber(&mut self, player_id: PlayerID, notify_handle: SessionNotifyHandle) { + let target_id = self.player_assoc.player.id; + + // Notify the addition of this user data to the subscriber + notify_handle.notify(Packet::notify( + user_sessions::COMPONENT, + user_sessions::USER_ADDED, + NotifyUserAdded { + session_data: self.ext_data(), + user: UserIdentification::from_player(&self.player_assoc.player), + }, + )); + + // Notify the user that they are now subscribed to this user + notify_handle.notify(Packet::notify( + user_sessions::COMPONENT, + user_sessions::USER_UPDATED, + NotifyUserUpdated { + flags: UserDataFlags::SUBSCRIBED | UserDataFlags::ONLINE, + player_id: target_id, + }, + )); + + // Add the subscriber + self.subscribers.push(SessionSubscription { + target_id, + source_id: player_id, + source_notify_handle: notify_handle, + }); + } + + pub fn remove_subscriber(&mut self, player_id: PlayerID) { + self.subscribers + .retain(|value| value.source_id != player_id); + } + + /// Publishes changes of the session data to all the + /// subscribed session links + fn publish_update(&self) { + let packet = Packet::notify( + user_sessions::COMPONENT, + user_sessions::USER_SESSION_EXTENDED_DATA_UPDATE, + UserSessionExtendedDataUpdate { + user_id: self.player_assoc.player.id, + data: self.ext_data(), + }, + ); + + self.subscribers + .iter() + .for_each(|sub| sub.source_notify_handle.notify(packet.clone())); + } +} + +/// Subscription to a session to be notified when the session details +/// change. +struct SessionSubscription { + /// ID of the player being subscribed to + target_id: PlayerID, + /// ID of the player who is subscribing + source_id: PlayerID, + /// Handle to send messages to the source + source_notify_handle: SessionNotifyHandle, +} + +impl Drop for SessionSubscription { + fn drop(&mut self) { + // Notify the subscriber they've removed the user subscription + self.source_notify_handle.notify(Packet::notify( + user_sessions::COMPONENT, + user_sessions::USER_REMOVED, + NotifyUserRemoved { + player_id: self.target_id, + }, + )) + } +} + +/// When dropped if the player is still connected to the game they will +/// be disconnected from the game +struct SessionGameData { + /// ID of the player session when they joined the game + player_id: PlayerID, + /// ID of the game that was joined + game_id: GameID, + /// Reference for accessing the game + game_ref: WeakGameRef, +} + +impl Drop for SessionGameData { + fn drop(&mut self) { + // Attempt to access the game + let game_ref = match self.game_ref.upgrade() { + Some(value) => value, + // Game doesn't exist anymore + None => return, + }; + + let player_id = self.player_id; + + // Spawn an async task to handle removing the player + tokio::spawn(async move { + let game = &mut *game_ref.write().await; + game.remove_player(player_id, RemoveReason::PlayerLeft); + }); + } +} + +#[derive(Debug, Default, Clone, Serialize)] +pub struct NetData { + pub addr: NetworkAddress, + pub qos: QosNetworkData, + pub hardware_flags: HardwareFlags, + pub ping_site_latency: Vec, +} + +impl NetData { + // Re-creates the current net data using the provided address and QOS data + pub fn with_basic( + &self, + addr: NetworkAddress, + qos: QosNetworkData, + ping_site_latency: Vec, + ) -> Self { + Self { + addr, + qos, + hardware_flags: self.hardware_flags, + ping_site_latency, + } + } + + /// Re-creates the current net data using the provided hardware flags + pub fn with_hardware_flags(&self, flags: HardwareFlags) -> Self { + Self { + addr: self.addr.clone(), + qos: self.qos, + hardware_flags: flags, + ping_site_latency: self.ping_site_latency.clone(), + } + } +} diff --git a/src/session/mod.rs b/src/session/mod.rs index 365ab69..aa007ea 100644 --- a/src/session/mod.rs +++ b/src/session/mod.rs @@ -3,35 +3,19 @@ //! networking data. use self::{ - models::{ - game_manager::RemoveReason, - user_sessions::{ - HardwareFlags, LookupResponse, NotifyUserAdded, NotifyUserRemoved, NotifyUserUpdated, - UserDataFlags, UserIdentification, UserSessionExtendedData, - UserSessionExtendedDataUpdate, - }, - }, packet::{Packet, PacketCodec, PacketDebug}, router::BlazeRouter, }; use crate::{ database::entities::Player, - services::{ - game::{GameRef, WeakGameRef}, - sessions::{AssociationId, SessionPlayerAssociation}, - }, - session::models::{NetworkAddress, QosNetworkData}, - utils::{ - components::{component_key, user_sessions, DEBUG_IGNORED_PACKETS}, - types::{GameID, PlayerID}, - }, + services::sessions::AssociationId, + utils::components::{component_key, DEBUG_IGNORED_PACKETS}, }; +use data::SessionData; use futures_util::{future::BoxFuture, Sink, Stream}; use hyper::upgrade::Upgraded; use hyper_util::rt::TokioIo; use log::{debug, log_enabled, warn}; -use parking_lot::Mutex; -use serde::Serialize; use std::{ fmt::Debug, net::Ipv4Addr, @@ -46,6 +30,7 @@ use std::{future::Future, sync::Weak}; use tokio::sync::{mpsc, OwnedMutexGuard}; use tokio_util::codec::Framed; +pub mod data; pub mod models; pub mod packet; pub mod router; @@ -73,7 +58,7 @@ pub struct Session { tx: mpsc::UnboundedSender, /// Mutable data associated with the session - data: Mutex>, + pub data: SessionData, } #[derive(Clone)] @@ -97,179 +82,6 @@ impl SessionNotifyHandle { } } -struct SessionExtData { - /// Session -> Player association, currently authenticated player - player_assoc: Arc, - /// Networking information for current session - net: Arc, - /// Currently connected game for the session - game: Option, - /// Subscribers listening for changes to this session - subscribers: Vec, -} - -/// Subscription to a session to be notified when the session details -/// change. -struct SessionSubscription { - /// ID of the player being subscribed to - target_id: PlayerID, - /// ID of the player who is subscribing - source_id: PlayerID, - /// Handle to send messages to the source - source_notify_handle: SessionNotifyHandle, -} - -impl Drop for SessionSubscription { - fn drop(&mut self) { - // Notify the subscriber they've removed the user subscription - self.source_notify_handle.notify(Packet::notify( - user_sessions::COMPONENT, - user_sessions::USER_REMOVED, - NotifyUserRemoved { - player_id: self.target_id, - }, - )) - } -} - -impl SessionExtData { - fn new(player: SessionPlayerAssociation) -> Self { - Self { - player_assoc: Arc::new(player), - net: Default::default(), - game: Default::default(), - subscribers: Default::default(), - } - } - - fn ext(&self) -> UserSessionExtendedData { - UserSessionExtendedData { - net: self.net.clone(), - game: self.game.as_ref().map(|game| game.game_id), - } - } - - /// Adds a new subscriber to this session `player_id` is the ID of the player who is - /// subscribing and `notify_handle` is the handle for sending messages to them - fn add_subscriber(&mut self, player_id: PlayerID, notify_handle: SessionNotifyHandle) { - let target_id = self.player_assoc.player.id; - - // Notify the addition of this user data to the subscriber - notify_handle.notify(Packet::notify( - user_sessions::COMPONENT, - user_sessions::USER_ADDED, - NotifyUserAdded { - session_data: self.ext(), - user: UserIdentification::from_player(&self.player_assoc.player), - }, - )); - - // Notify the user that they are now subscribed to this user - notify_handle.notify(Packet::notify( - user_sessions::COMPONENT, - user_sessions::USER_UPDATED, - NotifyUserUpdated { - flags: UserDataFlags::SUBSCRIBED | UserDataFlags::ONLINE, - player_id: target_id, - }, - )); - - // Add the subscriber - self.subscribers.push(SessionSubscription { - target_id, - source_id: player_id, - source_notify_handle: notify_handle, - }); - } - - fn remove_subscriber(&mut self, player_id: PlayerID) { - self.subscribers - .retain(|value| value.source_id != player_id); - } - - /// Publishes changes of the session data to all the - /// subscribed session links - fn publish_update(&self) { - let packet = Packet::notify( - user_sessions::COMPONENT, - user_sessions::USER_SESSION_EXTENDED_DATA_UPDATE, - UserSessionExtendedDataUpdate { - user_id: self.player_assoc.player.id, - data: self.ext(), - }, - ); - - self.subscribers - .iter() - .for_each(|sub| sub.source_notify_handle.notify(packet.clone())); - } -} - -/// When dropped if the player is still connected to the game they will -/// be disconnected from the game -struct SessionGameData { - /// ID of the player session when they joined the game - player_id: PlayerID, - /// ID of the game that was joined - game_id: GameID, - /// Reference for accessing the game - game_ref: WeakGameRef, -} - -impl Drop for SessionGameData { - fn drop(&mut self) { - // Attempt to access the game - let game_ref = match self.game_ref.upgrade() { - Some(value) => value, - // Game doesn't exist anymore - None => return, - }; - - let player_id = self.player_id; - - // Spawn an async task to handle removing the player - tokio::spawn(async move { - let game = &mut *game_ref.write().await; - game.remove_player(player_id, RemoveReason::PlayerLeft); - }); - } -} - -#[derive(Debug, Default, Clone, Serialize)] -pub struct NetData { - pub addr: NetworkAddress, - pub qos: QosNetworkData, - pub hardware_flags: HardwareFlags, - pub ping_site_latency: Vec, -} - -impl NetData { - // Re-creates the current net data using the provided address and QOS data - pub fn with_basic( - &self, - addr: NetworkAddress, - qos: QosNetworkData, - ping_site_latency: Vec, - ) -> Self { - Self { - addr, - qos, - hardware_flags: self.hardware_flags, - ping_site_latency, - } - } - - /// Re-creates the current net data using the provided hardware flags - pub fn with_hardware_flags(&self, flags: HardwareFlags) -> Self { - Self { - addr: self.addr.clone(), - qos: self.qos, - hardware_flags: flags, - ping_site_latency: self.ping_site_latency.clone(), - } - } -} - static SESSION_IDS: AtomicU32 = AtomicU32::new(1); impl Session { @@ -318,7 +130,7 @@ impl Session { /// in order to clean up any remaining references to the session before dropping fn stop(self: Arc) { // Clear session data - self.clear_data(); + self.data.clear(); // Session should now be the sole owner let session = match Arc::try_unwrap(self) { @@ -336,112 +148,6 @@ impl Session { debug!("Session stopped (SID: {})", session.id); } - pub fn add_subscriber(&self, player_id: PlayerID, subscriber: SessionNotifyHandle) { - let data = &mut *self.data.lock(); - if let Some(data) = data { - data.add_subscriber(player_id, subscriber); - } - } - - pub fn remove_subscriber(&self, player_id: PlayerID) { - let data = &mut *self.data.lock(); - if let Some(data) = data { - data.remove_subscriber(player_id) - } - } - - pub fn set_player(&self, player: SessionPlayerAssociation) -> Arc { - let data = &mut *self.data.lock(); - let data = data.insert(SessionExtData::new(player)); - - data.player_assoc.player.clone() - } - - /// Clears the current game returning the game data if - /// the player was in a game - /// - /// Called by the game itself when the player has been removed - pub fn clear_game(&self) { - self.update_data(|data| { - // Clear active game - data.game = None; - }); - } - - /// Clears data associated with the session (Authentication/Current game/Networking) - pub fn clear_data(&self) { - // Take the current data and drop it - self.data.lock().take(); - } - - pub fn get_game(&self) -> Option<(GameID, GameRef)> { - let data = &*self.data.lock(); - data.as_ref() - .and_then(|value| value.game.as_ref()) - // Try upgrading the reference to get an actual game - .and_then(|value| { - value - .game_ref - .upgrade() - .map(|game_ref| (value.game_id, game_ref)) - }) - } - - pub fn get_lookup(&self) -> Option { - let data = &*self.data.lock(); - data.as_ref().map(|data| LookupResponse { - player: data.player_assoc.player.clone(), - extended_data: data.ext(), - }) - } - - #[inline] - fn update_data(&self, update: F) - where - F: FnOnce(&mut SessionExtData), - { - let data = &mut *self.data.lock(); - if let Some(data) = data { - update(data); - data.publish_update(); - } - } - - pub fn set_game(&self, game_id: GameID, game_ref: WeakGameRef) { - // Set the current game - self.update_data(|data| { - data.game = Some(SessionGameData { - player_id: data.player_assoc.player.id, - game_id, - game_ref, - }); - }); - } - - #[inline] - pub fn set_hardware_flags(&self, value: HardwareFlags) { - self.update_data(|data| { - data.net = Arc::new(data.net.with_hardware_flags(value)); - }); - } - - pub fn network_info(&self) -> Option> { - let data = &mut *self.data.lock(); - data.as_ref().map(|value| value.net.clone()) - } - - #[inline] - pub fn set_network_info( - &self, - address: NetworkAddress, - qos: QosNetworkData, - ping_site_latency: Vec, - ) { - self.update_data(|data| { - data.net = Arc::new(data.net.with_basic(address, qos, ping_site_latency)); - }); - } - /// Logs the contents of the provided packet to the debug output along with /// the header information and basic session information. /// @@ -462,11 +168,7 @@ impl Session { } // Get the authenticated player to include in the debug message - let auth = self - .data - .lock() - .as_ref() - .map(|data| data.player_assoc.player.clone()); + let auth = self.data.get_player(); let debug_data = DebugSessionData { action, diff --git a/src/session/models/user_sessions.rs b/src/session/models/user_sessions.rs index 416acdc..062e00b 100644 --- a/src/session/models/user_sessions.rs +++ b/src/session/models/user_sessions.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use crate::{ database::entities::Player, - session::NetData, + session::data::NetData, utils::{components::game_manager::GAME_TYPE, types::PlayerID}, }; use bitflags::bitflags; diff --git a/src/session/router.rs b/src/session/router.rs index 6e04d4b..6ec84f6 100644 --- a/src/session/router.rs +++ b/src/session/router.rs @@ -221,7 +221,7 @@ impl FromPacketRequest for GamePlayer { Self: 'a, { Box::pin(async move { - let data = &*req.state.data.lock(); + let data = &*req.state.data.read(); let data = data.as_ref().ok_or(GlobalError::AuthenticationRequired)?; Ok(GamePlayer::new( data.player_assoc.player.clone(), @@ -243,7 +243,7 @@ impl FromPacketRequest for SessionAuth { Self: 'a, { Box::pin(async move { - let data = &*req.state.data.lock(); + let data = &*req.state.data.read(); let data = data.as_ref().ok_or(GlobalError::AuthenticationRequired)?; let player = data.player_assoc.player.clone(); Ok(SessionAuth(player)) diff --git a/src/session/routes/auth.rs b/src/session/routes/auth.rs index 324579a..cf9de49 100644 --- a/src/session/routes/auth.rs +++ b/src/session/routes/auth.rs @@ -64,7 +64,7 @@ pub async fn handle_login( let player = sessions.add_session(player, Arc::downgrade(&session)); // Update the session stored player - let player = session.set_player(player); + let player = session.data.start_session(player); let session_token: String = sessions.create_token(player.id); @@ -100,7 +100,7 @@ pub async fn handle_silent_login( let player = sessions.add_session(player, Arc::downgrade(&session)); // Update the session stored player - let player = session.set_player(player); + let player = session.data.start_session(player); Ok(Blaze(AuthResponse { player, @@ -137,7 +137,7 @@ pub async fn handle_origin_login( let player = sessions.add_session(player, Arc::downgrade(&session)); // Update the session stored player - let player = session.set_player(player); + let player = session.data.start_session(player); let session_token: String = sessions.create_token(player.id); @@ -157,7 +157,7 @@ pub async fn handle_origin_login( /// Content: {} /// ``` pub async fn handle_logout(session: SessionLink) { - session.clear_data(); + session.data.clear(); } // Skip formatting these entitlement creations @@ -363,7 +363,7 @@ pub async fn handle_create_account( // Create the session association let player = sessions.add_session(player, Arc::downgrade(&session)); - let player = session.set_player(player); + let player = session.data.start_session(player); let session_token = sessions.create_token(player.id); diff --git a/src/session/routes/game_manager.rs b/src/session/routes/game_manager.rs index 0c78658..11daf4c 100644 --- a/src/session/routes/game_manager.rs +++ b/src/session/routes/game_manager.rs @@ -29,6 +29,7 @@ pub async fn handle_join_game( // Find the game ID for the target session let (game_id, game_ref) = other_session + .data .get_game() .ok_or(GameManagerError::InvalidGameId)?; @@ -514,6 +515,6 @@ pub async fn handle_cancel_matchmaking( SessionAuth(player): SessionAuth, Extension(game_manager): Extension>, ) { - session.clear_game(); + session.data.clear_game(); game_manager.remove_queue(player.id).await; } diff --git a/src/session/routes/user_sessions.rs b/src/session/routes/user_sessions.rs index 9719b34..54ddf74 100644 --- a/src/session/routes/user_sessions.rs +++ b/src/session/routes/user_sessions.rs @@ -10,7 +10,7 @@ use crate::{ NetworkAddress, }, router::{Blaze, Extension}, - LookupResponse, SessionLink, + SessionLink, }, }; use chrono::Utc; @@ -38,14 +38,14 @@ pub async fn handle_lookup_user( Extension(sessions): Extension>, ) -> ServerResult> { // Lookup the session - let session = sessions .lookup_session(req.player_id) .ok_or(UserSessionsError::UserNotFound)?; // Get the lookup response from the session let response = session - .get_lookup() + .data + .get_lookup_response() .ok_or(UserSessionsError::UserNotFound)?; Ok(Blaze(response)) @@ -85,7 +85,7 @@ pub async fn handle_resume_session( } let player = sessions.add_session(player, Arc::downgrade(&session)); - let player = session.set_player(player); + let player = session.data.start_session(player); Ok(Blaze(AuthResponse { player, @@ -169,7 +169,9 @@ pub async fn handle_update_network( Vec::new() }; - session.set_network_info(address, qos, ping_site_latency); + session + .data + .set_network_info(address, qos, ping_site_latency); } /// Handles updating the stored hardware flag with the client provided hardware flag @@ -185,5 +187,5 @@ pub async fn handle_update_hardware_flag( session: SessionLink, Blaze(UpdateHardwareFlagsRequest { hardware_flags }): Blaze, ) { - session.set_hardware_flags(hardware_flags); + session.data.set_hardware_flags(hardware_flags); } diff --git a/src/session/routes/util.rs b/src/session/routes/util.rs index 1578c47..e625906 100644 --- a/src/session/routes/util.rs +++ b/src/session/routes/util.rs @@ -100,7 +100,9 @@ pub async fn handle_post_auth( SessionAuth(player): SessionAuth, ) -> ServerResult> { // Subscribe to the session with itself - session.add_subscriber(player.id, session.notify_handle()); + session + .data + .add_subscriber(player.id, session.notify_handle()); Ok(Blaze(PostAuthResponse { telemetry: TelemetryServer, @@ -510,7 +512,7 @@ pub async fn handle_set_client_metrics( if !wan.is_unspecified() && !blaze_flags.contains(UpnpFlags::DOUBLE_NAT) { debug!("Using client Upnp WAN address override: {}", wan); - let network_info = session.network_info().unwrap_or_default(); + let network_info = session.data.network_info().unwrap_or_default(); let ping_site_latency = network_info.ping_site_latency.clone(); let qos = network_info.qos; let mut pair_addr = match &network_info.addr { @@ -523,7 +525,7 @@ pub async fn handle_set_client_metrics( pair_addr.external.addr = wan; // Update network info with new details - session.set_network_info( + session.data.set_network_info( NetworkAddress::AddressPair(pair_addr), qos, ping_site_latency,