2018-11-25 21:00:36 -05:00
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using SharedLibraryCore.Database.Models;
|
|
|
|
|
using SharedLibraryCore.Exceptions;
|
|
|
|
|
using SharedLibraryCore.Interfaces;
|
|
|
|
|
using SharedLibraryCore.RCon;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2018-04-11 18:24:21 -04:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text.RegularExpressions;
|
2022-02-28 21:44:30 -05:00
|
|
|
|
using System.Threading;
|
2018-04-11 18:24:21 -04:00
|
|
|
|
using System.Threading.Tasks;
|
2021-03-22 12:09:25 -04:00
|
|
|
|
using Data.Models;
|
2022-06-01 12:25:11 -04:00
|
|
|
|
using IW4MAdmin.Application.Misc;
|
2020-11-11 18:31:26 -05:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2019-02-05 19:02:45 -05:00
|
|
|
|
using static SharedLibraryCore.Server;
|
2020-11-11 18:31:26 -05:00
|
|
|
|
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
2018-04-11 18:24:21 -04:00
|
|
|
|
|
2021-06-03 11:51:03 -04:00
|
|
|
|
namespace IW4MAdmin.Application.RConParsers
|
2018-04-11 18:24:21 -04:00
|
|
|
|
{
|
2019-06-24 12:01:34 -04:00
|
|
|
|
public class BaseRConParser : IRConParser
|
2018-04-11 18:24:21 -04:00
|
|
|
|
{
|
2020-11-11 18:31:26 -05:00
|
|
|
|
private readonly ILogger _logger;
|
2022-06-12 11:09:56 -04:00
|
|
|
|
private static string _botIpIndicator = "00000000.";
|
2020-11-11 18:31:26 -05:00
|
|
|
|
|
|
|
|
|
public BaseRConParser(ILogger<BaseRConParser> logger, IParserRegexFactory parserRegexFactory)
|
2018-04-13 02:32:30 -04:00
|
|
|
|
{
|
2020-11-11 18:31:26 -05:00
|
|
|
|
_logger = logger;
|
2020-04-01 15:11:56 -04:00
|
|
|
|
Configuration = new DynamicRConParserConfiguration(parserRegexFactory)
|
2019-01-26 21:33:37 -05:00
|
|
|
|
{
|
|
|
|
|
CommandPrefixes = new CommandPrefix()
|
|
|
|
|
{
|
2019-02-05 12:14:43 -05:00
|
|
|
|
Tell = "tell {0} {1}",
|
|
|
|
|
Say = "say {0}",
|
2019-01-26 21:33:37 -05:00
|
|
|
|
Kick = "clientkick {0} \"{1}\"",
|
|
|
|
|
Ban = "clientkick {0} \"{1}\"",
|
2019-02-01 20:49:25 -05:00
|
|
|
|
TempBan = "tempbanclient {0} \"{1}\"",
|
2019-02-03 21:47:05 -05:00
|
|
|
|
RConCommand = "ÿÿÿÿrcon {0} {1}",
|
|
|
|
|
RConGetDvar = "ÿÿÿÿrcon {0} {1}",
|
|
|
|
|
RConSetDvar = "ÿÿÿÿrcon {0} set {1}",
|
2019-02-01 20:49:25 -05:00
|
|
|
|
RConGetStatus = "ÿÿÿÿgetstatus",
|
|
|
|
|
RConGetInfo = "ÿÿÿÿgetinfo",
|
|
|
|
|
RConResponse = "ÿÿÿÿprint",
|
2020-04-18 18:48:49 -04:00
|
|
|
|
RconGetInfoResponseHeader = "ÿÿÿÿinfoResponse"
|
2019-01-26 21:33:37 -05:00
|
|
|
|
},
|
2020-01-13 17:51:16 -05:00
|
|
|
|
ServerNotRunningResponse = "Server is not running."
|
2019-01-26 21:33:37 -05:00
|
|
|
|
};
|
2019-01-27 19:41:54 -05:00
|
|
|
|
|
2019-11-15 15:50:20 -05:00
|
|
|
|
Configuration.Status.Pattern = @"^ *([0-9]+) +-?([0-9]+) +((?:[A-Z]+|[0-9]+)) +((?:[a-z]|[0-9]){8,32}|(?:[a-z]|[0-9]){8,32}|bot[0-9]+|(?:[0-9]+)) *(.{0,32}) +([0-9]+) +(\d+\.\d+\.\d+.\d+\:-*\d{1,5}|0+.0+:-*\d{1,5}|loopback|unknown) +(-*[0-9]+) +([0-9]+) *$";
|
2019-02-02 20:40:37 -05:00
|
|
|
|
Configuration.Status.AddMapping(ParserRegex.GroupType.RConClientNumber, 1);
|
|
|
|
|
Configuration.Status.AddMapping(ParserRegex.GroupType.RConScore, 2);
|
|
|
|
|
Configuration.Status.AddMapping(ParserRegex.GroupType.RConPing, 3);
|
|
|
|
|
Configuration.Status.AddMapping(ParserRegex.GroupType.RConNetworkId, 4);
|
|
|
|
|
Configuration.Status.AddMapping(ParserRegex.GroupType.RConName, 5);
|
|
|
|
|
Configuration.Status.AddMapping(ParserRegex.GroupType.RConIpAddress, 7);
|
2019-02-01 20:49:25 -05:00
|
|
|
|
|
2019-02-05 12:14:43 -05:00
|
|
|
|
Configuration.Dvar.Pattern = "^\"(.+)\" is: \"(.+)?\" default: \"(.+)?\"\n(?:latched: \"(.+)?\"\n)? *(.+)$";
|
2019-02-02 20:40:37 -05:00
|
|
|
|
Configuration.Dvar.AddMapping(ParserRegex.GroupType.RConDvarName, 1);
|
|
|
|
|
Configuration.Dvar.AddMapping(ParserRegex.GroupType.RConDvarValue, 2);
|
|
|
|
|
Configuration.Dvar.AddMapping(ParserRegex.GroupType.RConDvarDefaultValue, 3);
|
|
|
|
|
Configuration.Dvar.AddMapping(ParserRegex.GroupType.RConDvarLatchedValue, 4);
|
|
|
|
|
Configuration.Dvar.AddMapping(ParserRegex.GroupType.RConDvarDomain, 5);
|
2021-06-03 11:51:03 -04:00
|
|
|
|
Configuration.Dvar.AddMapping(ParserRegex.GroupType.AdditionalGroup, int.MaxValue);
|
2019-11-18 15:02:35 -05:00
|
|
|
|
|
2020-04-17 16:05:16 -04:00
|
|
|
|
Configuration.StatusHeader.Pattern = "num +score +ping +guid +name +lastmsg +address +qport +rate *";
|
2020-08-05 10:30:02 -04:00
|
|
|
|
Configuration.GametypeStatus.Pattern = "";
|
2019-11-18 15:02:35 -05:00
|
|
|
|
Configuration.MapStatus.Pattern = @"map: (([a-z]|_|\d)+)";
|
|
|
|
|
Configuration.MapStatus.AddMapping(ParserRegex.GroupType.RConStatusMap, 1);
|
2020-06-16 18:16:12 -04:00
|
|
|
|
|
|
|
|
|
if (!Configuration.DefaultDvarValues.ContainsKey("mapname"))
|
|
|
|
|
{
|
|
|
|
|
Configuration.DefaultDvarValues.Add("mapname", "Unknown");
|
|
|
|
|
}
|
2019-01-26 21:33:37 -05:00
|
|
|
|
}
|
2018-04-29 16:44:04 -04:00
|
|
|
|
|
2019-01-26 21:33:37 -05:00
|
|
|
|
public IRConParserConfiguration Configuration { get; set; }
|
2019-06-24 12:01:34 -04:00
|
|
|
|
public virtual string Version { get; set; } = "CoD";
|
2019-02-05 19:02:45 -05:00
|
|
|
|
public Game GameName { get; set; } = Game.COD;
|
|
|
|
|
public bool CanGenerateLogPath { get; set; } = true;
|
2020-01-21 19:08:18 -05:00
|
|
|
|
public string Name { get; set; } = "Call of Duty";
|
2021-06-03 11:51:03 -04:00
|
|
|
|
public string RConEngine { get; set; } = "COD";
|
2021-06-07 17:58:36 -04:00
|
|
|
|
public bool IsOneLog { get; set; }
|
2019-02-02 19:54:30 -05:00
|
|
|
|
|
2022-02-28 21:44:30 -05:00
|
|
|
|
public async Task<string[]> ExecuteCommandAsync(IRConConnection connection, string command, CancellationToken token = default)
|
2018-04-11 18:24:21 -04:00
|
|
|
|
{
|
2022-04-27 16:36:58 -04:00
|
|
|
|
command = command.FormatMessageForEngine(Configuration?.ColorCodeMapping);
|
2022-02-28 21:44:30 -05:00
|
|
|
|
var response = await connection.SendQueryAsync(StaticHelpers.QueryType.COMMAND, command, token);
|
2021-06-07 17:58:36 -04:00
|
|
|
|
return response.Where(item => item != Configuration.CommandPrefixes.RConResponse).ToArray();
|
2018-04-11 18:24:21 -04:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-28 21:44:30 -05:00
|
|
|
|
public async Task<Dvar<T>> GetDvarAsync<T>(IRConConnection connection, string dvarName, T fallbackValue = default, CancellationToken token = default)
|
2018-04-11 18:24:21 -04:00
|
|
|
|
{
|
2020-11-07 11:40:58 -05:00
|
|
|
|
string[] lineSplit;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2022-02-28 21:44:30 -05:00
|
|
|
|
lineSplit = await connection.SendQueryAsync(StaticHelpers.QueryType.GET_DVAR, dvarName, token);
|
2020-11-07 11:40:58 -05:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
if (fallbackValue == null)
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-28 21:44:30 -05:00
|
|
|
|
lineSplit = Array.Empty<string>();
|
2020-11-07 11:40:58 -05:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-28 21:44:30 -05:00
|
|
|
|
var response = string.Join('\n', lineSplit).TrimEnd('\0');
|
2019-02-01 20:49:25 -05:00
|
|
|
|
var match = Regex.Match(response, Configuration.Dvar.Pattern);
|
2018-04-11 18:24:21 -04:00
|
|
|
|
|
2020-04-17 16:05:16 -04:00
|
|
|
|
if (response.Contains("Unknown command") ||
|
2019-05-03 21:13:51 -04:00
|
|
|
|
!match.Success)
|
2018-04-11 18:24:21 -04:00
|
|
|
|
{
|
2020-04-17 16:05:16 -04:00
|
|
|
|
if (fallbackValue != null)
|
|
|
|
|
{
|
2022-02-28 21:44:30 -05:00
|
|
|
|
return new Dvar<T>
|
2020-04-17 16:05:16 -04:00
|
|
|
|
{
|
|
|
|
|
Name = dvarName,
|
|
|
|
|
Value = fallbackValue
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-03 21:13:51 -04:00
|
|
|
|
throw new DvarException(Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_DVAR"].FormatExt(dvarName));
|
2018-04-11 18:24:21 -04:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-28 21:44:30 -05:00
|
|
|
|
var value = match.Groups[Configuration.Dvar.GroupMapping[ParserRegex.GroupType.RConDvarValue]].Value;
|
|
|
|
|
var defaultValue = match.Groups[Configuration.Dvar.GroupMapping[ParserRegex.GroupType.RConDvarDefaultValue]].Value;
|
|
|
|
|
var latchedValue = match.Groups[Configuration.Dvar.GroupMapping[ParserRegex.GroupType.RConDvarLatchedValue]].Value;
|
2019-08-01 10:37:33 -04:00
|
|
|
|
|
2022-02-28 21:44:30 -05:00
|
|
|
|
string RemoveTrailingColorCode(string input) => Regex.Replace(input, @"\^7$", "");
|
2019-08-01 10:37:33 -04:00
|
|
|
|
|
2022-02-28 21:44:30 -05:00
|
|
|
|
value = RemoveTrailingColorCode(value);
|
|
|
|
|
defaultValue = RemoveTrailingColorCode(defaultValue);
|
|
|
|
|
latchedValue = RemoveTrailingColorCode(latchedValue);
|
2018-04-11 18:24:21 -04:00
|
|
|
|
|
2022-02-28 21:44:30 -05:00
|
|
|
|
return new Dvar<T>
|
2018-04-11 18:24:21 -04:00
|
|
|
|
{
|
2021-06-03 11:51:03 -04:00
|
|
|
|
Name = dvarName,
|
2019-05-03 21:13:51 -04:00
|
|
|
|
Value = string.IsNullOrEmpty(value) ? default : (T)Convert.ChangeType(value, typeof(T)),
|
|
|
|
|
DefaultValue = string.IsNullOrEmpty(defaultValue) ? default : (T)Convert.ChangeType(defaultValue, typeof(T)),
|
|
|
|
|
LatchedValue = string.IsNullOrEmpty(latchedValue) ? default : (T)Convert.ChangeType(latchedValue, typeof(T)),
|
2019-08-01 10:37:33 -04:00
|
|
|
|
Domain = match.Groups[Configuration.Dvar.GroupMapping[ParserRegex.GroupType.RConDvarDomain]].Value
|
2018-04-11 18:24:21 -04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-01 12:25:11 -04:00
|
|
|
|
public void BeginGetDvar(IRConConnection connection, string dvarName, AsyncCallback callback, CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
GetDvarAsync<string>(connection, dvarName, token: token).ContinueWith(action =>
|
|
|
|
|
{
|
|
|
|
|
if (action.Exception is null)
|
|
|
|
|
{
|
|
|
|
|
callback?.Invoke(new AsyncResult
|
|
|
|
|
{
|
|
|
|
|
IsCompleted = true,
|
|
|
|
|
AsyncState = (true, action.Result.Value)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
callback?.Invoke(new AsyncResult
|
|
|
|
|
{
|
|
|
|
|
IsCompleted = true,
|
|
|
|
|
AsyncState = (false, (string)null)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, token);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-28 21:44:30 -05:00
|
|
|
|
public virtual async Task<IStatusResponse> GetStatusAsync(IRConConnection connection, CancellationToken token = default)
|
2018-04-11 18:24:21 -04:00
|
|
|
|
{
|
2022-02-28 21:44:30 -05:00
|
|
|
|
var response = await connection.SendQueryAsync(StaticHelpers.QueryType.COMMAND_STATUS, "status", token);
|
|
|
|
|
|
|
|
|
|
_logger.LogDebug("Status Response {Response}", string.Join(Environment.NewLine, response));
|
|
|
|
|
|
2021-06-03 11:51:03 -04:00
|
|
|
|
return new StatusResponse
|
|
|
|
|
{
|
|
|
|
|
Clients = ClientsFromStatus(response).ToArray(),
|
|
|
|
|
Map = GetValueFromStatus<string>(response, ParserRegex.GroupType.RConStatusMap, Configuration.MapStatus.Pattern),
|
|
|
|
|
GameType = GetValueFromStatus<string>(response, ParserRegex.GroupType.RConStatusGametype, Configuration.GametypeStatus.Pattern),
|
|
|
|
|
Hostname = GetValueFromStatus<string>(response, ParserRegex.GroupType.RConStatusHostname, Configuration.HostnameStatus.Pattern),
|
|
|
|
|
MaxClients = GetValueFromStatus<int?>(response, ParserRegex.GroupType.RConStatusMaxPlayers, Configuration.MaxPlayersStatus.Pattern)
|
|
|
|
|
};
|
2019-11-18 15:02:35 -05:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-03 11:51:03 -04:00
|
|
|
|
private T GetValueFromStatus<T>(IEnumerable<string> response, ParserRegex.GroupType groupType, string groupPattern)
|
2019-11-18 15:02:35 -05:00
|
|
|
|
{
|
2021-06-03 11:51:03 -04:00
|
|
|
|
if (string.IsNullOrEmpty(groupPattern))
|
|
|
|
|
{
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string value = null;
|
2019-11-18 15:02:35 -05:00
|
|
|
|
foreach (var line in response)
|
|
|
|
|
{
|
2021-06-03 11:51:03 -04:00
|
|
|
|
var regex = Regex.Match(line, groupPattern);
|
2019-11-18 15:02:35 -05:00
|
|
|
|
if (regex.Success)
|
|
|
|
|
{
|
2021-06-03 11:51:03 -04:00
|
|
|
|
value = regex.Groups[Configuration.MapStatus.GroupMapping[groupType]].ToString();
|
2019-11-18 15:02:35 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-03 11:51:03 -04:00
|
|
|
|
if (value == null)
|
2020-08-05 10:30:02 -04:00
|
|
|
|
{
|
2021-06-03 11:51:03 -04:00
|
|
|
|
return default;
|
2020-08-05 10:30:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-03 11:51:03 -04:00
|
|
|
|
if (typeof(T) == typeof(int?))
|
2020-08-05 10:30:02 -04:00
|
|
|
|
{
|
2021-06-03 11:51:03 -04:00
|
|
|
|
return (T)Convert.ChangeType(int.Parse(value), Nullable.GetUnderlyingType(typeof(T)));
|
2020-08-05 10:30:02 -04:00
|
|
|
|
}
|
2021-06-03 11:51:03 -04:00
|
|
|
|
|
|
|
|
|
return (T)Convert.ChangeType(value, typeof(T));
|
2020-08-05 10:30:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-28 21:44:30 -05:00
|
|
|
|
public async Task<bool> SetDvarAsync(IRConConnection connection, string dvarName, object dvarValue, CancellationToken token = default)
|
2018-04-11 18:24:21 -04:00
|
|
|
|
{
|
2022-02-28 21:44:30 -05:00
|
|
|
|
var dvarString = (dvarValue is string str)
|
2020-04-01 15:11:56 -04:00
|
|
|
|
? $"{dvarName} \"{str}\""
|
2021-06-03 11:51:03 -04:00
|
|
|
|
: $"{dvarName} {dvarValue}";
|
2020-04-01 15:11:56 -04:00
|
|
|
|
|
2022-02-28 21:44:30 -05:00
|
|
|
|
return (await connection.SendQueryAsync(StaticHelpers.QueryType.SET_DVAR, dvarString, token)).Length > 0;
|
2018-04-11 18:24:21 -04:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-01 12:25:11 -04:00
|
|
|
|
public void BeginSetDvar(IRConConnection connection, string dvarName, object dvarValue, AsyncCallback callback,
|
|
|
|
|
CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
SetDvarAsync(connection, dvarName, dvarValue, token).ContinueWith(action =>
|
|
|
|
|
{
|
|
|
|
|
if (action.Exception is null)
|
|
|
|
|
{
|
|
|
|
|
callback?.Invoke(new AsyncResult
|
|
|
|
|
{
|
|
|
|
|
IsCompleted = true,
|
|
|
|
|
AsyncState = true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
callback?.Invoke(new AsyncResult
|
|
|
|
|
{
|
|
|
|
|
IsCompleted = true,
|
|
|
|
|
AsyncState = false
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, token);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-05 22:01:29 -05:00
|
|
|
|
private List<EFClient> ClientsFromStatus(string[] Status)
|
2018-04-11 18:24:21 -04:00
|
|
|
|
{
|
2018-11-05 22:01:29 -05:00
|
|
|
|
List<EFClient> StatusPlayers = new List<EFClient>();
|
2018-04-11 18:24:21 -04:00
|
|
|
|
|
2020-04-17 16:05:16 -04:00
|
|
|
|
bool parsedHeader = false;
|
2019-04-02 21:20:37 -04:00
|
|
|
|
foreach (string statusLine in Status)
|
2018-04-11 18:24:21 -04:00
|
|
|
|
{
|
2019-04-02 21:20:37 -04:00
|
|
|
|
string responseLine = statusLine.Trim();
|
2018-04-11 18:24:21 -04:00
|
|
|
|
|
2020-04-17 16:05:16 -04:00
|
|
|
|
if (Configuration.StatusHeader.PatternMatcher.Match(responseLine).Success)
|
|
|
|
|
{
|
|
|
|
|
parsedHeader = true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2018-05-03 01:25:49 -04:00
|
|
|
|
|
2020-04-17 16:05:16 -04:00
|
|
|
|
var match = Configuration.Status.PatternMatcher.Match(responseLine);
|
|
|
|
|
|
|
|
|
|
if (match.Success)
|
2018-04-11 18:24:21 -04:00
|
|
|
|
{
|
2020-12-14 22:10:50 -05:00
|
|
|
|
if (match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConPing]] == "ZMBI")
|
2020-11-14 19:24:51 -05:00
|
|
|
|
{
|
|
|
|
|
_logger.LogDebug("Ignoring detected client {client} because they are zombie state", string.Join(",", match.Values));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-16 09:53:50 -04:00
|
|
|
|
var clientNumber = int.Parse(match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConClientNumber]]);
|
|
|
|
|
var score = 0;
|
|
|
|
|
|
|
|
|
|
if (Configuration.Status.GroupMapping[ParserRegex.GroupType.RConScore] > 0)
|
|
|
|
|
{
|
|
|
|
|
score = int.Parse(match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConScore]]);
|
|
|
|
|
}
|
2018-04-29 16:44:04 -04:00
|
|
|
|
|
2021-06-16 09:53:50 -04:00
|
|
|
|
var ping = 999;
|
2018-04-29 16:44:04 -04:00
|
|
|
|
|
|
|
|
|
// their state can be CNCT, ZMBI etc
|
2020-04-17 16:05:16 -04:00
|
|
|
|
if (match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConPing]].Length <= 3)
|
2018-04-29 16:44:04 -04:00
|
|
|
|
{
|
2020-04-17 16:05:16 -04:00
|
|
|
|
ping = int.Parse(match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConPing]]);
|
2018-04-29 16:44:04 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-02 23:33:38 -04:00
|
|
|
|
long networkId;
|
2021-06-16 09:53:50 -04:00
|
|
|
|
var name = match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConName]].TrimNewLine();
|
2020-09-21 16:30:42 -04:00
|
|
|
|
string networkIdString;
|
2022-06-12 11:09:56 -04:00
|
|
|
|
|
2020-12-14 22:10:50 -05:00
|
|
|
|
var ip = match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConIpAddress]].Split(':')[0].ConvertToIP();
|
2020-05-04 17:50:02 -04:00
|
|
|
|
|
2022-06-12 11:09:56 -04:00
|
|
|
|
if (match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConIpAddress]]
|
|
|
|
|
.Contains(_botIpIndicator))
|
|
|
|
|
{
|
|
|
|
|
ip = System.Net.IPAddress.Broadcast.ToString().ConvertToIP();
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-02 23:33:38 -04:00
|
|
|
|
try
|
|
|
|
|
{
|
2020-09-21 16:30:42 -04:00
|
|
|
|
networkIdString = match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConNetworkId]];
|
2020-05-04 17:50:02 -04:00
|
|
|
|
|
2020-12-14 22:10:50 -05:00
|
|
|
|
networkId = networkIdString.IsBotGuid() || (ip == null && ping == 999) ?
|
2020-05-04 17:50:02 -04:00
|
|
|
|
name.GenerateGuidFromString() :
|
|
|
|
|
networkIdString.ConvertGuidToLong(Configuration.GuidNumberStyle);
|
2019-05-02 23:33:38 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (FormatException)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-15 20:37:34 -04:00
|
|
|
|
var client = new EFClient
|
2018-04-11 18:24:21 -04:00
|
|
|
|
{
|
2022-06-15 20:37:34 -04:00
|
|
|
|
CurrentAlias = new EFAlias
|
2018-11-25 21:00:36 -05:00
|
|
|
|
{
|
2019-05-29 17:55:35 -04:00
|
|
|
|
Name = name,
|
|
|
|
|
IPAddress = ip
|
2018-11-25 21:00:36 -05:00
|
|
|
|
},
|
2018-04-29 16:44:04 -04:00
|
|
|
|
NetworkId = networkId,
|
|
|
|
|
ClientNumber = clientNumber,
|
|
|
|
|
Ping = ping,
|
2018-04-21 18:18:20 -04:00
|
|
|
|
Score = score,
|
2018-11-05 22:01:29 -05:00
|
|
|
|
State = EFClient.ClientState.Connecting
|
2018-04-11 18:24:21 -04:00
|
|
|
|
};
|
2018-12-16 22:16:56 -05:00
|
|
|
|
|
2020-09-21 16:30:42 -04:00
|
|
|
|
client.SetAdditionalProperty("BotGuid", networkIdString);
|
2021-06-03 14:21:08 -04:00
|
|
|
|
|
|
|
|
|
if (Configuration.Status.GroupMapping.ContainsKey(ParserRegex.GroupType.AdditionalGroup))
|
2021-06-03 11:51:03 -04:00
|
|
|
|
{
|
2021-06-03 14:21:08 -04:00
|
|
|
|
var additionalGroupIndex =
|
|
|
|
|
Configuration.Status.GroupMapping[ParserRegex.GroupType.AdditionalGroup];
|
|
|
|
|
|
|
|
|
|
if (match.Values.Length > additionalGroupIndex)
|
|
|
|
|
{
|
|
|
|
|
client.SetAdditionalProperty("ConnectionClientId", match.Values[additionalGroupIndex]);
|
|
|
|
|
}
|
2021-06-03 11:51:03 -04:00
|
|
|
|
}
|
2020-09-21 16:30:42 -04:00
|
|
|
|
|
2018-12-17 14:45:16 -05:00
|
|
|
|
StatusPlayers.Add(client);
|
2018-04-11 18:24:21 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-17 16:05:16 -04:00
|
|
|
|
// this can happen if status is requested while map is rotating and we get a log dump back
|
|
|
|
|
if (!parsedHeader)
|
2018-05-03 01:25:49 -04:00
|
|
|
|
{
|
2020-04-17 16:05:16 -04:00
|
|
|
|
throw new ServerException(Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_UNEXPECTED_STATUS"]);
|
2018-05-03 01:25:49 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-11 18:24:21 -04:00
|
|
|
|
return StatusPlayers;
|
|
|
|
|
}
|
2020-06-16 18:16:12 -04:00
|
|
|
|
|
|
|
|
|
public string GetOverrideDvarName(string dvarName)
|
|
|
|
|
{
|
|
|
|
|
if (Configuration.OverrideDvarNameMapping.ContainsKey(dvarName))
|
|
|
|
|
{
|
|
|
|
|
return Configuration.OverrideDvarNameMapping[dvarName];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dvarName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public T GetDefaultDvarValue<T>(string dvarName) => Configuration.DefaultDvarValues.ContainsKey(dvarName) ?
|
|
|
|
|
(T)Convert.ChangeType(Configuration.DefaultDvarValues[dvarName], typeof(T)) :
|
|
|
|
|
default;
|
2020-11-11 19:53:23 -05:00
|
|
|
|
|
|
|
|
|
public TimeSpan OverrideTimeoutForCommand(string command)
|
|
|
|
|
{
|
|
|
|
|
if (command.Contains("map_rotate", StringComparison.InvariantCultureIgnoreCase) ||
|
|
|
|
|
command.StartsWith("map ", StringComparison.InvariantCultureIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return TimeSpan.FromSeconds(30);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TimeSpan.Zero;
|
|
|
|
|
}
|
2019-11-18 15:02:35 -05:00
|
|
|
|
}
|
|
|
|
|
}
|