abstract engine color codes to use (Color::<Color>) format to make codes more.

see pt6 parser and configs for example usages
This commit is contained in:
RaidMax
2021-11-23 17:26:33 -06:00
parent 66010a2fa2
commit 4a89744ee9
42 changed files with 775 additions and 540 deletions

View File

@ -136,7 +136,7 @@ namespace SharedLibraryCore.Commands
E.Origin.Tell(loc["COMMAND_TARGET_MULTI"]);
foreach (var p in matchingPlayers)
{
E.Origin.Tell($"[^3{p.ClientNumber}^7] {p.Name}");
E.Origin.Tell($"[(Color::Yellow){p.ClientNumber}(Color::White)] {p.Name}");
}
throw new CommandException($"{E.Origin} had multiple players found for {C.Name}");
}

View File

@ -219,72 +219,6 @@ namespace SharedLibraryCore.Commands
}
}
/// <summary>
/// Prints out a message to all clients on the server
/// </summary>
public class SayCommand : Command
{
public SayCommand(CommandConfiguration config, ITranslationLookup translationLookup) : base(config, translationLookup)
{
Name = "say";
Description = _translationLookup["COMMANDS_SAY_DESC"];
Alias = "s";
Permission = Permission.Moderator;
RequiresTarget = false;
Arguments = new[]
{
new CommandArgument()
{
Name = _translationLookup["COMMANDS_ARGS_MESSAGE"],
Required = true
}
};
}
public override Task ExecuteAsync(GameEvent E)
{
E.Owner.Broadcast($"{(E.Owner.GameName == Server.Game.IW4 ? "^:" : "")}{E.Origin.Name} - ^6{E.Data}^7", E.Origin);
E.Origin.Tell(_translationLookup["COMMANDS_SAY_SUCCESS"]);
return Task.CompletedTask;
}
}
/// <summary>
/// Prints out a message to all clients on all servers
/// </summary>
public class SayAllCommand : Command
{
public SayAllCommand(CommandConfiguration config, ITranslationLookup translationLookup) : base(config, translationLookup)
{
Name = "sayall";
Description = _translationLookup["COMMANDS_SAY_ALL_DESC"];
Alias = "sa";
Permission = Permission.Moderator;
RequiresTarget = false;
Arguments = new[]
{
new CommandArgument()
{
Name = _translationLookup["COMMANDS_ARGS_MESSAGE"],
Required = true
}
};
}
public override Task ExecuteAsync(GameEvent E)
{
string message = _translationLookup["COMMANDS_SAY_ALL_MESSAGE_FORMAT"].FormatExt(E.Origin.Name, E.Data);
foreach (var server in E.Owner.Manager.GetServers())
{
server.Broadcast(message, E.Origin);
}
E.Origin.Tell(_translationLookup["COMMANDS_SAY_SUCCESS"]);
return Task.CompletedTask;
}
}
/// <summary>
/// Temporarily bans a client
/// </summary>
@ -452,57 +386,6 @@ namespace SharedLibraryCore.Commands
}
}
/// <summary>
/// Prints client information
/// </summary>
public class WhoAmICommand : Command
{
public WhoAmICommand(CommandConfiguration config, ITranslationLookup translationLookup) : base(config, translationLookup)
{
Name = "whoami";
Description = _translationLookup["COMMANDS_WHO_DESC"];
Alias = "who";
Permission = Permission.User;
RequiresTarget = false;
}
public override Task ExecuteAsync(GameEvent gameEvent)
{
var you = _translationLookup["COMMANDS_WHOAMI_FORMAT"].FormatExt(gameEvent.Origin.ClientNumber, gameEvent.Origin.ClientId, gameEvent.Origin.GuidString,
gameEvent.Origin.IPAddressString, gameEvent.Origin.ClientPermission.Name, string.IsNullOrEmpty(gameEvent.Origin.Tag) ? "" : $" {gameEvent.Origin.Tag}^7", gameEvent.Origin.Name);
gameEvent.Origin.Tell(you);
return Task.CompletedTask;
}
}
/// <summary>
/// List online clients
/// </summary>
public class ListClientsCommand : Command
{
public ListClientsCommand(CommandConfiguration config, ITranslationLookup translationLookup) : base(config, translationLookup)
{
Name = "list";
Description = _translationLookup["COMMANDS_LIST_DESC"];
Alias = "l";
Permission = Permission.Moderator;
RequiresTarget = false;
}
public override Task ExecuteAsync(GameEvent gameEvent)
{
var clientList = gameEvent.Owner.GetClientsAsList()
.Select(client => _translationLookup["COMMANDS_LIST_FORMAT"]
.FormatExt(client.ClientPermission.Name, string.IsNullOrEmpty(client.Tag) ? "" : $" {client.Tag}^7", client.ClientNumber, client.Name))
.ToArray();
gameEvent.Origin.Tell(clientList);
return Task.CompletedTask;
}
}
/// <summary>
/// Fast restarts the map
/// </summary>
@ -522,7 +405,7 @@ namespace SharedLibraryCore.Commands
await E.Owner.ExecuteCommandAsync("fast_restart");
var _ = !E.Origin.Masked ?
E.Owner.Broadcast($"^5{E.Origin.Name} ^7{_translationLookup["COMMANDS_FASTRESTART_UNMASKED"]}") :
E.Owner.Broadcast($"(Color::Accent){E.Origin.Name} (Color::White){_translationLookup["COMMANDS_FASTRESTART_UNMASKED"]}") :
E.Owner.Broadcast(_translationLookup["COMMANDS_FASTRESTART_MASKED"]);
}
}
@ -544,7 +427,7 @@ namespace SharedLibraryCore.Commands
public override async Task ExecuteAsync(GameEvent E)
{
_ = !E.Origin.Masked ?
E.Owner.Broadcast($"{_translationLookup["COMMANDS_MAPROTATE"]} [^5{E.Origin.Name}^7]", E.Origin) :
E.Owner.Broadcast($"{_translationLookup["COMMANDS_MAPROTATE"]} [(Color::Accent){E.Origin.Name}(Color::White)]", E.Origin) :
E.Owner.Broadcast(_translationLookup["COMMANDS_MAPROTATE"], E.Origin);
await Task.Delay(E.Owner.Manager.GetApplicationSettings().Configuration().MapChangeDelaySeconds * 1000);
@ -618,13 +501,13 @@ namespace SharedLibraryCore.Commands
else if (gameEvent.Origin.Level < Permission.Owner && !steppedPrivileges)
{
// only the owner is allowed to set levels
gameEvent.Origin.Tell($"{_translationLookup["COMMANDS_SETLEVEL_STEPPEDDISABLED"]} ^5{gameEvent.Target.Name}");
gameEvent.Origin.Tell($"{_translationLookup["COMMANDS_SETLEVEL_STEPPEDDISABLED"]} (Color::White){gameEvent.Target.Name}");
return;
}
else if (gameEvent.Target.Level == Permission.Flagged)
{
gameEvent.Origin.Tell(_translationLookup["COMMANDS_SETLEVEL_FLAGGED"].FormatExt(gameEvent.Target.Name));
gameEvent.Origin.Tell(_translationLookup["COMMANDS_SETLEVEL_FLAGGED"].FormatExt(gameEvent.Target.Name + "(Color::White)"));
return;
}
@ -633,8 +516,8 @@ namespace SharedLibraryCore.Commands
{
// can't promote a client to higher than your current perms
// or your peer
gameEvent.Origin.Tell(string.Format(_translationLookup["COMMANDS_SETLEVEL_LEVELTOOHIGH"], gameEvent.Target.Name, (gameEvent.Origin.Level - 1).ToLocalizedLevelName()));
return;
gameEvent.Origin.Tell(_translationLookup["COMMANDS_SETLEVEL_LEVELTOOHIGH_V2"]
.FormatExt(gameEvent.Target.Name, (gameEvent.Origin.Level - 1).ToLocalizedLevelName()));
}
// valid
@ -654,7 +537,7 @@ namespace SharedLibraryCore.Commands
if (result.FailReason == GameEvent.EventFailReason.Invalid)
{
gameEvent.Origin.Tell(_translationLookup["COMMANDS_SETLEVEL_INVALID"]
.FormatExt(gameEvent.Target.Name, newPerm.ToString()));
.FormatExt(gameEvent.Target.Name + "(Color::White)", newPerm.ToString()));
return;
}
@ -733,42 +616,6 @@ namespace SharedLibraryCore.Commands
}
}
/// <summary>
/// Lists all unmasked admins
/// </summary>
public class ListAdminsCommand : Command
{
public ListAdminsCommand(CommandConfiguration config, ITranslationLookup translationLookup) : base(config, translationLookup)
{
Name = "admins";
Description = _translationLookup["COMMANDS_ADMINS_DESC"];
Alias = "a";
Permission = Permission.User;
RequiresTarget = false;
}
public static string OnlineAdmins(Server S, ITranslationLookup lookup)
{
var onlineAdmins = S.GetClientsAsList()
.Where(p => p.Level > Permission.Flagged)
.Where(p => !p.Masked)
.Select(p => $"[^3{Utilities.ConvertLevelToColor(p.Level, p.ClientPermission.Name)}^7] {p.Name}");
return onlineAdmins.Count() > 0 ?
string.Join(Environment.NewLine, onlineAdmins) :
lookup["COMMANDS_ADMINS_NONE"];
}
public override Task ExecuteAsync(GameEvent E)
{
foreach (string line in OnlineAdmins(E.Owner, _translationLookup).Split(Environment.NewLine))
{
var _ = E.Message.IsBroadcastCommand(_config.BroadcastCommandPrefix) ? E.Owner.Broadcast(line) : E.Origin.Tell(line);
}
return Task.CompletedTask;
}
}
/// <summary>
/// Attempts to load the specified map
@ -809,50 +656,6 @@ namespace SharedLibraryCore.Commands
}
}
/// <summary>
/// Finds player by name
/// </summary>
public class FindPlayerCommand : Command
{
public FindPlayerCommand(CommandConfiguration config, ITranslationLookup translationLookup) : base(config, translationLookup)
{
Name = "find";
Description = _translationLookup["COMMANDS_FIND_DESC"];
Alias = "f";
Permission = Permission.Administrator;
RequiresTarget = false;
Arguments = new[]
{
new CommandArgument()
{
Name = _translationLookup["COMMANDS_ARGS_PLAYER"],
Required = true
}
};
}
public override async Task ExecuteAsync(GameEvent E)
{
if (E.Data.Length < 3)
{
E.Origin.Tell(_translationLookup["COMMANDS_FIND_MIN"]);
return;
}
var db_players = (await (E.Owner.Manager.GetClientService() as ClientService).FindClientsByIdentifier(E.Data));
if (db_players.Count == 0)
{
E.Origin.Tell(_translationLookup["COMMANDS_FIND_EMPTY"]);
return;
}
foreach (var client in db_players)
{
E.Origin.Tell(_translationLookup["COMMANDS_FIND_FORMAT"].FormatExt(client.Name, client.ClientId, Utilities.ConvertLevelToColor((Permission)client.LevelInt, client.Level), client.IPAddress, client.LastConnectionText));
}
}
}
/// <summary>
/// Lists server and global rules
@ -902,40 +705,7 @@ namespace SharedLibraryCore.Commands
}
}
/// <summary>
/// Sends a private message to another player
/// </summary>
public class PrivateMessageCommand : Command
{
public PrivateMessageCommand(CommandConfiguration config, ITranslationLookup translationLookup) : base(config, translationLookup)
{
Name = "privatemessage";
Description = _translationLookup["COMMANDS_PM_DESC"];
Alias = "pm";
Permission = Permission.User;
RequiresTarget = true;
Arguments = new[]
{
new CommandArgument()
{
Name = _translationLookup["COMMANDS_ARGS_PLAYER"],
Required = true
},
new CommandArgument()
{
Name = _translationLookup["COMMANDS_ARGS_MESSAGE"],
Required = true
}
};
}
public override Task ExecuteAsync(GameEvent E)
{
E.Target.Tell($"^1{E.Origin.Name} ^3[PM]^7 - {E.Data}");
E.Origin.Tell($"To ^3{E.Target.Name} ^7-> {E.Data}");
return Task.CompletedTask;
}
}
/// <summary>
/// Flag given client for specified reason
@ -1031,116 +801,6 @@ namespace SharedLibraryCore.Commands
}
}
/// <summary>
/// Report client for given reason
/// </summary>
public class ReportClientCommand : Command
{
public ReportClientCommand(CommandConfiguration config, ITranslationLookup translationLookup) : base(config, translationLookup)
{
Name = "report";
Description = _translationLookup["COMMANDS_REPORT_DESC"];
Alias = "rep";
Permission = Permission.User;
RequiresTarget = true;
Arguments = new[]
{
new CommandArgument()
{
Name = _translationLookup["COMMANDS_ARGS_PLAYER"],
Required = true
},
new CommandArgument()
{
Name = _translationLookup["COMMANDS_ARGS_REASON"],
Required = true
}
};
}
public override async Task ExecuteAsync(GameEvent commandEvent)
{
if (commandEvent.Data.ToLower().Contains("camp"))
{
commandEvent.Origin.Tell(_translationLookup["COMMANDS_REPORT_FAIL_CAMP"]);
return;
}
bool success = false;
switch ((await commandEvent.Target.Report(commandEvent.Data, commandEvent.Origin).WaitAsync(Utilities.DefaultCommandTimeout, commandEvent.Owner.Manager.CancellationToken)).FailReason)
{
case GameEvent.EventFailReason.None:
commandEvent.Origin.Tell(_translationLookup["COMMANDS_REPORT_SUCCESS"]);
success = true;
break;
case GameEvent.EventFailReason.Exception:
commandEvent.Origin.Tell(_translationLookup["COMMANDS_REPORT_FAIL_DUPLICATE"]);
break;
case GameEvent.EventFailReason.Permission:
commandEvent.Origin.Tell(_translationLookup["COMMANDS_REPORT_FAIL"].FormatExt(commandEvent.Target.Name));
break;
case GameEvent.EventFailReason.Invalid:
commandEvent.Origin.Tell(_translationLookup["COMMANDS_REPORT_FAIL_SELF"]);
break;
case GameEvent.EventFailReason.Throttle:
commandEvent.Origin.Tell(_translationLookup["COMMANDS_REPORT_FAIL_TOOMANY"]);
break;
}
if (success)
{
commandEvent.Owner.ToAdmins(String.Format("^5{0}^7->^1{1}^7: {2}", commandEvent.Origin.Name, commandEvent.Target.Name, commandEvent.Data));
}
}
}
/// <summary>
/// List all reports on the server
/// </summary>
public class ListReportsCommand : Command
{
public ListReportsCommand(CommandConfiguration config, ITranslationLookup translationLookup) : base(config, translationLookup)
{
Name = "reports";
Description = _translationLookup["COMMANDS_REPORTS_DESC"];
Alias = "reps";
Permission = Permission.Moderator;
RequiresTarget = false;
Arguments = new[]
{
new CommandArgument()
{
Name = _translationLookup["COMMANDS_ARGS_CLEAR"],
Required = false
}
};
}
public override Task ExecuteAsync(GameEvent E)
{
if (E.Data != null && E.Data.ToLower().Contains(_translationLookup["COMMANDS_ARGS_CLEAR"]))
{
E.Owner.Reports = new List<Report>();
E.Origin.Tell(_translationLookup["COMMANDS_REPORTS_CLEAR_SUCCESS"]);
return Task.CompletedTask;
}
if (E.Owner.Reports.Count < 1)
{
E.Origin.Tell(_translationLookup["COMMANDS_REPORTS_NONE"]);
return Task.CompletedTask;
}
foreach (Report R in E.Owner.Reports)
{
E.Origin.Tell(String.Format("^5{0}^7->^1{1}^7: {2}", R.Origin.Name, R.Target.Name, R.Reason));
}
return Task.CompletedTask;
}
}
/// <summary>
/// Masks client from announcements and online admin list
/// </summary>
@ -1218,49 +878,6 @@ namespace SharedLibraryCore.Commands
}
}
/// <summary>
/// Lists alises of specified client
/// </summary>
public class ListAliasesCommand : Command
{
public ListAliasesCommand(CommandConfiguration config, ITranslationLookup translationLookup) : base(config, translationLookup)
{
Name = "alias";
Description = _translationLookup["COMMANDS_ALIAS_DESC"];
Alias = "known";
Permission = EFClient.Permission.Moderator;
RequiresTarget = true;
Arguments = new[]
{
new CommandArgument()
{
Name = _translationLookup["COMMANDS_ARGS_PLAYER"],
Required = true,
}
};
}
public override Task ExecuteAsync(GameEvent E)
{
StringBuilder message = new StringBuilder();
var names = new List<string>(E.Target.AliasLink.Children.Select(a => a.Name));
var IPs = new List<string>(E.Target.AliasLink.Children.Select(a => a.IPAddress.ConvertIPtoString()).Distinct());
E.Origin.Tell($"[^3{E.Target}^7]");
message.Append($"{_translationLookup["COMMANDS_ALIAS_ALIASES"]}: ");
message.Append(String.Join(" | ", names));
E.Origin.Tell(message.ToString());
message.Clear();
message.Append($"{_translationLookup["COMMANDS_ALIAS_IPS"]}: ");
message.Append(String.Join(" | ", IPs));
E.Origin.Tell(message.ToString());
return Task.CompletedTask;
}
}
/// <summary>
/// Executes RCon command
/// </summary>
@ -1298,33 +915,6 @@ namespace SharedLibraryCore.Commands
}
}
/// <summary>
/// Lists the loaded plugins
/// </summary>
/*public class ListPluginsCommand : Command
{
private readonly IPluginImporter _pluginImporter;
public ListPluginsCommand(CommandConfiguration config, ITranslationLookup translationLookup, IPluginImporter pluginImporter) : base(config, translationLookup)
{
Name = "plugins";
Description = _translationLookup["COMMANDS_PLUGINS_DESC"];
Alias = "p";
Permission = Permission.Administrator;
RequiresTarget = false;
_pluginImporter = pluginImporter;
}
public override Task ExecuteAsync(GameEvent E)
{
E.Origin.Tell(_translationLookup["COMMANDS_PLUGINS_LOADED"]);
foreach (var P in _pluginImporter.ActivePlugins)
{
E.Origin.Tell(string.Format("^3{0} ^7[v^3{1}^7] by ^5{2}^7", P.Name, P.Version, P.Author));
}
return Task.CompletedTask;
}
}*/
/// <summary>
/// Lists external IP
/// </summary>
@ -1484,11 +1074,11 @@ namespace SharedLibraryCore.Commands
if (E.Target == null)
{
E.Origin.Tell(_translationLookup["COMMANDS_PING_SELF"].FormatExt(E.Origin.Ping));
E.Origin.Tell(_translationLookup["COMMANDS_PING_SELF_V2"].FormatExt(E.Origin.Ping));
}
else
{
E.Origin.Tell(_translationLookup["COMMANDS_PING_TARGET"].FormatExt(E.Target.Name, E.Target.Ping));
E.Origin.Tell(_translationLookup["COMMANDS_PING_TARGET_V2"].FormatExt(E.Target.Name, E.Target.Ping));
}
return Task.CompletedTask;

View File

@ -108,7 +108,7 @@ namespace SharedLibraryCore.Configuration
public string ConnectionString { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_RCON_POLLRATE")]
public int RConPollRate { get; set; } = 5000;
public int RConPollRate { get; set; } = 8000;
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_MAX_TB")]
public TimeSpan MaximumTempBanTime { get; set; } = new TimeSpan(24 * 30, 0, 0);
@ -116,6 +116,9 @@ namespace SharedLibraryCore.Configuration
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_ENABLE_COLOR_CODES")]
public bool EnableColorCodes { get; set; }
[ConfigurationIgnore]
public string IngameAccentColorKey { get; set; } = "Cyan";
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_AUTOMESSAGE_PERIOD")]
public int AutoMessagePeriod { get; set; }

View File

@ -0,0 +1,26 @@
using System.Collections.Generic;
namespace SharedLibraryCore.Formatting
{
public enum ColorCodes
{
Black,
Red,
Green,
Yellow,
Blue,
Cyan,
Purple,
Pink,
White,
Map,
Grey,
Wildcard,
Accent
}
public class ColorCodeMapping : Dictionary<string, string>
{
}
}

View File

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SharedLibraryCore.Helpers
{

View File

@ -1,5 +1,4 @@
using System;
using System.Threading.Tasks;
using System.Threading.Tasks;
namespace SharedLibraryCore.Interfaces
{
@ -10,9 +9,9 @@ namespace SharedLibraryCore.Interfaces
Task OnEventAsync(GameEvent E, Server S);
Task OnTickAsync(Server S);
//for logging purposes
String Name { get; }
string Name { get; }
float Version { get; }
String Author { get; }
string Author { get; }
bool IsParser => false;
}
}

View File

@ -1,6 +1,8 @@
using SharedLibraryCore.RCon;
using System.Collections.Generic;
using System.Globalization;
using SharedLibraryCore.Formatting;
using SharedLibraryCore.Localization;
namespace SharedLibraryCore.Interfaces
{
@ -97,5 +99,7 @@ namespace SharedLibraryCore.Interfaces
/// Default Indicator of where the game is installed (ex file path or registry entry)
/// </summary>
string DefaultInstallationDirectoryHint { get; }
ColorCodeMapping ColorCodeMapping { get; }
}
}

View File

@ -100,8 +100,9 @@ namespace SharedLibraryCore.Database.Models
CorrelationId = CurrentServer.Manager.ProcessingEvents.Values
.FirstOrDefault(ev => ev.Type == GameEvent.EventType.Command && (ev.Origin?.ClientId == ClientId || ev.ImpersonationOrigin?.ClientId == ClientId))?.CorrelationId ?? Guid.NewGuid()
};
e.Output.Add(message.StripColors());
e.Output.Add(message.FormatMessageForEngine(CurrentServer?.RconParser.Configuration.ColorCodeMapping)
.StripColors());
CurrentServer?.Manager.AddEvent(e);
return e;

View File

@ -132,10 +132,12 @@ namespace SharedLibraryCore
/// <param name="message">Message to be sent to all players</param>
public GameEvent Broadcast(string message, EFClient sender = null)
{
string formattedMessage = string.Format(RconParser.Configuration.CommandPrefixes.Say ?? "", $"{(CustomSayEnabled && GameName == Game.IW4 ? $"{CustomSayName}: " : "")}{message.FixIW4ForwardSlash()}");
ServerLogger.LogDebug("All->" + message.StripColors());
var formattedMessage = string.Format(RconParser.Configuration.CommandPrefixes.Say ?? "",
$"{(CustomSayEnabled && GameName == Game.IW4 ? $"{CustomSayName}: " : "")}{message.FormatMessageForEngine(RconParser.Configuration.ColorCodeMapping)}");
ServerLogger.LogDebug("All-> {Message}",
message.FormatMessageForEngine(RconParser.Configuration.ColorCodeMapping).StripColors());
var e = new GameEvent()
var e = new GameEvent
{
Type = GameEvent.EventType.Broadcast,
Data = formattedMessage,
@ -165,6 +167,8 @@ namespace SharedLibraryCore
/// <param name="targetClient">EFClient to send message to</param>
protected async Task Tell(string message, EFClient targetClient)
{
var engineMessage = message.FormatMessageForEngine(RconParser.Configuration.ColorCodeMapping);
if (!Utilities.IsDevelopment)
{
var temporalClientId = targetClient.GetAdditionalProperty<string>("ConnectionClientId");
@ -173,24 +177,25 @@ namespace SharedLibraryCore
var formattedMessage = string.Format(RconParser.Configuration.CommandPrefixes.Tell,
clientNumber,
$"{(CustomSayEnabled && GameName == Game.IW4 ? $"{CustomSayName}: " : "")}{message.FixIW4ForwardSlash()}");
$"{(CustomSayEnabled && GameName == Game.IW4 ? $"{CustomSayName}: " : "")}{engineMessage}");
if (targetClient.ClientNumber > -1 && message.Length > 0 && targetClient.Level != EFClient.Permission.Console)
await this.ExecuteCommandAsync(formattedMessage);
}
else
{
ServerLogger.LogDebug("Tell[{clientNumber}]->{message}", targetClient.ClientNumber, message.StripColors());
ServerLogger.LogDebug("Tell[{ClientNumber}]->{Message}", targetClient.ClientNumber,
message.FormatMessageForEngine(RconParser.Configuration.ColorCodeMapping).StripColors());
}
if (targetClient.Level == EFClient.Permission.Console)
{
Console.ForegroundColor = ConsoleColor.Green;
using (LogContext.PushProperty("Server", ToString()))
{
ServerLogger.LogInformation("Command output received: {message}", message);
ServerLogger.LogInformation("Command output received: {Message}",
engineMessage.StripColors());
}
Console.WriteLine(message.StripColors());
Console.WriteLine(engineMessage.StripColors());
Console.ForegroundColor = ConsoleColor.Gray;
}
}

View File

@ -716,12 +716,15 @@ namespace SharedLibraryCore.Services
// we want to project our results
var iqClientProjection = iqClients.OrderByDescending(_client => _client.LastConnection)
.Select(_client => new PlayerInfo()
.Select(_client => new PlayerInfo
{
Name = _client.CurrentAlias.Name,
LevelInt = (int)_client.Level,
LevelInt = (int) _client.Level,
LastConnection = _client.LastConnection,
ClientId = _client.ClientId,
IPAddress = _client.CurrentAlias.IPAddress.HasValue
? _client.CurrentAlias.IPAddress.Value.ToString()
: ""
});
var clients = await iqClientProjection.ToListAsync();

View File

@ -1,8 +1,8 @@
using Microsoft.AspNetCore.Razor.TagHelpers;
using System.Linq;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Razor.TagHelpers;
namespace SharedLibraryCore
namespace SharedLibraryCore.TagHelpers
{
[HtmlTargetElement("color-code")]
public class ColorCode : TagHelper

View File

@ -21,6 +21,7 @@ using static SharedLibraryCore.Server;
using ILogger = Microsoft.Extensions.Logging.ILogger;
using static Data.Models.Client.EFClient;
using Data.Models;
using SharedLibraryCore.Formatting;
using static Data.Models.EFPenalty;
namespace SharedLibraryCore
@ -178,6 +179,24 @@ namespace SharedLibraryCore
/// <returns></returns>
public static string FixIW4ForwardSlash(this string str) => str.Replace("//", "/ /");
public static string FormatMessageForEngine(this string str, ColorCodeMapping mapping)
{
if (mapping == null || string.IsNullOrEmpty(str))
{
return str;
}
var output = str;
var colorCodeMatches = Regex.Matches(output, @"\(Color::(.{1,16})\)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
foreach (var match in colorCodeMatches.Where(m => m.Success))
{
var key = match.Groups[1].ToString();
output = output.Replace(match.Value, mapping.TryGetValue(key, out var code) ? code : "");
}
return output.FixIW4ForwardSlash() + mapping[ColorCodes.White.ToString()];
}
private static readonly IList<string> _zmGameTypes = new[] { "zclassic", "zstandard", "zcleansed", "zgrief" };
/// <summary>
/// indicates if the given server is running a zombie game mode
@ -189,36 +208,25 @@ namespace SharedLibraryCore
public static bool IsCodGame(this Server server) => server.RconParser?.RConEngine == "COD";
/// <summary>
/// Get the IW Engine color code corresponding to an admin level
/// Get the color key corresponding to a given user level
/// </summary>
/// <param name="level">Specified player level</param>
/// <param name="localizedLevel"></param>
/// <returns></returns>
public static String ConvertLevelToColor(EFClient.Permission level, string localizedLevel)
public static string ConvertLevelToColor(Permission level, string localizedLevel)
{
char colorCode = '6';
// todo: maybe make this game independant?
switch (level)
// todo: make configurable
var colorCode = level switch
{
case EFClient.Permission.Banned:
colorCode = '1';
break;
case EFClient.Permission.Flagged:
colorCode = '9';
break;
case EFClient.Permission.Owner:
colorCode = '5';
break;
case EFClient.Permission.User:
colorCode = '2';
break;
case EFClient.Permission.Trusted:
colorCode = '3';
break;
default:
break;
}
Permission.Banned => "Red",
Permission.Flagged => "Map",
Permission.Owner => "Accent",
Permission.User => "Yellow",
Permission.Trusted => "Green",
_ => "Pink"
};
return $"^{colorCode}{localizedLevel ?? level.ToString()}";
return $"(Color::{colorCode}){localizedLevel ?? level.ToString()}";
}
public static string ToLocalizedLevelName(this Permission permission)