From bb5b1b98b2cff890b0513af92802cfd6e0ff6c2c Mon Sep 17 00:00:00 2001 From: Madpeter <57852827+Madpeterz@users.noreply.github.com> Date: Thu, 8 Aug 2024 16:22:18 +0100 Subject: [PATCH] adds FriendsGetLocation --- SecondBotEvents/Commands/Friends.cs | 27 +++++++++++ SecondBotEvents/Services/DataStoreService.cs | 47 ++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/SecondBotEvents/Commands/Friends.cs b/SecondBotEvents/Commands/Friends.cs index 2046499..151e5e8 100644 --- a/SecondBotEvents/Commands/Friends.cs +++ b/SecondBotEvents/Commands/Friends.cs @@ -12,6 +12,33 @@ namespace SecondBotEvents.Commands { } + [About("Gets the location of a friend if map access was given \n also requests a update")] + [ReturnHints("a json object of global region X,Y sim X,Y,Z and time it was updated")] + [ReturnHintsFailure("avatar lookup")] + [ReturnHintsFailure("not in friends list")] + [ReturnHintsFailure("no map access or updating")] + [ArgHints("avatar", "A avatar uuid or Firstname Lastname")] + public object FieldGetLocation(string avatar) + { + ProcessAvatar(avatar); + if (avataruuid == UUID.Zero) + { + return Failure("avatar lookup", new[] { avatar }); + } + Dictionary FriendListCopy = GetClient().Friends.FriendList.Copy(); + if(FriendListCopy.ContainsKey(avataruuid) == false) + { + return Failure("not in friends list (updating)", new[] { avatar }); + } + GetClient().Friends.MapFriend(avataruuid); + FriendLocations loc = master.DataStoreService.GetFriendMap(avataruuid); + if(loc == null) + { + return Failure("no map access or updating", new[] { avatar }); + } + return BasicReply(JsonConvert.SerializeObject(loc), new[] { avatar }); + } + [About("Gets the friendslist")] [ReturnHints("array of FriendListEntry")] public object Friendslist() diff --git a/SecondBotEvents/Services/DataStoreService.cs b/SecondBotEvents/Services/DataStoreService.cs index 0b4e1c0..d365773 100644 --- a/SecondBotEvents/Services/DataStoreService.cs +++ b/SecondBotEvents/Services/DataStoreService.cs @@ -41,6 +41,8 @@ namespace SecondBotEvents.Services protected List commandHistories = new(); + + protected long lastCleanupKeyValueStore = 0; protected long lastCleanupAvatarStore = 0; @@ -847,6 +849,35 @@ namespace SecondBotEvents.Services } List estateBanlist = null; + Dictionary FriendMapLocations = new Dictionary(); + + public FriendLocations GetFriendMap(UUID id) + { + if(FriendMapLocations.ContainsKey(id) == false) + { + return null; + } + return FriendMapLocations[id]; + } + + protected void FindFriendReply(object o, FriendFoundReplyEventArgs e) + { + uint x, y; + Utils.LongToUInts(e.RegionHandle, out x, out y); + x /= 256; + y /= 256; + Dictionary FriendListCopy = GetClient().Friends.FriendList.Copy(); + if (FriendListCopy.ContainsKey(e.AgentID) == false) + { + return; + } + FriendLocations NewEntry = new FriendLocations(FriendListCopy[e.AgentID].Name, e.Location, new Vector3(x,y,10)); + if(FriendMapLocations.ContainsKey(e.AgentID) == false) + { + FriendMapLocations.Add(e.AgentID, NewEntry); + } + FriendMapLocations[e.AgentID] = NewEntry; + } protected void EstateBans(object o, EstateBansReplyEventArgs e) { @@ -883,6 +914,7 @@ namespace SecondBotEvents.Services GetClient().Groups.GroupMembersReply += GroupMembers; GetClient().Groups.GroupRoleDataReply += GroupRoles; GetClient().Estate.EstateBansReply += EstateBans; + GetClient().Friends.FriendFoundReply += FindFriendReply; GetClient().Groups.RequestCurrentGroups(); GetClient().Self.RetrieveInstantMessages(); } @@ -1114,6 +1146,21 @@ namespace SecondBotEvents.Services Unixtime = setUnixtime; } } + + public class FriendLocations + { + public string Name; + public Vector3 Pos; + public Vector3 RegionPos; + public long time; + public FriendLocations(string SetName, Vector3 setPos, Vector3 setRegionPos) + { + time = SecondbotHelpers.UnixTimeNow(); + Name = SetName; + Pos = setPos; + RegionPos = setRegionPos; + } + } }