This repository has been archived by the owner on Jul 4, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Jesus-QC/dev
bump
- Loading branch information
Showing
27 changed files
with
809 additions
and
103 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
SecretAdmin/API/Events/EventArgs/ReceivedActionEventArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using SecretAdmin.Features.Server.Enums; | ||
|
||
namespace SecretAdmin.API.Events.EventArgs | ||
{ | ||
public class ReceivedActionEventArgs : System.EventArgs | ||
{ | ||
public ReceivedActionEventArgs(byte actionCode) | ||
{ | ||
OutputCode = (OutputCodes)actionCode; | ||
IsEnabled = true; | ||
} | ||
|
||
public OutputCodes OutputCode { get; set; } | ||
public bool IsEnabled { get; set; } | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
SecretAdmin/API/Events/EventArgs/ReceivedMessageEventArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace SecretAdmin.API.Events.EventArgs | ||
{ | ||
public class ReceivedMessageEventArgs : System.EventArgs | ||
{ | ||
public ReceivedMessageEventArgs(string message, byte code) | ||
{ | ||
Message = message; | ||
Code = code; | ||
IsAllowed = !string.IsNullOrWhiteSpace(message); | ||
} | ||
|
||
public string Message { get; set; } | ||
public byte Code { get; set; } | ||
public bool IsAllowed { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using SecretAdmin.API.Events.EventArgs; | ||
|
||
namespace SecretAdmin.API.Events.Handlers | ||
{ | ||
public static class Server | ||
{ | ||
public static event Utils.CustomEventHandler<ReceivedMessageEventArgs> ReceivedMessage; | ||
public static event Utils.CustomEventHandler<ReceivedActionEventArgs> ReceivedAction; | ||
public static event Utils.CustomEventHandler Restarted; | ||
public static event Utils.CustomEventHandler RestartedRound; | ||
public static event Utils.CustomEventHandler RestartingRound; | ||
|
||
public static void OnReceivedMessage(ReceivedMessageEventArgs ev) => ReceivedMessage?.Invoke(ev); | ||
public static void OnReceivedAction(ReceivedActionEventArgs ev) => ReceivedAction?.Invoke(ev); | ||
public static void OnRestarted() => Restarted?.Invoke(); | ||
public static void OnRestartedRound() => RestartedRound?.Invoke(); | ||
public static void OnRestartingRound() => RestartingRound?.Invoke(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace SecretAdmin.API.Events | ||
{ | ||
public static class Utils | ||
{ | ||
public delegate void CustomEventHandler<T>(T ev) where T : System.EventArgs; | ||
public delegate void CustomEventHandler(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
|
||
namespace SecretAdmin.API.Features | ||
{ | ||
public interface IModule | ||
{ | ||
string Name { get; set; } | ||
string Author { get; set; } | ||
Version Version { get; set; } | ||
|
||
void OnEnabled(); | ||
void OnDisabled(); | ||
void OnRegisteringCommands(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Reflection; | ||
using SecretAdmin.Features.Console; | ||
|
||
namespace SecretAdmin.API.Features | ||
{ | ||
public abstract class Module : IModule | ||
{ | ||
protected Module() | ||
{ | ||
Assembly = Assembly.GetCallingAssembly(); | ||
Name ??= Assembly.GetName().Name; | ||
Author ??= "Unknown"; | ||
Version ??= Assembly.GetName().Version; | ||
} | ||
|
||
private Assembly Assembly { get; } | ||
public virtual string Name { get; set; } | ||
public virtual string Author { get; set; } | ||
public virtual Version Version { get; set; } | ||
|
||
public virtual void OnEnabled() | ||
{ | ||
Log.Raw($"The module {Name} [{Version}] by {Author} was enabled.", ConsoleColor.DarkMagenta); | ||
} | ||
|
||
public virtual void OnDisabled() | ||
{ | ||
Log.Raw($"The module {Name} [{Version}] by {Author} was disabled.", ConsoleColor.DarkMagenta); | ||
} | ||
|
||
public virtual void OnRegisteringCommands() | ||
{ | ||
Program.CommandHandler.RegisterCommands(Assembly); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Reflection; | ||
using SecretAdmin.API.Features; | ||
using SecretAdmin.Features.Console; | ||
using SecretAdmin.Features.Program; | ||
using Module = SecretAdmin.API.Features.Module; | ||
|
||
namespace SecretAdmin.API | ||
{ | ||
public static class ModuleManager | ||
{ | ||
public static List<IModule> Modules = new (); | ||
|
||
public static void LoadAll() | ||
{ | ||
Log.WriteLine(); | ||
Log.Raw("Loading modules dependencies!", ConsoleColor.DarkCyan); | ||
|
||
var startTime = DateTime.Now; | ||
|
||
foreach (var file in Directory.GetFiles(Paths.ModulesDependenciesFolder, "*.dll")) | ||
{ | ||
try | ||
{ | ||
var assembly = Assembly.UnsafeLoadFrom(file); | ||
Log.Raw($"Dependency {assembly.GetName().Name} ({assembly.GetName().Version}) has been loaded!"); | ||
} | ||
catch (Exception e) | ||
{ | ||
Log.Raw($"Couldn't load the dependency in the path {file}\n{e}", ConsoleColor.Red); | ||
throw; | ||
} | ||
} | ||
|
||
Log.Raw($"Dependencies loaded in {(DateTime.Now - startTime).TotalMilliseconds}ms", ConsoleColor.Cyan); | ||
Log.Raw("Loading modules!", ConsoleColor.DarkCyan); | ||
|
||
startTime = DateTime.Now; | ||
|
||
foreach (var file in Directory.GetFiles(Paths.ModulesFolder, "*.dll")) | ||
{ | ||
var assembly = Assembly.Load(File.ReadAllBytes(file)); | ||
|
||
try | ||
{ | ||
foreach (var type in assembly.GetTypes()) | ||
{ | ||
if(type.IsAbstract || type.IsInterface || type.BaseType != typeof(Module)) | ||
continue; | ||
|
||
var constructor = type.GetConstructor(Type.EmptyTypes); | ||
if (constructor == null) | ||
continue; | ||
|
||
var module = constructor.Invoke(null) as IModule; | ||
module?.OnEnabled(); | ||
module?.OnRegisteringCommands(); | ||
|
||
Modules.Add(module); | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
Log.Raw(e, ConsoleColor.Red); | ||
} | ||
} | ||
|
||
Log.Raw($"Modules loaded in {(DateTime.Now - startTime).TotalMilliseconds}ms", ConsoleColor.Cyan); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.IO; | ||
|
||
namespace SecretAdmin.Features.Console | ||
{ | ||
public class Logger | ||
{ | ||
private readonly string _path; | ||
|
||
public Logger(string path) | ||
{ | ||
_path = path; | ||
} | ||
|
||
public void AppendLog(object message, bool newLine = false) | ||
{ | ||
using var stream = File.AppendText(_path); | ||
|
||
if (newLine) | ||
stream.WriteLine(message); | ||
else | ||
stream.Write(message); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,43 @@ | ||
namespace SecretAdmin.Features.Program | ||
{ | ||
public class ArgumentsManager | ||
public static class ArgumentsManager | ||
{ | ||
// TODO: this | ||
/* | ||
* Arguments: | ||
* --reconfigure -r | ||
* --config <path> -c | ||
* --logs <path> -l | ||
* --game-logs <path> -gl | ||
* --config <filename> -c | ||
* --no-logs -nl | ||
*/ | ||
|
||
public static Args GetArgs(string[] args) | ||
{ | ||
var ret = new Args(); | ||
|
||
for (int i = 0; i < args.Length; i++) | ||
{ | ||
switch (args[i]) | ||
{ | ||
case "--reconfigure" or "-r": | ||
ret.Reconfigure = true; | ||
break; | ||
case "--config" or "-c" when args.Length > i + 1: | ||
ret.Config = args[i + 1]; | ||
break; | ||
case "--no-logs" or "-nl": | ||
ret.Logs = false; | ||
break; | ||
} | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
public class Args | ||
{ | ||
public bool Reconfigure = false; | ||
public string Config = "default.yml"; | ||
public bool Logs = true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace SecretAdmin.Features.Program | ||
{ | ||
public static class AutoUpdater | ||
{ | ||
public static void CheckForUpdates() | ||
{ | ||
// todo: this | ||
} | ||
} | ||
} |
Oops, something went wrong.