yay it logs in

This commit is contained in:
Madpeter 2022-03-16 22:19:46 +00:00
parent b16d17f228
commit e9c1f744ae
6 changed files with 76 additions and 23 deletions

View file

@ -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");
}
}
}

View file

@ -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<string, string> mysettings = new Dictionary<string, string>();
protected List<string> settings = new List<string>();
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<string, string> saveMe = new Dictionary<string, string>();
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<JToken>(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()

View file

@ -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;
}
}

View file

@ -4,9 +4,16 @@
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<StartupObject>SecondBotEvents.Startup</StartupObject>
<MSBuildGitHashCommand>git rev-parse --short HEAD</MSBuildGitHashCommand>
<MSBuildGitHashValidate>False</MSBuildGitHashValidate>
<MSBuildGitHashSuppressDirtyWarning>False</MSBuildGitHashSuppressDirtyWarning>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MSBuildGitHash" Version="2.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

View file

@ -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);
}
}
}

View file

@ -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)