From 23433811ad3e040b10add6367ce767924877176b Mon Sep 17 00:00:00 2001 From: ymo4 <41833771+ymo-4@users.noreply.github.com> Date: Sun, 30 Jun 2024 02:18:11 +0300 Subject: [PATCH 1/3] add set_key_value --- src/server.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/server.rs b/src/server.rs index 5fe2a08..67f2493 100644 --- a/src/server.rs +++ b/src/server.rs @@ -353,6 +353,20 @@ impl Server { } } + pub fn set_key_value(&self, key: String, value: String) -> Result<(), std::ffi::NulError> { + let key = CString::new(key)?; + let value = CString::new(value)?; + + unsafe { + Ok( + sys::SteamAPI_ISteamGameServer_SetKeyValue( + self.server, + key.as_ptr(), + value.as_ptr() + )) + } + } + /// Returns an accessor to the steam UGC interface (steam workshop) /// /// **For this to work properly, you need to call `UGC::init_for_game_server()`!** From cb37916625e6e970fe001cf669d9e44d0b29b9c4 Mon Sep 17 00:00:00 2001 From: ymo4 <41833771+ymo-4@users.noreply.github.com> Date: Thu, 18 Jul 2024 17:15:31 +0300 Subject: [PATCH 2/3] set_key_value arguments String -> &str, use unwrap as in other methods --- src/server.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/server.rs b/src/server.rs index 67f2493..56aa31d 100644 --- a/src/server.rs +++ b/src/server.rs @@ -353,17 +353,13 @@ impl Server { } } - pub fn set_key_value(&self, key: String, value: String) -> Result<(), std::ffi::NulError> { - let key = CString::new(key)?; - let value = CString::new(value)?; + /// Add/update a rules key/value pair. + pub fn set_key_value(&self, key: &str, value: &str) { + let key = CString::new(key).unwrap(); + let value = CString::new(value).unwrap(); unsafe { - Ok( - sys::SteamAPI_ISteamGameServer_SetKeyValue( - self.server, - key.as_ptr(), - value.as_ptr() - )) + sys::SteamAPI_ISteamGameServer_SetKeyValue(self.server, key.as_ptr(), value.as_ptr()); } } From e2cb548032cbe91dd57542e7374dad69acab7e4e Mon Sep 17 00:00:00 2001 From: ymo4 <41833771+ymo-4@users.noreply.github.com> Date: Thu, 18 Jul 2024 17:21:17 +0300 Subject: [PATCH 3/3] add clear_all_key_values --- src/server.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/server.rs b/src/server.rs index 56aa31d..778d569 100644 --- a/src/server.rs +++ b/src/server.rs @@ -363,6 +363,13 @@ impl Server { } } + /// Clears the whole list of key/values that are sent in rules queries. + pub fn clear_all_key_values(&self) { + unsafe { + sys::SteamAPI_ISteamGameServer_ClearAllKeyValues(self.server); + } + } + /// Returns an accessor to the steam UGC interface (steam workshop) /// /// **For this to work properly, you need to call `UGC::init_for_game_server()`!**