2015-07-03 00:10:01 -04:00
|
|
|
|
using System;
|
2015-03-08 17:20:10 -04:00
|
|
|
|
using System.Collections.Generic;
|
2015-07-03 00:10:01 -04:00
|
|
|
|
using System.Threading;
|
2015-03-08 17:20:10 -04:00
|
|
|
|
using System.IO;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
using System.Linq;
|
2015-08-20 01:06:44 -04:00
|
|
|
|
using SharedLibrary;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
using SharedLibrary.Network;
|
|
|
|
|
using System.Threading.Tasks;
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
|
|
|
|
namespace IW4MAdmin
|
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
public class IW4MServer : Server
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
public IW4MServer(SharedLibrary.Interfaces.IManager mgr, string address, int port, string password) : base(mgr, address, port, password)
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2015-08-20 15:23:13 -04:00
|
|
|
|
commandQueue = new Queue<string>();
|
2017-05-26 18:49:27 -04:00
|
|
|
|
initCommands();
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2015-08-21 21:11:35 -04:00
|
|
|
|
private void getAliases(List<Aliases> returnAliases, Aliases currentAlias)
|
|
|
|
|
{
|
|
|
|
|
foreach(String IP in currentAlias.IPS)
|
|
|
|
|
{
|
|
|
|
|
List<Aliases> Matching = aliasDB.getPlayer(IP);
|
|
|
|
|
foreach(Aliases I in Matching)
|
|
|
|
|
{
|
|
|
|
|
if (!returnAliases.Contains(I) && returnAliases.Find(x => x.Number == I.Number) == null)
|
|
|
|
|
{
|
|
|
|
|
returnAliases.Add(I);
|
|
|
|
|
getAliases(returnAliases, I);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-28 21:07:33 -04:00
|
|
|
|
public override List<Aliases> GetAliases(Player Origin)
|
2015-08-21 21:11:35 -04:00
|
|
|
|
{
|
|
|
|
|
List<Aliases> allAliases = new List<Aliases>();
|
|
|
|
|
|
2015-04-10 00:02:12 -04:00
|
|
|
|
if (Origin == null)
|
2015-08-21 21:11:35 -04:00
|
|
|
|
return allAliases;
|
|
|
|
|
|
|
|
|
|
Aliases currentIdentityAliases = aliasDB.getPlayer(Origin.databaseID);
|
|
|
|
|
|
|
|
|
|
if (currentIdentityAliases == null)
|
|
|
|
|
return allAliases;
|
|
|
|
|
|
|
|
|
|
getAliases(allAliases, currentIdentityAliases);
|
2015-08-23 17:58:48 -04:00
|
|
|
|
return allAliases;
|
2015-04-10 00:02:12 -04:00
|
|
|
|
}
|
2015-04-19 14:14:30 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
override public async Task<bool> AddPlayer(Player P)
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2017-05-28 21:07:33 -04:00
|
|
|
|
if (P.clientID < 0 || P.clientID > (Players.Count-1) || P.Ping < 1 || P.Ping == 999) // invalid index
|
2015-04-10 00:02:12 -04:00
|
|
|
|
return false;
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
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
|
2017-05-28 21:07:33 -04:00
|
|
|
|
{
|
|
|
|
|
// update their ping
|
|
|
|
|
Players[P.clientID].Ping = P.Ping;
|
2015-04-10 00:02:12 -04:00
|
|
|
|
return true;
|
2017-05-28 21:07:33 -04:00
|
|
|
|
}
|
2015-04-10 00:02:12 -04:00
|
|
|
|
|
2017-05-27 19:29:20 -04:00
|
|
|
|
Logger.WriteDebug($"Client slot #{P.clientID} now reserved");
|
2015-04-10 00:02:12 -04:00
|
|
|
|
|
|
|
|
|
|
2015-03-14 12:42:36 -04:00
|
|
|
|
#if DEBUG == false
|
2015-03-08 17:20:10 -04:00
|
|
|
|
try
|
2015-03-14 12:42:36 -04:00
|
|
|
|
#endif
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2017-05-27 18:08:04 -04:00
|
|
|
|
Player NewPlayer = Manager.GetClientDatabase().getPlayer(P.npID, P.clientID);
|
2015-04-10 00:02:12 -04:00
|
|
|
|
|
|
|
|
|
if (NewPlayer == null) // first time connecting
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2017-05-27 19:29:20 -04:00
|
|
|
|
Logger.WriteDebug($"Client slot #{P.clientID} first time connecting");
|
2017-05-27 18:08:04 -04:00
|
|
|
|
Manager.GetClientDatabase().addPlayer(P);
|
|
|
|
|
NewPlayer = Manager.GetClientDatabase().getPlayer(P.npID, P.clientID);
|
2015-08-20 01:06:44 -04:00
|
|
|
|
aliasDB.addPlayer(new Aliases(NewPlayer.databaseID, NewPlayer.Name, NewPlayer.IP));
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2017-05-27 18:08:04 -04:00
|
|
|
|
List<Player> Admins = Manager.GetClientDatabase().getAdmins();
|
2017-05-26 18:49:27 -04:00
|
|
|
|
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)
|
|
|
|
|
await this.ExecuteCommandAsync("clientkick " + P.clientID + " \"Please do not impersonate an admin^7\"");
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-28 21:07:33 -04:00
|
|
|
|
// below this needs to be optimized ~ 425ms runtime
|
2015-08-20 01:06:44 -04:00
|
|
|
|
NewPlayer.updateName(P.Name.Trim());
|
|
|
|
|
NewPlayer.Alias = aliasDB.getPlayer(NewPlayer.databaseID);
|
2015-03-14 12:42:36 -04:00
|
|
|
|
|
2015-04-10 00:02:12 -04:00
|
|
|
|
if (NewPlayer.Alias == null)
|
2015-03-09 21:28:37 -04:00
|
|
|
|
{
|
2015-08-20 01:06:44 -04:00
|
|
|
|
aliasDB.addPlayer(new Aliases(NewPlayer.databaseID, NewPlayer.Name, NewPlayer.IP));
|
|
|
|
|
NewPlayer.Alias = aliasDB.getPlayer(NewPlayer.databaseID);
|
2015-03-09 21:28:37 -04:00
|
|
|
|
}
|
2015-04-10 00:02:12 -04:00
|
|
|
|
|
|
|
|
|
if (P.lastEvent == null || P.lastEvent.Owner == null)
|
2015-03-14 12:42:36 -04:00
|
|
|
|
NewPlayer.lastEvent = new Event(Event.GType.Say, null, NewPlayer, null, this); // this is messy but its throwing an error when they've started it too late
|
|
|
|
|
else
|
|
|
|
|
NewPlayer.lastEvent = P.lastEvent;
|
2015-04-10 00:02:12 -04:00
|
|
|
|
|
|
|
|
|
// lets check aliases
|
2015-08-21 21:11:35 -04:00
|
|
|
|
if ((NewPlayer.Alias.Names.Find(m => m.Equals(P.Name))) == null || NewPlayer.Name == null || NewPlayer.Name == String.Empty)
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2015-08-20 01:06:44 -04:00
|
|
|
|
NewPlayer.updateName(P.Name.Trim());
|
2015-08-21 21:11:35 -04:00
|
|
|
|
NewPlayer.Alias.Names.Add(NewPlayer.Name);
|
2015-04-10 00:02:12 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// and ips
|
2015-08-21 21:11:35 -04:00
|
|
|
|
if (NewPlayer.Alias.IPS.Find(i => i.Equals(P.IP)) == null || P.IP == null || P.IP == String.Empty)
|
2015-04-10 00:02:12 -04:00
|
|
|
|
{
|
2015-08-21 21:11:35 -04:00
|
|
|
|
NewPlayer.Alias.IPS.Add(P.IP);
|
2015-04-10 00:02:12 -04:00
|
|
|
|
}
|
2015-03-16 16:40:30 -04:00
|
|
|
|
|
2015-08-20 01:06:44 -04:00
|
|
|
|
NewPlayer.updateIP(P.IP);
|
2015-04-19 14:14:30 -04:00
|
|
|
|
|
2015-04-10 00:02:12 -04:00
|
|
|
|
aliasDB.updatePlayer(NewPlayer.Alias);
|
2017-05-27 18:08:04 -04:00
|
|
|
|
Manager.GetClientDatabase().updatePlayer(NewPlayer);
|
2015-03-16 16:40:30 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
await ExecuteEvent(new Event(Event.GType.Connect, "", NewPlayer, null, this));
|
2015-07-15 18:10:07 -04:00
|
|
|
|
|
2015-08-20 01:06:44 -04:00
|
|
|
|
if (NewPlayer.Level == Player.Permission.Banned) // their guid is already banned so no need to check aliases
|
2015-04-10 00:02:12 -04:00
|
|
|
|
{
|
2017-05-27 19:29:20 -04:00
|
|
|
|
Logger.WriteInfo($"Banned client {P.Name}::{P.npID} trying to connect...");
|
2017-05-28 21:07:33 -04:00
|
|
|
|
await NewPlayer.Kick(NewPlayer.lastOffense != null ? "^7Previously banned for ^5 " + NewPlayer.lastOffense : "^7Previous Ban", NewPlayer);
|
2015-03-23 23:01:05 -04:00
|
|
|
|
|
2015-04-11 13:31:04 -04:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-03-16 16:40:30 -04:00
|
|
|
|
|
2015-08-21 21:11:35 -04:00
|
|
|
|
List<Player> newPlayerAliases = getPlayerAliases(NewPlayer);
|
2015-03-23 23:01:05 -04:00
|
|
|
|
|
2015-04-11 13:31:04 -04:00
|
|
|
|
foreach (Player aP in newPlayerAliases) // lets check their aliases
|
|
|
|
|
{
|
|
|
|
|
if (aP == null)
|
|
|
|
|
continue;
|
2015-04-10 00:02:12 -04:00
|
|
|
|
|
2015-08-20 01:06:44 -04:00
|
|
|
|
if (aP.Level == Player.Permission.Flagged)
|
2015-04-11 13:31:04 -04:00
|
|
|
|
NewPlayer.setLevel(Player.Permission.Flagged);
|
2015-04-10 00:02:12 -04:00
|
|
|
|
|
2016-01-15 17:15:39 -05:00
|
|
|
|
Penalty B = isBanned(aP);
|
2015-04-10 00:02:12 -04:00
|
|
|
|
|
2016-01-15 17:15:39 -05:00
|
|
|
|
if (B != null && B.BType == Penalty.Type.Ban)
|
2015-04-10 00:02:12 -04:00
|
|
|
|
{
|
2017-05-27 19:29:20 -04:00
|
|
|
|
Logger.WriteDebug($"Banned client {aP.Name}::{aP.npID} is connecting with new alias {NewPlayer.Name}");
|
2015-08-20 01:06:44 -04:00
|
|
|
|
NewPlayer.lastOffense = String.Format("Evading ( {0} )", aP.Name);
|
2015-04-10 00:02:12 -04:00
|
|
|
|
|
2017-05-28 21:07:33 -04:00
|
|
|
|
await NewPlayer.Ban(B.Reason != null ? "^7Previously banned for ^5 " + B.Reason : "^7Previous Ban", NewPlayer);
|
|
|
|
|
Players[NewPlayer.clientID] = null;
|
2015-03-23 23:01:05 -04:00
|
|
|
|
|
|
|
|
|
return true;
|
2015-03-16 16:40:30 -04:00
|
|
|
|
}
|
2015-04-10 00:02:12 -04:00
|
|
|
|
}
|
2017-05-28 21:07:33 -04:00
|
|
|
|
|
|
|
|
|
Players[NewPlayer.clientID] = null;
|
|
|
|
|
Players[NewPlayer.clientID] = NewPlayer;
|
2015-03-23 23:01:05 -04:00
|
|
|
|
#if DEBUG == FALSE
|
2017-05-26 18:49:27 -04:00
|
|
|
|
await NewPlayer.Tell($"Welcome ^5{NewPlayer.Name} ^7this is your ^5{NewPlayer.TimesConnected()} ^7time connecting!");
|
2015-03-23 23:01:05 -04:00
|
|
|
|
#endif
|
2017-05-27 19:29:20 -04:00
|
|
|
|
Logger.WriteInfo($"Client {NewPlayer.Name}::{NewPlayer.npID} connecting..."); // they're clean
|
2015-03-23 23:01:05 -04:00
|
|
|
|
|
2017-05-27 19:29:20 -04:00
|
|
|
|
// todo: get this out of here
|
2017-05-26 18:49:27 -04:00
|
|
|
|
while (chatHistory.Count > Math.Ceiling((double)ClientNum / 2))
|
2015-04-19 14:14:30 -04:00
|
|
|
|
chatHistory.RemoveAt(0);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
chatHistory.Add(new Chat(NewPlayer.Name, "<i>CONNECTED</i>", DateTime.Now));
|
2015-04-10 00:02:12 -04:00
|
|
|
|
|
2015-08-20 01:06:44 -04:00
|
|
|
|
if (NewPlayer.Level > Player.Permission.Moderator)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
await NewPlayer.Tell("There are ^5" + Reports.Count + " ^7recent reports!");
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
ClientNum++;
|
2015-03-08 17:20:10 -04:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-03-14 12:42:36 -04:00
|
|
|
|
#if DEBUG == false
|
2015-03-08 17:20:10 -04:00
|
|
|
|
catch (Exception E)
|
|
|
|
|
{
|
2017-05-28 16:47:21 -04:00
|
|
|
|
Manager.GetLogger().WriteError("Unable to add player " + P.Name + " - " + E.Message);
|
2015-03-08 17:20:10 -04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-03-14 12:42:36 -04:00
|
|
|
|
#endif
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Remove player by CLIENT NUMBER
|
2017-05-26 18:49:27 -04:00
|
|
|
|
override public async Task RemovePlayer(int cNum)
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
if (cNum >= 0 && cNum < Players.Count)
|
2015-03-16 16:40:30 -04:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
Player Leaving = Players[cNum];
|
2015-04-10 00:02:12 -04:00
|
|
|
|
Leaving.Connections++;
|
2017-05-27 18:08:04 -04:00
|
|
|
|
Manager.GetClientDatabase().updatePlayer(Leaving);
|
2015-03-16 16:40:30 -04:00
|
|
|
|
|
2017-05-27 19:29:20 -04:00
|
|
|
|
Logger.WriteInfo($"Client {Leaving.Name}::{Leaving.npID} disconnecting...");
|
2017-05-26 18:49:27 -04:00
|
|
|
|
await ExecuteEvent(new Event(Event.GType.Disconnect, "", Leaving, null, this));
|
2017-05-27 00:22:50 -04:00
|
|
|
|
Players[cNum] = null;
|
2015-03-16 16:40:30 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
ClientNum--;
|
2015-03-16 16:40:30 -04:00
|
|
|
|
}
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-16 16:40:30 -04:00
|
|
|
|
//Another version of client from line, written for the line created by a kill or death event
|
2015-08-20 01:06:44 -04:00
|
|
|
|
override public Player clientFromEventLine(String[] L, int cIDPos)
|
2015-03-16 16:40:30 -04:00
|
|
|
|
{
|
2015-04-10 00:02:12 -04:00
|
|
|
|
if (L.Length < cIDPos)
|
2015-03-16 16:40:30 -04:00
|
|
|
|
{
|
2017-05-27 19:29:20 -04:00
|
|
|
|
Logger.WriteError("Line sent for client creation is not long enough!");
|
2015-03-16 16:40:30 -04:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-30 01:04:10 -04:00
|
|
|
|
int pID = -2; // apparently falling = -1 cID so i can't use it now
|
2015-04-10 00:02:12 -04:00
|
|
|
|
int.TryParse(L[cIDPos].Trim(), out pID);
|
2015-03-16 16:40:30 -04:00
|
|
|
|
|
2015-03-30 01:04:10 -04:00
|
|
|
|
if (pID == -1) // special case similar to mod_suicide
|
|
|
|
|
int.TryParse(L[2], out pID);
|
|
|
|
|
|
2015-04-10 00:02:12 -04:00
|
|
|
|
if (pID < 0 || pID > 17)
|
|
|
|
|
{
|
2017-05-27 19:29:20 -04:00
|
|
|
|
Logger.WriteError("Event player index " + pID + " is out of bounds!");
|
|
|
|
|
Logger.WriteDebug("Offending line -- " + String.Join(";", L));
|
2015-04-10 00:02:12 -04:00
|
|
|
|
return null;
|
2015-03-16 16:40:30 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-04-10 00:02:12 -04:00
|
|
|
|
Player P = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
P = Players[pID];
|
2015-04-10 00:02:12 -04:00
|
|
|
|
return P;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
2017-05-27 19:29:20 -04:00
|
|
|
|
Logger.WriteError("Client index is invalid - " + pID);
|
|
|
|
|
Logger.WriteDebug(L.ToString());
|
2015-04-10 00:02:12 -04:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-16 16:40:30 -04:00
|
|
|
|
//Check ban list for every banned player and return ban if match is found
|
2016-01-15 17:15:39 -05:00
|
|
|
|
override public Penalty isBanned(Player C)
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2017-05-27 18:08:04 -04:00
|
|
|
|
return Manager.GetClientPenalties().FindPenalties(C).Where(b => b.BType == Penalty.Type.Ban).FirstOrDefault();
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-28 00:39:36 -04:00
|
|
|
|
//Process requested command correlating to an event
|
2017-05-26 18:49:27 -04:00
|
|
|
|
// todo: this needs to be removed out of here
|
|
|
|
|
override public async Task<Command> ProcessCommand(Event E, Command C)
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
E.Data = E.Data.RemoveWords(1);
|
2015-08-20 13:52:30 -04:00
|
|
|
|
String[] Args = E.Data.Trim().Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
|
|
|
|
|
if (E.Origin.Level < C.Permission)
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
await E.Origin.Tell("You do not have access to that command!");
|
2015-03-08 17:20:10 -04:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-20 13:52:30 -04:00
|
|
|
|
if (Args.Length < (C.requiredArgNum))
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
await E.Origin.Tell("Not enough arguments supplied!");
|
2015-03-08 17:20:10 -04:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
if (C.needsTarget)
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
|
|
|
|
int cNum = -1;
|
|
|
|
|
int.TryParse(Args[0], out cNum);
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
// this is so ugly wtf is it doing here?
|
2015-08-20 01:06:44 -04:00
|
|
|
|
if (C.Name == "stats" && Args.Length == 1)
|
2015-03-23 23:01:05 -04:00
|
|
|
|
E.Target = E.Origin;
|
|
|
|
|
|
2015-03-09 21:28:37 -04:00
|
|
|
|
if (Args[0] == String.Empty)
|
|
|
|
|
return C;
|
|
|
|
|
|
2015-03-23 23:01:05 -04:00
|
|
|
|
|
2015-03-16 16:40:30 -04:00
|
|
|
|
if (Args[0][0] == '@') // user specifying target by database ID
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
|
|
|
|
int dbID = -1;
|
|
|
|
|
int.TryParse(Args[0].Substring(1, Args[0].Length-1), out dbID);
|
2015-08-20 01:06:44 -04:00
|
|
|
|
|
|
|
|
|
IW4MServer castServer = (IW4MServer)(E.Owner);
|
2017-05-27 18:08:04 -04:00
|
|
|
|
Player found = Manager.GetClientDatabase().getPlayer(dbID);
|
2015-03-08 17:20:10 -04:00
|
|
|
|
if (found != null)
|
2015-03-16 16:40:30 -04:00
|
|
|
|
{
|
2015-03-08 17:20:10 -04:00
|
|
|
|
E.Target = found;
|
2015-03-16 16:40:30 -04:00
|
|
|
|
E.Target.lastEvent = E;
|
|
|
|
|
E.Owner = this;
|
|
|
|
|
}
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-16 16:40:30 -04:00
|
|
|
|
else if(Args[0].Length < 3 && cNum > -1 && cNum < 18) // user specifying target by client num
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
if (Players[cNum] != null)
|
|
|
|
|
E.Target = Players[cNum];
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
2015-04-10 00:02:12 -04:00
|
|
|
|
E.Target = clientFromName(Args[0]);
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
|
|
|
|
if (E.Target == null)
|
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
await E.Origin.Tell("Unable to find specified player.");
|
2015-03-08 17:20:10 -04:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return C;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
public override async Task ExecuteEvent(Event E)
|
2015-07-06 13:13:42 -04:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
await ProcessEvent(E);
|
2015-07-15 17:11:29 -04:00
|
|
|
|
|
2017-05-27 00:22:50 -04:00
|
|
|
|
foreach (SharedLibrary.Interfaces.IPlugin P in PluginImporter.potentialPlugins)
|
2015-08-20 13:52:30 -04:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
try
|
2015-08-20 15:23:13 -04:00
|
|
|
|
{
|
2017-05-27 18:08:04 -04:00
|
|
|
|
await P.OnEventAsync(E, this);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
2015-08-22 02:04:30 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
catch (Exception Except)
|
|
|
|
|
{
|
2017-05-27 19:29:20 -04:00
|
|
|
|
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));
|
2017-05-26 18:49:27 -04:00
|
|
|
|
continue;
|
2015-08-20 15:23:13 -04:00
|
|
|
|
}
|
2015-08-20 13:52:30 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-27 00:22:50 -04:00
|
|
|
|
async Task PollPlayersAsync()
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
var CurrentPlayers = await this.GetStatusAsync();
|
2015-07-06 13:13:42 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
for (int i = 0; i < Players.Count; i++)
|
2017-05-27 00:22:50 -04:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
if (CurrentPlayers.Find(p => p.clientID == i) == null && Players[i] != null)
|
|
|
|
|
await RemovePlayer(i);
|
2017-05-27 00:22:50 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var P in CurrentPlayers)
|
|
|
|
|
await AddPlayer(P);
|
2015-08-20 13:52:30 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
long l_size = -1;
|
|
|
|
|
String[] lines = new String[8];
|
|
|
|
|
String[] oldLines = new String[8];
|
|
|
|
|
DateTime start = DateTime.Now;
|
|
|
|
|
DateTime playerCountStart = DateTime.Now;
|
|
|
|
|
DateTime lastCount = DateTime.Now;
|
|
|
|
|
DateTime tickTime = DateTime.Now;
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
2017-05-28 16:47:21 -04:00
|
|
|
|
override public async Task ProcessUpdatesAsync(CancellationToken cts)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2015-03-14 12:42:36 -04:00
|
|
|
|
#if DEBUG == false
|
|
|
|
|
try
|
|
|
|
|
#endif
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
await PollPlayersAsync();
|
|
|
|
|
|
|
|
|
|
lastMessage = DateTime.Now - start;
|
|
|
|
|
lastCount = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
if ((DateTime.Now - tickTime).TotalMilliseconds >= 1000)
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2017-05-28 16:47:21 -04:00
|
|
|
|
// We don't want to await here, just in case user plugins are really slow :c
|
2017-05-26 18:49:27 -04:00
|
|
|
|
foreach (var Plugin in PluginImporter.potentialPlugins)
|
2017-05-28 16:47:21 -04:00
|
|
|
|
#if !DEBUG
|
|
|
|
|
Plugin.OnTickAsync(this);
|
|
|
|
|
#else
|
|
|
|
|
await Plugin.OnTickAsync(this);
|
|
|
|
|
#endif
|
2015-04-24 15:37:56 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
tickTime = DateTime.Now;
|
|
|
|
|
}
|
2015-04-24 15:37:56 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
if ((lastCount - playerCountStart).TotalMinutes > 4)
|
|
|
|
|
{
|
|
|
|
|
while (playerHistory.Count > 144) // 12 times a minute for 12 hours
|
|
|
|
|
playerHistory.Dequeue();
|
|
|
|
|
playerHistory.Enqueue(new PlayerHistory(lastCount, ClientNum));
|
|
|
|
|
playerCountStart = DateTime.Now;
|
|
|
|
|
}
|
2015-08-20 01:06:44 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
if (lastMessage.TotalSeconds > messageTime && messages.Count > 0 && Players.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
initMacros(); // somethings dynamically change so we have to re-init the dictionary
|
|
|
|
|
await Broadcast(Utilities.LoadMacro(Macros, messages[nextMessage]));
|
|
|
|
|
if (nextMessage == (messages.Count - 1))
|
|
|
|
|
nextMessage = 0;
|
|
|
|
|
else
|
|
|
|
|
nextMessage++;
|
|
|
|
|
start = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//logFile = new IFile();
|
|
|
|
|
if (l_size != logFile.getSize())
|
|
|
|
|
{
|
|
|
|
|
// this should be the longest running task
|
|
|
|
|
await Task.FromResult(lines = logFile.Tail(12));
|
|
|
|
|
if (lines != oldLines)
|
2015-05-09 12:46:25 -04:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
l_size = logFile.getSize();
|
|
|
|
|
int end;
|
|
|
|
|
if (lines.Length == oldLines.Length)
|
|
|
|
|
end = lines.Length - 1;
|
|
|
|
|
else
|
|
|
|
|
end = Math.Abs((lines.Length - oldLines.Length)) - 1;
|
2015-05-09 12:46:25 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
for (int count = 0; count < lines.Length; count++)
|
2015-05-09 12:46:25 -04:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
if (lines.Length < 1 && oldLines.Length < 1)
|
2015-07-03 00:10:01 -04:00
|
|
|
|
continue;
|
2015-05-09 12:46:25 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
if (lines[count] == oldLines[oldLines.Length - 1])
|
|
|
|
|
continue;
|
2015-05-09 12:46:25 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
if (lines[count].Length < 10) // it's not a needed line
|
|
|
|
|
continue;
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
string[] game_event = lines[count].Split(';');
|
|
|
|
|
Event event_ = Event.requestEvent(game_event, this);
|
|
|
|
|
if (event_ != null)
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
if (event_.Origin == null)
|
|
|
|
|
continue;
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
event_.Origin.lastEvent = event_;
|
|
|
|
|
event_.Origin.lastEvent.Owner = this;
|
|
|
|
|
await ExecuteEvent(event_);
|
|
|
|
|
}
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-26 18:49:27 -04:00
|
|
|
|
oldLines = lines;
|
|
|
|
|
l_size = logFile.getSize();
|
|
|
|
|
}
|
2015-03-14 12:42:36 -04:00
|
|
|
|
#if DEBUG == false
|
2015-03-08 17:20:10 -04:00
|
|
|
|
catch (Exception E)
|
|
|
|
|
{
|
2017-05-28 16:47:21 -04:00
|
|
|
|
Logger.WriteError("Unexpected error on \"" + Hostname + "\"");
|
|
|
|
|
Logger.WriteDebug("Error Message: " + E.Message);
|
|
|
|
|
Logger.WriteDebug("Error Trace: " + E.StackTrace);
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
2017-05-26 18:49:27 -04:00
|
|
|
|
#endif
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
2015-04-19 14:14:30 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
public async Task Initialize()
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
var shortversion = await this.GetDvarAsync<string>("shortversion");
|
|
|
|
|
var hostname = await this.GetDvarAsync<string>("sv_hostname");
|
|
|
|
|
var mapname = await this.GetDvarAsync<string>("mapname");
|
|
|
|
|
var maxplayers = await this.GetDvarAsync<int>("party_maxplayers");
|
|
|
|
|
var gametype = await this.GetDvarAsync<string>("g_gametype");
|
|
|
|
|
var basepath = await this.GetDvarAsync<string>("fs_basepath");
|
|
|
|
|
var game = await this.GetDvarAsync<string>("fs_game");
|
|
|
|
|
var logfile = await this.GetDvarAsync<string>("g_log");
|
|
|
|
|
var logsync = await this.GetDvarAsync<int>("g_logsync");
|
|
|
|
|
|
2015-08-22 02:04:30 -04:00
|
|
|
|
try
|
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
var website = await this.GetDvarAsync<string>("_website");
|
|
|
|
|
Website = website.Value;
|
|
|
|
|
}
|
2015-10-10 22:32:12 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
catch (SharedLibrary.Exceptions.DvarException)
|
|
|
|
|
{
|
|
|
|
|
Website = "this server's website";
|
|
|
|
|
}
|
2015-08-23 17:58:48 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
this.Hostname = hostname.Value.StripColors();
|
|
|
|
|
this.CurrentMap = maps.Find(m => m.Name == mapname.Value) ?? new Map(mapname.Value, mapname.Value);
|
|
|
|
|
this.MaxClients = maxplayers.Value;
|
|
|
|
|
this.FSGame = game.Value;
|
2015-08-23 17:58:48 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
await this.SetDvarAsync("sv_kickbantime", 3600);
|
|
|
|
|
await this.SetDvarAsync("sv_network_fps", 1000);
|
|
|
|
|
await this.SetDvarAsync("com_maxfps", 1000);
|
2015-08-22 02:04:30 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
if (logsync.Value != 1 || logfile.Value == string.Empty)
|
|
|
|
|
{
|
|
|
|
|
// this DVAR isn't set until the a map is loaded
|
|
|
|
|
await this.SetDvarAsync("g_logsync", 1);
|
|
|
|
|
await this.SetDvarAsync("g_log", "logs/games_mp.log");
|
|
|
|
|
await this.ExecuteCommandAsync("map_restart");
|
|
|
|
|
logfile = await this.GetDvarAsync<string>("g_log");
|
|
|
|
|
}
|
|
|
|
|
#if DEBUG
|
|
|
|
|
basepath.Value = @"\\tsclient\K\MW2";
|
|
|
|
|
#endif
|
|
|
|
|
string logPath = string.Empty;
|
2015-08-22 02:04:30 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
if (game.Value == "")
|
|
|
|
|
logPath = $"{basepath.Value.Replace("\\", "/")}/userraw/{logfile.Value}";
|
|
|
|
|
else
|
|
|
|
|
logPath = $"{basepath.Value.Replace("\\", "/")}/{game.Value}/{logfile.Value}";
|
2015-08-22 02:04:30 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
if (!File.Exists(logPath))
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2017-05-27 19:29:20 -04:00
|
|
|
|
Logger.WriteError($"Gamelog {logPath} does not exist!");
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
logFile = new IFile(logPath);
|
2017-05-27 19:29:20 -04:00
|
|
|
|
Logger.WriteInfo("Log file is " + logPath);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
await ExecuteEvent(new Event(Event.GType.Start, "Server started", null, null, this));
|
|
|
|
|
#if !DEBUG
|
|
|
|
|
Broadcast("IW4M Admin is now ^2ONLINE");
|
2015-10-10 19:31:24 -04:00
|
|
|
|
#endif
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
2015-07-06 13:13:42 -04:00
|
|
|
|
|
2015-03-08 17:20:10 -04:00
|
|
|
|
//Process any server event
|
2017-05-26 18:49:27 -04:00
|
|
|
|
override protected async Task ProcessEvent(Event E)
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2015-04-11 13:31:04 -04:00
|
|
|
|
if (E.Type == Event.GType.Connect)
|
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return;
|
2015-04-11 13:31:04 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-16 16:40:30 -04:00
|
|
|
|
if (E.Type == Event.GType.Disconnect)
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2015-03-16 16:40:30 -04:00
|
|
|
|
if (E.Origin == null)
|
2015-03-09 21:28:37 -04:00
|
|
|
|
{
|
2017-05-27 19:29:20 -04:00
|
|
|
|
Logger.WriteError("Disconnect event triggered, but no origin found.");
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return;
|
2015-03-09 21:28:37 -04:00
|
|
|
|
}
|
2015-03-16 16:40:30 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
while (chatHistory.Count > Math.Ceiling(((double)ClientNum - 1) / 2))
|
2015-04-19 14:14:30 -04:00
|
|
|
|
chatHistory.RemoveAt(0);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
chatHistory.Add(new Chat(E.Origin.Name, "<i>DISCONNECTED</i>", DateTime.Now));
|
2015-04-19 14:14:30 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
//removePlayer(E.Origin.clientID);
|
|
|
|
|
return;
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-09 21:28:37 -04:00
|
|
|
|
if (E.Type == Event.GType.Kill)
|
|
|
|
|
{
|
2015-03-16 16:40:30 -04:00
|
|
|
|
if (E.Origin == null)
|
|
|
|
|
{
|
2017-05-27 19:29:20 -04:00
|
|
|
|
Logger.WriteError("Kill event triggered, but no origin found!");
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return;
|
2015-03-16 16:40:30 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-23 23:01:05 -04:00
|
|
|
|
if (E.Origin != E.Target)
|
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
await ExecuteEvent(new Event(Event.GType.Death, E.Data, E.Target, null, this));
|
2015-03-23 23:01:05 -04:00
|
|
|
|
}
|
2015-03-16 16:40:30 -04:00
|
|
|
|
|
2015-04-11 13:31:04 -04:00
|
|
|
|
else // suicide/falling
|
2015-03-23 23:01:05 -04:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
//Log.Write(E.Origin.Name + " suicided...", Log.Level.Debug);
|
|
|
|
|
await ExecuteEvent(new Event(Event.GType.Death, "suicide", E.Target, null, this));
|
2015-03-23 23:01:05 -04:00
|
|
|
|
}
|
2015-03-09 21:28:37 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-16 16:40:30 -04:00
|
|
|
|
if (E.Type == Event.GType.Say)
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2015-03-16 16:40:30 -04:00
|
|
|
|
if (E.Data.Length < 2) // ITS A LIE!
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return;
|
2015-03-16 16:40:30 -04:00
|
|
|
|
|
|
|
|
|
if (E.Origin == null)
|
|
|
|
|
{
|
2017-05-27 19:29:20 -04:00
|
|
|
|
Logger.WriteError("Say event triggered, but no origin found! - " + E.Data);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return;
|
2015-03-16 16:40:30 -04:00
|
|
|
|
}
|
2015-03-09 21:28:37 -04:00
|
|
|
|
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
2015-03-16 16:40:30 -04:00
|
|
|
|
if (E.Owner == null)
|
|
|
|
|
{
|
2017-05-27 19:29:20 -04:00
|
|
|
|
Logger.WriteError("Say event does not have an owner!");
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return;
|
2015-03-16 16:40:30 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-22 02:04:30 -04:00
|
|
|
|
if (E.Data.Substring(0, 1) == "!" || E.Origin.Level == Player.Permission.Console)
|
2015-04-19 14:14:30 -04:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
Command C = E.isValidCMD(Manager.GetCommands());
|
2015-04-19 14:14:30 -04:00
|
|
|
|
|
2015-08-22 02:04:30 -04:00
|
|
|
|
if (C != null)
|
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
C = await ProcessCommand(E, C);
|
2015-08-22 02:04:30 -04:00
|
|
|
|
if (C != null)
|
|
|
|
|
{
|
|
|
|
|
if (C.needsTarget && E.Target == null)
|
|
|
|
|
{
|
2017-05-27 19:29:20 -04:00
|
|
|
|
Logger.WriteError("Requested event requiring target does not have a target!");
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return;
|
2015-08-22 02:04:30 -04:00
|
|
|
|
}
|
2015-04-19 14:14:30 -04:00
|
|
|
|
|
2015-08-22 02:04:30 -04:00
|
|
|
|
try
|
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
await C.ExecuteAsync(E);
|
2015-08-22 02:04:30 -04:00
|
|
|
|
}
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
2015-08-22 02:04:30 -04:00
|
|
|
|
catch (Exception Except)
|
|
|
|
|
{
|
2017-05-27 19:29:20 -04:00
|
|
|
|
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));
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return;
|
2015-08-22 02:04:30 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
2015-04-10 00:02:12 -04:00
|
|
|
|
|
2015-03-08 17:20:10 -04:00
|
|
|
|
else
|
2017-05-26 18:49:27 -04:00
|
|
|
|
await E.Origin.Tell("You entered an invalid command!");
|
|
|
|
|
return;
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
else // Not a command
|
2015-08-22 02:04:30 -04:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
E.Data = E.Data.StripColors().CleanChars();
|
2015-08-22 02:04:30 -04:00
|
|
|
|
if (E.Data.Length > 50)
|
|
|
|
|
E.Data = E.Data.Substring(0, 50) + "...";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
while (chatHistory.Count > Math.Ceiling((double)ClientNum / 2))
|
2015-08-22 02:04:30 -04:00
|
|
|
|
chatHistory.RemoveAt(0);
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
chatHistory.Add(new Chat(E.Origin.Name, E.Data, DateTime.Now));
|
2015-08-22 02:04:30 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return;
|
2015-08-22 02:04:30 -04:00
|
|
|
|
}
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (E.Type == Event.GType.MapChange)
|
|
|
|
|
{
|
2017-05-27 19:29:20 -04:00
|
|
|
|
Logger.WriteInfo($"New map loaded - {ClientNum} active players");
|
2015-04-27 23:29:43 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
// make async
|
|
|
|
|
Gametype = (await this.GetDvarAsync<string>("g_gametype")).Value.StripColors();
|
|
|
|
|
Hostname = (await this.GetDvarAsync<string>("sv_hostname")).Value.StripColors();
|
|
|
|
|
FSGame = (await this.GetDvarAsync<string>("fs_game")).Value.StripColors();
|
2015-04-27 23:29:43 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
string mapname = this.GetDvarAsync<string>("mapname").Result.Value;
|
|
|
|
|
CurrentMap = maps.Find(m => m.Name == mapname) ?? new Map(mapname, mapname);
|
2015-08-23 17:58:48 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return;
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (E.Type == Event.GType.MapEnd)
|
|
|
|
|
{
|
2017-05-27 19:29:20 -04:00
|
|
|
|
Logger.WriteInfo("Game ending...");
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return;
|
|
|
|
|
};
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
public override async Task Warn(String Reason, Player Target, Player Origin)
|
2016-01-16 17:58:24 -05:00
|
|
|
|
{
|
|
|
|
|
if (Target.Warnings >= 4)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
await Target.Kick("Too many warnings!", Origin);
|
2016-01-21 12:41:00 -05:00
|
|
|
|
else
|
|
|
|
|
{
|
2017-05-27 18:08:04 -04:00
|
|
|
|
Penalty newPenalty = new Penalty(Penalty.Type.Warning, Reason.StripColors(), Target.npID, Origin.npID, DateTime.Now, Target.IP);
|
|
|
|
|
Manager.GetClientPenalties().AddPenalty(newPenalty);
|
2016-01-21 12:41:00 -05:00
|
|
|
|
Target.Warnings++;
|
|
|
|
|
String Message = String.Format("^1WARNING ^7[^3{0}^7]: ^3{1}^7, {2}", Target.Warnings, Target.Name, Target.lastOffense);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
await Broadcast(Message);
|
2016-01-21 12:41:00 -05:00
|
|
|
|
}
|
2016-01-16 17:58:24 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
public override async Task Kick(String Reason, Player Target, Player Origin)
|
2016-01-15 17:15:39 -05:00
|
|
|
|
{
|
|
|
|
|
if (Target.clientID > -1)
|
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
String Message = "^1Player Kicked: ^5" + Reason;
|
2017-05-27 18:08:04 -04:00
|
|
|
|
Penalty newPenalty = new Penalty(Penalty.Type.Kick, Reason.StripColors().Trim(), Target.npID, Origin.npID, DateTime.Now, Target.IP);
|
|
|
|
|
Manager.GetClientPenalties().AddPenalty(newPenalty);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
await this.ExecuteCommandAsync("clientkick " + Target.clientID + " \"" + Message + "^7\"");
|
2016-01-15 17:15:39 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
public override async Task TempBan(String Reason, Player Target, Player Origin)
|
2016-01-15 17:15:39 -05:00
|
|
|
|
{
|
|
|
|
|
if (Target.clientID > -1)
|
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
await this.ExecuteCommandAsync($"tempbanclient {Target.clientID } \"^1Player Temporarily Banned: ^5{ Reason } (1 hour)\"");
|
2017-05-28 21:07:33 -04:00
|
|
|
|
Penalty newPenalty = new Penalty(Penalty.Type.TempBan, Reason.StripColors(), Target.npID, Origin.npID, DateTime.Now, Target.IP);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
await Task.Run(() =>
|
|
|
|
|
{
|
2017-05-27 18:08:04 -04:00
|
|
|
|
Manager.GetClientPenalties().AddPenalty(newPenalty);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
});
|
2016-01-15 17:15:39 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2017-05-28 21:07:33 -04:00
|
|
|
|
private String GetWebsiteString()
|
2015-03-13 19:40:16 -04:00
|
|
|
|
{
|
2017-05-28 21:07:33 -04:00
|
|
|
|
return Website != null ? $" (appeal at {Website}" : " (appeal at this server's website)";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override public async Task Ban(String Message, Player Target, Player Origin)
|
|
|
|
|
{
|
|
|
|
|
if (Target == null)
|
|
|
|
|
{
|
2017-05-27 19:29:20 -04:00
|
|
|
|
Logger.WriteError("Ban target is null");
|
|
|
|
|
Logger.WriteDebug($"Message: {Message}");
|
|
|
|
|
Logger.WriteDebug($"Origin: {Origin.Name}::{Origin.npID}");
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// banned from all servers if active
|
|
|
|
|
foreach (var server in Manager.GetServers())
|
|
|
|
|
{
|
|
|
|
|
if (server.getPlayers().Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var activeClient = server.getPlayers().Find(x => x.npID == Target.npID);
|
|
|
|
|
if (activeClient != null)
|
2017-05-28 21:07:33 -04:00
|
|
|
|
await server.ExecuteCommandAsync("tempbanclient " + activeClient.clientID + " \"" + Message + "^7" + GetWebsiteString() + "^7\"");
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-04-10 00:02:12 -04:00
|
|
|
|
|
2015-03-08 17:20:10 -04:00
|
|
|
|
if (Origin != null)
|
|
|
|
|
{
|
|
|
|
|
Target.setLevel(Player.Permission.Banned);
|
2017-05-27 19:29:20 -04:00
|
|
|
|
Penalty newBan = new Penalty(Penalty.Type.Ban, Target.lastOffense, Target.npID, Origin.npID, DateTime.Now, Target.IP);
|
2015-07-17 18:53:51 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
await Task.Run(() =>
|
|
|
|
|
{
|
2017-05-27 18:08:04 -04:00
|
|
|
|
Manager.GetClientPenalties().AddPenalty(newBan);
|
|
|
|
|
Manager.GetClientDatabase().updatePlayer(Target);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
});
|
2015-07-17 18:53:51 -04:00
|
|
|
|
|
2015-04-10 00:02:12 -04:00
|
|
|
|
lock (Reports) // threading seems to do something weird here
|
|
|
|
|
{
|
|
|
|
|
List<Report> toRemove = new List<Report>();
|
|
|
|
|
foreach (Report R in Reports)
|
|
|
|
|
{
|
2015-08-20 01:06:44 -04:00
|
|
|
|
if (R.Target.npID == Target.npID)
|
2015-04-10 00:02:12 -04:00
|
|
|
|
toRemove.Add(R);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (Report R in toRemove)
|
|
|
|
|
{
|
|
|
|
|
Reports.Remove(R);
|
2017-05-27 19:29:20 -04:00
|
|
|
|
Logger.WriteInfo("Removing report for banned GUID - " + R.Origin.npID);
|
2015-04-10 00:02:12 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-27 18:08:04 -04:00
|
|
|
|
override public async Task Unban(Player Target)
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2017-05-27 18:08:04 -04:00
|
|
|
|
// database stuff can be time consuming
|
|
|
|
|
await Task.Run(() =>
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2017-05-27 18:08:04 -04:00
|
|
|
|
var FoundPenalaties = Manager.GetClientPenalties().FindPenalties(Target);
|
|
|
|
|
var PenaltyToRemove = FoundPenalaties.Find(b => b.BType == Penalty.Type.Ban);
|
2015-07-06 13:13:42 -04:00
|
|
|
|
|
2017-05-27 18:08:04 -04:00
|
|
|
|
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);
|
|
|
|
|
});
|
2015-08-20 17:54:38 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool Reload()
|
|
|
|
|
{
|
2015-03-08 17:20:10 -04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
public override bool _Reload()
|
2015-08-20 17:54:38 -04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
messages = null;
|
|
|
|
|
maps = null;
|
|
|
|
|
rules = null;
|
|
|
|
|
initMaps();
|
|
|
|
|
initMessages();
|
|
|
|
|
initRules();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception E)
|
|
|
|
|
{
|
2017-05-27 19:29:20 -04:00
|
|
|
|
Logger.WriteError("Unable to reload configs! - " + E.Message);
|
2015-08-20 17:54:38 -04:00
|
|
|
|
messages = new List<String>();
|
|
|
|
|
maps = new List<Map>();
|
|
|
|
|
rules = new List<String>();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
2015-08-20 01:06:44 -04:00
|
|
|
|
override public void initMacros()
|
2015-03-13 19:40:16 -04:00
|
|
|
|
{
|
|
|
|
|
Macros = new Dictionary<String, Object>();
|
2017-05-27 18:08:04 -04:00
|
|
|
|
Macros.Add("TOTALPLAYERS", Manager.GetClientDatabase().totalPlayers());
|
2015-03-23 23:01:05 -04:00
|
|
|
|
Macros.Add("TOTALKILLS", totalKills);
|
2015-08-20 01:06:44 -04:00
|
|
|
|
Macros.Add("VERSION", IW4MAdmin.Program.Version);
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-20 01:06:44 -04:00
|
|
|
|
override public void initCommands()
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
foreach (Command C in PluginImporter.potentialCommands)
|
|
|
|
|
Manager.GetCommands().Add(C);
|
2015-08-23 17:58:48 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
Manager.GetCommands().Add(new Plugins("plugins", "view all loaded plugins. syntax: !plugins", "p", Player.Permission.Administrator, 0, false));
|
|
|
|
|
|
|
|
|
|
}
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
public bool commandQueueEmpty()
|
|
|
|
|
{
|
|
|
|
|
return commandQueue.Count == 0;
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Objects
|
2015-08-20 01:06:44 -04:00
|
|
|
|
private Queue<String> commandQueue;
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
}
|