Update static data, and don't hard code it

This commit is contained in:
Mikhail
2024-07-12 14:01:38 -04:00
parent 618619e36d
commit 3865b403b4
13 changed files with 115 additions and 44 deletions

View File

@@ -45,6 +45,7 @@ namespace nksrv.Utils
}
else
{
Logger.Error("Failed to download " + url + " with status code " + response.StatusCode);
return null;
}
}

64
nksrv/Utils/GameConfig.cs Normal file
View File

@@ -0,0 +1,64 @@
using Newtonsoft.Json;
using Swan.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace nksrv.Utils
{
public class GameConfigRoot
{
public StaticData StaticData { get; set; } = new();
public string ResourceBaseURL { get; set; } = "";
}
public class StaticData
{
public string Url { get; set; } = "";
public string Version { get; set; } = "";
public string Salt1 { get; set; } = "";
public string Salt2 { get; set; } = "";
public byte[] GetSalt1Bytes()
{
return Convert.FromBase64String(Salt1);
}
public byte[] GetSalt2Bytes()
{
return Convert.FromBase64String(Salt2);
}
}
public static class GameConfig
{
private static GameConfigRoot? _root;
public static GameConfigRoot Root
{
get
{
if (_root == null)
{
if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "/gameconfig.json"))
{
Logger.Error("Gameconfig.json is not found, the game WILL NOT work!");
_root = new GameConfigRoot();
}
Logger.Info("Loaded game config");
_root = JsonConvert.DeserializeObject<GameConfigRoot>(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "/gameconfig.json"));
if (_root == null)
{
throw new Exception("Failed to read gameconfig.json");
}
}
return _root;
}
}
}
}