1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-10 15:20:48 -05:00

Initial .net 6 upgrades

This commit is contained in:
RaidMax
2022-01-26 10:32:16 -06:00
parent 513f0afd34
commit 6f6dd035ee
170 changed files with 2805 additions and 2577 deletions

View File

@ -1,8 +1,8 @@
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Interfaces;
using System.Threading.Tasks;
using System.Threading.Tasks;
using Data.Models;
using Data.Models.Client;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Interfaces;
namespace SharedLibraryCore.Commands
{
@ -10,7 +10,8 @@ namespace SharedLibraryCore.Commands
{
private readonly IMetaService _metaService;
public AddClientTagCommand(CommandConfiguration config, ITranslationLookup layout, IMetaService metaService) : base(config, layout)
public AddClientTagCommand(CommandConfiguration config, ITranslationLookup layout, IMetaService metaService) :
base(config, layout)
{
Name = "addclienttag";
Description = layout["COMMANDS_ADD_CLIENT_TAG_DESC"];
@ -19,7 +20,7 @@ namespace SharedLibraryCore.Commands
RequiresTarget = false;
Arguments = new[]
{
new CommandArgument()
new CommandArgument
{
Name = _translationLookup["COMMANDS_ARGUMENT_TAG"],
Required = true
@ -31,8 +32,8 @@ namespace SharedLibraryCore.Commands
public override async Task ExecuteAsync(GameEvent gameEvent)
{
await _metaService.AddPersistentMeta(EFMeta.ClientTagName, gameEvent.Data);
gameEvent.Origin.Tell(_translationLookup["COMMANDS_ADD_CLIENT_TAG_SUCCESS"].FormatExt(gameEvent.Data));
await _metaService.AddPersistentMeta(EFMeta.ClientTagName, gameEvent.Data);
gameEvent.Origin.Tell(_translationLookup["COMMANDS_ADD_CLIENT_TAG_SUCCESS"].FormatExt(gameEvent.Data));
}
}
}
}

View File

@ -1,18 +1,18 @@
namespace SharedLibraryCore.Commands
{
/// <summary>
/// Holds information about command args
/// Holds information about command args
/// </summary>
public class CommandArgument
{
/// <summary>
/// Name of the argument
/// Name of the argument
/// </summary>
public string Name { get; set; }
/// <summary>
/// Indicates if the argument is required
/// Indicates if the argument is required
/// </summary>
public bool Required { get; set; }
}
}
}

View File

@ -1,13 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace SharedLibraryCore.Commands
namespace SharedLibraryCore.Commands
{
public static class CommandExtensions
{
public static bool IsTargetingSelf(this GameEvent gameEvent) => gameEvent.Origin?.Equals(gameEvent.Target) ?? false;
public static bool IsTargetingSelf(this GameEvent gameEvent)
{
return gameEvent.Origin?.Equals(gameEvent.Target) ?? false;
}
public static bool CanPerformActionOnTarget(this GameEvent gameEvent) => gameEvent.Origin?.Level > gameEvent.Target?.Level;
public static bool CanPerformActionOnTarget(this GameEvent gameEvent)
{
return gameEvent.Origin?.Level > gameEvent.Target?.Level;
}
}
}
}

View File

@ -1,36 +1,35 @@
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Exceptions;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Exceptions;
namespace SharedLibraryCore.Commands
{
public class CommandProcessing
{
public static async Task<Command> ValidateCommand(GameEvent E, ApplicationConfiguration appConfig, CommandConfiguration commandConfig)
public static async Task<Command> ValidateCommand(GameEvent E, ApplicationConfiguration appConfig,
CommandConfiguration commandConfig)
{
var loc = Utilities.CurrentLocalization.LocalizationIndex;
var Manager = E.Owner.Manager;
bool isBroadcast = E.Data.StartsWith(appConfig.BroadcastCommandPrefix);
int prefixLength = isBroadcast ? appConfig.BroadcastCommandPrefix.Length : appConfig.CommandPrefix.Length;
var isBroadcast = E.Data.StartsWith(appConfig.BroadcastCommandPrefix);
var prefixLength = isBroadcast ? appConfig.BroadcastCommandPrefix.Length : appConfig.CommandPrefix.Length;
string CommandString = E.Data.Substring(prefixLength, E.Data.Length - prefixLength).Split(' ')[0];
var CommandString = E.Data.Substring(prefixLength, E.Data.Length - prefixLength).Split(' ')[0];
E.Message = E.Data;
Command C = null;
foreach (Command cmd in Manager.GetCommands()
.Where(c => c.Name != null))
{
if (cmd.Name.Equals(CommandString, StringComparison.OrdinalIgnoreCase) ||
.Where(c => c.Name != null))
if (cmd.Name.Equals(CommandString, StringComparison.OrdinalIgnoreCase) ||
(cmd.Alias ?? "").Equals(CommandString, StringComparison.OrdinalIgnoreCase))
{
C = cmd;
}
}
if (C == null)
{
@ -43,7 +42,7 @@ namespace SharedLibraryCore.Commands
var allowImpersonation = commandConfig?.Commands?.ContainsKey(C.GetType().Name) ?? false
? commandConfig.Commands[C.GetType().Name].AllowImpersonation
: C.AllowImpersonation;
if (!allowImpersonation && E.ImpersonationOrigin != null)
{
E.ImpersonationOrigin.Tell(loc["COMMANDS_RUN_AS_FAIL"]);
@ -51,7 +50,7 @@ namespace SharedLibraryCore.Commands
}
E.Data = E.Data.RemoveWords(1);
String[] Args = E.Data.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
var Args = E.Data.Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
// todo: the code below can be cleaned up
if (E.Origin.Level < C.Permission)
@ -60,7 +59,7 @@ namespace SharedLibraryCore.Commands
throw new CommandException($"{E.Origin} does not have access to \"{C.Name}\"");
}
if (Args.Length < (C.RequiredArgumentCount))
if (Args.Length < C.RequiredArgumentCount)
{
E.Origin.Tell(loc["COMMAND_MISSINGARGS"]);
E.Origin.Tell(C.Syntax);
@ -71,14 +70,14 @@ namespace SharedLibraryCore.Commands
{
if (Args.Length > 0)
{
if (!Int32.TryParse(Args[0], out int cNum))
if (!int.TryParse(Args[0], out var cNum))
{
cNum = -1;
}
if (Args[0][0] == '@') // user specifying target by database ID
{
int.TryParse(Args[0].Substring(1, Args[0].Length - 1), out int dbID);
int.TryParse(Args[0].Substring(1, Args[0].Length - 1), out var dbID);
var found = await Manager.GetClientService().Get(dbID);
if (found != null)
@ -90,12 +89,13 @@ namespace SharedLibraryCore.Commands
}
}
else if (Args[0].Length < 3 && cNum > -1 && cNum < E.Owner.MaxClients) // user specifying target by client num
else if (Args[0].Length < 3 && cNum > -1 && cNum < E.Owner.MaxClients
) // user specifying target by client num
{
if (E.Owner.Clients[cNum] != null)
{
E.Target = E.Owner.Clients[cNum];
E.Data = String.Join(" ", Args.Skip(1));
E.Data = string.Join(" ", Args.Skip(1));
}
}
}
@ -111,11 +111,11 @@ namespace SharedLibraryCore.Commands
throw new CommandException($"{E.Origin} had multiple players found for {C.Name}");
}
else if (matchingPlayers.Count == 1)
if (matchingPlayers.Count == 1)
{
E.Target = matchingPlayers.First();
string escapedName = Regex.Escape(E.Target.CleanedName);
var escapedName = Regex.Escape(E.Target.CleanedName);
var reg = new Regex($"(\"{escapedName}\")|({escapedName})", RegexOptions.IgnoreCase);
E.Data = reg.Replace(E.Data, "", 1).Trim();
@ -135,23 +135,21 @@ namespace SharedLibraryCore.Commands
{
E.Origin.Tell(loc["COMMAND_TARGET_MULTI"]);
foreach (var p in matchingPlayers)
{
E.Origin.Tell($"[(Color::Yellow){p.ClientNumber}(Color::White)] {p.Name}");
}
throw new CommandException($"{E.Origin} had multiple players found for {C.Name}");
}
else if (matchingPlayers.Count == 1)
if (matchingPlayers.Count == 1)
{
E.Target = matchingPlayers.First();
string escapedName = Regex.Escape(E.Target.CleanedName);
string escapedArg = Regex.Escape(Args[0]);
var escapedName = Regex.Escape(E.Target.CleanedName);
var escapedArg = Regex.Escape(Args[0]);
var reg = new Regex($"({escapedName})|({escapedArg})", RegexOptions.IgnoreCase);
E.Data = reg.Replace(E.Data, "", 1).Trim();
if ((E.Data.Trim() == E.Target.CleanedName.ToLower().Trim() ||
E.Data == String.Empty) &&
E.Data == string.Empty) &&
C.RequiresTarget)
{
E.Origin.Tell(loc["COMMAND_MISSINGARGS"]);
@ -172,4 +170,4 @@ namespace SharedLibraryCore.Commands
return C;
}
}
}
}

View File

@ -1,27 +1,25 @@
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq;
using System.Threading.Tasks;
using Data.Models;
using Data.Models.Client;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Interfaces;
namespace SharedLibraryCore.Commands
{
public class ListClientTags : Command
{
private readonly IMetaService _metaService;
public ListClientTags(CommandConfiguration config, ITranslationLookup layout, IMetaService metaService) : base(config, layout)
public ListClientTags(CommandConfiguration config, ITranslationLookup layout, IMetaService metaService) : base(
config, layout)
{
Name = "listclienttags";
Description = layout["COMMANDS_LIST_CLIENT_TAGS_DESC"];
Alias = "lct";
Permission = EFClient.Permission.Owner;
RequiresTarget = false;
_metaService = metaService;
}
@ -31,4 +29,4 @@ namespace SharedLibraryCore.Commands
gameEvent.Origin.Tell(tags.Select(tag => tag.Value));
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,16 +1,16 @@
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Interfaces;
using System;
using System.Linq;
using System.Linq;
using System.Threading.Tasks;
using Data.Models.Client;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Interfaces;
using static SharedLibraryCore.Server;
namespace SharedLibraryCore.Commands
{
public class PrivateMessageAdminsCommand : Command
{
public PrivateMessageAdminsCommand(CommandConfiguration config, ITranslationLookup lookup) : base(config, lookup)
public PrivateMessageAdminsCommand(CommandConfiguration config, ITranslationLookup lookup) : base(config,
lookup)
{
Name = "privatemessageadmin";
Description = lookup["COMMANDS_PMADMINS_DESC"];
@ -21,12 +21,14 @@ namespace SharedLibraryCore.Commands
public override Task ExecuteAsync(GameEvent E)
{
bool isGameSupported = _config.Commands[nameof(PrivateMessageAdminsCommand)].SupportedGames.Length > 0 &&
_config.Commands[nameof(PrivateMessageAdminsCommand)].SupportedGames.Contains(E.Owner.GameName);
var isGameSupported = _config.Commands[nameof(PrivateMessageAdminsCommand)].SupportedGames.Length > 0 &&
_config.Commands[nameof(PrivateMessageAdminsCommand)].SupportedGames
.Contains(E.Owner.GameName);
if (!isGameSupported)
{
E.Origin.Tell(_translationLookup["COMMANDS_GAME_NOT_SUPPORTED"].FormatExt(nameof(PrivateMessageAdminsCommand)));
E.Origin.Tell(_translationLookup["COMMANDS_GAME_NOT_SUPPORTED"]
.FormatExt(nameof(PrivateMessageAdminsCommand)));
return Task.CompletedTask;
}
@ -34,4 +36,4 @@ namespace SharedLibraryCore.Commands
return Task.CompletedTask;
}
}
}
}

View File

@ -1,8 +1,8 @@
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Interfaces;
using System.Threading.Tasks;
using System.Threading.Tasks;
using Data.Models;
using Data.Models.Client;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Interfaces;
namespace SharedLibraryCore.Commands
{
@ -10,7 +10,8 @@ namespace SharedLibraryCore.Commands
{
private readonly IMetaService _metaService;
public RemoveClientTag(CommandConfiguration config, ITranslationLookup layout, IMetaService metaService) : base(config, layout)
public RemoveClientTag(CommandConfiguration config, ITranslationLookup layout, IMetaService metaService) : base(
config, layout)
{
Name = "removeclienttag";
Description = layout["COMMANDS_REMOVE_CLIENT_TAG_DESC"];
@ -19,7 +20,7 @@ namespace SharedLibraryCore.Commands
RequiresTarget = false;
Arguments = new[]
{
new CommandArgument()
new CommandArgument
{
Name = _translationLookup["COMMANDS_ARGUMENT_TAG"],
Required = true
@ -35,4 +36,4 @@ namespace SharedLibraryCore.Commands
gameEvent.Origin.Tell(_translationLookup["COMMANDS_REMOVE_CLIENT_TAG_SUCCESS"].FormatExt(gameEvent.Data));
}
}
}
}

View File

@ -1,12 +1,12 @@
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Database.Models;
using System.Threading.Tasks;
using Data.Models.Client;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Interfaces;
using System.Threading.Tasks;
namespace SharedLibraryCore.Commands
{
/// <summary>
/// Generates a token for use in webfront login
/// Generates a token for use in webfront login
/// </summary>
public class RequestTokenCommand : Command
{
@ -22,9 +22,10 @@ namespace SharedLibraryCore.Commands
public override Task ExecuteAsync(GameEvent E)
{
var state = E.Owner.Manager.TokenAuthenticator.GenerateNextToken(E.Origin.NetworkId);
E.Origin.Tell(string.Format(_translationLookup["COMMANDS_GENERATETOKEN_SUCCESS"], state.Token, $"{state.RemainingTime} {_translationLookup["GLOBAL_MINUTES"]}", E.Origin.ClientId));
E.Origin.Tell(string.Format(_translationLookup["COMMANDS_GENERATETOKEN_SUCCESS"], state.Token,
$"{state.RemainingTime} {_translationLookup["GLOBAL_MINUTES"]}", E.Origin.ClientId));
return Task.CompletedTask;
}
}
}
}

View File

@ -1,8 +1,8 @@
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Interfaces;
using System.Linq;
using System.Linq;
using System.Threading.Tasks;
using Data.Models.Client;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Interfaces;
namespace SharedLibraryCore.Commands
{
@ -17,7 +17,7 @@ namespace SharedLibraryCore.Commands
RequiresTarget = true;
Arguments = new[]
{
new CommandArgument()
new CommandArgument
{
Name = lookup["COMMANDS_ARGS_COMMANDS"],
Required = true
@ -40,7 +40,7 @@ namespace SharedLibraryCore.Commands
}
var cmd = $"{Utilities.CommandPrefix}{gameEvent.Data}";
var impersonatedCommandEvent = new GameEvent()
var impersonatedCommandEvent = new GameEvent
{
Type = GameEvent.EventType.Command,
Origin = gameEvent.Target,
@ -52,7 +52,8 @@ namespace SharedLibraryCore.Commands
};
gameEvent.Owner.Manager.AddEvent(impersonatedCommandEvent);
var result = await impersonatedCommandEvent.WaitAsync(Utilities.DefaultCommandTimeout, gameEvent.Owner.Manager.CancellationToken);
var result = await impersonatedCommandEvent.WaitAsync(Utilities.DefaultCommandTimeout,
gameEvent.Owner.Manager.CancellationToken);
await result.WaitAsync(Utilities.DefaultCommandTimeout, gameEvent.Owner.Manager.CancellationToken);
// remove the added command response
@ -61,11 +62,10 @@ namespace SharedLibraryCore.Commands
.Where(ev => ev.Value.CorrelationId == impersonatedCommandEvent.CorrelationId)
.SelectMany(ev => ev.Value.Output)
.ToList();
foreach (var output in responses)
{
await gameEvent.Origin.Tell(_translationLookup["COMMANDS_RUN_AS_SUCCESS"].FormatExt(output)).WaitAsync();
}
await gameEvent.Origin.Tell(_translationLookup["COMMANDS_RUN_AS_SUCCESS"].FormatExt(output))
.WaitAsync();
}
}
}
}

View File

@ -1,9 +1,9 @@
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Interfaces;
using System.Linq;
using System.Linq;
using System.Threading.Tasks;
using Data.Models;
using Data.Models.Client;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Interfaces;
namespace SharedLibraryCore.Commands
{
@ -12,7 +12,8 @@ namespace SharedLibraryCore.Commands
private readonly IMetaService _metaService;
public SetClientTagCommand(CommandConfiguration config, ITranslationLookup layout, IMetaService metaService) : base(config, layout)
public SetClientTagCommand(CommandConfiguration config, ITranslationLookup layout, IMetaService metaService) :
base(config, layout)
{
Name = "setclienttag";
Description = layout["COMMANDS_SET_CLIENT_TAG_DESC"];
@ -21,7 +22,7 @@ namespace SharedLibraryCore.Commands
RequiresTarget = true;
Arguments = new[]
{
new CommandArgument()
new CommandArgument
{
Name = _translationLookup["COMMANDS_ARGUMENT_TAG"],
Required = true
@ -47,4 +48,4 @@ namespace SharedLibraryCore.Commands
gameEvent.Origin.Tell(_translationLookup["COMMANDS_SET_CLIENT_TAG_SUCCESS"].FormatExt(matchingTag.Value));
}
}
}
}

View File

@ -1,16 +1,16 @@
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Database.Models;
using System.Threading.Tasks;
using Data.Models.Client;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Interfaces;
using System.Threading.Tasks;
namespace SharedLibraryCore.Commands
{
/// <summary>
/// Provides a way for administrators to "unlink" linked accounts
/// This problem is common in IW4x where the client identifier is a file
/// that is commonly transmitted when uploading and sharing the game files
/// This command creates a new link and assigns the guid, and all aliases with the current IP
/// associated to the provided client ID to the new link
/// Provides a way for administrators to "unlink" linked accounts
/// This problem is common in IW4x where the client identifier is a file
/// that is commonly transmitted when uploading and sharing the game files
/// This command creates a new link and assigns the guid, and all aliases with the current IP
/// associated to the provided client ID to the new link
/// </summary>
public class UnlinkClientCommand : Command
{
@ -29,4 +29,4 @@ namespace SharedLibraryCore.Commands
E.Origin.Tell(_translationLookup["COMMANDS_UNLINK_CLIENT_SUCCESS"].FormatExt(E.Target));
}
}
}
}

View File

@ -1,9 +1,8 @@
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Interfaces;
using System.Linq;
using System.Threading.Tasks;
using System.Threading.Tasks;
using Data.Models;
using Data.Models.Client;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Interfaces;
namespace SharedLibraryCore.Commands
{
@ -12,7 +11,8 @@ namespace SharedLibraryCore.Commands
private readonly IMetaService _metaService;
public UnsetClientTagCommand(CommandConfiguration config, ITranslationLookup layout, IMetaService metaService) : base(config, layout)
public UnsetClientTagCommand(CommandConfiguration config, ITranslationLookup layout, IMetaService metaService) :
base(config, layout)
{
Name = "unsetclienttag";
Description = layout["COMMANDS_UNSET_CLIENT_TAG_DESC"];
@ -21,7 +21,7 @@ namespace SharedLibraryCore.Commands
RequiresTarget = true;
Arguments = new[]
{
new CommandArgument()
new CommandArgument
{
Name = _translationLookup["COMMANDS_ARGUMENT_TAG"],
Required = true
@ -38,4 +38,4 @@ namespace SharedLibraryCore.Commands
gameEvent.Origin.Tell(_translationLookup["COMMANDS_UNSET_CLIENT_TAG_SUCCESS"]);
}
}
}
}