Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Cleaning up, version bump
Browse files Browse the repository at this point in the history
- Moved a lot of stuff out of the main plugin class, renamed some things for consistency
  • Loading branch information
Rnen committed Sep 15, 2020
1 parent c8c3781 commit a7cc84b
Show file tree
Hide file tree
Showing 23 changed files with 143 additions and 144 deletions.
38 changes: 29 additions & 9 deletions AdminToolbox/AdminToolbox/API/ATWeb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@ public static class ATWeb
private static AdminToolbox Plugin => AdminToolbox.singleton;

private static void Debug(string str) => Plugin.Debug("[ATWeb]: " + str);
private static void Info(string str) => Plugin.Info("[ATWeb]: " + str);

/// <summary>
/// Class for storing the latest GitHub release info
/// </summary>
public class AT_LatestReleaseInfo
public class ATReleaseInfo
{
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
public string Title { get; }
public string Version { get; }
public string Author { get; }
public string DownloadLink { get; }

public AT_LatestReleaseInfo(string Title, string Version, string Author, string DownloadLink)
public ATReleaseInfo(string Title, string Version, string Author, string DownloadLink)
{
this.Title = Title;
this.Version = Version;
Expand All @@ -37,13 +38,32 @@ public AT_LatestReleaseInfo(string Title, string Version, string Author, string
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
}

private static DateTime _lastVersionCheck = DateTime.Now;
private static ATReleaseInfo _latestReleaseInfo;

/// <summary>
/// Returns a <see cref="AT_LatestReleaseInfo"/> class containing info about the latest GitHub release
/// Returns a <see cref="ATReleaseInfo"/> class containing info about the latest GitHub release
/// </summary>
public static AT_LatestReleaseInfo GetOnlineInfo(AdminToolbox plugin)
/// <remarks>Only updates every 5 minutes to avoid rate limits</remarks>
public static ATReleaseInfo LatestRelease
{
get
{
if (_lastVersionCheck.AddMinutes(5) < DateTime.Now || _latestReleaseInfo == null)
{
_latestReleaseInfo = GetOnlineInfo();
_lastVersionCheck = DateTime.Now;
}
return _latestReleaseInfo;
}
}

private static ATReleaseInfo GetOnlineInfo()
{
Smod2.Attributes.PluginDetails Details = AdminToolbox.singleton.Details;
if (ConfigManager.Manager.Config.GetBoolValue("atb_disable_networking", false)
|| ConfigManager.Manager.Config.GetBoolValue("admintoolbox_disable_networking", false)) return new AT_LatestReleaseInfo(plugin.Details.name, plugin.Details.version, plugin.Details.author, "");
|| ConfigManager.Manager.Config.GetBoolValue("admintoolbox_disable_networking", false))
return new ATReleaseInfo(Details.name, Details.version, Details.author, "");
string rawResponse = string.Empty;
string apiURL = "https://api.github.com/repos/Rnen/AdminToolbox/releases/latest";
string _title = "", _version = "", _author = "", _dllink = "";
Expand Down Expand Up @@ -76,17 +96,17 @@ string FindValue(string key)
catch (Exception e)
{
Debug("Exception: " + e.Message);
plugin.Info(" \n\n - Downloading online version failed, skipping..." + "\n \n");
return new AT_LatestReleaseInfo(plugin.Details.name, plugin.Details.version, plugin.Details.author, "");
Info(" \n\n - Downloading online version failed, skipping..." + "\n \n");
return new ATReleaseInfo(Details.name, Details.version, Details.author, "");
}
return new AT_LatestReleaseInfo(_title, _version, _author, _dllink);
return new ATReleaseInfo(_title, _version, _author, _dllink);
}

internal static bool NewerVersionAvailable()
{
if (Plugin == null) return false;
string thisVersion = Plugin.Details.version.Split('-').FirstOrDefault().Replace(".", string.Empty);
string onlineVersion = Plugin.GetGitReleaseInfo().Version.Split('-').FirstOrDefault().Replace(".", string.Empty);
string onlineVersion = LatestRelease.Version.Split('-').FirstOrDefault().Replace(".", string.Empty);

if (int.TryParse(thisVersion, out int thisV)
&& int.TryParse(onlineVersion, out int onlineV)
Expand Down
2 changes: 1 addition & 1 deletion AdminToolbox/AdminToolbox/API/ExtentionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ internal static void Cleanup(this Dictionary<string, PlayerSettings> dict)
{
if (!currentPlayers.Any(s => s == kp.Key) && !kp.Value.keepSettings && Math.Abs((DateTime.Now - kp.Value.JoinTime).TotalMinutes - Server.Round.Duration) > 2)
{
AdminToolbox.atfileManager.PlayerStatsFileManager(kp.Key, Managers.ATFile.PlayerFile.Write);
AdminToolbox.FileManager.PlayerStatsFileManager(kp.Key, Managers.ATFile.PlayerFile.Write);
dict.Remove(kp.Key);
}
}
Expand Down
79 changes: 11 additions & 68 deletions AdminToolbox/AdminToolbox/AdminToolbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,47 +21,32 @@ namespace AdminToolbox
name = "Admin Toolbox",
description = "Plugin for advanced admin tools",
id = "rnen.admin.toolbox",
version = AT_Version + "-" + AT_Revision,
version = AT_Version + "-" + AT_Revision,
SmodMajor = 3,
SmodMinor = 8,
SmodRevision = 2
SmodMinor = 9,
SmodRevision = 0
)]
public class AdminToolbox : Plugin
{
internal const string AT_Version = "1.3.8";
internal const string AT_Revision = "19";

#region GitHub release info
private DateTime LastOnlineCheck = DateTime.Now;
private ATWeb.AT_LatestReleaseInfo LatestReleaseInfo;
internal const string AT_Revision = "20";

internal static List<WaitForTeleport> waitForTeleports = new List<WaitForTeleport>();

internal ATWeb.AT_LatestReleaseInfo GetGitReleaseInfo()
{
if (LastOnlineCheck.AddMinutes(5) < DateTime.Now || LatestReleaseInfo == null)
{
LatestReleaseInfo = ATWeb.GetOnlineInfo(this);
LastOnlineCheck = DateTime.Now;
}
return LatestReleaseInfo;
}
#endregion

/// <summary>
/// The plugin's instance of <see cref="LogManager"/>
/// The plugin's instance of <see cref="Managers.LogManager"/>
/// </summary>
public static readonly LogManager logManager = new LogManager();
public static readonly LogManager LogManager = new LogManager();

/// <summary>
/// The plugin's instance instance of <see cref="WarpManager"/>
/// The plugin's instance instance of <see cref="Managers.WarpManager"/>
/// </summary>
public static readonly WarpManager warpManager = new WarpManager();
public static readonly WarpManager WarpManager = new WarpManager();

/// <summary>
/// The plugin's instance instance of <see cref="ATFile"/>
/// The plugin's instance instance of <see cref="Managers.ATFile"/>
/// </summary>
public static readonly ATFile atfileManager = new ATFile();
public static readonly ATFile FileManager = new ATFile();

internal static bool roundStatsRecorded = false;
internal static readonly ATRoundStats roundStats = new ATRoundStats();
Expand Down Expand Up @@ -95,7 +80,7 @@ public static bool
/// <summary>
/// <see cref ="Dictionary{TKey, TValue}"/> of all current warp vectors
/// </summary>
public static Dictionary<string, WarpPoint> WarpVectorDict = new Dictionary<string, WarpPoint>(warpManager.presetWarps);
public static Dictionary<string, WarpPoint> WarpVectorDict = new Dictionary<string, WarpPoint>(WarpManager.presetWarps);

/// <summary>
/// <see cref="AdminToolbox"/> round count
Expand Down Expand Up @@ -129,7 +114,6 @@ public override void Register()
this.RegisterCommands();
this.RegisterConfigs();
}

internal void RegisterEvents()
{
this.AddEventHandlers(new RoundEventHandler(this));
Expand Down Expand Up @@ -234,47 +218,6 @@ internal void RegisterConfigs()
//this.AddConfig(new Smod2.Config.ConfigSetting("atb_timedrestart_automessages", new string[] { "" }, Smod2.Config.SettingType.LIST, true, ""));
}


internal static void AddMissingPlayerVariables()
{
if (PluginManager.Manager.Server.GetPlayers().Count == 0) return;
AddMissingPlayerVariables(PluginManager.Manager.Server.GetPlayers());
}
internal static void AddMissingPlayerVariables(Player player)
=> AddMissingPlayerVariables(new List<Player>() { player });
internal static void AddMissingPlayerVariables(List<Player> players)
=> AddMissingPlayerVariables(players.ToArray());
internal static void AddMissingPlayerVariables(Player[] players)
{
Player[] allPlayers = PluginManager.Manager.Server.GetPlayers().ToArray();
if (allPlayers.Length == 0)
{
return;
}
else if (players == null || players.Length < 1)
{
players = allPlayers;
}
if (players.Length > 0)
{
foreach (Player player in players)
{
if (player != null && !string.IsNullOrEmpty(player.UserId))
{
AddToPlayerDict(player);
}
}
}
}
private static void AddToPlayerDict(Player player)
{
if (player != null && player is Player p &&
!string.IsNullOrEmpty(p.UserId) && !ATPlayerDict.ContainsKey(p.UserId))
{
ATPlayerDict.Add(p.UserId, new PlayerSettings(p.UserId));
}
}

/// <summary>
/// Debugs messages when <see cref="DebugMode"/> is enabled
/// </summary>
Expand Down
22 changes: 9 additions & 13 deletions AdminToolbox/AdminToolbox/AdminToolbox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,11 @@
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\SCP_SL_SERVER\SCPSL_Data\Managed\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\..\SCP_SL_SERVER\SCPSL_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Smod2, Version=3.6.0.2, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\SCP_SL_SERVER\SCPSL_Data\Managed\Smod2.dll</HintPath>
<Private>False</Private>
<Reference Include="Smod2">
<HintPath>..\..\..\..\..\SCP_SL_SERVER\SCPSL_Data\Managed\Smod2.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -59,23 +55,23 @@
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine">
<HintPath>..\..\..\..\SCP_SL_SERVER\SCPSL_Data\Managed\UnityEngine.dll</HintPath>
<HintPath>..\..\..\..\..\SCP_SL_SERVER\SCPSL_Data\Managed\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\..\..\..\SCP_SL_SERVER\SCPSL_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
<HintPath>..\..\..\..\..\SCP_SL_SERVER\SCPSL_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.PhysicsModule">
<HintPath>..\..\..\..\SCP_SL_SERVER\SCPSL_Data\Managed\UnityEngine.PhysicsModule.dll</HintPath>
<HintPath>..\..\..\..\..\SCP_SL_SERVER\SCPSL_Data\Managed\UnityEngine.PhysicsModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UnityWebRequestModule">
<HintPath>..\..\..\..\SCP_SL_SERVER\SCPSL_Data\Managed\UnityEngine.UnityWebRequestModule.dll</HintPath>
<HintPath>..\..\..\..\..\SCP_SL_SERVER\SCPSL_Data\Managed\UnityEngine.UnityWebRequestModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UnityWebRequestWWWModule">
<HintPath>..\..\..\..\SCP_SL_SERVER\SCPSL_Data\Managed\UnityEngine.UnityWebRequestWWWModule.dll</HintPath>
<HintPath>..\..\..\..\..\SCP_SL_SERVER\SCPSL_Data\Managed\UnityEngine.UnityWebRequestWWWModule.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion AdminToolbox/AdminToolbox/Commands/AT_TemplateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public string[] OnCall(ICommandSender sender, string[] args)
if (targetPlayer == null) { return new string[] { "Could not find player: " + args[0] }; ; }

//Adds player(s) to the AdminToolbox player dictionary
AdminToolbox.AddMissingPlayerVariables(new List<Player> { targetPlayer, caller });
Managers.ATFile.AddMissingPlayerVariables(new List<Player> { targetPlayer, caller });

//Do whatever with the found player
return new string[] { "We did something to player: " + targetPlayer.Name + "!" };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public string[] OnCall(ICommandSender sender, string[] args)
return new string[] { "Could not find player" };

//Adds player(s) to the AdminToolbox player dictionary
AdminToolbox.AddMissingPlayerVariables(targetPlayer);
Managers.ATFile.AddMissingPlayerVariables(targetPlayer);

SMDoor closestDoor = null;
float dist = float.MaxValue;
Expand Down
2 changes: 1 addition & 1 deletion AdminToolbox/AdminToolbox/Commands/Facility/JailCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,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);
Managers.ATFile.AddMissingPlayerVariables(myPlayer);
if (args.Length > 1)
{
if (int.TryParse(args[1], out int x))
Expand Down
8 changes: 4 additions & 4 deletions AdminToolbox/AdminToolbox/Commands/Facility/WarpCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public string[] OnCall(ICommandSender sender, string[] args)
if (sender.IsPermitted(CommandAliases, out string[] deniedReply))
{
if (sender != null && sender is Player p && p != null)
AdminToolbox.AddMissingPlayerVariables(p);
Managers.ATFile.AddMissingPlayerVariables(p);

if (args.Length > 0)
{
Expand All @@ -58,14 +58,14 @@ public string[] OnCall(ICommandSender sender, string[] args)
}
return new string[] { str };
case "REFRESH":
AdminToolbox.warpManager.RefreshWarps();
AdminToolbox.WarpManager.RefreshWarps();
return new string[] { "Refreshed warps!" };
case "REMOVE":
case "-":
if (AdminToolbox.WarpVectorDict.ContainsKey(args[1].ToLower()))
{
AdminToolbox.WarpVectorDict.Remove(args[1].ToLower());
AdminToolbox.warpManager.WriteWarpsToFile();
AdminToolbox.WarpManager.WriteWarpsToFile();
return new string[] { "Warp point: " + args[1].ToLower() + " removed." };
}
else
Expand All @@ -84,7 +84,7 @@ public string[] OnCall(ICommandSender sender, string[] args)
for (int i = 3; i < args.Length; i++)
desc = args[i] + " ";
AdminToolbox.WarpVectorDict.Add(args[2].ToLower(), new WarpPoint { Name = args[2].ToLower(), Description = desc, Vector = new ATVector(myvector) });
AdminToolbox.warpManager.WriteWarpsToFile();
AdminToolbox.WarpManager.WriteWarpsToFile();
return new string[] { "Warp point: " + args[2].ToLower() + " added." };
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public string[] OnCall(ICommandSender sender, string[] args)
{
if (args.Length >= 1 && (args[0].ToUpper() == "R" || args[0].ToUpper() == "REFRESH"))
{
AdminToolbox.warpManager.RefreshWarps();
AdminToolbox.WarpManager.RefreshWarps();
return new string[] { "Warps was refreshed!" };
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public string[] OnCall(ICommandSender sender, string[] args)
{
if (sender.IsPermitted(CommandAliases, out string[] deniedReply))
{
AdminToolbox.AddMissingPlayerVariables();
Managers.ATFile.AddMissingPlayerVariables();
if (args.Length > 0)
{
if (Utility.AllAliasWords.Contains(args[0].ToUpper()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public string[] OnCall(ICommandSender sender, string[] args)
{
if (sender.IsPermitted(CommandAliases, out string[] deniedReply))
{
if (sender is Player p) AdminToolbox.AddMissingPlayerVariables(new List<Player> { p });
if (sender is Player p) Managers.ATFile.AddMissingPlayerVariables(new List<Player> { p });
if (args.Length > 0)
{
if (Utility.AllAliasWords.Contains(args[0].ToUpper()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public string[] OnCall(ICommandSender sender, string[] args)
{
if (Utility.AllAliasWords.Contains(args[0].ToUpper()))
{
AdminToolbox.AddMissingPlayerVariables();
Managers.ATFile.AddMissingPlayerVariables();
if (args.Length > 1)
{
if (bool.TryParse(args[1], out bool j))
Expand Down Expand Up @@ -60,7 +60,7 @@ public string[] OnCall(ICommandSender sender, string[] args)
}
else if (args[0].ToLower() == "list" || args[0].ToLower() == "get")
{
AdminToolbox.AddMissingPlayerVariables();
Managers.ATFile.AddMissingPlayerVariables();
string str = "\nPlayers with InstantKill enabled: \n";
List<string> myPlayerList = new List<string>();
foreach (Player pl in Server.GetPlayers())
Expand All @@ -84,7 +84,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);
Managers.ATFile.AddMissingPlayerVariables(myPlayer);
if (args.Length > 1)
{
if (AdminToolbox.ATPlayerDict.TryGetValue(myPlayer.UserId, out PlayerSettings ps))
Expand Down
Loading

0 comments on commit a7cc84b

Please sign in to comment.