mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-26 07:29:00 -07:00
168 lines
4.0 KiB
C#
168 lines
4.0 KiB
C#
using System.Text;
|
|
using RadicadeServer.RecNet.Enums;
|
|
using RadicadeServer.RecNet;
|
|
using System.Buffers.Text;
|
|
using System.Security.Cryptography;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace RadicadeServer.Utils
|
|
{
|
|
public static class StringTools
|
|
{
|
|
public static string AltGuid(this Guid guid)
|
|
{
|
|
return guid.ToString().Replace("-", "");
|
|
}
|
|
|
|
public static string FromAES(this string encrypted, string? b64Key, string? b64IV)
|
|
{
|
|
if (string.IsNullOrEmpty(b64Key)) return "";
|
|
if (string.IsNullOrEmpty(b64IV)) return "";
|
|
|
|
try
|
|
{
|
|
byte[] cipherBytes = Convert.FromBase64String(encrypted);
|
|
byte[] keyBytes = Convert.FromBase64String(b64Key);
|
|
byte[] ivBytes = Convert.FromBase64String(b64IV);
|
|
|
|
using (Aes aes = Aes.Create())
|
|
{
|
|
aes.KeySize = 128;
|
|
aes.BlockSize = 128;
|
|
aes.Key = keyBytes;
|
|
aes.IV = ivBytes;
|
|
aes.Mode = CipherMode.CBC;
|
|
aes.Padding = PaddingMode.PKCS7;
|
|
|
|
using (MemoryStream ms = new MemoryStream(cipherBytes))
|
|
using (CryptoStream cs = new CryptoStream(ms, aes.CreateDecryptor(), CryptoStreamMode.Read))
|
|
using (StreamReader sr = new StreamReader(cs, Encoding.UTF8))
|
|
{
|
|
return sr.ReadToEnd();
|
|
}
|
|
}
|
|
} catch
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
|
|
public static List<CardBoxWord> ParseCardBoxWords(this string req)
|
|
{
|
|
var split = req.Split(';', StringSplitOptions.TrimEntries);
|
|
var words = new List<CardBoxWord>();
|
|
|
|
foreach (var word in split)
|
|
{
|
|
words.Add(new CardBoxWord { Difficulty = CardDifficulty.CharadesEasy, EN_US = word });
|
|
}
|
|
|
|
return words;
|
|
}
|
|
|
|
public static string CreateTagString(List<ItemTag>? Tags)
|
|
{
|
|
if (Tags == null)
|
|
return "";
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
foreach (ItemTag itemTag in Tags)
|
|
{
|
|
stringBuilder.Append(itemTag.Tag.ToString() + "," + ((int)itemTag.Type).ToString() + "|");
|
|
}
|
|
return stringBuilder.ToString().TrimEnd('|');
|
|
}
|
|
|
|
public static string CreateTagString(string[]? Tags)
|
|
{
|
|
if (Tags == null)
|
|
return "";
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
foreach (string itemTag in Tags)
|
|
{
|
|
stringBuilder.Append(itemTag.ToString() + "," + ((int)TagType.General).ToString() + "|");
|
|
}
|
|
return stringBuilder.ToString().TrimEnd('|');
|
|
}
|
|
|
|
public static List<ItemTag> ReadTags(string Tags)
|
|
{
|
|
List<ItemTag> list = new List<ItemTag>();
|
|
if (string.IsNullOrWhiteSpace(Tags)) return list;
|
|
string[] tags = Tags.Split("|", StringSplitOptions.None);
|
|
foreach (string text in tags)
|
|
{
|
|
string[] array3 = text.Split(",", StringSplitOptions.None);
|
|
if (array3.Length != 2) continue;
|
|
if (!int.TryParse(array3[1], out var typeValue) || !Enum.IsDefined(typeof(TagType), typeValue))
|
|
continue;
|
|
list.Add(new ItemTag
|
|
{
|
|
Tag = array3[0],
|
|
Type = (TagType)typeValue
|
|
});
|
|
}
|
|
return list;
|
|
}
|
|
|
|
public static List<string> TagsToStrings(List<ItemTag> Tags)
|
|
{
|
|
List<string> list = new List<string>();
|
|
foreach (var tag in Tags)
|
|
{
|
|
list.Add(tag.Tag);
|
|
}
|
|
return list;
|
|
}
|
|
|
|
public static string ToBase64(this string str)
|
|
{
|
|
var bytes = System.Text.Encoding.UTF8.GetBytes(str);
|
|
var b64 = Convert.ToBase64String(bytes);
|
|
return b64;
|
|
}
|
|
|
|
|
|
private static string[] BlacklistedWords = {
|
|
"nigger",
|
|
"nigga",
|
|
"faggot",
|
|
"fag",
|
|
"nigg",
|
|
};
|
|
private static string[] BlacklistedTags = {
|
|
"rro",
|
|
"featured"
|
|
};
|
|
|
|
public static string Sanitize(this string str)
|
|
{
|
|
foreach (var tag in BlacklistedWords)
|
|
{
|
|
str = Regex.Replace(str, tag, "****", RegexOptions.IgnoreCase);
|
|
}
|
|
return str;
|
|
}
|
|
public static bool IsPure(this string str)
|
|
{
|
|
if (string.IsNullOrEmpty(str)) return true;
|
|
|
|
foreach (var tag in BlacklistedWords)
|
|
{
|
|
if (Regex.IsMatch(str, tag, RegexOptions.IgnoreCase))
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public static bool TagAllowed(this string str)
|
|
{
|
|
foreach (var tag in BlacklistedTags) {
|
|
if (Regex.IsMatch(tag, str))
|
|
return false;
|
|
}
|
|
return str.IsPure();
|
|
}
|
|
}
|
|
}
|