SCHALE.GameServer/SCHALE.Common/Crypto/ProtocolConverter.cs

32 lines
943 B
C#
Raw Normal View History

using SCHALE.Common.NetworkProtocol;
using Serilog;
using System.Text.Json;
namespace SCHALE.Common.Crypto
{
internal class ProtocolConverter
{
private Dictionary<int, List<int>> ProtocolConversionMappings { get; set; }
public ProtocolConverter()
{
var jsonPath = Path.Combine(Path.GetDirectoryName(AppContext.BaseDirectory), "protocol_converter_values.json");
if (!File.Exists(jsonPath))
{
Log.Information("The Json file for Protocol Converter does not exist...");
return;
}
string protocolJson = File.ReadAllText(jsonPath);
ProtocolConversionMappings = JsonSerializer.Deserialize<Dictionary<int, List<int>>>(protocolJson);
}
public int TypeConversion(uint crc, Protocol protocol)
{
return ProtocolConversionMappings[(int)protocol][(int)crc];
}
}
}