diff --git a/LanguageManagerPlugin.cs b/LanguageManagerPlugin.cs index 12ae5a4..0e898c1 100644 --- a/LanguageManagerPlugin.cs +++ b/LanguageManagerPlugin.cs @@ -7,6 +7,9 @@ using System.Globalization; using Microsoft.Data.Sqlite; using Dapper; +using System.Text.Json; +using System.IO; +using System.Xml.Linq; namespace LanguageManagerPlugin; @@ -14,14 +17,16 @@ public class LanguageManagerPlugin : BasePlugin { public override string ModuleAuthor => "aproxje"; public override string ModuleName => "Language Manager Plugin"; - - public override string ModuleVersion => "0.0.2"; + public override string ModuleVersion => "0.0.3"; private SqliteConnection? _sqlConnection { get; set; } private PlayerLanguageManager playerLanguageManager = new PlayerLanguageManager(); + private PluginConfig? _config; public override void Load(bool hotReload) { + Console.WriteLine("XDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"); + this.SetupConfig(); this.SetupPlayerDatabase(); this.SetupCommand(); @@ -43,6 +48,28 @@ public override void Load(bool hotReload) } } + private void SetupConfig() + { + string configPath = Path.Combine(ModuleDirectory, "config.json"); + + if (!File.Exists(configPath)) + { + Console.WriteLine("Config file not found for language manager"); + return; + } + + string jsonString = File.ReadAllText(configPath); + _config = JsonSerializer.Deserialize(jsonString); + + if (_config == null) + { + Console.WriteLine("Failed to deserialize configuration file for language manager"); + } else + { + Console.WriteLine("Language manager config loaded"); + } + } + public void OnClientPutInServerHandler(int slot) { @@ -98,6 +125,11 @@ public void SetPlayerLanguage(string playerISOCode, ulong steamID, bool updateDa public string? GetPlayerISOCode(string ipAddress) { + const string dbName = "GeoLite2-Country.mmdb"; + string pathToDb = string.IsNullOrEmpty(_config?.GeoDatabasePath) + ? Path.Combine(ModuleDirectory, dbName) + : _config.GeoDatabasePath; + using var reader = new DatabaseReader(Path.Combine(ModuleDirectory, "GeoLite2-Country.mmdb")); try { @@ -180,5 +212,8 @@ public void SetupCommand() }); } - + private class PluginConfig + { + public string? GeoDatabasePath { get; set; } + } } diff --git a/config.json.example b/config.json.example new file mode 100644 index 0000000..1ca8838 --- /dev/null +++ b/config.json.example @@ -0,0 +1,5 @@ +// Needs to be a valid JSON. Remove this comment and DO NOT include the filename. + +{ + "GeoDatabasePath": "C:\\server\\game\\csgo\\addons\\counterstrikesharp\\plugins" +} \ No newline at end of file