Moved Alias Database into interface...

This commit is contained in:
RaidMax 2017-05-28 20:54:46 -05:00
parent bc452cfd93
commit d86836ae8d
6 changed files with 28 additions and 26 deletions

View File

@ -19,6 +19,7 @@ namespace IW4MAdmin
public List<Server> Servers { get; private set; } public List<Server> Servers { get; private set; }
List<AsyncStatus> TaskStatuses; List<AsyncStatus> TaskStatuses;
Database ClientDatabase; Database ClientDatabase;
Database AliasesDatabase;
SharedLibrary.Interfaces.IPenaltyList ClientPenalties; SharedLibrary.Interfaces.IPenaltyList ClientPenalties;
List<Command> Commands; List<Command> Commands;
Kayak.IScheduler webServiceTask; Kayak.IScheduler webServiceTask;
@ -33,15 +34,13 @@ namespace IW4MAdmin
private Manager() private Manager()
{ {
//IFile logFile = new IFile("Logs/IW4MAdminManager.log", true);
Logger = new Logger("Logs/IW4MAdmin.log"); Logger = new Logger("Logs/IW4MAdmin.log");
//Logger = new Log(logFile, Log.Level.Production, 0);
Servers = new List<Server>(); Servers = new List<Server>();
Commands = new List<Command>(); Commands = new List<Command>();
TaskStatuses = new List<AsyncStatus>(); TaskStatuses = new List<AsyncStatus>();
ClientDatabase = new ClientsDB("Database/clients.rm"); ClientDatabase = new ClientsDB("Database/clients.rm");
AliasesDatabase = new AliasesDB("Database/aliases.rm");
ClientPenalties = new PenaltyList(); ClientPenalties = new PenaltyList();
} }
@ -149,6 +148,11 @@ namespace IW4MAdmin
return ClientDatabase as ClientsDB; return ClientDatabase as ClientsDB;
} }
public AliasesDB GetAliasesDatabase()
{
return AliasesDatabase as AliasesDB;
}
public SharedLibrary.Interfaces.IPenaltyList GetClientPenalties() public SharedLibrary.Interfaces.IPenaltyList GetClientPenalties()
{ {
return ClientPenalties; return ClientPenalties;

View File

@ -17,17 +17,17 @@ namespace IW4MAdmin
initCommands(); initCommands();
} }
private void getAliases(List<Aliases> returnAliases, Aliases currentAlias) private void GetAliases(List<Aliases> returnAliases, Aliases currentAlias)
{ {
foreach(String IP in currentAlias.IPS) foreach(String IP in currentAlias.IPS)
{ {
List<Aliases> Matching = aliasDB.getPlayer(IP); List<Aliases> Matching = Manager.GetAliasesDatabase().getPlayer(IP);
foreach(Aliases I in Matching) foreach(Aliases I in Matching)
{ {
if (!returnAliases.Contains(I) && returnAliases.Find(x => x.Number == I.Number) == null) if (!returnAliases.Contains(I) && returnAliases.Find(x => x.Number == I.Number) == null)
{ {
returnAliases.Add(I); returnAliases.Add(I);
getAliases(returnAliases, I); GetAliases(returnAliases, I);
} }
} }
} }
@ -40,12 +40,12 @@ namespace IW4MAdmin
if (Origin == null) if (Origin == null)
return allAliases; return allAliases;
Aliases currentIdentityAliases = aliasDB.getPlayer(Origin.databaseID); Aliases currentIdentityAliases = Manager.GetAliasesDatabase().getPlayer(Origin.databaseID);
if (currentIdentityAliases == null) if (currentIdentityAliases == null)
return allAliases; return allAliases;
getAliases(allAliases, currentIdentityAliases); GetAliases(allAliases, currentIdentityAliases);
return allAliases; return allAliases;
} }
@ -62,11 +62,8 @@ namespace IW4MAdmin
} }
Logger.WriteDebug($"Client slot #{P.clientID} now reserved"); Logger.WriteDebug($"Client slot #{P.clientID} now reserved");
#if DEBUG == false
try try
#endif
{ {
Player NewPlayer = Manager.GetClientDatabase().getPlayer(P.npID, P.clientID); Player NewPlayer = Manager.GetClientDatabase().getPlayer(P.npID, P.clientID);
@ -75,7 +72,7 @@ namespace IW4MAdmin
Logger.WriteDebug($"Client slot #{P.clientID} first time connecting"); Logger.WriteDebug($"Client slot #{P.clientID} first time connecting");
Manager.GetClientDatabase().addPlayer(P); Manager.GetClientDatabase().addPlayer(P);
NewPlayer = Manager.GetClientDatabase().getPlayer(P.npID, P.clientID); NewPlayer = Manager.GetClientDatabase().getPlayer(P.npID, P.clientID);
aliasDB.addPlayer(new Aliases(NewPlayer.databaseID, NewPlayer.Name, NewPlayer.IP)); Manager.GetAliasesDatabase().addPlayer(new Aliases(NewPlayer.databaseID, NewPlayer.Name, NewPlayer.IP));
} }
@ -88,12 +85,12 @@ namespace IW4MAdmin
// below this needs to be optimized ~ 425ms runtime // below this needs to be optimized ~ 425ms runtime
NewPlayer.updateName(P.Name.Trim()); NewPlayer.updateName(P.Name.Trim());
NewPlayer.Alias = aliasDB.getPlayer(NewPlayer.databaseID); NewPlayer.Alias = Manager.GetAliasesDatabase().getPlayer(NewPlayer.databaseID);
if (NewPlayer.Alias == null) if (NewPlayer.Alias == null)
{ {
aliasDB.addPlayer(new Aliases(NewPlayer.databaseID, NewPlayer.Name, NewPlayer.IP)); Manager.GetAliasesDatabase().addPlayer(new Aliases(NewPlayer.databaseID, NewPlayer.Name, NewPlayer.IP));
NewPlayer.Alias = aliasDB.getPlayer(NewPlayer.databaseID); NewPlayer.Alias = Manager.GetAliasesDatabase().getPlayer(NewPlayer.databaseID);
} }
if (P.lastEvent == null || P.lastEvent.Owner == null) if (P.lastEvent == null || P.lastEvent.Owner == null)
@ -116,7 +113,7 @@ namespace IW4MAdmin
NewPlayer.updateIP(P.IP); NewPlayer.updateIP(P.IP);
aliasDB.updatePlayer(NewPlayer.Alias); Manager.GetAliasesDatabase().updatePlayer(NewPlayer.Alias);
Manager.GetClientDatabase().updatePlayer(NewPlayer); Manager.GetClientDatabase().updatePlayer(NewPlayer);
await ExecuteEvent(new Event(Event.GType.Connect, "", NewPlayer, null, this)); await ExecuteEvent(new Event(Event.GType.Connect, "", NewPlayer, null, this));
@ -171,13 +168,13 @@ namespace IW4MAdmin
ClientNum++; ClientNum++;
return true; return true;
} }
#if DEBUG == false
catch (Exception E) catch (Exception E)
{ {
Manager.GetLogger().WriteError("Unable to add player " + P.Name + " - " + E.Message); Manager.GetLogger().WriteError($"Unable to add player {P.Name}::{P.npID}");
Manager.GetLogger().WriteDebug(E.StackTrace);
return false; return false;
} }
#endif
} }
//Remove player by CLIENT NUMBER //Remove player by CLIENT NUMBER

Binary file not shown.

View File

@ -406,8 +406,7 @@ namespace SharedLibrary.Commands
return; return;
} }
//var db_players = E.Owner.Manager.GetClientDatabase().findPlayers(E.Data.Trim()); var db_aliases = E.Owner.Manager.GetAliasesDatabase().findPlayers(E.Data);
var db_aliases = E.Owner.aliasDB.findPlayers(E.Data);
if (db_aliases == null) if (db_aliases == null)
{ {
@ -625,7 +624,7 @@ namespace SharedLibrary.Commands
public override async Task ExecuteAsync(Event E) public override async Task ExecuteAsync(Event E)
{ {
E.Target.Alias = E.Owner.aliasDB.getPlayer(E.Target.databaseID); E.Target.Alias = E.Owner.Manager.GetAliasesDatabase().getPlayer(E.Target.databaseID);
if (E.Target.Alias == null) if (E.Target.Alias == null)
{ {

View File

@ -16,5 +16,6 @@ namespace SharedLibrary.Interfaces
List<Command> GetCommands(); List<Command> GetCommands();
IPenaltyList GetClientPenalties(); IPenaltyList GetClientPenalties();
ClientsDB GetClientDatabase(); ClientsDB GetClientDatabase();
AliasesDB GetAliasesDatabase();
} }
} }

View File

@ -21,8 +21,7 @@ namespace SharedLibrary
Port = port; Port = port;
Manager = mgr; Manager = mgr;
Logger = Manager.GetLogger(); Logger = Manager.GetLogger();
ClientNum = 0; ClientNum = 0;
aliasDB = new AliasesDB("Database/aliases.rm");
Players = new List<Player>(new Player[18]); Players = new List<Player>(new Player[18]);
events = new Queue<Event>(); events = new Queue<Event>();
@ -221,6 +220,7 @@ namespace SharedLibrary
/// <param name="Message">Message to be sent to all players</param> /// <param name="Message">Message to be sent to all players</param>
public async Task Broadcast(String Message) public async Task Broadcast(String Message)
{ {
return;
await this.ExecuteCommandAsync($"sayraw {Message}"); await this.ExecuteCommandAsync($"sayraw {Message}");
} }
@ -231,6 +231,7 @@ namespace SharedLibrary
/// <param name="Target">Player to send message to</param> /// <param name="Target">Player to send message to</param>
public async Task Tell(String Message, Player Target) public async Task Tell(String Message, Player Target)
{ {
return;
if (Target.clientID > -1 && Message.Length > 0 && Target.Level != Player.Permission.Console && !Target.lastEvent.Remote) if (Target.clientID > -1 && Message.Length > 0 && Target.Level != Player.Permission.Console && !Target.lastEvent.Remote)
await this.ExecuteCommandAsync($"tellraw {Target.clientID} {Message}^7"); await this.ExecuteCommandAsync($"tellraw {Target.clientID} {Message}^7");
@ -467,7 +468,7 @@ namespace SharedLibrary
// Databases // Databases
//public ClientsDB clientDB; //public ClientsDB clientDB;
public AliasesDB aliasDB; //public AliasesDB aliasDB;
//Remote //Remote
public Queue<String> commandResult = new Queue<string>(); public Queue<String> commandResult = new Queue<string>();