aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFlaise <[email protected]>2019-08-11 17:03:24 -0500
committerMatthew Collins <[email protected]>2019-08-14 15:47:12 +0100
commitf8818e261699eb58b71ab8b9dcc9672a9bd5054e (patch)
tree85d4ede2726f64fd44f407994f0fbac3073dc0c5 /src
parentImplemented P2PSessionConnectFail callback and removed a result handler's Syn... (diff)
downloadsteamworks-rs-f8818e261699eb58b71ab8b9dcc9672a9bd5054e.tar.xz
steamworks-rs-f8818e261699eb58b71ab8b9dcc9672a9bd5054e.zip
Added more bindings to SteamGameServer API
Diffstat (limited to 'src')
-rw-r--r--src/callback.rs4
-rw-r--r--src/networking.rs3
-rw-r--r--src/server.rs62
3 files changed, 57 insertions, 12 deletions
diff --git a/src/callback.rs b/src/callback.rs
index 12b4542..f88946b 100644
--- a/src/callback.rs
+++ b/src/callback.rs
@@ -15,7 +15,7 @@ pub unsafe trait Callback {
unsafe fn from_raw(raw: *mut c_void) -> Self;
}
-/// A handled that can be used to remove a callback
+/// A handle that can be used to remove a callback
/// at a later point.
///
/// Removes the callback when dropped
@@ -82,7 +82,7 @@ pub(crate) unsafe fn register_callback<C, F, Manager>(inner: &Arc<Inner<Manager>
let func: Box<F> = Box::from_raw(userdata as _);
let res = catch_unwind(AssertUnwindSafe(move ||
- // Its possible for callback to panic whilst being dropped
+ // It's possible for callback to panic whilst being dropped
drop(func)
));
if let Err(err) = res {
diff --git a/src/networking.rs b/src/networking.rs
index ac2230c..82fe1e7 100644
--- a/src/networking.rs
+++ b/src/networking.rs
@@ -110,7 +110,8 @@ unsafe impl Callback for P2PSessionRequest {
}
}
-#[derive(Clone, Debug, Serialize, Deserialize)]
+#[derive(Clone, Debug)]
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct P2PSessionConnectFail {
pub remote: SteamId,
pub error: u8,
diff --git a/src/server.rs b/src/server.rs
index 3d957ee..1f9a246 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -183,25 +183,26 @@ impl Server {
}
}
- /// Sets the game product identifier.
+ /// Sets the game product identifier. This is currently used by the master server for version
+ /// checking purposes. Converting the games app ID to a string for this is recommended.
///
- /// Used by the master server for version checking. Required
- /// field but it will go away eventually.
+ /// This is required for all game servers and can only be set before calling
+ /// log_on() or log_on_anonymous().
pub fn set_product(&self, product: &str) {
+ let product = CString::new(product).unwrap();
unsafe {
- let product = CString::new(product).unwrap();
sys::SteamAPI_ISteamGameServer_SetProduct(self.server, product.as_ptr() as *const _);
}
}
- /// Sets the game description.
+ /// Sets the game description. Setting this to the full name of your game is recommended.
///
- /// Displayed in the steam server browser (for now). Required
- /// field but it will go away eventually.
+ /// This is required for all game servers and can only be set before calling
+ /// log_on() or log_on_anonymous().
pub fn set_game_description(&self, desc: &str) {
+ let desc = CString::new(desc).unwrap();
unsafe {
- let desc = CString::new(desc).unwrap();
- sys::SteamAPI_ISteamGameServer_SetGameDescription(self.server, desc.as_ptr() as *const _);
+ sys::SteamAPI_ISteamGameServer_SetGameDescription(self.server, desc.as_ptr());
}
}
@@ -219,6 +220,49 @@ impl Server {
}
}
+ /// If active, updates the master server with this server's presence so players can find it via
+ /// the steam matchmaking/server browser interfaces.
+ pub fn enable_heartbeats(&self, active: bool) {
+ unsafe {
+ sys::SteamAPI_ISteamGameServer_EnableHeartbeats(self.server, active);
+ }
+ }
+
+ /// If your game is a "mod," pass the string that identifies it. The default is an empty
+ /// string, meaning this application is the original game, not a mod.
+ pub fn set_mod_dir(&self, mod_dir: &str) {
+ let mod_dir = CString::new(mod_dir).unwrap();
+ unsafe {
+ sys::SteamAPI_ISteamGameServer_SetModDir(self.server, mod_dir.as_ptr());
+ }
+ }
+
+ /// Set name of map to report in the server browser
+ pub fn set_map_name(&self, map_name: &str) {
+ let map_name = CString::new(map_name).unwrap();
+ unsafe {
+ sys::SteamAPI_ISteamGameServer_SetMapName(self.server, map_name.as_ptr());
+ }
+ }
+
+ /// Set the name of server as it will appear in the server browser
+ pub fn set_server_name(&self, server_name: &str) {
+ let server_name = CString::new(server_name).unwrap();
+ unsafe {
+ sys::SteamAPI_ISteamGameServer_SetMapName(self.server, server_name.as_ptr());
+ }
+ }
+
+
+ /// Sets the maximum number of players allowed on the server at once.
+ ///
+ /// This value may be changed at any time.
+ pub fn set_max_players(&self, count: i32) {
+ unsafe {
+ sys::SteamAPI_ISteamGameServer_SetMaxPlayerCount(self.server, count);
+ }
+ }
+
/* TODO: Buggy currently?
/// Returns an accessor to the steam apps interface
pub fn apps(&self) -> Apps<ServerManager> {