yay it logs in
This commit is contained in:
parent
b16d17f228
commit
e9c1f744ae
6 changed files with 76 additions and 23 deletions
|
|
@ -12,7 +12,7 @@ namespace SecondBotEvents.Config
|
||||||
filename = "basic";
|
filename = "basic";
|
||||||
settings.Add("username");
|
settings.Add("username");
|
||||||
settings.Add("password");
|
settings.Add("password");
|
||||||
settings.Add("loginuri");
|
settings.Add("loginURI");
|
||||||
}
|
}
|
||||||
|
|
||||||
public string getUsername()
|
public string getUsername()
|
||||||
|
|
@ -44,7 +44,7 @@ namespace SecondBotEvents.Config
|
||||||
|
|
||||||
public string getLoginURI()
|
public string getLoginURI()
|
||||||
{
|
{
|
||||||
return readSetting("loginuri", "secondlife");
|
return readSetting("loginURI", "secondlife");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
using System;
|
using Newtonsoft.Json;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
|
||||||
namespace SecondBotEvents.Config
|
namespace SecondBotEvents.Config
|
||||||
{
|
{
|
||||||
|
|
@ -11,12 +13,18 @@ namespace SecondBotEvents.Config
|
||||||
protected Dictionary<string, string> mysettings = new Dictionary<string, string>();
|
protected Dictionary<string, string> mysettings = new Dictionary<string, string>();
|
||||||
protected List<string> settings = new List<string>();
|
protected List<string> settings = new List<string>();
|
||||||
protected string filename = "config";
|
protected string filename = "config";
|
||||||
|
protected bool loaded = false;
|
||||||
public config(bool fromENV, string fromFolder="")
|
public config(bool fromENV, string fromFolder="")
|
||||||
{
|
{
|
||||||
makeSettings();
|
makeSettings();
|
||||||
loadSettings(fromENV, fromFolder);
|
loadSettings(fromENV, fromFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool isLoaded()
|
||||||
|
{
|
||||||
|
return loaded;
|
||||||
|
}
|
||||||
|
|
||||||
protected void loadSettings(bool fromENV, string fromFolder = "")
|
protected void loadSettings(bool fromENV, string fromFolder = "")
|
||||||
{
|
{
|
||||||
if(fromENV == true)
|
if(fromENV == true)
|
||||||
|
|
@ -27,6 +35,23 @@ namespace SecondBotEvents.Config
|
||||||
loadSettingsFromFile(fromFolder);
|
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)
|
protected void loadSettingsFromFile(string fromFolder)
|
||||||
{
|
{
|
||||||
SimpleIO IO = new SimpleIO();
|
SimpleIO IO = new SimpleIO();
|
||||||
|
|
@ -34,12 +59,17 @@ namespace SecondBotEvents.Config
|
||||||
string readfile = filename + ".json";
|
string readfile = filename + ".json";
|
||||||
if (IO.Exists(readfile) == false)
|
if (IO.Exists(readfile) == false)
|
||||||
{
|
{
|
||||||
|
makeSettingsFile(fromFolder);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
JToken result = JsonConvert.DeserializeObject<JToken>(IO.ReadFile(readfile));
|
JObject result = JObject.Parse(IO.ReadFile(readfile));
|
||||||
foreach (string setting in settings)
|
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)
|
if (SecondbotHelpers.notempty(value) == false)
|
||||||
{
|
{
|
||||||
mysettings.Add(setting, "");
|
mysettings.Add(setting, "");
|
||||||
|
|
@ -47,6 +77,7 @@ namespace SecondBotEvents.Config
|
||||||
}
|
}
|
||||||
mysettings.Add(setting, value);
|
mysettings.Add(setting, value);
|
||||||
}
|
}
|
||||||
|
loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void loadSettingsFromEnv()
|
protected void loadSettingsFromEnv()
|
||||||
|
|
@ -62,6 +93,7 @@ namespace SecondBotEvents.Config
|
||||||
}
|
}
|
||||||
mysettings.Add(setting, value);
|
mysettings.Add(setting, value);
|
||||||
}
|
}
|
||||||
|
loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void makeSettings()
|
protected virtual void makeSettings()
|
||||||
|
|
|
||||||
|
|
@ -32,12 +32,18 @@ namespace SecondBotEvents
|
||||||
|
|
||||||
public bool fromEnv = false;
|
public bool fromEnv = false;
|
||||||
public string fromFolder = "";
|
public string fromFolder = "";
|
||||||
|
protected bool exitNow = false;
|
||||||
public EventsSecondBot(string[] args)
|
public EventsSecondBot(string[] args)
|
||||||
{
|
{
|
||||||
if (SecondbotHelpers.notempty(Environment.GetEnvironmentVariable("basic_username")) == true)
|
if (SecondbotHelpers.notempty(Environment.GetEnvironmentVariable("basic_username")) == true)
|
||||||
{
|
{
|
||||||
fromEnv = true;
|
fromEnv = true;
|
||||||
}
|
}
|
||||||
|
fromFolder = "defaultBot";
|
||||||
|
if (args.Length == 1)
|
||||||
|
{
|
||||||
|
fromFolder = args[0];
|
||||||
|
}
|
||||||
restartServices();
|
restartServices();
|
||||||
}
|
}
|
||||||
public void restartServices()
|
public void restartServices()
|
||||||
|
|
@ -50,6 +56,12 @@ namespace SecondBotEvents
|
||||||
HttpService = new http(this);
|
HttpService = new http(this);
|
||||||
HttpService.start();
|
HttpService.start();
|
||||||
botClient = new BotClient(this);
|
botClient = new BotClient(this);
|
||||||
|
if(botClient.basicCfg.isLoaded() == false)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Config is not loaded :(");
|
||||||
|
exitNow = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
botClient.start();
|
botClient.start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -69,7 +81,7 @@ namespace SecondBotEvents
|
||||||
|
|
||||||
public bool exit()
|
public bool exit()
|
||||||
{
|
{
|
||||||
return false;
|
return exitNow;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,16 @@
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
<StartupObject>SecondBotEvents.Startup</StartupObject>
|
<StartupObject>SecondBotEvents.Startup</StartupObject>
|
||||||
|
<MSBuildGitHashCommand>git rev-parse --short HEAD</MSBuildGitHashCommand>
|
||||||
|
<MSBuildGitHashValidate>False</MSBuildGitHashValidate>
|
||||||
|
<MSBuildGitHashSuppressDirtyWarning>False</MSBuildGitHashSuppressDirtyWarning>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<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" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,19 +40,19 @@ namespace SecondBotEvents.Services
|
||||||
{
|
{
|
||||||
resetClient();
|
resetClient();
|
||||||
}
|
}
|
||||||
LoginParams loginParams = new LoginParams();
|
LoginParams loginParams = new LoginParams(
|
||||||
loginParams.AgreeToTos = true;
|
client,
|
||||||
loginParams.Version = "Build: " + master.getVersion();
|
basicCfg.getFirstName(),
|
||||||
loginParams.FirstName = basicCfg.getFirstName();
|
basicCfg.getLastName(),
|
||||||
loginParams.LastName = basicCfg.getLastName();
|
basicCfg.getPassword(),
|
||||||
loginParams.Password = basicCfg.getPassword();
|
"secondbot",
|
||||||
loginParams.Timeout = 4000;
|
master.getVersion()
|
||||||
loginParams.URI = basicCfg.getLoginURI();
|
);
|
||||||
if (loginParams.URI == "secondlife")
|
if (basicCfg.getLoginURI() != "secondlife")
|
||||||
{
|
{
|
||||||
loginParams.URI = Settings.AGNI_LOGIN_SERVER;
|
loginParams.URI = basicCfg.getLoginURI();
|
||||||
}
|
}
|
||||||
client.Network.Login(loginParams);
|
client.Network.BeginLogin(loginParams);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,13 @@ namespace SecondBotEvents
|
||||||
protected string root_folder = "";
|
protected string root_folder = "";
|
||||||
public void ChangeRoot(string A)
|
public void ChangeRoot(string A)
|
||||||
{
|
{
|
||||||
|
|
||||||
root_folder = 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)
|
public static bool DirExists(string target_folder)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue