From c40037784ef91794e35be6498617954961ef1aae Mon Sep 17 00:00:00 2001 From: Kyle Kukshtel Date: Mon, 31 Jul 2017 09:28:09 -0700 Subject: [PATCH] Caches created LobbyType to be assigned as a LobbyData to be referenced by other members in the lobby. Because there is no GetLobbyType, provides a layer in which all users can get a LobbyType from LobbyData. --- Facepunch.Steamworks/Client/Lobby.cs | 36 +++++++++++++++++++++------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/Facepunch.Steamworks/Client/Lobby.cs b/Facepunch.Steamworks/Client/Lobby.cs index 0db6f79..4cc1645 100644 --- a/Facepunch.Steamworks/Client/Lobby.cs +++ b/Facepunch.Steamworks/Client/Lobby.cs @@ -29,7 +29,7 @@ public enum Type : int FriendsOnly = SteamNative.LobbyType.FriendsOnly, Public = SteamNative.LobbyType.Public, Invisible = SteamNative.LobbyType.Invisible, - None + Error //happens if you try to get this when you aren't in a valid lobby } internal Client client; @@ -37,7 +37,7 @@ public enum Type : int public Lobby(Client c) { client = c; - SteamNative.LobbyDataUpdate_t.RegisterCallback(client, OnLobbyDataUpdated); + SteamNative.LobbyDataUpdate_t.RegisterCallback(client, OnLobbyDataUpdatedAPI); } /// @@ -84,9 +84,11 @@ void OnLobbyJoinedAPI(LobbyEnter_t callback, bool error) public void Create(Lobby.Type lobbyType, int maxMembers) { client.native.matchmaking.CreateLobby((SteamNative.LobbyType)lobbyType, maxMembers, OnLobbyCreatedAPI); - LobbyType = lobbyType; + createdLobbyType = lobbyType; } + internal Type createdLobbyType; + internal void OnLobbyCreatedAPI(LobbyCreated_t callback, bool error) { //from SpaceWarClient.cpp 793 @@ -102,7 +104,9 @@ internal void OnLobbyCreatedAPI(LobbyCreated_t callback, bool error) CurrentLobbyData = new LobbyData(client, CurrentLobby); Name = client.Username + "'s Lobby"; CurrentLobbyData.SetData("appid", client.AppId.ToString()); + LobbyType = createdLobbyType; CurrentLobbyData.SetData("lobbytype", LobbyType.ToString()); + Joinable = true; if (OnLobbyCreated != null) { OnLobbyCreated(true); } } @@ -115,7 +119,7 @@ public class LobbyData { internal Client client; internal ulong lobby; - internal Dictionary data; + internal Dictionary data; public LobbyData(Client c, ulong l) { @@ -134,6 +138,16 @@ public string GetData(string k) return "ERROR: key not found"; } + public List> GetAllData() + { + List> returnData = new List>(); + foreach(KeyValuePair item in data) + { + returnData.Add(new KeyValuePair(item.Key, item.Value)); + } + return returnData; + } + public bool SetData(string k, string v) { if (data.ContainsKey(k)) @@ -173,7 +187,7 @@ public bool RemoveData(string k) } - internal void OnLobbyDataUpdated(LobbyDataUpdate_t callback, bool error) + internal void OnLobbyDataUpdatedAPI(LobbyDataUpdate_t callback, bool error) { if(error) { return; } if(callback.SteamIDLobby == CurrentLobby) //actual lobby data was updated by owner @@ -198,13 +212,19 @@ internal void UpdateLobbyData() CurrentLobbyData.SetData(key, value); } } + + if(OnLobbyDataUpdated != null) { OnLobbyDataUpdated(); } } + //Called when the lobby data itself has been updated. This callback is slower than the actual setting/getting of LobbyData, but it ensures safety. + public Action OnLobbyDataUpdated; + + public Type LobbyType { get { - if (!IsValid) { return Type.None; } //if we're currently in a valid server + if (!IsValid) { return Type.Error; } //if we're currently in a valid server //we know that we've set the lobby type via the lobbydata in the creation function //ps this is important because steam doesn't have an easy way to get lobby type (why idk) @@ -220,12 +240,12 @@ public Type LobbyType case "Public": return Type.Public; default: - return Type.None; + return Type.Error; } } set { - if(!IsValid) { return; } + if(!IsValid) { return; } if(client.native.matchmaking.SetLobbyType(CurrentLobby, (SteamNative.LobbyType)value)) { CurrentLobbyData.SetData("lobbytype", value.ToString());