From 8a203448ab920ac13bb8c1a99293dfb27d1236c5 Mon Sep 17 00:00:00 2001 From: Rug Date: Mon, 8 Apr 2024 17:25:22 -0700 Subject: [PATCH] added checking for registered keys --- MyceliumNetworkingForCW/MyceliumNetwork.cs | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/MyceliumNetworkingForCW/MyceliumNetwork.cs b/MyceliumNetworkingForCW/MyceliumNetwork.cs index fafc9f0..69f15eb 100644 --- a/MyceliumNetworkingForCW/MyceliumNetwork.cs +++ b/MyceliumNetworkingForCW/MyceliumNetwork.cs @@ -366,6 +366,12 @@ public static void SetLobbyData(string key, object value) return; } + if(!lobbyDataKeys.Contains(key)) + { + RugLogger.LogError($"Cannot access lobby data for unregistered key '{key}'."); + return; + } + if(!SteamMatchmaking.SetLobbyData(Lobby, key, value.ToString())) { RugLogger.LogError("Error setting lobby data."); @@ -385,6 +391,12 @@ public static bool HasLobbyData(string key) return false; } + if(!lobbyDataKeys.Contains(key)) + { + RugLogger.LogError($"Cannot access lobby data for unregistered key '{key}'."); + return false; + } + string value = SteamMatchmaking.GetLobbyData(Lobby, key.ToString()); return !string.IsNullOrEmpty(value); @@ -404,6 +416,12 @@ public static T GetLobbyData(string key) return default(T); } + if(!lobbyDataKeys.Contains(key)) + { + RugLogger.LogError($"Cannot access lobby data for unregistered key '{key}'."); + return default(T); + } + string value = SteamMatchmaking.GetLobbyData(Lobby, key.ToString()); try @@ -431,6 +449,12 @@ public static void SetPlayerData(string key, object value) return; } + if(!playerDataKeys.Contains(key)) + { + RugLogger.LogError($"Cannot access player data for unregistered key '{key}'."); + return; + } + SteamMatchmaking.SetLobbyMemberData(Lobby, key.ToString(), value.ToString()); } @@ -447,6 +471,12 @@ public static bool HasPlayerData(CSteamID player, string key) return false; } + if(!playerDataKeys.Contains(key)) + { + RugLogger.LogError($"Cannot access player data for unregistered key '{key}'."); + return false; + } + string value = SteamMatchmaking.GetLobbyMemberData(MyceliumNetwork.Lobby, player, key.ToString()); return !string.IsNullOrEmpty(value); @@ -465,6 +495,12 @@ public static T GetPlayerData(CSteamID player, string key) return default(T); } + if(!playerDataKeys.Contains(key)) + { + RugLogger.LogError($"Cannot access player data for unregistered key '{key}'."); + return default(T); + } + string value = SteamMatchmaking.GetLobbyMemberData(Lobby, player, key.ToString()); // If this key has been set