Skip to content

sharedlibrarycore Utilities

RaidMax edited this page May 21, 2023 · 1 revision

Utilities Public class

Diagram

  flowchart LR
  classDef interfaceStyle stroke-dasharray: 5 5;
  classDef abstractStyle stroke-width:4px
  subgraph SharedLibraryCore
  SharedLibraryCore.Utilities[[Utilities]]
  end
Loading

Members

Properties

Public Static properties

Type Name Methods
char CommandPrefix get, set
TimeSpan DefaultCommandTimeout get, set
ILogger DefaultLogger get, set
bool IsDevelopment
indicates if running in development mode
get
string OperatingDirectory get
Dictionary<Permission, string> PermissionLevelOverrides get

Methods

Public Static methods

Returns Name
IServiceCollection AddConfiguration(IServiceCollection serviceCollection, string fileName, TConfigurationType defaultConfig)
double``[] AngleStuff(Vector3 a, Vector3 b)
EFClient AsConsoleClient(IGameServer server)
string CapClientName(string name, int maxLength)
caps client name to the specified character length - 3
and adds ellipses to the end of the remaining client name
long ConvertGuidToLong(...)
string ConvertIPtoString(Nullable<int> ip)
string ConvertLevelToColor(Permission level, string localizedLevel)
Nullable<int> ConvertToIP(string str)
Dictionary<string, string> DictionaryFromKeyValue(string eventLine)
void ExecuteAfterDelay(...)
Task<string``[]> ExecuteCommandAsync(...)
string FindRuleForReason(string reason, ApplicationConfiguration appConfig, Server server)
string FixDirectoryCharacters(string path)
replaces any directory separator chars with the platform specific character
Vector3 FixIW4Angles(Vector3 vector)
string FixIW4ForwardSlash(string str)
returns a "fixed" string that prevents message truncation in IW4 (and probably other Q3 clients)
string FormatExt(string input, object``[] values)
string FormatMessageForEngine(string str, IRConParserConfiguration config)
string``[] FragmentMessageForDisplay(string message)
long GenerateGuidFromString(string value)
generates a numerical hashcode from a string value
string GetCommandLine(int pId)
Task<Dvar<T>> GetDvarAsync(...)
Task<string> GetExternalIP()
retrieves the external IP address of the current running machine
Game GetGame(string gameName)
Task<IDictionary<string, string>> GetInfoAsync(Server server, Nullable<TimeSpan> delay)
string GetLocalizedGametype(string input)
Get the full gametype name
Task<Dvar<T>> GetMappedDvarValueOrDefaultAsync(Server server, string dvarName, string infoResponseName, IDictionary<string, string> infoResponse, T overrideDefault, CancellationToken token)
int GetStableHashCode(string str)
Task<IStatusResponse> GetStatusAsync(Server server, CancellationToken token)
double GetVersionAsDouble()
string GetVersionAsString()
bool HasPermission(...)
string HumanizeForCurrentCulture(...)
wrapper method for humanizee that uses current current culture
EFClient IW4MAdminClient(Server server)
bool IsBotGuid(string guid)
determines if the guid provided appears to be a bot guid
"1277538174" - (Pluto?)WaW (T4)
bool IsBroadcastCommand(string str, string broadcastCommandPrefix)
bool IsCodGame(Server server)
bool IsInternal(IPAddress toTest)
https://stackoverflow.com/questions/8113546/how-to-determine-whether-an-ip-address-in-private/39120248
An extension method to determine if an IP address is internal, as specified in RFC1918
bool IsPrivileged(EFClient p)
Helper extension that determines if a user is a privileged client
bool IsQuickMessage(string message)
Determines if the given message is a quick message
bool IsRemoteLog(string log)
indicates if the given log path is a remote (http) uri
bool IsZombieServer(Server server)
indicates if the given server is running a zombie game mode
PenaltyType``[] LinkedPenaltyTypes()
returns a list of penalty types that should be shown across all profiles
string MakeAbbreviation(string gameName)
Permission MatchPermission(string str)
TimeSpan ParseTimespan(string input)
Task<string> ProcessMessageToken(Server server, IList<MessageToken> tokens, string str)
bool PromptBool(string question, string description, bool defaultValue)
prompt user to answer a yes/no question
int PromptInt(string question, string description, int minValue, int maxValue, Nullable<int> defaultValue)
(int Item1, T Item2) PromptSelection(string question, T defaultValue, string description, T``[] selections)
string PromptString(string question, string description, string defaultValue)
prompt use to enter a string response
string RemoveDiacritics(string text)
string RemoveWords(string str, int num)
Task SetDvarAsync(...)
bool ShouldHideLevel(Permission perm)
WebfrontTranslationHelper[] SplitTranslationTokens(string translationKey)
parses translation string into tokens that are able to be formatted by the webfront
string StripColors(string str)
Remove all IW Engine color codes
string ToBase64UrlSafeString(string src)
float ToDegrees(float value)
string ToLocalizedLevelName(Permission permission)
string ToNumericalString(...)
EFClient ToPartialClient(EFClient client)
float ToRadians(float value)
string ToStandardFormat(...)
string ToTranslatedName(MetaType metaType)
string TrimNewLine(string str)
trims new line and whitespace from string
Task<bool> TryCreatePenalty(EFPenalty penalty, IEntityService<EFPenalty> penaltyService, ILogger logger)
Task<T> WithTimeout(...)
Task WithWaitCancellation(...)
https://www.planetgeek.ch/2016/12/08/async-method-without-cancellation-support-do-it-my-way/

Internal Static methods

Returns Name
string [`g__InputOrDefault
string [`g__InputOrDefault

Details

Methods

ToStandardFormat [1/2]

Source code

public static string ToStandardFormat(Nullable<DateTime> time)
Arguments
Type Name Description
Nullable<DateTime> time

ToStandardFormat [2/2]

Source code

public static string ToStandardFormat(DateTime time)
Arguments
Type Name Description
DateTime time

IW4MAdminClient

Source code

public static EFClient IW4MAdminClient(Server server)
Arguments
Type Name Description
Server server

AsConsoleClient

Source code

public static EFClient AsConsoleClient(IGameServer server)
Arguments
Type Name Description
IGameServer server

RemoveWords

Source code

public static string RemoveWords(string str, int num)
Arguments
Type Name Description
string str
int num

CapClientName

Source code

public static string CapClientName(string name, int maxLength)
Arguments
Type Name Description
string name client name
int maxLength max number of characters for the name
Summary

caps client name to the specified character length - 3 and adds ellipses to the end of the remaining client name

Returns

MatchPermission

Source code

public static Permission MatchPermission(string str)
Arguments
Type Name Description
string str

StripColors

Source code

public static string StripColors(string str)
Arguments
Type Name Description
string str String containing color codes
Summary

Remove all IW Engine color codes

Returns

FixIW4ForwardSlash

Source code

public static string FixIW4ForwardSlash(string str)
Arguments
Type Name Description
string str
Summary

returns a "fixed" string that prevents message truncation in IW4 (and probably other Q3 clients)

Returns

RemoveDiacritics

Source code

public static string RemoveDiacritics(string text)
Arguments
Type Name Description
string text

FormatMessageForEngine

Source code

public static string FormatMessageForEngine(string str, IRConParserConfiguration config)
Arguments
Type Name Description
string str
IRConParserConfiguration config

IsZombieServer

Source code

public static bool IsZombieServer(Server server)
Arguments
Type Name Description
Server server
Summary

indicates if the given server is running a zombie game mode

Returns

IsCodGame

Source code

public static bool IsCodGame(Server server)
Arguments
Type Name Description
Server server

ConvertLevelToColor

Source code

public static string ConvertLevelToColor(Permission level, string localizedLevel)
Arguments
Type Name Description
Permission level
string localizedLevel

ToLocalizedLevelName

Source code

public static string ToLocalizedLevelName(Permission permission)
Arguments
Type Name Description
Permission permission

ProcessMessageToken

Source code

public static async Task<string> ProcessMessageToken(Server server, IList<MessageToken> tokens, string str)
Arguments
Type Name Description
Server server
IList<MessageToken> tokens
string str

IsBroadcastCommand

Source code

public static bool IsBroadcastCommand(string str, string broadcastCommandPrefix)
Arguments
Type Name Description
string str
string broadcastCommandPrefix

GetLocalizedGametype

Source code

public static string GetLocalizedGametype(string input)
Arguments
Type Name Description
string input Shorthand gametype reported from server
Summary

Get the full gametype name

Returns

ConvertGuidToLong [1/2]

Source code

public static long ConvertGuidToLong(string str, NumberStyles numberStyle, Nullable<long> fallback)
Arguments
Type Name Description
string str
NumberStyles numberStyle
Nullable<long> fallback

ConvertGuidToLong [2/2]

Source code

public static long ConvertGuidToLong(string str, NumberStyles numberStyle, bool convertSigned, Nullable<long> fallback)
Arguments
Type Name Description
string str
NumberStyles numberStyle
bool convertSigned
Nullable<long> fallback

IsBotGuid

Source code

public static bool IsBotGuid(string guid)
Arguments
Type Name Description
string guid value of the guid
Summary

determines if the guid provided appears to be a bot guid "1277538174" - (Pluto?)WaW (T4)

Returns

true if is bot guid, otherwise false

GenerateGuidFromString

Source code

public static long GenerateGuidFromString(string value)
Arguments
Type Name Description
string value value string
Summary

generates a numerical hashcode from a string value

Returns

GetStableHashCode

Source code

public static int GetStableHashCode(string str)
Arguments
Type Name Description
string str

ConvertToIP

Source code

public static Nullable<int> ConvertToIP(string str)
Arguments
Type Name Description
string str

ConvertIPtoString

Source code

public static string ConvertIPtoString(Nullable<int> ip)
Arguments
Type Name Description
Nullable<int> ip

GetGame

Source code

public static Game GetGame(string gameName)
Arguments
Type Name Description
string gameName

ParseTimespan

Source code

public static TimeSpan ParseTimespan(string input)
Arguments
Type Name Description
string input

HasPermission [1/2]

Source code

public static bool HasPermission<TEntity, TPermission>(IEnumerable<string> permissionsSet, TEntity entity, TPermission permission)
where TEntity : Enum
where TPermission : Enum
Arguments
Type Name Description
IEnumerable<string> permissionsSet
TEntity entity
TPermission permission

HasPermission [2/2]

Source code

public static bool HasPermission<TEntity, TPermission>(ApplicationConfiguration appConfig, Permission permissionLevel, TEntity entity, TPermission permission)
where TEntity : Enum
where TPermission : Enum
Arguments
Type Name Description
ApplicationConfiguration appConfig
Permission permissionLevel
TEntity entity
TPermission permission

LinkedPenaltyTypes

Source code

public static PenaltyType LinkedPenaltyTypes()
Summary

returns a list of penalty types that should be shown across all profiles

Returns

IsPrivileged

Source code

public static bool IsPrivileged(EFClient p)
Arguments
Type Name Description
EFClient p
Summary

Helper extension that determines if a user is a privileged client

Returns

PromptBool

Source code

public static bool PromptBool(string question, string description, bool defaultValue)
Arguments
Type Name Description
string question question to prompt the user with
string description description of the question's value
bool defaultValue default value to set if no input is entered
Summary

prompt user to answer a yes/no question

Returns

PromptSelection

Source code

public static Tuple<int,T> PromptSelection<T>(string question, T defaultValue, string description, T[] selections)
where T : 
Arguments
Type Name Description
string question
T defaultValue
string description
T``[] selections

PromptInt

Source code

public static int PromptInt(string question, string description, int minValue, int maxValue, Nullable<int> defaultValue)
Arguments
Type Name Description
string question
string description
int minValue
int maxValue
Nullable<int> defaultValue

PromptString

Source code

public static string PromptString(string question, string description, string defaultValue)
Arguments
Type Name Description
string question question to prompt with
string description description of the question's value
string defaultValue default value to set the return value to
Summary

prompt use to enter a string response

Returns

DictionaryFromKeyValue

Source code

public static Dictionary<string, string> DictionaryFromKeyValue(string eventLine)
Arguments
Type Name Description
string eventLine

GetCommandLine

Source code

public static string GetCommandLine(int pId)
Arguments
Type Name Description
int pId

IsRemoteLog

Source code

public static bool IsRemoteLog(string log)
Arguments
Type Name Description
string log
Summary

indicates if the given log path is a remote (http) uri

Returns

ToBase64UrlSafeString

Source code

public static string ToBase64UrlSafeString(string src)
Arguments
Type Name Description
string src

GetDvarAsync [1/2]

Source code

public static async Task<Dvar<T>> GetDvarAsync<T>(Server server, string dvarName, T fallbackValue, CancellationToken token)
where T : 
Arguments
Type Name Description
Server server
string dvarName
T fallbackValue
CancellationToken token

GetDvarAsync [2/2]

Source code

public static async Task<Dvar<T>> GetDvarAsync<T>(Server server, string dvarName, T fallbackValue)
where T : 
Arguments
Type Name Description
Server server
string dvarName
T fallbackValue

GetMappedDvarValueOrDefaultAsync

Source code

public static async Task<Dvar<T>> GetMappedDvarValueOrDefaultAsync<T>(Server server, string dvarName, string infoResponseName, IDictionary<string, string> infoResponse, T overrideDefault, CancellationToken token)
where T : 
Arguments
Type Name Description
Server server
string dvarName
string infoResponseName
IDictionary<string, string> infoResponse
T overrideDefault
CancellationToken token

SetDvarAsync [1/2]

Source code

public static async Task SetDvarAsync(Server server, string dvarName, object dvarValue, CancellationToken token)
Arguments
Type Name Description
Server server
string dvarName
object dvarValue
CancellationToken token

SetDvarAsync [2/2]

Source code

public static async Task SetDvarAsync(Server server, string dvarName, object dvarValue)
Arguments
Type Name Description
Server server
string dvarName
object dvarValue

ExecuteCommandAsync [1/2]

Source code

public static async Task<string> ExecuteCommandAsync(Server server, string commandName, CancellationToken token)
Arguments
Type Name Description
Server server
string commandName
CancellationToken token

ExecuteCommandAsync [2/2]

public static async Task<string> ExecuteCommandAsync(Server server, string commandName)
Arguments
Type Name Description
Server server
string commandName

GetStatusAsync

Source code

public static async Task<IStatusResponse> GetStatusAsync(Server server, CancellationToken token)
Arguments
Type Name Description
Server server
CancellationToken token

GetInfoAsync

public static async Task<IDictionary<string, string>> GetInfoAsync(Server server, Nullable<TimeSpan> delay)
Arguments
Type Name Description
Server server
Nullable<TimeSpan> delay

GetVersionAsDouble

Source code

public static double GetVersionAsDouble()

GetVersionAsString

Source code

public static string GetVersionAsString()

FormatExt

Source code

public static string FormatExt(string input, object[] values)
Arguments
Type Name Description
string input
object``[] values

IsInternal

Source code

public static bool IsInternal(IPAddress toTest)
Arguments
Type Name Description
IPAddress toTest The IP address that will be tested
Summary

https://stackoverflow.com/questions/8113546/how-to-determine-whether-an-ip-address-in-private/39120248 An extension method to determine if an IP address is internal, as specified in RFC1918

Returns

Returns true if the IP is internal, false if it is external

GetExternalIP

Source code

public static async Task<string> GetExternalIP()
Summary

retrieves the external IP address of the current running machine

Returns

IsQuickMessage

Source code

public static bool IsQuickMessage(string message)
Arguments
Type Name Description
string message
Summary

Determines if the given message is a quick message

Returns

true if the

TrimNewLine

Source code

public static string TrimNewLine(string str)
Arguments
Type Name Description
string str source string
Summary

trims new line and whitespace from string

Returns

FixIW4Angles

Source code

public static Vector3 FixIW4Angles(Vector3 vector)
Arguments
Type Name Description
Vector3 vector

ToRadians

Source code

public static float ToRadians(float value)
Arguments
Type Name Description
float value

ToDegrees

Source code

public static float ToDegrees(float value)
Arguments
Type Name Description
float value

AngleStuff

Source code

public static double AngleStuff(Vector3 a, Vector3 b)
Arguments
Type Name Description
Vector3 a
Vector3 b

TryCreatePenalty

Source code

public static async Task<bool> TryCreatePenalty(EFPenalty penalty, IEntityService<EFPenalty> penaltyService, ILogger logger)
Arguments
Type Name Description
EFPenalty penalty
IEntityService<EFPenalty> penaltyService
ILogger logger

WithWaitCancellation [1/2]

Source code

public static async Task WithWaitCancellation(Task task, CancellationToken cancellationToken)
Arguments
Type Name Description
Task task
CancellationToken cancellationToken
Summary

https://www.planetgeek.ch/2016/12/08/async-method-without-cancellation-support-do-it-my-way/

WithWaitCancellation [2/2]

Source code

public static async Task<T> WithWaitCancellation<T>(Task<T> task, CancellationToken cancellationToken)
where T : 
Arguments
Type Name Description
Task<T> task
CancellationToken cancellationToken

WithTimeout [1/2]

Source code

public static async Task<T> WithTimeout<T>(Task<T> task, TimeSpan timeout)
where T : 
Arguments
Type Name Description
Task<T> task
TimeSpan timeout

WithTimeout [2/2]

Source code

public static async Task WithTimeout(Task task, TimeSpan timeout)
Arguments
Type Name Description
Task task
TimeSpan timeout

ShouldHideLevel

Source code

public static bool ShouldHideLevel(Permission perm)
Arguments
Type Name Description
Permission perm

SplitTranslationTokens

Source code

public static WebfrontTranslationHelper SplitTranslationTokens(string translationKey)
Arguments
Type Name Description
string translationKey key for translation lookup
Summary

parses translation string into tokens that are able to be formatted by the webfront

Returns

FixDirectoryCharacters

Source code

public static string FixDirectoryCharacters(string path)
Arguments
Type Name Description
string path original file path
Summary

replaces any directory separator chars with the platform specific character

Returns

HumanizeForCurrentCulture [1/2]

Source code

public static string HumanizeForCurrentCulture(TimeSpan timeSpan, int precision, TimeUnit maxUnit, TimeUnit minUnit, string collectionSeparator, bool toWords)
Arguments
Type Name Description
TimeSpan timeSpan
int precision
TimeUnit maxUnit
TimeUnit minUnit
string collectionSeparator
bool toWords
Summary

wrapper method for humanizee that uses current current culture

HumanizeForCurrentCulture [2/2]

Source code

public static string HumanizeForCurrentCulture(DateTime input, bool utcDate, Nullable<DateTime> dateToCompareAgainst, CultureInfo culture)
Arguments
Type Name Description
DateTime input
bool utcDate
Nullable<DateTime> dateToCompareAgainst
CultureInfo culture

ToTranslatedName

Source code

public static string ToTranslatedName(MetaType metaType)
Arguments
Type Name Description
MetaType metaType

ToPartialClient

Source code

public static EFClient ToPartialClient(EFClient client)
Arguments
Type Name Description
EFClient client

ToNumericalString [1/4]

Source code

public static string ToNumericalString(Nullable<int> value)
Arguments
Type Name Description
Nullable<int> value

ToNumericalString [2/4]

Source code

public static string ToNumericalString(int value)
Arguments
Type Name Description
int value

ToNumericalString [3/4]

Source code

public static string ToNumericalString(double value, int precision)
Arguments
Type Name Description
double value
int precision

ToNumericalString [4/4]

Source code

public static string ToNumericalString(Nullable<double> value, int precision)
Arguments
Type Name Description
Nullable<double> value
int precision

FragmentMessageForDisplay

Source code

public static string FragmentMessageForDisplay(string message)
Arguments
Type Name Description
string message

FindRuleForReason

Source code

public static string FindRuleForReason(string reason, ApplicationConfiguration appConfig, Server server)
Arguments
Type Name Description
string reason
ApplicationConfiguration appConfig
Server server

MakeAbbreviation

Source code

public static string MakeAbbreviation(string gameName)
Arguments
Type Name Description
string gameName

AddConfiguration

Source code

public static IServiceCollection AddConfiguration<TConfigurationType>(IServiceCollection serviceCollection, string fileName, TConfigurationType defaultConfig)
where TConfigurationType : 
Arguments
Type Name Description
IServiceCollection serviceCollection
string fileName
TConfigurationType defaultConfig

ExecuteAfterDelay [1/3]

Source code

public static void ExecuteAfterDelay(TimeSpan duration, Func<CancellationToken, Task> action, CancellationToken token)
Arguments
Type Name Description
TimeSpan duration
Func<CancellationToken, Task> action
CancellationToken token

ExecuteAfterDelay [2/3]

Source code

public static void ExecuteAfterDelay(int delayMs, Func<CancellationToken, Task> action, CancellationToken token)
Arguments
Type Name Description
int delayMs
Func<CancellationToken, Task> action
CancellationToken token

ExecuteAfterDelay [3/3]

Source code

public static void ExecuteAfterDelay(Func<CancellationToken, Task> action, int delayMs, CancellationToken token)
Arguments
Type Name Description
Func<CancellationToken, Task> action
int delayMs
CancellationToken token

g__InputOrDefault|55_0

Source code

internal static string <PromptInt>g__InputOrDefault|55_0()

g__InputOrDefault|56_0

Source code

internal static string <PromptString>g__InputOrDefault|56_0()

Properties

DefaultLogger

public static ILogger DefaultLogger { get; set; }

OperatingDirectory

public static string OperatingDirectory { get; }

DefaultCommandTimeout

public static TimeSpan DefaultCommandTimeout { get; set; }

CommandPrefix

public static char CommandPrefix { get; set; }

PermissionLevelOverrides

public static Dictionary<Permission, string> PermissionLevelOverrides { get; }

IsDevelopment

public static bool IsDevelopment { get; }
Summary

indicates if running in development mode

Generated with ModularDoc

Clone this wiki locally