Skip to content

Commit

Permalink
added checking for registered keys
Browse files Browse the repository at this point in the history
  • Loading branch information
RugbugRedfern committed Apr 9, 2024
1 parent 7fcda83 commit 8a20344
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions MyceliumNetworkingForCW/MyceliumNetwork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand All @@ -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);
Expand All @@ -404,6 +416,12 @@ public static T GetLobbyData<T>(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
Expand Down Expand Up @@ -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());
}

Expand All @@ -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);
Expand All @@ -465,6 +495,12 @@ public static T GetPlayerData<T>(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
Expand Down

0 comments on commit 8a20344

Please sign in to comment.