add localized level names

intellisense suggestion junk
This commit is contained in:
RaidMax 2018-08-03 21:11:58 -05:00
parent 3c0e101f14
commit bbade07646
23 changed files with 93 additions and 50 deletions

View File

@ -36,7 +36,7 @@ namespace IW4MAdmin.Application.API.Master
public class Endpoint
{
#if !DEBUG
private static IMasterApi api = RestClient.For<IMasterApi>("http://api.raidmax.org:5000");
private static readonly IMasterApi api = RestClient.For<IMasterApi>("http://api.raidmax.org:5000");
#else
private static IMasterApi api = RestClient.For<IMasterApi>("http://127.0.0.1");
#endif

View File

@ -11,7 +11,7 @@ namespace IW4MAdmin.Application.IO
Server Server;
long PreviousFileSize;
GameLogReader Reader;
string GameLogFile;
readonly string GameLogFile;
class EventState
{

View File

@ -10,7 +10,7 @@ namespace IW4MAdmin.Application.IO
class GameLogReader
{
IEventParser Parser;
string LogFile;
readonly string LogFile;
public GameLogReader(string logFile, IEventParser parser)
{

View File

@ -17,8 +17,8 @@ namespace IW4MAdmin.Application
Assert
}
string FileName;
object ThreadLock;
readonly string FileName;
readonly object ThreadLock;
public Logger(string fn)
{

View File

@ -36,12 +36,12 @@ namespace IW4MAdmin.Application
public DateTime StartTime { get; private set; }
static ApplicationManager Instance;
List<AsyncStatus> TaskStatuses;
readonly List<AsyncStatus> TaskStatuses;
List<Command> Commands;
List<MessageToken> MessageTokens;
readonly List<MessageToken> MessageTokens;
ClientService ClientSvc;
AliasService AliasSvc;
PenaltyService PenaltySvc;
readonly AliasService AliasSvc;
readonly PenaltyService PenaltySvc;
BaseConfigurationHandler<ApplicationConfiguration> ConfigHandler;
EventApi Api;
GameEventHandler Handler;

View File

@ -14,7 +14,7 @@ namespace Application.RconParsers
{
class IW4RConParser : IRConParser
{
private static CommandPrefix Prefixes = new CommandPrefix()
private static readonly CommandPrefix Prefixes = new CommandPrefix()
{
Tell = "tellraw {0} {1}",
Say = "sayraw {0}",
@ -23,7 +23,7 @@ namespace Application.RconParsers
TempBan = "tempbanclient {0} \"{1}\""
};
private static string StatusRegex = @"^( *[0-9]+) +-*([0-9]+) +((?:[A-Z]+|[0-9]+)) +((?:[a-z]|[0-9]){16}|(?:[a-z]|[0-9]){32}|bot[0-9]+|(?:[0-9]+)) *(.{0,32}) +([0-9]+) +(\d+\.\d+\.\d+.\d+\:-*\d{1,5}|0+.0+:-*\d{1,5}|loopback) +(-*[0-9]+) +([0-9]+) *$";
private static readonly string StatusRegex = @"^( *[0-9]+) +-*([0-9]+) +((?:[A-Z]+|[0-9]+)) +((?:[a-z]|[0-9]){16}|(?:[a-z]|[0-9]){32}|bot[0-9]+|(?:[0-9]+)) *(.{0,32}) +([0-9]+) +(\d+\.\d+\.\d+.\d+\:-*\d{1,5}|0+.0+:-*\d{1,5}|loopback) +(-*[0-9]+) +([0-9]+) *$";
public async Task<string[]> ExecuteCommandAsync(Connection connection, string command)
{

View File

@ -16,7 +16,7 @@ namespace Application.RconParsers
{
public class IW5MRConParser : IRConParser
{
private static CommandPrefix Prefixes = new CommandPrefix()
private static readonly CommandPrefix Prefixes = new CommandPrefix()
{
Tell = "tell {0} {1}",
Say = "say {0}",

View File

@ -52,7 +52,7 @@ namespace Application.RconParsers
public PInfo[] Players { get; set; }
}
private static CommandPrefix Prefixes = new CommandPrefix()
private static readonly CommandPrefix Prefixes = new CommandPrefix()
{
Tell = "tell {0} {1}",
Say = "say {0}",

View File

@ -223,9 +223,18 @@ namespace IW4MAdmin
$"{loc["SERVER_TB_REMAIN"]} ({(currentBan.Expires - DateTime.UtcNow).TimeSpanText()} {loc["WEBFRONT_PENALTY_TEMPLATE_REMAINING"]})");
await this.ExecuteCommandAsync(formattedKick);
}
// the player is permanently banned
else
await player.Kick($"{loc["SERVER_BAN_PREV"]} {currentBan.Offense} ({loc["SERVER_BAN_APPEAL"]} {Website})", autoKickClient);
{
// don't store the kick message
string formattedKick = String.Format(
RconParser.GetCommandPrefixes().Kick,
polledPlayer.ClientNumber,
$"{loc["SERVER_BAN_PREV"]} {currentBan.Offense} ({loc["SERVER_BAN_APPEAL"]} {Website})");
await this.ExecuteCommandAsync(formattedKick);
}
// reban the "evading" guid
if (player.Level != Player.Permission.Banned && currentBan.Type == Penalty.PenaltyType.Ban)
await player.Ban($"{currentBan.Offense}", autoKickClient);
@ -594,7 +603,6 @@ namespace IW4MAdmin
DateTime start = DateTime.Now;
DateTime playerCountStart = DateTime.Now;
DateTime lastCount = DateTime.Now;
DateTime tickTime = DateTime.Now;
override public async Task<bool> ProcessUpdatesAsync(CancellationToken cts)
{

View File

@ -30,7 +30,7 @@ namespace IW4MAdmin.Plugins.Stats.Cheat
long LastOffset;
ILogger Log;
Strain Strain;
DateTime ConnectionTime = DateTime.UtcNow;
readonly DateTime ConnectionTime = DateTime.UtcNow;
public Detection(ILogger log, EFClientStatistics clientStats)
{

View File

@ -99,7 +99,7 @@ namespace IW4MAdmin.Plugins.Welcome
private string ProcessAnnouncement(string msg, Player joining)
{
msg = msg.Replace("{{ClientName}}", joining.Name);
msg = msg.Replace("{{ClientLevel}}", Utilities.ConvertLevelToColor(joining.Level));
msg = msg.Replace("{{ClientLevel}}", Utilities.ConvertLevelToColor(joining.Level, joining.ClientPermission.Name));
try
{
CountryLookupProj.CountryLookup CLT = new CountryLookupProj.CountryLookup($"{Utilities.OperatingDirectory}Plugins{System.IO.Path.DirectorySeparatorChar}GeoIP.dat");

View File

@ -273,7 +273,7 @@ namespace SharedLibraryCore.Commands
public override async Task ExecuteAsync(GameEvent E)
{
String You = String.Format("{0} [^3#{1}^7] {2} [^3@{3}^7] [{4}^7] IP: {5}", E.Origin.Name, E.Origin.ClientNumber, E.Origin.NetworkId, E.Origin.ClientId, Utilities.ConvertLevelToColor(E.Origin.Level), E.Origin.IPAddressString);
String You = String.Format("{0} [^3#{1}^7] {2} [^3@{3}^7] [{4}^7] IP: {5}", E.Origin.Name, E.Origin.ClientNumber, E.Origin.NetworkId, E.Origin.ClientId, Utilities.ConvertLevelToColor(E.Origin.Level, E.Origin.ClientPermission.Name), E.Origin.IPAddressString);
await E.Origin.Tell(You);
}
}
@ -294,11 +294,11 @@ namespace SharedLibraryCore.Commands
if (P == null)
continue;
// todo: fix spacing
if (P.Masked)
playerList.AppendFormat("[^3{0}^7]{3}[^3{1}^7] {2}", Utilities.ConvertLevelToColor(Player.Permission.User), P.ClientNumber, P.Name, Utilities.GetSpaces(Player.Permission.SeniorAdmin.ToString().Length - Player.Permission.User.ToString().Length));
playerList.AppendFormat("[^3{0}^7]{3}[^3{1}^7] {2}", Utilities.ConvertLevelToColor(Player.Permission.User, P.ClientPermission.Name), P.ClientNumber, P.Name, Utilities.GetSpaces(Player.Permission.SeniorAdmin.ToString().Length - Player.Permission.User.ToString().Length));
else
playerList.AppendFormat("[^3{0}^7]{3}[^3{1}^7] {2}", Utilities.ConvertLevelToColor(P.Level), P.ClientNumber, P.Name, Utilities.GetSpaces(Player.Permission.SeniorAdmin.ToString().Length - P.Level.ToString().Length));
playerList.AppendFormat("[^3{0}^7]{3}[^3{1}^7] {2}", Utilities.ConvertLevelToColor(P.Level, P.ClientPermission.Name), P.ClientNumber, P.Name, Utilities.GetSpaces(Player.Permission.SeniorAdmin.ToString().Length - P.Level.ToString().Length));
if (count == 2 || E.Owner.GetPlayersAsList().Count == 1)
{
@ -536,7 +536,7 @@ namespace SharedLibraryCore.Commands
var onlineAdmins = S.GetPlayersAsList()
.Where(p => p.Level > Player.Permission.Flagged)
.Where(p => !p.Masked)
.Select(p => $"[^3{Utilities.ConvertLevelToColor(p.Level)}^7] {p.Name}");
.Select(p => $"[^3{Utilities.ConvertLevelToColor(p.Level, p.ClientPermission.Name)}^7] {p.Name}");
return onlineAdmins.Count() > 0 ?
string.Join(Environment.NewLine, onlineAdmins) :
@ -622,10 +622,11 @@ namespace SharedLibraryCore.Commands
foreach (var P in db_players)
{
string localizedLevel = Utilities.CurrentLocalization.LocalizationIndex[$"GLOBAL_PERMISSION_{P.Level.ToString().ToUpper()}"];
// they're not going by another alias
string msg = P.Name.ToLower().Contains(E.Data.ToLower()) ?
$"[^3{P.Name}^7] [^3@{P.ClientId}^7] - [{ Utilities.ConvertLevelToColor(P.Level)}^7] - {P.IPAddressString} | last seen {Utilities.GetTimePassed(P.LastConnection)}" :
$"({P.AliasLink.Children.First(a => a.Name.ToLower().Contains(E.Data.ToLower())).Name})->[^3{P.Name}^7] [^3@{P.ClientId}^7] - [{ Utilities.ConvertLevelToColor(P.Level)}^7] - {P.IPAddressString} | last seen {Utilities.GetTimePassed(P.LastConnection)}";
$"[^3{P.Name}^7] [^3@{P.ClientId}^7] - [{ Utilities.ConvertLevelToColor(P.Level, localizedLevel)}^7] - {P.IPAddressString} | last seen {Utilities.GetTimePassed(P.LastConnection)}" :
$"({P.AliasLink.Children.First(a => a.Name.ToLower().Contains(E.Data.ToLower())).Name})->[^3{P.Name}^7] [^3@{P.ClientId}^7] - [{ Utilities.ConvertLevelToColor(P.Level, localizedLevel)}^7] - {P.IPAddressString} | last seen {Utilities.GetTimePassed(P.LastConnection)}";
await E.Origin.Tell(msg);
}
}

View File

@ -11,7 +11,7 @@ namespace SharedLibraryCore
{
public class RemoteFile : IFile
{
string Location;
readonly string Location;
string[] FileCache = new string[0];
public RemoteFile(string location) : base(string.Empty)
@ -101,7 +101,7 @@ namespace SharedLibraryCore
//END
private long sze;
private String Name;
private readonly String Name;
private StreamReader Handle;
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;
using static SharedLibraryCore.Objects.Player;
namespace SharedLibraryCore.Objects
{
public sealed class ClientPermission
{
public Permission Level { get; set; }
public string Name { get; set; }
}
}

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;
@ -26,7 +27,7 @@ namespace SharedLibraryCore.Objects
SeniorAdmin = 5,
Owner = 6,
Creator = 7,
Console = 8,
Console = 8
}
public Player()
@ -102,8 +103,6 @@ namespace SharedLibraryCore.Objects
[NotMapped]
public int Score { get; set; }
[NotMapped]
public IList<Dtos.ProfileMeta> Meta { get; set; }
[NotMapped]
public bool IsBot { get; set; }
private int _ipaddress;
public override int IPAddress
@ -123,6 +122,14 @@ namespace SharedLibraryCore.Objects
public ClientState State { get; set; }
[NotMapped]
public Queue<GameEvent> DelayedEvents { get; set; }
[NotMapped]
// this is kinda dirty, but I need localizable level names
public ClientPermission ClientPermission => new ClientPermission()
{
Level = Level,
Name = Utilities.CurrentLocalization
.LocalizationIndex[$"GLOBAL_PERMISSION_{Level.ToString().ToUpper()}"]
};
public override bool Equals(object obj)
{

View File

@ -330,8 +330,8 @@ namespace SharedLibraryCore
protected ManualResetEventSlim OnRemoteCommandResponse;
// only here for performance
private bool CustomSayEnabled;
private string CustomSayName;
private readonly bool CustomSayEnabled;
private readonly string CustomSayName;
//Remote
public IList<CommandResponseInfo> CommandResult = new List<CommandResponseInfo>();

View File

@ -56,7 +56,8 @@ namespace SharedLibraryCore
String lookingFor = str.ToLower();
for (Player.Permission Perm = Player.Permission.User; Perm < Player.Permission.Console; Perm++)
if (lookingFor.Contains(Perm.ToString().ToLower()))
if (lookingFor.Contains(Perm.ToString().ToLower())
|| lookingFor.Contains(CurrentLocalization.LocalizationIndex[$"GLOBAL_PERMISSION_{Perm.ToString().ToUpper()}"].ToLower()))
return Perm;
return Player.Permission.Banned;
@ -83,25 +84,36 @@ namespace SharedLibraryCore
/// </summary>
/// <param name="level">Specified player level</param>
/// <returns></returns>
public static String ConvertLevelToColor(Player.Permission level)
public static String ConvertLevelToColor(Player.Permission level, string localizedLevel)
{
char colorCode = '6';
// todo: maybe make this game independant?
switch (level)
{
case Player.Permission.Banned:
return "^1" + Player.Permission.Banned;
colorCode = '1';
break;
case Player.Permission.Flagged:
return "^9" + Player.Permission.Flagged;
colorCode = '9';
break;
case Player.Permission.Owner:
return "^5" + Player.Permission.Owner;
colorCode = '5';
break;
case Player.Permission.User:
return "^2" + Player.Permission.User;
colorCode = '2';
break;
case Player.Permission.Trusted:
return "^3" + Player.Permission.Trusted;
colorCode = '3';
break;
default:
return "^6" + level;
break;
}
return $"^{colorCode}{localizedLevel ?? level.ToString()}";
}
public static string ToLocalizedLevelName(this Player.Permission perm) => CurrentLocalization.LocalizationIndex[$"GLOBAL_PERMISSION_{perm.ToString().ToUpper()}"];
public static String ProcessMessageToken(this Server server, IList<Helpers.MessageToken> tokens, String str)
{
MatchCollection RegexMatches = Regex.Matches(str, @"\{\{[A-Z]+\}\}", RegexOptions.IgnoreCase);

View File

@ -37,9 +37,9 @@ namespace WebfrontCore.Controllers.API
player.Name,
player.Score,
player.Ping,
player.State,
State = player.State.ToString(),
player.ClientNumber,
player.ConnectionTime,
ConnectionTime = (DateTime.UtcNow - player.ConnectionTime).TotalSeconds,
player.Level,
})
});

View File

@ -27,7 +27,7 @@ namespace WebfrontCore.Controllers
var clientDto = new PlayerInfo()
{
Name = client.Name,
Level = client.Level.ToString(),
Level = client.Level.ToLocalizedLevelName(),
LevelInt = (int)client.Level,
ClientId = client.ClientId,
IPAddress = client.IPAddressString,
@ -148,7 +148,7 @@ namespace WebfrontCore.Controllers
var clientsDto = clients.Select(c => new PlayerInfo()
{
Name = c.Name,
Level = c.Level.ToString(),
Level = c.Level.ToLocalizedLevelName(),
LevelInt = (int)c.Level,
ClientId = c.ClientId,
LastSeen = Utilities.GetTimePassed(c.LastConnection, false)

View File

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using SharedLibraryCore;
using SharedLibraryCore.Dtos;
using System;
using System.Collections.Generic;
@ -31,7 +32,7 @@ namespace WebfrontCore.Controllers
{
Name = p.Name,
ClientId = p.ClientId,
Level = p.Level.ToString(),
Level = p.Level.ToLocalizedLevelName(),
LevelInt = (int)p.Level
}).ToList(),
ChatHistory = s.ChatHistory,

View File

@ -14,7 +14,7 @@ namespace WebfrontCore
{
public class Startup
{
private IHostingEnvironment _appHost;
private readonly IHostingEnvironment _appHost;
public static IConfigurationRoot Configuration { get; private set; }
public Startup(IHostingEnvironment env)

View File

@ -20,7 +20,7 @@ namespace WebfrontCore.ViewComponents
OffenderName = p.Offender.Name,
PunisherId = p.PunisherId,
PunisherName = p.Punisher.Name,
PunisherLevel = p.Punisher.Level.ToString(),
PunisherLevel = p.Punisher.Level.ToLocalizedLevelName(),
#if DEBUG
Offense = !string.IsNullOrEmpty(p.AutomatedOffense) ? p.AutomatedOffense : p.Offense,
#else

View File

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using SharedLibraryCore;
using SharedLibraryCore.Dtos;
using System.Linq;
@ -24,7 +25,7 @@ namespace WebfrontCore.ViewComponents
{
Name = p.Name,
ClientId = p.ClientId,
Level = p.Level.ToString(),
Level = p.Level.ToLocalizedLevelName(),
LevelInt = (int)p.Level
}).ToList(),
ChatHistory = s.ChatHistory,