diff --git a/Admin/IW4M ADMIN.csproj b/Admin/IW4M ADMIN.csproj
index 1c9d9a239..9aff25ebf 100644
--- a/Admin/IW4M ADMIN.csproj
+++ b/Admin/IW4M ADMIN.csproj
@@ -31,7 +31,7 @@
true
publish.htm
6
- 0.9.1.%2a
+ 1.3.1.%2a
false
true
true
@@ -55,7 +55,7 @@
bin\Release\
TRACE
prompt
- 0
+ 3
true
On
false
@@ -115,6 +115,7 @@
+
diff --git a/Admin/Manager.cs b/Admin/Manager.cs
index a60274958..556a96582 100644
--- a/Admin/Manager.cs
+++ b/Admin/Manager.cs
@@ -17,6 +17,8 @@ namespace IW4MAdmin
{
static Manager Instance;
public List Servers { get; private set; }
+ Database ClientDatabase;
+ SharedLibrary.Interfaces.IPenaltyList ClientPenalties;
List Commands;
Kayak.IScheduler webServiceTask;
Thread WebThread;
@@ -35,6 +37,9 @@ namespace IW4MAdmin
Logger = new Log(logFile, Log.Level.Production, 0);
Servers = new List();
Commands = new List();
+
+ ClientDatabase = new ClientsDB("Database/clients.rm");
+ ClientPenalties = new PenaltyList();
}
public List GetServers()
@@ -59,6 +64,7 @@ namespace IW4MAdmin
if (Configs.Count() == 0)
Config.Generate();
+ SharedLibrary.WebService.Init();
PluginImporter.Load();
foreach (var file in Configs)
@@ -87,7 +93,6 @@ namespace IW4MAdmin
}
- SharedLibrary.WebService.Init();
webServiceTask = WebService.getScheduler();
WebThread = new Thread(webServiceTask.Start);
@@ -136,5 +141,15 @@ namespace IW4MAdmin
{
Running = false;
}
+
+ public ClientsDB GetClientDatabase()
+ {
+ return ClientDatabase as ClientsDB;
+ }
+
+ public SharedLibrary.Interfaces.IPenaltyList GetClientPenalties()
+ {
+ return ClientPenalties;
+ }
}
}
diff --git a/Admin/PenaltyList.cs b/Admin/PenaltyList.cs
new file mode 100644
index 000000000..76eb4b03e
--- /dev/null
+++ b/Admin/PenaltyList.cs
@@ -0,0 +1,36 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SharedLibrary;
+
+namespace IW4MAdmin
+{
+ class PenaltyList : SharedLibrary.Interfaces.IPenaltyList
+ {
+ public PenaltyList()
+ {
+ }
+
+ public void AddPenalty(Penalty P)
+ {
+ Manager.GetInstance().GetClientDatabase().addBan(P);
+ }
+
+ public void RemovePenalty(Penalty P)
+ {
+ Manager.GetInstance().GetClientDatabase().removeBan(P.npID);
+ }
+
+ public List FindPenalties(Player P)
+ {
+ return Manager.GetInstance().GetClientDatabase().GetClientPenalties(P);
+ }
+
+ public List AsChronoList(int offset, int count)
+ {
+ return Manager.GetInstance().GetClientDatabase().GetPenaltiesChronologically(offset, count);
+ }
+ }
+}
diff --git a/Admin/Plugins.cs b/Admin/Plugins.cs
index 243d536cf..202a4abff 100644
--- a/Admin/Plugins.cs
+++ b/Admin/Plugins.cs
@@ -70,7 +70,7 @@ namespace IW4MAdmin
if (potentialPlugins.Find(x => x.Name == newNotify.Name) == null)
{
potentialPlugins.Add(newNotify);
- newNotify.OnLoad();
+ newNotify.OnLoadAsync();
Manager.GetInstance().Logger.Write("Loaded plugin \"" + newNotify.Name + "\"" + " [" + newNotify.Version + "]", Log.Level.Debug);
totalLoaded++;
}
diff --git a/Admin/Properties/AssemblyInfo.cs b/Admin/Properties/AssemblyInfo.cs
index 81f067e13..da5918ddf 100644
--- a/Admin/Properties/AssemblyInfo.cs
+++ b/Admin/Properties/AssemblyInfo.cs
@@ -7,11 +7,11 @@ using System.Resources;
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("IW4M Admin")]
-[assembly: AssemblyDescription("Server admin for your IW4M Servers")]
+[assembly: AssemblyDescription("Server administration for your IW4X Servers")]
[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("RaidMax LLC")]
+[assembly: AssemblyCompany("ForeverNone LLC")]
[assembly: AssemblyProduct("")]
-[assembly: AssemblyCopyright("2016")]
+[assembly: AssemblyCopyright("2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -33,5 +33,5 @@ using System.Resources;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.2.*")]
+[assembly: AssemblyVersion("1.3.*")]
[assembly: NeutralResourcesLanguageAttribute("en")]
diff --git a/Admin/Server.cs b/Admin/Server.cs
index 1bb497800..6e8238712 100644
--- a/Admin/Server.cs
+++ b/Admin/Server.cs
@@ -68,18 +68,18 @@ namespace IW4MAdmin
try
#endif
{
- Player NewPlayer = clientDB.getPlayer(P.npID, P.clientID);
+ Player NewPlayer = Manager.GetClientDatabase().getPlayer(P.npID, P.clientID);
if (NewPlayer == null) // first time connecting
{
Log.Write("Client slot #" + P.clientID + " first time connecting", Log.Level.All);
- clientDB.addPlayer(P);
- NewPlayer = clientDB.getPlayer(P.npID, P.clientID);
+ Manager.GetClientDatabase().addPlayer(P);
+ NewPlayer = Manager.GetClientDatabase().getPlayer(P.npID, P.clientID);
aliasDB.addPlayer(new Aliases(NewPlayer.databaseID, NewPlayer.Name, NewPlayer.IP));
}
- List Admins = clientDB.getAdmins();
+ List Admins = Manager.GetClientDatabase().getAdmins();
if (Admins.Find(x => x.Name == P.Name) != null)
{
if ((Admins.Find(x => x.Name == P.Name).npID != P.npID) && NewPlayer.Level < Player.Permission.Moderator)
@@ -116,7 +116,7 @@ namespace IW4MAdmin
NewPlayer.updateIP(P.IP);
aliasDB.updatePlayer(NewPlayer.Alias);
- clientDB.updatePlayer(NewPlayer);
+ Manager.GetClientDatabase().updatePlayer(NewPlayer);
await ExecuteEvent(new Event(Event.GType.Connect, "", NewPlayer, null, this));
@@ -214,7 +214,7 @@ namespace IW4MAdmin
{
Player Leaving = Players[cNum];
Leaving.Connections++;
- clientDB.updatePlayer(Leaving);
+ Manager.GetClientDatabase().updatePlayer(Leaving);
Log.Write("Client at " + cNum + " disconnecting...", Log.Level.Debug);
await ExecuteEvent(new Event(Event.GType.Disconnect, "", Leaving, null, this));
@@ -266,28 +266,7 @@ namespace IW4MAdmin
//Check ban list for every banned player and return ban if match is found
override public Penalty isBanned(Player C)
{
- if (C.Level == Player.Permission.Banned)
- return Bans.Find(p => p.npID.Equals(C.npID));
-
- foreach (Penalty B in Bans)
- {
- if (B.npID.Length < 5 || B.IP.Length < 5)
- continue;
-
- if (B.npID == null || C.npID == null)
- continue;
-
- if (B.npID == C.npID)
- return B;
-
- if (B.IP == null || C.IP == null)
- continue;
-
- if (C.IP == B.IP)
- return B;
- }
-
- return null;
+ return Manager.GetClientPenalties().FindPenalties(C).Where(b => b.BType == Penalty.Type.Ban).FirstOrDefault();
}
//Process requested command correlating to an event
@@ -328,7 +307,7 @@ namespace IW4MAdmin
int.TryParse(Args[0].Substring(1, Args[0].Length-1), out dbID);
IW4MServer castServer = (IW4MServer)(E.Owner);
- Player found = castServer.clientDB.getPlayer(dbID);
+ Player found = Manager.GetClientDatabase().getPlayer(dbID);
if (found != null)
{
E.Target = found;
@@ -363,7 +342,7 @@ namespace IW4MAdmin
{
try
{
- await P.OnEvent(E, this);
+ await P.OnEventAsync(E, this);
}
catch (Exception Except)
@@ -413,7 +392,7 @@ namespace IW4MAdmin
if ((DateTime.Now - tickTime).TotalMilliseconds >= 1000)
{
foreach (var Plugin in PluginImporter.potentialPlugins)
- await Plugin.OnTick(this);
+ await Plugin.OnTickAsync(this);
tickTime = DateTime.Now;
}
@@ -555,7 +534,7 @@ namespace IW4MAdmin
logFile = new IFile(logPath);
Log.Write("Log file is " + logPath, Log.Level.Debug);
await ExecuteEvent(new Event(Event.GType.Start, "Server started", null, null, this));
- //Bans = clientDB.getBans();
+ //Bans = Manager.GetClientDatabase().getBans();
#if !DEBUG
Broadcast("IW4M Admin is now ^2ONLINE");
#endif
@@ -706,10 +685,8 @@ namespace IW4MAdmin
await Target.Kick("Too many warnings!", Origin);
else
{
- Penalty newPenalty = new Penalty(Penalty.Type.Warning, SharedLibrary.Utilities.StripColors(Reason), Target.npID, Origin.npID, DateTime.Now, Target.IP);
- clientDB.addBan(newPenalty);
- foreach (var S in Manager.GetServers()) // make sure bans show up on the webfront
- S.Bans = S.clientDB.getBans();
+ Penalty newPenalty = new Penalty(Penalty.Type.Warning, Reason.StripColors(), Target.npID, Origin.npID, DateTime.Now, Target.IP);
+ Manager.GetClientPenalties().AddPenalty(newPenalty);
Target.Warnings++;
String Message = String.Format("^1WARNING ^7[^3{0}^7]: ^3{1}^7, {2}", Target.Warnings, Target.Name, Target.lastOffense);
await Broadcast(Message);
@@ -721,10 +698,8 @@ namespace IW4MAdmin
if (Target.clientID > -1)
{
String Message = "^1Player Kicked: ^5" + Reason;
- Penalty newPenalty = new Penalty(Penalty.Type.Kick, SharedLibrary.Utilities.StripColors(Reason.Trim()), Target.npID, Origin.npID, DateTime.Now, Target.IP);
- clientDB.addBan(newPenalty);
- foreach (Server S in Manager.GetServers()) // make sure bans show up on the webfront
- S.Bans = S.clientDB.getBans();
+ Penalty newPenalty = new Penalty(Penalty.Type.Kick, Reason.StripColors().Trim(), Target.npID, Origin.npID, DateTime.Now, Target.IP);
+ Manager.GetClientPenalties().AddPenalty(newPenalty);
await this.ExecuteCommandAsync("clientkick " + Target.clientID + " \"" + Message + "^7\"");
}
}
@@ -737,10 +712,7 @@ namespace IW4MAdmin
Penalty newPenalty = new Penalty(Penalty.Type.TempBan, SharedLibrary.Utilities.StripColors(Reason), Target.npID, Origin.npID, DateTime.Now, Target.IP);
await Task.Run(() =>
{
- // todo: single database.. again
- foreach (Server S in Manager.GetServers()) // make sure bans show up on the webfront
- S.Bans = S.clientDB.getBans();
- clientDB.addBan(newPenalty);
+ Manager.GetClientPenalties().AddPenalty(newPenalty);
});
}
}
@@ -778,11 +750,8 @@ namespace IW4MAdmin
await Task.Run(() =>
{
- clientDB.addBan(newBan);
- clientDB.updatePlayer(Target);
-
- foreach (Server S in Manager.GetServers()) // make sure bans show up on the webfront
- S.Bans = S.clientDB.getBans();
+ Manager.GetClientPenalties().AddPenalty(newBan);
+ Manager.GetClientDatabase().updatePlayer(Target);
});
lock (Reports) // threading seems to do something weird here
@@ -803,27 +772,24 @@ namespace IW4MAdmin
}
}
- override public async Task Unban(String GUID, Player Target)
+ override public async Task Unban(Player Target)
{
- foreach (Penalty B in Bans)
+ // database stuff can be time consuming
+ await Task.Run(() =>
{
- if (B.npID == Target.npID)
- {
- // database stuff can be time consuming
- await Task.Run(() =>
- {
- clientDB.removeBan(Target.npID, Target.IP);
+ var FoundPenalaties = Manager.GetClientPenalties().FindPenalties(Target);
+ var PenaltyToRemove = FoundPenalaties.Find(b => b.BType == Penalty.Type.Ban);
- Player P = clientDB.getPlayer(Target.npID, -1);
- P.setLevel(Player.Permission.User);
- clientDB.updatePlayer(P);
+ if (PenaltyToRemove == null)
+ return;
+
+ Manager.GetClientPenalties().RemovePenalty(PenaltyToRemove);
+
+ Player P = Manager.GetClientDatabase().getPlayer(Target.npID, -1);
+ P.setLevel(Player.Permission.User);
+ Manager.GetClientDatabase().updatePlayer(P);
+ });
- // todo: single database
- foreach (Server S in Manager.GetServers()) // make sure bans show up on the webfront
- S.Bans = S.clientDB.getBans();
- });
- }
- }
}
public override bool Reload()
@@ -856,7 +822,7 @@ namespace IW4MAdmin
override public void initMacros()
{
Macros = new Dictionary();
- Macros.Add("TOTALPLAYERS", clientDB.totalPlayers());
+ Macros.Add("TOTALPLAYERS", Manager.GetClientDatabase().totalPlayers());
Macros.Add("TOTALKILLS", totalKills);
Macros.Add("VERSION", IW4MAdmin.Program.Version);
}
diff --git a/Admin/WebService.cs b/Admin/WebService.cs
index 174f270db..201131234 100644
--- a/Admin/WebService.cs
+++ b/Admin/WebService.cs
@@ -288,7 +288,7 @@ namespace IW4MAdmin
if (S != null)
{
- Player admin = Manager.GetInstance().Servers.First().clientDB.getPlayer(querySet["IP"]);
+ Player admin = Manager.GetInstance().GetClientDatabase().getPlayer(querySet["IP"]);
if (admin == null)
admin = new Player("RestUser", "-1", -1, (int)Player.Permission.User);
@@ -354,7 +354,8 @@ namespace IW4MAdmin
try
{
- selectedPenalties = Manager.GetInstance().Servers.First().Bans.OrderByDescending(x => x.When).ToList().GetRange(Convert.ToInt32(querySet["from"]), 15);
+ //selectedPenalties = Manager.GetInstance().Servers.First().Bans.OrderByDescending(x => x.When).ToList().GetRange(Convert.ToInt32(querySet["from"]), 15);
+ selectedPenalties = ((Manager.GetInstance().GetClientPenalties()) as PenaltyList).AsChronoList(Convert.ToInt32(querySet["from"]), 15).OrderByDescending(b => b.When).ToList();
}
catch (Exception)
@@ -366,8 +367,8 @@ namespace IW4MAdmin
foreach (var p in selectedPenalties)
{
- Player admin = Manager.GetInstance().Servers.First().clientDB.getPlayer(p.bannedByID, 0);
- Player penalized = Manager.GetInstance().Servers.First().clientDB.getPlayer(p.npID, 0);
+ Player admin = Manager.GetInstance().GetClientDatabase().getPlayer(p.bannedByID, 0);
+ Player penalized = Manager.GetInstance().GetClientDatabase().getPlayer(p.npID, 0);
if (admin == null && penalized == null)
continue;
if (admin == null)
@@ -503,7 +504,7 @@ namespace IW4MAdmin
{
HttpResponse resp = new HttpResponse();
resp.contentType = getContentType();
- resp.content = Newtonsoft.Json.JsonConvert.SerializeObject(Manager.GetInstance().Servers[0].Bans.Where(x => x.BType == Penalty.Type.Ban), Newtonsoft.Json.Formatting.Indented, new Newtonsoft.Json.JsonConverter[] { new Newtonsoft.Json.Converters.StringEnumConverter() });
+ resp.content = Newtonsoft.Json.JsonConvert.SerializeObject(((Manager.GetInstance().GetClientPenalties()) as PenaltyList).AsChronoList(Convert.ToInt32(querySet["from"]), 15), Newtonsoft.Json.Formatting.Indented, new Newtonsoft.Json.JsonConverter[] { new Newtonsoft.Json.Converters.StringEnumConverter() });
resp.additionalHeaders = new Dictionary();
return resp;
}
@@ -591,29 +592,26 @@ namespace IW4MAdmin
resp.contentType = getContentType();
resp.additionalHeaders = new Dictionary();
- bool authed = Manager.GetInstance().Servers.First().clientDB.getAdmins().FindAll(x => x.IP == querySet["IP"]).Count > 0;
+ bool authed = Manager.GetInstance().GetClientDatabase().getAdmins().FindAll(x => x.IP == querySet["IP"]).Count > 0;
if (querySet["id"] != null)
{
- matchedPlayers.Add(Manager.GetInstance().Servers.First().clientDB.getPlayer(Convert.ToInt32(querySet["id"])));
+ matchedPlayers.Add(Manager.GetInstance().GetClientDatabase().getPlayer(Convert.ToInt32(querySet["id"])));
}
else if (querySet["npID"] != null)
{
- matchedPlayers.Add(Manager.GetInstance().Servers.First().clientDB.getPlayers(new List { querySet["npID"] }).First());
+ matchedPlayers.Add(Manager.GetInstance().GetClientDatabase().getPlayers(new List { querySet["npID"] }).First());
}
else if (querySet["name"] != null)
{
- matchedPlayers = Manager.GetInstance().Servers.First().clientDB.findPlayers(querySet["name"]);
+ matchedPlayers = Manager.GetInstance().GetClientDatabase().findPlayers(querySet["name"]);
}
else if (querySet["recent"] != null)
{
- if (Manager.GetInstance().Servers.Count > 0)
- matchedPlayers = Manager.GetInstance().Servers.First().clientDB.getRecentPlayers();
- else
- resp.content = Newtonsoft.Json.JsonConvert.SerializeObject(null);
+ matchedPlayers = Manager.GetInstance().GetClientDatabase().getRecentPlayers();
}
if (matchedPlayers != null && matchedPlayers.Count > 0)
@@ -631,8 +629,7 @@ namespace IW4MAdmin
eachPlayer.playernpID = pp.npID;
eachPlayer.forumID = -1;
eachPlayer.authed = authed;
- if (eachPlayer.forumID < 500000)
- eachPlayer.showV2Features = true;
+ eachPlayer.showV2Features = false;
foreach (var a in playerAliases)
{
diff --git a/Admin/lib/SharedLibrary.dll b/Admin/lib/SharedLibrary.dll
index e1a0d44ca..0ca9621d0 100644
Binary files a/Admin/lib/SharedLibrary.dll and b/Admin/lib/SharedLibrary.dll differ
diff --git a/Auto Restart Plugin/Main.cs b/Auto Restart Plugin/Main.cs
index 421a8c98c..d22c4f7f0 100644
--- a/Auto Restart Plugin/Main.cs
+++ b/Auto Restart Plugin/Main.cs
@@ -31,17 +31,17 @@ namespace Auto_Restart_Plugin
}
}
- public async Task OnLoad()
+ public async Task OnLoadAsync()
{
return;
}
- public async Task OnUnload()
+ public async Task OnUnloadAsync()
{
return;
}
- public async Task OnTick(Server S)
+ public async Task OnTickAsync(Server S)
{
switch (Monitoring.shouldRestart())
{
@@ -64,7 +64,7 @@ namespace Auto_Restart_Plugin
}
}
- public async Task OnEvent(Event E, Server S)
+ public async Task OnEventAsync(Event E, Server S)
{
return;
}
diff --git a/EventAPI/EventAPI.csproj b/EventAPI/EventAPI.csproj
index 68fa7925f..d7e7ff8f7 100644
--- a/EventAPI/EventAPI.csproj
+++ b/EventAPI/EventAPI.csproj
@@ -48,9 +48,8 @@
-
- ..\packages\Newtonsoft.Json.9.0.1\lib\net40\Newtonsoft.Json.dll
- False
+
+ ..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll
diff --git a/EventAPI/Plugin.cs b/EventAPI/Plugin.cs
index 04dd0c233..9715adaff 100644
--- a/EventAPI/Plugin.cs
+++ b/EventAPI/Plugin.cs
@@ -95,7 +95,7 @@ namespace EventAPI
}
}
- public async Task OnLoad()
+ public async Task OnLoadAsync()
{
apiEvents = new Queue();
flaggedMessagesText = new List();
@@ -103,29 +103,28 @@ namespace EventAPI
WebService.pageList.Add(new EventsJSON());
}
- public async Task OnUnload()
+ public async Task OnUnloadAsync()
{
apiEvents.Clear();
activeServers.Clear();
}
- public async Task OnTick(Server S)
+ public async Task OnTickAsync(Server S)
{
return;
}
- public async Task OnEvent(Event E, Server S)
+ public async Task OnEventAsync(Event E, Server S)
{
if (E.Type == Event.GType.Start)
{
activeServers.Add(S);
- S.Log.Write("Event API now running on " + S.getName(), Log.Level.Production);
}
if (E.Type == Event.GType.Stop)
{
+ // fixme: this will be bad once FTP is working and there can be multiple servers on the same port.
activeServers.RemoveAll(s => s.getPort() == S.getPort());
- S.Log.Write("Event API no longer running on " + S.getName(), Log.Level.Production);
}
if (E.Type == Event.GType.Connect)
diff --git a/EventAPI/packages.config b/EventAPI/packages.config
index 0cdd293b3..a272c64df 100644
--- a/EventAPI/packages.config
+++ b/EventAPI/packages.config
@@ -1,4 +1,4 @@
-
+
\ No newline at end of file
diff --git a/MessageboardPlugin/Forum.cs b/MessageboardPlugin/Forum.cs
index f6345a6c7..036789502 100644
--- a/MessageboardPlugin/Forum.cs
+++ b/MessageboardPlugin/Forum.cs
@@ -54,7 +54,7 @@ namespace MessageBoard.Forum
{
forumPages = new List();
activeSessions = new List();
- database = new Storage.Database("forum.db");
+ database = new Storage.Database("Database/forum.db");
}
public void startSession(string sessionID)
diff --git a/MessageboardPlugin/MessageboardPlugin.csproj b/MessageboardPlugin/MessageboardPlugin.csproj
index decbd7f06..0f897a327 100644
--- a/MessageboardPlugin/MessageboardPlugin.csproj
+++ b/MessageboardPlugin/MessageboardPlugin.csproj
@@ -62,9 +62,8 @@
..\packages\DNA.Text.2.1.1.10633\lib\DNA.Text.dll
True
-
- ..\packages\Newtonsoft.Json.9.0.1\lib\net40\Newtonsoft.Json.dll
- False
+
+ ..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll
diff --git a/MessageboardPlugin/Plugin.cs b/MessageboardPlugin/Plugin.cs
index 14a6f3195..79abe9949 100644
--- a/MessageboardPlugin/Plugin.cs
+++ b/MessageboardPlugin/Plugin.cs
@@ -34,23 +34,23 @@ namespace MessageBoard.Plugin
}
}
- public async Task OnLoad()
+ public async Task OnLoadAsync()
{
forum = new Forum.Manager();
forum.Start();
}
- public async Task OnUnload()
+ public async Task OnUnloadAsync()
{
forum.Stop();
}
- public async Task OnTick(Server S)
+ public async Task OnTickAsync(Server S)
{
return;
}
- public async Task OnEvent(Event E, Server S)
+ public async Task OnEventAsync(Event E, Server S)
{
if (E.Type == Event.GType.Start)
{
diff --git a/MessageboardPlugin/packages.config b/MessageboardPlugin/packages.config
index 2cc52d7ea..bb9bbeecc 100644
--- a/MessageboardPlugin/packages.config
+++ b/MessageboardPlugin/packages.config
@@ -3,5 +3,5 @@
-
+
\ No newline at end of file
diff --git a/SharedLibrary/Commands/NativeCommands.cs b/SharedLibrary/Commands/NativeCommands.cs
index 7a2e9fcce..8f743a211 100644
--- a/SharedLibrary/Commands/NativeCommands.cs
+++ b/SharedLibrary/Commands/NativeCommands.cs
@@ -24,12 +24,12 @@ namespace SharedLibrary.Commands
public override async Task ExecuteAsync(Event E)
{
- if (E.Owner.clientDB.getOwner() == null)
+ if (E.Owner.Manager.GetClientDatabase().getOwner() == null)
{
E.Origin.setLevel(Player.Permission.Owner);
await E.Origin.Tell("Congratulations, you have claimed ownership of this server!");
E.Owner.owner = E.Origin;
- E.Owner.clientDB.updatePlayer(E.Origin);
+ E.Owner.Manager.GetClientDatabase().updatePlayer(E.Origin);
}
else
await E.Origin.Tell("This server already has an owner!");
@@ -131,7 +131,7 @@ namespace SharedLibrary.Commands
public override async Task ExecuteAsync(Event E)
{
- await E.Owner.Unban(E.Data.Trim(), E.Target);
+ await E.Owner.Unban(E.Target);
await E.Origin.Tell($"Successfully unbanned {E.Target.Name}::{E.Target.npID}");
}
}
@@ -236,7 +236,7 @@ namespace SharedLibrary.Commands
public override async Task ExecuteAsync(Event E)
{
- await E.Owner.Broadcast("Performing fast restart...");
+ await E.Owner.Broadcast($"Fast restarting in ^53 ^7seconds [^5{E.Origin.Name}]");
await Task.Delay(3000);
await E.Owner.ExecuteCommandAsync("fast_restart");
}
@@ -248,8 +248,8 @@ namespace SharedLibrary.Commands
public override async Task ExecuteAsync(Event E)
{
- await E.Owner.Broadcast("Performing map rotate...");
- await Task.Delay(3000);
+ await E.Owner.Broadcast($"Map rotating in ^55 ^7seconds [^5{E.Origin.Name}]");
+ await Task.Delay(5000);
await E.Owner.ExecuteCommandAsync("map_rotate");
}
}
@@ -296,7 +296,7 @@ namespace SharedLibrary.Commands
await E.Origin.Tell(E.Target.Name + " was successfully promoted!");
//NEEED TO MOVE
- E.Owner.clientDB.updatePlayer(E.Target);
+ E.Owner.Manager.GetClientDatabase().updatePlayer(E.Target);
}
else
@@ -370,7 +370,7 @@ namespace SharedLibrary.Commands
public override async Task ExecuteAsync(Event E)
{
- var db_players = E.Owner.clientDB.findPlayers(E.Data.Trim());
+ var db_players = E.Owner.Manager.GetClientDatabase().findPlayers(E.Data.Trim());
if (db_players == null)
{
@@ -400,7 +400,7 @@ namespace SharedLibrary.Commands
return;
}
- //var db_players = E.Owner.clientDB.findPlayers(E.Data.Trim());
+ //var db_players = E.Owner.Manager.GetClientDatabase().findPlayers(E.Data.Trim());
var db_aliases = E.Owner.aliasDB.findPlayers(E.Data);
if (db_aliases == null)
@@ -422,7 +422,7 @@ namespace SharedLibrary.Commands
lookingFor = S;
}
- Player Current = E.Owner.clientDB.getPlayer(P.Number);
+ Player Current = E.Owner.Manager.GetClientDatabase().getPlayer(P.Number);
if (Current != null)
{
@@ -498,7 +498,7 @@ namespace SharedLibrary.Commands
await E.Origin.Tell("You have ^5flagged ^7" + E.Target.Name);
}
- E.Owner.clientDB.updatePlayer(E.Target);
+ E.Owner.Manager.GetClientDatabase().updatePlayer(E.Target);
}
}
@@ -591,15 +591,17 @@ namespace SharedLibrary.Commands
return;
}
- Penalty B = E.Owner.Bans.Find(b => b.npID.Equals(E.Target.npID));
-
- if (B == null)
+ var B = E.Owner.Manager.GetClientPenalties().FindPenalties(E.Target);
+ var BannedPenalty = B.Find(b => b.BType == Penalty.Type.Ban);
+
+
+ if (BannedPenalty == null)
{
await E.Origin.Tell("No active ban was found for that player.");
return;
}
- Player Banner = E.Owner.clientDB.getPlayer(B.bannedByID, -1);
+ Player Banner = E.Owner.Manager.GetClientDatabase().getPlayer(BannedPenalty.bannedByID, -1);
if (Banner == null)
{
@@ -607,7 +609,7 @@ namespace SharedLibrary.Commands
return;
}
- await E.Origin.Tell(String.Format("^1{0} ^7was banned by ^5{1} ^7for: {2}", E.Target.Name, Banner.Name, B.Reason));
+ await E.Origin.Tell(String.Format("^1{0} ^7was banned by ^5{1} ^7for: {2}", E.Target.Name, Banner.Name, BannedPenalty.Reason));
}
}
diff --git a/SharedLibrary/Database.cs b/SharedLibrary/Database.cs
index be6504e1a..6f8cfb754 100644
--- a/SharedLibrary/Database.cs
+++ b/SharedLibrary/Database.cs
@@ -157,7 +157,7 @@ namespace SharedLibrary
catch (Exception e)
{
//LOGME
- Console.Write("Could not execute");
+ Console.WriteLine($"Line 160: {e.Message}");
}
return dt;
@@ -178,7 +178,7 @@ namespace SharedLibrary
catch (Exception e)
{
//LOGME
- Console.Write("Couldnotexecute");
+ Console.Write($"Line 181: {e.Message}");
}
return dt;
@@ -263,7 +263,7 @@ namespace SharedLibrary
public List getRecentPlayers()
{
List returnssss = new List();
- String Query = String.Format("SELECT * FROM CLIENTS ORDER BY Connections desc LIMIT 25");
+ String Query = String.Format($"SELECT * FROM CLIENTS LIMIT 15 OFFSET (SELECT COUNT(*) FROM CLIENTS)-15");
DataTable Result = GetDataTable(Query);
if (Result != null && Result.Rows.Count > 0)
@@ -277,25 +277,9 @@ namespace SharedLibrary
}
}
- return returnssss;
+ return returnssss.OrderByDescending(p => p.LastConnection).ToList(); ;
}
- public List getReservedNPIDs()
- {
- List npIDs = new List();
- String Query = String.Format("SELECT npID FROM CLIENTS WHERE Reserved = 1");
- DataTable Result = GetDataTable(Query);
-
- if (Result != null && Result.Rows.Count > 0)
- foreach (DataRow ResponseRow in Result.Rows)
- npIDs.Add(ResponseRow["npID"].ToString());
-
-
- return npIDs;
- }
-
-
-
public List getPlayers(List npIDs)
{
List returnssss = new List();
@@ -459,11 +443,11 @@ namespace SharedLibrary
return null;
}
- //Returns list of bans in database
- public List getBans()
+ public List GetClientPenalties(Player P)
{
- List Bans = new List();
- DataTable Result = GetDataTable("SELECT * FROM BANS ORDER BY TIME DESC");
+ List ClientPenalties = new List();
+ String Query = $"SELECT * FROM `BANS` WHERE `npID` = '{P.npID}' OR `IP` = '{P.IP}'";
+ DataTable Result = GetDataTable(Query);
foreach (DataRow Row in Result.Rows)
{
@@ -474,11 +458,32 @@ namespace SharedLibrary
if (Row["TYPE"].ToString().Length != 0)
BanType = (Penalty.Type)Enum.Parse(typeof(Penalty.Type), Row["TYPE"].ToString());
- Bans.Add(new Penalty(BanType, Row["Reason"].ToString().Trim(), Row["npID"].ToString(), Row["bannedByID"].ToString(), DateTime.Parse(Row["TIME"].ToString()), Row["IP"].ToString()));
+ ClientPenalties.Add(new Penalty(BanType, Row["Reason"].ToString().Trim(), Row["npID"].ToString(), Row["bannedByID"].ToString(), DateTime.Parse(Row["TIME"].ToString()), Row["IP"].ToString()));
}
- return Bans;
+ return ClientPenalties;
+ }
+
+ public List GetPenaltiesChronologically(int offset, int count)
+ {
+ List ClientPenalties = new List();
+ DataTable Result = GetDataTable($"SELECT * FROM BANS LIMIT {count} OFFSET (SELECT COUNT(*) FROM BANS)-{offset + 10}");
+
+ foreach (DataRow Row in Result.Rows)
+ {
+ if (Row["TIME"].ToString().Length < 2) //compatibility with my old database
+ Row["TIME"] = DateTime.Now.ToString();
+
+ SharedLibrary.Penalty.Type BanType = Penalty.Type.Ban;
+ if (Row["TYPE"].ToString().Length != 0)
+ BanType = (Penalty.Type)Enum.Parse(typeof(Penalty.Type), Row["TYPE"].ToString());
+
+ ClientPenalties.Add(new Penalty(BanType, Row["Reason"].ToString().Trim(), Row["npID"].ToString(), Row["bannedByID"].ToString(), DateTime.Parse(Row["TIME"].ToString()), Row["IP"].ToString()));
+
+ }
+
+ return ClientPenalties;
}
//Returns all players with level > Flagged
diff --git a/SharedLibrary/Interfaces/IManager.cs b/SharedLibrary/Interfaces/IManager.cs
index 6a3b4e46f..4eae7cde6 100644
--- a/SharedLibrary/Interfaces/IManager.cs
+++ b/SharedLibrary/Interfaces/IManager.cs
@@ -13,5 +13,7 @@ namespace SharedLibrary.Interfaces
void Stop();
List GetServers();
List GetCommands();
+ IPenaltyList GetClientPenalties();
+ ClientsDB GetClientDatabase();
}
}
diff --git a/SharedLibrary/Interfaces/IPenaltyList.cs b/SharedLibrary/Interfaces/IPenaltyList.cs
new file mode 100644
index 000000000..3a85b9f65
--- /dev/null
+++ b/SharedLibrary/Interfaces/IPenaltyList.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SharedLibrary.Interfaces
+{
+ public interface IPenaltyList
+ {
+ void AddPenalty(Penalty P);
+ void RemovePenalty(Penalty P);
+ List FindPenalties(Player P);
+ }
+}
diff --git a/SharedLibrary/Interfaces/IPlugin.cs b/SharedLibrary/Interfaces/IPlugin.cs
index e12b7f240..f6e5d7521 100644
--- a/SharedLibrary/Interfaces/IPlugin.cs
+++ b/SharedLibrary/Interfaces/IPlugin.cs
@@ -5,10 +5,10 @@ namespace SharedLibrary.Interfaces
{
public interface IPlugin
{
- Task OnLoad();
- Task OnUnload();
- Task OnEvent(Event E, Server S);
- Task OnTick(Server S);
+ Task OnLoadAsync();
+ Task OnUnloadAsync();
+ Task OnEventAsync(Event E, Server S);
+ Task OnTickAsync(Server S);
//for logging purposes
String Name { get; }
diff --git a/SharedLibrary/Server.cs b/SharedLibrary/Server.cs
index 5f9978ee4..94c6e3b70 100644
--- a/SharedLibrary/Server.cs
+++ b/SharedLibrary/Server.cs
@@ -27,10 +27,8 @@ namespace SharedLibrary
#else
Log = new Log(logFile, Log.Level.Production, port);
#endif
- clientDB = new ClientsDB("Database/clients.rm");
aliasDB = new AliasesDB("Database/aliases.rm");
- Bans = new List();
Players = new List(new Player[18]);
events = new Queue();
Macros = new Dictionary();
@@ -47,7 +45,7 @@ namespace SharedLibrary
var commands = mgr.GetCommands();
- owner = clientDB.getOwner();
+ owner = Manager.GetClientDatabase().getOwner();
if (owner == null)
commands.Add(new Owner("owner", "claim ownership of the server", "owner", Player.Permission.User, 0, false));
@@ -118,11 +116,6 @@ namespace SharedLibrary
return Players.FindAll(x => x != null);
}
- //Returns list of all active bans (loaded at runtime)
- public List getBans()
- {
- return Bans;
- }
public int pID()
{
@@ -142,7 +135,7 @@ namespace SharedLibrary
foreach (Aliases A in getAliases(Origin))
databaseIDs.Add(A.Number);
- return clientDB.getPlayers(databaseIDs);
+ return Manager.GetClientDatabase().getPlayers(databaseIDs);
}
///
@@ -303,7 +296,7 @@ namespace SharedLibrary
/// npID of the player
/// I don't remember what this is for
///
- abstract public Task Unban(String npID, Player Target);
+ abstract public Task Unban(Player Target);
///
/// Change the current searver map
@@ -437,7 +430,6 @@ namespace SharedLibrary
//Objects
public Interfaces.IManager Manager { get; protected set; }
public Log Log { get; private set; }
- public List Bans;
public Player owner;
public List
///
- public async Task OnTick(Server S)
+ public async Task OnTickAsync(Server S)
{
var serverVotes = getServerVotes(S.getPort());
@@ -277,7 +277,7 @@ namespace Votemap_Plugin
}
}
- public async Task OnEvent(Event E, Server S)
+ public async Task OnEventAsync(Event E, Server S)
{
if (E.Type == Event.GType.Start)
{
diff --git a/Welcome Plugin/Plugin.cs b/Welcome Plugin/Plugin.cs
index 20d951aca..68584c9fb 100644
--- a/Welcome Plugin/Plugin.cs
+++ b/Welcome Plugin/Plugin.cs
@@ -31,22 +31,22 @@ namespace Welcome_Plugin
}
}
- public async Task OnLoad()
+ public async Task OnLoadAsync()
{
return;
}
- public async Task OnUnload()
+ public async Task OnUnloadAsync()
{
return;
}
- public async Task OnTick(Server S)
+ public async Task OnTickAsync(Server S)
{
return;
}
- public async Task OnEvent(Event E, Server S)
+ public async Task OnEventAsync(Event E, Server S)
{
if (E.Type == Event.GType.Connect)
{