From 2ee5fa4a5df15bbd314ef431693b805a527b4d4b Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Thu, 15 Feb 2018 13:59:36 +0000 Subject: [PATCH] Lobby GameServer information --- Facepunch.Steamworks/Client/Lobby.cs | 81 +++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/Facepunch.Steamworks/Client/Lobby.cs b/Facepunch.Steamworks/Client/Lobby.cs index 11a83bb..bcf8afe 100644 --- a/Facepunch.Steamworks/Client/Lobby.cs +++ b/Facepunch.Steamworks/Client/Lobby.cs @@ -26,7 +26,7 @@ namespace Facepunch.Steamworks { Private = SteamNative.LobbyType.Private, FriendsOnly = SteamNative.LobbyType.FriendsOnly, - Public = SteamNative.LobbyType.Public, + Public = SteamNative.LobbyType.Public, Invisible = SteamNative.LobbyType.Invisible, Error //happens if you try to get this when you aren't in a valid lobby } @@ -323,6 +323,17 @@ namespace Facepunch.Steamworks } } + /// + /// returns true if we're the current owner + /// + public bool IsOwner + { + get + { + return Owner == client.SteamId; + } + } + /// /// The Owner of the current lobby. Returns 0 if you are not in a valid lobby. /// @@ -491,6 +502,74 @@ namespace Facepunch.Steamworks if ( OnLobbyMemberDataUpdated != null ) { OnLobbyMemberDataUpdated( callback.SteamID ); } } + /// + /// Sets the game server associated with the lobby. + /// This can only be set by the owner of the lobby. + /// Either the IP/Port or the Steam ID of the game server must be valid, depending on how you want the clients to be able to connect. + /// + public bool SetGameServer( System.Net.IPAddress ip, int port, ulong serverSteamId = 0 ) + { + if ( !IsValid || !IsOwner ) return false; + + var ipint = System.Net.IPAddress.NetworkToHostOrder( ip.Address ); + client.native.matchmaking.SetLobbyGameServer( CurrentLobby, (uint)ipint, (ushort)port, serverSteamId ); + return true; + } + + /// + /// Gets the details of a game server set in a lobby. + /// + public System.Net.IPAddress GameServerIp + { + get + { + uint ip; + ushort port; + CSteamID steamid; + + if ( !client.native.matchmaking.GetLobbyGameServer( CurrentLobby, out ip, out port, out steamid ) || ip == 0 ) + return null; + + return new System.Net.IPAddress( System.Net.IPAddress.HostToNetworkOrder( ip ) ); + } + } + + /// + /// Gets the details of a game server set in a lobby. + /// + public int GameServerPort + { + get + { + uint ip; + ushort port; + CSteamID steamid; + + if ( !client.native.matchmaking.GetLobbyGameServer( CurrentLobby, out ip, out port, out steamid ) ) + return 0; + + return (int)port; + } + } + + /// + /// Gets the details of a game server set in a lobby. + /// + public ulong GameServerSteamId + { + get + { + uint ip; + ushort port; + CSteamID steamid; + + if ( !client.native.matchmaking.GetLobbyGameServer( CurrentLobby, out ip, out port, out steamid ) ) + return 0; + + return steamid; + } + } + /*not implemented //set the game server of the lobby