diff --git a/BSBshared/BSBshared.csproj b/BSBshared/BSBshared.csproj
index 033ee71..6b92d7a 100644
--- a/BSBshared/BSBshared.csproj
+++ b/BSBshared/BSBshared.csproj
@@ -15,8 +15,8 @@
-
-
+
+
diff --git a/BetterSecondBot.sln b/BetterSecondBot.sln
index c07ad16..0749f08 100644
--- a/BetterSecondBot.sln
+++ b/BetterSecondBot.sln
@@ -10,12 +10,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BSBshared", "BSBshared\BSBs
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Libmeta-core", "Libmeta-core", "{7538B15D-152B-4A0F-A24D-A89EDC382564}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibreMetaverse-core.Types", "libremetaverse-core\Libremetaverse.types\LibreMetaverse-core.Types.csproj", "{EF718593-1FC7-433A-8495-5B1A7106CAF3}"
-EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibreMetaverse-core.StructuredData", "libremetaverse-core\Libremetaverse.structureddata\LibreMetaverse-core.StructuredData.csproj", "{3928AB19-219D-4284-BFE9-6C0E779F98A3}"
-EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibreMetaverse-core", "libremetaverse-core\Libremetaverse\LibreMetaverse-core.csproj", "{97198293-1B92-4FD2-811E-AE1F33D4B2B2}"
-EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B861AB1B-8F09-41A9-8817-CB8A2E961E4C}"
ProjectSection(SolutionItems) = preProject
Dockerfile = Dockerfile
@@ -23,6 +17,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibreMetaverse", "libremetaverse-core\LibreMetaverse\LibreMetaverse.csproj", "{27C70F3A-0000-0000-0000-000000000000}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibreMetaverse.StructuredData", "libremetaverse-core\LibreMetaverse.StructuredData\LibreMetaverse.StructuredData.csproj", "{89D7A3E5-0000-0000-0000-000000000000}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibreMetaverse.Types", "libremetaverse-core\LibreMetaverseTypes\LibreMetaverse.Types.csproj", "{B37B02AD-0000-0000-0000-000000000000}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -66,41 +66,50 @@ Global
{42075C8C-8055-4178-8C12-AE97DAFE8484}.Release|Any CPU.ActiveCfg = Release|x64
{42075C8C-8055-4178-8C12-AE97DAFE8484}.Release|x64.ActiveCfg = Release|x64
{42075C8C-8055-4178-8C12-AE97DAFE8484}.Release|x64.Build.0 = Release|x64
- {EF718593-1FC7-433A-8495-5B1A7106CAF3}.Debug|Any CPU.ActiveCfg = Debug|x64
- {EF718593-1FC7-433A-8495-5B1A7106CAF3}.Debug|x64.ActiveCfg = Debug|x64
- {EF718593-1FC7-433A-8495-5B1A7106CAF3}.Debug|x64.Build.0 = Debug|x64
- {EF718593-1FC7-433A-8495-5B1A7106CAF3}.DockerBuild|Any CPU.ActiveCfg = DockerBuild|x64
- {EF718593-1FC7-433A-8495-5B1A7106CAF3}.DockerBuild|x64.ActiveCfg = DockerBuild|x64
- {EF718593-1FC7-433A-8495-5B1A7106CAF3}.DockerBuild|x64.Build.0 = DockerBuild|x64
- {EF718593-1FC7-433A-8495-5B1A7106CAF3}.Release|Any CPU.ActiveCfg = Release|x64
- {EF718593-1FC7-433A-8495-5B1A7106CAF3}.Release|x64.ActiveCfg = Release|x64
- {EF718593-1FC7-433A-8495-5B1A7106CAF3}.Release|x64.Build.0 = Release|x64
- {3928AB19-219D-4284-BFE9-6C0E779F98A3}.Debug|Any CPU.ActiveCfg = Debug|x64
- {3928AB19-219D-4284-BFE9-6C0E779F98A3}.Debug|x64.ActiveCfg = Debug|x64
- {3928AB19-219D-4284-BFE9-6C0E779F98A3}.Debug|x64.Build.0 = Debug|x64
- {3928AB19-219D-4284-BFE9-6C0E779F98A3}.DockerBuild|Any CPU.ActiveCfg = DockerBuild|x64
- {3928AB19-219D-4284-BFE9-6C0E779F98A3}.DockerBuild|x64.ActiveCfg = DockerBuild|x64
- {3928AB19-219D-4284-BFE9-6C0E779F98A3}.DockerBuild|x64.Build.0 = DockerBuild|x64
- {3928AB19-219D-4284-BFE9-6C0E779F98A3}.Release|Any CPU.ActiveCfg = Release|x64
- {3928AB19-219D-4284-BFE9-6C0E779F98A3}.Release|x64.ActiveCfg = Release|x64
- {3928AB19-219D-4284-BFE9-6C0E779F98A3}.Release|x64.Build.0 = Release|x64
- {97198293-1B92-4FD2-811E-AE1F33D4B2B2}.Debug|Any CPU.ActiveCfg = Debug|x64
- {97198293-1B92-4FD2-811E-AE1F33D4B2B2}.Debug|x64.ActiveCfg = Debug|x64
- {97198293-1B92-4FD2-811E-AE1F33D4B2B2}.Debug|x64.Build.0 = Debug|x64
- {97198293-1B92-4FD2-811E-AE1F33D4B2B2}.DockerBuild|Any CPU.ActiveCfg = DockerBuild|x64
- {97198293-1B92-4FD2-811E-AE1F33D4B2B2}.DockerBuild|x64.ActiveCfg = DockerBuild|x64
- {97198293-1B92-4FD2-811E-AE1F33D4B2B2}.DockerBuild|x64.Build.0 = DockerBuild|x64
- {97198293-1B92-4FD2-811E-AE1F33D4B2B2}.Release|Any CPU.ActiveCfg = Release|x64
- {97198293-1B92-4FD2-811E-AE1F33D4B2B2}.Release|x64.ActiveCfg = Release|x64
- {97198293-1B92-4FD2-811E-AE1F33D4B2B2}.Release|x64.Build.0 = Release|x64
+ {27C70F3A-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {27C70F3A-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {27C70F3A-0000-0000-0000-000000000000}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {27C70F3A-0000-0000-0000-000000000000}.Debug|x64.Build.0 = Debug|Any CPU
+ {27C70F3A-0000-0000-0000-000000000000}.DockerBuild|Any CPU.ActiveCfg = Debug|Any CPU
+ {27C70F3A-0000-0000-0000-000000000000}.DockerBuild|Any CPU.Build.0 = Debug|Any CPU
+ {27C70F3A-0000-0000-0000-000000000000}.DockerBuild|x64.ActiveCfg = Debug|Any CPU
+ {27C70F3A-0000-0000-0000-000000000000}.DockerBuild|x64.Build.0 = Debug|Any CPU
+ {27C70F3A-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {27C70F3A-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU
+ {27C70F3A-0000-0000-0000-000000000000}.Release|x64.ActiveCfg = Release|Any CPU
+ {27C70F3A-0000-0000-0000-000000000000}.Release|x64.Build.0 = Release|Any CPU
+ {89D7A3E5-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {89D7A3E5-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {89D7A3E5-0000-0000-0000-000000000000}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {89D7A3E5-0000-0000-0000-000000000000}.Debug|x64.Build.0 = Debug|Any CPU
+ {89D7A3E5-0000-0000-0000-000000000000}.DockerBuild|Any CPU.ActiveCfg = Debug|Any CPU
+ {89D7A3E5-0000-0000-0000-000000000000}.DockerBuild|Any CPU.Build.0 = Debug|Any CPU
+ {89D7A3E5-0000-0000-0000-000000000000}.DockerBuild|x64.ActiveCfg = Debug|Any CPU
+ {89D7A3E5-0000-0000-0000-000000000000}.DockerBuild|x64.Build.0 = Debug|Any CPU
+ {89D7A3E5-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {89D7A3E5-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU
+ {89D7A3E5-0000-0000-0000-000000000000}.Release|x64.ActiveCfg = Release|Any CPU
+ {89D7A3E5-0000-0000-0000-000000000000}.Release|x64.Build.0 = Release|Any CPU
+ {B37B02AD-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B37B02AD-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B37B02AD-0000-0000-0000-000000000000}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {B37B02AD-0000-0000-0000-000000000000}.Debug|x64.Build.0 = Debug|Any CPU
+ {B37B02AD-0000-0000-0000-000000000000}.DockerBuild|Any CPU.ActiveCfg = Debug|Any CPU
+ {B37B02AD-0000-0000-0000-000000000000}.DockerBuild|Any CPU.Build.0 = Debug|Any CPU
+ {B37B02AD-0000-0000-0000-000000000000}.DockerBuild|x64.ActiveCfg = Debug|Any CPU
+ {B37B02AD-0000-0000-0000-000000000000}.DockerBuild|x64.Build.0 = Debug|Any CPU
+ {B37B02AD-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B37B02AD-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B37B02AD-0000-0000-0000-000000000000}.Release|x64.ActiveCfg = Release|Any CPU
+ {B37B02AD-0000-0000-0000-000000000000}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
- {EF718593-1FC7-433A-8495-5B1A7106CAF3} = {7538B15D-152B-4A0F-A24D-A89EDC382564}
- {3928AB19-219D-4284-BFE9-6C0E779F98A3} = {7538B15D-152B-4A0F-A24D-A89EDC382564}
- {97198293-1B92-4FD2-811E-AE1F33D4B2B2} = {7538B15D-152B-4A0F-A24D-A89EDC382564}
+ {27C70F3A-0000-0000-0000-000000000000} = {7538B15D-152B-4A0F-A24D-A89EDC382564}
+ {89D7A3E5-0000-0000-0000-000000000000} = {7538B15D-152B-4A0F-A24D-A89EDC382564}
+ {B37B02AD-0000-0000-0000-000000000000} = {7538B15D-152B-4A0F-A24D-A89EDC382564}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {39A7E333-AFC1-4BA8-9EBC-9298791FDC78}
diff --git a/CLI/CliExitOnLogout.cs b/CLI/CliExitOnLogout.cs
index f55dbb2..d2e9dee 100644
--- a/CLI/CliExitOnLogout.cs
+++ b/CLI/CliExitOnLogout.cs
@@ -51,7 +51,10 @@ namespace BetterSecondBot
SecondBotHttpServer my_http_server = new SecondBotHttpServer();
my_http_server.StartHttpServer(Bot, Config);
*/
- new HttpAsService(Bot, Config);
+ new Thread(() =>
+ {
+ new HttpAsService(Bot, Config);
+ }).Start();
}
if(use_self_keep_alive == true)
{
diff --git a/CLI/HttpService/Chat.cs b/CLI/HttpService/Chat.cs
new file mode 100644
index 0000000..5b3c8cf
--- /dev/null
+++ b/CLI/HttpService/Chat.cs
@@ -0,0 +1,42 @@
+using BSB.bottypes;
+using BSB.Static;
+using EmbedIO;
+using EmbedIO.Routing;
+using EmbedIO.WebApi;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using OpenMetaverse;
+using Newtonsoft.Json;
+
+namespace BetterSecondBot.HttpService
+{
+ public class SecondbotChat : WebApiControllerWithTokens
+ {
+ public SecondbotChat(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { }
+
+ [Route(HttpVerbs.Get, "/localchathistory/{token}")]
+ public object localchatHistory(string token)
+ {
+ if (tokens.Allow(token, getClientIP()) == true)
+ {
+ return BasicReply(JsonConvert.SerializeObject(bot.getLocalChatHistory()));
+ }
+ return BasicReply("Token not accepted");
+ }
+
+ [Route(HttpVerbs.Post, "/localchatsay/{token}")]
+ public object localchatSay(string token, [FormField] string message)
+ {
+ if (tokens.Allow(token, getClientIP()) == true)
+ {
+ bot.GetCommandsInterface.Call("say", message);
+ return BasicReply(JsonConvert.SerializeObject(bot.getLocalChatHistory()));
+ }
+ return BasicReply("Token not accepted");
+ }
+
+ }
+
+
+}
diff --git a/CLI/HttpService/Group.cs b/CLI/HttpService/Group.cs
new file mode 100644
index 0000000..b0fb945
--- /dev/null
+++ b/CLI/HttpService/Group.cs
@@ -0,0 +1,84 @@
+using BSB.bottypes;
+using BSB.Static;
+using EmbedIO;
+using EmbedIO.Routing;
+using EmbedIO.WebApi;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using OpenMetaverse;
+using Newtonsoft.Json;
+
+namespace BetterSecondBot.HttpService
+{
+ public class SecondbotGroup : WebApiControllerWithTokens
+ {
+ public SecondbotGroup(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { }
+
+ [Route(HttpVerbs.Get, "/listgroups/{token}")]
+ public object listgroups(string token)
+ {
+ if (tokens.Allow(token, getClientIP()) == true)
+ {
+ Dictionary grouppackage = new Dictionary();
+ foreach(KeyValuePair entry in bot.MyGroups)
+ {
+ grouppackage.Add(entry.Value.ID.ToString(), entry.Value.Name);
+ }
+ return BasicReply(JsonConvert.SerializeObject(grouppackage));
+ }
+ return BasicReply("Token not accepted");
+ }
+
+ [Route(HttpVerbs.Get, "/listgroupswithunread/{token}")]
+ public object listgroupswithunread(string group, string token)
+ {
+ if (tokens.Allow(token, getClientIP()) == true)
+ {
+ return BasicReply(JsonConvert.SerializeObject(bot.UnreadGroupchatGroups()));
+ }
+ return BasicReply("Token not accepted");
+ }
+
+ [Route(HttpVerbs.Get, "/haveunreadgroupchat/{token}")]
+ public object haveunreadgroupchat(string token)
+ {
+ if (tokens.Allow(token, getClientIP()) == true)
+ {
+ return BasicReply(bot.HasUnreadGroupchats().ToString());
+ }
+ return BasicReply("Token not accepted");
+ }
+
+ [Route(HttpVerbs.Get, "/getgroupchat/{group}/{token}")]
+ public object getgroupchat(string group, string token)
+ {
+ if (tokens.Allow(token, getClientIP()) == true)
+ {
+ if (UUID.TryParse(group, out UUID groupUUID) == true)
+ {
+ return BasicReply(JsonConvert.SerializeObject(bot.GetGroupchat(groupUUID)));
+ }
+ return BasicReply("Group UUID invaild");
+ }
+ return BasicReply("Token not accepted");
+ }
+
+ [Route(HttpVerbs.Post, "/sendgroupchat/{group}/{token}")]
+ public object sendgroupchat(string group, string token, [FormField] string message)
+ {
+ if (tokens.Allow(token, getClientIP()) == true)
+ {
+ if (UUID.TryParse(group, out UUID groupUUID) == true)
+ {
+ bool status = bot.GetCommandsInterface.Call("Groupchat", group + "~#~" + message, UUID.Zero, "~#~");
+ return BasicReply("Processing");
+ }
+ return BasicReply("Group UUID invaild");
+ }
+ return BasicReply("Token not accepted");
+ }
+
+
+ }
+}
diff --git a/CLI/HttpService/HttpAsService.cs b/CLI/HttpService/HttpAsService.cs
index 3f85bab..e1cd5ec 100644
--- a/CLI/HttpService/HttpAsService.cs
+++ b/CLI/HttpService/HttpAsService.cs
@@ -32,7 +32,7 @@ namespace BetterSecondBot.HttpService
server.RunAsync();
while(Bot.KillMe == false)
{
- Thread.Sleep(1000);
+ Thread.Sleep(3000);
}
}
}
@@ -43,14 +43,26 @@ namespace BetterSecondBot.HttpService
var server = new WebServer(o => o
.WithUrlPrefix(url)
.WithMode(HttpListenerMode.EmbedIO))
- .WithIPBanning(o => o
- .WithMaxRequestsPerSecond(10)
- .WithRegexRules("HTTP exception 404")
- )
+ .WithCors()
+ //.WithIPBanning(o => o
+ // .WithMaxRequestsPerSecond(30)
+ // .WithRegexRules("HTTP exception 404")
+ //)
.WithWebApi("/inventory", m => m
- .WithController(() => new SecondbotInventory(Bot, Tokens)))
+ .WithController(() => new SecondbotInventory(Bot, Tokens))
+ )
+ .WithWebApi("/chat", m => m
+ .WithController(() => new SecondbotChat(Bot, Tokens))
+ )
+ .WithWebApi("/groups", m => m
+ .WithController(() => new SecondbotGroup(Bot, Tokens))
+ )
+ .WithWebApi("/ims", m => m
+ .WithController(() => new SecondbotIm(Bot, Tokens))
+ )
.WithWebApi("/core", m => m
.WithController(() => new SecondbotCoreWebAPi(Config, Bot, Tokens)))
+
.WithModule(new ActionModule("/", HttpVerbs.Any, ctx => ctx.SendDataAsync(new { Message = "Error" })));
return server;
}
@@ -100,7 +112,7 @@ namespace BetterSecondBot.HttpService
PurgeExpired();
return false;
}
- if (info.IP == IPaddress)
+ if (IPaddress.Equals(info.IP) == true)
{
return true;
}
@@ -110,21 +122,27 @@ namespace BetterSecondBot.HttpService
public string CreateToken(IPAddress IP)
{
- PurgeExpired();
- bool used = true;
- string last = "";
- while(used == true)
+ if (IP != null)
{
- last = helpers.GetSHA1(last + helpers.UnixTimeNow() + new Random().Next(13256).ToString()).Substring(0, 10);
- used = tokens.ContainsKey(last);
- if (used == false)
+ PurgeExpired();
+ bool used = true;
+ string last = "";
+ while (used == true)
{
- tokenInfo Info = new tokenInfo();
- Info.IP = IP;
- Info.Expires = helpers.UnixTimeNow() + (60 * 10);
+ last = helpers.GetSHA1(last + helpers.UnixTimeNow() + new Random().Next(13256).ToString()).Substring(0, 10);
+ used = tokens.ContainsKey(last);
+ if (used == false)
+ {
+ tokenInfo Info = new tokenInfo();
+ Info.IP = IP;
+ Info.Expires = helpers.UnixTimeNow() + (60 * 10);
+ tokens.Add(last, Info);
+ break;
+ }
}
+ return last;
}
- return last;
+ return null;
}
}
@@ -132,7 +150,11 @@ namespace BetterSecondBot.HttpService
{
protected TokenStorage tokens;
protected SecondBot bot;
-
+
+ protected Object BasicReply(string input)
+ {
+ return new { reply = input };
+ }
public WebApiControllerWithTokens(SecondBot mainbot, TokenStorage setuptokens)
{
bot = mainbot;
diff --git a/CLI/HttpService/Im.cs b/CLI/HttpService/Im.cs
new file mode 100644
index 0000000..b30db6e
--- /dev/null
+++ b/CLI/HttpService/Im.cs
@@ -0,0 +1,92 @@
+using BSB.bottypes;
+using BSB.Static;
+using EmbedIO;
+using EmbedIO.Routing;
+using EmbedIO.WebApi;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using OpenMetaverse;
+using Newtonsoft.Json;
+
+namespace BetterSecondBot.HttpService
+{
+ public class SecondbotIm : WebApiControllerWithTokens
+ {
+ public SecondbotIm(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { }
+
+ [Route(HttpVerbs.Get, "/chatwindows/{token}")]
+ public object chatwindows(string token)
+ {
+ if (tokens.Allow(token, getClientIP()) == true)
+ {
+ return BasicReply(JsonConvert.SerializeObject(bot.GetIMChatWindowKeyNames()));
+ }
+ return BasicReply("Token not accepted");
+ }
+
+ [Route(HttpVerbs.Get, "/listwithunread/{token}")]
+ public object listwithunread(string group, string token)
+ {
+ if (tokens.Allow(token, getClientIP()) == true)
+ {
+ List unreadimwindows = new List();
+ foreach (UUID window in bot.IMChatWindows())
+ {
+ if (bot.ImChatWindowHasUnread(window) == true)
+ {
+ unreadimwindows.Add(window);
+ }
+ }
+ return BasicReply(JsonConvert.SerializeObject(unreadimwindows));
+ }
+ return BasicReply("Token not accepted");
+ }
+
+ [Route(HttpVerbs.Get, "/haveunreadims/{token}")]
+ public object haveunreadims(string token)
+ {
+ if (tokens.Allow(token, getClientIP()) == true)
+ {
+ bool reply = false;
+ foreach(UUID window in bot.IMChatWindows())
+ {
+ if(bot.ImChatWindowHasUnread(window) == true)
+ {
+ reply = true;
+ break;
+ }
+ }
+ return BasicReply(reply.ToString());
+ }
+ return BasicReply("Token not accepted");
+ }
+
+ [Route(HttpVerbs.Get, "/getimchat/{window}/{token}")]
+ public object getimchat(string window, string token)
+ {
+ if (tokens.Allow(token, getClientIP()) == true)
+ {
+ if (UUID.TryParse(window, out UUID windowUUID) == true)
+ {
+ return BasicReply(JsonConvert.SerializeObject(bot.GetIMChatWindow(windowUUID)));
+ }
+ return BasicReply("Window UUID invaild");
+ }
+ return BasicReply("Token not accepted");
+ }
+
+ [Route(HttpVerbs.Post, "/sendimchat/{avatar}/{token}")]
+ public object sendgroupchat(string avatar, string token, [FormField] string message)
+ {
+ if (tokens.Allow(token, getClientIP()) == true)
+ {
+ bot.GetCommandsInterface.Call("im", avatar + "~#~" + message, UUID.Zero, "~#~");
+ return BasicReply("ok");
+ }
+ return BasicReply("Token not accepted");
+ }
+
+
+ }
+}
diff --git a/CLI/HttpService/Inventory.cs b/CLI/HttpService/Inventory.cs
index 25c4865..342960f 100644
--- a/CLI/HttpService/Inventory.cs
+++ b/CLI/HttpService/Inventory.cs
@@ -14,30 +14,100 @@ namespace BetterSecondBot.HttpService
{
public SecondbotInventory(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { }
+
+ [Route(HttpVerbs.Post, "/rename/{item}/{token}")]
+ public object rename(string item, string token, [FormField] string newname)
+ {
+ if (tokens.Allow(token, getClientIP()) == true)
+ {
+ bool status = bot.GetCommandsInterface.Call("RenameInventory", "12~#~" + item + "~#~" + newname);
+ return BasicReply(status.ToString());
+ }
+ return BasicReply("Token not accepted");
+ }
+
+ [Route(HttpVerbs.Get, "/realuuid/{item}/{token}")]
+ public object realuuid(string item, string token)
+ {
+ if (tokens.Allow(token, getClientIP()) == true)
+ {
+ if (UUID.TryParse(item, out UUID itemUUID) == true)
+ {
+ UUID reply = HelperInventory.GetAssetUUID(bot, itemUUID);
+ if (reply != UUID.Zero)
+ {
+ return BasicReply(reply.ToString());
+ }
+ }
+ return BasicReply("Failed");
+ }
+ return BasicReply("Token not accepted");
+ }
+
+ [Route(HttpVerbs.Get, "/send/{item}/{avatar}/{token}")]
+ public object send(string item, string avatar, string token)
+ {
+ if (tokens.Allow(token, getClientIP()) == true)
+ {
+ if (UUID.TryParse(item, out UUID itemUUID) == true)
+ {
+ bool status = bot.GetCommandsInterface.Call("SendItem", avatar+"~#~"+item);
+ return BasicReply(status.ToString());
+ }
+ return BasicReply("Failed - item must be a vaild UUID");
+ }
+ return BasicReply("Token not accepted");
+ }
+
+ [Route(HttpVerbs.Get, "/delete/{item}/{isfolder}/{token}")]
+ public object delete(string item,string isfolder, string token)
+ {
+ if (tokens.Allow(token, getClientIP()) == true)
+ {
+ if (UUID.TryParse(item, out UUID itemUUID) == true)
+ {
+ if (bool.TryParse(isfolder, out bool asfolder) == true)
+ {
+ bool status = false;
+ if (asfolder == true) status = bot.GetCommandsInterface.Call("DeleteInventoryFolder", item);
+ else status = bot.GetCommandsInterface.Call("DeleteInventoryItem", item);
+ return BasicReply(status.ToString());
+ }
+ return BasicReply("Failed - isfolder must be True or False");
+ }
+ return BasicReply("Failed - item must be a vaild UUID");
+ }
+ return BasicReply("Token not accepted");
+ }
+
[Route(HttpVerbs.Get, "/folders/{token}")]
- public string folders(string token)
+ public object folders(string token)
{
if(tokens.Allow(token, getClientIP()) == true)
{
- return HelperInventory.MapFolderJson(bot);
+ string reply = HelperInventory.MapFolderJson(bot);
+ if(reply != null) return BasicReply(reply);
+ return BasicReply("error");
}
- return "Token not accepted";
+ return BasicReply("Token not accepted");
}
[Route(HttpVerbs.Get, "/contents/{folderUUID}/{token}")]
- public string Contents(string folderUUID, string token)
+ public object Contents(string folderUUID, string token)
{
if (tokens.Allow(token, getClientIP()) == true)
{
if (UUID.TryParse(folderUUID, out UUID folder) == true)
{
- return HelperInventory.MapFolderInventoryJson(bot, folder);
+ return BasicReply(HelperInventory.MapFolderInventoryJson(bot, folder));
}
- return "Invaild folder UUID";
+ return BasicReply("Invaild folder UUID");
}
- return "Token not accepted";
+ return BasicReply("Token not accepted");
}
+
+
}
diff --git a/CLI/HttpService/Secondbot.cs b/CLI/HttpService/Secondbot.cs
index 8f3497b..0f3c000 100644
--- a/CLI/HttpService/Secondbot.cs
+++ b/CLI/HttpService/Secondbot.cs
@@ -3,14 +3,16 @@ using BetterSecondBotShared.Static;
using BSB.bottypes;
using OpenMetaverse;
using System.Threading.Tasks;
-
using EmbedIO;
using EmbedIO.Routing;
using EmbedIO.WebApi;
-
+using System;
+using System.Collections.Generic;
+using Newtonsoft.Json;
namespace BetterSecondBot.HttpService
{
+
public class SecondbotCoreWebAPi : WebApiControllerWithTokens
{
@@ -21,61 +23,92 @@ namespace BetterSecondBot.HttpService
}
[Route(HttpVerbs.Post, "/gettoken")]
- public string GetToken([FormField] string authcode)
+ public Object GetToken([FormField] string authcode, [FormField] string unixtimegiven)
{
- long now = helpers.UnixTimeNow() + 120;
- int loop = 0;
- bool accepted = false;
- while(loop <= 30)
+ long now = helpers.UnixTimeNow();
+ long dif = 0;
+ if(long.TryParse(unixtimegiven,out long given) == true)
{
- string hashA = helpers.GetSHA1((now + loop) + "" + config.Security_WebUIKey).Substring(0, 10);
- string hashB = helpers.GetSHA1((now - loop) + "" + config.Security_WebUIKey).Substring(0, 10);
- if ((authcode == hashA) || (authcode == hashB))
+ dif = now - given;
+ now = given;
+ }
+ if((dif < 30) && (dif > -30))
+ {
+ var raw = now.ToString() + config.Security_WebUIKey;
+ string hash = helpers.GetSHA1(raw).Substring(0, 10);
+ if (hash == authcode)
{
- accepted = true;
- break;
+ string newtoken = tokens.CreateToken(getClientIP());
+ if(newtoken != null) return BasicReply(newtoken);
}
- loop++;
}
- if(accepted == true)
+ return BasicReply("Authcode not accepted");
+ }
+
+ [Route(HttpVerbs.Get, "/friends/{token}")]
+ public object friends(string token)
+ {
+ return BasicReply(bot.getJsonFriendlist());
+ }
+
+
+ [Route(HttpVerbs.Get, "/nearme/{token}")]
+ public object nearme(string token)
+ {
+ if (bot.GetClient.Network.CurrentSim != null)
{
- return tokens.CreateToken(HttpContext.Request.RemoteEndPoint.Address);
+ Dictionary NearMe = new Dictionary();
+ Dictionary avcopy = bot.GetClient.Network.CurrentSim.ObjectsAvatars.Copy();
+ foreach (Avatar av in avcopy.Values)
+ {
+ if (av.ID != bot.GetClient.Self.AgentID)
+ {
+ NearMe.Add(av.ID, av.Name);
+ }
+ }
+ return BasicReply(JsonConvert.SerializeObject(NearMe));
}
- return "Authcode not accepted";
+ return BasicReply("Error");
+ }
+
+ [Route(HttpVerbs.Get, "/hello")]
+ public object Hello()
+ {
+ return BasicReply("world");
}
[Route(HttpVerbs.Get, "/logout/{token}")]
- public string Logout(string token)
+ public object Logout(string token)
{
if (tokens.Allow(token, getClientIP()) == true)
{
return tokens.Expire(token);
}
- return "Token not accepted";
+ return BasicReply("Token not accepted");
}
[Route(HttpVerbs.Get, "/version/{token}")]
- public string Version(string token)
+ public object Version(string token)
{
if (tokens.Allow(token, getClientIP()) == true)
{
- return bot.MyVersion;
+ return BasicReply(bot.MyVersion);
}
- return "Token not accepted";
+ return BasicReply("Token not accepted");
}
[Route(HttpVerbs.Get, "/name/{token}")]
- public string Name(string token)
+ public object Name(string token)
{
if (tokens.Allow(token, getClientIP()) == true)
{
- return bot.GetClient.Self.FirstName + " " + bot.GetClient.Self.LastName;
+ return BasicReply(bot.GetClient.Self.FirstName + " " + bot.GetClient.Self.LastName);
}
- return "Token not accepted";
+ return BasicReply("Token not accepted");
}
[Route(HttpVerbs.Post, "/command/{token}")]
- public async Task command(string token)
+ public async Task