Skip to content

Commit

Permalink
fix IW4x regression error with alternative encodings
Browse files Browse the repository at this point in the history
add parser selection to server config setup
  • Loading branch information
RaidMax committed Feb 5, 2019
1 parent 54147e2 commit 0a85d88
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 29 deletions.
6 changes: 3 additions & 3 deletions Application/Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<RuntimeFrameworkVersion>2.1.5</RuntimeFrameworkVersion>
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
<PackageId>RaidMax.IW4MAdmin.Application</PackageId>
<Version>2.2.4.3</Version>
<Version>2.2.4.4</Version>
<Authors>RaidMax</Authors>
<Company>Forever None</Company>
<Product>IW4MAdmin</Product>
Expand All @@ -31,8 +31,8 @@
<PropertyGroup>
<ServerGarbageCollection>true</ServerGarbageCollection>
<TieredCompilation>true</TieredCompilation>
<AssemblyVersion>2.2.4.3</AssemblyVersion>
<FileVersion>2.2.4.3</FileVersion>
<AssemblyVersion>2.2.4.4</AssemblyVersion>
<FileVersion>2.2.4.4</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
50 changes: 31 additions & 19 deletions Application/ApplicationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,25 @@ public async Task Init()
{
Running = true;


#region PLUGINS
SharedLibraryCore.Plugins.PluginImporter.Load(this);

foreach (var Plugin in SharedLibraryCore.Plugins.PluginImporter.ActivePlugins)
{
try
{
await Plugin.OnLoadAsync(this);
}

catch (Exception ex)
{
Logger.WriteError($"{Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_PLUGIN"]} {Plugin.Name}");
Logger.WriteDebug(ex.GetExceptionInfo());
}
}
#endregion

#region CONFIG
var config = ConfigHandler.Configuration();

Expand All @@ -232,7 +251,18 @@ public async Task Init()

do
{
newConfig.Servers.Add((ServerConfiguration)new ServerConfiguration().Generate());
var serverConfig = new ServerConfiguration();
foreach (var parser in AdditionalRConParsers)
{
serverConfig.AddRConParser(parser);
}

foreach (var parser in AdditionalEventParsers)
{
serverConfig.AddEventParser(parser);
}

newConfig.Servers.Add((ServerConfiguration)serverConfig.Generate());
} while (Utilities.PromptBool(Utilities.CurrentLocalization.LocalizationIndex["SETUP_SERVER_SAVE"]));

config = newConfig;
Expand Down Expand Up @@ -275,24 +305,6 @@ public async Task Init()
PrivilegedClients = (await ClientSvc.GetPrivilegedClients()).ToDictionary(_client => _client.ClientId);
#endregion

#region PLUGINS
SharedLibraryCore.Plugins.PluginImporter.Load(this);

foreach (var Plugin in SharedLibraryCore.Plugins.PluginImporter.ActivePlugins)
{
try
{
await Plugin.OnLoadAsync(this);
}

catch (Exception ex)
{
Logger.WriteError($"{Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_PLUGIN"]} {Plugin.Name}");
Logger.WriteDebug(ex.GetExceptionInfo());
}
}
#endregion

#region COMMANDS
if (ClientSvc.GetOwners().Result.Count == 0)
{
Expand Down
2 changes: 1 addition & 1 deletion Application/RconParsers/BaseRConParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public BaseRConParser()
Configuration.Status.AddMapping(ParserRegex.GroupType.RConName, 5);
Configuration.Status.AddMapping(ParserRegex.GroupType.RConIpAddress, 7);

Configuration.Dvar.Pattern = "^\"(.+)\" is: \"(.+)\" default: \"(.+)\"\n(?:latched: \"(.+)\"\n)? *(.+)$";
Configuration.Dvar.Pattern = "^\"(.+)\" is: \"(.+)\" default: \"(.+)?\"\n(?:latched: \"(.+)?\"\n)? *(.+)$";
Configuration.Dvar.AddMapping(ParserRegex.GroupType.RConDvarName, 1);
Configuration.Dvar.AddMapping(ParserRegex.GroupType.RConDvarValue, 2);
Configuration.Dvar.AddMapping(ParserRegex.GroupType.RConDvarDefaultValue, 3);
Expand Down
31 changes: 29 additions & 2 deletions SharedLibraryCore/Configuration/ServerConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using SharedLibraryCore.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;

namespace SharedLibraryCore.Configuration
{
Expand All @@ -11,11 +12,22 @@ public class ServerConfiguration : IBaseConfiguration
public string Password { get; set; }
public IList<string> Rules { get; set; }
public IList<string> AutoMessages { get; set; }
public bool UseT6MParser { get; set; }
public string ManualLogPath { get; set; }
public string CustomParserVersion { get; set; }
public int ReservedSlotNumber { get; set; }

private readonly IList<IRConParser> rconParsers;
private readonly IList<IEventParser> eventParsers;

public ServerConfiguration()
{
rconParsers = new List<IRConParser>();
eventParsers = new List<IEventParser>();
}

public void AddRConParser(IRConParser parser) => rconParsers.Add(parser);
public void AddEventParser(IEventParser parser) => eventParsers.Add(parser);

public IBaseConfiguration Generate()
{
var loc = Utilities.CurrentLocalization.LocalizationIndex;
Expand All @@ -38,9 +50,24 @@ public IBaseConfiguration Generate()
Password = Utilities.PromptString(loc["SETUP_SERVER_RCON"]);
AutoMessages = new List<string>();
Rules = new List<string>();
UseT6MParser = Utilities.PromptBool(loc["SETUP_SERVER_USET6M"]);
ReservedSlotNumber = loc["SETUP_SERVER_RESERVEDSLOT"].PromptInt(null, 0, 32);

var parserVersions = rconParsers.Select(_parser => _parser.Version).ToArray();
var selection = Utilities.PromptSelection(loc["SETUP_SERVER_RCON_PARSER_VERSION"], $"{loc["SETUP_PROMPT_DEFAULT"]} (IW4x)", null, parserVersions);

if (selection.Item1 > 0)
{
CustomParserVersion = selection.Item2;
}

parserVersions = eventParsers.Select(_parser => _parser.Version).ToArray();
selection = Utilities.PromptSelection(loc["SETUP_SERVER_EVENT_PARSER_VERSION"], $"{loc["SETUP_PROMPT_DEFAULT"]} (IW4x)", null, parserVersions);

if (selection.Item1 > 0)
{
CustomParserVersion = selection.Item2;
}

return this;
}

Expand Down
1 change: 1 addition & 0 deletions SharedLibraryCore/Helpers/Vector3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public Vector3()
{

}

public Vector3(float x, float y, float z)
{
X = x;
Expand Down
6 changes: 3 additions & 3 deletions SharedLibraryCore/RCon/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ public async Task<string[]> SendQueryAsync(StaticHelpers.QueryType type, string
{
case StaticHelpers.QueryType.GET_DVAR:
waitForResponse |= true;
payload = (string.Format(Config.CommandPrefixes.RConGetDvar, RConPassword, parameters + '\0')).Select(Convert.ToByte).ToArray();
payload = Utilities.EncodingType.GetBytes(string.Format(Config.CommandPrefixes.RConGetDvar, RConPassword, parameters + '\0'));
break;
case StaticHelpers.QueryType.SET_DVAR:
payload = (string.Format(Config.CommandPrefixes.RConSetDvar, RConPassword, parameters + '\0')).Select(Convert.ToByte).ToArray();
payload = Utilities.EncodingType.GetBytes(string.Format(Config.CommandPrefixes.RConSetDvar, RConPassword, parameters + '\0'));
break;
case StaticHelpers.QueryType.COMMAND:
payload = (string.Format(Config.CommandPrefixes.RConCommand, RConPassword, parameters + '\0')).Select(Convert.ToByte).ToArray();
payload = Utilities.EncodingType.GetBytes(string.Format(Config.CommandPrefixes.RConCommand, RConPassword, parameters + '\0'));
break;
case StaticHelpers.QueryType.GET_STATUS:
waitForResponse |= true;
Expand Down
41 changes: 40 additions & 1 deletion SharedLibraryCore/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,45 @@ public static bool PromptBool(string question, string description = null, bool d
return response != 0 ? response == 'y' : defaultValue;
}

/// <summary>
/// prompt user to make a selection
/// </summary>
/// <typeparam name="T">type of selection</typeparam>
/// <param name="question">question to prompt the user with</param>
/// <param name="defaultValue">default value to set if no input is entered</param>
/// <param name="description">description of the question's value</param>
/// <param name="selections">array of possible selections (should be able to convert to string)</param>
/// <returns></returns>
public static Tuple<int, T> PromptSelection<T>(string question, T defaultValue, string description = null, params T[] selections)
{
bool hasDefault = false;

if (defaultValue != null)
{
hasDefault = true;
selections = (new T[] { defaultValue }).Union(selections).ToArray();
}

Console.WriteLine($"{question}{(string.IsNullOrEmpty(description) ? "" : $" [{ description}:]")}");
Console.WriteLine(new string('=', 52));
for (int index = 0; index < selections.Length; index++)
{
Console.WriteLine($"{(hasDefault ? index : index + 1)}] {selections[index]}");
}
Console.WriteLine(new string('=', 52));

int selectionIndex = PromptInt(CurrentLocalization.LocalizationIndex["SETUP_PROMPT_MAKE_SELECTION"], null, hasDefault ? 0 : 1, selections.Length, hasDefault ? 0 : (int?)null);

if (!hasDefault)
{
selectionIndex--;
}

T selection = selections[selectionIndex ];

return Tuple.Create(selectionIndex, selection);
}

/// <summary>
/// prompt user to enter a number
/// </summary>
Expand All @@ -503,7 +542,7 @@ public static bool PromptBool(string question, string description = null, bool d
/// <returns>integer from user's input</returns>
public static int PromptInt(this string question, string description = null, int minValue = 0, int maxValue = int.MaxValue, int? defaultValue = null)
{
Console.Write($"{question}{(string.IsNullOrEmpty(description) ? "" : $" ({description})")}{(defaultValue == null ? "" : $" [{CurrentLocalization.LocalizationIndex["SETUP_PROMPT_DEFAULT"]} {defaultValue.Value.ToString()}")}]: ");
Console.Write($"{question}{(string.IsNullOrEmpty(description) ? "" : $" ({description})")}{(defaultValue == null ? "" : $" [{CurrentLocalization.LocalizationIndex["SETUP_PROMPT_DEFAULT"]} {defaultValue.Value.ToString()}]")}: ");
int response;

string inputOrDefault()
Expand Down

0 comments on commit 0a85d88

Please sign in to comment.