Skip to content

Commit

Permalink
Don't use built-in function to get players by steam id
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlOfDuty committed Oct 26, 2024
1 parent d143d1d commit 6a333b9
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion SCPDiscordPlugin/BotCommands/BanCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static void Execute(Interface.BanCommand command)

// Send player banned event if player is online, and add ipban
bool offlineBan = true;
if (Player.TryGet(command.SteamID.EndsWith("@steam") ? command.SteamID : command.SteamID + "@steam", out Player player))
if (Utilities.TryGetPlayer(command.SteamID, out Player player))
{
offlineBan = false;
banVars.AddPlayerVariables(player, "player");
Expand Down
2 changes: 1 addition & 1 deletion SCPDiscordPlugin/BotCommands/KickCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static void Execute(Interface.KickCommand command)
}

//Get player name for feedback message
if (!Player.TryGet(command.SteamID, out Player player))
if (!Utilities.TryGetPlayer(command.SteamID, out Player player))
{
Dictionary<string, string> vars = new Dictionary<string, string>
{
Expand Down
4 changes: 2 additions & 2 deletions SCPDiscordPlugin/BotCommands/MuteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private static void MutePlayer(Interface.MuteCommand command, DateTime endTime,
string userID = command.SteamID.EndsWith("@steam") ? command.SteamID : command.SteamID + "@steam";
string playerName = "";

if (Player.TryGet(userID, out Player player))
if (Utilities.TryGetPlayer(userID, out Player player))
{
MuteSystem.ignoreUserID = userID;
if (!EventManager.ExecuteEvent(new PlayerMutedEvent(player.ReferenceHub, Server.Instance.ReferenceHub, false)))
Expand Down Expand Up @@ -171,7 +171,7 @@ private static void UnmutePlayer(Interface.MuteCommand command)
string userID = command.SteamID.EndsWith("@steam") ? command.SteamID : command.SteamID + "@steam";
string playerName = "";

if (Player.TryGet(userID, out Player player))
if (Utilities.TryGetPlayer(userID, out Player player))
{
MuteSystem.ignoreUserID = userID;
if (!EventManager.ExecuteEvent(new PlayerUnmutedEvent(player.ReferenceHub, Server.Instance.ReferenceHub, false)))
Expand Down
2 changes: 1 addition & 1 deletion SCPDiscordPlugin/BotCommands/PlayerInfoCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static void Execute(Interface.PlayerInfoCommand command)
}
}

if (Player.TryGet(command.SteamID, out Player player))
if (Utilities.TryGetPlayer(command.SteamID, out Player player))
{
Dictionary<string, string> vars = new Dictionary<string, string>
{
Expand Down
2 changes: 1 addition & 1 deletion SCPDiscordPlugin/MuteSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private static async Task SchedulePlayerCheck(DateTime targetTime, ulong steamID
await Task.Delay(remaining);
}

if (Player.TryGet(userId, out Player player))
if (Utilities.TryGetPlayer(userId, out Player player))
{
CheckMuteStatus(player);
}
Expand Down
15 changes: 15 additions & 0 deletions SCPDiscordPlugin/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ public static string TicksToCompoundTime(long ticks)
return SecondsToCompoundTime(ticks / TimeSpan.TicksPerSecond);
}

public static bool TryGetPlayer(string userID, out Player pl)
{
foreach (Player player in Player.GetPlayers<Player>())
{
if (userID.Contains(player.GetParsedUserID()))
{
pl = player;
return true;
}
}

pl = null;
return false;
}

public static bool TryGetPlayerName(string userID, out string name)
{
foreach (Player player in Player.GetPlayers<Player>())
Expand Down

0 comments on commit 6a333b9

Please sign in to comment.