diff --git a/Admin/IW4M ADMIN.csproj b/Admin/IW4M ADMIN.csproj
index 9aff25ebf..23c2a8956 100644
--- a/Admin/IW4M ADMIN.csproj
+++ b/Admin/IW4M ADMIN.csproj
@@ -113,6 +113,7 @@
+
diff --git a/Admin/Kayak.cs b/Admin/Kayak.cs
index 206d801da..3d143ede4 100644
--- a/Admin/Kayak.cs
+++ b/Admin/Kayak.cs
@@ -13,12 +13,12 @@ namespace IW4MAdmin
{
public void OnException(IScheduler scheduler, Exception e)
{
- Manager.GetInstance().Logger.Write("Web service has encountered an error - " + e.Message);
+ Manager.GetInstance().Logger.WriteError("Web service has encountered an error - " + e.Message);
}
public void OnStop(IScheduler scheduler)
{
- Manager.GetInstance().Logger.Write("Web service has been stopped...");
+ Manager.GetInstance().Logger.WriteDebug("Web service has been stopped...");
}
}
diff --git a/Admin/Logger.cs b/Admin/Logger.cs
new file mode 100644
index 000000000..8168c21ae
--- /dev/null
+++ b/Admin/Logger.cs
@@ -0,0 +1,70 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.IO;
+
+namespace IW4MAdmin
+{
+ class Logger : SharedLibrary.Interfaces.ILogger
+ {
+ enum LogType
+ {
+ Verbose,
+ Info,
+ Debug,
+ Warning,
+ Error
+ }
+
+ string FileName;
+
+ public Logger(string fn)
+ {
+ FileName = fn;
+ }
+
+ void Write(string msg, LogType type)
+ {
+ string LogLine = $"[{DateTime.Now.ToString("HH:mm:ss")}] - {type}: {msg}";
+#if DEBUG
+ // lets keep it simple and dispose of everything quickly as logging wont be that much (relatively)
+
+ Console.WriteLine(LogLine);
+ File.AppendAllText(FileName, LogLine);
+#else
+ if (type == LogType.Error || type == LogType.Verbose)
+ Console.WriteLine(LogLine);
+ if (type != LogType.Debug)
+ File.AppendAllText(FileName, LogLine);
+#endif
+
+ }
+
+ public void WriteVerbose(string msg)
+ {
+ Write(msg, LogType.Verbose);
+ }
+
+ public void WriteDebug(string msg)
+ {
+ Write(msg, LogType.Debug);
+ }
+
+ public void WriteError(string msg)
+ {
+ Write(msg, LogType.Error);
+ }
+
+ public void WriteInfo(string msg)
+ {
+ Write(msg, LogType.Info);
+ }
+
+ public void WriteWarning(string msg)
+ {
+ Write(msg, LogType.Warning);
+ }
+ }
+}
diff --git a/Admin/Main.cs b/Admin/Main.cs
index 698c228c4..8672054a9 100644
--- a/Admin/Main.cs
+++ b/Admin/Main.cs
@@ -117,6 +117,9 @@ namespace IW4MAdmin
if (!Directory.Exists("Database"))
Directory.CreateDirectory("Database");
+
+ if (!Directory.Exists("Plugins"))
+ Directory.CreateDirectory("Plugins");
}
}
}
diff --git a/Admin/Manager.cs b/Admin/Manager.cs
index 556a96582..9166ce114 100644
--- a/Admin/Manager.cs
+++ b/Admin/Manager.cs
@@ -22,6 +22,7 @@ namespace IW4MAdmin
List Commands;
Kayak.IScheduler webServiceTask;
Thread WebThread;
+ public SharedLibrary.Interfaces.ILogger Logger { get; private set; }
public bool Running { get; private set; }
#if FTP_LOG
const double UPDATE_FREQUENCY = 15000;
@@ -29,12 +30,11 @@ namespace IW4MAdmin
const double UPDATE_FREQUENCY = 300;
#endif
- public Log Logger;
-
private Manager()
{
- IFile logFile = new IFile("Logs/IW4MAdminManager.log", true);
- Logger = new Log(logFile, Log.Level.Production, 0);
+ //IFile logFile = new IFile("Logs/IW4MAdminManager.log", true);
+ Logger = new Logger("Logs/IW4MAdmin.log");
+ //Logger = new Log(logFile, Log.Level.Production, 0);
Servers = new List();
Commands = new List();
@@ -54,7 +54,7 @@ namespace IW4MAdmin
public static Manager GetInstance()
{
- return Instance == null ? Instance = new Manager() : Instance;
+ return Instance ?? (Instance = new Manager());
}
public void Init()
@@ -78,16 +78,16 @@ namespace IW4MAdmin
{
await ServerInstance.Initialize();
Servers.Add(ServerInstance);
- Logger.Write($"Now monitoring {ServerInstance.Hostname}", Log.Level.Production);
+ Logger.WriteVerbose($"Now monitoring {ServerInstance.Hostname}");
}
catch (SharedLibrary.Exceptions.ServerException e)
{
- Logger.Write($"Not monitoring server {Conf.IP}:{Conf.Port} due to uncorrectable errors", Log.Level.Production);
+ Logger.WriteWarning($"Not monitoring server {Conf.IP}:{Conf.Port} due to uncorrectable errors");
if (e.GetType() == typeof(SharedLibrary.Exceptions.DvarException))
- Logger.Write($"Could not get the dvar value for {(e as SharedLibrary.Exceptions.DvarException).Data["dvar_name"]} (ensure the server has a map loaded)", Log.Level.Production);
+ Logger.WriteError($"Could not get the dvar value for {(e as SharedLibrary.Exceptions.DvarException).Data["dvar_name"]} (ensure the server has a map loaded)");
else if (e.GetType() == typeof(SharedLibrary.Exceptions.NetworkException))
- Logger.Write("Could not communicate with the server (ensure the configuration is correct)", Log.Level.Production);
+ Logger.WriteError("Could not communicate with the server (ensure the configuration is correct)");
}
});
@@ -151,5 +151,10 @@ namespace IW4MAdmin
{
return ClientPenalties;
}
+
+ public SharedLibrary.Interfaces.ILogger GetLogger()
+ {
+ return Logger;
+ }
}
}
diff --git a/Admin/Plugins.cs b/Admin/Plugins.cs
index 202a4abff..25d3c56a3 100644
--- a/Admin/Plugins.cs
+++ b/Admin/Plugins.cs
@@ -24,13 +24,13 @@ namespace IW4MAdmin
else
{
- Manager.GetInstance().Logger.Write("Plugin folder does not exist!", Log.Level.All);
+ Manager.GetInstance().Logger.WriteWarning("Plugin folder does not exist!");
return false;
}
if (dllFileNames == null || dllFileNames.Length == 0)
{
- Manager.GetInstance().Logger.Write("No plugins to load", Log.Level.All);
+ Manager.GetInstance().Logger.WriteDebug("No plugins to load");
return true;
}
@@ -42,7 +42,8 @@ namespace IW4MAdmin
assemblies.Add(assembly);
}
- int totalLoaded = 0;
+ int LoadedPlugins = 0;
+ int LoadedCommands = 0;
foreach (Assembly Plugin in assemblies)
{
if (Plugin != null)
@@ -55,8 +56,8 @@ namespace IW4MAdmin
Object commandObject = Activator.CreateInstance(assemblyType);
Command newCommand = (Command)commandObject;
potentialCommands.Add(newCommand);
- Manager.GetInstance().Logger.Write("Registered command \"" + newCommand.Name + "\"", Log.Level.Debug);
- totalLoaded++;
+ Manager.GetInstance().Logger.WriteDebug("Registered command \"" + newCommand.Name + "\"");
+ LoadedCommands++;
continue;
}
@@ -71,20 +72,20 @@ namespace IW4MAdmin
{
potentialPlugins.Add(newNotify);
newNotify.OnLoadAsync();
- Manager.GetInstance().Logger.Write("Loaded plugin \"" + newNotify.Name + "\"" + " [" + newNotify.Version + "]", Log.Level.Debug);
- totalLoaded++;
+ Manager.GetInstance().Logger.WriteDebug($"Loaded plugin \"{ newNotify.Name }\" [{newNotify.Version}]");
+ LoadedPlugins++;
}
}
catch (Exception E)
{
- Manager.GetInstance().Logger.Write("Could not load plugin " + Plugin.Location + " - " + E.Message);
+ Manager.GetInstance().Logger.WriteWarning($"Could not load plugin {Plugin.Location} - {E.Message}");
}
}
}
}
- Manager.GetInstance().Logger.Write("Loaded " + totalLoaded + " plugins.", Log.Level.Production);
+ Manager.GetInstance().Logger.WriteInfo($"Loaded {LoadedPlugins} plugins and registered {LoadedCommands} commands.");
return true;
}
diff --git a/Admin/Server.cs b/Admin/Server.cs
index 6e8238712..879ae5a64 100644
--- a/Admin/Server.cs
+++ b/Admin/Server.cs
@@ -61,7 +61,7 @@ namespace IW4MAdmin
if (Players[P.clientID] != null && Players[P.clientID].npID == P.npID) // if someone has left and a new person has taken their spot between polls
return true;
- Log.Write("Client slot #" + P.clientID + " now reserved", Log.Level.Debug);
+ Logger.WriteDebug($"Client slot #{P.clientID} now reserved");
#if DEBUG == false
@@ -72,7 +72,7 @@ namespace IW4MAdmin
if (NewPlayer == null) // first time connecting
{
- Log.Write("Client slot #" + P.clientID + " first time connecting", Log.Level.All);
+ Logger.WriteDebug($"Client slot #{P.clientID} first time connecting");
Manager.GetClientDatabase().addPlayer(P);
NewPlayer = Manager.GetClientDatabase().getPlayer(P.npID, P.clientID);
aliasDB.addPlayer(new Aliases(NewPlayer.databaseID, NewPlayer.Name, NewPlayer.IP));
@@ -124,7 +124,7 @@ namespace IW4MAdmin
{
String Message;
- Log.Write("Banned client " + P.Name + " trying to connect...", Log.Level.Debug);
+ Logger.WriteInfo($"Banned client {P.Name}::{P.npID} trying to connect...");
if (NewPlayer.lastOffense != null)
Message = "Previously banned for ^5" + NewPlayer.lastOffense;
@@ -158,7 +158,7 @@ namespace IW4MAdmin
if (B != null && B.BType == Penalty.Type.Ban)
{
- Log.Write(String.Format("Banned client {0} is connecting with new alias {1}", aP.Name, NewPlayer.Name), Log.Level.Debug);
+ Logger.WriteDebug($"Banned client {aP.Name}::{aP.npID} is connecting with new alias {NewPlayer.Name}");
NewPlayer.lastOffense = String.Format("Evading ( {0} )", aP.Name);
if (B.Reason != null)
@@ -183,11 +183,9 @@ namespace IW4MAdmin
#if DEBUG == FALSE
await NewPlayer.Tell($"Welcome ^5{NewPlayer.Name} ^7this is your ^5{NewPlayer.TimesConnected()} ^7time connecting!");
#endif
- if (NewPlayer.Name == "nosTEAM")
- await NewPlayer.Tell("We encourage you to change your ^5name ^7using ^5/name^7");
-
- Log.Write("Client " + NewPlayer.Name + " connecting...", Log.Level.Debug); // they're clean
+ Logger.WriteInfo($"Client {NewPlayer.Name}::{NewPlayer.npID} connecting..."); // they're clean
+ // todo: get this out of here
while (chatHistory.Count > Math.Ceiling((double)ClientNum / 2))
chatHistory.RemoveAt(0);
chatHistory.Add(new Chat(NewPlayer.Name, "CONNECTED", DateTime.Now));
@@ -216,7 +214,7 @@ namespace IW4MAdmin
Leaving.Connections++;
Manager.GetClientDatabase().updatePlayer(Leaving);
- Log.Write("Client at " + cNum + " disconnecting...", Log.Level.Debug);
+ Logger.WriteInfo($"Client {Leaving.Name}::{Leaving.npID} disconnecting...");
await ExecuteEvent(new Event(Event.GType.Disconnect, "", Leaving, null, this));
Players[cNum] = null;
@@ -229,7 +227,7 @@ namespace IW4MAdmin
{
if (L.Length < cIDPos)
{
- Log.Write("Line sent for client creation is not long enough!", Log.Level.Debug);
+ Logger.WriteError("Line sent for client creation is not long enough!");
return null;
}
@@ -241,8 +239,8 @@ namespace IW4MAdmin
if (pID < 0 || pID > 17)
{
- Log.Write("Error event player index " + pID + " is out of bounds!", Log.Level.Debug);
- Log.Write("Offending line -- " + String.Join(";", L), Log.Level.Debug);
+ Logger.WriteError("Event player index " + pID + " is out of bounds!");
+ Logger.WriteDebug("Offending line -- " + String.Join(";", L));
return null;
}
@@ -256,8 +254,8 @@ namespace IW4MAdmin
}
catch (Exception)
{
- Log.Write("Client index is invalid - " + pID, Log.Level.Debug);
- Log.Write(L.ToString(), Log.Level.Debug);
+ Logger.WriteError("Client index is invalid - " + pID);
+ Logger.WriteDebug(L.ToString());
return null;
}
}
@@ -347,9 +345,9 @@ namespace IW4MAdmin
catch (Exception Except)
{
- Log.Write(String.Format("The plugin \"{0}\" generated an error. ( see log )", P.Name), Log.Level.Production);
- Log.Write(String.Format("Error Message: {0}", Except.Message), Log.Level.Debug);
- Log.Write(String.Format("Error Trace: {0}", Except.StackTrace), Log.Level.Debug);
+ Logger.WriteError(String.Format("The plugin \"{0}\" generated an error. ( see log )", P.Name));
+ Logger.WriteDebug(String.Format("Error Message: {0}", Except.Message));
+ Logger.WriteDebug(String.Format("Error Trace: {0}", Except.StackTrace));
continue;
}
}
@@ -528,11 +526,11 @@ namespace IW4MAdmin
if (!File.Exists(logPath))
{
- Log.Write($"Gamelog {logPath} does not exist!", Log.Level.All);
+ Logger.WriteError($"Gamelog {logPath} does not exist!");
}
logFile = new IFile(logPath);
- Log.Write("Log file is " + logPath, Log.Level.Debug);
+ Logger.WriteInfo("Log file is " + logPath);
await ExecuteEvent(new Event(Event.GType.Start, "Server started", null, null, this));
//Bans = Manager.GetClientDatabase().getBans();
#if !DEBUG
@@ -552,7 +550,7 @@ namespace IW4MAdmin
{
if (E.Origin == null)
{
- Log.Write("Disconnect event triggered, but no origin found.", Log.Level.Debug);
+ Logger.WriteError("Disconnect event triggered, but no origin found.");
return;
}
@@ -568,7 +566,7 @@ namespace IW4MAdmin
{
if (E.Origin == null)
{
- Log.Write("Kill event triggered, but no origin found!", Log.Level.Debug);
+ Logger.WriteError("Kill event triggered, but no origin found!");
return;
}
@@ -591,14 +589,14 @@ namespace IW4MAdmin
if (E.Origin == null)
{
- Log.Write("Say event triggered, but no origin found! - " + E.Data, Log.Level.Debug);
+ Logger.WriteError("Say event triggered, but no origin found! - " + E.Data);
return;
}
if (E.Owner == null)
{
- Log.Write("Say event does not have an owner!", Log.Level.Debug);
+ Logger.WriteError("Say event does not have an owner!");
return;
}
@@ -613,7 +611,7 @@ namespace IW4MAdmin
{
if (C.needsTarget && E.Target == null)
{
- Log.Write("Requested event requiring target does not have a target!", Log.Level.Debug);
+ Logger.WriteError("Requested event requiring target does not have a target!");
return;
}
@@ -624,18 +622,12 @@ namespace IW4MAdmin
catch (Exception Except)
{
- Log.Write(String.Format("A command request \"{0}\" generated an error.", C.Name, Log.Level.Debug));
- Log.Write(String.Format("Error Message: {0}", Except.Message), Log.Level.Debug);
- Log.Write(String.Format("Error Trace: {0}", Except.StackTrace), Log.Level.Debug);
+ Logger.WriteError(String.Format("A command request \"{0}\" generated an error.", C.Name));
+ Logger.WriteDebug(String.Format("Error Message: {0}", Except.Message));
+ Logger.WriteDebug(String.Format("Error Trace: {0}", Except.StackTrace));
return;
}
}
-
- else
- {
- Log.Write("Player didn't properly enter command - " + E.Origin.Name, Log.Level.Debug);
- return;
- }
}
else
@@ -659,7 +651,7 @@ namespace IW4MAdmin
if (E.Type == Event.GType.MapChange)
{
- Log.Write("New map loaded - " + ClientNum + " active players", Log.Level.Debug);
+ Logger.WriteInfo($"New map loaded - {ClientNum} active players");
// make async
Gametype = (await this.GetDvarAsync("g_gametype")).Value.StripColors();
@@ -674,7 +666,7 @@ namespace IW4MAdmin
if (E.Type == Event.GType.MapEnd)
{
- Log.Write("Game ending...", Log.Level.Debug);
+ Logger.WriteInfo("Game ending...");
return;
};
}
@@ -728,7 +720,9 @@ namespace IW4MAdmin
{
if (Target == null)
{
- Log.Write("Something really bad happened, because there's no ban target!");
+ Logger.WriteError("Ban target is null");
+ Logger.WriteDebug($"Message: {Message}");
+ Logger.WriteDebug($"Origin: {Origin.Name}::{Origin.npID}");
return;
}
@@ -746,7 +740,7 @@ namespace IW4MAdmin
if (Origin != null)
{
Target.setLevel(Player.Permission.Banned);
- Penalty newBan = new Penalty(Penalty.Type.Ban, Target.lastOffense, SharedLibrary.Utilities.StripColors(Target.npID), Origin.npID, DateTime.Now, Target.IP);
+ Penalty newBan = new Penalty(Penalty.Type.Ban, Target.lastOffense, Target.npID, Origin.npID, DateTime.Now, Target.IP);
await Task.Run(() =>
{
@@ -766,7 +760,7 @@ namespace IW4MAdmin
foreach (Report R in toRemove)
{
Reports.Remove(R);
- Log.Write("Removing report for banned GUID -- " + R.Origin.npID, Log.Level.Debug);
+ Logger.WriteInfo("Removing report for banned GUID - " + R.Origin.npID);
}
}
}
@@ -811,7 +805,7 @@ namespace IW4MAdmin
}
catch (Exception E)
{
- Log.Write("Unable to reload configs! - " + E.Message, Log.Level.Debug);
+ Logger.WriteError("Unable to reload configs! - " + E.Message);
messages = new List();
maps = new List