From 71048f104115c91bd8a5da38d6774af7d8df8d02 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Thu, 15 Feb 2018 13:47:21 +0000 Subject: [PATCH] Moved LobbyData to its own file --- .../Client/Lobby.LobbyData.cs | 112 ++++++++++++++++++ Facepunch.Steamworks/Client/Lobby.cs | 97 +-------------- 2 files changed, 113 insertions(+), 96 deletions(-) create mode 100644 Facepunch.Steamworks/Client/Lobby.LobbyData.cs diff --git a/Facepunch.Steamworks/Client/Lobby.LobbyData.cs b/Facepunch.Steamworks/Client/Lobby.LobbyData.cs new file mode 100644 index 0000000..63e4e84 --- /dev/null +++ b/Facepunch.Steamworks/Client/Lobby.LobbyData.cs @@ -0,0 +1,112 @@ +using System.Collections.Generic; + +namespace Facepunch.Steamworks +{ + public partial class Lobby + { + /// + /// Class to hold global lobby data. This is stuff like maps/modes/etc. Data set here can be filtered by LobbyList. + /// + public class LobbyData + { + internal Client client; + internal ulong lobby; + internal Dictionary data; + + public LobbyData( Client c, ulong l ) + { + client = c; + lobby = l; + data = new Dictionary(); + } + + /// + /// Get the lobby value for the specific key + /// + /// The key to find + /// The value at key + public string GetData( string k ) + { + if ( data.ContainsKey( k ) ) + { + return data[k]; + } + + return "ERROR: key not found"; + } + + /// + /// Get a list of all the data in the Lobby + /// + /// Dictionary of all the key/value pairs in the data + public Dictionary GetAllData() + { + Dictionary returnData = new Dictionary(); + foreach ( KeyValuePair item in data ) + { + returnData.Add( item.Key, item.Value ); + } + return returnData; + } + + /// + /// Set the value for specified Key. Note that the keys "joinable", "appid", "name", and "lobbytype" are reserved for internal library use. + /// + /// The key to set the value for + /// The value of the Key + /// True if data successfully set + public bool SetData( string k, string v ) + { + if ( data.ContainsKey( k ) ) + { + if ( data[k] == v ) { return true; } + if ( client.native.matchmaking.SetLobbyData( lobby, k, v ) ) + { + data[k] = v; + return true; + } + } + else + { + if ( client.native.matchmaking.SetLobbyData( lobby, k, v ) ) + { + data.Add( k, v ); + return true; + } + } + + return false; + } + + /// + /// Remove the key from the LobbyData. Note that the keys "joinable", "appid", "name", and "lobbytype" are reserved for internal library use. + /// + /// The key to remove + /// True if Key successfully removed + public bool RemoveData( string k ) + { + if ( data.ContainsKey( k ) ) + { + if ( client.native.matchmaking.DeleteLobbyData( lobby, k ) ) + { + data.Remove( k ); + return true; + } + } + + return false; + } + + } + + /*not implemented + + //set the game server of the lobby + client.native.matchmaking.GetLobbyGameServer; + client.native.matchmaking.SetLobbyGameServer; + + //used with game server stuff + SteamNative.LobbyGameCreated_t + */ + } +} diff --git a/Facepunch.Steamworks/Client/Lobby.cs b/Facepunch.Steamworks/Client/Lobby.cs index 1d013a4..11a83bb 100644 --- a/Facepunch.Steamworks/Client/Lobby.cs +++ b/Facepunch.Steamworks/Client/Lobby.cs @@ -19,7 +19,7 @@ namespace Facepunch.Steamworks } } } - public class Lobby : IDisposable + public partial class Lobby : IDisposable { //The type of lobby you are creating public enum Type : int @@ -127,101 +127,6 @@ namespace Facepunch.Steamworks /// public Action OnLobbyCreated; - /// - /// Class to hold global lobby data. This is stuff like maps/modes/etc. Data set here can be filtered by LobbyList. - /// - public class LobbyData - { - internal Client client; - internal ulong lobby; - internal Dictionary data; - - public LobbyData( Client c, ulong l ) - { - client = c; - lobby = l; - data = new Dictionary(); - } - - /// - /// Get the lobby value for the specific key - /// - /// The key to find - /// The value at key - public string GetData( string k ) - { - if ( data.ContainsKey( k ) ) - { - return data[k]; - } - - return "ERROR: key not found"; - } - - /// - /// Get a list of all the data in the Lobby - /// - /// Dictionary of all the key/value pairs in the data - public Dictionary GetAllData() - { - Dictionary returnData = new Dictionary(); - foreach ( KeyValuePair item in data ) - { - returnData.Add( item.Key, item.Value ); - } - return returnData; - } - - /// - /// Set the value for specified Key. Note that the keys "joinable", "appid", "name", and "lobbytype" are reserved for internal library use. - /// - /// The key to set the value for - /// The value of the Key - /// True if data successfully set - public bool SetData( string k, string v ) - { - if ( data.ContainsKey( k ) ) - { - if ( data[k] == v ) { return true; } - if ( client.native.matchmaking.SetLobbyData( lobby, k, v ) ) - { - data[k] = v; - return true; - } - } - else - { - if ( client.native.matchmaking.SetLobbyData( lobby, k, v ) ) - { - data.Add( k, v ); - return true; - } - } - - return false; - } - - /// - /// Remove the key from the LobbyData. Note that the keys "joinable", "appid", "name", and "lobbytype" are reserved for internal library use. - /// - /// The key to remove - /// True if Key successfully removed - public bool RemoveData( string k ) - { - if ( data.ContainsKey( k ) ) - { - if ( client.native.matchmaking.DeleteLobbyData( lobby, k ) ) - { - data.Remove( k ); - return true; - } - } - - return false; - } - - } - /// /// Sets user data for the Lobby. Things like Character, Skin, Ready, etc. Can only set your own member data ///