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;
|
2017-06-19 13:58:01 -04:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2015-08-20 01:06:44 -04:00
|
|
|
|
using SharedLibrary;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
using SharedLibrary.Network;
|
2017-06-19 13:58:01 -04:00
|
|
|
|
using SharedLibrary.Interfaces;
|
2017-11-25 20:29:58 -05:00
|
|
|
|
using SharedLibrary.Objects;
|
|
|
|
|
using System.Text.RegularExpressions;
|
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
|
|
|
|
{
|
2018-02-10 01:26:38 -05:00
|
|
|
|
private CancellationToken cts;
|
|
|
|
|
|
2017-06-19 13:58:01 -04:00
|
|
|
|
public IW4MServer(IManager mgr, ServerConfiguration cfg) : base(mgr, cfg) { }
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2018-02-07 00:19:06 -05:00
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
2018-02-10 01:26:38 -05:00
|
|
|
|
return Math.Abs($"{IP}:{Port.ToString()}".GetHashCode());
|
2018-02-07 00:19:06 -05:00
|
|
|
|
}
|
2018-02-14 14:01:26 -05:00
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
override public async Task<bool> AddPlayer(Player polledPlayer)
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2018-02-07 00:19:06 -05:00
|
|
|
|
if (polledPlayer.Ping == 999 || polledPlayer.Ping < 1 || polledPlayer.ClientNumber > (MaxClients) || polledPlayer.ClientNumber < 0)
|
|
|
|
|
{
|
|
|
|
|
//Logger.WriteDebug($"Skipping client not in connected state {P}");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
if (Players[polledPlayer.ClientNumber] != null &&
|
|
|
|
|
Players[polledPlayer.ClientNumber].NetworkId == polledPlayer.NetworkId)
|
2017-05-28 21:07:33 -04:00
|
|
|
|
{
|
2018-02-10 01:26:38 -05:00
|
|
|
|
// update their ping & score
|
2017-11-25 20:29:58 -05:00
|
|
|
|
Players[polledPlayer.ClientNumber].Ping = polledPlayer.Ping;
|
2018-02-09 02:21:25 -05:00
|
|
|
|
Players[polledPlayer.ClientNumber].Score = polledPlayer.Score;
|
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-11-25 20:29:58 -05:00
|
|
|
|
if (polledPlayer.Name.Length < 3)
|
2017-11-13 16:58:23 -05:00
|
|
|
|
{
|
2017-11-25 20:29:58 -05:00
|
|
|
|
await this.ExecuteCommandAsync($"clientkick {polledPlayer.ClientNumber} \"Your name must contain atleast 3 characters.\"");
|
2017-11-13 16:58:23 -05:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
Logger.WriteDebug($"Client slot #{polledPlayer.ClientNumber} now reserved");
|
2017-08-23 18:29:48 -04:00
|
|
|
|
|
2015-03-08 17:20:10 -04:00
|
|
|
|
try
|
|
|
|
|
{
|
2017-11-25 20:29:58 -05:00
|
|
|
|
Player player = null;
|
2017-11-29 19:35:50 -05:00
|
|
|
|
var client = await Manager.GetClientService().GetUnique(polledPlayer.NetworkId);
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
// first time client is connecting to server
|
|
|
|
|
if (client == null)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-11-25 20:29:58 -05:00
|
|
|
|
Logger.WriteDebug($"Client {polledPlayer} first time connecting");
|
|
|
|
|
player = (await Manager.GetClientService().Create(polledPlayer)).AsPlayer();
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
// client has connected in the past
|
2015-03-14 12:42:36 -04:00
|
|
|
|
else
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2017-11-25 20:29:58 -05:00
|
|
|
|
client.Connections += 1;
|
|
|
|
|
bool aliasExists = client.AliasLink.Children
|
2017-11-29 19:35:50 -05:00
|
|
|
|
.FirstOrDefault(a => a.Name == polledPlayer.Name && a.IPAddress == polledPlayer.IPAddress) != null;
|
2017-08-23 18:29:48 -04:00
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
if (!aliasExists)
|
|
|
|
|
{
|
|
|
|
|
Logger.WriteDebug($"Client {polledPlayer} has connected previously under a different alias");
|
2017-11-29 19:35:50 -05:00
|
|
|
|
client.CurrentAlias = new SharedLibrary.Database.Models.EFAlias()
|
2017-11-25 20:29:58 -05:00
|
|
|
|
{
|
2017-11-29 19:35:50 -05:00
|
|
|
|
IPAddress = polledPlayer.IPAddress,
|
2017-11-25 20:29:58 -05:00
|
|
|
|
Name = polledPlayer.Name,
|
2017-11-29 19:35:50 -05:00
|
|
|
|
};
|
|
|
|
|
await Manager.GetClientService().Update(client);
|
2017-11-25 20:29:58 -05:00
|
|
|
|
}
|
|
|
|
|
player = client.AsPlayer();
|
|
|
|
|
}
|
2015-04-19 14:14:30 -04:00
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
/*var Admins = Manager.GetDatabase().GetPrivilegedClients();
|
|
|
|
|
if (Admins.Where(x => x.Name == polledPlayer.Name).Count() > 0)
|
2015-04-10 00:02:12 -04:00
|
|
|
|
{
|
2017-11-25 20:29:58 -05:00
|
|
|
|
if ((Admins.First(x => x.Name == polledPlayer.Name).NetworkId != polledPlayer.NetworkId) && NewPlayer.Level < Player.Permission.Moderator)
|
|
|
|
|
await this.ExecuteCommandAsync("clientkick " + polledPlayer.ClientNumber + " \"Please do not impersonate an admin^7\"");
|
|
|
|
|
}*/
|
|
|
|
|
player.CurrentServer = this;
|
2017-11-29 19:35:50 -05:00
|
|
|
|
#if DEBUG
|
|
|
|
|
player.ClientNumber = polledPlayer.ClientNumber;
|
|
|
|
|
Players[player.ClientNumber] = player;
|
|
|
|
|
#endif
|
2015-03-23 23:01:05 -04:00
|
|
|
|
|
2018-02-07 00:19:06 -05:00
|
|
|
|
var ban = Manager.GetPenaltyService().Find(p => p.LinkId == player.AliasLink.AliasLinkId
|
|
|
|
|
&& p.Expires > DateTime.UtcNow).Result.FirstOrDefault();
|
2015-03-23 23:01:05 -04:00
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
if (ban != null)
|
2015-04-11 13:31:04 -04:00
|
|
|
|
{
|
2017-11-25 20:29:58 -05:00
|
|
|
|
Logger.WriteInfo($"Banned client {player} trying to connect...");
|
|
|
|
|
var autoKickClient = (await Manager.GetClientService().Get(1)).AsPlayer();
|
|
|
|
|
autoKickClient.CurrentServer = this;
|
2015-04-10 00:02:12 -04:00
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
if (ban.Type == Penalty.PenaltyType.TempBan)
|
2017-11-29 19:35:50 -05:00
|
|
|
|
await this.ExecuteCommandAsync($"clientkick {player.ClientNumber} \"You are temporarily banned. ({(ban.Expires - DateTime.UtcNow).TimeSpanText()} left)\"");
|
2017-11-25 20:29:58 -05:00
|
|
|
|
else
|
2017-11-29 19:35:50 -05:00
|
|
|
|
await player.Kick($"Previously banned for {ban.Offense}", autoKickClient);
|
2015-03-23 23:01:05 -04:00
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
if (player.Level != Player.Permission.Banned && ban.Type == Penalty.PenaltyType.Ban)
|
2017-11-29 19:35:50 -05:00
|
|
|
|
await player.Ban($"Previously banned for {ban.Offense}", autoKickClient);
|
2017-11-25 20:29:58 -05:00
|
|
|
|
return true;
|
2015-04-10 00:02:12 -04:00
|
|
|
|
}
|
2017-08-23 18:29:48 -04:00
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
// if (aP.Level == Player.Permission.Flagged)
|
|
|
|
|
// NewPlayer.Level = Player.Permission.Flagged;
|
|
|
|
|
// Do the player specific stuff
|
|
|
|
|
player.ClientNumber = polledPlayer.ClientNumber;
|
2018-02-09 02:21:25 -05:00
|
|
|
|
player.Score = polledPlayer.Score;
|
2017-11-25 20:29:58 -05:00
|
|
|
|
Players[player.ClientNumber] = player;
|
2018-02-07 00:19:06 -05:00
|
|
|
|
Logger.WriteInfo($"Client {player} connecting...");
|
2017-11-25 20:29:58 -05:00
|
|
|
|
|
2018-02-10 01:26:38 -05:00
|
|
|
|
// give trusted rank
|
|
|
|
|
if (Config.AllowTrustedRank &&
|
|
|
|
|
player.TotalConnectionTime / 60.0 >= 2880 &&
|
|
|
|
|
player.Level < Player.Permission.Trusted &&
|
|
|
|
|
player.Level != Player.Permission.Flagged)
|
|
|
|
|
{
|
|
|
|
|
player.Level = Player.Permission.Trusted;
|
|
|
|
|
await player.Tell("Congratulations, you are now a ^5trusted ^7player! Type ^5!help ^7to view new commands.");
|
|
|
|
|
await player.Tell("You earned this by playing for ^53 ^7full days!");
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
await ExecuteEvent(new Event(Event.GType.Connect, "", player, null, this));
|
2015-04-10 00:02:12 -04:00
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
// if (NewPlayer.Level > Player.Permission.Moderator)
|
|
|
|
|
// await NewPlayer.Tell("There are ^5" + Reports.Count + " ^7recent reports!");
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-05-28 21:54:46 -04:00
|
|
|
|
|
2015-03-08 17:20:10 -04:00
|
|
|
|
catch (Exception E)
|
|
|
|
|
{
|
2017-11-25 20:29:58 -05:00
|
|
|
|
Manager.GetLogger().WriteError($"Unable to add player {polledPlayer.Name}::{polledPlayer.NetworkId}");
|
2017-05-28 21:54:46 -04:00
|
|
|
|
Manager.GetLogger().WriteDebug(E.StackTrace);
|
2015-03-08 17:20:10 -04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//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-11-29 19:35:50 -05:00
|
|
|
|
if (cNum >= 0 && Players[cNum] != null)
|
2015-03-16 16:40:30 -04:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
Player Leaving = Players[cNum];
|
2017-11-25 20:29:58 -05:00
|
|
|
|
Leaving.TotalConnectionTime += (int)(DateTime.UtcNow - Leaving.ConnectionTime).TotalSeconds;
|
|
|
|
|
await Manager.GetClientService().Update(Leaving);
|
2015-03-16 16:40:30 -04:00
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
Logger.WriteInfo($"Client {Leaving} 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
|
|
|
|
}
|
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
|
2017-06-07 17:08:29 -04:00
|
|
|
|
override public Player ParseClientFromString(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
|
|
|
|
}
|
|
|
|
|
|
2017-06-19 13:58:01 -04:00
|
|
|
|
return Players[pID];
|
2015-04-10 00:02:12 -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
|
2017-05-30 17:23:31 -04:00
|
|
|
|
override public async Task<Command> ValidateCommand(Event E)
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2017-05-30 17:23:31 -04:00
|
|
|
|
string CommandString = E.Data.Substring(1, E.Data.Length - 1).Split(' ')[0];
|
2017-05-31 01:31:56 -04:00
|
|
|
|
E.Message = E.Data;
|
2017-05-30 17:23:31 -04:00
|
|
|
|
|
|
|
|
|
Command C = null;
|
|
|
|
|
foreach (Command cmd in Manager.GetCommands())
|
|
|
|
|
{
|
|
|
|
|
if (cmd.Name == CommandString.ToLower() || cmd.Alias == CommandString.ToLower())
|
|
|
|
|
C = cmd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (C == null)
|
|
|
|
|
{
|
|
|
|
|
await E.Origin.Tell("You entered an unknown command");
|
|
|
|
|
throw new SharedLibrary.Exceptions.CommandException($"{E.Origin} entered unknown command \"{CommandString}\"");
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
E.Data = E.Data.RemoveWords(1);
|
2017-08-23 18:29:48 -04:00
|
|
|
|
String[] Args = E.Data.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
2015-08-20 13:52:30 -04:00
|
|
|
|
|
|
|
|
|
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!");
|
2017-05-30 17:23:31 -04:00
|
|
|
|
throw new SharedLibrary.Exceptions.CommandException($"{E.Origin} does not have access to \"{C.Name}\"");
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-07 17:08:29 -04:00
|
|
|
|
if (Args.Length < (C.RequiredArgumentCount))
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2017-11-15 16:04:13 -05:00
|
|
|
|
await E.Origin.Tell($"Not enough arguments supplied!");
|
|
|
|
|
await E.Origin.Tell(C.Syntax);
|
2017-05-30 17:23:31 -04:00
|
|
|
|
throw new SharedLibrary.Exceptions.CommandException($"{E.Origin} did not supply enough arguments for \"{C.Name}\"");
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-23 18:29:48 -04:00
|
|
|
|
if (C.RequiresTarget || Args.Length > 0)
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
|
|
|
|
int cNum = -1;
|
2018-02-09 02:21:25 -05:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
cNum = Convert.ToInt32(Args[0]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch(FormatException)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2015-03-08 17:20:10 -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;
|
2017-08-23 18:29:48 -04:00
|
|
|
|
int.TryParse(Args[0].Substring(1, Args[0].Length - 1), out dbID);
|
2015-08-20 01:06:44 -04:00
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
var found = await Manager.GetClientService().Get(dbID);
|
2015-03-08 17:20:10 -04:00
|
|
|
|
if (found != null)
|
2015-03-16 16:40:30 -04:00
|
|
|
|
{
|
2017-11-25 20:29:58 -05:00
|
|
|
|
E.Target = found.AsPlayer();
|
|
|
|
|
E.Target.CurrentServer = this as IW4MServer;
|
2017-05-30 17:23:31 -04:00
|
|
|
|
E.Owner = this as IW4MServer;
|
2017-11-29 19:35:50 -05:00
|
|
|
|
E.Data = String.Join(" ", Args.Skip(1));
|
2015-03-16 16:40:30 -04:00
|
|
|
|
}
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-09 02:21:25 -05:00
|
|
|
|
else if (Args[0].Length < 3 && cNum > -1 && cNum < MaxClients) // 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)
|
2017-11-25 20:29:58 -05:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
E.Target = Players[cNum];
|
2017-11-25 20:29:58 -05:00
|
|
|
|
E.Data = String.Join(" ", Args.Skip(1));
|
|
|
|
|
}
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-16 18:09:19 -05:00
|
|
|
|
List<Player> matchingPlayers;
|
|
|
|
|
|
2017-06-19 13:58:01 -04:00
|
|
|
|
if (E.Target == null) // Find active player including quotes (multiple words)
|
2017-11-16 18:09:19 -05:00
|
|
|
|
{
|
|
|
|
|
matchingPlayers = GetClientByName(E.Data.Trim());
|
|
|
|
|
if (matchingPlayers.Count > 1)
|
|
|
|
|
{
|
|
|
|
|
await E.Origin.Tell("Multiple players match that name");
|
2018-02-07 00:19:06 -05:00
|
|
|
|
throw new SharedLibrary.Exceptions.CommandException($"{E.Origin} had multiple players found for {C.Name}");
|
2017-11-16 18:09:19 -05:00
|
|
|
|
}
|
|
|
|
|
else if (matchingPlayers.Count == 1)
|
2017-11-25 20:29:58 -05:00
|
|
|
|
{
|
2017-11-16 18:09:19 -05:00
|
|
|
|
E.Target = matchingPlayers.First();
|
2017-11-29 19:35:50 -05:00
|
|
|
|
E.Data = Regex.Replace(E.Data, $"\"{E.Target.Name}\"", "", RegexOptions.IgnoreCase).Trim();
|
2018-02-09 02:21:25 -05:00
|
|
|
|
|
2018-02-10 01:26:38 -05:00
|
|
|
|
if ((E.Data.ToLower().Trim() == E.Target.Name.ToLower().Trim() ||
|
|
|
|
|
E.Data == String.Empty) &&
|
|
|
|
|
C.RequiresTarget)
|
2018-02-09 02:21:25 -05:00
|
|
|
|
{
|
|
|
|
|
await E.Origin.Tell($"Not enough arguments supplied!");
|
|
|
|
|
await E.Origin.Tell(C.Syntax);
|
|
|
|
|
throw new SharedLibrary.Exceptions.CommandException($"{E.Origin} did not supply enough arguments for \"{C.Name}\"");
|
|
|
|
|
}
|
2017-11-25 20:29:58 -05:00
|
|
|
|
}
|
2017-11-16 18:09:19 -05:00
|
|
|
|
}
|
2017-06-16 17:35:51 -04:00
|
|
|
|
|
2017-06-19 13:58:01 -04:00
|
|
|
|
if (E.Target == null) // Find active player as single word
|
2017-11-16 18:09:19 -05:00
|
|
|
|
{
|
|
|
|
|
matchingPlayers = GetClientByName(Args[0]);
|
|
|
|
|
if (matchingPlayers.Count > 1)
|
|
|
|
|
{
|
|
|
|
|
await E.Origin.Tell("Multiple players match that name");
|
|
|
|
|
foreach (var p in matchingPlayers)
|
2017-11-25 20:29:58 -05:00
|
|
|
|
await E.Origin.Tell($"[^3{p.ClientNumber}^7] {p.Name}");
|
2018-02-07 00:19:06 -05:00
|
|
|
|
throw new SharedLibrary.Exceptions.CommandException($"{E.Origin} had multiple players found for {C.Name}");
|
2017-11-16 18:09:19 -05:00
|
|
|
|
}
|
|
|
|
|
else if (matchingPlayers.Count == 1)
|
2017-11-25 20:29:58 -05:00
|
|
|
|
{
|
2017-11-16 18:09:19 -05:00
|
|
|
|
E.Target = matchingPlayers.First();
|
2017-11-25 20:29:58 -05:00
|
|
|
|
E.Data = Regex.Replace(E.Data, $"{E.Target.Name}", "", RegexOptions.IgnoreCase).Trim();
|
2018-02-10 01:26:38 -05:00
|
|
|
|
E.Data = Regex.Replace(E.Data, $"{Args[0]}", "", RegexOptions.IgnoreCase).Trim();
|
2018-02-09 02:21:25 -05:00
|
|
|
|
|
2018-02-10 01:26:38 -05:00
|
|
|
|
if ((E.Data.Trim() == E.Target.Name.ToLower().Trim() ||
|
|
|
|
|
E.Data == String.Empty) &&
|
|
|
|
|
C.RequiresTarget)
|
2018-02-09 02:21:25 -05:00
|
|
|
|
{
|
|
|
|
|
await E.Origin.Tell($"Not enough arguments supplied!");
|
|
|
|
|
await E.Origin.Tell(C.Syntax);
|
|
|
|
|
throw new SharedLibrary.Exceptions.CommandException($"{E.Origin} did not supply enough arguments for \"{C.Name}\"");
|
|
|
|
|
}
|
2017-11-25 20:29:58 -05:00
|
|
|
|
}
|
2017-11-16 18:09:19 -05:00
|
|
|
|
}
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
2017-06-07 17:08:29 -04:00
|
|
|
|
if (E.Target == null && C.RequiresTarget)
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
await E.Origin.Tell("Unable to find specified player.");
|
2017-05-30 17:23:31 -04:00
|
|
|
|
throw new SharedLibrary.Exceptions.CommandException($"{E.Origin} specified invalid player for \"{C.Name}\"");
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-11 20:17:20 -05:00
|
|
|
|
E.Data = E.Data.Trim();
|
2015-03-08 17:20:10 -04:00
|
|
|
|
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-08-09 00:35:23 -04:00
|
|
|
|
if (Throttled)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-08-23 18:29:48 -04:00
|
|
|
|
await ProcessEvent(E);
|
2015-07-15 17:11:29 -04:00
|
|
|
|
|
2017-06-19 13:58:01 -04:00
|
|
|
|
foreach (IPlugin P in SharedLibrary.Plugins.PluginImporter.ActivePlugins)
|
2015-08-20 13:52:30 -04:00
|
|
|
|
{
|
2018-02-07 00:19:06 -05:00
|
|
|
|
#if !DEBUG
|
2017-05-26 18:49:27 -04:00
|
|
|
|
try
|
2018-02-07 00:19:06 -05:00
|
|
|
|
#endif
|
2015-08-20 15:23:13 -04:00
|
|
|
|
{
|
2018-02-10 01:26:38 -05:00
|
|
|
|
if (cts.IsCancellationRequested)
|
|
|
|
|
break;
|
|
|
|
|
|
2017-05-27 18:08:04 -04:00
|
|
|
|
await P.OnEventAsync(E, this);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
2018-02-07 00:19:06 -05:00
|
|
|
|
#if !DEBUG
|
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
|
|
|
|
}
|
2018-02-07 00:19:06 -05:00
|
|
|
|
#endif
|
2015-08-20 13:52:30 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-17 19:28:08 -04:00
|
|
|
|
async Task<int> PollPlayersAsync()
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2017-09-27 16:07:43 -04:00
|
|
|
|
#if DEBUG
|
2018-02-07 00:19:06 -05:00
|
|
|
|
// return Players.Where(p => p != null).Count();
|
2017-09-27 16:07:43 -04:00
|
|
|
|
#endif
|
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-11-25 20:29:58 -05:00
|
|
|
|
if (CurrentPlayers.Find(p => p.ClientNumber == i) == null && Players[i] != null)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
await RemovePlayer(i);
|
2017-05-27 00:22:50 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
//polledPlayer.ClientNumber < 0 || polledPlayer.ClientNumber > (Players.Count - 1) || polledPlayer.Ping < 1 || polledPlayer.Ping == 999
|
2018-02-07 00:19:06 -05:00
|
|
|
|
for (int i = 0; i < CurrentPlayers.Count; i++)
|
2017-11-25 20:29:58 -05:00
|
|
|
|
{
|
2018-02-07 00:19:06 -05:00
|
|
|
|
await AddPlayer(CurrentPlayers[i]);
|
2017-11-25 20:29:58 -05:00
|
|
|
|
}
|
2017-08-17 19:28:08 -04:00
|
|
|
|
|
|
|
|
|
return CurrentPlayers.Count;
|
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;
|
2018-02-10 23:33:42 -05:00
|
|
|
|
bool firstRun = true;
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
2018-02-07 00:19:06 -05:00
|
|
|
|
override public async Task<bool> ProcessUpdatesAsync(CancellationToken cts)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2018-02-10 01:26:38 -05:00
|
|
|
|
this.cts = cts;
|
2015-03-14 12:42:36 -04:00
|
|
|
|
#if DEBUG == false
|
2017-05-30 17:23:31 -04:00
|
|
|
|
try
|
2015-03-14 12:42:36 -04:00
|
|
|
|
#endif
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2018-02-10 23:33:42 -05:00
|
|
|
|
// first start
|
|
|
|
|
if (firstRun)
|
|
|
|
|
{
|
|
|
|
|
await ExecuteEvent(new Event(Event.GType.Start, "Server started", null, null, this));
|
|
|
|
|
firstRun = false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-09 00:35:23 -04:00
|
|
|
|
if ((DateTime.Now - LastPoll).TotalMinutes < 2 && ConnectionErrors >= 1)
|
2018-02-07 00:19:06 -05:00
|
|
|
|
return true;
|
2017-06-12 08:28:08 -04:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2018-02-07 00:19:06 -05:00
|
|
|
|
int polledPlayerCount = await PollPlayersAsync();
|
2017-08-09 00:35:23 -04:00
|
|
|
|
|
2017-08-08 22:44:52 -04:00
|
|
|
|
if (ConnectionErrors > 0)
|
2017-08-09 00:35:23 -04:00
|
|
|
|
{
|
2017-11-13 16:58:23 -05:00
|
|
|
|
Logger.WriteVerbose($"Connection has been reestablished with {IP}:{Port}");
|
2017-08-09 00:35:23 -04:00
|
|
|
|
Throttled = false;
|
|
|
|
|
}
|
2017-06-12 08:28:08 -04:00
|
|
|
|
ConnectionErrors = 0;
|
|
|
|
|
LastPoll = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-23 18:29:48 -04:00
|
|
|
|
catch (SharedLibrary.Exceptions.NetworkException e)
|
2017-06-12 08:28:08 -04:00
|
|
|
|
{
|
|
|
|
|
ConnectionErrors++;
|
2017-08-08 22:44:52 -04:00
|
|
|
|
if (ConnectionErrors == 1)
|
2017-08-09 00:35:23 -04:00
|
|
|
|
{
|
2017-06-12 08:28:08 -04:00
|
|
|
|
Logger.WriteError($"{e.Message} {IP}:{Port}, reducing polling rate");
|
2017-11-13 16:58:23 -05:00
|
|
|
|
Logger.WriteDebug($"Internal Exception: {e.Data["internal_exception"]}");
|
2017-08-09 00:35:23 -04:00
|
|
|
|
Throttled = true;
|
|
|
|
|
}
|
2018-02-07 00:19:06 -05:00
|
|
|
|
return true;
|
2017-06-12 08:28:08 -04:00
|
|
|
|
}
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2017-06-19 13:58:01 -04:00
|
|
|
|
LastMessage = DateTime.Now - start;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
lastCount = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
if ((DateTime.Now - tickTime).TotalMilliseconds >= 1000)
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2017-06-12 17:47:31 -04:00
|
|
|
|
foreach (var Plugin in SharedLibrary.Plugins.PluginImporter.ActivePlugins)
|
2018-02-10 01:26:38 -05:00
|
|
|
|
{
|
|
|
|
|
if (cts.IsCancellationRequested)
|
|
|
|
|
break;
|
|
|
|
|
|
2017-05-28 16:47:21 -04:00
|
|
|
|
await Plugin.OnTickAsync(this);
|
2018-02-10 01:26:38 -05:00
|
|
|
|
}
|
2017-05-26 18:49:27 -04:00
|
|
|
|
tickTime = DateTime.Now;
|
|
|
|
|
}
|
2015-04-24 15:37:56 -04:00
|
|
|
|
|
2017-11-02 12:49:45 -04:00
|
|
|
|
if ((lastCount - playerCountStart).TotalMinutes >= SharedLibrary.Helpers.PlayerHistory.UpdateInterval)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-11-04 19:42:31 -04:00
|
|
|
|
while (PlayerHistory.Count > ((60 / SharedLibrary.Helpers.PlayerHistory.UpdateInterval) * 12)) // 12 times a hour for 12 hours
|
2017-06-12 13:50:00 -04:00
|
|
|
|
PlayerHistory.Dequeue();
|
2017-09-27 16:07:43 -04:00
|
|
|
|
PlayerHistory.Enqueue(new SharedLibrary.Helpers.PlayerHistory(ClientNum));
|
2017-05-26 18:49:27 -04:00
|
|
|
|
playerCountStart = DateTime.Now;
|
|
|
|
|
}
|
2015-08-20 01:06:44 -04:00
|
|
|
|
|
2017-09-27 16:07:43 -04:00
|
|
|
|
if (LastMessage.TotalSeconds > MessageTime && BroadcastMessages.Count > 0 && ClientNum > 0)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-08-23 18:29:48 -04:00
|
|
|
|
await Broadcast(Utilities.ProcessMessageToken(Manager.GetMessageTokens(), BroadcastMessages[NextMessage]));
|
2017-08-17 19:28:08 -04:00
|
|
|
|
NextMessage = NextMessage == (BroadcastMessages.Count - 1) ? 0 : NextMessage + 1;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
start = DateTime.Now;
|
|
|
|
|
}
|
2017-05-30 17:23:31 -04:00
|
|
|
|
|
2017-10-15 21:40:27 -04:00
|
|
|
|
if (LogFile == null)
|
2018-02-07 00:19:06 -05:00
|
|
|
|
return true;
|
2017-10-15 21:40:27 -04:00
|
|
|
|
|
2017-06-19 13:58:01 -04:00
|
|
|
|
if (l_size != LogFile.Length())
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
// this should be the longest running task
|
2017-06-19 13:58:01 -04:00
|
|
|
|
await Task.FromResult(lines = LogFile.Tail(12));
|
2017-05-26 18:49:27 -04:00
|
|
|
|
if (lines != oldLines)
|
2015-05-09 12:46:25 -04:00
|
|
|
|
{
|
2017-06-19 13:58:01 -04:00
|
|
|
|
l_size = LogFile.Length();
|
2018-02-08 02:23:45 -05:00
|
|
|
|
int end = (lines.Length == oldLines.Length) ? lines.Length - 1 : 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(';');
|
2017-06-07 17:08:29 -04:00
|
|
|
|
Event event_ = Event.ParseEventString(game_event, this);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
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
|
|
|
|
await ExecuteEvent(event_);
|
|
|
|
|
}
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-26 18:49:27 -04:00
|
|
|
|
oldLines = lines;
|
2017-06-19 13:58:01 -04:00
|
|
|
|
l_size = LogFile.Length();
|
2018-02-10 01:26:38 -05:00
|
|
|
|
if (!((ApplicationManager)Manager).Running)
|
|
|
|
|
{
|
|
|
|
|
foreach (var plugin in SharedLibrary.Plugins.PluginImporter.ActivePlugins)
|
|
|
|
|
await plugin.OnUnloadAsync();
|
|
|
|
|
}
|
2018-02-07 00:19:06 -05:00
|
|
|
|
return true;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
2015-03-14 12:42:36 -04:00
|
|
|
|
#if DEBUG == false
|
2017-05-30 17:23:31 -04:00
|
|
|
|
catch (SharedLibrary.Exceptions.NetworkException)
|
|
|
|
|
{
|
|
|
|
|
Logger.WriteError($"Could not communicate with {IP}:{Port}");
|
2018-02-07 00:19:06 -05:00
|
|
|
|
return false;
|
2017-05-30 17:23:31 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exception E)
|
|
|
|
|
{
|
|
|
|
|
Logger.WriteError($"Encountered error on {IP}:{Port}");
|
|
|
|
|
Logger.WriteDebug("Error Message: " + E.Message);
|
|
|
|
|
Logger.WriteDebug("Error Trace: " + E.StackTrace);
|
2018-02-07 00:19:06 -05:00
|
|
|
|
return false;
|
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-08-08 22:44:52 -04:00
|
|
|
|
var version = await this.GetDvarAsync<string>("version");
|
|
|
|
|
GameName = Utilities.GetGame(version.Value);
|
|
|
|
|
|
|
|
|
|
if (GameName == Game.UKN)
|
|
|
|
|
Logger.WriteWarning($"Game name not recognized: {version}");
|
|
|
|
|
|
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");
|
2017-08-08 22:44:52 -04:00
|
|
|
|
var maxplayers = (GameName == Game.IW4) ? // gotta love IW4 idiosyncrasies
|
|
|
|
|
await this.GetDvarAsync<int>("party_maxplayers") :
|
|
|
|
|
await this.GetDvarAsync<int>("sv_maxclients");
|
2017-05-26 18:49:27 -04:00
|
|
|
|
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");
|
2017-08-08 22:44:52 -04:00
|
|
|
|
|
|
|
|
|
DVAR<int> onelog = null;
|
|
|
|
|
if (GameName == Game.IW4)
|
|
|
|
|
onelog = await this.GetDvarAsync<int>("iw4x_onelog");
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
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();
|
2017-06-19 13:58:01 -04:00
|
|
|
|
this.CurrentMap = Maps.Find(m => m.Name == mapname.Value) ?? new Map(mapname.Value, mapname.Value);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
this.MaxClients = maxplayers.Value;
|
|
|
|
|
this.FSGame = game.Value;
|
2015-08-23 17:58:48 -04:00
|
|
|
|
|
2017-11-13 16:58:23 -05:00
|
|
|
|
await this.SetDvarAsync("sv_kickbantime", 60);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
await this.SetDvarAsync("sv_network_fps", 1000);
|
|
|
|
|
await this.SetDvarAsync("com_maxfps", 1000);
|
2015-08-22 02:04:30 -04:00
|
|
|
|
|
2017-08-08 22:44:52 -04:00
|
|
|
|
if (logsync.Value == 0 || logfile.Value == string.Empty)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
// this DVAR isn't set until the a map is loaded
|
2017-08-08 22:44:52 -04:00
|
|
|
|
await this.SetDvarAsync("logfile", 2);
|
|
|
|
|
await this.SetDvarAsync("g_logsync", 2); // set to 2 for continous in other games, clamps to 1 for IW4
|
|
|
|
|
await this.SetDvarAsync("g_log", "games_mp.log");
|
2017-06-12 13:50:00 -04:00
|
|
|
|
Logger.WriteWarning("Game log file not properly initialized, restarting map...");
|
2017-05-26 18:49:27 -04:00
|
|
|
|
await this.ExecuteCommandAsync("map_restart");
|
|
|
|
|
logfile = await this.GetDvarAsync<string>("g_log");
|
|
|
|
|
}
|
2017-11-02 12:49:45 -04:00
|
|
|
|
|
|
|
|
|
CustomCallback = await ScriptLoaded();
|
2017-05-26 18:49:27 -04:00
|
|
|
|
#if DEBUG
|
2017-09-29 22:42:24 -04:00
|
|
|
|
{
|
|
|
|
|
basepath.Value = (GameName == Game.IW4) ?
|
|
|
|
|
@"\\tsclient\J\WIN7_10.25\MW2" :
|
|
|
|
|
@"\\tsclient\G\Program Files (x86)\Steam\SteamApps\common\Call of Duty 4";
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
#endif
|
2017-08-08 22:44:52 -04:00
|
|
|
|
string mainPath = (GameName == Game.IW4) ? "userraw" : "main";
|
|
|
|
|
|
2017-08-23 18:29:48 -04:00
|
|
|
|
string logPath = (game.Value == "" || onelog?.Value == 1) ?
|
|
|
|
|
$"{ basepath.Value.Replace("\\", "/")}/{mainPath}/{logfile.Value}" :
|
2017-08-08 22:44:52 -04:00
|
|
|
|
$"{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!");
|
2017-06-12 13:50:00 -04:00
|
|
|
|
#if !DEBUG
|
|
|
|
|
throw new SharedLibrary.Exceptions.ServerException($"Invalid gamelog file {logPath}");
|
|
|
|
|
#endif
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
2017-06-13 18:33:47 -04:00
|
|
|
|
else
|
2018-02-08 02:23:45 -05:00
|
|
|
|
{
|
|
|
|
|
#if !DEBUG
|
2017-06-19 13:58:01 -04:00
|
|
|
|
LogFile = new IFile(logPath);
|
2018-02-08 02:23:45 -05:00
|
|
|
|
#else
|
|
|
|
|
}
|
|
|
|
|
LogFile = new RemoteFile("https://raidmax.org/IW4MAdmin/getlog.php");
|
|
|
|
|
#endif
|
2017-05-27 19:29:20 -04:00
|
|
|
|
Logger.WriteInfo("Log file is " + logPath);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
#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-06-07 20:59:59 -04:00
|
|
|
|
ChatHistory.Add(new Chat(E.Origin.Name, "<i>CONNECTED</i>", DateTime.Now));
|
2015-04-11 13:31:04 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-08 22:44:52 -04:00
|
|
|
|
else if (E.Type == Event.GType.Disconnect)
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2017-06-07 20:59:59 -04:00
|
|
|
|
ChatHistory.Add(new Chat(E.Origin.Name, "<i>DISCONNECTED</i>", DateTime.Now));
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-29 22:42:24 -04:00
|
|
|
|
else if (E.Type == Event.GType.Script)
|
2015-03-09 21:28:37 -04:00
|
|
|
|
{
|
2018-02-10 23:33:42 -05:00
|
|
|
|
/* if (E.Origin == E.Target)// suicide/falling
|
2017-09-29 22:42:24 -04:00
|
|
|
|
await ExecuteEvent(new Event(Event.GType.Death, E.Data, E.Target, E.Target, this));
|
|
|
|
|
else
|
2018-02-10 23:33:42 -05:00
|
|
|
|
{*/
|
2017-09-29 22:42:24 -04:00
|
|
|
|
await ExecuteEvent(new Event(Event.GType.Kill, E.Data, E.Origin, E.Target, this));
|
2018-02-10 23:33:42 -05:00
|
|
|
|
//await ExecuteEvent(new Event(Event.GType.Death, E.Data, E.Target, E.Origin, this));
|
|
|
|
|
// }
|
2015-03-09 21:28:37 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-08 22:44:52 -04:00
|
|
|
|
if (E.Type == Event.GType.Say && E.Data.Length >= 2)
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2017-08-23 18:29:48 -04:00
|
|
|
|
if (E.Data.Substring(0, 1) == "!" || E.Data.Substring(0, 1) == "@" || E.Origin.Level == Player.Permission.Console)
|
2015-03-16 16:40:30 -04:00
|
|
|
|
{
|
2017-05-30 17:23:31 -04:00
|
|
|
|
Command C = null;
|
2015-03-09 21:28:37 -04:00
|
|
|
|
|
2017-05-30 17:23:31 -04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
C = await ValidateCommand(E);
|
|
|
|
|
}
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
2017-05-30 17:23:31 -04:00
|
|
|
|
catch (SharedLibrary.Exceptions.CommandException e)
|
|
|
|
|
{
|
|
|
|
|
Logger.WriteInfo(e.Message);
|
|
|
|
|
}
|
2015-04-19 14:14:30 -04:00
|
|
|
|
|
2015-08-22 02:04:30 -04:00
|
|
|
|
if (C != null)
|
|
|
|
|
{
|
2017-06-07 17:08:29 -04:00
|
|
|
|
if (C.RequiresTarget && E.Target == null)
|
2015-08-22 02:04:30 -04:00
|
|
|
|
{
|
2017-05-30 17:23:31 -04:00
|
|
|
|
Logger.WriteWarning("Requested event (command) requiring target does not have a target!");
|
|
|
|
|
}
|
2015-04-19 14:14:30 -04:00
|
|
|
|
|
2017-05-30 17:23:31 -04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await C.ExecuteAsync(E);
|
|
|
|
|
}
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
2017-05-30 17:23:31 -04:00
|
|
|
|
catch (Exception Except)
|
|
|
|
|
{
|
|
|
|
|
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-06-01 13:42:28 -04:00
|
|
|
|
await E.Origin.Tell("^1An internal error occured while processing your command^7");
|
|
|
|
|
#if DEBUG
|
|
|
|
|
await E.Origin.Tell(Except.Message);
|
|
|
|
|
#endif
|
2015-08-22 02:04:30 -04:00
|
|
|
|
}
|
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-11-16 18:09:19 -05:00
|
|
|
|
E.Data = E.Data.StripColors();
|
2015-08-22 02:04:30 -04:00
|
|
|
|
|
2017-06-07 20:59:59 -04:00
|
|
|
|
ChatHistory.Add(new Chat(E.Origin.Name, E.Data, DateTime.Now));
|
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
|
|
|
|
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;
|
2017-06-19 13:58:01 -04:00
|
|
|
|
CurrentMap = Maps.Find(m => m.Name == mapname) ?? new Map(mapname, mapname);
|
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-08-08 22:44:52 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//todo: move
|
|
|
|
|
while (ChatHistory.Count > Math.Ceiling((double)ClientNum / 2))
|
|
|
|
|
ChatHistory.RemoveAt(0);
|
|
|
|
|
|
|
|
|
|
// the last client hasn't fully disconnected yet
|
|
|
|
|
// so there will still be at least 1 client left
|
|
|
|
|
if (ClientNum < 2)
|
|
|
|
|
ChatHistory.Clear();
|
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
|
|
|
|
{
|
2017-11-29 19:35:50 -05:00
|
|
|
|
// ensure player gets warned if command not performed on them in game
|
|
|
|
|
if (Target.ClientNumber < 0)
|
2016-01-21 12:41:00 -05:00
|
|
|
|
{
|
2017-11-29 19:35:50 -05:00
|
|
|
|
Player ingameClient = null;
|
|
|
|
|
|
|
|
|
|
ingameClient = Manager.GetServers()
|
|
|
|
|
.Select(s => s.GetPlayersAsList())
|
|
|
|
|
.FirstOrDefault(l => l.FirstOrDefault(c => c.ClientId == Target.ClientId) != null)
|
|
|
|
|
?.First(c => c.ClientId == Target.ClientId);
|
|
|
|
|
|
|
|
|
|
if (ingameClient != null)
|
2017-11-25 20:29:58 -05:00
|
|
|
|
{
|
2017-11-29 19:35:50 -05:00
|
|
|
|
await Warn(Reason, ingameClient, Origin);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (Target.Warnings >= 4)
|
|
|
|
|
await Target.Kick("Too many warnings!", (await Manager.GetClientService().Get(1)).AsPlayer());
|
2017-11-25 20:29:58 -05:00
|
|
|
|
|
2017-11-29 19:35:50 -05:00
|
|
|
|
Target.Warnings++;
|
2017-11-25 20:29:58 -05:00
|
|
|
|
String Message = String.Format("^1WARNING ^7[^3{0}^7]: ^3{1}^7, {2}", Target.Warnings, Target.Name, Reason);
|
2017-11-29 19:35:50 -05:00
|
|
|
|
await Target.CurrentServer.Broadcast(Message);
|
2016-01-21 12:41:00 -05:00
|
|
|
|
}
|
2017-11-29 19:35:50 -05:00
|
|
|
|
|
|
|
|
|
Penalty newPenalty = new Penalty()
|
|
|
|
|
{
|
|
|
|
|
Type = Penalty.PenaltyType.Warning,
|
|
|
|
|
Expires = DateTime.UtcNow,
|
|
|
|
|
Offender = Target,
|
|
|
|
|
Offense = Reason,
|
|
|
|
|
Punisher = Origin,
|
|
|
|
|
Active = true,
|
|
|
|
|
When = DateTime.UtcNow,
|
|
|
|
|
Link = Target.AliasLink
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await Manager.GetPenaltyService().Create(newPenalty);
|
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
|
|
|
|
{
|
2017-11-29 19:35:50 -05:00
|
|
|
|
// ensure player gets kicked if command not performed on them in game
|
|
|
|
|
if (Target.ClientNumber < 0)
|
2016-01-15 17:15:39 -05:00
|
|
|
|
{
|
2017-11-29 19:35:50 -05:00
|
|
|
|
Player ingameClient = null;
|
|
|
|
|
|
|
|
|
|
ingameClient = Manager.GetServers()
|
|
|
|
|
.Select(s => s.GetPlayersAsList())
|
|
|
|
|
.FirstOrDefault(l => l.FirstOrDefault(c => c.ClientId == Target.ClientId) != null)
|
|
|
|
|
?.First(c => c.ClientId == Target.ClientId);
|
|
|
|
|
|
|
|
|
|
if (ingameClient != null)
|
2017-11-25 20:29:58 -05:00
|
|
|
|
{
|
2017-11-29 19:35:50 -05:00
|
|
|
|
await Kick(Reason, ingameClient, Origin);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-01-15 17:15:39 -05:00
|
|
|
|
}
|
2017-11-29 19:35:50 -05:00
|
|
|
|
else
|
|
|
|
|
await Target.CurrentServer.ExecuteCommandAsync($"clientkick {Target.ClientNumber} \"Player Kicked: ^5{Reason}^7\"");
|
|
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
await Target.CurrentServer.RemovePlayer(Target.ClientNumber);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
var newPenalty = new Penalty()
|
|
|
|
|
{
|
|
|
|
|
Type = Penalty.PenaltyType.Kick,
|
|
|
|
|
Expires = DateTime.UtcNow,
|
|
|
|
|
Offender = Target,
|
|
|
|
|
Offense = Reason,
|
|
|
|
|
Punisher = Origin,
|
|
|
|
|
Active = true,
|
|
|
|
|
When = DateTime.UtcNow,
|
|
|
|
|
Link = Target.AliasLink
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await Manager.GetPenaltyService().Create(newPenalty);
|
2016-01-15 17:15:39 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-23 18:29:48 -04:00
|
|
|
|
public override async Task TempBan(String Reason, TimeSpan length, Player Target, Player Origin)
|
2016-01-15 17:15:39 -05:00
|
|
|
|
{
|
2017-11-29 19:35:50 -05:00
|
|
|
|
// ensure player gets banned if command not performed on them in game
|
|
|
|
|
if (Target.ClientNumber < 0)
|
|
|
|
|
{
|
|
|
|
|
Player ingameClient = null;
|
|
|
|
|
|
|
|
|
|
ingameClient = Manager.GetServers()
|
|
|
|
|
.Select(s => s.GetPlayersAsList())
|
|
|
|
|
.FirstOrDefault(l => l.FirstOrDefault(c => c.ClientId == Target.ClientId) != null)
|
|
|
|
|
?.First(c => c.ClientId == Target.ClientId);
|
|
|
|
|
|
|
|
|
|
if (ingameClient != null)
|
|
|
|
|
{
|
|
|
|
|
await TempBan(Reason, length, ingameClient, Origin);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
2018-02-10 23:33:42 -05:00
|
|
|
|
await Target.CurrentServer.ExecuteCommandAsync($"clientkick {Target.ClientNumber } \"^7Player Temporarily Banned: ^5{ Reason }\"");
|
2017-11-29 19:35:50 -05:00
|
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
await Target.CurrentServer.RemovePlayer(Target.ClientNumber);
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
Penalty newPenalty = new Penalty()
|
|
|
|
|
{
|
|
|
|
|
Type = Penalty.PenaltyType.TempBan,
|
|
|
|
|
Expires = DateTime.UtcNow + length,
|
|
|
|
|
Offender = Target,
|
|
|
|
|
Offense = Reason,
|
|
|
|
|
Punisher = Origin,
|
|
|
|
|
Active = true,
|
|
|
|
|
When = DateTime.UtcNow,
|
|
|
|
|
Link = Target.AliasLink
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await Manager.GetPenaltyService().Create(newPenalty);
|
2016-01-15 17:15:39 -05:00
|
|
|
|
}
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
override public async Task Ban(String Message, Player Target, Player Origin)
|
|
|
|
|
{
|
2017-11-29 19:35:50 -05:00
|
|
|
|
// ensure player gets banned if command not performed on them in game
|
|
|
|
|
if (Target.ClientNumber < 0)
|
|
|
|
|
{
|
|
|
|
|
Player ingameClient = null;
|
|
|
|
|
|
|
|
|
|
ingameClient = Manager.GetServers()
|
|
|
|
|
.Select(s => s.GetPlayersAsList())
|
|
|
|
|
.FirstOrDefault(l => l.FirstOrDefault(c => c.ClientId == Target.ClientId) != null)
|
|
|
|
|
?.First(c => c.ClientId == Target.ClientId);
|
|
|
|
|
|
|
|
|
|
if (ingameClient != null)
|
|
|
|
|
{
|
|
|
|
|
await Ban(Message, ingameClient, Origin);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// this is set only because they're still in the server.
|
|
|
|
|
Target.Level = Player.Permission.Banned;
|
|
|
|
|
await Target.CurrentServer.ExecuteCommandAsync($"clientkick {Target.ClientNumber} \"Player Banned: ^5{Message} ^7(appeal at {Website}) ^7\"");
|
|
|
|
|
#if DEBUG
|
|
|
|
|
await Target.CurrentServer.RemovePlayer(Target.ClientNumber);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
Penalty newPenalty = new Penalty()
|
|
|
|
|
{
|
|
|
|
|
Type = Penalty.PenaltyType.Ban,
|
|
|
|
|
Expires = DateTime.MinValue,
|
|
|
|
|
Offender = Target,
|
|
|
|
|
Offense = Message,
|
|
|
|
|
Punisher = Origin,
|
|
|
|
|
Active = true,
|
|
|
|
|
When = DateTime.UtcNow,
|
|
|
|
|
Link = Target.AliasLink
|
|
|
|
|
};
|
|
|
|
|
|
2017-11-29 19:35:50 -05:00
|
|
|
|
await Manager.GetPenaltyService().Create(newPenalty);
|
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-11-25 20:29:58 -05:00
|
|
|
|
await Manager.GetPenaltyService().RemoveActivePenalties(Target.AliasLink.AliasLinkId);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-07 17:08:29 -04:00
|
|
|
|
public override bool Reload()
|
2015-08-20 17:54:38 -04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
InitializeMaps();
|
|
|
|
|
InitializeAutoMessages();
|
|
|
|
|
InitializeRules();
|
2015-08-20 17:54:38 -04:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception E)
|
|
|
|
|
{
|
2017-05-27 19:29:20 -04:00
|
|
|
|
Logger.WriteError("Unable to reload configs! - " + E.Message);
|
2017-06-19 13:58:01 -04:00
|
|
|
|
BroadcastMessages = new List<String>();
|
|
|
|
|
Maps = new List<Map>();
|
|
|
|
|
Rules = new List<String>();
|
2015-08-20 17:54:38 -04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
override public void InitializeTokens()
|
2015-03-13 19:40:16 -04:00
|
|
|
|
{
|
2017-11-25 20:29:58 -05:00
|
|
|
|
Manager.GetMessageTokens().Add(new SharedLibrary.Helpers.MessageToken("TOTALPLAYERS", Manager.GetClientService().GetTotalClientsAsync().Result.ToString));
|
2017-06-12 17:47:31 -04:00
|
|
|
|
Manager.GetMessageTokens().Add(new SharedLibrary.Helpers.MessageToken("VERSION", Program.Version.ToString));
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
}
|