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;
|
2018-04-02 01:25:06 -04:00
|
|
|
|
using System.Text.RegularExpressions;
|
2018-04-16 16:31:14 -04:00
|
|
|
|
using System.Runtime.InteropServices;
|
2017-06-19 13:58:01 -04:00
|
|
|
|
|
2018-04-08 02:44:42 -04:00
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using SharedLibraryCore.Interfaces;
|
|
|
|
|
using SharedLibraryCore.Objects;
|
|
|
|
|
using SharedLibraryCore.Database.Models;
|
|
|
|
|
using SharedLibraryCore.Dtos;
|
|
|
|
|
using SharedLibraryCore.Configuration;
|
2018-04-16 16:31:14 -04:00
|
|
|
|
using SharedLibraryCore.Exceptions;
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
2018-04-16 16:31:14 -04:00
|
|
|
|
using Application.Misc;
|
2018-04-11 18:24:21 -04:00
|
|
|
|
using Application.RconParsers;
|
2018-04-25 02:38:59 -04:00
|
|
|
|
using IW4MAdmin.Application.EventParsers;
|
2018-04-26 02:13:04 -04:00
|
|
|
|
using IW4MAdmin.Application.IO;
|
2018-04-02 01:25:06 -04:00
|
|
|
|
|
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;
|
2018-04-22 16:04:18 -04:00
|
|
|
|
private static Dictionary<string, string> loc = Utilities.CurrentLocalization.LocalizationSet;
|
2018-04-26 02:13:04 -04:00
|
|
|
|
private GameLogEvent LogEvent;
|
|
|
|
|
|
2018-02-10 01:26:38 -05:00
|
|
|
|
|
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-04-10 02:38:18 -04:00
|
|
|
|
// todo: make this better with collisions
|
|
|
|
|
int id = Math.Abs($"{IP}:{Port.ToString()}".Select(a => (int)a).Sum());
|
|
|
|
|
|
2018-04-28 17:39:45 -04:00
|
|
|
|
// hack: this is a nasty fix for get hashcode being changed
|
2018-04-14 00:51:38 -04:00
|
|
|
|
switch (id)
|
2018-04-10 02:38:18 -04:00
|
|
|
|
{
|
|
|
|
|
case 765:
|
|
|
|
|
return 886229536;
|
|
|
|
|
case 760:
|
|
|
|
|
return 1645744423;
|
|
|
|
|
case 761:
|
|
|
|
|
return 1645809959;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return id;
|
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-04-15 21:27:43 -04:00
|
|
|
|
|
2018-04-23 01:43:48 -04:00
|
|
|
|
if ((polledPlayer.Ping == 999 && !polledPlayer.IsBot) ||
|
2018-04-28 01:22:18 -04:00
|
|
|
|
polledPlayer.Ping < 1 ||
|
2018-04-15 21:27:43 -04:00
|
|
|
|
polledPlayer.ClientNumber < 0)
|
2018-02-07 00:19:06 -05:00
|
|
|
|
{
|
|
|
|
|
//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
|
|
|
|
}
|
2018-03-26 00:51:25 -04:00
|
|
|
|
#if !DEBUG
|
2017-11-25 20:29:58 -05:00
|
|
|
|
if (polledPlayer.Name.Length < 3)
|
2017-11-13 16:58:23 -05:00
|
|
|
|
{
|
2018-02-27 23:19:54 -05:00
|
|
|
|
Logger.WriteDebug($"Kicking {polledPlayer} because their name is too short");
|
2018-04-22 16:04:18 -04:00
|
|
|
|
string formattedKick = String.Format(RconParser.GetCommandPrefixes().Kick, polledPlayer.ClientNumber, loc["SERVER_KICK_MINNAME"]);
|
2018-04-13 02:32:30 -04:00
|
|
|
|
await this.ExecuteCommandAsync(formattedKick);
|
2017-11-13 16:58:23 -05:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-26 23:24:19 -05:00
|
|
|
|
if (Players.FirstOrDefault(p => p != null && p.Name == polledPlayer.Name) != null)
|
|
|
|
|
{
|
2018-02-27 23:19:54 -05:00
|
|
|
|
Logger.WriteDebug($"Kicking {polledPlayer} because their name is already in use");
|
2018-04-22 16:04:18 -04:00
|
|
|
|
string formattedKick = String.Format(RconParser.GetCommandPrefixes().Kick, polledPlayer.ClientNumber, loc["SERVER_KICK_NAME_INUSE"]);
|
2018-04-13 02:32:30 -04:00
|
|
|
|
await this.ExecuteCommandAsync(formattedKick);
|
2018-02-26 23:24:19 -05:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (polledPlayer.Name == "Unknown Soldier" ||
|
2018-03-09 03:01:12 -05:00
|
|
|
|
polledPlayer.Name == "UnknownSoldier" ||
|
|
|
|
|
polledPlayer.Name == "CHEATER")
|
2018-02-26 23:24:19 -05:00
|
|
|
|
{
|
2018-02-27 23:19:54 -05:00
|
|
|
|
Logger.WriteDebug($"Kicking {polledPlayer} because their name is generic");
|
2018-04-22 16:04:18 -04:00
|
|
|
|
string formattedKick = String.Format(RconParser.GetCommandPrefixes().Kick, polledPlayer.ClientNumber, loc["SERVER_KICK_GENERICNAME"]);
|
2018-04-13 02:32:30 -04:00
|
|
|
|
await this.ExecuteCommandAsync(formattedKick);
|
2018-02-26 23:24:19 -05:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-22 14:50:09 -04:00
|
|
|
|
if (polledPlayer.Name.Where(c => Char.IsControl(c)).Count() > 0)
|
|
|
|
|
{
|
2018-04-22 16:04:18 -04:00
|
|
|
|
Logger.WriteDebug($"Kicking {polledPlayer} because their name contains control characters");
|
|
|
|
|
string formattedKick = String.Format(RconParser.GetCommandPrefixes().Kick, polledPlayer.ClientNumber, loc["SERVER_KICK_CONTROLCHARS"]);
|
2018-04-13 02:32:30 -04:00
|
|
|
|
await this.ExecuteCommandAsync(formattedKick);
|
2018-03-22 14:50:09 -04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-26 00:51:25 -04:00
|
|
|
|
#endif
|
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
|
|
|
|
{
|
2018-04-09 23:33:42 -04:00
|
|
|
|
client.LastConnection = DateTime.UtcNow;
|
2017-11-25 20:29:58 -05:00
|
|
|
|
client.Connections += 1;
|
2018-04-09 15:17:10 -04:00
|
|
|
|
|
2018-02-26 23:24:19 -05:00
|
|
|
|
var existingAlias = client.AliasLink.Children
|
|
|
|
|
.FirstOrDefault(a => a.Name == polledPlayer.Name && a.IPAddress == polledPlayer.IPAddress);
|
2017-08-23 18:29:48 -04:00
|
|
|
|
|
2018-02-26 23:24:19 -05:00
|
|
|
|
if (existingAlias == null)
|
2017-11-25 20:29:58 -05:00
|
|
|
|
{
|
2018-02-24 00:56:03 -05:00
|
|
|
|
Logger.WriteDebug($"Client {polledPlayer} has connected previously under a different ip/name");
|
2018-03-13 17:30:22 -04:00
|
|
|
|
client.CurrentAlias = new 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
|
|
|
|
};
|
2018-02-24 00:56:03 -05:00
|
|
|
|
// we need to update their new ip and name to the virtual property
|
|
|
|
|
client.Name = polledPlayer.Name;
|
|
|
|
|
client.IPAddress = polledPlayer.IPAddress;
|
|
|
|
|
|
2017-11-29 19:35:50 -05:00
|
|
|
|
await Manager.GetClientService().Update(client);
|
2017-11-25 20:29:58 -05:00
|
|
|
|
}
|
2018-02-26 23:24:19 -05:00
|
|
|
|
|
2018-03-06 02:22:19 -05:00
|
|
|
|
else if (existingAlias.Name == polledPlayer.Name)
|
2018-02-26 23:24:19 -05:00
|
|
|
|
{
|
|
|
|
|
client.CurrentAlias = existingAlias;
|
2018-02-27 23:19:54 -05:00
|
|
|
|
client.CurrentAliasId = existingAlias.AliasId;
|
2018-02-26 23:24:19 -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
|
|
|
|
|
2018-02-17 15:06:37 -05:00
|
|
|
|
// Do the player specific stuff
|
2017-11-29 19:35:50 -05:00
|
|
|
|
player.ClientNumber = polledPlayer.ClientNumber;
|
2018-04-21 18:18:20 -04:00
|
|
|
|
player.IsBot = polledPlayer.IsBot;
|
2018-02-17 15:06:37 -05:00
|
|
|
|
player.Score = polledPlayer.Score;
|
|
|
|
|
player.CurrentServer = this;
|
2017-11-29 19:35:50 -05:00
|
|
|
|
Players[player.ClientNumber] = player;
|
2015-03-23 23:01:05 -04:00
|
|
|
|
|
2018-04-13 02:32:30 -04:00
|
|
|
|
var activePenalties = await Manager.GetPenaltyService().GetActivePenaltiesAsync(player.AliasLinkId, player.IPAddress);
|
2018-02-15 23:01:28 -05:00
|
|
|
|
var currentBan = activePenalties.FirstOrDefault(b => b.Expires > DateTime.UtcNow);
|
2015-03-23 23:01:05 -04:00
|
|
|
|
|
2018-02-15 23:01:28 -05:00
|
|
|
|
if (currentBan != 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
|
|
|
|
|
2018-02-15 23:01:28 -05:00
|
|
|
|
if (currentBan.Type == Penalty.PenaltyType.TempBan)
|
2018-04-13 02:32:30 -04:00
|
|
|
|
{
|
2018-04-22 16:04:18 -04:00
|
|
|
|
string formattedKick = String.Format(RconParser.GetCommandPrefixes().Kick, polledPlayer.ClientNumber, $"{loc["SERVER_TB_REMAIN"]} ({(currentBan.Expires - DateTime.UtcNow).TimeSpanText()} left)");
|
2018-04-13 02:32:30 -04:00
|
|
|
|
await this.ExecuteCommandAsync(formattedKick);
|
|
|
|
|
}
|
2017-11-25 20:29:58 -05:00
|
|
|
|
else
|
2018-04-22 16:04:18 -04:00
|
|
|
|
await player.Kick($"{loc["SERVER_BAN_PREV"]} {currentBan.Offense}", autoKickClient);
|
2015-03-23 23:01:05 -04:00
|
|
|
|
|
2018-02-15 23:01:28 -05:00
|
|
|
|
if (player.Level != Player.Permission.Banned && currentBan.Type == Penalty.PenaltyType.Ban)
|
2018-04-22 16:04:18 -04:00
|
|
|
|
await player.Ban($"{loc["SERVER_BAN_PREV"]} {currentBan.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
|
|
|
|
|
2018-02-07 00:19:06 -05:00
|
|
|
|
Logger.WriteInfo($"Client {player} connecting...");
|
2017-11-25 20:29:58 -05:00
|
|
|
|
|
2018-04-26 20:19:42 -04:00
|
|
|
|
var e = new GameEvent(GameEvent.EventType.Connect, "", player, null, this);
|
|
|
|
|
Manager.GetEventHandler().AddEvent(e);
|
2018-04-26 02:13:04 -04:00
|
|
|
|
|
2018-04-28 21:11:13 -04:00
|
|
|
|
// e.OnProcessed.Wait();
|
2018-03-09 03:01:12 -05:00
|
|
|
|
|
2018-03-18 22:25:11 -04:00
|
|
|
|
if (!Manager.GetApplicationSettings().Configuration().EnableClientVPNs &&
|
|
|
|
|
await VPNCheck.UsingVPN(player.IPAddressString, Manager.GetApplicationSettings().Configuration().IPHubAPIKey))
|
2018-03-09 03:01:12 -05:00
|
|
|
|
{
|
2018-04-22 16:04:18 -04:00
|
|
|
|
await player.Kick(Utilities.CurrentLocalization.LocalizationSet["SERVER_KICK_VPNS_NOTALLOWED"], new Player() { ClientId = 1 });
|
2018-03-09 03:01:12 -05:00
|
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2018-04-24 18:01:27 -04:00
|
|
|
|
Manager.GetLogger().WriteError($"{loc["SERVER_ERROR_ADDPLAYER"]} {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];
|
2018-03-06 02:22:19 -05:00
|
|
|
|
Logger.WriteInfo($"Client {Leaving} disconnecting...");
|
|
|
|
|
|
2018-04-26 20:19:42 -04:00
|
|
|
|
var e = new GameEvent(GameEvent.EventType.Disconnect, "", Leaving, null, this);
|
|
|
|
|
Manager.GetEventHandler().AddEvent(e);
|
|
|
|
|
e.OnProcessed.Wait();
|
2018-03-06 02:22:19 -05:00
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
Leaving.TotalConnectionTime += (int)(DateTime.UtcNow - Leaving.ConnectionTime).TotalSeconds;
|
2018-02-16 23:24:03 -05:00
|
|
|
|
Leaving.LastConnection = DateTime.UtcNow;
|
2017-11-25 20:29:58 -05:00
|
|
|
|
await Manager.GetClientService().Update(Leaving);
|
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-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
|
2018-04-13 02:32:30 -04:00
|
|
|
|
override public async Task<Command> ValidateCommand(GameEvent 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)
|
|
|
|
|
{
|
2018-04-22 16:04:18 -04:00
|
|
|
|
await E.Origin.Tell(loc["COMMAND_UNKNOWN"]);
|
2018-04-14 00:51:38 -04:00
|
|
|
|
throw new CommandException($"{E.Origin} entered unknown command \"{CommandString}\"");
|
2017-05-30 17:23:31 -04:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
2018-04-22 16:04:18 -04:00
|
|
|
|
await E.Origin.Tell(loc["COMMAND_NOACCESS"]);
|
2018-04-14 00:51:38 -04:00
|
|
|
|
throw new 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
|
|
|
|
{
|
2018-04-22 16:04:18 -04:00
|
|
|
|
await E.Origin.Tell(loc["COMMAND_MISSINGARGS"]);
|
2017-11-15 16:04:13 -05:00
|
|
|
|
await E.Origin.Tell(C.Syntax);
|
2018-04-14 00:51:38 -04:00
|
|
|
|
throw new 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
|
|
|
|
{
|
2018-04-26 02:13:04 -04:00
|
|
|
|
if (!Int32.TryParse(Args[0], out int cNum))
|
|
|
|
|
cNum = -1;
|
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)
|
|
|
|
|
{
|
2018-04-22 16:04:18 -04:00
|
|
|
|
await E.Origin.Tell(loc["COMMAND_TARGET_MULTI"]);
|
2018-04-14 00:51:38 -04:00
|
|
|
|
throw new 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();
|
2018-02-09 02:21:25 -05:00
|
|
|
|
|
2018-03-24 17:35:54 -04:00
|
|
|
|
string escapedName = Regex.Escape(E.Target.Name);
|
|
|
|
|
var reg = new Regex($"(\"{escapedName}\")|({escapedName})", RegexOptions.IgnoreCase);
|
|
|
|
|
E.Data = reg.Replace(E.Data, "", 1).Trim();
|
2018-03-27 00:54:20 -04:00
|
|
|
|
|
2018-03-13 17:30:22 -04:00
|
|
|
|
if (E.Data.Length == 0 && C.RequiredArgumentCount > 1)
|
2018-02-09 02:21:25 -05:00
|
|
|
|
{
|
2018-04-22 16:04:18 -04:00
|
|
|
|
await E.Origin.Tell(loc["COMMAND_MISSINGARGS"]);
|
2018-02-09 02:21:25 -05:00
|
|
|
|
await E.Origin.Tell(C.Syntax);
|
2018-04-14 00:51:38 -04:00
|
|
|
|
throw new CommandException($"{E.Origin} did not supply enough arguments for \"{C.Name}\"");
|
2018-02-09 02:21:25 -05:00
|
|
|
|
}
|
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)
|
|
|
|
|
{
|
2018-04-22 16:04:18 -04:00
|
|
|
|
await E.Origin.Tell(loc["COMMAND_TARGET_MULTI"]);
|
2017-11-16 18:09:19 -05:00
|
|
|
|
foreach (var p in matchingPlayers)
|
2017-11-25 20:29:58 -05:00
|
|
|
|
await E.Origin.Tell($"[^3{p.ClientNumber}^7] {p.Name}");
|
2018-04-14 00:51:38 -04:00
|
|
|
|
throw new 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();
|
2018-03-24 17:35:54 -04:00
|
|
|
|
|
|
|
|
|
string escapedName = Regex.Escape(E.Target.Name);
|
|
|
|
|
string escapedArg = Regex.Escape(Args[0]);
|
|
|
|
|
var reg = new Regex($"({escapedName})|({escapedArg})", RegexOptions.IgnoreCase);
|
|
|
|
|
E.Data = reg.Replace(E.Data, "", 1).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
|
|
|
|
{
|
2018-04-22 16:04:18 -04:00
|
|
|
|
await E.Origin.Tell(loc["COMMAND_MISSINGARGS"]);
|
2018-02-09 02:21:25 -05:00
|
|
|
|
await E.Origin.Tell(C.Syntax);
|
2018-04-14 00:51:38 -04:00
|
|
|
|
throw new CommandException($"{E.Origin} did not supply enough arguments for \"{C.Name}\"");
|
2018-02-09 02:21:25 -05:00
|
|
|
|
}
|
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
|
|
|
|
{
|
2018-04-22 16:04:18 -04:00
|
|
|
|
await E.Origin.Tell(loc["COMMAND_TARGET_NOTFOUND"]);
|
2018-04-14 00:51:38 -04:00
|
|
|
|
throw new 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;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 02:32:30 -04:00
|
|
|
|
public override async Task ExecuteEvent(GameEvent E)
|
2015-07-06 13:13:42 -04:00
|
|
|
|
{
|
2018-04-26 02:13:04 -04:00
|
|
|
|
bool canExecuteCommand = true;
|
2017-08-23 18:29:48 -04:00
|
|
|
|
await ProcessEvent(E);
|
2018-04-08 14:48:40 -04:00
|
|
|
|
Manager.GetEventApi().OnServerEvent(this, E);
|
2015-07-15 17:11:29 -04:00
|
|
|
|
|
2018-04-08 02:44:42 -04:00
|
|
|
|
foreach (IPlugin P in SharedLibraryCore.Plugins.PluginImporter.ActivePlugins)
|
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
|
|
|
|
{
|
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-04-26 02:13:04 -04:00
|
|
|
|
|
|
|
|
|
// this happens if a plugin (login) wants to stop commands from executing
|
|
|
|
|
catch (AuthorizationException e)
|
|
|
|
|
{
|
|
|
|
|
await E.Origin.Tell($"{loc["COMMAND_NOTAUTHORIZED"]} - {e.Message}");
|
|
|
|
|
canExecuteCommand = false;
|
|
|
|
|
}
|
|
|
|
|
|
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));
|
2018-04-09 23:33:42 -04:00
|
|
|
|
while (Except.InnerException != null)
|
|
|
|
|
{
|
|
|
|
|
Except = Except.InnerException;
|
|
|
|
|
Logger.WriteDebug($"Inner exception: {Except.Message}");
|
|
|
|
|
}
|
2017-05-26 18:49:27 -04:00
|
|
|
|
continue;
|
2015-08-20 15:23:13 -04:00
|
|
|
|
}
|
2018-04-26 02:13:04 -04:00
|
|
|
|
|
2015-08-20 13:52:30 -04:00
|
|
|
|
}
|
2018-04-26 02:13:04 -04:00
|
|
|
|
|
|
|
|
|
// hack: this prevents commands from getting executing that 'shouldn't' be
|
|
|
|
|
if (E.Type == GameEvent.EventType.Command &&
|
|
|
|
|
E.Extra != null &&
|
2018-04-26 20:19:42 -04:00
|
|
|
|
(canExecuteCommand ||
|
2018-04-26 02:13:04 -04:00
|
|
|
|
E.Origin?.Level == Player.Permission.Console))
|
|
|
|
|
{
|
|
|
|
|
await (((Command)E.Extra).ExecuteAsync(E));
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-20 13:52:30 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-26 02:13:04 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Perform the server specific tasks when an event occurs
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="E"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
override protected async Task ProcessEvent(GameEvent E)
|
|
|
|
|
{
|
|
|
|
|
if (E.Type == GameEvent.EventType.Connect)
|
2018-04-28 21:11:13 -04:00
|
|
|
|
{
|
|
|
|
|
ChatHistory.Add(new ChatInfo()
|
|
|
|
|
{
|
|
|
|
|
Name = E.Origin.Name,
|
|
|
|
|
Message = "CONNECTED",
|
|
|
|
|
Time = DateTime.UtcNow
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (E.Origin.Level > Player.Permission.Moderator)
|
|
|
|
|
await E.Origin.Tell(string.Format(loc["SERVER_REPORT_COUNT"], E.Owner.Reports.Count));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (E.Type == GameEvent.EventType.Join)
|
2018-04-26 02:13:04 -04:00
|
|
|
|
{
|
|
|
|
|
// special case for IW5 when connect is from the log
|
2018-04-28 01:22:18 -04:00
|
|
|
|
if (E.Extra != null && GameName == Game.IW5)
|
2018-04-26 02:13:04 -04:00
|
|
|
|
{
|
|
|
|
|
var logClient = (Player)E.Extra;
|
|
|
|
|
var client = (await this.GetStatusAsync())
|
|
|
|
|
.Single(c => c.ClientNumber == logClient.ClientNumber &&
|
|
|
|
|
c.Name == logClient.Name);
|
|
|
|
|
client.NetworkId = logClient.NetworkId;
|
|
|
|
|
|
|
|
|
|
await AddPlayer(client);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (E.Type == GameEvent.EventType.Disconnect)
|
|
|
|
|
{
|
|
|
|
|
ChatHistory.Add(new ChatInfo()
|
|
|
|
|
{
|
|
|
|
|
Name = E.Origin.Name,
|
|
|
|
|
Message = "DISCONNECTED",
|
|
|
|
|
Time = DateTime.UtcNow
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (E.Type == GameEvent.EventType.Script)
|
|
|
|
|
{
|
2018-04-28 17:39:45 -04:00
|
|
|
|
Manager.GetEventHandler().AddEvent(GameEvent.TranferWaiter(GameEvent.EventType.Kill, E));
|
2018-04-26 02:13:04 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (E.Type == GameEvent.EventType.Say && E.Data.Length >= 2)
|
|
|
|
|
{
|
|
|
|
|
if (E.Data.Substring(0, 1) == "!" ||
|
|
|
|
|
E.Data.Substring(0, 1) == "@" ||
|
|
|
|
|
E.Origin.Level == Player.Permission.Console)
|
|
|
|
|
{
|
|
|
|
|
Command C = null;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
C = await ValidateCommand(E);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (CommandException e)
|
|
|
|
|
{
|
|
|
|
|
Logger.WriteInfo(e.Message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (C != null)
|
|
|
|
|
{
|
|
|
|
|
if (C.RequiresTarget && E.Target == null)
|
|
|
|
|
{
|
|
|
|
|
Logger.WriteWarning("Requested event (command) requiring target does not have a target!");
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-28 17:39:45 -04:00
|
|
|
|
E.Extra = C;
|
2018-04-28 21:11:13 -04:00
|
|
|
|
|
2018-04-28 17:39:45 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// reprocess event as a command
|
|
|
|
|
Manager.GetEventHandler().AddEvent(GameEvent.TranferWaiter(GameEvent.EventType.Command, E));
|
2018-04-26 02:13:04 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else // Not a command
|
|
|
|
|
{
|
|
|
|
|
E.Data = E.Data.StripColors();
|
|
|
|
|
|
|
|
|
|
ChatHistory.Add(new ChatInfo()
|
|
|
|
|
{
|
|
|
|
|
Name = E.Origin.Name,
|
|
|
|
|
Message = E.Data,
|
|
|
|
|
Time = DateTime.UtcNow
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (E.Type == GameEvent.EventType.MapChange)
|
|
|
|
|
{
|
|
|
|
|
Logger.WriteInfo($"New map loaded - {ClientNum} active players");
|
|
|
|
|
|
|
|
|
|
// iw4 doesn't log the game info
|
|
|
|
|
if (E.Extra == null)
|
|
|
|
|
{
|
|
|
|
|
var dict = await this.GetInfoAsync();
|
|
|
|
|
|
|
|
|
|
Gametype = dict["gametype"].StripColors();
|
|
|
|
|
Hostname = dict["hostname"].StripColors();
|
|
|
|
|
|
|
|
|
|
string mapname = dict["mapname"].StripColors();
|
|
|
|
|
CurrentMap = Maps.Find(m => m.Name == mapname) ?? new Map() { Alias = mapname, Name = mapname };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var dict = (Dictionary<string, string>)E.Extra;
|
|
|
|
|
Gametype = dict["g_gametype"].StripColors();
|
|
|
|
|
Hostname = dict["sv_hostname"].StripColors();
|
|
|
|
|
|
|
|
|
|
string mapname = dict["mapname"].StripColors();
|
|
|
|
|
CurrentMap = Maps.Find(m => m.Name == mapname) ?? new Map() { Alias = mapname, Name = mapname };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (E.Type == GameEvent.EventType.MapEnd)
|
|
|
|
|
{
|
|
|
|
|
Logger.WriteInfo("Game ending...");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-08-17 19:28:08 -04:00
|
|
|
|
async Task<int> PollPlayersAsync()
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2018-03-06 02:22:19 -05:00
|
|
|
|
var now = DateTime.Now;
|
2018-04-02 01:25:06 -04:00
|
|
|
|
|
|
|
|
|
List<Player> CurrentPlayers = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
CurrentPlayers = await this.GetStatusAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// when the server has lost connection
|
2018-04-14 00:51:38 -04:00
|
|
|
|
catch (NetworkException)
|
2018-04-02 01:25:06 -04:00
|
|
|
|
{
|
|
|
|
|
Throttled = true;
|
|
|
|
|
return ClientNum;
|
|
|
|
|
}
|
2018-03-06 02:22:19 -05:00
|
|
|
|
#if DEBUG
|
|
|
|
|
Logger.WriteInfo($"Polling players took {(DateTime.Now - now).TotalMilliseconds}ms");
|
|
|
|
|
#endif
|
2018-03-13 17:30:22 -04:00
|
|
|
|
Throttled = false;
|
2018-04-28 01:22:18 -04:00
|
|
|
|
|
|
|
|
|
var clients = GetPlayersAsList();
|
2018-04-28 21:11:13 -04:00
|
|
|
|
foreach (var client in clients)
|
2017-05-27 00:22:50 -04:00
|
|
|
|
{
|
2018-04-28 21:11:13 -04:00
|
|
|
|
if (GameName == Game.IW5)
|
|
|
|
|
{
|
|
|
|
|
if (!CurrentPlayers.Select(c => c.ClientNumber).Contains(client.ClientNumber))
|
|
|
|
|
await RemovePlayer(client.ClientNumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!CurrentPlayers.Select(c => c.NetworkId).Contains(client.NetworkId))
|
|
|
|
|
await RemovePlayer(client.ClientNumber);
|
|
|
|
|
}
|
2017-05-27 00:22:50 -04:00
|
|
|
|
}
|
|
|
|
|
|
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-04-23 01:43:48 -04:00
|
|
|
|
// todo: wait til GUID is included in status to fix this
|
|
|
|
|
if (GameName != Game.IW5)
|
|
|
|
|
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
|
|
|
|
DateTime start = DateTime.Now;
|
|
|
|
|
DateTime playerCountStart = DateTime.Now;
|
|
|
|
|
DateTime lastCount = DateTime.Now;
|
|
|
|
|
DateTime tickTime = DateTime.Now;
|
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;
|
2017-05-30 17:23:31 -04:00
|
|
|
|
try
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
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-04-23 01:43:48 -04:00
|
|
|
|
// trying to reduce the polling rate as every 450ms is unnecessary
|
|
|
|
|
if ((DateTime.Now - LastPoll).TotalSeconds >= 10)
|
2017-08-09 00:35:23 -04:00
|
|
|
|
{
|
2018-04-23 01:43:48 -04:00
|
|
|
|
int polledPlayerCount = await PollPlayersAsync();
|
|
|
|
|
|
|
|
|
|
if (ConnectionErrors > 0)
|
|
|
|
|
{
|
2018-04-24 18:01:27 -04:00
|
|
|
|
Logger.WriteVerbose($"{loc["MANAGER_CONNECTION_REST"]} {IP}:{Port}");
|
2018-04-23 01:43:48 -04:00
|
|
|
|
Throttled = false;
|
|
|
|
|
}
|
|
|
|
|
ConnectionErrors = 0;
|
|
|
|
|
LastPoll = DateTime.Now;
|
2017-08-09 00:35:23 -04:00
|
|
|
|
}
|
2017-06-12 08:28:08 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-14 00:51:38 -04:00
|
|
|
|
catch (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
|
|
|
|
{
|
2018-04-24 18:01:27 -04:00
|
|
|
|
Logger.WriteError($"{e.Message} {IP}:{Port}, {loc["SERVER_ERROR_POLLING"]}");
|
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
|
|
|
|
{
|
2018-04-08 02:44:42 -04:00
|
|
|
|
foreach (var Plugin in SharedLibraryCore.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
|
|
|
|
|
2018-04-08 02:44:42 -04:00
|
|
|
|
if ((lastCount - playerCountStart).TotalMinutes >= SharedLibraryCore.Helpers.PlayerHistory.UpdateInterval)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2018-04-08 02:44:42 -04:00
|
|
|
|
while (PlayerHistory.Count > ((60 / SharedLibraryCore.Helpers.PlayerHistory.UpdateInterval) * 12)) // 12 times a hour for 12 hours
|
2017-06-12 13:50:00 -04:00
|
|
|
|
PlayerHistory.Dequeue();
|
2018-04-08 02:44:42 -04:00
|
|
|
|
PlayerHistory.Enqueue(new SharedLibraryCore.Helpers.PlayerHistory(ClientNum));
|
2017-05-26 18:49:27 -04:00
|
|
|
|
playerCountStart = DateTime.Now;
|
|
|
|
|
}
|
2015-08-20 01:06:44 -04:00
|
|
|
|
|
2018-03-27 00:54:20 -04:00
|
|
|
|
if (LastMessage.TotalSeconds > Manager.GetApplicationSettings().Configuration().AutoMessagePeriod
|
|
|
|
|
&& BroadcastMessages.Count > 0
|
2018-03-18 22:25:11 -04:00
|
|
|
|
&& 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
|
|
|
|
|
2018-04-08 17:50:58 -04:00
|
|
|
|
if (Manager.ShutdownRequested())
|
2018-02-10 01:26:38 -05:00
|
|
|
|
{
|
2018-04-08 02:44:42 -04:00
|
|
|
|
foreach (var plugin in SharedLibraryCore.Plugins.PluginImporter.ActivePlugins)
|
2018-02-15 23:01:28 -05:00
|
|
|
|
await plugin.OnUnloadAsync();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < Players.Count; i++)
|
|
|
|
|
await RemovePlayer(i);
|
2018-02-10 01:26:38 -05:00
|
|
|
|
}
|
2018-02-07 00:19:06 -05:00
|
|
|
|
return true;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
2017-05-30 17:23:31 -04:00
|
|
|
|
|
2018-04-28 01:22:18 -04:00
|
|
|
|
// this one is ok
|
|
|
|
|
catch (ServerException e)
|
2018-04-15 21:27:43 -04:00
|
|
|
|
{
|
2018-04-28 01:22:18 -04:00
|
|
|
|
if (e is NetworkException)
|
|
|
|
|
{
|
|
|
|
|
Logger.WriteError($"{loc["SERVER_ERROR_COMMUNICATION"]} {IP}:{Port}");
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-15 21:27:43 -04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-30 17:23:31 -04:00
|
|
|
|
catch (Exception E)
|
|
|
|
|
{
|
2018-04-24 18:01:27 -04:00
|
|
|
|
Logger.WriteError($"{loc["SERVER_ERROR_EXCEPTION"]} {IP}:{Port}");
|
2017-05-30 17:23:31 -04:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
|
{
|
2018-04-13 02:32:30 -04:00
|
|
|
|
RconParser = ServerConfig.UseT6MParser ? (IRConParser)new T6MRConParser() : new IW4RConParser();
|
2018-04-23 01:43:48 -04:00
|
|
|
|
if (ServerConfig.UseIW5MParser)
|
|
|
|
|
RconParser = new IW5MRConParser();
|
2018-04-11 18:24:21 -04:00
|
|
|
|
|
2018-04-26 20:19:42 -04:00
|
|
|
|
|
2017-08-08 22:44:52 -04:00
|
|
|
|
var version = await this.GetDvarAsync<string>("version");
|
|
|
|
|
GameName = Utilities.GetGame(version.Value);
|
|
|
|
|
|
2018-04-15 00:26:27 -04:00
|
|
|
|
if (GameName == Game.IW4)
|
|
|
|
|
EventParser = new IW4EventParser();
|
|
|
|
|
else if (GameName == Game.IW5)
|
|
|
|
|
EventParser = new IW5EventParser();
|
2018-04-26 20:19:42 -04:00
|
|
|
|
else if (GameName == Game.T5M)
|
|
|
|
|
EventParser = new T5MEventParser();
|
2018-04-15 00:26:27 -04:00
|
|
|
|
else if (GameName == Game.T6M)
|
|
|
|
|
EventParser = new T6MEventParser();
|
|
|
|
|
else
|
2018-04-25 02:38:59 -04:00
|
|
|
|
EventParser = new IW3EventParser(); // this uses the 'main' folder for log paths
|
2017-08-08 22:44:52 -04:00
|
|
|
|
|
2018-04-26 20:19:42 -04:00
|
|
|
|
if (GameName == Game.UKN)
|
|
|
|
|
Logger.WriteWarning($"Game name not recognized: {version}");
|
|
|
|
|
|
|
|
|
|
var infoResponse = await this.GetInfoAsync();
|
|
|
|
|
// this is normally slow, but I'm only doing it because different games have different prefixes
|
2018-04-28 21:11:13 -04:00
|
|
|
|
var hostname = infoResponse == null ?
|
2018-04-26 20:19:42 -04:00
|
|
|
|
(await this.GetDvarAsync<string>("sv_hostname")).Value :
|
|
|
|
|
infoResponse.Where(kvp => kvp.Key.Contains("hostname")).Select(kvp => kvp.Value).First();
|
2018-04-28 21:11:13 -04:00
|
|
|
|
var mapname = infoResponse == null ?
|
2018-04-26 20:19:42 -04:00
|
|
|
|
(await this.GetDvarAsync<string>("mapname")).Value :
|
|
|
|
|
infoResponse["mapname"];
|
|
|
|
|
int maxplayers = (GameName == Game.IW4) ? // gotta love IW4 idiosyncrasies
|
|
|
|
|
(await this.GetDvarAsync<int>("party_maxplayers")).Value :
|
|
|
|
|
infoResponse == null ?
|
|
|
|
|
(await this.GetDvarAsync<int>("sv_maxclients")).Value :
|
|
|
|
|
Convert.ToInt32(infoResponse["sv_maxclients"]);
|
2018-04-28 21:11:13 -04:00
|
|
|
|
var gametype = infoResponse == null ?
|
2018-04-26 20:19:42 -04:00
|
|
|
|
(await this.GetDvarAsync<string>("g_gametype")).Value :
|
|
|
|
|
infoResponse.Where(kvp => kvp.Key.Contains("gametype")).Select(kvp => kvp.Value).First();
|
2017-05-26 18:49:27 -04:00
|
|
|
|
var basepath = await this.GetDvarAsync<string>("fs_basepath");
|
2018-04-28 21:11:13 -04:00
|
|
|
|
var game = infoResponse == null || !infoResponse.ContainsKey("fs_game") ?
|
2018-04-26 20:19:42 -04:00
|
|
|
|
(await this.GetDvarAsync<string>("fs_game")).Value :
|
|
|
|
|
infoResponse["fs_game"];
|
2017-05-26 18:49:27 -04:00
|
|
|
|
var logfile = await this.GetDvarAsync<string>("g_log");
|
|
|
|
|
var logsync = await this.GetDvarAsync<int>("g_logsync");
|
2017-08-08 22:44:52 -04:00
|
|
|
|
|
2018-04-26 20:19:42 -04:00
|
|
|
|
WorkingDirectory = basepath.Value;
|
|
|
|
|
|
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
|
|
|
|
|
2018-04-15 00:26:27 -04:00
|
|
|
|
catch (DvarException)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2018-04-22 16:04:18 -04:00
|
|
|
|
Website = loc["SERVER_WEBSITE_GENERIC"];
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
2015-08-23 17:58:48 -04:00
|
|
|
|
|
2018-03-14 14:22:04 -04:00
|
|
|
|
InitializeMaps();
|
|
|
|
|
|
2018-04-26 20:19:42 -04:00
|
|
|
|
this.Hostname = hostname.StripColors();
|
|
|
|
|
this.CurrentMap = Maps.Find(m => m.Name == mapname) ?? new Map() { Alias = mapname, Name = mapname };
|
|
|
|
|
this.MaxClients = maxplayers;
|
|
|
|
|
this.FSGame = game;
|
|
|
|
|
this.Gametype = gametype;
|
2015-08-23 17:58:48 -04:00
|
|
|
|
|
2018-04-23 01:43:48 -04:00
|
|
|
|
//wait this.SetDvarAsync("sv_kickbantime", 60);
|
2018-03-13 17:30:22 -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();
|
2018-04-15 00:26:27 -04:00
|
|
|
|
string mainPath = EventParser.GetGameDir();
|
2018-04-13 02:32:30 -04:00
|
|
|
|
#if DEBUG
|
2018-04-28 01:22:18 -04:00
|
|
|
|
basepath.Value = @"\\192.168.88.253\mw2";
|
2018-04-13 02:32:30 -04:00
|
|
|
|
#endif
|
2018-04-23 01:43:48 -04:00
|
|
|
|
string logPath;
|
|
|
|
|
if (GameName == Game.IW5)
|
|
|
|
|
{
|
|
|
|
|
logPath = ServerConfig.ManualLogPath;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-04-26 20:19:42 -04:00
|
|
|
|
logPath = game == string.Empty ?
|
2018-04-23 01:43:48 -04:00
|
|
|
|
$"{basepath.Value.Replace('\\', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{mainPath}{Path.DirectorySeparatorChar}{logfile.Value}" :
|
2018-04-26 20:19:42 -04:00
|
|
|
|
$"{basepath.Value.Replace('\\', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{game.Replace('/', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{logfile.Value}";
|
2018-04-23 01:43:48 -04:00
|
|
|
|
}
|
2015-08-22 02:04:30 -04:00
|
|
|
|
|
2018-04-26 02:13:04 -04:00
|
|
|
|
|
2018-04-15 00:26:27 -04:00
|
|
|
|
// hopefully fix wine drive name mangling
|
|
|
|
|
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
|
|
{
|
|
|
|
|
logPath = Regex.Replace(logPath, @"[A-Z]:", "");
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
if (!File.Exists(logPath))
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2018-04-24 18:01:27 -04:00
|
|
|
|
Logger.WriteError($"{logPath} {loc["SERVER_ERROR_DNE"]}");
|
2017-06-12 13:50:00 -04:00
|
|
|
|
#if !DEBUG
|
2018-04-24 18:01:27 -04:00
|
|
|
|
throw new ServerException($"{loc["SERVER_ERROR_LOG"]} {logPath}");
|
2017-06-12 13:50:00 -04:00
|
|
|
|
#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
|
|
|
|
{
|
2018-04-26 20:19:42 -04:00
|
|
|
|
LogEvent = new GameLogEvent(this, logPath, logfile.Value);
|
2018-04-26 02:13:04 -04:00
|
|
|
|
}
|
2018-04-28 21:11:13 -04:00
|
|
|
|
|
2018-04-07 15:49:00 -04:00
|
|
|
|
Logger.WriteInfo($"Log file is {logPath}");
|
2018-03-27 20:27:01 -04:00
|
|
|
|
#if DEBUG
|
2018-04-26 02:13:04 -04:00
|
|
|
|
// LogFile = new RemoteFile("https://raidmax.org/IW4MAdmin/getlog.php");
|
2018-04-07 15:49:00 -04:00
|
|
|
|
#else
|
2018-04-22 16:04:18 -04:00
|
|
|
|
await Broadcast(loc["BROADCAST_ONLINE"]);
|
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
|
|
|
|
|
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
|
|
|
|
{
|
2018-02-17 15:06:37 -05:00
|
|
|
|
var ingameClient = Manager.GetActiveClients()
|
|
|
|
|
.FirstOrDefault(c => c.ClientId == Target.ClientId);
|
2017-11-29 19:35:50 -05:00
|
|
|
|
|
|
|
|
|
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)
|
2018-04-13 02:32:30 -04:00
|
|
|
|
{
|
2018-04-22 16:04:18 -04:00
|
|
|
|
await Target.Kick(loc["SERVER_WARNLIMT_REACHED"], (await Manager.GetClientService().Get(1)).AsPlayer());
|
2018-04-13 02:32:30 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-11-25 20:29:58 -05:00
|
|
|
|
|
2017-11-29 19:35:50 -05:00
|
|
|
|
Target.Warnings++;
|
2018-04-22 16:04:18 -04:00
|
|
|
|
String Message = $"^1{loc["SERVER_WARNING"]} ^7[^3{Target.Warnings}^7]: ^3{Target.Name}^7, {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
|
|
|
|
{
|
2018-02-17 15:06:37 -05:00
|
|
|
|
var ingameClient = Manager.GetActiveClients()
|
|
|
|
|
.FirstOrDefault(c => c.ClientId == Target.ClientId);
|
2017-11-29 19:35:50 -05:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2018-02-21 20:29:23 -05:00
|
|
|
|
#if !DEBUG
|
2017-11-29 19:35:50 -05:00
|
|
|
|
else
|
2018-04-13 02:32:30 -04:00
|
|
|
|
{
|
2018-04-22 16:04:18 -04:00
|
|
|
|
string formattedKick = String.Format(RconParser.GetCommandPrefixes().Kick, Target.ClientNumber, $"{loc["SERVER_KICK_TEXT"]} - ^5{Reason}^7");
|
2018-04-13 02:32:30 -04:00
|
|
|
|
await Target.CurrentServer.ExecuteCommandAsync(formattedKick);
|
|
|
|
|
}
|
2018-02-21 20:29:23 -05:00
|
|
|
|
#endif
|
2017-11-29 19:35:50 -05:00
|
|
|
|
|
|
|
|
|
#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)
|
|
|
|
|
{
|
2018-02-21 20:29:23 -05:00
|
|
|
|
var ingameClient = Manager.GetActiveClients()
|
|
|
|
|
.FirstOrDefault(c => c.ClientId == Target.ClientId);
|
2017-11-29 19:35:50 -05:00
|
|
|
|
|
|
|
|
|
if (ingameClient != null)
|
|
|
|
|
{
|
|
|
|
|
await TempBan(Reason, length, ingameClient, Origin);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-03-27 00:54:20 -04:00
|
|
|
|
#if !DEBUG
|
2017-11-29 19:35:50 -05:00
|
|
|
|
else
|
2018-04-13 02:32:30 -04:00
|
|
|
|
{
|
2018-04-22 16:04:18 -04:00
|
|
|
|
string formattedKick = String.Format(RconParser.GetCommandPrefixes().Kick, Target.ClientNumber, $"^7{loc["SERVER_TB_TEXT"]}- ^5{Reason}");
|
2018-04-13 02:32:30 -04:00
|
|
|
|
await Target.CurrentServer.ExecuteCommandAsync(formattedKick);
|
|
|
|
|
}
|
2018-03-27 00:54:20 -04:00
|
|
|
|
#else
|
2017-11-29 19:35:50 -05:00
|
|
|
|
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;
|
2018-03-27 00:54:20 -04:00
|
|
|
|
#if !DEBUG
|
2018-04-22 16:04:18 -04:00
|
|
|
|
string formattedString = String.Format(RconParser.GetCommandPrefixes().Kick, Target.ClientNumber, $"{loc["SERVER_BAN_TEXT"]} - ^5{Message} ^7({loc["SERVER_BAN_APPEAL"]} {Website})^7");
|
2018-04-13 02:32:30 -04:00
|
|
|
|
await Target.CurrentServer.ExecuteCommandAsync(formattedString);
|
2018-04-07 15:49:00 -04:00
|
|
|
|
#else
|
2017-11-29 19:35:50 -05:00
|
|
|
|
await Target.CurrentServer.RemovePlayer(Target.ClientNumber);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
Penalty newPenalty = new Penalty()
|
|
|
|
|
{
|
|
|
|
|
Type = Penalty.PenaltyType.Ban,
|
2018-02-17 01:13:38 -05:00
|
|
|
|
Expires = DateTime.MaxValue,
|
2017-11-25 20:29:58 -05:00
|
|
|
|
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);
|
2018-04-28 17:39:45 -04:00
|
|
|
|
// prevent them from logging in again
|
|
|
|
|
Manager.GetPrivilegedClients().Remove(Target.ClientId);
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-17 01:13:38 -05:00
|
|
|
|
override public async Task Unban(string reason, Player Target, Player Origin)
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2018-02-17 01:13:38 -05:00
|
|
|
|
var unbanPenalty = new Penalty()
|
|
|
|
|
{
|
|
|
|
|
Type = Penalty.PenaltyType.Unban,
|
|
|
|
|
Expires = DateTime.UtcNow,
|
|
|
|
|
Offender = Target,
|
|
|
|
|
Offense = reason,
|
|
|
|
|
Punisher = Origin,
|
|
|
|
|
When = DateTime.UtcNow,
|
|
|
|
|
Active = true,
|
|
|
|
|
Link = Target.AliasLink
|
|
|
|
|
};
|
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
await Manager.GetPenaltyService().RemoveActivePenalties(Target.AliasLink.AliasLinkId);
|
2018-04-26 16:26:03 -04:00
|
|
|
|
await Manager.GetPenaltyService().Create(unbanPenalty);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
override public void InitializeTokens()
|
2015-03-13 19:40:16 -04:00
|
|
|
|
{
|
2018-04-08 02:44:42 -04:00
|
|
|
|
Manager.GetMessageTokens().Add(new SharedLibraryCore.Helpers.MessageToken("TOTALPLAYERS", Manager.GetClientService().GetTotalClientsAsync().Result.ToString));
|
2018-04-09 15:17:10 -04:00
|
|
|
|
Manager.GetMessageTokens().Add(new SharedLibraryCore.Helpers.MessageToken("VERSION", Application.Program.Version.ToString));
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
}
|