adjustments for T6 and tekno (implement mapped dvars and default values)

This commit is contained in:
RaidMax
2020-06-16 17:16:12 -05:00
parent ba77e0149c
commit bb4e51d9c8
9 changed files with 109 additions and 51 deletions

View File

@ -63,8 +63,24 @@ namespace SharedLibraryCore.Interfaces
bool CanGenerateLogPath { get; set; }
/// <summary>
/// Specifies the name of the parser
/// specifies the name of the parser
/// </summary>
string Name { get; set; }
/// <summary>
/// retrieves the value of given dvar key if it exists in the override dict
/// otherwise returns original
/// </summary>
/// <param name="dvarName">name of dvar key</param>
/// <returns></returns>
string GetOverrideDvarName(string dvarName);
/// <summary>
/// retrieves the configuration value of a dvar key for
/// games that do not support the given dvar
/// </summary>
/// <param name="dvarName">dvar key name</param>
/// <returns></returns>
T GetDefaultDvarValue<T>(string dvarName);
}
}

View File

@ -1,4 +1,5 @@
using SharedLibraryCore.RCon;
using System.Collections.Generic;
using System.Globalization;
namespace SharedLibraryCore.Interfaces
@ -45,5 +46,16 @@ namespace SharedLibraryCore.Interfaces
/// indicates the format expected for parsed guids
/// </summary>
NumberStyles GuidNumberStyle { get; set; }
/// <summary>
/// specifies simple mappings for dvar names in scenarios where the needed
/// information is not stored in a traditional dvar name
/// </summary>
IDictionary<string, string> OverrideDvarNameMapping { get; set; }
/// <summary>
/// specifies the default dvar values for games that don't support certain dvars
/// </summary>
IDictionary<string, string> DefaultDvarValues { get; set; }
}
}

View File

@ -1,4 +1,5 @@
using SharedLibraryCore.Database.Models;

using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Helpers;
using SharedLibraryCore.Interfaces;
using System;
@ -747,7 +748,27 @@ namespace SharedLibraryCore
public static Task<Dvar<T>> GetDvarAsync<T>(this Server server, string dvarName, T fallbackValue = default)
{
return server.RconParser.GetDvarAsync<T>(server.RemoteConnection, dvarName, fallbackValue);
return server.RconParser.GetDvarAsync(server.RemoteConnection, dvarName, fallbackValue);
}
public static async Task<Dvar<T>> GetMappedDvarValueOrDefaultAsync<T>(this Server server, string dvarName, string infoResponseName = null, IDictionary<string, string> infoResponse = null)
{
// todo: unit test this
string mappedKey = server.RconParser.GetOverrideDvarName(dvarName);
var defaultValue = server.RconParser.GetDefaultDvarValue<T>(mappedKey);
string foundKey = infoResponse?.Keys.Where(_key => new[] { mappedKey, dvarName, infoResponseName ?? dvarName }.Contains(_key)).FirstOrDefault();
if (!string.IsNullOrEmpty(foundKey))
{
return new Dvar<T>
{
Value = (T)Convert.ChangeType(infoResponse[foundKey], typeof(T)),
Name = foundKey
};
}
return await server.GetDvarAsync(mappedKey, defaultValue);
}
public static Task SetDvarAsync(this Server server, string dvarName, object dvarValue)
@ -944,6 +965,8 @@ namespace SharedLibraryCore
public static bool ShouldHideLevel(this Permission perm) => perm == Permission.Flagged;
/// <summary>
/// replaces any directory separator chars with the platform specific character
/// </summary>