diff --git a/lightyear/src/connection/client.rs b/lightyear/src/connection/client.rs index ab5c9fa80..7a68cf4ab 100644 --- a/lightyear/src/connection/client.rs +++ b/lightyear/src/connection/client.rs @@ -165,7 +165,7 @@ impl NetConfig { } => { let client = super::steam::client::Client::new( steamworks_client.unwrap_or_else(|| { - Arc::new(RwLock::new(SteamworksClient::new(config.app_id))) + Arc::new(RwLock::new(SteamworksClient::new_with_app_id(config.app_id))) }), config, conditioner, diff --git a/lightyear/src/connection/server.rs b/lightyear/src/connection/server.rs index 83e679a69..ca51ed3f5 100644 --- a/lightyear/src/connection/server.rs +++ b/lightyear/src/connection/server.rs @@ -158,7 +158,7 @@ impl NetConfig { // TODO: handle errors let server = super::steam::server::Server::new( steamworks_client.unwrap_or_else(|| { - Arc::new(RwLock::new(SteamworksClient::new(config.app_id))) + Arc::new(RwLock::new(SteamworksClient::new_with_app_id(config.app_id))) }), config, conditioner, diff --git a/lightyear/src/connection/steam/steamworks_client.rs b/lightyear/src/connection/steam/steamworks_client.rs index c2d518737..6e3b5c301 100644 --- a/lightyear/src/connection/steam/steamworks_client.rs +++ b/lightyear/src/connection/steam/steamworks_client.rs @@ -19,9 +19,9 @@ impl std::fmt::Debug for SteamworksClient { } impl SteamworksClient { - /// Creates and initializes the Steamworks client. This must only be called - /// once per application run. - pub fn new(app_id: u32) -> Self { + /// Creates and initializes the Steamworks client with the specified AppId. + /// This must only be called once per application run. + pub fn new_with_app_id(app_id: u32) -> Self { let (client, single) = steamworks::Client::::init_app(app_id).unwrap(); Self { @@ -31,6 +31,20 @@ impl SteamworksClient { } } + /// Creates and initializes the Steamworks client. If the game isn’t being run through steam + /// this can be provided by placing a steam_appid.txt with the ID inside in the current + /// working directory. + /// This must only be called once per application run. + pub fn new() -> Self { + let (client, single) = steamworks::Client::::init().unwrap(); + + Self { + app_id: client.utils().app_id().0, + client, + single: SyncCell::new(single), + } + } + /// Gets the thread-safe Steamworks client. Most Steamworks API calls live /// under this client. pub fn get_client(&self) -> steamworks::Client {