Moved client database into manager, as it should be.. Some more transitional things and a few fixes.

This commit is contained in:
RaidMax 2017-05-27 17:08:04 -05:00
parent c151bcbdae
commit c1faf8a02e
26 changed files with 215 additions and 186 deletions

View File

@ -31,7 +31,7 @@
<CreateWebPageOnPublish>true</CreateWebPageOnPublish>
<WebPage>publish.htm</WebPage>
<ApplicationRevision>6</ApplicationRevision>
<ApplicationVersion>0.9.1.%2a</ApplicationVersion>
<ApplicationVersion>1.3.1.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
@ -55,7 +55,7 @@
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>0</WarningLevel>
<WarningLevel>3</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GenerateSerializationAssemblies>On</GenerateSerializationAssemblies>
<Prefer32Bit>false</Prefer32Bit>
@ -115,6 +115,7 @@
<Compile Include="Kayak.cs" />
<Compile Include="Main.cs" />
<Compile Include="Manager.cs" />
<Compile Include="PenaltyList.cs" />
<Compile Include="Plugins.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Settings.Designer.cs">

View File

@ -17,6 +17,8 @@ namespace IW4MAdmin
{
static Manager Instance;
public List<Server> Servers { get; private set; }
Database ClientDatabase;
SharedLibrary.Interfaces.IPenaltyList ClientPenalties;
List<Command> Commands;
Kayak.IScheduler webServiceTask;
Thread WebThread;
@ -35,6 +37,9 @@ namespace IW4MAdmin
Logger = new Log(logFile, Log.Level.Production, 0);
Servers = new List<Server>();
Commands = new List<Command>();
ClientDatabase = new ClientsDB("Database/clients.rm");
ClientPenalties = new PenaltyList();
}
public List<Server> 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;
}
}
}

36
Admin/PenaltyList.cs Normal file
View File

@ -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<Penalty> FindPenalties(Player P)
{
return Manager.GetInstance().GetClientDatabase().GetClientPenalties(P);
}
public List<Penalty> AsChronoList(int offset, int count)
{
return Manager.GetInstance().GetClientDatabase().GetPenaltiesChronologically(offset, count);
}
}
}

View File

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

View File

@ -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")]

View File

@ -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<Player> Admins = clientDB.getAdmins();
List<Player> 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<String, Object>();
Macros.Add("TOTALPLAYERS", clientDB.totalPlayers());
Macros.Add("TOTALPLAYERS", Manager.GetClientDatabase().totalPlayers());
Macros.Add("TOTALKILLS", totalKills);
Macros.Add("VERSION", IW4MAdmin.Program.Version);
}

View File

@ -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<string, string>();
return resp;
}
@ -591,29 +592,26 @@ namespace IW4MAdmin
resp.contentType = getContentType();
resp.additionalHeaders = new Dictionary<string, string>();
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<string> { querySet["npID"] }).First());
matchedPlayers.Add(Manager.GetInstance().GetClientDatabase().getPlayers(new List<string> { 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)
{

Binary file not shown.

View File

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

View File

@ -48,9 +48,8 @@
<Compile Include="Plugin.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net40\Newtonsoft.Json.dll</HintPath>
<Private>False</Private>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
</ItemGroup>

View File

@ -95,7 +95,7 @@ namespace EventAPI
}
}
public async Task OnLoad()
public async Task OnLoadAsync()
{
apiEvents = new Queue<RestEvent>();
flaggedMessagesText = new List<string>();
@ -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)

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net40" requireReinstallation="true" />
<package id="Newtonsoft.Json" version="10.0.2" targetFramework="net45" />
</packages>

View File

@ -54,7 +54,7 @@ namespace MessageBoard.Forum
{
forumPages = new List<IPage>();
activeSessions = new List<Session>();
database = new Storage.Database("forum.db");
database = new Storage.Database("Database/forum.db");
}
public void startSession(string sessionID)

View File

@ -62,9 +62,8 @@
<HintPath>..\packages\DNA.Text.2.1.1.10633\lib\DNA.Text.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net40\Newtonsoft.Json.dll</HintPath>
<Private>False</Private>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />

View File

@ -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)
{

View File

@ -3,5 +3,5 @@
<package id="CodeKicker.BBCode" version="5.0.0.0" targetFramework="net40" />
<package id="CryptSharp" version="1.2.0.1" targetFramework="net40" />
<package id="DNA.Text" version="2.1.1.10633" targetFramework="net40" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net40" requireReinstallation="true" />
<package id="Newtonsoft.Json" version="10.0.2" targetFramework="net45" />
</packages>

View File

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

View File

@ -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<Player> getRecentPlayers()
{
List<Player> returnssss = new List<Player>();
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<string> getReservedNPIDs()
{
List<string> npIDs = new List<string>();
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<Player> getPlayers(List<String> npIDs)
{
List<Player> returnssss = new List<Player>();
@ -459,11 +443,11 @@ namespace SharedLibrary
return null;
}
//Returns list of bans in database
public List<Penalty> getBans()
public List<Penalty> GetClientPenalties(Player P)
{
List<Penalty> Bans = new List<Penalty>();
DataTable Result = GetDataTable("SELECT * FROM BANS ORDER BY TIME DESC");
List<Penalty> ClientPenalties = new List<Penalty>();
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<Penalty> GetPenaltiesChronologically(int offset, int count)
{
List<Penalty> ClientPenalties = new List<Penalty>();
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

View File

@ -13,5 +13,7 @@ namespace SharedLibrary.Interfaces
void Stop();
List<Server> GetServers();
List<Command> GetCommands();
IPenaltyList GetClientPenalties();
ClientsDB GetClientDatabase();
}
}

View File

@ -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<Penalty> FindPenalties(Player P);
}
}

View File

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

View File

@ -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<Penalty>();
Players = new List<Player>(new Player[18]);
events = new Queue<Event>();
Macros = new Dictionary<String, Object>();
@ -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<Penalty> 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);
}
/// <summary>
@ -303,7 +296,7 @@ namespace SharedLibrary
/// <param name="npID">npID of the player</param>
/// <param name="Target">I don't remember what this is for</param>
/// <returns></returns>
abstract public Task Unban(String npID, Player Target);
abstract public Task Unban(Player Target);
/// <summary>
/// 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<Penalty> Bans;
public Player owner;
public List<Map> maps;
public List<String> rules;
@ -479,7 +471,7 @@ namespace SharedLibrary
protected String Mod;
// Databases
public ClientsDB clientDB;
//public ClientsDB clientDB;
public AliasesDB aliasDB;
//Remote

View File

@ -60,6 +60,7 @@
<Compile Include="Exceptions\NetworkException.cs" />
<Compile Include="Exceptions\ServerException.cs" />
<Compile Include="Interfaces\IManager.cs" />
<Compile Include="Interfaces\IPenaltyList.cs" />
<Compile Include="Interfaces\ISerializable.cs" />
<Compile Include="Penalty.cs" />
<Compile Include="Command.cs" />

View File

@ -46,7 +46,7 @@ namespace StatsPlugin
await E.Origin.Tell("^5--Top Players--");
foreach (KeyValuePair<String, PlayerStats> pStat in pStats)
{
Player P = E.Owner.clientDB.getPlayer(pStat.Key, -1);
Player P = E.Owner.Manager.GetClientDatabase().getPlayer(pStat.Key, -1);
if (P == null)
continue;
await E.Origin.Tell(String.Format("^3{0}^7 - ^5{1} ^7KDR | ^5{2} ^7SKILL", P.Name, pStat.Value.KDR, pStat.Value.Skill));
@ -71,7 +71,7 @@ namespace StatsPlugin
public StatTracking(int port)
{
playerStats = new StatsDB("stats_" + port + ".rm");
playerStats = new StatsDB("Database/stats_" + port + ".rm");
inactiveMinutes = new int[18];
Kills = new int[18];
deathStreaks = new int[18];
@ -97,22 +97,22 @@ namespace StatsPlugin
get { return "RaidMax"; }
}
public async Task OnLoad()
public async Task OnLoadAsync()
{
statLists = new List<StatTracking>();
}
public async Task OnUnload()
public async Task OnUnloadAsync()
{
statLists.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)
{
@ -132,7 +132,7 @@ namespace StatsPlugin
if (checkForTrusted.playTime >= 4320 && E.Origin.Level < Player.Permission.Trusted)
{
E.Origin.setLevel(Player.Permission.Trusted);
E.Owner.clientDB.updatePlayer(E.Origin);
E.Owner.Manager.GetClientDatabase().updatePlayer(E.Origin);
await E.Origin.Tell("Congratulations, you are now a ^5trusted ^7player! Type ^5!help ^7to view new commands.");
await E.Origin.Tell("You earned this by playing for ^53 ^7full days!");
}

View File

@ -204,12 +204,12 @@ namespace Votemap_Plugin
}
}
public async Task OnLoad()
public async Task OnLoadAsync()
{
serverVotingList = new List<ServerVoting>();
}
public async Task OnUnload()
public async Task OnUnloadAsync()
{
serverVotingList.Clear();
}
@ -219,7 +219,7 @@ namespace Votemap_Plugin
/// This is not high-precision, but will run 1 time per second
/// </summary>
/// <param name="S"></param>
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)
{

View File

@ -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)
{