adjustments for T6 and tekno (implement mapped dvars and default values)
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
@ -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>
|
||||
|
Reference in New Issue
Block a user