From 9bb5283e09b40684fbb7feb73acf367db32c5032 Mon Sep 17 00:00:00 2001 From: Evan Date: Sat, 16 May 2020 01:31:07 +0200 Subject: [PATCH] Updated to SMod 3.7.0-A (Ish) --- AdminToolbox/AdminToolbox/API/ATWeb.cs | 2 +- .../AdminToolbox/API/ExtentionMethods.cs | 20 +- .../AdminToolbox/API/GetPlayerFromString.cs | 2 +- AdminToolbox/AdminToolbox/API/JailHandler.cs | 24 +-- .../AdminToolbox/API/PlayerSettings.cs | 15 +- .../AdminToolbox/API/SetPlayerVariables.cs | 22 +-- AdminToolbox/AdminToolbox/API/Utility.cs | 20 +- AdminToolbox/AdminToolbox/AdminToolbox.cs | 36 ++-- AdminToolbox/AdminToolbox/AdminToolbox.csproj | 15 +- .../Commands/Facility/JailCommand.cs | 4 +- .../Commands/Facility/SpeakCommand.cs | 2 +- .../Commands/Player/ATBanCommand.cs | 12 +- .../Commands/Player/BreakDoorsCommand.cs | 10 +- .../Commands/Player/EmptyCommand.cs | 22 +-- .../Commands/Player/GodModeCommand.cs | 8 +- .../Commands/Player/GrenadeModeCommand.cs | 4 +- .../Commands/Player/InfiniteItemCommand.cs | 6 +- .../Commands/Player/InstantKillCommand.cs | 20 +- .../Commands/Player/KeepSettingsCommand.cs | 8 +- .../Commands/Player/KillCommand.cs | 6 +- .../Commands/Player/LockDoorsCommand.cs | 4 +- .../Commands/Player/LockdownCommand.cs | 8 +- .../Commands/Player/NoDmgCommand.cs | 8 +- .../Commands/Player/PlayerCommand.cs | 12 +- .../Commands/Player/RoleCommand.cs | 8 +- .../Commands/Player/SpectatorCommand.cs | 8 +- .../Commands/Player/TutorialCommand.cs | 6 +- .../Commands/Server/PlayerListCommand.cs | 2 +- .../AdminToolbox/Events/MyMiscEvents.cs | 67 +++---- .../AdminToolbox/Events/PlayerDamageEvent.cs | 16 +- .../AdminToolbox/Managers/ATFileManager.cs | 173 ++++++++++++------ .../AdminToolbox/Managers/LogManager.cs | 8 +- .../AdminToolbox/Managers/WarpManager.cs | 9 +- 33 files changed, 322 insertions(+), 265 deletions(-) diff --git a/AdminToolbox/AdminToolbox/API/ATWeb.cs b/AdminToolbox/AdminToolbox/API/ATWeb.cs index 5fd7a2d..2bb4e63 100644 --- a/AdminToolbox/AdminToolbox/API/ATWeb.cs +++ b/AdminToolbox/AdminToolbox/API/ATWeb.cs @@ -12,7 +12,7 @@ namespace AdminToolbox.API /// public static class ATWeb { - private static AdminToolbox Plugin => AdminToolbox.plugin; + private static AdminToolbox Plugin => AdminToolbox.singleton; private static void Debug(string str) => Plugin.Debug("[ATWeb]: " + str); diff --git a/AdminToolbox/AdminToolbox/API/ExtentionMethods.cs b/AdminToolbox/AdminToolbox/API/ExtentionMethods.cs index 336219b..8f79820 100644 --- a/AdminToolbox/AdminToolbox/API/ExtentionMethods.cs +++ b/AdminToolbox/AdminToolbox/API/ExtentionMethods.cs @@ -13,10 +13,10 @@ public static class ExtentionMethods { private static Server Server => PluginManager.Manager.Server; - private static AdminToolbox Plugin => AdminToolbox.plugin; + private static AdminToolbox Plugin => AdminToolbox.singleton; internal static bool GetIsJailed(this Player player) - => AdminToolbox.ATPlayerDict.ContainsKey(player.SteamId) && AdminToolbox.ATPlayerDict[player.SteamId].isJailed; + => AdminToolbox.ATPlayerDict.ContainsKey(player.UserId) && AdminToolbox.ATPlayerDict[player.UserId].isJailed; public static bool IsInsideJail(this Player player) { @@ -30,12 +30,12 @@ public static bool IsInsideJail(this Player player) return x > 7 || y > 5 || z > 7 ? false : true; } - internal static string[] SteamIDsToArray(this List players) + internal static string[] UserIdsToArray(this List players) { string[] newArray = new string[players.Count]; for (int i = 0; i < players.Count; i++) { - newArray[i] = players[i].SteamId; + newArray[i] = players[i].UserId; } return newArray; } @@ -49,8 +49,8 @@ internal static Player[] JailedPlayers(this Player[] players) return players.Length > 0 && Server.Round.Duration > 0 ? players - .Where(p => p.TeamRole.Role != Role.UNASSIGNED - && p.TeamRole.Role != Role.SPECTATOR + .Where(p => p.TeamRole.Role != Smod2.API.RoleType.UNASSIGNED + && p.TeamRole.Role != Smod2.API.RoleType.SPECTATOR && !p.OverwatchMode && p.GetIsJailed()).ToArray() : (new Player[0]); @@ -70,7 +70,7 @@ private static bool ContainsPlayer(this string[] array, Player player) { if (string.IsNullOrEmpty(str)) continue; - if (str == player.SteamId) + if (str == player.UserId) return true; else if (player.GetUserGroup().Name != null && str == player.GetUserGroup().Name.Trim().ToUpper()) return true; @@ -87,7 +87,7 @@ private static bool ContainsPlayer(this string[] array, Player player) } } - internal static bool IsPlayer(this ICommandSender sender) => sender is Player p && !string.IsNullOrEmpty(p.SteamId); + internal static bool IsPlayer(this ICommandSender sender) => sender is Player p && !string.IsNullOrEmpty(p.UserId); internal static bool IsPermitted(this ICommandSender sender, string[] commandKey) => sender.IsPermitted(commandKey, false, out string[] reply); @@ -129,7 +129,7 @@ internal static bool IsPermitted(this ICommandSender sender, string[] commandKey } internal static bool ContainsPlayer(this Dictionary dict, Player player) - => AdminToolbox.ATPlayerDict?.ContainsKey(player?.SteamId) ?? false; + => AdminToolbox.ATPlayerDict?.ContainsKey(player?.UserId) ?? false; internal static void ResetPlayerBools(this Dictionary.KeyCollection dict) { @@ -163,7 +163,7 @@ internal static bool TryGetVector(this Dictionary dict, strin /// internal static void Cleanup(this Dictionary dict) { - string[] currentPlayers = PluginManager.Manager.Server.GetPlayers().SteamIDsToArray(); + string[] currentPlayers = PluginManager.Manager.Server.GetPlayers().UserIdsToArray(); Dictionary newDict = new Dictionary(dict); if (newDict.Count > 0) { diff --git a/AdminToolbox/AdminToolbox/API/GetPlayerFromString.cs b/AdminToolbox/AdminToolbox/API/GetPlayerFromString.cs index 9c60984..c9e5b0d 100644 --- a/AdminToolbox/AdminToolbox/API/GetPlayerFromString.cs +++ b/AdminToolbox/AdminToolbox/API/GetPlayerFromString.cs @@ -26,7 +26,7 @@ public static Player GetPlayer(string args) else if (long.TryParse(args, out long sID)) { foreach (Player pl in Server.GetPlayers()) - if (pl.SteamId == sID.ToString()) + if (pl.UserId == sID.ToString()) return pl; } else diff --git a/AdminToolbox/AdminToolbox/API/JailHandler.cs b/AdminToolbox/AdminToolbox/API/JailHandler.cs index e716a1b..a739488 100644 --- a/AdminToolbox/AdminToolbox/API/JailHandler.cs +++ b/AdminToolbox/AdminToolbox/API/JailHandler.cs @@ -18,7 +18,7 @@ public class JailHandler private static Server Server => PluginManager.Manager.Server; - private static void Debug(string message) => AdminToolbox.plugin.Debug("[JailHandler]: " + message); + private static void Debug(string message) => AdminToolbox.singleton.Debug("[JailHandler]: " + message); /// /// Checks the players marked as "Jailed" to see if they are at where they're supposed to be @@ -29,9 +29,9 @@ internal static void CheckJailedPlayers() Player[] jailedPlayers = Server.GetPlayers().ToArray().JailedPlayers(); if (jailedPlayers.Length > 0) foreach (Player pl in jailedPlayers) - if (AdminToolbox.ATPlayerDict.ContainsKey(pl.SteamId)) + if (AdminToolbox.ATPlayerDict.ContainsKey(pl.UserId)) if (!pl.IsInsideJail()) SendToJail(pl); - else if (AdminToolbox.ATPlayerDict[pl.SteamId].JailedToTime <= DateTime.Now) ReturnFromJail(pl); + else if (AdminToolbox.ATPlayerDict[pl.UserId].JailedToTime <= DateTime.Now) ReturnFromJail(pl); } /// @@ -43,11 +43,11 @@ internal static void CheckJailedPlayers() /// /// the to send into jail /// the time to jail the player. Null sets the time to remaining time, or if thats null, one year - public static bool SendToJail(Player player, DateTime? jailedToTime) + public static bool SendToJail(Smod2.API.Player player, DateTime? jailedToTime) { - if (player == null || player.TeamRole.Role == Role.SPECTATOR || player.OverwatchMode) return false; + if (player == null || player.TeamRole.Role == Smod2.API.RoleType.SPECTATOR || player.OverwatchMode) return false; Debug($"Attempting to jail {player.Name}"); - if (AdminToolbox.ATPlayerDict.TryGetValue(player.SteamId, out PlayerSettings psetting)) + if (AdminToolbox.ATPlayerDict.TryGetValue(player.UserId, out PlayerSettings psetting)) { if (!jailedToTime.HasValue || jailedToTime < DateTime.Now) Debug($"Jail time for \"{player.Name}\" not specified, jailing for a year."); @@ -65,7 +65,7 @@ public static bool SendToJail(Player player, DateTime? jailedToTime) } //Changes role to Tutorial, teleports to jail, removes inv. Debug($"Variables stored, sending \"{player.Name}\" to jail"); - player.ChangeRole(Role.TUTORIAL, true, false); + player.ChangeRole(Smod2.API.RoleType.TUTORIAL, true, false); player.Teleport(JailPos, true); foreach (SMItem item in player.GetInventory()) item.Remove(); @@ -86,13 +86,13 @@ public static bool SendToJail(Player player, DateTime? jailedToTime) /// the player to return public static bool ReturnFromJail(Player player) { - if (player == null || string.IsNullOrEmpty(player.SteamId.Trim())) + if (player == null || string.IsNullOrEmpty(player.UserId.Trim())) { - Debug("Return: Player or SteamID null/empty"); + Debug("Return: Player or UserId null/empty"); return false; } Debug($"Attempting to unjail \"{player.Name}\""); - if (AdminToolbox.ATPlayerDict.TryGetValue(player.SteamId, out PlayerSettings psetting)) + if (AdminToolbox.ATPlayerDict.TryGetValue(player.UserId, out PlayerSettings psetting)) { psetting.isJailed = false; psetting.JailedToTime = DateTime.Now; @@ -109,12 +109,12 @@ public static bool ReturnFromJail(Player player) player.SetAmmo(AmmoType.DROPPED_5, psetting.prevAmmo5); player.SetAmmo(AmmoType.DROPPED_7, psetting.prevAmmo7); player.SetAmmo(AmmoType.DROPPED_9, psetting.prevAmmo9); - AdminToolbox.ATPlayerDict[player.SteamId].playerPrevInv = null; + AdminToolbox.ATPlayerDict[player.UserId].playerPrevInv = null; return true; } else { - AdminToolbox.plugin.Info("Could not return player from jail! Player not in PlayerDict!"); + AdminToolbox.singleton.Info("Could not return player from jail! Player not in PlayerDict!"); return false; } } diff --git a/AdminToolbox/AdminToolbox/API/PlayerSettings.cs b/AdminToolbox/AdminToolbox/API/PlayerSettings.cs index d6bab8c..5ce39c6 100644 --- a/AdminToolbox/AdminToolbox/API/PlayerSettings.cs +++ b/AdminToolbox/AdminToolbox/API/PlayerSettings.cs @@ -8,7 +8,7 @@ namespace AdminToolbox.API public class PlayerInfo { public string LastNickname { get; internal set; } = "Unknown"; - public string SteamID { get; internal set; } = "00000000000000000"; + public string UserId { get; internal set; } = "00000000000000000"; public bool DNT { get; internal set; } = false; public string FirstJoin { get; set; } = ""; @@ -34,7 +34,7 @@ public class PlayerStats public PlayerStats() { } } /// - /// is 's settings + /// is 's settings /// Used in /// public class PlayerSettings @@ -54,22 +54,23 @@ public bool public PlayerStats PlayerStats = new PlayerStats(); public PlayerInfo PlayerInfo = new PlayerInfo(); - internal int - previousHealth = 100, + internal float + previousHealth = 100; + internal int prevAmmo5 = 0, prevAmmo7 = 0, prevAmmo9 = 0; public Vector DeathPos = Vector.Zero; internal Vector originalPos = Vector.Zero; - internal Role previousRole = Role.CLASSD; + internal Smod2.API.RoleType previousRole = Smod2.API.RoleType.CLASSD; internal List playerPrevInv = new List(); - internal ItemType InfiniteItem = ItemType.NULL; + internal Smod2.API.ItemType InfiniteItem = Smod2.API.ItemType.NULL; public DateTime JailedToTime { get; internal set; } = DateTime.Now; public DateTime JoinTime { get; internal set; } = DateTime.Now; - public PlayerSettings(string steamID) => this.PlayerInfo.SteamID = steamID; + public PlayerSettings(string UserId) => this.PlayerInfo.UserId = UserId; } } diff --git a/AdminToolbox/AdminToolbox/API/SetPlayerVariables.cs b/AdminToolbox/AdminToolbox/API/SetPlayerVariables.cs index 3f5b11b..c2aa84d 100644 --- a/AdminToolbox/AdminToolbox/API/SetPlayerVariables.cs +++ b/AdminToolbox/AdminToolbox/API/SetPlayerVariables.cs @@ -9,12 +9,12 @@ namespace AdminToolbox.API public static class SetPlayerVariables { /// - /// For setting bools by - /// Returns false if is not in + /// For setting bools by + /// Returns false if is not in /// - public static bool SetPlayerBools(string steamID, bool? spectatorOnly = null, bool? godMode = null, bool? dmgOff = null, bool? destroyDoor = null, bool? keepSettings = null, bool? lockDown = null, bool? instantKill = null, bool? isJailed = null) + public static bool SetPlayerBools(string UserId, bool? spectatorOnly = null, bool? godMode = null, bool? dmgOff = null, bool? destroyDoor = null, bool? keepSettings = null, bool? lockDown = null, bool? instantKill = null, bool? isJailed = null) { - if (AdminToolbox.ATPlayerDict.TryGetValue(steamID, out PlayerSettings setting)) + if (AdminToolbox.ATPlayerDict.TryGetValue(UserId, out PlayerSettings setting)) { setting.overwatchMode = spectatorOnly ?? setting.overwatchMode; setting.godMode = godMode ?? setting.godMode; @@ -31,29 +31,29 @@ public static bool SetPlayerBools(string steamID, bool? spectatorOnly = null, bo } /// /// For setting bools on a - /// Returns false if 's steamID is not in + /// Returns false if 's UserId is not in /// public static bool SetPlayerBools(Player player, bool? spectatorOnly = null, bool? godMode = null, bool? dmgOff = null, bool? destroyDoor = null, bool? keepSettings = null, bool? lockDown = null, bool? instantKill = null, bool? isJailed = null) - => SetPlayerBools(player.SteamId, spectatorOnly, godMode, dmgOff, destroyDoor, keepSettings, lockDown, instantKill, isJailed); + => SetPlayerBools(player.UserId, spectatorOnly, godMode, dmgOff, destroyDoor, keepSettings, lockDown, instantKill, isJailed); /// /// For setting bools on a list of s - /// Returns false if one or more of steamid's is not in + /// Returns false if one or more of UserId's is not in /// public static bool SetPlayerBools(List players, bool? spectatorOnly = null, bool? godMode = null, bool? dmgOff = null, bool? destroyDoor = null, bool? keepSettings = null, bool? lockDown = null, bool? instantKill = null, bool? isJailed = null) { int failiures = 0; foreach (Player player in players) - if (!SetPlayerBools(player.SteamId, spectatorOnly, godMode, dmgOff, destroyDoor, keepSettings, lockDown, instantKill, isJailed)) + if (!SetPlayerBools(player.UserId, spectatorOnly, godMode, dmgOff, destroyDoor, keepSettings, lockDown, instantKill, isJailed)) failiures++; return !(failiures > 0); } /// /// For setting - /// Returns false if is not in + /// Returns false if is not in /// - public static bool SetPlayerStats(string steamID, int? Kills = null, int? TeamKills = null, int? Deaths = null, int? RoundsPlayed = null, int? BanCount = null) + public static bool SetPlayerStats(string UserId, int? Kills = null, int? TeamKills = null, int? Deaths = null, int? RoundsPlayed = null, int? BanCount = null) { - if (AdminToolbox.ATPlayerDict.TryGetValue(steamID, out PlayerSettings settings)) + if (AdminToolbox.ATPlayerDict.TryGetValue(UserId, out PlayerSettings settings)) { PlayerStats stats = settings.PlayerStats; stats.Kills = Kills ?? stats.Kills; diff --git a/AdminToolbox/AdminToolbox/API/Utility.cs b/AdminToolbox/AdminToolbox/API/Utility.cs index e9843bc..93b111d 100644 --- a/AdminToolbox/AdminToolbox/API/Utility.cs +++ b/AdminToolbox/AdminToolbox/API/Utility.cs @@ -12,15 +12,15 @@ public static class Utility /// Returns based on success /// Invalid parameters returns /// - public static bool TryParseRole(int roleID, out Role role) + public static bool TryParseRole(int roleID, out Smod2.API.RoleType role) { - role = Role.UNASSIGNED; + role = Smod2.API.RoleType.UNASSIGNED; int[] validRoles = Enum.GetValues(typeof(Role)).Cast().ToArray(); if (!validRoles.Contains(roleID)) return false; else { - role = (Role)roleID; + role = (Smod2.API.RoleType)roleID; return true; } } @@ -30,15 +30,15 @@ public static bool TryParseRole(int roleID, out Role role) /// Returns based on success /// Invalid parameters returns /// - public static bool TryParseItem(int itemID, out ItemType itemType) + public static bool TryParseItem(int itemID, out Smod2.API.ItemType itemType) { - itemType = ItemType.NULL; - int[] validItems = Enum.GetValues(typeof(ItemType)).Cast().ToArray(); + itemType = Smod2.API.ItemType.NULL; + int[] validItems = Enum.GetValues(typeof(Smod2.API.ItemType)).Cast().ToArray(); if (!validItems.Contains(itemID)) return false; else { - itemType = (ItemType)itemID; + itemType = (Smod2.API.ItemType)itemID; return true; } } @@ -48,14 +48,14 @@ public static bool TryParseItem(int itemID, out ItemType itemType) /// Returns based on success /// Tries to cast to first, then compares names /// - public static bool TryParseItem(string item, out ItemType itemType) + public static bool TryParseItem(string item, out Smod2.API.ItemType itemType) { if (int.TryParse(item, out int x)) return TryParseItem(x, out itemType); - itemType = ItemType.NULL; + itemType = Smod2.API.ItemType.NULL; - foreach (ItemType i in Enum.GetValues(typeof(ItemType))) + foreach (Smod2.API.ItemType i in Enum.GetValues(typeof(Smod2.API.ItemType))) { if (i.ToString().ToUpper().Contains(item.ToUpper())) { diff --git a/AdminToolbox/AdminToolbox/AdminToolbox.cs b/AdminToolbox/AdminToolbox/AdminToolbox.cs index 0d70be9..c83d54d 100644 --- a/AdminToolbox/AdminToolbox/AdminToolbox.cs +++ b/AdminToolbox/AdminToolbox/AdminToolbox.cs @@ -23,13 +23,13 @@ namespace AdminToolbox id = "rnen.admin.toolbox", version = AT_Version + "-" + AT_Revision, SmodMajor = 3, - SmodMinor = 6, + SmodMinor = 7, SmodRevision = 0 )] public class AdminToolbox : Plugin { internal const string AT_Version = "1.3.8"; - internal const string AT_Revision = "12"; + internal const string AT_Revision = "13"; #region GitHub release info private DateTime LastOnlineCheck = DateTime.Now; @@ -49,17 +49,17 @@ internal ATWeb.AT_LatestReleaseInfo GetGitReleaseInfo() #endregion /// - /// s instance of + /// The plugin's instance of /// public static readonly LogManager logManager = new LogManager(); /// - /// s instance of + /// The plugin's instance instance of /// public static readonly WarpManager warpManager = new WarpManager(); /// - /// s instance of + /// The plugin's instance instance of /// public static readonly ATFileManager atfileManager = new ATFileManager(); @@ -88,7 +88,7 @@ public static bool #endif /// - /// of containing settings on all players. Uses as KEY + /// of containing the plugin's settings on all players. Uses as KEY /// public static Dictionary ATPlayerDict { get; internal set; } = new Dictionary(); @@ -102,7 +102,7 @@ public static bool /// public static int RoundCount { get; internal set; } = 0; - internal static AdminToolbox plugin; + internal static AdminToolbox singleton; /// /// Called when gets disabled @@ -115,7 +115,7 @@ public override void OnDisable() /// public override void OnEnable() { - plugin = this; + singleton = this; ATFileManager.WriteVersionToFile(); Debug(this.Details.name + " v." + this.Details.version + (isColored ? " - @#fg=Green;Enabled@#fg=Default;" : " - Enabled")); } @@ -132,10 +132,10 @@ public override void Register() internal void RegisterEvents() { - this.AddEventHandlers(new RoundEventHandler(this), Priority.Normal); - this.AddEventHandler(typeof(IEventHandlerPlayerHurt), new DamageDetect(this), Priority.Normal); - this.AddEventHandler(typeof(IEventHandlerPlayerDie), new DieDetect(this), Priority.Normal); - this.AddEventHandlers(new MyMiscEvents(this), Priority.Normal); + this.AddEventHandlers(new RoundEventHandler(this)); + this.AddEventHandler(typeof(IEventHandlerPlayerHurt), new DamageDetect(this)); + this.AddEventHandler(typeof(IEventHandlerPlayerDie), new DieDetect(this)); + this.AddEventHandlers(new MyMiscEvents(this)); this.AddEventHandler(typeof(IEventHandlerCheckRoundEnd), new LateOnCheckRoundEndEvent(this), Priority.Highest); this.AddEventHandler(typeof(IEventHandlerCheckEscape), new LateEscapeEventCheck(), Priority.Highest); } @@ -223,7 +223,7 @@ internal void RegisterConfigs() #endregion #region Intercom //this.AddConfig(new Smod2.Config.ConfigSetting("admintoolbox_intercom_whitelist", new string[] { string.Empty }, Smod2.Config.SettingType.LIST, true, "What ServerRank can use the Intercom to your specified settings")); - this.AddConfig(new ConfigSetting("admintoolbox_intercom_steamid_blacklist", new string[0], true, "Blacklist of steamID's that cannot use the intercom")); + this.AddConfig(new ConfigSetting("admintoolbox_intercom_UserId_blacklist", new string[0], true, "Blacklist of UserId's that cannot use the intercom")); this.AddConfig(new ConfigSetting("admintoolbox_intercomlock", false, true, "If set to true, locks the command for all non-whitelist players")); #endregion @@ -232,7 +232,6 @@ internal void RegisterConfigs() this.AddConfig(new ConfigSetting("admintoolbox_ban_webhooks", new string[0], true, "Links to channel webhooks for bans")); //this.AddConfig(new Smod2.Config.ConfigSetting("admintoolbox_timedrestart_automessages", new string[] { "" }, Smod2.Config.SettingType.LIST, true, "")); //this.AddConfig(new Smod2.Config.ConfigSetting("atb_timedrestart_automessages", new string[] { "" }, Smod2.Config.SettingType.LIST, true, "")); - } @@ -260,7 +259,7 @@ internal static void AddMissingPlayerVariables(Player[] players) { foreach (Player player in players) { - if (player != null && !string.IsNullOrEmpty(player.SteamId)) + if (player != null && !string.IsNullOrEmpty(player.UserId)) { AddToPlayerDict(player); } @@ -270,20 +269,21 @@ internal static void AddMissingPlayerVariables(Player[] players) private static void AddToPlayerDict(Player player) { if (player != null && player is Player p && - !string.IsNullOrEmpty(p.SteamId) && !ATPlayerDict.ContainsKey(p.SteamId)) + !string.IsNullOrEmpty(p.UserId) && !ATPlayerDict.ContainsKey(p.UserId)) { - ATPlayerDict.Add(p.SteamId, new PlayerSettings(p.SteamId)); + ATPlayerDict.Add(p.UserId, new PlayerSettings(p.UserId)); } } /// - /// Debugs messages in when DEBUG is defined + /// Debugs messages when is enabled /// public new void Debug(string message) { if (DebugMode) this.Info(message); } + } } diff --git a/AdminToolbox/AdminToolbox/AdminToolbox.csproj b/AdminToolbox/AdminToolbox/AdminToolbox.csproj index 8138a08..ff22818 100644 --- a/AdminToolbox/AdminToolbox/AdminToolbox.csproj +++ b/AdminToolbox/AdminToolbox/AdminToolbox.csproj @@ -42,19 +42,18 @@ OnBuildSuccess - + False - ..\..\..\..\SCP_SL_SERVER\SCPSL_Data\Managed\Assembly-CSharp.dll - False + ..\Builds\Assembly-CSharp.dll False ..\..\..\..\SCP_SL_SERVER\SCPSL_Data\Managed\Newtonsoft.Json.dll + False - + False - ..\..\..\..\SCP_SL_SERVER\SCPSL_Data\Managed\Smod2.dll - False + ..\Builds\Smod2.dll @@ -70,10 +69,6 @@ ..\..\..\..\SCP_SL_SERVER\SCPSL_Data\Managed\UnityEngine.CoreModule.dll False - - ..\..\..\..\SCP_SL_SERVER\SCPSL_Data\Managed\UnityEngine.Networking.dll - False - ..\..\..\..\SCP_SL_SERVER\SCPSL_Data\Managed\UnityEngine.PhysicsModule.dll False diff --git a/AdminToolbox/AdminToolbox/Commands/Facility/JailCommand.cs b/AdminToolbox/AdminToolbox/Commands/Facility/JailCommand.cs index 4596d5a..4cccd82 100644 --- a/AdminToolbox/AdminToolbox/Commands/Facility/JailCommand.cs +++ b/AdminToolbox/AdminToolbox/Commands/Facility/JailCommand.cs @@ -42,8 +42,8 @@ public string[] OnCall(ICommandSender sender, string[] args) } else if (args.Length == 1) { - if (!AdminToolbox.ATPlayerDict.ContainsKey(myPlayer.SteamId)) return new string[] { "Failed to jail/unjail " + myPlayer.Name + "!", "Error: Player not in dictionary" }; - if (AdminToolbox.ATPlayerDict[myPlayer.SteamId].isJailed) + if (!AdminToolbox.ATPlayerDict.ContainsKey(myPlayer.UserId)) return new string[] { "Failed to jail/unjail " + myPlayer.Name + "!", "Error: Player not in dictionary" }; + if (AdminToolbox.ATPlayerDict[myPlayer.UserId].isJailed) { JailHandler.ReturnFromJail(myPlayer); return new string[] { "\"" + myPlayer.Name + "\" returned from jail" }; diff --git a/AdminToolbox/AdminToolbox/Commands/Facility/SpeakCommand.cs b/AdminToolbox/AdminToolbox/Commands/Facility/SpeakCommand.cs index bab3814..95d75d8 100644 --- a/AdminToolbox/AdminToolbox/Commands/Facility/SpeakCommand.cs +++ b/AdminToolbox/AdminToolbox/Commands/Facility/SpeakCommand.cs @@ -11,7 +11,7 @@ public class SpeakCommand : ICommandHandler private Server Server => PluginManager.Manager.Server; public string GetCommandDescription() => "Sets specified player as intercom speaker"; - public string GetUsage() => "(" + string.Join(" / ", CommandAliases) + ") [PLAYERNAME/ID/STEAMID]"; + public string GetUsage() => "(" + string.Join(" / ", CommandAliases) + ") [PLAYERNAME/ID/UserId]"; public static readonly string[] CommandAliases = new string[] { "ATSPEAK", "ATINTERCOM", "AT-SPEAK" }; diff --git a/AdminToolbox/AdminToolbox/Commands/Player/ATBanCommand.cs b/AdminToolbox/AdminToolbox/Commands/Player/ATBanCommand.cs index b3114c3..2496449 100644 --- a/AdminToolbox/AdminToolbox/Commands/Player/ATBanCommand.cs +++ b/AdminToolbox/AdminToolbox/Commands/Player/ATBanCommand.cs @@ -14,7 +14,7 @@ public class ATBanCommand : ICommandHandler private Server Server => PluginManager.Manager.Server; public ATBanCommand(AdminToolbox plugin) => this.plugin = plugin; - public string GetUsage() => "(" + string.Join(" / ", CommandAliases) + ") [NAME] [IP/SteamID] "; + public string GetUsage() => "(" + string.Join(" / ", CommandAliases) + ") [NAME] [IP/UserId] "; public string GetCommandDescription() => "Alternative ban for offline users"; public static readonly string[] CommandAliases = new string[] { "ATBAN", "OBAN", "OFFLINEBAN" }; @@ -27,7 +27,7 @@ public string[] OnCall(ICommandSender sender, string[] args) { if (args.Length < 2) return new string[] { GetUsage() }; - string IssuingPlayer = (sender is Player pl && !string.IsNullOrEmpty(pl.SteamId)) ? pl.Name : "Server"; + string IssuingPlayer = (sender is Player pl && !string.IsNullOrEmpty(pl.UserId)) ? pl.Name : "Server"; string bannedPlayer = args[0]; string input = args[1]; int minutes = Config.GetIntValue("admintoolbox_atban_duration_default", 43800); //Default 4 weeks @@ -72,7 +72,7 @@ public string[] OnCall(ICommandSender sender, string[] args) Player[] plist = Server.GetPlayers().ToArray(); foreach (Player player in plist) { - if (player.SteamId == sID.ToString()) + if (player.UserId == sID.ToString()) { bannedPlayer = player.Name; player.Ban(0, "You have been banned from this server!"); @@ -80,11 +80,11 @@ public string[] OnCall(ICommandSender sender, string[] args) } } - Server.BanSteamId(bannedPlayer, input, minutes, reason, IssuingPlayer); + Server.BanUserId(bannedPlayer, input, minutes, reason, IssuingPlayer); string response = "\n" + "Player with name: " + bannedPlayer + "\n" + - "SteamID64: " + input.Trim() + "\n" + + "UserId64: " + input.Trim() + "\n" + "Was banned for: " + minutes + " minutes \n" + "By: " + IssuingPlayer; @@ -93,7 +93,7 @@ public string[] OnCall(ICommandSender sender, string[] args) return new string[] { response }; } else - return new string[] { "SteamID / IP not in correct format!", GetUsage() }; + return new string[] { "UserId / IP not in correct format!", GetUsage() }; } catch (Exception e) { diff --git a/AdminToolbox/AdminToolbox/Commands/Player/BreakDoorsCommand.cs b/AdminToolbox/AdminToolbox/Commands/Player/BreakDoorsCommand.cs index 8bd7d17..c9afea3 100644 --- a/AdminToolbox/AdminToolbox/Commands/Player/BreakDoorsCommand.cs +++ b/AdminToolbox/AdminToolbox/Commands/Player/BreakDoorsCommand.cs @@ -34,7 +34,7 @@ public string[] OnCall(ICommandSender sender, string[] args) int playerNum = 0; foreach (Player pl in Server.GetPlayers()) { - if (AdminToolbox.ATPlayerDict.TryGetValue(pl.SteamId, out PlayerSettings ps)) + if (AdminToolbox.ATPlayerDict.TryGetValue(pl.UserId, out PlayerSettings ps)) { ps.destroyDoor = j; playerNum++; @@ -50,7 +50,7 @@ public string[] OnCall(ICommandSender sender, string[] args) { foreach (Player pl in Server.GetPlayers()) { - if (AdminToolbox.ATPlayerDict.TryGetValue(pl.SteamId, out PlayerSettings ps)) + if (AdminToolbox.ATPlayerDict.TryGetValue(pl.UserId, out PlayerSettings ps)) ps.destroyDoor = !ps.destroyDoor; } return new string[] { "Toggled all players BreakDoors" }; @@ -62,7 +62,7 @@ public string[] OnCall(ICommandSender sender, string[] args) List myPlayerList = new List(); foreach (Player pl in Server.GetPlayers()) { - if (AdminToolbox.ATPlayerDict.TryGetValue(pl.SteamId, out PlayerSettings ps) && ps.destroyDoor) + if (AdminToolbox.ATPlayerDict.TryGetValue(pl.UserId, out PlayerSettings ps) && ps.destroyDoor) myPlayerList.Add(pl.Name); } if (myPlayerList.Count > 0) @@ -78,7 +78,7 @@ public string[] OnCall(ICommandSender sender, string[] args) if (myPlayer == null && sender is Player sendingPlayer) myPlayer = sendingPlayer; if (myPlayer == null) { return new string[] { "Couldn't find player: " + args[0] }; } - if (AdminToolbox.ATPlayerDict.TryGetValue(myPlayer.SteamId, out PlayerSettings psetting)) + if (AdminToolbox.ATPlayerDict.TryGetValue(myPlayer.UserId, out PlayerSettings psetting)) if (args.Length > 1) { if (args[1].ToLower() == "on" || args[1].ToLower() == "true") { psetting.destroyDoor = true; } @@ -94,7 +94,7 @@ public string[] OnCall(ICommandSender sender, string[] args) return new string[] { myPlayer.Name + " not in dictionary" }; } - else if (sender is Player p && AdminToolbox.ATPlayerDict.TryGetValue(p.SteamId, out PlayerSettings ps)) + else if (sender is Player p && AdminToolbox.ATPlayerDict.TryGetValue(p.UserId, out PlayerSettings ps)) { ps.destroyDoor = !ps.destroyDoor; return new string[] { "Toggled BreakDoors! Currently: " + ps.destroyDoor }; diff --git a/AdminToolbox/AdminToolbox/Commands/Player/EmptyCommand.cs b/AdminToolbox/AdminToolbox/Commands/Player/EmptyCommand.cs index be3c02f..28f0b38 100644 --- a/AdminToolbox/AdminToolbox/Commands/Player/EmptyCommand.cs +++ b/AdminToolbox/AdminToolbox/Commands/Player/EmptyCommand.cs @@ -26,7 +26,7 @@ public class EmptyCommand : ICommandHandler { if (sender.IsPermitted(CommandAliases, out string[] deniedReply)) { - ItemType type = ItemType.NULL; + Smod2.API.ItemType type = Smod2.API.ItemType.NULL; Player player = null; bool delete = false; @@ -55,26 +55,26 @@ public class EmptyCommand : ICommandHandler } - private string[] DropItems(Player player, ItemType itemFilter = ItemType.NULL, bool delete = false) + private string[] DropItems(Player player, Smod2.API.ItemType itemFilter = Smod2.API.ItemType.NULL, bool delete = false) { - ItemType ammoFlag = ItemType.DROPPED_5 | ItemType.DROPPED_7 | ItemType.DROPPED_9; + Smod2.API.ItemType ammoFlag = Smod2.API.ItemType.DROPPED_5 | Smod2.API.ItemType.DROPPED_7 | Smod2.API.ItemType.DROPPED_9; if (player == null) return new string[] { "Player not spesified!" }; - if (player.TeamRole.Role == Role.UNASSIGNED) + if (player.TeamRole.Role == Smod2.API.RoleType.UNASSIGNED) return new string[] { "Player not properly initialized!" }; - if (player.TeamRole.Role == Role.SPECTATOR) + if (player.TeamRole.Role == Smod2.API.RoleType.SPECTATOR) return new string[] { "This can not be used on spectators!" }; byte itemCount = 0; Vector pos = player.GetPosition(), rot = player.GetRotation(); - if (itemFilter == ItemType.NULL || !ammoFlag.HasFlag(itemFilter)) + if (itemFilter == Smod2.API.ItemType.NULL || !ammoFlag.HasFlag(itemFilter)) { foreach (SMItem playerItem in player.GetInventory()) { - if (playerItem.ItemType != ItemType.NULL) - if (itemFilter == ItemType.NULL || playerItem.ItemType == itemFilter) + if (playerItem.ItemType != Smod2.API.ItemType.NULL) + if (itemFilter == Smod2.API.ItemType.NULL || playerItem.ItemType == itemFilter) { if (delete) playerItem.Remove(); @@ -87,13 +87,13 @@ private string[] DropItems(Player player, ItemType itemFilter = ItemType.NULL, b } - if (itemFilter == ItemType.NULL || ammoFlag.HasFlag(itemFilter)) + if (itemFilter == Smod2.API.ItemType.NULL || ammoFlag.HasFlag(itemFilter)) { foreach (AmmoType ammo in Enum.GetValues(typeof(AmmoType))) { - ItemType ammoItem = ammo == AmmoType.DROPPED_5 ? ItemType.DROPPED_5 : ammo == AmmoType.DROPPED_7 ? ItemType.DROPPED_7 : ItemType.DROPPED_9; + Smod2.API.ItemType ammoItem = ammo == Smod2.API.AmmoType.DROPPED_5 ? Smod2.API.ItemType.DROPPED_5 : ammo == Smod2.API.AmmoType.DROPPED_7 ? Smod2.API.ItemType.DROPPED_7 : Smod2.API.ItemType.DROPPED_9; - if (itemFilter == ItemType.NULL || ammoItem == itemFilter) + if (itemFilter == Smod2.API.ItemType.NULL || ammoItem == itemFilter) { player.SetAmmo(ammo, 0); if (!delete) diff --git a/AdminToolbox/AdminToolbox/Commands/Player/GodModeCommand.cs b/AdminToolbox/AdminToolbox/Commands/Player/GodModeCommand.cs index 913d41e..05e736c 100644 --- a/AdminToolbox/AdminToolbox/Commands/Player/GodModeCommand.cs +++ b/AdminToolbox/AdminToolbox/Commands/Player/GodModeCommand.cs @@ -38,7 +38,7 @@ public string[] OnCall(ICommandSender sender, string[] args) int playerNum = 0; foreach (Player pl in Server.GetPlayers()) { - if (AdminToolbox.ATPlayerDict.TryGetValue(pl.SteamId, out PlayerSettings ps)) + if (AdminToolbox.ATPlayerDict.TryGetValue(pl.UserId, out PlayerSettings ps)) { ps.godMode = j; if (changedState) @@ -59,7 +59,7 @@ public string[] OnCall(ICommandSender sender, string[] args) { foreach (Player pl in Server.GetPlayers()) { - if (AdminToolbox.ATPlayerDict.TryGetValue(pl.SteamId, out PlayerSettings psetting)) + if (AdminToolbox.ATPlayerDict.TryGetValue(pl.UserId, out PlayerSettings psetting)) psetting.godMode = !psetting.godMode; } return new string[] { "Toggled all players AT-Godmodes" }; @@ -71,7 +71,7 @@ public string[] OnCall(ICommandSender sender, string[] args) List myPlayerList = new List(); foreach (Player pl in Server.GetPlayers()) { - if (AdminToolbox.ATPlayerDict.TryGetValue(pl.SteamId, out PlayerSettings plsetting) && plsetting.godMode) + if (AdminToolbox.ATPlayerDict.TryGetValue(pl.UserId, out PlayerSettings plsetting) && plsetting.godMode) { myPlayerList.Add(pl.Name); //str += " - " +pl.Name + "\n"; @@ -90,7 +90,7 @@ public string[] OnCall(ICommandSender sender, string[] args) } Player myPlayer = GetPlayerFromString.GetPlayer(args[0]); if (myPlayer == null) return new string[] { "Couldn't find player: " + args[0] }; - if (AdminToolbox.ATPlayerDict.TryGetValue(myPlayer.SteamId, out PlayerSettings pls)) + if (AdminToolbox.ATPlayerDict.TryGetValue(myPlayer.UserId, out PlayerSettings pls)) { if (args.Length > 1) { diff --git a/AdminToolbox/AdminToolbox/Commands/Player/GrenadeModeCommand.cs b/AdminToolbox/AdminToolbox/Commands/Player/GrenadeModeCommand.cs index 29420ec..4b6b4f5 100644 --- a/AdminToolbox/AdminToolbox/Commands/Player/GrenadeModeCommand.cs +++ b/AdminToolbox/AdminToolbox/Commands/Player/GrenadeModeCommand.cs @@ -35,7 +35,7 @@ public string[] OnCall(ICommandSender sender, string[] args) case "PLAYERS": List plNames = new List { "Players with GRENADEMODE enabled:" }; foreach (Player p in Server.GetPlayers()) - if (AdminToolbox.ATPlayerDict.TryGetValue(p.SteamId, out PlayerSettings ps) && ps.grenadeMode) + if (AdminToolbox.ATPlayerDict.TryGetValue(p.UserId, out PlayerSettings ps) && ps.grenadeMode) plNames.Add(" - " + p.Name); return plNames.ToArray(); } @@ -59,7 +59,7 @@ public string[] OnCall(ICommandSender sender, string[] args) bool? s = (args.Length > 1 && bool.TryParse(args[1], out bool b) ? (bool?)b : null); foreach (Player pl in players) { - if (AdminToolbox.ATPlayerDict.TryGetValue(pl.SteamId, out PlayerSettings ps)) + if (AdminToolbox.ATPlayerDict.TryGetValue(pl.UserId, out PlayerSettings ps)) { ps.grenadeMode = s.HasValue ? (bool)s : !ps.grenadeMode; } diff --git a/AdminToolbox/AdminToolbox/Commands/Player/InfiniteItemCommand.cs b/AdminToolbox/AdminToolbox/Commands/Player/InfiniteItemCommand.cs index 07f9d97..97599ce 100644 --- a/AdminToolbox/AdminToolbox/Commands/Player/InfiniteItemCommand.cs +++ b/AdminToolbox/AdminToolbox/Commands/Player/InfiniteItemCommand.cs @@ -35,7 +35,7 @@ public string[] OnCall(ICommandSender sender, string[] args) case "PLAYERS": List plNames = new List { "Players with INFINITEITEM enabled:" }; foreach (Player p in Server.GetPlayers()) - if (AdminToolbox.ATPlayerDict.TryGetValue(p.SteamId, out PlayerSettings ps) && ps.InfiniteItem != ItemType.NULL) + if (AdminToolbox.ATPlayerDict.TryGetValue(p.UserId, out PlayerSettings ps) && ps.InfiniteItem != Smod2.API.ItemType.NULL) plNames.Add(" - " + p.Name + " -> + " + ps.InfiniteItem.ToString()); return plNames.ToArray(); } @@ -56,10 +56,10 @@ public string[] OnCall(ICommandSender sender, string[] args) } if (players.Length > 0) { - ItemType item = args.Length > 1 && Utility.TryParseItem(args[1], out ItemType i) ? i : ItemType.NULL; + Smod2.API.ItemType item = args.Length > 1 && Utility.TryParseItem(args[1], out Smod2.API.ItemType i) ? i : Smod2.API.ItemType.NULL; foreach (Player pl in players) { - if (AdminToolbox.ATPlayerDict.TryGetValue(pl.SteamId, out PlayerSettings ps)) + if (AdminToolbox.ATPlayerDict.TryGetValue(pl.UserId, out PlayerSettings ps)) { ps.InfiniteItem = item; } diff --git a/AdminToolbox/AdminToolbox/Commands/Player/InstantKillCommand.cs b/AdminToolbox/AdminToolbox/Commands/Player/InstantKillCommand.cs index 6c04740..b4a1190 100644 --- a/AdminToolbox/AdminToolbox/Commands/Player/InstantKillCommand.cs +++ b/AdminToolbox/AdminToolbox/Commands/Player/InstantKillCommand.cs @@ -34,7 +34,7 @@ public string[] OnCall(ICommandSender sender, string[] args) int playerNum = 0; foreach (Player pl in Server.GetPlayers()) { - if (AdminToolbox.ATPlayerDict.TryGetValue(pl.SteamId, out PlayerSettings ps)) + if (AdminToolbox.ATPlayerDict.TryGetValue(pl.UserId, out PlayerSettings ps)) { ps.instantKill = j; playerNum++; @@ -52,7 +52,7 @@ public string[] OnCall(ICommandSender sender, string[] args) { foreach (Player pl in Server.GetPlayers()) { - if (AdminToolbox.ATPlayerDict.TryGetValue(pl.SteamId, out PlayerSettings psetting)) + if (AdminToolbox.ATPlayerDict.TryGetValue(pl.UserId, out PlayerSettings psetting)) psetting.instantKill = !psetting.instantKill; } return new string[] { "Toggled all players InstantKill" }; @@ -65,7 +65,7 @@ public string[] OnCall(ICommandSender sender, string[] args) List myPlayerList = new List(); foreach (Player pl in Server.GetPlayers()) { - if (AdminToolbox.ATPlayerDict.TryGetValue(pl.SteamId, out PlayerSettings psett) && psett.instantKill) + if (AdminToolbox.ATPlayerDict.TryGetValue(pl.UserId, out PlayerSettings psett) && psett.instantKill) { myPlayerList.Add(pl.Name); //str += " - " +pl.Name + "\n"; @@ -87,21 +87,21 @@ public string[] OnCall(ICommandSender sender, string[] args) AdminToolbox.AddMissingPlayerVariables(myPlayer); if (args.Length > 1) { - if (AdminToolbox.ATPlayerDict.TryGetValue(myPlayer.SteamId, out PlayerSettings ps)) + if (AdminToolbox.ATPlayerDict.TryGetValue(myPlayer.UserId, out PlayerSettings ps)) { - if (bool.TryParse(args[1], out bool g)) AdminToolbox.ATPlayerDict[myPlayer.SteamId].instantKill = g; - else if (args[1].ToLower() == "on") { AdminToolbox.ATPlayerDict[myPlayer.SteamId].instantKill = true; } - else if (args[1].ToLower() == "off") { AdminToolbox.ATPlayerDict[myPlayer.SteamId].instantKill = false; } + if (bool.TryParse(args[1], out bool g)) AdminToolbox.ATPlayerDict[myPlayer.UserId].instantKill = g; + else if (args[1].ToLower() == "on") { AdminToolbox.ATPlayerDict[myPlayer.UserId].instantKill = true; } + else if (args[1].ToLower() == "off") { AdminToolbox.ATPlayerDict[myPlayer.UserId].instantKill = false; } else return new string[] { GetUsage() }; - return new string[] { myPlayer.Name + " InstantKill: " + AdminToolbox.ATPlayerDict[myPlayer.SteamId].instantKill }; + return new string[] { myPlayer.Name + " InstantKill: " + AdminToolbox.ATPlayerDict[myPlayer.UserId].instantKill }; } else return new string[] { myPlayer.Name + " not in dictionary" }; } else { - AdminToolbox.ATPlayerDict[myPlayer.SteamId].instantKill = !AdminToolbox.ATPlayerDict[myPlayer.SteamId].instantKill; - return new string[] { myPlayer.Name + " InstantKill: " + AdminToolbox.ATPlayerDict[myPlayer.SteamId].instantKill }; + AdminToolbox.ATPlayerDict[myPlayer.UserId].instantKill = !AdminToolbox.ATPlayerDict[myPlayer.UserId].instantKill; + return new string[] { myPlayer.Name + " InstantKill: " + AdminToolbox.ATPlayerDict[myPlayer.UserId].instantKill }; } } diff --git a/AdminToolbox/AdminToolbox/Commands/Player/KeepSettingsCommand.cs b/AdminToolbox/AdminToolbox/Commands/Player/KeepSettingsCommand.cs index 6c2d6ce..fc2a0b4 100644 --- a/AdminToolbox/AdminToolbox/Commands/Player/KeepSettingsCommand.cs +++ b/AdminToolbox/AdminToolbox/Commands/Player/KeepSettingsCommand.cs @@ -34,7 +34,7 @@ public string[] OnCall(ICommandSender sender, string[] args) foreach (Player pl in Server.GetPlayers()) { AdminToolbox.AddMissingPlayerVariables(pl); - if (AdminToolbox.ATPlayerDict.TryGetValue(pl.SteamId, out PlayerSettings ps)) + if (AdminToolbox.ATPlayerDict.TryGetValue(pl.UserId, out PlayerSettings ps)) ps.keepSettings = j; playerNum++; } @@ -51,7 +51,7 @@ public string[] OnCall(ICommandSender sender, string[] args) foreach (Player pl in Server.GetPlayers()) { AdminToolbox.AddMissingPlayerVariables(pl); - if (AdminToolbox.ATPlayerDict.TryGetValue(pl.SteamId, out PlayerSettings ps)) + if (AdminToolbox.ATPlayerDict.TryGetValue(pl.UserId, out PlayerSettings ps)) ps.keepSettings = !ps.keepSettings; } return new string[] { "Toggled all players KeepSettings" }; @@ -63,7 +63,7 @@ public string[] OnCall(ICommandSender sender, string[] args) List myPlayerList = new List(); foreach (Player pl in Server.GetPlayers()) { - if (AdminToolbox.ATPlayerDict.TryGetValue(pl.SteamId, out PlayerSettings ps) && ps.keepSettings) + if (AdminToolbox.ATPlayerDict.TryGetValue(pl.UserId, out PlayerSettings ps) && ps.keepSettings) { myPlayerList.Add(pl.Name); } @@ -82,7 +82,7 @@ public string[] OnCall(ICommandSender sender, string[] args) Player myPlayer = GetPlayerFromString.GetPlayer(args[0]); if (myPlayer == null) { return new string[] { "Couldn't find player: " + args[0] }; } AdminToolbox.AddMissingPlayerVariables(myPlayer); - if (AdminToolbox.ATPlayerDict.TryGetValue(myPlayer.SteamId, out PlayerSettings psett)) + if (AdminToolbox.ATPlayerDict.TryGetValue(myPlayer.UserId, out PlayerSettings psett)) if (args.Length > 1) { if (args[1].ToLower() == "on" || args[1].ToLower() == "true") { psett.keepSettings = true; } diff --git a/AdminToolbox/AdminToolbox/Commands/Player/KillCommand.cs b/AdminToolbox/AdminToolbox/Commands/Player/KillCommand.cs index 1c6b457..a7e12cc 100644 --- a/AdminToolbox/AdminToolbox/Commands/Player/KillCommand.cs +++ b/AdminToolbox/AdminToolbox/Commands/Player/KillCommand.cs @@ -39,8 +39,8 @@ public string[] OnCall(ICommandSender sender, string[] args) foreach (Player p in Server.GetPlayers().Where(pl => pl.PlayerId != (caller != null ? caller.PlayerId : -1) && !pl.GetGodmode() && - (AdminToolbox.ATPlayerDict.ContainsKey(pl.SteamId) ? !AdminToolbox.ATPlayerDict[pl.SteamId].godMode : true) - && pl.TeamRole.Team != Smod2.API.Team.SPECTATOR)) + (AdminToolbox.ATPlayerDict.ContainsKey(pl.UserId) ? !AdminToolbox.ATPlayerDict[pl.UserId].godMode : true) + && pl.TeamRole.Team != Smod2.API.TeamType.SPECTATOR)) { p.Kill(killType); playerNum++; @@ -50,7 +50,7 @@ public string[] OnCall(ICommandSender sender, string[] args) } Player myPlayer = GetPlayerFromString.GetPlayer(args[0]); if (myPlayer == null) { return new string[] { "Couldn't get player: " + args[0] }; } - if (myPlayer.TeamRole.Role != Role.SPECTATOR) + if (myPlayer.TeamRole.Role != Smod2.API.RoleType.SPECTATOR) { if (caller != null && !string.IsNullOrEmpty(caller.Name) && caller.Name.ToLower() != "server") plugin.Info(caller.Name + " ran the \"SLAY\" command on: " + myPlayer.Name); myPlayer.Kill(killType); diff --git a/AdminToolbox/AdminToolbox/Commands/Player/LockDoorsCommand.cs b/AdminToolbox/AdminToolbox/Commands/Player/LockDoorsCommand.cs index a67e68b..934c650 100644 --- a/AdminToolbox/AdminToolbox/Commands/Player/LockDoorsCommand.cs +++ b/AdminToolbox/AdminToolbox/Commands/Player/LockDoorsCommand.cs @@ -32,7 +32,7 @@ public string[] OnCall(ICommandSender sender, string[] args) List myPlayerList = new List(); foreach (Player pl in Server.GetPlayers()) { - if (AdminToolbox.ATPlayerDict.TryGetValue(pl.SteamId, out PlayerSettings psetting) && psetting.lockDoors) + if (AdminToolbox.ATPlayerDict.TryGetValue(pl.UserId, out PlayerSettings psetting) && psetting.lockDoors) myPlayerList.Add(pl.Name); } if (myPlayerList.Count > 0) @@ -71,7 +71,7 @@ public string[] OnCall(ICommandSender sender, string[] args) int pcount = 0; foreach (Player pl in players) { - if (AdminToolbox.ATPlayerDict.TryGetValue(pl.SteamId, out PlayerSettings ps)) + if (AdminToolbox.ATPlayerDict.TryGetValue(pl.UserId, out PlayerSettings ps)) { pcount++; if (enabled.HasValue) diff --git a/AdminToolbox/AdminToolbox/Commands/Player/LockdownCommand.cs b/AdminToolbox/AdminToolbox/Commands/Player/LockdownCommand.cs index 94cba45..d531dc8 100644 --- a/AdminToolbox/AdminToolbox/Commands/Player/LockdownCommand.cs +++ b/AdminToolbox/AdminToolbox/Commands/Player/LockdownCommand.cs @@ -34,7 +34,7 @@ public string[] OnCall(ICommandSender sender, string[] args) foreach (Player pl in Server.GetPlayers()) { AdminToolbox.AddMissingPlayerVariables(pl); - if (AdminToolbox.ATPlayerDict.TryGetValue(pl.SteamId, out PlayerSettings ps)) + if (AdminToolbox.ATPlayerDict.TryGetValue(pl.UserId, out PlayerSettings ps)) { ps.lockDown = j; playerNum++; @@ -51,7 +51,7 @@ public string[] OnCall(ICommandSender sender, string[] args) foreach (Player pl in Server.GetPlayers()) { AdminToolbox.AddMissingPlayerVariables(pl); - if (AdminToolbox.ATPlayerDict.TryGetValue(pl.SteamId, out PlayerSettings ps)) + if (AdminToolbox.ATPlayerDict.TryGetValue(pl.UserId, out PlayerSettings ps)) ps.lockDown = !ps.lockDown; } return new string[] { "Toggled all players Lockdown" }; @@ -63,7 +63,7 @@ public string[] OnCall(ICommandSender sender, string[] args) List myPlayerList = new List(); foreach (Player pl in Server.GetPlayers()) { - if (AdminToolbox.ATPlayerDict.TryGetValue(pl.SteamId, out PlayerSettings pls) && pls.lockDown) + if (AdminToolbox.ATPlayerDict.TryGetValue(pl.UserId, out PlayerSettings pls) && pls.lockDown) { myPlayerList.Add(pl.Name); //str += " - " +pl.Name + "\n"; @@ -83,7 +83,7 @@ public string[] OnCall(ICommandSender sender, string[] args) Player myPlayer = GetPlayerFromString.GetPlayer(args[0]); if (myPlayer == null) { return new string[] { "Couldn't find player: " + args[0] }; } AdminToolbox.AddMissingPlayerVariables(myPlayer); - if (AdminToolbox.ATPlayerDict.TryGetValue(myPlayer.SteamId, out PlayerSettings psetting)) + if (AdminToolbox.ATPlayerDict.TryGetValue(myPlayer.UserId, out PlayerSettings psetting)) if (args.Length > 1) { if (bool.TryParse(args[1], out bool g)) psetting.lockDown = g; diff --git a/AdminToolbox/AdminToolbox/Commands/Player/NoDmgCommand.cs b/AdminToolbox/AdminToolbox/Commands/Player/NoDmgCommand.cs index 0d74cae..2484053 100644 --- a/AdminToolbox/AdminToolbox/Commands/Player/NoDmgCommand.cs +++ b/AdminToolbox/AdminToolbox/Commands/Player/NoDmgCommand.cs @@ -34,7 +34,7 @@ public string[] OnCall(ICommandSender sender, string[] args) foreach (Player pl in Server.GetPlayers()) { AdminToolbox.AddMissingPlayerVariables(pl); - if (AdminToolbox.ATPlayerDict.TryGetValue(pl.SteamId, out PlayerSettings ps)) + if (AdminToolbox.ATPlayerDict.TryGetValue(pl.UserId, out PlayerSettings ps)) { ps.dmgOff = j; playerNum++; @@ -50,7 +50,7 @@ public string[] OnCall(ICommandSender sender, string[] args) foreach (Player pl in Server.GetPlayers()) { AdminToolbox.AddMissingPlayerVariables(pl); - if (AdminToolbox.ATPlayerDict.TryGetValue(pl.SteamId, out PlayerSettings ps)) + if (AdminToolbox.ATPlayerDict.TryGetValue(pl.UserId, out PlayerSettings ps)) ps.dmgOff = !ps.dmgOff; } return new string[] { "Toggled all player's \"No Dmg\"" }; @@ -62,7 +62,7 @@ public string[] OnCall(ICommandSender sender, string[] args) List myPlayerList = new List(); foreach (Player pl in Server.GetPlayers()) { - if (AdminToolbox.ATPlayerDict.TryGetValue(pl.SteamId, out PlayerSettings pls) && pls.dmgOff) + if (AdminToolbox.ATPlayerDict.TryGetValue(pl.UserId, out PlayerSettings pls) && pls.dmgOff) myPlayerList.Add(pl.Name); } if (myPlayerList.Count > 0) @@ -79,7 +79,7 @@ public string[] OnCall(ICommandSender sender, string[] args) Player myPlayer = GetPlayerFromString.GetPlayer(args[0]); if (myPlayer == null) { return new string[] { "Couldn't get player: " + args[0] }; } AdminToolbox.AddMissingPlayerVariables(myPlayer); - if (AdminToolbox.ATPlayerDict.TryGetValue(myPlayer.SteamId, out PlayerSettings psetting)) + if (AdminToolbox.ATPlayerDict.TryGetValue(myPlayer.UserId, out PlayerSettings psetting)) if (args.Length > 1) { bool changedValue = false; diff --git a/AdminToolbox/AdminToolbox/Commands/Player/PlayerCommand.cs b/AdminToolbox/AdminToolbox/Commands/Player/PlayerCommand.cs index e94e366..6e18ed2 100644 --- a/AdminToolbox/AdminToolbox/Commands/Player/PlayerCommand.cs +++ b/AdminToolbox/AdminToolbox/Commands/Player/PlayerCommand.cs @@ -15,7 +15,7 @@ public class PlayerCommand : ICommandHandler private Server Server => PluginManager.Manager.Server; public string GetCommandDescription() => "Gets toolbox info about spesific player"; - public string GetUsage() => "(" + string.Join(" / ", CommandAliases) + ") [PLAYERNAME/ID/STEAMID]"; + public string GetUsage() => "(" + string.Join(" / ", CommandAliases) + ") [PLAYERNAME/ID/UserId]"; public static readonly string[] CommandAliases = new string[] { "PLAYER", "P", "PLAYERINFO", "PINFO" }; @@ -51,26 +51,26 @@ public string[] OnCall(ICommandSender sender, string[] args) //Handling player stats AdminToolbox.AddMissingPlayerVariables(myPlayer); - AdminToolbox.atfileManager.PlayerStatsFileManager(myPlayer.SteamId, Managers.ATFileManager.PlayerFile.Write); - PlayerSettings playerDict = AdminToolbox.ATPlayerDict.TryGetValue(myPlayer.SteamId, out PlayerSettings ps) ? ps : new PlayerSettings(myPlayer.SteamId); + AdminToolbox.atfileManager.PlayerStatsFileManager(myPlayer.UserId, Managers.ATFileManager.PlayerFile.Write); + PlayerSettings playerDict = AdminToolbox.ATPlayerDict.TryGetValue(myPlayer.UserId, out PlayerSettings ps) ? ps : new PlayerSettings(myPlayer.UserId); //Inventory string playerInv = string.Empty; - foreach (SMItem i in myPlayer.GetInventory().Where(i => i.ItemType != ItemType.NULL)) + foreach (SMItem i in myPlayer.GetInventory().Where(i => i.ItemType != Smod2.API.ItemType.NULL)) playerInv += i.ItemType + ", "; if (playerInv == string.Empty) playerInv = "Empty Inventory"; //Calculating remaining jail time int remainingJailTime = ((int)playerDict.JailedToTime.Subtract(DateTime.Now).TotalSeconds >= 0) ? (int)playerDict.JailedToTime.Subtract(DateTime.Now).TotalSeconds : 0; - string _playerRole = sender.IsPlayer() ? myPlayer.ToColoredRichTextRole() : myPlayer.TeamRole.Role + ""; + string _playerRole = sender.IsPlayer() ? myPlayer.ToColoredRichTextRole() : (myPlayer.TeamRole.Role == Smod2.API.RoleType.SCP_457 ? Smod2.API.RoleType.UNASSIGNED : myPlayer.TeamRole.Role) + ""; string _roleColor = myPlayer.GetUserGroup().Color ?? "default"; string _serverRole = myPlayer.GetRankName() ?? ""; //Building string string playerInfoString = Environment.NewLine + Environment.NewLine + "Player: (" + myPlayer.PlayerId + ") " + myPlayer.Name + Environment.NewLine + - BuildTwoLiner(" - SteamID: " + myPlayer.SteamId, " - IP: " + myPlayer.IpAddress.Replace("::ffff:", string.Empty)) + Environment.NewLine + + BuildTwoLiner(" - UserId: " + myPlayer.UserId, " - IP: " + myPlayer.IpAddress.Replace("::ffff:", string.Empty)) + Environment.NewLine + BuildTwoLiner(" - Server Rank: " + "" + _serverRole + "") + Environment.NewLine + BuildTwoLiner(" - Role: " + _playerRole, " - Health: " + myPlayer.GetHealth()) + Environment.NewLine + BuildTwoLiner(" - AdminToolbox Toggables: ") + Environment.NewLine + diff --git a/AdminToolbox/AdminToolbox/Commands/Player/RoleCommand.cs b/AdminToolbox/AdminToolbox/Commands/Player/RoleCommand.cs index 76fab33..70db2b3 100644 --- a/AdminToolbox/AdminToolbox/Commands/Player/RoleCommand.cs +++ b/AdminToolbox/AdminToolbox/Commands/Player/RoleCommand.cs @@ -26,13 +26,13 @@ public string[] OnCall(ICommandSender sender, string[] args) { if (args.Length > 1) { - if (int.TryParse(args[1], out int j) && Utility.TryParseRole(j, out Role spesifiedRole)) + if (int.TryParse(args[1], out int j) && Utility.TryParseRole(j, out Smod2.API.RoleType spesifiedRole)) { int playerNum = 0; foreach (Player pl in Server.GetPlayers()) { Vector originalPos = pl.GetPosition(); - if (pl.TeamRole.Role == Role.UNASSIGNED || pl.TeamRole.Role == Role.SPECTATOR) + if (pl.TeamRole.Role == Smod2.API.RoleType.UNASSIGNED || pl.TeamRole.Role == Smod2.API.RoleType.SPECTATOR) pl.ChangeRole(spesifiedRole, true, true); else { @@ -58,11 +58,11 @@ public string[] OnCall(ICommandSender sender, string[] args) if (myPlayer == null) { return new string[] { "Couldn't get player: " + args[0] }; } if (args.Length > 1) { - if (int.TryParse(args[1], out int j) && Utility.TryParseRole(j, out Role spesifiedRole)) + if (int.TryParse(args[1], out int j) && Utility.TryParseRole(j, out Smod2.API.RoleType spesifiedRole)) { TeamRole oldRole = myPlayer.TeamRole; Vector originalPos = myPlayer.GetPosition(); - bool tele = myPlayer.TeamRole.Role == Role.UNASSIGNED || myPlayer.TeamRole.Role == Role.SPECTATOR; + bool tele = myPlayer.TeamRole.Role == Smod2.API.RoleType.UNASSIGNED || myPlayer.TeamRole.Role == Smod2.API.RoleType.SPECTATOR; myPlayer.ChangeRole(spesifiedRole, true, tele); if (tele) myPlayer.Teleport(originalPos, true); diff --git a/AdminToolbox/AdminToolbox/Commands/Player/SpectatorCommand.cs b/AdminToolbox/AdminToolbox/Commands/Player/SpectatorCommand.cs index 8b14d81..6b76df0 100644 --- a/AdminToolbox/AdminToolbox/Commands/Player/SpectatorCommand.cs +++ b/AdminToolbox/AdminToolbox/Commands/Player/SpectatorCommand.cs @@ -32,7 +32,7 @@ public string[] OnCall(ICommandSender sender, string[] args) foreach (Player player in Server.GetPlayers()) { AdminToolbox.AddMissingPlayerVariables(player); - if (AdminToolbox.ATPlayerDict.TryGetValue(player.SteamId, out PlayerSettings ps)) + if (AdminToolbox.ATPlayerDict.TryGetValue(player.UserId, out PlayerSettings ps)) { ps.overwatchMode = j; player.OverwatchMode = j; @@ -52,7 +52,7 @@ public string[] OnCall(ICommandSender sender, string[] args) int playerNum = 0; foreach (Player pl in Server.GetPlayers()) { - if (AdminToolbox.ATPlayerDict.TryGetValue(pl.SteamId, out PlayerSettings plsett)) + if (AdminToolbox.ATPlayerDict.TryGetValue(pl.UserId, out PlayerSettings plsett)) { plsett.overwatchMode = !plsett.overwatchMode; pl.OverwatchMode = !pl.OverwatchMode; @@ -68,7 +68,7 @@ public string[] OnCall(ICommandSender sender, string[] args) List myPlayerList = new List(); foreach (Player pl in Server.GetPlayers()) { - if (AdminToolbox.ATPlayerDict.TryGetValue(pl.SteamId, out PlayerSettings plsett) && plsett.overwatchMode) + if (AdminToolbox.ATPlayerDict.TryGetValue(pl.UserId, out PlayerSettings plsett) && plsett.overwatchMode) myPlayerList.Add(pl.Name); } if (myPlayerList.Count > 0) @@ -83,7 +83,7 @@ public string[] OnCall(ICommandSender sender, string[] args) Player myPlayer = GetPlayerFromString.GetPlayer(args[0]); if (myPlayer == null) { return new string[] { "Couldn't find player: " + args[0] }; } AdminToolbox.AddMissingPlayerVariables(myPlayer); - if (AdminToolbox.ATPlayerDict.TryGetValue(myPlayer.SteamId, out PlayerSettings psetting)) + if (AdminToolbox.ATPlayerDict.TryGetValue(myPlayer.UserId, out PlayerSettings psetting)) if (args.Length > 1) { if (args[1].ToLower() == "on" || args[1].ToLower() == "true") { psetting.overwatchMode = true; myPlayer.OverwatchMode = true; } diff --git a/AdminToolbox/AdminToolbox/Commands/Player/TutorialCommand.cs b/AdminToolbox/AdminToolbox/Commands/Player/TutorialCommand.cs index d51cf3c..0ab880d 100644 --- a/AdminToolbox/AdminToolbox/Commands/Player/TutorialCommand.cs +++ b/AdminToolbox/AdminToolbox/Commands/Player/TutorialCommand.cs @@ -41,12 +41,12 @@ public string[] OnCall(ICommandSender sender, string[] args) { if (pl == null) continue; Vector originalPos2 = pl.GetPosition(); - Vector newPos2 = pl.TeamRole.Role == Role.SPECTATOR ? AdminToolbox.WarpVectorDict.TryGetVector("tutorial", out Vector vector2) ? vector2 : null : originalPos2; - pl.ChangeRole(Role.TUTORIAL, spawnTeleport: newPos2 == null, removeHandcuffs: true); + Vector newPos2 = pl.TeamRole.Role == Smod2.API.RoleType.SPECTATOR ? AdminToolbox.WarpVectorDict.TryGetVector("tutorial", out Vector vector2) ? vector2 : null : originalPos2; + pl.ChangeRole(Smod2.API.RoleType.TUTORIAL, spawnTeleport: newPos2 == null, removeHandcuffs: true); if (newPos2 != null) AdminToolbox.waitForTeleports.Add(new WaitForTeleport { Player = pl, Pos = newPos2, DateTime = DateTime.Now.AddSeconds(1) }); } - return new string[] { $"Set {(players.Length > 1 ? players.Length.ToString() + " players roles " : (players?[0]?.Name ?? "1 player") + "'s role ")}) to {Role.TUTORIAL}" }; + return new string[] { $"Set {(players.Length > 1 ? players.Length.ToString() + " players roles " : (players?[0]?.Name ?? "1 player") + "'s role ")}) to {Smod2.API.RoleType.TUTORIAL}" }; } else return new string[] { GetUsage() }; diff --git a/AdminToolbox/AdminToolbox/Commands/Server/PlayerListCommand.cs b/AdminToolbox/AdminToolbox/Commands/Server/PlayerListCommand.cs index d63e698..d00e83b 100644 --- a/AdminToolbox/AdminToolbox/Commands/Server/PlayerListCommand.cs +++ b/AdminToolbox/AdminToolbox/Commands/Server/PlayerListCommand.cs @@ -26,7 +26,7 @@ public string[] OnCall(ICommandSender sender, string[] args) List myPlayerList = new List(); foreach (Player pl in players) { - myPlayerList.Add(pl.TeamRole.Role + "(" + (int)pl.TeamRole.Role + ")" + " " + pl.Name + " IP: " + pl.IpAddress + " STEAMID: " + pl.SteamId + "\n"); + myPlayerList.Add(pl.TeamRole.Role + "(" + (int)pl.TeamRole.Role + ")" + " " + pl.Name + " IP: " + pl.IpAddress + " USERID: " + pl.UserId + "\n"); } myPlayerList.Sort(); foreach (string item in myPlayerList) diff --git a/AdminToolbox/AdminToolbox/Events/MyMiscEvents.cs b/AdminToolbox/AdminToolbox/Events/MyMiscEvents.cs index 0ca5de0..2af7bbb 100644 --- a/AdminToolbox/AdminToolbox/Events/MyMiscEvents.cs +++ b/AdminToolbox/AdminToolbox/Events/MyMiscEvents.cs @@ -13,6 +13,7 @@ namespace AdminToolbox using API; using API.Extentions; using API.Webhook; + using Managers; internal class MyMiscEvents : IEventHandlerIntercom, IEventHandlerDoorAccess, IEventHandlerSpawn, IEventHandlerWaitingForPlayers, IEventHandlerAdminQuery, IEventHandlerLure, IEventHandlerContain106, @@ -38,10 +39,10 @@ public void OnIntercom(PlayerIntercomEvent ev) ev.SpeechTime = 0f; } #region Blacklist - string[] blackListedSTEAMIDS = ConfigManager.Manager.Config.GetListValue("admintoolbox_intercom_steamid_blacklist", new string[] { string.Empty }, false); - if (blackListedSTEAMIDS.Length > 0) - foreach (string item in blackListedSTEAMIDS) - if (item == ev.Player.SteamId) + string[] blackListedUserIdS = ConfigManager.Manager.Config.GetListValue("admintoolbox_intercom_UserId_blacklist", new string[] { string.Empty }, false); + if (blackListedUserIdS.Length > 0) + foreach (string item in blackListedUserIdS) + if (item == ev.Player.UserId) { Debug($"Player \"{ev.Player.Name}\" found in intercom blacklist, denied use."); ev.SpeechTime = 0f; @@ -97,7 +98,7 @@ public void OnDoorAccess(PlayerDoorAccessEvent ev) if (ev.Player != null && ev.Player is Player player) { AdminToolbox.AddMissingPlayerVariables(player); - AdminToolbox.ATPlayerDict.TryGetValue(player.SteamId, out PlayerSettings playerSetting); + AdminToolbox.ATPlayerDict.TryGetValue(player.UserId, out PlayerSettings playerSetting); if (playerSetting != null) { @@ -155,15 +156,15 @@ public void OnSpawn(PlayerSpawnEvent ev) AdminToolbox.AddMissingPlayerVariables(ev.Player); } - if (AdminToolbox.ATPlayerDict.ContainsKey(ev.Player.SteamId)) + if (AdminToolbox.ATPlayerDict.ContainsKey(ev.Player.UserId)) { - PlayerSettings pSettings = AdminToolbox.ATPlayerDict[ev.Player.SteamId]; + PlayerSettings pSettings = AdminToolbox.ATPlayerDict[ev.Player.UserId]; if (pSettings.overwatchMode) { pSettings.DeathPos = ev.SpawnPos; ev.Player.OverwatchMode = true; } - else if (ev.Player.TeamRole.Role != Role.TUTORIAL + else if (ev.Player.TeamRole.Role != Smod2.API.RoleType.TUTORIAL && pSettings.isJailed && !ev.Player.IsInsideJail()) { JailHandler.SendToJail(ev.Player, pSettings.JailedToTime); @@ -172,9 +173,11 @@ public void OnSpawn(PlayerSpawnEvent ev) } private int checkNewVersion = 8; - public void OnWaitingForPlayers(WaitingForPlayersEvent ev) { + ATFileManager.ConvertOldFilesToNewUserID(); + + AdminToolbox.lockRound = false; if (AdminToolbox.isStarting) { @@ -227,7 +230,7 @@ public void OnAdminQuery(AdminQueryEvent ev) public void OnLure(PlayerLureEvent ev) { int[] TUTallowedDmg = Config.GetIntListValue("admintoolbox_tutorial_dmg_allowed", new int[] { -1 }, false); - if ((AdminToolbox.ATPlayerDict.ContainsKey(ev.Player.SteamId) && AdminToolbox.ATPlayerDict[ev.Player.SteamId].godMode) || (ev.Player.TeamRole.Team == Smod2.API.Team.TUTORIAL && !TUTallowedDmg.Contains((int)DamageType.LURE))) + if ((AdminToolbox.ATPlayerDict.ContainsKey(ev.Player.UserId) && AdminToolbox.ATPlayerDict[ev.Player.UserId].godMode) || (ev.Player.TeamRole.Team == Smod2.API.TeamType.TUTORIAL && !TUTallowedDmg.Contains((int)DamageType.LURE))) { ev.AllowContain = false; } @@ -237,7 +240,7 @@ public void OnContain106(PlayerContain106Event ev) { foreach (Player scp106 in ev.SCP106s) { - if (AdminToolbox.ATPlayerDict.ContainsKey(scp106.SteamId) && (AdminToolbox.ATPlayerDict[scp106.SteamId].godMode || AdminToolbox.ATPlayerDict[ev.Player.SteamId].dmgOff)) + if (AdminToolbox.ATPlayerDict.ContainsKey(scp106.UserId) && (AdminToolbox.ATPlayerDict[scp106.UserId].godMode || AdminToolbox.ATPlayerDict[ev.Player.UserId].dmgOff)) { ev.ActivateContainment = false; break; @@ -255,11 +258,11 @@ public void OnPlayerJoin(PlayerJoinEvent ev) if (Config.GetBoolValue("admintoolbox_player_join_info_extended", true, false)) { - int bancount = AdminToolbox.ATPlayerDict.ContainsKey(player.SteamId) ? AdminToolbox.ATPlayerDict[player.SteamId].PlayerStats.BanCount : 0; + int bancount = AdminToolbox.ATPlayerDict.ContainsKey(player.UserId) ? AdminToolbox.ATPlayerDict[player.UserId].PlayerStats.BanCount : 0; string str = Environment.NewLine + ev.Player.Name + " joined as player (" + player.PlayerId + ")" + Environment.NewLine + "From IP: " + player.IpAddress.Replace("::ffff:", string.Empty) + Environment.NewLine + - "Using steamID: " + player.SteamId + Environment.NewLine; + "Using UserId: " + player.UserId + Environment.NewLine; if (bancount > 0) str += "Player has: \"" + bancount + "\" ban(s) on record" + Environment.NewLine; plugin.Info(str); } @@ -267,13 +270,13 @@ public void OnPlayerJoin(PlayerJoinEvent ev) { plugin.Info(player.Name + " just joined the server!"); } - if (AdminToolbox.ATPlayerDict.ContainsKey(player.SteamId)) + if (AdminToolbox.ATPlayerDict.ContainsKey(player.UserId)) { - if (AdminToolbox.ATPlayerDict[player.SteamId].overwatchMode) + if (AdminToolbox.ATPlayerDict[player.UserId].overwatchMode) { ev.Player.OverwatchMode = true; } - AdminToolbox.ATPlayerDict[player.SteamId].JoinTime = DateTime.Now; + AdminToolbox.ATPlayerDict[player.UserId].JoinTime = DateTime.Now; } } } @@ -356,13 +359,13 @@ public void OnSetServerName(SetServerNameEvent ev) public void OnHandcuffed(PlayerHandcuffedEvent ev) { - PlayerSettings playerSetting = Dict.ContainsKey(ev.Player.SteamId) ? Dict[ev.Player.SteamId] : null; + PlayerSettings playerSetting = Dict.ContainsKey(ev.Player.UserId) ? Dict[ev.Player.UserId] : null; if (ev.Player.GetGodmode() || (playerSetting?.godMode ?? false)) { ev.Allow = false; } - else if (ev.Player.TeamRole.Role == Role.TUTORIAL && !Config.GetBoolValue("admintoolbox_tutorial_canbehandcuffed", false)) + else if (ev.Player.TeamRole.Role == Smod2.API.RoleType.TUTORIAL && !Config.GetBoolValue("admintoolbox_tutorial_canbehandcuffed", false)) { ev.Allow = false; } @@ -381,7 +384,7 @@ public void OnBan(BanEvent ev) if (!string.IsNullOrEmpty(ev.Reason)) listOfFields.AddField("Reason: ", ev.Reason); if (Config.GetBoolValue("admintoolbox_ban_webhook_include_admin", false)) - listOfFields.AddField("Issued By: ", ev.Admin.Name ?? "Server"); + listOfFields.AddField("Issued By: ", ev.Issuer ?? "Server"); webH = new DiscordWebhook { embeds = new EmbedData[] { new EmbedData { author = new Author { name = "User Banned: " }, title = "", fields = listOfFields.ToArray() } } }; @@ -396,10 +399,10 @@ public void OnBan(BanEvent ev) AdminToolbox.AddMissingPlayerVariables(ev.Player); } - if (AdminToolbox.ATPlayerDict.ContainsKey(ev.Player.SteamId) && ev.Duration > 1) + if (AdminToolbox.ATPlayerDict.ContainsKey(ev.Player.UserId) && ev.Duration > 1) { - AdminToolbox.ATPlayerDict[ev.Player.SteamId].PlayerStats.BanCount++; - AdminToolbox.atfileManager.PlayerStatsFileManager(ev.Player.SteamId); + AdminToolbox.ATPlayerDict[ev.Player.UserId].PlayerStats.BanCount++; + AdminToolbox.atfileManager.PlayerStatsFileManager(ev.Player.UserId); } } @@ -411,31 +414,31 @@ public void OnTeamRespawn(TeamRespawnEvent ev) public void OnThrowGrenade(PlayerThrowGrenadeEvent ev) { - if (AdminToolbox.ATPlayerDict.TryGetValue(ev.Player.SteamId, out PlayerSettings ps)) + if (AdminToolbox.ATPlayerDict.TryGetValue(ev.Player.UserId, out PlayerSettings ps)) { if (ps.isJailed || ps.lockDown) ev.Allow = false; - else if (ps.grenadeMode || ps.InfiniteItem == ItemType.FRAG_GRENADE || ps.InfiniteItem == ItemType.FLASHBANG) - ev.Player.GiveItem((ev.GrenadeType == GrenadeType.FRAG_GRENADE) ? ItemType.FRAG_GRENADE : ItemType.FLASHBANG); + else if (ps.grenadeMode || ps.InfiniteItem == Smod2.API.ItemType.FRAG_GRENADE || ps.InfiniteItem == Smod2.API.ItemType.FLASHBANG) + ev.Player.GiveItem((ev.GrenadeType == GrenadeType.FRAG_GRENADE) ? Smod2.API.ItemType.FRAG_GRENADE : Smod2.API.ItemType.FLASHBANG); } } public void OnPlayerDropItem(PlayerDropItemEvent ev) { - if (AdminToolbox.ATPlayerDict.TryGetValue(ev.Player.SteamId, out PlayerSettings ps)) + if (AdminToolbox.ATPlayerDict.TryGetValue(ev.Player.UserId, out PlayerSettings ps)) { if (ps.isJailed || ps.lockDown) ev.Allow = false; - else if (ps.InfiniteItem != ItemType.NULL && ev.Item.ItemType == ps.InfiniteItem) + else if (ps.InfiniteItem != Smod2.API.ItemType.NULL && ev.Item.ItemType == ps.InfiniteItem) ev.Player.GiveItem(ps.InfiniteItem); - else if (ps.grenadeMode && ev.Item.ItemType == ItemType.FRAG_GRENADE) - ev.Player.GiveItem(ItemType.FRAG_GRENADE); + else if (ps.grenadeMode && ev.Item.ItemType == Smod2.API.ItemType.FRAG_GRENADE) + ev.Player.GiveItem(Smod2.API.ItemType.FRAG_GRENADE); } } public void OnReload(PlayerReloadEvent ev) { - if (AdminToolbox.ATPlayerDict.TryGetValue(ev.Player.SteamId, out PlayerSettings ps) && ps.InfiniteItem != ItemType.NULL) + if (AdminToolbox.ATPlayerDict.TryGetValue(ev.Player.UserId, out PlayerSettings ps) && ps.InfiniteItem != Smod2.API.ItemType.NULL) if (ps.InfiniteItem.ToString().Contains("DROPPED")) foreach (AmmoType ammo in Enum.GetValues(typeof(AmmoType))) if (ammo.ToString() == ps.InfiniteItem.ToString()) @@ -450,9 +453,9 @@ public class LateEscapeEventCheck : IEventHandlerCheckEscape { public void OnCheckEscape(PlayerCheckEscapeEvent ev) { - if (ev.AllowEscape && AdminToolbox.ATPlayerDict.ContainsKey(ev.Player.SteamId)) + if (ev.AllowEscape && AdminToolbox.ATPlayerDict.ContainsKey(ev.Player.UserId)) { - AdminToolbox.ATPlayerDict[ev.Player.SteamId].PlayerStats.EscapeCount++; + AdminToolbox.ATPlayerDict[ev.Player.UserId].PlayerStats.EscapeCount++; } } } diff --git a/AdminToolbox/AdminToolbox/Events/PlayerDamageEvent.cs b/AdminToolbox/AdminToolbox/Events/PlayerDamageEvent.cs index ad2f37f..dbe679a 100644 --- a/AdminToolbox/AdminToolbox/Events/PlayerDamageEvent.cs +++ b/AdminToolbox/AdminToolbox/Events/PlayerDamageEvent.cs @@ -58,8 +58,8 @@ public void OnPlayerHurt(PlayerHurtEvent ev) { AdminToolbox.AddMissingPlayerVariables(new Player[] { ev.Attacker, ev.Player }); - Dict.TryGetValue(ev.Player.SteamId, out PlayerSettings playerSetting); - Dict.TryGetValue(ev.Attacker.SteamId, out PlayerSettings attackerSetting); + Dict.TryGetValue(ev.Player.UserId, out PlayerSettings playerSetting); + Dict.TryGetValue(ev.Attacker.UserId, out PlayerSettings attackerSetting); float originalDamage = ev.Damage; DamageType originalType = ev.DamageType; @@ -74,7 +74,7 @@ public void OnPlayerHurt(PlayerHurtEvent ev) int[] allowedTutDmg = new int[] { -1 }; - if (ev.Player.TeamRole.Role == Role.TUTORIAL) + if (ev.Player.TeamRole.Role == Smod2.API.RoleType.TUTORIAL) allowedTutDmg = CalculateTutorialDamage(); int[] DebugDmg = Config.GetIntListValue("admintoolbox_debug_damagetypes", Utility.HumanDamageTypes, false); @@ -104,14 +104,14 @@ public void OnPlayerHurt(PlayerHurtEvent ev) foreach (string item in roleDamages) { string[] myStringKey = item.Trim().Split(':'); - if (int.TryParse(myStringKey[0], out int attackerIntRole) && Utility.TryParseRole(attackerIntRole, out Role attackerRole)) + if (int.TryParse(myStringKey[0], out int attackerIntRole) && Utility.TryParseRole(attackerIntRole, out Smod2.API.RoleType attackerRole)) { string[] myString = myStringKey[1].Split('.', '-', '#', '_', ',', '+', '@', '>', '<', ';'); if (myString.Length >= 1) { foreach (string item2 in myString) { - if (int.TryParse(item2, out int victimIntRole) && Utility.TryParseRole(victimIntRole, out Role victimRole)) + if (int.TryParse(item2, out int victimIntRole) && Utility.TryParseRole(victimIntRole, out Smod2.API.RoleType victimRole)) { if (attackerRole == ev.Attacker.TeamRole.Role && victimRole == ev.Player.TeamRole.Role) { @@ -148,7 +148,7 @@ public void OnPlayerHurt(PlayerHurtEvent ev) } switch (ev.Player.TeamRole.Role) { - case Role.TUTORIAL: + case Smod2.API.RoleType.TUTORIAL: if (allowedTutDmg.Contains((int)ev.DamageType) || allowedTutDmg.Contains(-2)) goto default; if (DebugDmg.Contains((int)ev.DamageType) && Config.GetBoolValue("admintoolbox_debug_tutorial", false, false)) @@ -204,8 +204,8 @@ public class DieDetect : IEventHandlerPlayerDie public void OnPlayerDie(PlayerDeathEvent ev) { AdminToolbox.AddMissingPlayerVariables(new Player[] { ev.Player, ev.Killer }); - Dict.TryGetValue(ev.Player.SteamId, out PlayerSettings playerSetting); - Dict.TryGetValue(ev.Killer.SteamId, out PlayerSettings killerSetting); + Dict.TryGetValue(ev.Player.UserId, out PlayerSettings playerSetting); + Dict.TryGetValue(ev.Killer.UserId, out PlayerSettings killerSetting); switch ((int)ev.Player.TeamRole.Role) { diff --git a/AdminToolbox/AdminToolbox/Managers/ATFileManager.cs b/AdminToolbox/AdminToolbox/Managers/ATFileManager.cs index 400ceef..5eb41e3 100644 --- a/AdminToolbox/AdminToolbox/Managers/ATFileManager.cs +++ b/AdminToolbox/AdminToolbox/Managers/ATFileManager.cs @@ -44,7 +44,7 @@ private static string GetATFolderPath() } else { - cnfgpath = FileManager.GetAppFolder(shared: true, addseparator: true) + "AdminToolbox" + Path.DirectorySeparatorChar; + cnfgpath = FileManager.GetAppFolder(addSeparator: true) + "AdminToolbox" + Path.DirectorySeparatorChar; } if (!Directory.Exists(cnfgpath)) Directory.CreateDirectory(cnfgpath); @@ -76,7 +76,7 @@ internal static string GetFolderPath(Folder folder = Folder.ATRoot) break; case Folder.AppData: - return FileManager.GetAppFolder(shared: true, addseparator: true); + return FileManager.GetAppFolder(addSeparator: true); case Folder.ATRoot: default: @@ -102,14 +102,14 @@ internal static string GetFolderPath(Folder folder = Folder.ATRoot) public void PlayerStatsFileManager(PlayerFile FileOperation = PlayerFile.Read) => PlayerStatsFileManager(new string[] { }, FileOperation); /// - /// Read/Writes the 's stats to/from + /// Read/Writes the 's stats to/from /// - public void PlayerStatsFileManager(string steamID, PlayerFile FileOperation = PlayerFile.Write) => PlayerStatsFileManager(new string[] { steamID }, FileOperation); + public void PlayerStatsFileManager(string UserId, PlayerFile FileOperation = PlayerFile.Write) => PlayerStatsFileManager(new string[] { UserId }, FileOperation); /// /// Read/Writes stats to/from /// - public void PlayerStatsFileManager(Player player, PlayerFile FileOperation = PlayerFile.Write) => PlayerStatsFileManager(new string[] { player.SteamId }, FileOperation); + public void PlayerStatsFileManager(Player player, PlayerFile FileOperation = PlayerFile.Write) => PlayerStatsFileManager(new string[] { player.UserId }, FileOperation); /// /// Read/Writes stats to/from for each in the @@ -117,27 +117,29 @@ internal static string GetFolderPath(Folder folder = Folder.ATRoot) public void PlayerStatsFileManager(List playerList, PlayerFile FileOperation = PlayerFile.Read) { if (playerList != null && playerList.Count > 0) - PlayerStatsFileManager(playerList.Select(p => p.SteamId).ToArray(), FileOperation); + PlayerStatsFileManager(playerList.Select(p => p.UserId).ToArray(), FileOperation); else PlayerStatsFileManager(FileOperation); } /// - /// Read/Writes stats to/from for each steamID in the + /// Read/Writes stats to/from for each UserId in the /// - public void PlayerStatsFileManager(List steamIdList, PlayerFile FileOperation = PlayerFile.Read) + public void PlayerStatsFileManager(List UserIdList, PlayerFile FileOperation = PlayerFile.Read) { - if (steamIdList != null && steamIdList.Count > 0) - PlayerStatsFileManager(steamIdList.ToArray(), FileOperation); + if (UserIdList != null && UserIdList.Count > 0) + PlayerStatsFileManager(UserIdList.ToArray(), FileOperation); else PlayerStatsFileManager(new string[0], FileOperation); } /// - /// Read/Writes stats to/from for each steamID in the + /// Read/Writes stats to/from for each UserId in the /// - public void PlayerStatsFileManager(string[] steamIdArray, PlayerFile FileOperation = PlayerFile.Read) + public void PlayerStatsFileManager(string[] UserIdArray, PlayerFile FileOperation = PlayerFile.Read) { + if (!Config.GetBoolValue("admintoolbox_playerfiles", false)) + return; if (Directory.Exists(AdminToolboxFolder)) { if (!Directory.Exists(AdminToolboxFolder)) @@ -147,51 +149,51 @@ public void PlayerStatsFileManager(string[] steamIdArray, PlayerFile FileOperati ProcessingCollection = true; - if (steamIdArray != null && steamIdArray.Length > 0) - foreach (string sid in steamIdArray) + if (UserIdArray != null && UserIdArray.Length > 0) + foreach (string sid in UserIdArray) ReadWriteHandler(sid, FileOperation); else { string[] keys = AdminToolbox.ATPlayerDict.Keys.ToArray(); - foreach (string steamID in keys) - ReadWriteHandler(steamID, FileOperation); + foreach (string UserId in keys) + ReadWriteHandler(UserId, FileOperation); } ProcessingCollection = false; - void ReadWriteHandler(string steamID, PlayerFile Operation) + void ReadWriteHandler(string UserId, PlayerFile Operation) { - if (string.IsNullOrEmpty(steamID)) return; - if (!AdminToolbox.ATPlayerDict.ContainsKey(steamID)) + if (string.IsNullOrEmpty(UserId)) return; + if (!AdminToolbox.ATPlayerDict.ContainsKey(UserId)) { - AdminToolbox.AddMissingPlayerVariables(PluginManager.Manager.Server.GetPlayers(steamID)); + AdminToolbox.AddMissingPlayerVariables(PluginManager.Manager.Server.GetPlayers(UserId)); return; } switch (Operation) { case PlayerFile.Write: - WriteToFile(steamID); + WriteToFile(UserId); break; case PlayerFile.Read: default: - ReadFromFile(steamID); + ReadFromFile(UserId); break; } } #region NewFilesStuff /* - void NewWriteToFile(string steamID) + void NewWriteToFile(string UserId) { - if (!AdminToolbox.ATPlayerDict.ContainsKey(steamID)) return; - string playerFilePath = AdminToolboxPlayerStats + steamID + ".txt"; + if (!AdminToolbox.ATPlayerDict.ContainsKey(UserId)) return; + string playerFilePath = AdminToolboxPlayerStats + UserId + ".txt"; if (!File.Exists(playerFilePath)) File.Create(playerFilePath).Dispose(); if (File.ReadAllLines(playerFilePath).Length <= 2) ConvertOldFilesToJSON(playerFilePath); - SerilizablePlayerClass pl = new SerilizablePlayerClass(AdminToolbox.ATPlayerDict[steamID]); + SerilizablePlayerClass pl = new SerilizablePlayerClass(AdminToolbox.ATPlayerDict[UserId]); if (string.IsNullOrEmpty(pl.PlayerInfo.FirstJoin)) pl.PlayerInfo.FirstJoin = DateTime.Now.AddMinutes(-pl.PlayerStats.MinutesPlayed).ToString(CultureInfo.InvariantCulture); @@ -201,14 +203,14 @@ void NewWriteToFile(string steamID) sw.WriteLine(JsonConvert.SerializeObject(pl, Formatting.Indented)); } - NewReadFromFile(steamID); + NewReadFromFile(UserId); } - void NewReadFromFile(string steamID) + void NewReadFromFile(string UserId) { - if (!AdminToolbox.ATPlayerDict.ContainsKey(steamID)) return; - string playerFilePath = AdminToolboxPlayerStats + steamID + ".txt"; + if (!AdminToolbox.ATPlayerDict.ContainsKey(UserId)) return; + string playerFilePath = AdminToolboxPlayerStats + UserId + ".txt"; if (!File.Exists(playerFilePath)) - WriteToFile(steamID); + WriteToFile(UserId); if (File.ReadAllLines(playerFilePath).FirstOrDefault().Split(splitChar).Length > 3) ConvertOldFilesToJSON(playerFilePath); @@ -216,7 +218,7 @@ void NewReadFromFile(string steamID) string rawJSON = File.ReadAllText(playerFilePath); SerilizablePlayerClass pl = JsonConvert.DeserializeObject(rawJSON); - PlayerSettings playersetting = AdminToolbox.ATPlayerDict[steamID]; + PlayerSettings playersetting = AdminToolbox.ATPlayerDict[UserId]; if (string.IsNullOrEmpty(pl.PlayerInfo.FirstJoin)) playersetting.PlayerInfo.FirstJoin = DateTime.Now.AddMinutes(-pl.PlayerStats.MinutesPlayed).ToString(CultureInfo.InvariantCulture); @@ -225,56 +227,107 @@ void NewReadFromFile(string steamID) */ #endregion - void WriteToFile(string steamID) + void WriteToFile(string UserId) { - if (!AdminToolbox.ATPlayerDict.ContainsKey(steamID)) + if (!AdminToolbox.ATPlayerDict.ContainsKey(UserId)) { - if (PluginManager.Manager.Server.GetPlayers(steamID).Count < 1) return; - AdminToolbox.AddMissingPlayerVariables(PluginManager.Manager.Server.GetPlayers(steamID).FirstOrDefault()); + if (PluginManager.Manager.Server.GetPlayers(UserId).Count < 1) return; + AdminToolbox.AddMissingPlayerVariables(PluginManager.Manager.Server.GetPlayers(UserId).FirstOrDefault()); } - if (!AdminToolbox.ATPlayerDict.ContainsKey(steamID)) return; - string playerFilePath = AdminToolbox.ATPlayerDict.ContainsKey(steamID) ? AdminToolboxPlayerStats + Path.DirectorySeparatorChar + steamID + ".txt" : AdminToolboxPlayerStats + Path.DirectorySeparatorChar + "server" + ".txt"; + if (!AdminToolbox.ATPlayerDict.ContainsKey(UserId)) return; + string playerFilePath = AdminToolbox.ATPlayerDict.ContainsKey(UserId) ? AdminToolboxPlayerStats + Path.DirectorySeparatorChar + UserId + ".txt" : AdminToolboxPlayerStats + Path.DirectorySeparatorChar + "server" + ".txt"; if (!File.Exists(playerFilePath)) File.Create(playerFilePath).Dispose(); - - PlayerSettings setting = AdminToolbox.ATPlayerDict.ContainsKey(steamID) ? AdminToolbox.ATPlayerDict[steamID] : new API.PlayerSettings(steamID); - int Kills = (AdminToolbox.ATPlayerDict.ContainsKey(steamID) && AdminToolbox.ATPlayerDict[steamID].PlayerStats.Kills > 0) ? AdminToolbox.ATPlayerDict[steamID].PlayerStats.Kills : 0; - int TeamKills = (AdminToolbox.ATPlayerDict.ContainsKey(steamID) && AdminToolbox.ATPlayerDict[steamID].PlayerStats.TeamKills > 0) ? AdminToolbox.ATPlayerDict[steamID].PlayerStats.TeamKills : 0; - int Deaths = (AdminToolbox.ATPlayerDict.ContainsKey(steamID) && AdminToolbox.ATPlayerDict[steamID].PlayerStats.Deaths > 0) ? AdminToolbox.ATPlayerDict[steamID].PlayerStats.Deaths : 0; - double minutesPlayed = (AdminToolbox.ATPlayerDict.ContainsKey(steamID) && AdminToolbox.ATPlayerDict[steamID].PlayerStats.MinutesPlayed > 0) ? DateTime.Now.Subtract(AdminToolbox.ATPlayerDict[steamID].JoinTime).TotalMinutes + AdminToolbox.ATPlayerDict[steamID].PlayerStats.MinutesPlayed : 0; - int BanCount = (AdminToolbox.ATPlayerDict.ContainsKey(steamID) && AdminToolbox.ATPlayerDict[steamID].PlayerStats.BanCount > 0) ? AdminToolbox.ATPlayerDict[steamID].PlayerStats.BanCount : 0; - if (AdminToolbox.ATPlayerDict.ContainsKey(steamID)) AdminToolbox.ATPlayerDict[steamID].JoinTime = DateTime.Now; + AdminToolbox.singleton.Debug("Writing: " + playerFilePath); + + PlayerSettings setting = AdminToolbox.ATPlayerDict.ContainsKey(UserId) ? AdminToolbox.ATPlayerDict[UserId] : new API.PlayerSettings(UserId); + int Kills = (AdminToolbox.ATPlayerDict.ContainsKey(UserId) && AdminToolbox.ATPlayerDict[UserId].PlayerStats.Kills > 0) ? AdminToolbox.ATPlayerDict[UserId].PlayerStats.Kills : 0; + int TeamKills = (AdminToolbox.ATPlayerDict.ContainsKey(UserId) && AdminToolbox.ATPlayerDict[UserId].PlayerStats.TeamKills > 0) ? AdminToolbox.ATPlayerDict[UserId].PlayerStats.TeamKills : 0; + int Deaths = (AdminToolbox.ATPlayerDict.ContainsKey(UserId) && AdminToolbox.ATPlayerDict[UserId].PlayerStats.Deaths > 0) ? AdminToolbox.ATPlayerDict[UserId].PlayerStats.Deaths : 0; + double minutesPlayed = (AdminToolbox.ATPlayerDict.ContainsKey(UserId) && AdminToolbox.ATPlayerDict[UserId].PlayerStats.MinutesPlayed > 0) ? DateTime.Now.Subtract(AdminToolbox.ATPlayerDict[UserId].JoinTime).TotalMinutes + AdminToolbox.ATPlayerDict[UserId].PlayerStats.MinutesPlayed : 0; + int BanCount = (AdminToolbox.ATPlayerDict.ContainsKey(UserId) && AdminToolbox.ATPlayerDict[UserId].PlayerStats.BanCount > 0) ? AdminToolbox.ATPlayerDict[UserId].PlayerStats.BanCount : 0; + if (AdminToolbox.ATPlayerDict.ContainsKey(UserId)) AdminToolbox.ATPlayerDict[UserId].JoinTime = DateTime.Now; string str = string.Empty + Kills + SplitChar + TeamKills + SplitChar + Deaths + SplitChar + minutesPlayed + SplitChar + BanCount; using (StreamWriter streamWriter = new StreamWriter(playerFilePath, false)) { streamWriter.Write(str); streamWriter.Close(); } - ReadFromFile(steamID); + ReadFromFile(UserId); } - void ReadFromFile(string steamID) + void ReadFromFile(string UserId) { - string playerFilePath = AdminToolbox.ATPlayerDict.ContainsKey(steamID) ? AdminToolboxPlayerStats + Path.DirectorySeparatorChar + steamID + ".txt" : AdminToolboxPlayerStats + Path.DirectorySeparatorChar + "server" + ".txt"; + string playerFilePath = AdminToolbox.ATPlayerDict.ContainsKey(UserId) ? AdminToolboxPlayerStats + Path.DirectorySeparatorChar + UserId + ".txt" : AdminToolboxPlayerStats + Path.DirectorySeparatorChar + "server" + ".txt"; if (!File.Exists(playerFilePath)) - PlayerStatsFileManager(new List { steamID }, PlayerFile.Write); + PlayerStatsFileManager(new List { UserId }, PlayerFile.Write); + AdminToolbox.singleton.Debug("Reading: " + playerFilePath); string[] fileStrings = (File.ReadAllLines(playerFilePath).Length > 0) ? File.ReadAllLines(playerFilePath) : new string[] { "0;0;0;0;0" }; string[] playerStats = fileStrings.FirstOrDefault().Split(SplitChar); - if (AdminToolbox.ATPlayerDict.ContainsKey(steamID)) + if (AdminToolbox.ATPlayerDict.ContainsKey(UserId)) { - PlayerSettings setting = AdminToolbox.ATPlayerDict[steamID]; + PlayerSettings setting = AdminToolbox.ATPlayerDict[UserId]; setting.PlayerStats.Kills = (playerStats.Length > 0 && int.TryParse(playerStats[0], out int x0) && x0 > setting.PlayerStats.Kills) ? x0 : setting.PlayerStats.Kills; setting.PlayerStats.TeamKills = (playerStats.Length > 1 && int.TryParse(playerStats[1], out int x1) && x1 > setting.PlayerStats.TeamKills) ? x1 : setting.PlayerStats.TeamKills; setting.PlayerStats.Deaths = (playerStats.Length > 2 && int.TryParse(playerStats[2], out int x2) && x2 > setting.PlayerStats.Deaths) ? x2 : setting.PlayerStats.Deaths; setting.PlayerStats.MinutesPlayed = (playerStats.Length > 3 && double.TryParse(playerStats[3], out double x3) && x3 > setting.PlayerStats.MinutesPlayed) ? x3 : setting.PlayerStats.MinutesPlayed; setting.PlayerStats.BanCount = (playerStats.Length > 4 && int.TryParse(playerStats[4], out int x4) && x4 > setting.PlayerStats.BanCount) ? x4 : setting.PlayerStats.BanCount; - AdminToolbox.ATPlayerDict[steamID] = setting; + AdminToolbox.ATPlayerDict[UserId] = setting; + } + } + } + } + + public static void ConvertOldFilesToNewUserID() + { + if (!Config.GetBoolValue("admintoolbox_playerfiles", false)) + return; + if (Config.GetBoolValue("admintoolbox_userfiles_convert", true)) + { + string[] files = Directory.GetFiles(AdminToolboxPlayerStats); + if (files.Any(s => !s.Contains('@'))) + { + int x = 0; + AdminToolbox.singleton.Info("(File Manager) - Converting old files to new UserID format"); + if (files.Length > 5000) + { + AdminToolbox.singleton.Info("(File Manager) - Large amount of files detected, this may take a moment..."); + } + for (int i = files.Length - 1; i > -1; i--) + { + if (!Path.GetFileName(files[i]).Contains('@')) + { + x++; + AdminToolbox.singleton.Debug(files[i].Substring(0, files[i].Length - 4) + "@steam.txt"); + File.Move(files[i], files[i].Substring(0, files[i].Length - 4) + "@steam.txt"); + } + } + AdminToolbox.singleton.Info($"(File Manager) - {x} files converted"); + } + } + else if (Config.GetBoolValue("admintoolbox_userfiles_revert", false)) + { + string[] files = Directory.GetFiles(AdminToolboxPlayerStats); + if (files.Any(s => s.Contains('@'))) + { + int x = 0; + AdminToolbox.singleton.Info("(File Manager) - Reverting new files to old SteamID format"); + + for (int i = files.Length - 1; i > -1; i--) + { + if (Path.GetFileName(files[i]).Contains('@')) + { + x++; + AdminToolbox.singleton.Debug(files[i].Substring(0, files[i].Length - 4) + "@steam.txt"); + File.Move(files[i], files[i].Substring(0, files[i].Length - 10) + ".txt"); + } } + AdminToolbox.singleton.Info($"(File Manager) - {x} files reverted"); } } } /// - /// Read/Writes stats to/from for each steamID in the + /// Read/Writes stats to/from for each UserId in the /// public static void ConvertOldFilesToJSON(string file = "") { @@ -285,7 +338,7 @@ public static void ConvertOldFilesToJSON(string file = "") string[] files = string.IsNullOrEmpty(file) ? Directory.GetFiles(AdminToolboxPlayerStats) : new string[] { file }; if (files.Where(f => !File.ReadAllText(f).StartsWith("{")).Count() >= 100) { - AdminToolbox.plugin.Info("Warning: The plugin will be converting old playerfiles to a new format." + "\n" + "Beware that this might take some time"); + AdminToolbox.singleton.Info("Warning: The plugin will be converting old playerfiles to a new format." + "\n" + "Beware that this might take some time"); } if (files.Length > 0) foreach (string path in files) @@ -315,14 +368,14 @@ public static void ConvertOldFilesToJSON(string file = "") } catch (Exception e) { - AdminToolbox.plugin.Debug("Failed during convertion of: " + path); - AdminToolbox.plugin.Debug(e.StackTrace); + AdminToolbox.singleton.Debug("Failed during convertion of: " + path); + AdminToolbox.singleton.Debug(e.StackTrace); continue; } // Kills + TeamKills + Deaths + minutesPlayed + BanCount; } if (x > 0) - AdminToolbox.plugin.Debug(x + " files converted to new JSON format!"); + AdminToolbox.singleton.Debug(x + " files converted to new JSON format!"); #pragma warning restore CS0162 // Unreachable code detected } @@ -351,7 +404,7 @@ public static void WriteVersionToFile() string path = GetFolderPath(Folder.AppData); if (Directory.Exists(path)) { - string text = "at_version=" + AdminToolbox.plugin.Details.version.Split('-').FirstOrDefault(); + string text = "at_version=" + AdminToolbox.singleton.Details.version.Split('-').FirstOrDefault(); using (StreamWriter streamWriter = new StreamWriter(path + "at_version.md", false)) { streamWriter.Write(text); @@ -360,7 +413,7 @@ public static void WriteVersionToFile() File.Delete(path + "n_at_version.md"); } else - AdminToolbox.plugin.Info("Could not find SCP Secret Lab folder!"); + AdminToolbox.singleton.Info("Could not find SCP Secret Lab folder!"); } } } diff --git a/AdminToolbox/AdminToolbox/Managers/LogManager.cs b/AdminToolbox/AdminToolbox/Managers/LogManager.cs index ac96af1..ae17da3 100644 --- a/AdminToolbox/AdminToolbox/Managers/LogManager.cs +++ b/AdminToolbox/AdminToolbox/Managers/LogManager.cs @@ -138,15 +138,15 @@ public void ManageDatedATLogs(uint hoursOld) if (configInt > 0) { string[] files = Directory.GetFiles(AdminToolboxLogs + Port, "Round-*.txt", SearchOption.TopDirectoryOnly); - AdminToolbox.plugin.Debug("LogManager file age to keep: " + configInt); + AdminToolbox.singleton.Debug("LogManager file age to keep: " + configInt); if (files.Length > 0) foreach (string path in files) { int num = (int)(DateTime.Now - File.GetCreationTime(path)).TotalHours; - AdminToolbox.plugin.Debug(path + "\nHours Old: " + num); + AdminToolbox.singleton.Debug(path + "\nHours Old: " + num); if (num > configInt) { - AdminToolbox.plugin.Debug("-----------Deleted--------------\n"); + AdminToolbox.singleton.Debug("-----------Deleted--------------\n"); File.Delete(path); } } @@ -217,7 +217,7 @@ private void MoveOldFiles() } } if (infoString != string.Empty) - AdminToolbox.plugin.Info(infoString + "\n\n New Path: " + AdminToolboxLogs.Replace(AppFolder, string.Empty)); + AdminToolbox.singleton.Info(infoString + "\n\n New Path: " + AdminToolboxLogs.Replace(AppFolder, string.Empty)); Directory.Delete(AppFolder + "ATServerLogs"); } } diff --git a/AdminToolbox/AdminToolbox/Managers/WarpManager.cs b/AdminToolbox/AdminToolbox/Managers/WarpManager.cs index 991957b..312493b 100644 --- a/AdminToolbox/AdminToolbox/Managers/WarpManager.cs +++ b/AdminToolbox/AdminToolbox/Managers/WarpManager.cs @@ -14,7 +14,7 @@ namespace AdminToolbox.Managers /// public class WarpManager { - private static AdminToolbox Plugin => AdminToolbox.plugin; + private static AdminToolbox Plugin => AdminToolbox.singleton; private static int Port => PluginManager.Manager.Server.Port; @@ -82,9 +82,12 @@ public void RemoveUndergroundWarps() /// the array of WarpPoints to write, null writes the AT WarpVectorDict public bool WriteWarpsToFile(WarpPoint[] warpPoints = null) { + Debug("Entered WriteToFile"); + if (!ConfigManager.Manager.Config.GetBoolValue("admintoolbox_warpfiles", false)) + return false; try { - Debug("Entered WriteToFile"); + WarpPoint[] warparray = (warpPoints != null && warpPoints.Length > 0) ? warpPoints : AdminToolbox.WarpVectorDict.Values.ToArray(); if (warparray == null || warparray.Length < 1) { @@ -129,6 +132,8 @@ public bool WriteWarpsToFile(WarpPoint[] warpPoints = null) public Dictionary ReadWarpsFromFile() { Debug("Entered ReadFromFile"); + if (!ConfigManager.Manager.Config.GetBoolValue("admintoolbox_warpfiles", false)) + return presetWarps; try { Dictionary newDict = new Dictionary();