2017-05-26 18:49:27 -04:00
|
|
|
|
using System;
|
2015-08-20 01:06:44 -04:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace SharedLibrary
|
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
public static class Utilities
|
2015-08-20 01:06:44 -04:00
|
|
|
|
{
|
|
|
|
|
//Get string with specified number of spaces -- really only for visual output
|
|
|
|
|
public static String getSpaces(int Num)
|
|
|
|
|
{
|
|
|
|
|
String SpaceString = String.Empty;
|
|
|
|
|
while (Num > 0)
|
|
|
|
|
{
|
|
|
|
|
SpaceString += ' ';
|
|
|
|
|
Num--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return SpaceString;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Sleep for x amount of seconds
|
|
|
|
|
public static void Wait(double time)
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep((int)Math.Ceiling(time * 1000));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Remove words from a space delimited string
|
2017-05-26 18:49:27 -04:00
|
|
|
|
public static String RemoveWords(this string str, int num)
|
2015-08-20 01:06:44 -04:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
if (str == null || str.Length == 0)
|
|
|
|
|
return "";
|
|
|
|
|
|
2015-08-20 01:06:44 -04:00
|
|
|
|
String newStr = String.Empty;
|
|
|
|
|
String[] tmp = str.Split(' ');
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < tmp.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (i >= num)
|
|
|
|
|
newStr += tmp[i] + ' ';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newStr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Player.Permission matchPermission(String str)
|
|
|
|
|
{
|
|
|
|
|
String lookingFor = str.ToLower();
|
2015-10-10 19:31:24 -04:00
|
|
|
|
#if REPZ_BUILD
|
|
|
|
|
for (Player.Permission Perm = Player.Permission.User; Perm <= Player.Permission.Owner; Perm++)
|
|
|
|
|
#else
|
2015-08-20 01:06:44 -04:00
|
|
|
|
for (Player.Permission Perm = Player.Permission.User; Perm < Player.Permission.Owner; Perm++)
|
2015-10-10 19:31:24 -04:00
|
|
|
|
#endif
|
2015-08-20 01:06:44 -04:00
|
|
|
|
{
|
|
|
|
|
if (lookingFor.Contains(Perm.ToString().ToLower()))
|
|
|
|
|
return Perm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Player.Permission.Banned;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String removeNastyChars(String str)
|
|
|
|
|
{
|
|
|
|
|
if (str != null)
|
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return str.Replace("`", "").Replace("\\", "").Replace("\"", "").Replace(""", "").Replace("&", "&").Replace("\"", "''").Replace("'", "").Replace("?", "");
|
2015-08-20 01:06:44 -04:00
|
|
|
|
}
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
return String.Empty;
|
2015-08-20 01:06:44 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
public static String CleanChars(this string S)
|
2015-08-20 01:06:44 -04:00
|
|
|
|
{
|
|
|
|
|
if (S == null)
|
|
|
|
|
return "";
|
|
|
|
|
|
|
|
|
|
StringBuilder Cleaned = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
foreach (char c in S)
|
|
|
|
|
if (c < 127 && c > 31 && c != 37 && c != 34 && c != 92) Cleaned.Append(c);
|
|
|
|
|
return Cleaned.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-23 17:58:48 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Remove all IW Engine color codes
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="str">String containing color codes</param>
|
|
|
|
|
/// <returns></returns>
|
2017-05-26 18:49:27 -04:00
|
|
|
|
public static String StripColors(this string str)
|
2015-08-20 01:06:44 -04:00
|
|
|
|
{
|
|
|
|
|
if (str == null)
|
|
|
|
|
return "";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return Regex.Replace(str, @"\^([0-9]|\:)", "");
|
2015-08-20 01:06:44 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-23 17:58:48 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Get the IW Engine color code corresponding to an admin level
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="level">Specified player level</param>
|
|
|
|
|
/// <returns></returns>
|
2015-08-20 01:06:44 -04:00
|
|
|
|
public static String levelToColor(Player.Permission level)
|
|
|
|
|
{
|
|
|
|
|
switch (level)
|
|
|
|
|
{
|
|
|
|
|
case Player.Permission.Banned:
|
|
|
|
|
return "^1" + Player.Permission.Banned;
|
|
|
|
|
case Player.Permission.Flagged:
|
2016-01-16 17:58:24 -05:00
|
|
|
|
return "^9" + Player.Permission.Flagged;
|
2015-08-20 01:06:44 -04:00
|
|
|
|
case Player.Permission.Owner:
|
|
|
|
|
return "^5" + Player.Permission.Owner;
|
|
|
|
|
case Player.Permission.User:
|
|
|
|
|
return "^2" + Player.Permission.User;
|
2016-01-16 17:58:24 -05:00
|
|
|
|
case Player.Permission.Trusted:
|
|
|
|
|
return "^3" + Player.Permission.Trusted;
|
2015-08-20 01:06:44 -04:00
|
|
|
|
default:
|
2016-01-16 17:58:24 -05:00
|
|
|
|
return "^6" + level;
|
2015-08-20 01:06:44 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
public static String LoadMacro(Dictionary<String, Object> Dict, String str)
|
2015-08-20 01:06:44 -04:00
|
|
|
|
{
|
|
|
|
|
MatchCollection Found = Regex.Matches(str, @"\{\{[A-Z]+\}\}", RegexOptions.IgnoreCase);
|
|
|
|
|
foreach (Match M in Found)
|
|
|
|
|
{
|
|
|
|
|
String Match = M.Value;
|
|
|
|
|
String Identifier = M.Value.Substring(2, M.Length - 4);
|
2015-08-22 02:04:30 -04:00
|
|
|
|
Object foundVal;
|
|
|
|
|
Dict.TryGetValue(Identifier, out foundVal);
|
|
|
|
|
String Replacement;
|
|
|
|
|
|
|
|
|
|
if (foundVal != null)
|
|
|
|
|
Replacement = foundVal.ToString();
|
|
|
|
|
else
|
|
|
|
|
Replacement = "";
|
|
|
|
|
|
2015-08-20 01:06:44 -04:00
|
|
|
|
str = str.Replace(Match, Replacement);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-23 17:58:48 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Get the full gametype name
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input">Shorthand gametype reported from server</param>
|
|
|
|
|
/// <returns></returns>
|
2015-08-20 01:06:44 -04:00
|
|
|
|
public static String gametypeLocalized(String input)
|
|
|
|
|
{
|
|
|
|
|
switch (input)
|
|
|
|
|
{
|
|
|
|
|
case "dm":
|
|
|
|
|
return "Deathmatch";
|
|
|
|
|
case "war":
|
|
|
|
|
return "Team Deathmatch";
|
|
|
|
|
case "koth":
|
|
|
|
|
return "Headquarters";
|
|
|
|
|
case "ctf":
|
|
|
|
|
return "Capture The Flag";
|
|
|
|
|
case "dd":
|
|
|
|
|
return "Demolition";
|
|
|
|
|
case "dom":
|
|
|
|
|
return "Domination";
|
|
|
|
|
case "sab":
|
|
|
|
|
return "Sabotage";
|
|
|
|
|
case "sd":
|
|
|
|
|
return "Search & Destroy";
|
|
|
|
|
case "vip":
|
|
|
|
|
return "Very Important Person";
|
|
|
|
|
case "gtnw":
|
|
|
|
|
return "Global Thermonuclear War";
|
|
|
|
|
case "oitc":
|
|
|
|
|
return "One In The Chamber";
|
|
|
|
|
case "arena":
|
|
|
|
|
return "Arena";
|
|
|
|
|
case "dzone":
|
|
|
|
|
return "Drop Zone";
|
|
|
|
|
case "gg":
|
|
|
|
|
return "Gun Game";
|
|
|
|
|
case "snipe":
|
|
|
|
|
return "Sniping";
|
|
|
|
|
case "ss":
|
|
|
|
|
return "Sharp Shooter";
|
|
|
|
|
case "m40a3":
|
|
|
|
|
return "M40A3";
|
|
|
|
|
case "fo":
|
|
|
|
|
return "Face Off";
|
|
|
|
|
case "dmc":
|
|
|
|
|
return "Deathmatch Classic";
|
|
|
|
|
case "killcon":
|
|
|
|
|
return "Kill Confirmed";
|
|
|
|
|
case "oneflag":
|
|
|
|
|
return "One Flag CTF";
|
|
|
|
|
default:
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return input;
|
2015-08-20 01:06:44 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String DateTimeSQLite(DateTime datetime)
|
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return datetime.ToString("yyyy-MM-dd H:mm:ss");
|
2015-08-20 01:06:44 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String timePassed(DateTime start)
|
|
|
|
|
{
|
|
|
|
|
TimeSpan Elapsed = DateTime.Now - start;
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
if (Elapsed.TotalSeconds < 30)
|
|
|
|
|
return "just now";
|
2015-08-20 01:06:44 -04:00
|
|
|
|
if (Elapsed.TotalMinutes < 120)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
if (Elapsed.TotalMinutes < 1.5)
|
|
|
|
|
return "1 minute";
|
2015-08-20 01:06:44 -04:00
|
|
|
|
return Math.Round(Elapsed.TotalMinutes, 0) + " minutes";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
2015-08-20 01:06:44 -04:00
|
|
|
|
if (Elapsed.TotalHours <= 24)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
if (Elapsed.TotalHours < 1.5)
|
|
|
|
|
return "1 hour";
|
2015-08-20 01:06:44 -04:00
|
|
|
|
return Math.Round(Elapsed.TotalHours, 0) + " hours";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
2015-08-20 01:06:44 -04:00
|
|
|
|
if (Elapsed.TotalDays <= 365)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
if (Elapsed.TotalDays < 1.5)
|
|
|
|
|
return "1 day";
|
2015-08-20 01:06:44 -04:00
|
|
|
|
return Math.Round(Elapsed.TotalDays, 0) + " days";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
2015-08-20 01:06:44 -04:00
|
|
|
|
else
|
|
|
|
|
return "a very long time";
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
public static String TimesConnected(this Player P)
|
2015-08-20 01:06:44 -04:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
int connection = P.Connections;
|
2015-08-20 01:06:44 -04:00
|
|
|
|
String Prefix = String.Empty;
|
|
|
|
|
if (connection % 10 > 3 || connection % 10 == 0 || (connection % 100 > 9 && connection % 100 < 19))
|
|
|
|
|
Prefix = "th";
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
switch (connection % 10)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
Prefix = "st";
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
Prefix = "nd";
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
Prefix = "rd";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (connection)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
case 1:
|
|
|
|
|
return "first";
|
|
|
|
|
case 2:
|
|
|
|
|
return "second";
|
|
|
|
|
case 3:
|
|
|
|
|
return "third";
|
|
|
|
|
case 4:
|
|
|
|
|
return "fourth";
|
|
|
|
|
case 5:
|
|
|
|
|
return "fifth";
|
|
|
|
|
case 100:
|
|
|
|
|
return "One-Hundreth (amazing!)";
|
2015-08-23 17:58:48 -04:00
|
|
|
|
case 500:
|
|
|
|
|
return "^7You're really ^5dedicated ^7to this server! This is your ^5500th ^7time connecting!";
|
2016-01-16 17:58:24 -05:00
|
|
|
|
case 1000:
|
|
|
|
|
return "WOW! Soldier, it's your ^11000th ^7time connecting! You deserve a medal.";
|
|
|
|
|
|
2015-08-20 01:06:44 -04:00
|
|
|
|
default:
|
|
|
|
|
return connection.ToString() + Prefix;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|