fix rcon issue on restart

This commit is contained in:
RaidMax 2022-07-09 20:57:00 -05:00
parent 9e17bcc38f
commit 4e44bb5ea1
4 changed files with 29 additions and 54 deletions

View File

@ -61,7 +61,7 @@ namespace IW4MAdmin.Application
public IConfigurationHandler<ApplicationConfiguration> ConfigHandler; public IConfigurationHandler<ApplicationConfiguration> ConfigHandler;
readonly IPageList PageList; readonly IPageList PageList;
private readonly TimeSpan _throttleTimeout = new TimeSpan(0, 1, 0); private readonly TimeSpan _throttleTimeout = new TimeSpan(0, 1, 0);
private readonly CancellationTokenSource _tokenSource; private CancellationTokenSource _tokenSource;
private readonly Dictionary<string, Task<IList>> _operationLookup = new Dictionary<string, Task<IList>>(); private readonly Dictionary<string, Task<IList>> _operationLookup = new Dictionary<string, Task<IList>>();
private readonly ITranslationLookup _translationLookup; private readonly ITranslationLookup _translationLookup;
private readonly IConfigurationHandler<CommandConfiguration> _commandConfiguration; private readonly IConfigurationHandler<CommandConfiguration> _commandConfiguration;
@ -94,8 +94,8 @@ namespace IW4MAdmin.Application
ConfigHandler = appConfigHandler; ConfigHandler = appConfigHandler;
StartTime = DateTime.UtcNow; StartTime = DateTime.UtcNow;
PageList = new PageList(); PageList = new PageList();
AdditionalEventParsers = new List<IEventParser>() { new BaseEventParser(parserRegexFactory, logger, _appConfig) }; AdditionalEventParsers = new List<IEventParser> { new BaseEventParser(parserRegexFactory, logger, _appConfig) };
AdditionalRConParsers = new List<IRConParser>() { new BaseRConParser(serviceProvider.GetRequiredService<ILogger<BaseRConParser>>(), parserRegexFactory) }; AdditionalRConParsers = new List<IRConParser> { new BaseRConParser(serviceProvider.GetRequiredService<ILogger<BaseRConParser>>(), parserRegexFactory) };
TokenAuthenticator = new TokenAuthentication(); TokenAuthenticator = new TokenAuthentication();
_logger = logger; _logger = logger;
_tokenSource = new CancellationTokenSource(); _tokenSource = new CancellationTokenSource();
@ -613,6 +613,7 @@ namespace IW4MAdmin.Application
{ {
IsRestartRequested = true; IsRestartRequested = true;
Stop().GetAwaiter().GetResult(); Stop().GetAwaiter().GetResult();
_tokenSource = new CancellationTokenSource();
} }
[Obsolete] [Obsolete]

View File

@ -458,6 +458,12 @@ namespace Integrations.Cod
connectionState.SendEventArgs.DisconnectReuseSocket = true; connectionState.SendEventArgs.DisconnectReuseSocket = true;
} }
if (connectionState.ReceiveEventArgs.UserToken is ConnectionUserToken { CancellationToken.IsCancellationRequested: true })
{
// after a graceful restart we need to reset the receive user token as the cancellation has been updated
connectionState.ReceiveEventArgs.UserToken = connectionState.SendEventArgs.UserToken;
}
connectionState.SendEventArgs.SetBuffer(payload); connectionState.SendEventArgs.SetBuffer(payload);
// send the data to the server // send the data to the server

View File

@ -71,31 +71,7 @@ namespace SharedLibraryCore
/// </summary> /// </summary>
public const long WORLD_ID = -1; public const long WORLD_ID = -1;
public static Dictionary<Permission, string> PermissionLevelOverrides { get; } = public static Dictionary<Permission, string> PermissionLevelOverrides { get; } = new ();
new Dictionary<Permission, string>();
public static string HttpRequest(string location, string header, string headerValue)
{
using (var RequestClient = new HttpClient())
{
RequestClient.DefaultRequestHeaders.Add(header, headerValue);
var response = RequestClient.GetStringAsync(location).Result;
return response;
}
}
//Get string with specified number of spaces -- really only for visual output
public static string GetSpaces(int Num)
{
var SpaceString = string.Empty;
while (Num > 0)
{
SpaceString += ' ';
Num--;
}
return SpaceString;
}
//Remove words from a space delimited string //Remove words from a space delimited string
public static string RemoveWords(this string str, int num) public static string RemoveWords(this string str, int num)
@ -133,12 +109,12 @@ namespace SharedLibraryCore
{ {
var lookingFor = str.ToLower(); var lookingFor = str.ToLower();
for (var Perm = Permission.User; Perm < Permission.Console; Perm++) for (var perm = Permission.User; perm < Permission.Console; perm++)
if (lookingFor.Contains(Perm.ToString().ToLower()) if (lookingFor.Contains(perm.ToString().ToLower())
|| lookingFor.Contains(CurrentLocalization || lookingFor.Contains(CurrentLocalization
.LocalizationIndex[$"GLOBAL_PERMISSION_{Perm.ToString().ToUpper()}"].ToLower())) .LocalizationIndex[$"GLOBAL_PERMISSION_{perm.ToString().ToUpper()}"].ToLower()))
{ {
return Perm; return perm;
} }
return Permission.Banned; return Permission.Banned;
@ -211,7 +187,8 @@ namespace SharedLibraryCore
return output.FixIW4ForwardSlash(); return output.FixIW4ForwardSlash();
} }
private static readonly IList<string> _zmGameTypes = new[] { "zclassic", "zstandard", "zcleansed", "zgrief" }; private static readonly IList<string> ZmGameTypes = new[]
{ "zclassic", "zstandard", "zcleansed", "zgrief", "zom", "cmp" };
/// <summary> /// <summary>
/// indicates if the given server is running a zombie game mode /// indicates if the given server is running a zombie game mode
@ -220,7 +197,8 @@ namespace SharedLibraryCore
/// <returns></returns> /// <returns></returns>
public static bool IsZombieServer(this Server server) public static bool IsZombieServer(this Server server)
{ {
return server.GameName == Game.T6 && _zmGameTypes.Contains(server.Gametype.ToLower()); return new[] { Game.T4, Game.T5, Game.T6 }.Contains(server.GameName) &&
ZmGameTypes.Contains(server.Gametype.ToLower());
} }
public static bool IsCodGame(this Server server) public static bool IsCodGame(this Server server)
@ -283,11 +261,6 @@ namespace SharedLibraryCore
return str.StartsWith(broadcastCommandPrefix); return str.StartsWith(broadcastCommandPrefix);
} }
public static IManagerCommand AsCommand(this GameEvent gameEvent)
{
return gameEvent.Extra as IManagerCommand;
}
/// <summary> /// <summary>
/// Get the full gametype name /// Get the full gametype name
/// </summary> /// </summary>
@ -454,7 +427,7 @@ namespace SharedLibraryCore
{ {
var success = IPAddress.TryParse(str, out var ip); var success = IPAddress.TryParse(str, out var ip);
return success && ip.GetAddressBytes().Count(_byte => _byte == 0) != 4 return success && ip.GetAddressBytes().Count(_byte => _byte == 0) != 4
? (int?)BitConverter.ToInt32(ip.GetAddressBytes(), 0) ? BitConverter.ToInt32(ip.GetAddressBytes(), 0)
: null; : null;
} }
@ -503,11 +476,6 @@ namespace SharedLibraryCore
return Game.UKN; return Game.UKN;
} }
public static string EscapeMarkdown(this string markdownString)
{
return markdownString.Replace("<", "\\<").Replace(">", "\\>").Replace("|", "\\|");
}
public static TimeSpan ParseTimespan(this string input) public static TimeSpan ParseTimespan(this string input)
{ {
var expressionMatch = Regex.Match(input, @"([0-9]+)(\w+)"); var expressionMatch = Regex.Match(input, @"([0-9]+)(\w+)");
@ -629,7 +597,7 @@ namespace SharedLibraryCore
public static bool PromptBool(this string question, string description = null, bool defaultValue = true) public static bool PromptBool(this string question, string description = null, bool defaultValue = true)
{ {
Console.Write($"{question}?{(string.IsNullOrEmpty(description) ? " " : $" ({description}) ")}[y/n]: "); Console.Write($"{question}?{(string.IsNullOrEmpty(description) ? " " : $" ({description}) ")}[y/n]: ");
var response = Console.ReadLine().ToLower().FirstOrDefault(); var response = Console.ReadLine()?.ToLower().FirstOrDefault();
return response != 0 ? response == 'y' : defaultValue; return response != 0 ? response == 'y' : defaultValue;
} }
@ -660,7 +628,7 @@ namespace SharedLibraryCore
Console.WriteLine(new string('=', 52)); Console.WriteLine(new string('=', 52));
var selectionIndex = PromptInt(CurrentLocalization.LocalizationIndex["SETUP_PROMPT_MAKE_SELECTION"], null, var selectionIndex = PromptInt(CurrentLocalization.LocalizationIndex["SETUP_PROMPT_MAKE_SELECTION"], null,
hasDefault ? 0 : 1, selections.Length, hasDefault ? 0 : (int?)null); hasDefault ? 0 : 1, selections.Length, hasDefault ? 0 : null);
if (!hasDefault) if (!hasDefault)
{ {
@ -688,13 +656,13 @@ namespace SharedLibraryCore
$"{question}{(string.IsNullOrEmpty(description) ? "" : $" ({description})")}{(defaultValue == null ? "" : $" [{CurrentLocalization.LocalizationIndex["SETUP_PROMPT_DEFAULT"]} {defaultValue.Value.ToString()}]")}: "); $"{question}{(string.IsNullOrEmpty(description) ? "" : $" ({description})")}{(defaultValue == null ? "" : $" [{CurrentLocalization.LocalizationIndex["SETUP_PROMPT_DEFAULT"]} {defaultValue.Value.ToString()}]")}: ");
int response; int response;
string inputOrDefault() string InputOrDefault()
{ {
var input = Console.ReadLine(); var input = Console.ReadLine();
return string.IsNullOrEmpty(input) && defaultValue != null ? defaultValue.ToString() : input; return string.IsNullOrEmpty(input) && defaultValue != null ? defaultValue.ToString() : input;
} }
while (!int.TryParse(inputOrDefault(), out response) || while (!int.TryParse(InputOrDefault(), out response) ||
response < minValue || response < minValue ||
response > maxValue) response > maxValue)
{ {
@ -719,7 +687,7 @@ namespace SharedLibraryCore
/// <returns></returns> /// <returns></returns>
public static string PromptString(this string question, string description = null, string defaultValue = null) public static string PromptString(this string question, string description = null, string defaultValue = null)
{ {
string inputOrDefault() string InputOrDefault()
{ {
var input = Console.ReadLine(); var input = Console.ReadLine();
return string.IsNullOrEmpty(input) && defaultValue != null ? defaultValue : input; return string.IsNullOrEmpty(input) && defaultValue != null ? defaultValue : input;
@ -730,7 +698,7 @@ namespace SharedLibraryCore
{ {
Console.Write( Console.Write(
$"{question}{(string.IsNullOrEmpty(description) ? "" : $" ({description})")}{(defaultValue == null ? "" : $" [{CurrentLocalization.LocalizationIndex["SETUP_PROMPT_DEFAULT"]} {defaultValue}]")}: "); $"{question}{(string.IsNullOrEmpty(description) ? "" : $" ({description})")}{(defaultValue == null ? "" : $" [{CurrentLocalization.LocalizationIndex["SETUP_PROMPT_DEFAULT"]} {defaultValue}]")}: ");
response = inputOrDefault(); response = InputOrDefault();
} while (string.IsNullOrWhiteSpace(response) && response != defaultValue); } while (string.IsNullOrWhiteSpace(response) && response != defaultValue);
return response; return response;

View File

@ -34,7 +34,7 @@
</div> </div>
<div class="text-danger font-weight-light">@ban.AttachedPenalty.DateTime.ToStandardFormat()</div> <div class="text-danger font-weight-light">@ban.AttachedPenalty.DateTime.ToStandardFormat()</div>
<br/> <br/>
<div class="btn profile-action w-100" data-action="unban" data-action-id="@ban.ClientId">@ViewBag.Localization["WEBFRONT_BAN_MGMT_ACTION_UNBAN"]</div> <div class="btn profile-action" ata-action="unban" data-action-id="@ban.ClientId">@ViewBag.Localization["WEBFRONT_BAN_MGMT_ACTION_UNBAN"]</div>
} }
else else
{ {
@ -51,7 +51,7 @@
{ {
<div class="d-flex flex-wrap flex-column w-full w-md-200 p-10 border rounded mt-10 mt-md-0" style="border-style: dashed !important;"> <div class="d-flex flex-wrap flex-column w-full w-md-200 p-10 border rounded mt-10 mt-md-0" style="border-style: dashed !important;">
<div class="d-flex font-size-16"> <div class="d-flex font-size-16">
<div data-toggle="tooltip" data-title="@ViewBag.Localization["WEBFRONT_BAN_MGMT_TOOLTIP_LINKED"]" class="d-flex"> <div data-toggle="tooltip" data-title="@ViewBag.Localization["WEBFRONT_BAN_MGMT_TOOLTIP_LINKED"]" class="d-flex flex-fill">
<i class="oi oi-link-intact align-self-center"></i> <i class="oi oi-link-intact align-self-center"></i>
<div class="text-truncate ml-5 mr-5"> <div class="text-truncate ml-5 mr-5">
<a asp-controller="Client" asp-action="Profile" asp-route-id="@associatedEntity.OffenderInfo.ClientId" class="no-decoration text-force-break"> <a asp-controller="Client" asp-action="Profile" asp-route-id="@associatedEntity.OffenderInfo.ClientId" class="no-decoration text-force-break">
@ -76,7 +76,7 @@
<color-code value="@associatedEntity.Offense.CapClientName(30)"></color-code> <color-code value="@associatedEntity.Offense.CapClientName(30)"></color-code>
</div> </div>
<div class="text-danger font-weight-light">@associatedEntity.DateTime.ToStandardFormat()</div> <div class="text-danger font-weight-light">@associatedEntity.DateTime.ToStandardFormat()</div>
<div class="btn profile-action mt-10 w-100" data-action="unban" data-action-id="@associatedEntity.OffenderInfo.ClientId">@ViewBag.Localization["WEBFRONT_BAN_MGMT_ACTION_UNBAN"]</div> <div class="btn profile-action mt-10" data-action="unban" data-action-id="@associatedEntity.OffenderInfo.ClientId">@ViewBag.Localization["WEBFRONT_BAN_MGMT_ACTION_UNBAN"]</div>
</div> </div>
} }
</div> </div>