2018-11-05 22:01:29 -05:00
|
|
|
|
using IW4MAdmin.Application.EventParsers;
|
|
|
|
|
using IW4MAdmin.Application.IO;
|
|
|
|
|
using IW4MAdmin.Application.RconParsers;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
using SharedLibraryCore;
|
2018-11-05 22:01:29 -05:00
|
|
|
|
using SharedLibraryCore.Configuration;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
using SharedLibraryCore.Database.Models;
|
|
|
|
|
using SharedLibraryCore.Dtos;
|
2018-04-16 16:31:14 -04:00
|
|
|
|
using SharedLibraryCore.Exceptions;
|
2018-11-05 22:01:29 -05:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2018-08-07 14:43:09 -04:00
|
|
|
|
using SharedLibraryCore.Localization;
|
2018-11-05 22:01:29 -05:00
|
|
|
|
using SharedLibraryCore.Objects;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
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-08-03 18:10:20 -04:00
|
|
|
|
private static readonly Index loc = Utilities.CurrentLocalization.LocalizationIndex;
|
2018-08-28 17:32:59 -04:00
|
|
|
|
private GameLogEventDetection LogEvent;
|
2018-10-25 09:14:39 -04:00
|
|
|
|
public int Id { get; private set; }
|
2018-04-26 02:13:04 -04:00
|
|
|
|
|
2018-06-30 21:55:16 -04:00
|
|
|
|
public IW4MServer(IManager mgr, ServerConfiguration cfg) : base(mgr, cfg)
|
|
|
|
|
{
|
|
|
|
|
}
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2018-11-27 19:31:48 -05:00
|
|
|
|
//public override int EndPoint
|
|
|
|
|
//{
|
|
|
|
|
// // hack: my laziness
|
|
|
|
|
// if ($"{IP}:{Port.ToString()}" == "66.150.121.184:28965")
|
|
|
|
|
// {
|
|
|
|
|
// return 886229536;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// if ($"{IP}:{Port.ToString()}" == "66.150.121.184:28960")
|
|
|
|
|
// {
|
|
|
|
|
// return 1645744423;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// if ($"{IP}:{Port.ToString()}" == "66.150.121.184:28970")
|
|
|
|
|
// {
|
|
|
|
|
// return 1645809959;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// if (Id == 0)
|
|
|
|
|
// {
|
|
|
|
|
// Id = HashCode.Combine(IP, Port);
|
|
|
|
|
// Id = Id < 0 ? Math.Abs(Id) : Id;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// return Id;
|
|
|
|
|
//}
|
2018-02-14 14:01:26 -05:00
|
|
|
|
|
2018-11-05 22:01:29 -05:00
|
|
|
|
override public async Task OnClientConnected(EFClient clientFromLog)
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2018-11-05 22:01:29 -05:00
|
|
|
|
Logger.WriteDebug($"Client slot #{clientFromLog.ClientNumber} now reserved");
|
2017-08-23 18:29:48 -04:00
|
|
|
|
|
2015-03-08 17:20:10 -04:00
|
|
|
|
try
|
|
|
|
|
{
|
2018-11-05 22:01:29 -05:00
|
|
|
|
EFClient client = await Manager.GetClientService().GetUnique(clientFromLog.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
|
|
|
|
{
|
2018-11-05 22:01:29 -05:00
|
|
|
|
Logger.WriteDebug($"Client {clientFromLog} first time connecting");
|
|
|
|
|
client = await Manager.GetClientService().Create(clientFromLog);
|
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-11-25 21:00:36 -05:00
|
|
|
|
// this is only a temporary version until the IPAddress is transmitted
|
|
|
|
|
client.CurrentAlias.Active = false;
|
|
|
|
|
client.CurrentAlias.Name = clientFromLog.Name;
|
2018-08-07 14:43:09 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-05 22:01:29 -05:00
|
|
|
|
Logger.WriteInfo($"Client {client} connected...");
|
2018-07-04 22:09:42 -04:00
|
|
|
|
|
2018-02-17 15:06:37 -05:00
|
|
|
|
// Do the player specific stuff
|
2018-11-05 22:01:29 -05:00
|
|
|
|
client.ClientNumber = clientFromLog.ClientNumber;
|
|
|
|
|
client.IsBot = clientFromLog.IsBot;
|
|
|
|
|
client.Score = clientFromLog.Score;
|
|
|
|
|
client.Ping = clientFromLog.Ping;
|
|
|
|
|
client.CurrentServer = this;
|
2015-04-10 00:02:12 -04:00
|
|
|
|
|
2018-11-05 22:01:29 -05:00
|
|
|
|
Clients[client.ClientNumber] = client;
|
2015-03-23 23:01:05 -04:00
|
|
|
|
|
2018-11-25 21:00:36 -05:00
|
|
|
|
// this only happens if the preconnect event occurred from RCon polling
|
|
|
|
|
if (clientFromLog.IPAddress.HasValue)
|
2018-11-07 21:30:11 -05:00
|
|
|
|
{
|
|
|
|
|
await client.OnJoin(clientFromLog.IPAddress);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-25 21:00:36 -05:00
|
|
|
|
client.OnConnect();
|
|
|
|
|
|
2018-11-05 22:01:29 -05:00
|
|
|
|
client.State = EFClient.ClientState.Connected;
|
2018-11-07 21:30:11 -05:00
|
|
|
|
#if DEBUG == true
|
|
|
|
|
Logger.WriteDebug($"End PreConnect for {client}");
|
|
|
|
|
#endif
|
|
|
|
|
var e = new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Origin = client,
|
|
|
|
|
Owner = this,
|
|
|
|
|
Type = GameEvent.EventType.Connect
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Manager.GetEventHandler().AddEvent(e);
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
2017-05-28 21:54:46 -04:00
|
|
|
|
|
2018-10-02 13:39:08 -04:00
|
|
|
|
catch (Exception ex)
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2018-11-07 21:30:11 -05:00
|
|
|
|
Logger.WriteError($"{loc["SERVER_ERROR_ADDPLAYER"]} {clientFromLog}");
|
|
|
|
|
Logger.WriteError(ex.GetExceptionInfo());
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-07 21:30:11 -05:00
|
|
|
|
override public async Task OnClientDisconnected(EFClient client)
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2018-11-07 21:30:11 -05:00
|
|
|
|
Logger.WriteInfo($"Client {client} [{client.State.ToString().ToLower()}] disconnecting...");
|
|
|
|
|
await client.OnDisconnect();
|
|
|
|
|
Clients[client.ClientNumber] = null;
|
|
|
|
|
#if DEBUG == true
|
|
|
|
|
Logger.WriteDebug($"End PreDisconnect for {client}");
|
|
|
|
|
#endif
|
|
|
|
|
var e = new GameEvent()
|
2015-03-16 16:40:30 -04:00
|
|
|
|
{
|
2018-11-07 21:30:11 -05:00
|
|
|
|
Origin = client,
|
|
|
|
|
Owner = this,
|
|
|
|
|
Type = GameEvent.EventType.Disconnect
|
|
|
|
|
};
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
2018-11-07 21:30:11 -05:00
|
|
|
|
Manager.GetEventHandler().AddEvent(e);
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
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;
|
2018-09-29 15:52:22 -04:00
|
|
|
|
|
2018-09-23 20:45:54 -04:00
|
|
|
|
if (!await ProcessEvent(E))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-07-15 17:11:29 -04:00
|
|
|
|
|
2018-05-10 01:34:29 -04:00
|
|
|
|
Command C = null;
|
|
|
|
|
if (E.Type == GameEvent.EventType.Command)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2018-06-30 21:55:16 -04:00
|
|
|
|
C = await SharedLibraryCore.Commands.CommandProcessing.ValidateCommand(E);
|
2018-05-10 01:34:29 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (CommandException e)
|
|
|
|
|
{
|
|
|
|
|
Logger.WriteInfo(e.Message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (C != null)
|
|
|
|
|
{
|
|
|
|
|
E.Extra = C;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-26 20:20:47 -04:00
|
|
|
|
foreach (var plugin 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-08-26 20:20:47 -04:00
|
|
|
|
await plugin.OnEventAsync(E, this);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
2018-04-26 02:13:04 -04:00
|
|
|
|
catch (AuthorizationException e)
|
|
|
|
|
{
|
2018-09-29 15:52:22 -04:00
|
|
|
|
E.Origin.Tell($"{loc["COMMAND_NOTAUTHORIZED"]} - {e.Message}");
|
2018-04-26 02:13:04 -04:00
|
|
|
|
canExecuteCommand = false;
|
|
|
|
|
}
|
2017-05-26 18:49:27 -04:00
|
|
|
|
catch (Exception Except)
|
|
|
|
|
{
|
2018-08-26 20:20:47 -04:00
|
|
|
|
Logger.WriteError($"{loc["SERVER_PLUGIN_ERROR"]} [{plugin.Name}]");
|
2018-09-23 20:45:54 -04:00
|
|
|
|
Logger.WriteDebug(Except.GetExceptionInfo());
|
2015-08-20 15:23:13 -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-11-05 22:01:29 -05:00
|
|
|
|
E.Origin?.Level == EFClient.Permission.Console))
|
2018-04-26 02:13:04 -04:00
|
|
|
|
{
|
2018-10-06 12:47:14 -04:00
|
|
|
|
await (((Command)E.Extra).ExecuteAsync(E));
|
2018-04-26 02:13:04 -04:00
|
|
|
|
}
|
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>
|
2018-09-23 20:45:54 -04:00
|
|
|
|
override protected async Task<bool> ProcessEvent(GameEvent E)
|
2018-04-26 02:13:04 -04:00
|
|
|
|
{
|
2018-11-25 21:00:36 -05:00
|
|
|
|
if (E.Type == GameEvent.EventType.ChangePermission)
|
2018-04-28 21:11:13 -04:00
|
|
|
|
{
|
2018-11-25 21:00:36 -05:00
|
|
|
|
if (!E.Target.IsPrivileged())
|
|
|
|
|
{
|
|
|
|
|
// remove banned or demoted privileged user
|
|
|
|
|
Manager.GetPrivilegedClients().Remove(E.Target.ClientId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Manager.GetPrivilegedClients()[E.Target.ClientId] = E.Target;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-27 18:07:54 -04:00
|
|
|
|
|
2018-11-25 21:00:36 -05:00
|
|
|
|
else if (E.Type == GameEvent.EventType.PreConnect)
|
|
|
|
|
{
|
|
|
|
|
if (Clients[E.Origin.ClientNumber] == null)
|
2018-04-28 21:11:13 -04:00
|
|
|
|
{
|
2018-11-07 21:30:11 -05:00
|
|
|
|
#if DEBUG == true
|
|
|
|
|
Logger.WriteDebug($"Begin PreConnect for {E.Origin}");
|
|
|
|
|
#endif
|
|
|
|
|
await OnClientConnected(E.Origin);
|
2018-04-28 21:11:13 -04:00
|
|
|
|
|
2018-11-07 21:30:11 -05:00
|
|
|
|
ChatHistory.Add(new ChatInfo()
|
|
|
|
|
{
|
|
|
|
|
Name = E.Origin.Name,
|
|
|
|
|
Message = "CONNECTED",
|
|
|
|
|
Time = DateTime.UtcNow
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (E.Origin.Level > EFClient.Permission.Moderator)
|
|
|
|
|
{
|
|
|
|
|
E.Origin.Tell(string.Format(loc["SERVER_REPORT_COUNT"], E.Owner.Reports.Count));
|
|
|
|
|
}
|
2018-09-29 15:52:22 -04:00
|
|
|
|
}
|
2018-04-28 21:11:13 -04:00
|
|
|
|
|
2018-11-07 21:30:11 -05:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-06-30 21:55:16 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 13:39:08 -04:00
|
|
|
|
else if (E.Type == GameEvent.EventType.Flag)
|
|
|
|
|
{
|
|
|
|
|
Penalty newPenalty = new Penalty()
|
|
|
|
|
{
|
|
|
|
|
Type = Penalty.PenaltyType.Flag,
|
|
|
|
|
Expires = DateTime.UtcNow,
|
|
|
|
|
Offender = E.Target,
|
|
|
|
|
Offense = E.Data,
|
|
|
|
|
Punisher = E.Origin,
|
|
|
|
|
Active = true,
|
|
|
|
|
When = DateTime.UtcNow,
|
|
|
|
|
Link = E.Target.AliasLink
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var addedPenalty = await Manager.GetPenaltyService().Create(newPenalty);
|
|
|
|
|
E.Target.ReceivedPenalties.Add(addedPenalty);
|
|
|
|
|
|
|
|
|
|
await Manager.GetClientService().Update(E.Target);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (E.Type == GameEvent.EventType.Unflag)
|
|
|
|
|
{
|
|
|
|
|
await Manager.GetClientService().Update(E.Target);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (E.Type == GameEvent.EventType.Report)
|
|
|
|
|
{
|
|
|
|
|
this.Reports.Add(new Report()
|
|
|
|
|
{
|
|
|
|
|
Origin = E.Origin,
|
|
|
|
|
Target = E.Target,
|
|
|
|
|
Reason = E.Data
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (E.Type == GameEvent.EventType.TempBan)
|
|
|
|
|
{
|
|
|
|
|
await TempBan(E.Data, (TimeSpan)E.Extra, E.Target, E.Origin); ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (E.Type == GameEvent.EventType.Ban)
|
|
|
|
|
{
|
|
|
|
|
await Ban(E.Data, E.Target, E.Origin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (E.Type == GameEvent.EventType.Unban)
|
|
|
|
|
{
|
|
|
|
|
await Unban(E.Data, E.Target, E.Origin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (E.Type == GameEvent.EventType.Kick)
|
|
|
|
|
{
|
|
|
|
|
await Kick(E.Data, E.Target, E.Origin);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-03 22:20:49 -04:00
|
|
|
|
else if (E.Type == GameEvent.EventType.Warn)
|
|
|
|
|
{
|
|
|
|
|
await Warn(E.Data, E.Target, E.Origin);
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-30 21:55:16 -04:00
|
|
|
|
else if (E.Type == GameEvent.EventType.Quit)
|
|
|
|
|
{
|
2018-11-07 21:30:11 -05:00
|
|
|
|
var origin = GetClientsAsList().FirstOrDefault(_client => _client.NetworkId.Equals(E.Origin));
|
2018-09-07 23:29:42 -04:00
|
|
|
|
|
2018-11-07 21:30:11 -05:00
|
|
|
|
if (origin != null)
|
2018-09-07 23:29:42 -04:00
|
|
|
|
{
|
|
|
|
|
var e = new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Type = GameEvent.EventType.Disconnect,
|
|
|
|
|
Origin = origin,
|
|
|
|
|
Owner = this
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Manager.GetEventHandler().AddEvent(e);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-07 21:30:11 -05:00
|
|
|
|
else
|
2018-09-07 23:29:42 -04:00
|
|
|
|
{
|
2018-11-07 21:30:11 -05:00
|
|
|
|
return false;
|
2018-09-07 23:29:42 -04:00
|
|
|
|
}
|
2018-04-26 02:13:04 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-07 21:30:11 -05:00
|
|
|
|
else if (E.Type == GameEvent.EventType.PreDisconnect)
|
2018-04-26 02:13:04 -04:00
|
|
|
|
{
|
2018-11-07 21:30:11 -05:00
|
|
|
|
// predisconnect comes from minimal rcon polled players and minimal log players
|
|
|
|
|
// so we need to disconnect the "full" version of the client
|
|
|
|
|
var client = GetClientsAsList().FirstOrDefault(_client => _client.Equals(E.Origin));
|
|
|
|
|
|
|
|
|
|
if (client != null)
|
2018-04-26 02:13:04 -04:00
|
|
|
|
{
|
2018-11-07 21:30:11 -05:00
|
|
|
|
#if DEBUG == true
|
|
|
|
|
Logger.WriteDebug($"Begin PreDisconnect for {client}");
|
|
|
|
|
#endif
|
|
|
|
|
ChatHistory.Add(new ChatInfo()
|
|
|
|
|
{
|
|
|
|
|
Name = client.Name,
|
|
|
|
|
Message = "DISCONNECTED",
|
|
|
|
|
Time = DateTime.UtcNow
|
|
|
|
|
});
|
2018-06-30 21:55:16 -04:00
|
|
|
|
|
2018-11-07 21:30:11 -05:00
|
|
|
|
await OnClientDisconnected(client);
|
|
|
|
|
}
|
2018-08-28 17:32:59 -04:00
|
|
|
|
|
2018-11-07 21:30:11 -05:00
|
|
|
|
else
|
2018-08-28 17:32:59 -04:00
|
|
|
|
{
|
2018-11-07 21:30:11 -05:00
|
|
|
|
return false;
|
2018-08-28 17:32:59 -04:00
|
|
|
|
}
|
2018-04-26 02:13:04 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-07 21:30:11 -05:00
|
|
|
|
else if (E.Type == GameEvent.EventType.Update)
|
|
|
|
|
{
|
|
|
|
|
#if DEBUG == true
|
|
|
|
|
Logger.WriteDebug($"Begin Update for {E.Origin}");
|
|
|
|
|
#endif
|
|
|
|
|
await OnClientUpdate(E.Origin);
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-14 13:55:10 -04:00
|
|
|
|
if (E.Type == GameEvent.EventType.Say)
|
2018-04-26 02:13:04 -04:00
|
|
|
|
{
|
2018-05-10 01:34:29 -04:00
|
|
|
|
E.Data = E.Data.StripColors();
|
2018-04-26 02:13:04 -04:00
|
|
|
|
|
2018-05-14 13:55:10 -04:00
|
|
|
|
if (E.Data.Length > 0)
|
2018-04-26 02:13:04 -04:00
|
|
|
|
{
|
2018-05-14 13:55:10 -04:00
|
|
|
|
// this may be a fix for a hard to reproduce null exception error
|
|
|
|
|
lock (ChatHistory)
|
|
|
|
|
{
|
|
|
|
|
ChatHistory.Add(new ChatInfo()
|
|
|
|
|
{
|
2018-05-16 00:57:37 -04:00
|
|
|
|
Name = E.Origin.Name,
|
|
|
|
|
Message = E.Data ?? "NULL",
|
2018-05-14 13:55:10 -04:00
|
|
|
|
Time = DateTime.UtcNow
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-26 02:13:04 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
2018-05-03 01:25:49 -04:00
|
|
|
|
if (dict == null)
|
|
|
|
|
{
|
|
|
|
|
Logger.WriteWarning("Map change event response doesn't have any data");
|
|
|
|
|
}
|
2018-04-26 02:13:04 -04:00
|
|
|
|
|
2018-05-03 01:25:49 -04:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Gametype = dict["gametype"].StripColors();
|
|
|
|
|
Hostname = dict["hostname"]?.StripColors();
|
|
|
|
|
|
|
|
|
|
string mapname = dict["mapname"]?.StripColors() ?? CurrentMap.Name;
|
|
|
|
|
CurrentMap = Maps.Find(m => m.Name == mapname) ?? new Map() { Alias = mapname, Name = mapname };
|
|
|
|
|
}
|
2018-04-26 02:13:04 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var dict = (Dictionary<string, string>)E.Extra;
|
|
|
|
|
Gametype = dict["g_gametype"].StripColors();
|
|
|
|
|
Hostname = dict["sv_hostname"].StripColors();
|
|
|
|
|
|
|
|
|
|
string mapname = dict["mapname"].StripColors();
|
2018-05-10 01:34:29 -04:00
|
|
|
|
CurrentMap = Maps.Find(m => m.Name == mapname) ?? new Map()
|
|
|
|
|
{
|
|
|
|
|
Alias = mapname,
|
|
|
|
|
Name = mapname
|
|
|
|
|
};
|
2018-04-26 02:13:04 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (E.Type == GameEvent.EventType.MapEnd)
|
|
|
|
|
{
|
|
|
|
|
Logger.WriteInfo("Game ending...");
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-04 00:22:10 -04:00
|
|
|
|
if (E.Type == GameEvent.EventType.Tell)
|
|
|
|
|
{
|
|
|
|
|
await Tell(E.Message, E.Target);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (E.Type == GameEvent.EventType.Broadcast)
|
|
|
|
|
{
|
2018-10-25 09:14:39 -04:00
|
|
|
|
#if DEBUG == false
|
2018-05-04 00:22:10 -04:00
|
|
|
|
// this is a little ugly but I don't want to change the abstract class
|
2018-08-31 23:35:51 -04:00
|
|
|
|
if (E.Data != null)
|
2018-06-30 21:55:16 -04:00
|
|
|
|
{
|
2018-08-31 23:35:51 -04:00
|
|
|
|
await E.Owner.ExecuteCommandAsync(E.Data);
|
2018-06-30 21:55:16 -04:00
|
|
|
|
}
|
2018-10-25 09:14:39 -04:00
|
|
|
|
#endif
|
2018-05-04 00:22:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-26 02:13:04 -04:00
|
|
|
|
while (ChatHistory.Count > Math.Ceiling((double)ClientNum / 2))
|
2018-11-05 22:01:29 -05:00
|
|
|
|
{
|
2018-04-26 02:13:04 -04:00
|
|
|
|
ChatHistory.RemoveAt(0);
|
2018-11-05 22:01:29 -05:00
|
|
|
|
}
|
2018-04-26 02:13:04 -04:00
|
|
|
|
|
|
|
|
|
// the last client hasn't fully disconnected yet
|
|
|
|
|
// so there will still be at least 1 client left
|
|
|
|
|
if (ClientNum < 2)
|
2018-11-05 22:01:29 -05:00
|
|
|
|
{
|
2018-04-26 02:13:04 -04:00
|
|
|
|
ChatHistory.Clear();
|
2018-11-05 22:01:29 -05:00
|
|
|
|
}
|
2018-09-23 20:45:54 -04:00
|
|
|
|
|
|
|
|
|
return true;
|
2018-04-26 02:13:04 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-07 21:30:11 -05:00
|
|
|
|
private Task OnClientUpdate(EFClient origin)
|
|
|
|
|
{
|
|
|
|
|
var client = Clients[origin.ClientNumber];
|
|
|
|
|
|
|
|
|
|
if (client != null)
|
|
|
|
|
{
|
|
|
|
|
client.Ping = origin.Ping;
|
|
|
|
|
client.Score = origin.Score;
|
|
|
|
|
|
2018-11-25 21:00:36 -05:00
|
|
|
|
// update their IP if it hasn't been set yet
|
|
|
|
|
if (!client.IPAddress.HasValue)
|
2018-11-07 21:30:11 -05:00
|
|
|
|
{
|
|
|
|
|
return client.OnJoin(origin.IPAddress);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-27 18:07:54 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// lists the connecting and disconnecting clients via RCon response
|
|
|
|
|
/// array index 0 = connecting clients
|
|
|
|
|
/// array index 1 = disconnecting clients
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2018-11-05 22:01:29 -05:00
|
|
|
|
async Task<IList<EFClient>[]> PollPlayersAsync()
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2018-08-27 18:07:54 -04:00
|
|
|
|
#if DEBUG
|
2018-03-06 02:22:19 -05:00
|
|
|
|
var now = DateTime.Now;
|
2018-08-27 18:07:54 -04:00
|
|
|
|
#endif
|
2018-11-05 22:01:29 -05:00
|
|
|
|
var currentClients = GetClientsAsList();
|
2018-10-13 19:49:08 -04:00
|
|
|
|
var polledClients = (await this.GetStatusAsync()).AsEnumerable();
|
|
|
|
|
if (this.Manager.GetApplicationSettings().Configuration().IgnoreBots)
|
|
|
|
|
{
|
|
|
|
|
polledClients = polledClients.Where(c => !c.IsBot);
|
|
|
|
|
}
|
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
|
|
|
|
|
2018-08-27 18:07:54 -04:00
|
|
|
|
var disconnectingClients = currentClients.Except(polledClients);
|
2018-11-07 21:30:11 -05:00
|
|
|
|
var connectingClients = polledClients.Except(currentClients);
|
2018-11-25 21:00:36 -05:00
|
|
|
|
var updatedClients = polledClients.Except(connectingClients).Except(disconnectingClients);
|
2018-06-30 21:55:16 -04:00
|
|
|
|
|
2018-11-07 21:30:11 -05:00
|
|
|
|
return new List<EFClient>[]
|
|
|
|
|
{
|
|
|
|
|
connectingClients.ToList(),
|
|
|
|
|
disconnectingClients.ToList(),
|
|
|
|
|
updatedClients.ToList()
|
|
|
|
|
};
|
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;
|
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
|
|
|
|
{
|
2017-05-30 17:23:31 -04:00
|
|
|
|
try
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2018-11-07 21:30:11 -05:00
|
|
|
|
#region SHUTDOWN
|
2018-04-29 16:44:04 -04:00
|
|
|
|
if (Manager.ShutdownRequested())
|
|
|
|
|
{
|
2018-11-07 21:30:11 -05:00
|
|
|
|
foreach (var client in GetClientsAsList())
|
|
|
|
|
{
|
|
|
|
|
var e = new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Type = GameEvent.EventType.PreDisconnect,
|
|
|
|
|
Origin = client,
|
|
|
|
|
Owner = this,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Manager.GetEventHandler().AddEvent(e);
|
|
|
|
|
await e.WaitAsync();
|
|
|
|
|
}
|
2018-05-10 01:34:29 -04:00
|
|
|
|
|
|
|
|
|
foreach (var plugin in SharedLibraryCore.Plugins.PluginImporter.ActivePlugins)
|
2018-11-05 22:01:29 -05:00
|
|
|
|
{
|
2018-05-10 01:34:29 -04:00
|
|
|
|
await plugin.OnUnloadAsync();
|
2018-11-05 22:01:29 -05:00
|
|
|
|
}
|
2018-04-29 16:44:04 -04:00
|
|
|
|
|
2018-11-07 21:30:11 -05:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
2017-06-12 08:28:08 -04:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2018-08-27 18:07:54 -04:00
|
|
|
|
var polledClients = await PollPlayersAsync();
|
2018-09-06 14:25:58 -04:00
|
|
|
|
var waiterList = new List<GameEvent>();
|
2018-08-27 18:07:54 -04:00
|
|
|
|
|
|
|
|
|
foreach (var disconnectingClient in polledClients[1])
|
|
|
|
|
{
|
2018-11-05 22:01:29 -05:00
|
|
|
|
if (disconnectingClient.State == EFClient.ClientState.Disconnecting)
|
2018-08-27 18:07:54 -04:00
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var e = new GameEvent()
|
|
|
|
|
{
|
2018-11-07 21:30:11 -05:00
|
|
|
|
Type = GameEvent.EventType.PreDisconnect,
|
2018-08-27 18:07:54 -04:00
|
|
|
|
Origin = disconnectingClient,
|
|
|
|
|
Owner = this
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Manager.GetEventHandler().AddEvent(e);
|
|
|
|
|
// wait until the disconnect event is complete
|
|
|
|
|
// because we don't want to try to fill up a slot that's not empty yet
|
2018-09-06 14:25:58 -04:00
|
|
|
|
waiterList.Add(e);
|
2018-08-27 18:07:54 -04:00
|
|
|
|
}
|
|
|
|
|
// wait for all the disconnect tasks to finish
|
2018-10-25 09:14:39 -04:00
|
|
|
|
await Task.WhenAll(waiterList.Select(e => e.WaitAsync(10 * 1000)));
|
2018-08-27 18:07:54 -04:00
|
|
|
|
|
|
|
|
|
waiterList.Clear();
|
|
|
|
|
// this are our new connecting clients
|
|
|
|
|
foreach (var client in polledClients[0])
|
|
|
|
|
{
|
2018-11-07 21:30:11 -05:00
|
|
|
|
var e = new GameEvent()
|
2018-09-02 17:59:27 -04:00
|
|
|
|
{
|
2018-11-07 21:30:11 -05:00
|
|
|
|
Type = GameEvent.EventType.PreConnect,
|
|
|
|
|
Origin = client,
|
|
|
|
|
Owner = this
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Manager.GetEventHandler().AddEvent(e);
|
|
|
|
|
waiterList.Add(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// wait for all the connect tasks to finish
|
|
|
|
|
await Task.WhenAll(waiterList.Select(e => e.WaitAsync(10 * 1000)));
|
2018-09-02 17:59:27 -04:00
|
|
|
|
|
2018-11-07 21:30:11 -05:00
|
|
|
|
waiterList.Clear();
|
|
|
|
|
// these are the clients that have updated
|
|
|
|
|
foreach (var client in polledClients[2])
|
|
|
|
|
{
|
2018-08-27 18:07:54 -04:00
|
|
|
|
var e = new GameEvent()
|
|
|
|
|
{
|
2018-11-07 21:30:11 -05:00
|
|
|
|
Type = GameEvent.EventType.Update,
|
2018-08-27 18:07:54 -04:00
|
|
|
|
Origin = client,
|
|
|
|
|
Owner = this
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Manager.GetEventHandler().AddEvent(e);
|
2018-09-06 14:25:58 -04:00
|
|
|
|
waiterList.Add(e);
|
2018-08-27 18:07:54 -04:00
|
|
|
|
}
|
2018-04-23 01:43:48 -04:00
|
|
|
|
|
2018-10-25 09:14:39 -04:00
|
|
|
|
await Task.WhenAll(waiterList.Select(e => e.WaitAsync(10 * 1000)));
|
2018-08-28 17:32:59 -04:00
|
|
|
|
|
2018-04-29 16:44:04 -04:00
|
|
|
|
if (ConnectionErrors > 0)
|
|
|
|
|
{
|
|
|
|
|
Logger.WriteVerbose($"{loc["MANAGER_CONNECTION_REST"]} {IP}:{Port}");
|
|
|
|
|
Throttled = false;
|
2017-08-09 00:35:23 -04:00
|
|
|
|
}
|
2018-11-07 21:30:11 -05:00
|
|
|
|
|
2018-04-29 16:44:04 -04:00
|
|
|
|
ConnectionErrors = 0;
|
|
|
|
|
LastPoll = DateTime.Now;
|
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++;
|
2018-10-25 09:14:39 -04:00
|
|
|
|
if (ConnectionErrors == 3)
|
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;
|
|
|
|
|
|
2018-04-29 16:44:04 -04:00
|
|
|
|
// update the player history
|
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-11-05 22:01:29 -05:00
|
|
|
|
while (ClientHistory.Count > ((60 / SharedLibraryCore.Helpers.PlayerHistory.UpdateInterval) * 12)) // 12 times a hour for 12 hours
|
|
|
|
|
{
|
|
|
|
|
ClientHistory.Dequeue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientHistory.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-04-29 16:44:04 -04:00
|
|
|
|
// send out broadcast messages
|
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
|
|
|
|
{
|
2018-05-05 16:36:26 -04:00
|
|
|
|
string[] messages = this.ProcessMessageToken(Manager.GetMessageTokens(), BroadcastMessages[NextMessage]).Split(Environment.NewLine);
|
|
|
|
|
|
2018-05-10 01:34:29 -04:00
|
|
|
|
foreach (string message in messages)
|
2018-09-29 15:52:22 -04:00
|
|
|
|
{
|
|
|
|
|
Broadcast(message);
|
|
|
|
|
}
|
2018-05-05 16:36:26 -04:00
|
|
|
|
|
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-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-09-23 20:45:54 -04:00
|
|
|
|
Logger.WriteDebug(e.GetExceptionInfo());
|
2018-04-28 01:22:18 -04:00
|
|
|
|
}
|
|
|
|
|
|
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}");
|
2018-09-23 20:45:54 -04:00
|
|
|
|
Logger.WriteDebug(E.GetExceptionInfo());
|
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-06-05 17:31:36 -04:00
|
|
|
|
RconParser = ServerConfig.UseT6MParser ?
|
|
|
|
|
(IRConParser)new T6MRConParser() :
|
|
|
|
|
new IW3RConParser();
|
|
|
|
|
|
2018-04-23 01:43:48 -04:00
|
|
|
|
if (ServerConfig.UseIW5MParser)
|
2018-11-05 22:01:29 -05:00
|
|
|
|
{
|
2018-04-23 01:43:48 -04:00
|
|
|
|
RconParser = new IW5MRConParser();
|
2018-11-05 22:01:29 -05:00
|
|
|
|
}
|
2018-04-11 18:24:21 -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)
|
2018-05-14 13:55:10 -04:00
|
|
|
|
{
|
2018-04-15 00:26:27 -04:00
|
|
|
|
EventParser = new IW4EventParser();
|
2018-05-14 13:55:10 -04:00
|
|
|
|
RconParser = new IW4RConParser();
|
|
|
|
|
}
|
2018-04-15 00:26:27 -04:00
|
|
|
|
else if (GameName == Game.IW5)
|
2018-11-05 22:01:29 -05:00
|
|
|
|
{
|
2018-04-15 00:26:27 -04:00
|
|
|
|
EventParser = new IW5EventParser();
|
2018-11-05 22:01:29 -05:00
|
|
|
|
}
|
2018-04-26 20:19:42 -04:00
|
|
|
|
else if (GameName == Game.T5M)
|
2018-11-05 22:01:29 -05:00
|
|
|
|
{
|
2018-04-26 20:19:42 -04:00
|
|
|
|
EventParser = new T5MEventParser();
|
2018-11-05 22:01:29 -05:00
|
|
|
|
}
|
2018-04-15 00:26:27 -04:00
|
|
|
|
else if (GameName == Game.T6M)
|
2018-11-05 22:01:29 -05:00
|
|
|
|
{
|
2018-04-15 00:26:27 -04:00
|
|
|
|
EventParser = new T6MEventParser();
|
2018-11-05 22:01:29 -05:00
|
|
|
|
}
|
2018-04-15 00:26:27 -04:00
|
|
|
|
else
|
2018-11-05 22:01:29 -05:00
|
|
|
|
{
|
2018-04-25 02:38:59 -04:00
|
|
|
|
EventParser = new IW3EventParser(); // this uses the 'main' folder for log paths
|
2018-11-05 22:01:29 -05:00
|
|
|
|
}
|
2017-08-08 22:44:52 -04:00
|
|
|
|
|
2018-04-26 20:19:42 -04:00
|
|
|
|
if (GameName == Game.UKN)
|
2018-11-05 22:01:29 -05:00
|
|
|
|
{
|
2018-04-26 20:19:42 -04:00
|
|
|
|
Logger.WriteWarning($"Game name not recognized: {version}");
|
2018-11-05 22:01:29 -05:00
|
|
|
|
}
|
2018-04-26 20:19:42 -04:00
|
|
|
|
|
|
|
|
|
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");
|
2018-11-25 21:00:36 -05:00
|
|
|
|
var ip = await this.GetDvarAsync<string>("net_ip");
|
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;
|
2018-11-27 19:31:48 -05:00
|
|
|
|
this.IP = ip.Value == "localhost" ? ServerConfig.IPAddress : ip.Value;
|
2018-11-25 21:00:36 -05: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");
|
2018-09-29 15:52:22 -04:00
|
|
|
|
}
|
2017-11-02 12:49:45 -04:00
|
|
|
|
|
2018-09-08 18:29:30 -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-10-13 19:49:08 -04:00
|
|
|
|
// basepath.Value = @"D:\";
|
2018-04-13 02:32:30 -04:00
|
|
|
|
#endif
|
2018-09-06 14:25:58 -04:00
|
|
|
|
string logPath = string.Empty;
|
|
|
|
|
|
|
|
|
|
LogPath = game == string.Empty ?
|
|
|
|
|
$"{basepath.Value.Replace('\\', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{mainPath}{Path.DirectorySeparatorChar}{logfile.Value}" :
|
|
|
|
|
$"{basepath.Value.Replace('\\', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{game.Replace('/', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{logfile.Value}";
|
|
|
|
|
|
2018-08-28 17:32:59 -04:00
|
|
|
|
if (GameName == Game.IW5 || ServerConfig.ManualLogPath?.Length > 0)
|
2018-04-23 01:43:48 -04:00
|
|
|
|
{
|
|
|
|
|
logPath = ServerConfig.ManualLogPath;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-09-06 14:25:58 -04:00
|
|
|
|
logPath = LogPath;
|
2018-04-23 01:43:48 -04:00
|
|
|
|
}
|
2015-08-22 02:04:30 -04:00
|
|
|
|
|
2018-04-15 00:26:27 -04:00
|
|
|
|
// hopefully fix wine drive name mangling
|
|
|
|
|
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
|
|
{
|
2018-09-08 21:20:11 -04:00
|
|
|
|
logPath = Regex.Replace($"{Path.DirectorySeparatorChar}{LogPath}", @"[A-Z]:/", "");
|
2018-04-15 00:26:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-08 21:20:11 -04:00
|
|
|
|
if (!File.Exists(logPath) && !logPath.StartsWith("http"))
|
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}");
|
2018-10-10 20:22:08 -04:00
|
|
|
|
#else
|
2018-08-28 17:32:59 -04:00
|
|
|
|
LogEvent = new GameLogEventDetection(this, logPath, logfile.Value);
|
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-08-28 17:32:59 -04:00
|
|
|
|
LogEvent = new GameLogEventDetection(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-08-30 21:53:00 -04:00
|
|
|
|
|
2018-09-04 13:40:29 -04:00
|
|
|
|
_ = Task.Run(() => LogEvent.PollForChanges());
|
2018-05-08 00:58:46 -04:00
|
|
|
|
#if !DEBUG
|
2018-09-29 15:52:22 -04:00
|
|
|
|
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
|
|
|
|
|
2018-11-05 22:01:29 -05:00
|
|
|
|
protected override async Task Warn(String Reason, EFClient Target, EFClient 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-10-07 22:34:30 -04:00
|
|
|
|
Target.Kick(loc["SERVER_WARNLIMT_REACHED"], Utilities.IW4MAdminClient(this));
|
2018-04-13 02:32:30 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-11-25 20:29:58 -05:00
|
|
|
|
|
2018-09-29 15:52:22 -04:00
|
|
|
|
String message = $"^1{loc["SERVER_WARNING"]} ^7[^3{Target.Warnings}^7]: ^3{Target.Name}^7, {Reason}";
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2018-11-05 22:01:29 -05:00
|
|
|
|
protected override async Task Kick(String Reason, EFClient Target, EFClient 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
|
2018-11-07 21:30:11 -05:00
|
|
|
|
await Target.CurrentServer.OnClientDisconnected(Target);
|
2017-11-29 19:35:50 -05:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
var newPenalty = new Penalty()
|
|
|
|
|
{
|
|
|
|
|
Type = Penalty.PenaltyType.Kick,
|
|
|
|
|
Expires = DateTime.UtcNow,
|
|
|
|
|
Offender = Target,
|
|
|
|
|
Offense = Reason,
|
|
|
|
|
Punisher = Origin,
|
|
|
|
|
When = DateTime.UtcNow,
|
|
|
|
|
Link = Target.AliasLink
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await Manager.GetPenaltyService().Create(newPenalty);
|
2016-01-15 17:15:39 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-05 22:01:29 -05:00
|
|
|
|
protected override async Task TempBan(String Reason, TimeSpan length, EFClient Target, EFClient 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
|
2018-11-07 21:30:11 -05:00
|
|
|
|
await Target.CurrentServer.OnClientDisconnected(Target);
|
2017-11-29 19:35:50 -05:00
|
|
|
|
#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
|
|
|
|
|
2018-11-05 22:01:29 -05:00
|
|
|
|
override protected async Task Ban(String Message, EFClient Target, EFClient Origin)
|
2017-05-26 18:49:27 -04: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-11-05 22:01:29 -05:00
|
|
|
|
EFClient ingameClient = null;
|
2017-11-29 19:35:50 -05:00
|
|
|
|
|
|
|
|
|
ingameClient = Manager.GetServers()
|
2018-11-05 22:01:29 -05:00
|
|
|
|
.Select(s => s.GetClientsAsList())
|
2017-11-29 19:35:50 -05:00
|
|
|
|
.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.
|
2018-11-05 22:01:29 -05:00
|
|
|
|
Target.Level = EFClient.Permission.Banned;
|
2018-08-22 21:25:34 -04:00
|
|
|
|
|
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
|
2018-11-07 21:30:11 -05:00
|
|
|
|
await Target.CurrentServer.OnClientDisconnected(Target);
|
2017-11-29 19:35:50 -05:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
Penalty newPenalty = new Penalty()
|
|
|
|
|
{
|
|
|
|
|
Type = Penalty.PenaltyType.Ban,
|
2018-10-15 20:51:04 -04:00
|
|
|
|
Expires = null,
|
2017-11-25 20:29:58 -05:00
|
|
|
|
Offender = Target,
|
|
|
|
|
Offense = Message,
|
|
|
|
|
Punisher = Origin,
|
|
|
|
|
Active = true,
|
|
|
|
|
When = DateTime.UtcNow,
|
2018-05-30 21:50:20 -04:00
|
|
|
|
Link = Target.AliasLink,
|
|
|
|
|
AutomatedOffense = Origin.AdministeredPenalties.FirstOrDefault()?.AutomatedOffense
|
2017-11-25 20:29:58 -05:00
|
|
|
|
};
|
|
|
|
|
|
2017-11-29 19:35:50 -05:00
|
|
|
|
await Manager.GetPenaltyService().Create(newPenalty);
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-05 22:01:29 -05:00
|
|
|
|
override public async Task Unban(string reason, EFClient Target, EFClient 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,
|
2018-10-15 20:51:04 -04:00
|
|
|
|
Expires = null,
|
2018-02-17 01:13:38 -05:00
|
|
|
|
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-05-05 16:36:26 -04:00
|
|
|
|
Manager.GetMessageTokens().Add(new SharedLibraryCore.Helpers.MessageToken("TOTALPLAYERS", (Server s) => Manager.GetClientService().GetTotalClientsAsync().Result.ToString()));
|
|
|
|
|
Manager.GetMessageTokens().Add(new SharedLibraryCore.Helpers.MessageToken("VERSION", (Server s) => Application.Program.Version.ToString()));
|
2018-06-02 22:21:01 -04:00
|
|
|
|
Manager.GetMessageTokens().Add(new SharedLibraryCore.Helpers.MessageToken("NEXTMAP", (Server s) => SharedLibraryCore.Commands.CNextMap.GetNextMap(s).Result));
|
2018-06-26 21:17:24 -04:00
|
|
|
|
Manager.GetMessageTokens().Add(new SharedLibraryCore.Helpers.MessageToken("ADMINS", (Server s) => SharedLibraryCore.Commands.CListAdmins.OnlineAdmins(s)));
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
}
|