tracking
This commit is contained in:
parent
d73497dff4
commit
2330d962e7
2 changed files with 96 additions and 0 deletions
|
|
@ -7,6 +7,7 @@ using System.Threading;
|
|||
using static BetterSecondBot.Program;
|
||||
using BetterSecondbot.BetterAtHome;
|
||||
using BetterSecondbot.DataStorage;
|
||||
using BetterSecondbot.Tracking;
|
||||
|
||||
namespace BetterSecondBot
|
||||
{
|
||||
|
|
@ -16,6 +17,7 @@ namespace BetterSecondBot
|
|||
protected bool exitBot = false;
|
||||
public SecondBot Bot;
|
||||
protected BetterAtHome betterAtHomeService;
|
||||
protected BetterTracking betterTracking;
|
||||
protected Datastorage datastorage;
|
||||
|
||||
protected void keep_alive()
|
||||
|
|
@ -48,6 +50,7 @@ namespace BetterSecondBot
|
|||
}).Start();
|
||||
}
|
||||
betterAtHomeService = new BetterAtHome(this, Config);
|
||||
betterTracking = new BetterTracking(this);
|
||||
datastorage = new Datastorage(this);
|
||||
}
|
||||
public Cli(JsonConfig Config, bool as_docker, bool use_self_keep_alive)
|
||||
|
|
|
|||
93
BetterSecondbot/Tracking/BetterTracking.cs
Normal file
93
BetterSecondbot/Tracking/BetterTracking.cs
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
using BetterSecondBot;
|
||||
using BetterSecondBotShared.logs;
|
||||
using OpenMetaverse;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace BetterSecondbot.Tracking
|
||||
{
|
||||
public class BetterTracking
|
||||
{
|
||||
protected Cli controler = null;
|
||||
|
||||
protected bool output_to_url = false;
|
||||
|
||||
protected bool output_to_channel = false;
|
||||
protected int output_channel = 0;
|
||||
|
||||
|
||||
protected Dictionary<UUID, long> AvatarSeen = new Dictionary<UUID, long>();
|
||||
|
||||
public BetterTracking(Cli setcontroler)
|
||||
{
|
||||
controler = setcontroler;
|
||||
if(controler.Bot.getMyConfig.Setting_Tracker.ToLowerInvariant() == "false")
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(int.TryParse(controler.Bot.getMyConfig.Setting_Tracker,out output_channel) == true)
|
||||
{
|
||||
output_to_channel = true;
|
||||
attachEvents();
|
||||
}
|
||||
else if (controler.Bot.getMyConfig.Setting_Tracker.StartsWith("http") == true)
|
||||
{
|
||||
output_to_url = true;
|
||||
attachEvents();
|
||||
}
|
||||
}
|
||||
protected void attachEvents()
|
||||
{
|
||||
controler.Bot.GetClient.Grid.CoarseLocationUpdate += LocationUpdate;
|
||||
}
|
||||
|
||||
protected void output(UUID av, string mode)
|
||||
{
|
||||
string output = av.ToString() + "|||" + mode;
|
||||
if (output_to_channel == true)
|
||||
{
|
||||
controler.Bot.GetClient.Self.Chat(output, output_channel, ChatType.Normal);
|
||||
}
|
||||
if(output_to_url)
|
||||
{
|
||||
Thread newThread = new Thread(this.SendHTTPData);
|
||||
newThread.Start(output);
|
||||
}
|
||||
}
|
||||
|
||||
protected HttpClient HTTPclient = new HttpClient();
|
||||
|
||||
protected void SendHTTPData(object data)
|
||||
{
|
||||
Dictionary<string, string> values = new Dictionary<string, string>
|
||||
{
|
||||
{ "reply", data.ToString() },
|
||||
};
|
||||
|
||||
var content = new FormUrlEncodedContent(values);
|
||||
try
|
||||
{
|
||||
HTTPclient.PostAsync(controler.Bot.getMyConfig.Setting_Tracker, content);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogFormater.Crit("[Tracker] HTTP failed: " + e.Message + "");
|
||||
}
|
||||
}
|
||||
|
||||
protected void LocationUpdate(object o, CoarseLocationUpdateEventArgs e)
|
||||
{
|
||||
foreach(UUID av in e.NewEntries)
|
||||
{
|
||||
output(av, "entry");
|
||||
}
|
||||
foreach(UUID av in e.RemovedEntries)
|
||||
{
|
||||
output(av, "exit");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue