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

@ -113,6 +113,7 @@
<Compile Include="Connection.cs" />
<Compile Include="Heartbeat.cs" />
<Compile Include="Kayak.cs" />
<Compile Include="Logger.cs" />
<Compile Include="Main.cs" />
<Compile Include="Manager.cs" />
<Compile Include="PenaltyList.cs" />

View File

@ -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...");
}
}

70
Admin/Logger.cs Normal file
View File

@ -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);
}
}
}

View File

@ -117,6 +117,9 @@ namespace IW4MAdmin
if (!Directory.Exists("Database"))
Directory.CreateDirectory("Database");
if (!Directory.Exists("Plugins"))
Directory.CreateDirectory("Plugins");
}
}
}

View File

@ -22,6 +22,7 @@ namespace IW4MAdmin
List<Command> 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<Server>();
Commands = new List<Command>();
@ -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;
}
}
}

View File

@ -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;
}

View File

@ -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, "<i>CONNECTED</i>", 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<string>("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<String>();
maps = new List<Map>();
rules = new List<String>();

View File

@ -53,9 +53,8 @@ namespace IW4MAdmin
catch (Exception e)
{
Console.WriteLine("Unable to start webservice ( port is probably in use ): " + e.Message);
Thread.Sleep(5000);
Environment.Exit(-1);
Manager.GetInstance().Logger.WriteError($"Unable to start webservice ( port is probably in use ): {e.Message}");
}
}

Binary file not shown.

View File

@ -41,7 +41,7 @@ namespace Auto_Restart_Plugin
catch (Exception E)
{
goodBye.Log.Write("SOMETHING FUCKED UP BEYOND ALL REPAIR " + E.ToString());
//goodBye.Log.Write("SOMETHING FUCKED UP BEYOND ALL REPAIR " + E.ToString());
}
}

View File

@ -63,7 +63,6 @@ namespace MessageBoard.Forum
{
Session newSession = getSession(sessionID);
newSession.sessionStartTime = DateTime.Now;
//Console.WriteLine("Matching session was found - {0}", sessionID);
addSession(newSession);
}

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);
}
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)

View File

@ -149,7 +149,7 @@ namespace StatsPlugin
calculateAndSaveSkill(P, statLists.Find(x =>x.Port == S.getPort()));
resetCounters(P.clientID, S.getPort());
E.Owner.Log.Write("Updated skill for client #" + P.databaseID, Log.Level.Debug);
E.Owner.Logger.WriteInfo("Updated skill for client #" + P.databaseID);
//E.Owner.Log.Write(String.Format("\r\nJoin: {0}\r\nInactive Minutes: {1}\r\nnewPlayTime: {2}\r\nnewSPM: {3}\r\nkdrWeight: {4}\r\nMultiplier: {5}\r\nscoreWeight: {6}\r\nnewSkillFactor: {7}\r\nprojectedNewSkill: {8}\r\nKills: {9}\r\nDeaths: {10}", connectionTime[P.clientID].ToShortTimeString(), inactiveMinutes[P.clientID], newPlayTime, newSPM, kdrWeight, Multiplier, scoreWeight, newSkillFactor, disconnectStats.Skill, disconnectStats.Kills, disconnectStats.Deaths));
}
}
@ -158,7 +158,7 @@ namespace StatsPlugin
{
calculateAndSaveSkill(E.Origin, statLists.Find(x=>x.Port == S.getPort()));
resetCounters(E.Origin.clientID, S.getPort());
E.Owner.Log.Write("Updated skill for disconnecting client #" + E.Origin.databaseID, Log.Level.Debug);
E.Owner.Logger.WriteInfo("Updated skill for disconnecting client #" + E.Origin.databaseID);
}
if (E.Type == Event.GType.Kill)

View File

@ -40,7 +40,7 @@ namespace CountryLookupProj
"O1","AX","GG","IM","JE","BL","MF"
};
private static string[] countryName =
{"N/A","Asia/Pacific Region","Europe","Andorra","United Arab Emirates","Afghanistan","Antigua and Barbuda","Anguilla","Albania","Armenia","Netherlands Antilles","Angola","Antarctica","Argentina","American Samoa","Austria","Australia","Aruba","Azerbaijan","Bosnia and Herzegovina","Barbados","Bangladesh","Belgium",
{"An Unknown Country","Asia/Pacific Region","Europe","Andorra","United Arab Emirates","Afghanistan","Antigua and Barbuda","Anguilla","Albania","Armenia","Netherlands Antilles","Angola","Antarctica","Argentina","American Samoa","Austria","Australia","Aruba","Azerbaijan","Bosnia and Herzegovina","Barbados","Bangladesh","Belgium",
"Burkina Faso","Bulgaria","Bahrain","Burundi","Benin","Bermuda","Brunei Darussalam","Bolivia","Brazil","Bahamas","Bhutan","Bouvet Island","Botswana","Belarus","Belize","Canada","Cocos (Keeling) Islands","Congo, The Democratic Republic of the","Central African Republic","Congo","Switzerland","Cote D'Ivoire",
"Cook Islands","Chile","Cameroon","China","Colombia","Costa Rica","Cuba","Cape Verde","Christmas Island","Cyprus","Czech Republic","Germany","Djibouti","Denmark","Dominica","Dominican Republic","Algeria","Ecuador","Estonia","Egypt","Western Sahara","Eritrea","Spain","Ethiopia","Finland","Fiji","Falkland Islands (Malvinas)",
"Micronesia, Federated States of","Faroe Islands","France","France, Metropolitan","Gabon","United Kingdom","Grenada","Georgia","French Guiana","Ghana","Gibraltar","Greenland","Gambia","Guinea","Guadeloupe","Equatorial Guinea","Greece","South Georgia and the South Sandwich Islands","Guatemala","Guam","Guinea-Bissau","Guyana",
@ -55,16 +55,9 @@ namespace CountryLookupProj
public CountryLookup(string fileName)
{
try
{
fileInput = new FileStream(fileName, FileMode.Open, FileAccess.Read);
}
catch (FileNotFoundException)
{
Console.WriteLine("File " + fileName + " not found.");
}
}
public string lookupCountryCode(string str)
{
@ -93,13 +86,12 @@ namespace CountryLookupProj
}
ipnum += y << ((3 - i) * 8);
}
//Console.WriteLine(ipnum);
return ipnum;
}
public string lookupCountryCode(IPAddress addr)
{
return (countryCode[(int)seekCountry(0, addrToNum(addr), 31)]);
return (countryCode[(int)SeekCountry(0, addrToNum(addr), 31)]);
}
public string lookupCountryName(string str)
@ -111,33 +103,24 @@ namespace CountryLookupProj
}
catch (FormatException)
{
return "N/A";
return "An Unknown Country";
}
return lookupCountryName(addr);
}
public string lookupCountryName(IPAddress addr)
{
return (countryName[(int)seekCountry(0, addrToNum(addr), 31)]);
return (countryName[(int)SeekCountry(0, addrToNum(addr), 31)]);
}
private long seekCountry(long offset, long ipnum, int depth)
private long SeekCountry(long offset, long ipnum, int depth)
{
byte[] buf = new byte[6];
long[] x = new long[2];
if (depth == 0)
{
Console.WriteLine("Error seeking country.");
}
try
{
fileInput.Seek(6 * offset, 0);
fileInput.Read(buf, 0, 6);
}
catch (IOException)
{
Console.WriteLine("IO Exception");
}
for (int i = 0; i < 2; i++)
{
x[i] = 0;
@ -158,7 +141,7 @@ namespace CountryLookupProj
{
return x[1] - COUNTRY_BEGIN;
}
return seekCountry(x[1], ipnum, depth - 1);
return SeekCountry(x[1], ipnum, depth - 1);
}
else
{
@ -166,7 +149,7 @@ namespace CountryLookupProj
{
return x[0] - COUNTRY_BEGIN;
}
return seekCountry(x[0], ipnum, depth - 1);
return SeekCountry(x[0], ipnum, depth - 1);
}
}
}

View File

@ -59,10 +59,19 @@ namespace Welcome_Plugin
await E.Owner.ToAdmins($"^1NOTICE: ^7Flagged player ^5{newPlayer.Name}^7 has joined!");
else
{
try
{
CountryLookupProj.CountryLookup CLT = new CountryLookupProj.CountryLookup("Plugins/GeoIP.dat");
await E.Owner.Broadcast($"^5{newPlayer.Name} ^7hails from ^5{CLT.lookupCountryName(newPlayer.IP)}");
}
catch (Exception)
{
E.Owner.Manager.GetLogger().WriteError("Could not open file Plugins/GeoIP.dat for Welcome Plugin");
}
}
}
}
}