1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-10 15:20:48 -05:00

Redid the logging system

This commit is contained in:
RaidMax
2017-05-27 18:29:20 -05:00
parent c1faf8a02e
commit ac7908de91
23 changed files with 191 additions and 216 deletions

View File

@ -236,7 +236,7 @@ namespace SharedLibrary.Commands
public override async Task ExecuteAsync(Event E)
{
await E.Owner.Broadcast($"Fast restarting in ^53 ^7seconds [^5{E.Origin.Name}]");
await E.Owner.Broadcast($"Fast restarting in ^53 ^7seconds [^5{E.Origin.Name}^7]");
await Task.Delay(3000);
await E.Owner.ExecuteCommandAsync("fast_restart");
}
@ -248,7 +248,7 @@ namespace SharedLibrary.Commands
public override async Task ExecuteAsync(Event E)
{
await E.Owner.Broadcast($"Map rotating in ^55 ^7seconds [^5{E.Origin.Name}]");
await E.Owner.Broadcast($"Map rotating in ^55 ^7seconds [^5{E.Origin.Name}^7]");
await Task.Delay(5000);
await E.Owner.ExecuteCommandAsync("map_rotate");
}

View File

@ -13,18 +13,7 @@ namespace SharedLibrary
{
FileName = FN;
DBCon = String.Format("Data Source={0}", FN);
try
{
Con = new SQLiteConnection(DBCon);
}
catch (DllNotFoundException)
{
Console.WriteLine("Fatal Error: could not locate the SQLite DLL(s)!\nEnsure they are located in the 'lib' folder");
Utilities.Wait(5);
Environment.Exit(0);
}
Con = new SQLiteConnection(DBCon);
Open = false;
Init();
}
@ -130,6 +119,7 @@ namespace SharedLibrary
catch (Exception E)
{
// fixme: this needs to have a reference to a logger..
Console.WriteLine(E.Message);
Console.WriteLine(E.StackTrace);
Console.WriteLine(Request);
@ -205,7 +195,7 @@ namespace SharedLibrary
}
catch (Exception e)
{
Console.WriteLine(e.Message + " GetDataTable");
Console.WriteLine($"Line 198: {e.Message}");
return new DataTable();
}
return dt;

View File

@ -20,22 +20,6 @@ namespace SharedLibrary
Name = (fileName.Split('/'))[fileName.Split('/').Length - 1];
//if (!Directory.Exists(_Directory))
// Directory.CreateDirectory(_Directory);
if (!File.Exists(fileName))
{
try
{
//FileStream penis = File.Create(fileName);
//penis.Close();
}
catch
{
Console.WriteLine("Unable to create file!");
}
}
try
{
@ -89,20 +73,6 @@ namespace SharedLibrary
}
}
public String[] getParameters(int num)
{
if (sze > 0)
{
String firstLine = Handle.ReadLine();
String[] Parms = firstLine.Split(':');
if (Parms.Length < num)
return null;
else
return Parms;
}
return null;
}
public void Close()
{

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SharedLibrary.Interfaces
{
public interface ILogger
{
void WriteVerbose(string msg);
void WriteInfo(string msg);
void WriteDebug(string msg);
void WriteWarning(string msg);
void WriteError(string msg);
}
}

View File

@ -11,6 +11,7 @@ namespace SharedLibrary.Interfaces
void Init();
void Start();
void Stop();
ILogger GetLogger();
List<Server> GetServers();
List<Command> GetCommands();
IPenaltyList GetClientPenalties();

View File

@ -1,61 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SharedLibrary
{
public class Log
{
public enum Level
{
All,
Debug,
Production,
None,
}
public Log(IFile logf, Level mode, int port)
{
logFile = logf;
logMode = mode;
Identifier = port;
}
public void Write(String line)
{
Write(line, Level.Debug);
}
public void Write(String line, Level lv)
{
String Line = String.Format("{1} - [{0}]: {2}", Identifier, getTime(), line);
switch (logMode)
{
case Level.All:
if (lv == Level.All || lv == Level.Debug || lv == Level.Production)
Console.WriteLine(Line);
break;
case Level.Debug:
if (lv == Level.All || lv == Level.Debug)
Console.WriteLine(Line);
break;
case Level.Production:
if (lv == Level.Production)
Console.WriteLine(Line);
break;
}
logFile.Write(Line);
}
private string getTime()
{
return DateTime.Now.ToString("HH:mm:ss");
}
private IFile logFile;
private Level logMode;
private int Identifier;
}
}

View File

@ -20,13 +20,8 @@ namespace SharedLibrary
IP = address;
Port = port;
Manager = mgr;
Logger = Manager.GetLogger();
ClientNum = 0;
logFile = new IFile($"Logs/{address}_{port}.log", true);
#if DEBUG
Log = new Log(logFile, Log.Level.Debug, port);
#else
Log = new Log(logFile, Log.Level.Production, port);
#endif
aliasDB = new AliasesDB("Database/aliases.rm");
Players = new List<Player>(new Player[18]);
@ -358,7 +353,7 @@ namespace SharedLibrary
}
}
else
Log.Write("Maps configuration appears to be empty - skipping...", Log.Level.All);
Logger.WriteInfo("Maps configuration appears to be empty - skipping...");
}
/// <summary>
@ -374,7 +369,7 @@ namespace SharedLibrary
if (lines.Length < 2) //readAll returns minimum one empty string
{
Log.Write("Messages configuration appears empty - skipping...", Log.Level.All);
Logger.WriteInfo("Messages configuration appears empty - skipping...");
return;
}
@ -417,7 +412,7 @@ namespace SharedLibrary
}
}
else
Log.Write("Rules configuration appears empty - skipping...", Log.Level.All);
Logger.WriteInfo("Rules configuration appears empty - skipping...");
ruleFile.Close();
}
@ -429,7 +424,7 @@ namespace SharedLibrary
//Objects
public Interfaces.IManager Manager { get; protected set; }
public Log Log { get; private set; }
public Interfaces.ILogger Logger { get; private set; }
public Player owner;
public List<Map> maps;
public List<String> rules;

View File

@ -59,6 +59,7 @@
<Compile Include="Exceptions\DvarException.cs" />
<Compile Include="Exceptions\NetworkException.cs" />
<Compile Include="Exceptions\ServerException.cs" />
<Compile Include="Interfaces\ILogger.cs" />
<Compile Include="Interfaces\IManager.cs" />
<Compile Include="Interfaces\IPenaltyList.cs" />
<Compile Include="Interfaces\ISerializable.cs" />
@ -68,7 +69,6 @@
<Compile Include="Event.cs" />
<Compile Include="File.cs" />
<Compile Include="Dvar.cs" />
<Compile Include="Log.cs" />
<Compile Include="Map.cs" />
<Compile Include="Miscellaneous.cs" />
<Compile Include="Player.cs" />

View File

@ -127,8 +127,7 @@ namespace SharedLibrary
{
String Match = M.Value;
String Identifier = M.Value.Substring(2, M.Length - 4);
Object foundVal;
Dict.TryGetValue(Identifier, out foundVal);
Dict.TryGetValue(Identifier, out object foundVal);
String Replacement;
if (foundVal != null)