re-added the kill server command (can only be used if run as admin)

less warns when using a disposed socket
topstats added to tokens as {{TOPSTATS}}
fixed topstats reporting for only a single server
added fix to iw4 regex for negative score
tokens now support multiple lines (using Environment.NewLine to separate)
localization includes culture again
This commit is contained in:
RaidMax
2018-05-05 15:36:26 -05:00
parent 3092a529e9
commit e8dff01c41
36 changed files with 1209 additions and 1063 deletions

View File

@ -9,33 +9,51 @@ namespace IW4MAdmin.Application.Localization
{
public class Configure
{
public static void Initialize()
public static void Initialize(string customLocale)
{
string currentLocale = Program.ServerManager.GetApplicationSettings().Configuration()?.CustomLocale ??
CultureInfo.CurrentCulture?.Name?.Substring(0, 2);
string currentLocale = string.IsNullOrEmpty(customLocale) ? CultureInfo.CurrentCulture.Name : customLocale;
string[] localizationFiles = Directory.GetFiles("Localization", $"*.{currentLocale}.json");
// culture doesn't exist so we just want language
if (localizationFiles.Length == 0)
{
localizationFiles = Directory.GetFiles("Localization", $"*.{currentLocale.Substring(0, 2)}*.json");
}
// language doesn't exist either so defaulting to english
if (localizationFiles.Length == 0)
{
localizationFiles = Directory.GetFiles("Localization", "*.en-US.json");
}
// this should never happen unless the localization folder is empty
if (localizationFiles.Length == 0)
{
throw new Exception("No localization files were found");
}
var localizationDict = new Dictionary<string, string>();
foreach (string filePath in localizationFiles)
{
var localizationContents = File.ReadAllText(filePath, Encoding.UTF8);
var eachLocalizationFile = Newtonsoft.Json.JsonConvert.DeserializeObject<SharedLibraryCore.Localization.Layout>(localizationContents);
foreach (var item in eachLocalizationFile.LocalizationIndex.Set)
{
if (!localizationDict.TryAdd(item.Key, item.Value))
{
Program.ServerManager.GetLogger().WriteError($"Could not add locale string {item.Key} to localization");
}
}
}
if (currentLocale == null)
throw new Exception("Computer CurrentCulture does not exist");
#if DEBUG
// currentLocal = "ru-RU";
#endif
string localizationFile = $"Localization{Path.DirectorySeparatorChar}IW4MAdmin.{currentLocale}-{currentLocale.ToUpper()}.json";
string localizationContents;
if (File.Exists(localizationFile))
Utilities.CurrentLocalization = new SharedLibraryCore.Localization.Layout(localizationDict)
{
localizationContents = File.ReadAllText(localizationFile, Encoding.UTF8);
}
else
{
localizationFile = $"Localization{Path.DirectorySeparatorChar}IW4MAdmin.en-EN.json";
localizationContents = File.ReadAllText(localizationFile, Encoding.UTF8);
}
if (localizationContents.Length < 1)
throw new Exception($"Localization file {localizationFile} does not exist");
Utilities.CurrentLocalization = Newtonsoft.Json.JsonConvert.DeserializeObject<SharedLibraryCore.Localization.Layout>(localizationContents);
LocalizationName = currentLocale,
};
}
}
}