diff --git a/SecondBotEvents/Config/basic_config.cs b/SecondBotEvents/Config/basic_config.cs index b262e79..a46f3b8 100644 --- a/SecondBotEvents/Config/basic_config.cs +++ b/SecondBotEvents/Config/basic_config.cs @@ -12,7 +12,7 @@ namespace SecondBotEvents.Config filename = "basic"; settings.Add("username"); settings.Add("password"); - settings.Add("loginuri"); + settings.Add("loginURI"); } public string getUsername() @@ -44,7 +44,7 @@ namespace SecondBotEvents.Config public string getLoginURI() { - return readSetting("loginuri", "secondlife"); + return readSetting("loginURI", "secondlife"); } } } diff --git a/SecondBotEvents/Config/config.cs b/SecondBotEvents/Config/config.cs index fd18b5a..1142615 100644 --- a/SecondBotEvents/Config/config.cs +++ b/SecondBotEvents/Config/config.cs @@ -1,8 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Newtonsoft.Json; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Text; + namespace SecondBotEvents.Config { @@ -11,12 +13,18 @@ namespace SecondBotEvents.Config protected Dictionary mysettings = new Dictionary(); protected List settings = new List(); protected string filename = "config"; + protected bool loaded = false; public config(bool fromENV, string fromFolder="") { makeSettings(); loadSettings(fromENV, fromFolder); } + public bool isLoaded() + { + return loaded; + } + protected void loadSettings(bool fromENV, string fromFolder = "") { if(fromENV == true) @@ -27,6 +35,23 @@ namespace SecondBotEvents.Config loadSettingsFromFile(fromFolder); } + protected void makeSettingsFile(string fromFolder) + { + Dictionary saveMe = new Dictionary(); + Type thisType = this.GetType(); + foreach (string setting in settings) + { + string reader = "get"+ StringExtensions.FirstCharToUpper(setting); + MethodInfo theMethod = thisType.GetMethod(reader); + string value = theMethod.Invoke(this, null).ToString(); + saveMe.Add(setting, value); + } + SimpleIO IO = new SimpleIO(); + IO.ChangeRoot(fromFolder); + string writeFile = filename + ".json"; + IO.WriteFile(writeFile, JsonConvert.SerializeObject(saveMe)); + + } protected void loadSettingsFromFile(string fromFolder) { SimpleIO IO = new SimpleIO(); @@ -34,12 +59,17 @@ namespace SecondBotEvents.Config string readfile = filename + ".json"; if (IO.Exists(readfile) == false) { + makeSettingsFile(fromFolder); return; } - JToken result = JsonConvert.DeserializeObject(IO.ReadFile(readfile)); + JObject result = JObject.Parse(IO.ReadFile(readfile)); foreach (string setting in settings) { - string value = Environment.GetEnvironmentVariable(key); + if(result.ContainsKey(setting) == false) + { + continue; + } + string value = result[setting].ToString(); if (SecondbotHelpers.notempty(value) == false) { mysettings.Add(setting, ""); @@ -47,6 +77,7 @@ namespace SecondBotEvents.Config } mysettings.Add(setting, value); } + loaded = true; } protected void loadSettingsFromEnv() @@ -62,6 +93,7 @@ namespace SecondBotEvents.Config } mysettings.Add(setting, value); } + loaded = true; } protected virtual void makeSettings() diff --git a/SecondBotEvents/EventsSecondBot.cs b/SecondBotEvents/EventsSecondBot.cs index 6c7fe48..e25fc71 100644 --- a/SecondBotEvents/EventsSecondBot.cs +++ b/SecondBotEvents/EventsSecondBot.cs @@ -32,12 +32,18 @@ namespace SecondBotEvents public bool fromEnv = false; public string fromFolder = ""; + protected bool exitNow = false; public EventsSecondBot(string[] args) { if (SecondbotHelpers.notempty(Environment.GetEnvironmentVariable("basic_username")) == true) { fromEnv = true; } + fromFolder = "defaultBot"; + if (args.Length == 1) + { + fromFolder = args[0]; + } restartServices(); } public void restartServices() @@ -50,6 +56,12 @@ namespace SecondBotEvents HttpService = new http(this); HttpService.start(); botClient = new BotClient(this); + if(botClient.basicCfg.isLoaded() == false) + { + Console.WriteLine("Config is not loaded :("); + exitNow = true; + return; + } botClient.start(); } @@ -69,7 +81,7 @@ namespace SecondBotEvents public bool exit() { - return false; + return exitNow; } } diff --git a/SecondBotEvents/SecondBotEvents.csproj b/SecondBotEvents/SecondBotEvents.csproj index 26a709c..27d98e9 100644 --- a/SecondBotEvents/SecondBotEvents.csproj +++ b/SecondBotEvents/SecondBotEvents.csproj @@ -4,9 +4,16 @@ Exe netcoreapp3.1 SecondBotEvents.Startup + git rev-parse --short HEAD + False + False + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/SecondBotEvents/Services/BotClient.cs b/SecondBotEvents/Services/BotClient.cs index 3f4b49c..09aa854 100644 --- a/SecondBotEvents/Services/BotClient.cs +++ b/SecondBotEvents/Services/BotClient.cs @@ -40,19 +40,19 @@ namespace SecondBotEvents.Services { resetClient(); } - LoginParams loginParams = new LoginParams(); - loginParams.AgreeToTos = true; - loginParams.Version = "Build: " + master.getVersion(); - loginParams.FirstName = basicCfg.getFirstName(); - loginParams.LastName = basicCfg.getLastName(); - loginParams.Password = basicCfg.getPassword(); - loginParams.Timeout = 4000; - loginParams.URI = basicCfg.getLoginURI(); - if (loginParams.URI == "secondlife") + LoginParams loginParams = new LoginParams( + client, + basicCfg.getFirstName(), + basicCfg.getLastName(), + basicCfg.getPassword(), + "secondbot", + master.getVersion() + ); + if (basicCfg.getLoginURI() != "secondlife") { - loginParams.URI = Settings.AGNI_LOGIN_SERVER; + loginParams.URI = basicCfg.getLoginURI(); } - client.Network.Login(loginParams); + client.Network.BeginLogin(loginParams); } } } diff --git a/SecondBotEvents/SimpleIO.cs b/SecondBotEvents/SimpleIO.cs index ad4f774..f344071 100644 --- a/SecondBotEvents/SimpleIO.cs +++ b/SecondBotEvents/SimpleIO.cs @@ -10,11 +10,13 @@ namespace SecondBotEvents protected string root_folder = ""; public void ChangeRoot(string A) { - root_folder = A; - if (DirExists(root_folder) == false) + if (root_folder != "") { - System.IO.Directory.CreateDirectory(root_folder); + if (DirExists(root_folder) == false) + { + System.IO.Directory.CreateDirectory(root_folder); + } } } public static bool DirExists(string target_folder)