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

Commit

Permalink
1.3.9 Update (#122)
Browse files Browse the repository at this point in the history
* Huge ass commit featuring loads of stuff

 - Add static commandaliases to all command classes
 - Move IsInsideJail & JailedPlayers list to ExentionMethods
 - New PlayerFile storage format, including new serializable classes
 - New Utility class with utilitary Methods
 - Minor optimizations

* 1.3.8-5

 - Fixed Enumerator errors on changed collection OnRoundEnd / OnRoundRestart
 - Fixed WarpPoint serialization crash
 - Fixed `admintoolbox_logremover_hours_old` not working at all (also changed default from 48 hours to disabled)
 - New static system for getting AT related folder paths
 - General cleanup

* Fixed ATBAN not handling additional args

 - Closes #84
 - Made Command take 1 less arg, defaults time to config `admintoolbox_atban_duration_default` (default 1 month)

* 1.3.9 Part 1 (unfinished)

* Added LockDoors command, removed excess code

This closes #87

* Ban-Webhook stuff, Tutorial command changes, Empty command rework, WaitForTeleport class

- New Ban-Wehbook `admintoolbox_ban_webhooks` list config & `admintoolbox_ban_webhook_onkick` bool config
- Trying something new with the EMPTY command, might be broken
- Made TUTORIALS teleport to an existing `tutorial` warppoint if the command is used in SPECTATOR mode

* Updated dummy wehbook variables

* Fixed webhook duration display

* Added RespawnLock

closes #89

* 1.3.9 Final?

- Cleanup
- More Cleanup
- Change remaining ContainsKey to TryGetValue
- Remove unused/unfinished feature
- More XML

* Add new Master branch files (#94)

* Create FUNDING.yml

* 1.3.9 Final Final?

- ClosestDoor command
- GrenadeMode command
- InfiniteItem command
- `admintoolbox_warps_remove_underground` config
- Formatting fixes and cleanup

* Switchng to Unity JSON System

* Fix csproj error

* Apparently Unity JSON doesn't like arrays

* Bump version

* Updated to SMod 3.6.0

* Removed startup info

- SMod PluginManager does this automatically now

* Added more debug

* Updated to SMod 3.7.0-A (Ish)

* Update to Pre-release 4

- Removed enum

* Framework update for Smod Beta

* 13.8-16 Updated to Scopophobia

* Updated for SMod 3.8.2

* Remove obsolete code

* New AT Sub-commands

- Webhook test command
- Room ID command

* Minor MiscEvents cleanup and failsafes

* Replace Newtonsoft with UTF8Json, rename ATFileManager

- Reworked JSON stuff to use UTF8Json that comes with the game
- Renamed the class ATFileManager to ATFile (Its under the Manager Namespace anyways)

* Version bump

* Added SMod version to AT INFO command

* Webhook update, new config, version bump

- Updated Webhooks to now send bytes instead of text
- Added `admintoolbox_ban_console_info` bool config (default true). Outputs info into server console on player ban
- Updated the ban webhook layout, added timespan display and replaced missing picture
- Moved the WebHook assembling to a static Utility method

* Update to SMod 3.9.0, Rename ATFileManager

* Cleaning up, version bump

- Moved a lot of stuff out of the main plugin class, renamed some things for consistency

* "Copy local" is stupid.

* Structs are cool.

* More structs

* UTC Time, Struct, Renaming, new Method,

- Updated to use DateTime UTC instead of NOW
- Renamed several things to be more intuitive
- Added some Try-Catch'es (ATFile, ExtentionMethods, GetPlayerFromString)
- Made the WarpPoint class into a Struct
- Better static JailPos property
- Added TryGetPlayer method
- Made the class GetPlayerFromString static

* Remove Unused stuff, update enums

* ATfile updates, adapt to SMod API changes, version bump

* Added "blank" playerfilename check to file save ,Changed Info messages to Debug

Some messages that was meant to be debug in the first place 💩

* Updated Utility enum

* Version bump

* Rename GetPlayerFromString

* Added more methods to GetFromString

* Update to Karl's SMod update (#121)

* Update to Karl's SMod update

* Remove obolete event stuff

* Update for SMod 3.10.0 release

* Update to AT 1.3.9

*Time to finally get out of this revision-hell*
  • Loading branch information
Rnen committed Mar 7, 2022
1 parent 7d77773 commit 5427341
Show file tree
Hide file tree
Showing 54 changed files with 1,548 additions and 1,365 deletions.
56 changes: 39 additions & 17 deletions AdminToolbox/AdminToolbox/API/ATWeb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,22 @@ 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);

private const string ApiURL = "https://api.github.com/repos/Rnen/AdminToolbox/releases/latest";

/// <summary>
/// Class for storing the latest GitHub release info
/// </summary>
public class AT_LatestReleaseInfo
public struct 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,24 +40,43 @@ 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.UtcNow;
private static ATReleaseInfo _latestReleaseInfo = new ATReleaseInfo();

/// <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.UtcNow || _latestReleaseInfo.Equals(default(ATReleaseInfo)))
{
_latestReleaseInfo = GetOnlineInfo();
_lastVersionCheck = DateTime.UtcNow;
Debug("Refreshed online version!");
}
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 = "";

try
{
using (UnityWebRequest ww = UnityWebRequest.Get(apiURL))
using (UnityWebRequest ww = UnityWebRequest.Get(ApiURL))
{
ww.SendWebRequest();
DateTime timer = DateTime.Now.AddSeconds(2);
while (!ww.isDone || (!ww.downloadHandler.isDone && DateTime.Now < timer)) { }
DateTime timer = DateTime.UtcNow.AddSeconds(2);
while (!ww.isDone || (!ww.downloadHandler.isDone && DateTime.UtcNow < timer)) { }
rawResponse = ww.downloadHandler.text;
if (string.IsNullOrEmpty(rawResponse))
throw new Exception("[AdminToolbox]: GitHub web request response was NullOrEmpty!");
Expand All @@ -76,17 +98,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 All @@ -99,20 +121,20 @@ internal static string SendWebhook(DiscordWebhook discordWebHook, string url)
{
if (!string.IsNullOrEmpty(url) && Uri.TryCreate(url, UriKind.Absolute, out Uri uri))
{
//string jsonData = UnityEngine.JsonUtility.ToJson(discordWebHook, true);
string jsonData = Newtonsoft.Json.JsonConvert.SerializeObject(discordWebHook);
byte[] jsonData = Utf8Json.JsonSerializer.Serialize(discordWebHook);
Debug("WebHook sent: \n" + Utf8.GetString(jsonData));
return WebPost(uri, jsonData);
}
else
return "Failed creating URI of WebHook link: " + url;
}

private static string WebPost(Uri uri, string rawJsonData)
private static string WebPost(Uri uri, byte[] rawJsonData)
{
using (WebClient wb = new WebClient())
{
wb.Headers[HttpRequestHeader.ContentType] = "application/json";
return wb.UploadString(uri, "POST", rawJsonData);
return Utf8Json.JsonSerializer.PrettyPrint(wb.UploadData(uri, "POST", rawJsonData));
}
}
}
Expand Down
22 changes: 9 additions & 13 deletions AdminToolbox/AdminToolbox/API/DiscordWebhook.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
namespace AdminToolbox.API.Webhook
{
public class Image
public struct Image
{
public string url;
}
public class Author
public struct Author
{
public string name = "";
public string url = "";
public string icon_url = "";
public string name;
public string url;
public string icon_url;
}
public class Field
public struct Field
{
public string name;
public string value;
public string inline = "false";
public Field() { }
public bool inline;

public Field(Field field)
{
Expand All @@ -24,10 +23,7 @@ public Field(Field field)
this.inline = field.inline;
}

public override string ToString()
{
return "Name: " + this.name + " Value: " + this.value + " InLine: " + inline;
}
public override string ToString() => "Name: " + this.name + " Value: " + this.value + " InLine: " + inline;
}
public class EmbedData
{
Expand All @@ -44,7 +40,7 @@ public class EmbedData
public class DiscordWebhook
{
public string username = "AdminToolbox";
public string avatar_url = "https://puu.sh/D0DRU.png";
public string avatar_url = "https://i.imgur.com/nQpIuUT.png";
public string content = "";
public EmbedData[] embeds = new EmbedData[1] { new EmbedData() };
}
Expand Down

0 comments on commit 5427341

Please sign in to comment.