From feacb8318200d063e38237a2c72ace0964627e19 Mon Sep 17 00:00:00 2001 From: Madpeter <57852827+Madpeterz@users.noreply.github.com> Date: Sun, 29 May 2022 23:08:34 +0100 Subject: [PATCH] wip --- SecondBotEvents/Commands/Avatars.cs | 2 +- SecondBotEvents/Commands/Core.cs | 18 -- SecondBotEvents/Commands/Group.cs | 134 +++----- SecondBotEvents/Config/DataStoreConfig.cs | 12 + SecondBotEvents/Services/Commands.cs | 16 +- SecondBotEvents/Services/DataStoreService.cs | 292 +++++++++++++----- SecondBotEvents/Services/DiscordService.cs | 10 +- SecondBotEvents/Services/HttpService.cs | 8 +- .../Services/InteractionService.cs | 34 +- 9 files changed, 303 insertions(+), 223 deletions(-) diff --git a/SecondBotEvents/Commands/Avatars.cs b/SecondBotEvents/Commands/Avatars.cs index 3cdcf74..6bfc0a0 100644 --- a/SecondBotEvents/Commands/Avatars.cs +++ b/SecondBotEvents/Commands/Avatars.cs @@ -103,7 +103,7 @@ namespace SecondBotEvents.Commands { return Failure("Token not accepted"); } - if(name != null) + if(name == null) { return Failure("Not a vaild name"); } diff --git a/SecondBotEvents/Commands/Core.cs b/SecondBotEvents/Commands/Core.cs index e5be4e1..01e44a9 100644 --- a/SecondBotEvents/Commands/Core.cs +++ b/SecondBotEvents/Commands/Core.cs @@ -21,24 +21,6 @@ namespace SecondBotEvents.Commands return BasicReply("world", "Hello"); } - [About("Delays a thead by X ms
Mostly pointless but good if your doing custom commands")] - [ReturnHintsFailure("Invaild amount")] - [ReturnHints("ok")] - [Route(HttpVerbs.Get, "/Delay/{amount}/{token}")] - public object Delay(string amount,string token) - { - if (AllowToken(token) == false) - { - return Failure("Token not accepted"); - } - if (int.TryParse(amount,out int amountvalue) == false) - { - return Failure("Invaild amount", "Delay", new [] { amount }); - } - Thread.Sleep(amountvalue); - return BasicReply("Ok", "Delay", new [] { amount }); - } - [About("Removes the given token from the accepted token pool")] [ReturnHints("ok")] [Route(HttpVerbs.Get, "/LogoutUI/{token}")] diff --git a/SecondBotEvents/Commands/Group.cs b/SecondBotEvents/Commands/Group.cs index 9106437..5994594 100644 --- a/SecondBotEvents/Commands/Group.cs +++ b/SecondBotEvents/Commands/Group.cs @@ -35,8 +35,7 @@ namespace SecondBotEvents.Commands return Failure("Invaild group UUID", "IsGroupMember", new [] { group, avatar }); } ProcessAvatar(avatar); - return Failure("@todo group membership storage"); - // IsGroupMemberReply object + return BasicReply(master.DataStoreService.IsGroupMember(groupuuid, avataruuid).ToString()); } [About("Gets membership of a group")] @@ -57,7 +56,7 @@ namespace SecondBotEvents.Commands { return Failure("Invaild group UUID", "GetGroupMembers", new [] { group }); } - return Failure("@todo group membership storage"); + return BasicReply(JsonConvert.SerializeObject(master.DataStoreService.GetGroupMembers(groupuuid))); } [About("Attempts to ban/unban a given avatar from a group")] @@ -124,6 +123,10 @@ namespace SecondBotEvents.Commands { return Failure("Invaild group UUID", "GroupEject", new [] { group, avatar }); } + if (getClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false) + { + return Failure("Unknown group", "GroupEject", new[] { group, avatar }); + } ProcessAvatar(avatar); if (avataruuid == null) { @@ -134,13 +137,12 @@ namespace SecondBotEvents.Commands } [About("Adds the avatar to the Group with the role \n if they are not in the group then it invites them at that role")] - [ReturnHints("Roles updated")] [ReturnHints("Invite sent")] + [ReturnHints("Adding role")] [ReturnHintsFailure("Updating")] [ReturnHintsFailure("Unknown group")] [ReturnHintsFailure("Invaild group UUID")] [ReturnHintsFailure("Invaild role UUID")] - [ReturnHintsFailure("Not in group")] [ReturnHintsFailure("avatar lookup")] [ArgHints("group", "URLARG", "the UUID of the group")] [ArgHints("avatar", "URLARG", "the UUID of the avatar you wish to check with")] @@ -159,7 +161,18 @@ namespace SecondBotEvents.Commands { return Failure("Invaild role UUID", "GroupAddRole", new [] { group, avatar }); } - return Failure("@todo group membership storage"); + if (getClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false) + { + return Failure("Unknown group", "GroupAddRole", new[] { group, avatar, role }); + } + ProcessAvatar(avatar); + if(master.DataStoreService.IsGroupMember(groupuuid, avataruuid) == false) + { + getClient().Groups.Invite(groupuuid, new List() { UUID.Zero, roleuuid }, avataruuid); + return BasicReply("Invite sent"); + } + getClient().Groups.AddToRole(groupuuid, roleuuid, avataruuid); + return BasicReply("Adding role"); } [About("Invites selected avatar to the group with the selected role")] @@ -184,20 +197,27 @@ namespace SecondBotEvents.Commands { return Failure("Invaild group UUID", "GroupInvite", new [] { group, avatar, role }); } + if (getClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false) + { + return Failure("Unknown group", "GroupInvite", new[] { group, avatar, role }); + } ProcessAvatar(avatar); if (avataruuid == UUID.Zero) { return Failure("avatar lookup", "GroupInvite", new [] { group, avatar, role }); } - if(role == "everyone") + List roles = new List(); + roles.Add(UUID.Zero); + if(role != "everyone") { - role = UUID.Zero.ToString(); + UUID roleuuid = UUID.Zero; + if (UUID.TryParse(role, out roleuuid) == false) + { + return Failure("Unable to process role UUID", "GroupInvite", new[] { group, avatar, role }); + } + roles.Add(roleuuid); } - if(UUID.TryParse(role,out UUID roleuuid) == false) - { - return Failure("Unable to process role UUID", "GroupInvite", new [] { group, avatar, role }); - } - getClient().Groups.Invite(groupuuid, new List() { roleuuid }, avataruuid); + getClient().Groups.Invite(groupuuid, roles, avataruuid); return BasicReply("Invite sent", "GroupInvite", new [] { group, avatar, role }); } @@ -234,15 +254,12 @@ namespace SecondBotEvents.Commands { return Failure("Message empty", "Groupnotice", new [] { group, title, message }); } - return Failure("@todo groups stoage"); - /* GroupNotice NewNotice = new GroupNotice(); NewNotice.Subject = title; NewNotice.Message = message; NewNotice.OwnerID = getClient().Self.AgentID; getClient().Groups.SendGroupNotice(groupuuid, NewNotice); return BasicReply("Sending notice", "Groupnotice", new [] { group, title, message }); - */ } [About("Activates the selected title")] @@ -338,13 +355,6 @@ namespace SecondBotEvents.Commands { return Failure("Message empty", "GroupnoticeWithAttachment", new [] { group, title, message, attachment }); } - return Failure("@togo groups storage"); - /* - Group G = bot.MyGroups[groupuuid]; - if (G.Powers.HasFlag(GroupPowers.SendNotices) == false) - { - return Failure("Missing group notice power", "GroupnoticeWithAttachment", new [] { group, title, message, attachment }); - } GroupNotice NewNotice = new GroupNotice(); NewNotice.Subject = title; NewNotice.Message = message; @@ -352,7 +362,6 @@ namespace SecondBotEvents.Commands NewNotice.AttachmentID = inventoryuuid; getClient().Groups.SendGroupNotice(groupuuid, NewNotice); return BasicReply("Sending notice with attachment", "GroupnoticeWithAttachment", new [] { group, title, message, attachment }); - */ } @@ -365,18 +374,10 @@ namespace SecondBotEvents.Commands { return Failure("Token not accepted"); } - return Failure("@togo groups storage"); - /* - Dictionary grouppackage = new Dictionary(); - foreach (KeyValuePair entry in bot.MyGroups) - { - grouppackage.Add(entry.Value.ID.ToString(), entry.Value.Name); - } - return BasicReply(JsonConvert.SerializeObject(grouppackage), "GetGroupList"); - */ + return BasicReply(JsonConvert.SerializeObject(master.DataStoreService.GetGroups())); } - [About("Requests the roles for the selected group
Replys with GroupRoleDetails object formated as follows
  • UpdateUnderway (Bool)
  • RoleDataAge (Int) [default -1]
  • Roles (KeyPair array of UUID=Name)

")] + [About("Requests the roles for the selected group")] [ReturnHints("GroupRoleDetails object")] [ReturnHintsFailure("Group is not currently known")] [ReturnHintsFailure("Invaild group UUID")] @@ -536,70 +537,5 @@ namespace SecondBotEvents.Commands } return Failure("@todo groupchat"); } - - protected KeyValuePair waitForReady(bool avatar, bool group, UUID groupuuid) - { - /* this function is poorly named - * and is ugly :( - */ - bool exit = false; - int sleeps = 0; - string failed_on = ""; - bool allok = true; - while (exit == false) - { - allok = true; - failed_on = ""; - if (avatar == true) - { - if (avataruuid == UUID.Zero) - { - allok = false; - failed_on = "avatar lookup"; - } - } - if ((group == true) && (allok == true)) - { - // @todo wait for group loading - allok = true; - failed_on = "Updating"; - } - if (allok == false) - { - if (sleeps > 3) - { - exit = true; - } - } - if (allok == true) - { - exit = true; - } - else - { - if (exit == false) - { - Thread.Sleep(1000); - sleeps++; - } - } - } - return new KeyValuePair(allok, failed_on); - } - } - - public class GroupRoleDetails - { - public bool UpdateUnderway { get; set; } - public Dictionary Roles { get; set; } - public long RoleDataAge = 0; - } - - public class IsGroupMemberReply - { - public bool membershipStatus { get; set; } - public string AvatarUUID { get; set; } - public string GroupUUID { get; set; } - public string AvatarnameIfKnown { get; set; } } } diff --git a/SecondBotEvents/Config/DataStoreConfig.cs b/SecondBotEvents/Config/DataStoreConfig.cs index 5a01554..0819e63 100644 --- a/SecondBotEvents/Config/DataStoreConfig.cs +++ b/SecondBotEvents/Config/DataStoreConfig.cs @@ -15,6 +15,18 @@ namespace SecondBotEvents.Config settings.Add("GroupChatHistoryLimitPerGroup"); settings.Add("ImChatHistoryLimit"); settings.Add("NotecardStoragePurgeAfterMins"); + settings.Add("PrefetchGroupMembers"); + settings.Add("PrefetchGroupRoles"); + } + + public bool GetPrefetchGroupRoles() + { + return ReadSettingAsBool("PrefetchGroupRoles", false); + } + + public bool GetPrefetchGroupMembers() + { + return ReadSettingAsBool("PrefetchGroupMembers", true); } public int GetAvatarsPurgeAfterMins() diff --git a/SecondBotEvents/Services/Commands.cs b/SecondBotEvents/Services/Commands.cs index 9b706eb..c4731b2 100644 --- a/SecondBotEvents/Services/Commands.cs +++ b/SecondBotEvents/Services/Commands.cs @@ -127,7 +127,7 @@ namespace SecondBotEvents.Services { return; } - if (e.IM.FromAgentName == master.botClient.client.Self.Name) + if (e.IM.FromAgentName == getClient().Self.Name) { return; } @@ -209,11 +209,11 @@ namespace SecondBotEvents.Services LogFormater.Crit("[SmartReply] output Channel must be zero or higher - using 99"); target_channel = 999; } - master.botClient.client.Self.Chat(output, target_channel, ChatType.Normal); + getClient().Self.Chat(output, target_channel, ChatType.Normal); } else if (mode == "IM") { - master.botClient.client.Self.InstantMessage(target_avatar, output); + getClient().Self.InstantMessage(target_avatar, output); } else if (mode == "HTTP") { @@ -305,20 +305,20 @@ namespace SecondBotEvents.Services { acceptNewCommands = false; Console.WriteLine("Commands service [Attached to new client]"); - master.botClient.client.Network.LoggedOut += BotLoggedOut; - master.botClient.client.Network.SimConnected += BotLoggedIn; + getClient().Network.LoggedOut += BotLoggedOut; + getClient().Network.SimConnected += BotLoggedIn; } protected void BotLoggedOut(object o, LoggedOutEventArgs e) { - master.botClient.client.Network.SimConnected += BotLoggedIn; + getClient().Network.SimConnected += BotLoggedIn; Console.WriteLine("Commands service [Waiting for connect]"); } protected void BotLoggedIn(object o, SimConnectedEventArgs e) { - master.botClient.client.Network.SimConnected -= BotLoggedIn; - master.botClient.client.Self.IM += BotImMessage; + getClient().Network.SimConnected -= BotLoggedIn; + getClient().Self.IM += BotImMessage; if (myConfig.GetOnlyMasterAvs() == true) { foreach(string A in myConfig.GetMastersCSV()) diff --git a/SecondBotEvents/Services/DataStoreService.cs b/SecondBotEvents/Services/DataStoreService.cs index 54a7018..9b25730 100644 --- a/SecondBotEvents/Services/DataStoreService.cs +++ b/SecondBotEvents/Services/DataStoreService.cs @@ -5,6 +5,7 @@ using System; using System.Linq; using System.Collections; using System.Collections.Generic; +using System.Threading; namespace SecondBotEvents.Services { @@ -27,19 +28,66 @@ namespace SecondBotEvents.Services } protected Dictionary avatarsName2Key = new Dictionary(); - protected Dictionary avatarsKey2Name = new Dictionary(); protected Dictionary groupsKey2Name = new Dictionary(); - protected Dictionary groupsName2Key = new Dictionary(); + + protected Dictionary> groupMembers = new Dictionary>(); + protected Dictionary> groupRoles = new Dictionary>(); protected List localChatHistory = new List(); - protected Dictionary> chatWindows = new Dictionary>(); // sess, list chat protected Dictionary chatWindowsUnread = new Dictionary(); // sess, bool protected Dictionary chatWindowsIsGroup = new Dictionary(); // sess, bool protected Dictionary chatWindowsOwner = new Dictionary(); // sess, owner id + public Dictionary GetGroups() + { + return groupsKey2Name; + } + public bool IsGroupMember(UUID Group, UUID avatar) + { + if(groupMembers.ContainsKey(Group) == false) + { + groupMembers.Add(Group, new List()); + } + if(groupMembers[Group].Contains(avatar) == false) + { + bool found = false; + AutoResetEvent fetchEvent = new AutoResetEvent(false); + EventHandler callback = + delegate (object sender, GroupMembersReplyEventArgs e) + { + if (e.GroupID == Group) + { + foreach (KeyValuePair a in e.Members) + { + if (a.Value.ID == avatar) + { + found = true; + break; + } + } + } + }; + getClient().Groups.GroupMembersReply += callback; + getClient().Groups.RequestGroupMembers(Group); + + fetchEvent.WaitOne(1000, false); + getClient().Groups.GroupMembersReply -= callback; + return found; + } + return true; + } + + public List GetGroupMembers(UUID Group) + { + if (groupMembers.ContainsKey(Group) == false) + { + groupMembers.Add(Group, new List()); + } + return groupMembers[Group]; + } protected void recordChat(UUID sessionID, string fromname, string message) { @@ -61,6 +109,33 @@ namespace SecondBotEvents.Services counter--; } } + + protected void closeChat(UUID owner) + { + UUID sessionID = UUID.Zero; + if(chatWindowsOwner.ContainsValue(owner) == false) + { + return; + } + foreach(KeyValuePair ownermap in chatWindowsOwner) + { + if(ownermap.Value != owner) + { + continue; + } + sessionID = ownermap.Key; + } + if(sessionID == UUID.Zero) + { + return; + } + chatWindowsOwner.Remove(sessionID); + chatWindowsIsGroup.Remove(sessionID); + chatWindowsUnread.Remove(sessionID); + chatWindows.Remove(sessionID); + + } + protected void openChatWindow(bool group, UUID sessionID, UUID ownerID) { if (chatWindows.ContainsKey(sessionID) == true) @@ -109,7 +184,7 @@ namespace SecondBotEvents.Services { return groupsKey2Name.ContainsKey(groupId); } - return groupsName2Key.ContainsKey(name); + return groupsKey2Name.ContainsValue(name); } public List getGroupChat(UUID groupId) @@ -139,13 +214,14 @@ namespace SecondBotEvents.Services * if not the bot will attempt to * lookup the avatar */ + public bool knownAvatar(string name, UUID avatarId) { - int currentHash = master.botClient.client.Network.CurrentSim.ObjectsAvatars.GetHashCode(); + int currentHash = getClient().Network.CurrentSim.ObjectsAvatars.GetHashCode(); if (currentHash != ObjectsAvatarsHash) { ObjectsAvatarsHash = currentHash; - List avs = master.botClient.client.Network.CurrentSim.ObjectsAvatars.Copy().Values.ToList(); + List avs = getClient().Network.CurrentSim.ObjectsAvatars.Copy().Values.ToList(); foreach (Avatar A in avs) { addAvatar(A.ID, A.Name); @@ -153,10 +229,28 @@ namespace SecondBotEvents.Services } if (avatarId != UUID.Zero) { - if(avatarsKey2Name.ContainsKey(avatarId) == false) + if(avatarsName2Key.ContainsValue(avatarId) == false) { - master.botClient.client.Avatars.RequestAvatarName(avatarId); - return false; + bool hasReply = false; + AutoResetEvent fetchEvent = new AutoResetEvent(false); + EventHandler callback = + delegate (object sender, UUIDNameReplyEventArgs e) + { + foreach (KeyValuePair av in e.Names) + { + if (av.Key == avatarId) + { + hasReply = true; + fetchEvent.Set(); + } + } + }; + getClient().Avatars.UUIDNameReply += callback; + getClient().Avatars.RequestAvatarName(avatarId); + + fetchEvent.WaitOne(1000, false); + getClient().Avatars.UUIDNameReply -= callback; + return hasReply; } return true; } @@ -167,8 +261,31 @@ namespace SecondBotEvents.Services } if (avatarsName2Key.ContainsKey(name) == false) { - master.botClient.client.Avatars.RequestAvatarNameSearch(name, UUID.Random()); - return false; + UUID wantedReplyID = UUID.SecureRandom(); + + bool hasReply = false; + AutoResetEvent fetchEvent = new AutoResetEvent(false); + EventHandler callback = + delegate (object sender, AvatarPickerReplyEventArgs e) + { + if (e.QueryID == wantedReplyID) + { + foreach(KeyValuePair av in e.Avatars) + { + if(av.Value == name) + { + hasReply = true; + fetchEvent.Set(); + } + } + } + }; + getClient().Avatars.AvatarPickerReply += callback; + getClient().Avatars.RequestAvatarNameSearch(name, wantedReplyID); + + fetchEvent.WaitOne(1000, false); + getClient().Avatars.AvatarPickerReply -= callback; + return hasReply; } return true; } @@ -179,7 +296,16 @@ namespace SecondBotEvents.Services { return "lookup"; } - return avatarsKey2Name[avatarId]; + string results = "lookup"; + foreach (KeyValuePair av in avatarsName2Key) + { + if(av.Value == avatarId) + { + results = av.Key; + break; + } + } + return results; } public string getAvatarUUID(string name) @@ -304,43 +430,74 @@ namespace SecondBotEvents.Services protected void reset() { avatarsName2Key = new Dictionary(); - avatarsKey2Name = new Dictionary(); groupsKey2Name = new Dictionary(); - groupsName2Key = new Dictionary(); + + groupMembers = new Dictionary>(); + groupRoles = new Dictionary>(); localChatHistory = new List(); notecardDataStore = new Dictionary>(); - } + + chatWindows = new Dictionary>(); // sess, list chat + chatWindowsUnread = new Dictionary(); // sess, bool + chatWindowsIsGroup = new Dictionary(); // sess, bool + chatWindowsOwner = new Dictionary(); // sess, owner id + } protected void BotClientRestart(object o, BotClientNotice e) { botConnected = false; Console.WriteLine("DataStore Service [Attached to new client]"); - master.botClient.client.Network.LoggedOut += BotLoggedOut; - master.botClient.client.Network.SimConnected += BotLoggedIn; + getClient().Network.LoggedOut += BotLoggedOut; + getClient().Network.SimConnected += BotLoggedIn; } protected void BotLoggedOut(object o, LoggedOutEventArgs e) { botConnected = false; - master.botClient.client.Network.SimConnected += BotLoggedIn; + getClient().Network.SimConnected += BotLoggedIn; Console.WriteLine("DataStore Service [Standby]"); } + protected void GroupRoles(object o, GroupRolesDataReplyEventArgs e) + { + if(groupRoles.ContainsKey(e.GroupID) == false) + { + groupRoles.Add(e.GroupID, new Dictionary()); + } + groupRoles[e.GroupID] = e.Roles; + } + + protected void GroupMembers(object o, GroupMembersReplyEventArgs e) + { + if(groupMembers.ContainsKey(e.GroupID) == true) + { + groupMembers.Remove(e.GroupID); + } + groupMembers.Add(e.GroupID, new List()); + foreach (KeyValuePair a in e.Members) + { + groupMembers[e.GroupID].Add(a.Value.ID); + } + } + protected void BotLoggedIn(object o, SimConnectedEventArgs e) { - master.botClient.client.Network.SimConnected -= BotLoggedIn; - master.botClient.client.Groups.CurrentGroups += GroupCurrent; - master.botClient.client.Groups.GroupJoinedReply += GroupJoin; - master.botClient.client.Groups.GroupLeaveReply += GroupLeave; - master.botClient.client.Avatars.UUIDNameReply += AvatarUUIDName; - master.botClient.client.Friends.FriendNames += AvatarFriendNames; - master.botClient.client.Self.IM += ImEvent; - master.botClient.client.Self.ChatFromSimulator += ChatFromSim; - master.botClient.client.Groups.RequestCurrentGroups(); + getClient().Network.SimConnected -= BotLoggedIn; + getClient().Groups.CurrentGroups += GroupCurrent; + getClient().Groups.GroupJoinedReply += GroupJoin; + getClient().Groups.GroupLeaveReply += GroupLeave; + getClient().Avatars.UUIDNameReply += AvatarUUIDName; + getClient().Friends.FriendNames += AvatarFriendNames; + getClient().Self.IM += ImEvent; + getClient().Self.ChatFromSimulator += ChatFromSim; + getClient().Avatars.AvatarPickerReply += AvatarUUIDNamePicker; + getClient().Groups.GroupMembersReply += GroupMembers; + getClient().Groups.GroupRoleDataReply += GroupRoles; + getClient().Groups.RequestCurrentGroups(); botConnected = true; Console.WriteLine("DataStore Service [Active]"); } @@ -362,7 +519,11 @@ namespace SecondBotEvents.Services break; } localChatHistory.Add(e.FromName + ": " + e.Message); - cleanLocalChat(); + if (localChatHistory.Count <= myConfig.GetLocalChatHistoryLimit()) + { + break; + } + localChatHistory.RemoveAt(0); break; } default: @@ -383,8 +544,15 @@ namespace SecondBotEvents.Services continue; } groupsKey2Name.Add(G.ID, G.Name); - groupsName2Key.Add(G.Name, G.ID); - master.botClient.client.Self.RequestJoinGroupChat(G.ID); + getClient().Self.RequestJoinGroupChat(G.ID); + if (myConfig.GetPrefetchGroupMembers() == true) + { + getClient().Groups.RequestGroupMembers(G.ID); + } + if(myConfig.GetPrefetchGroupRoles() == true) + { + getClient().Groups.RequestGroupRoles(G.ID); + } } foreach(UUID G in missingGroups) @@ -395,28 +563,26 @@ namespace SecondBotEvents.Services } string name = groupsKey2Name[G]; groupsKey2Name.Remove(G); - groupsName2Key.Remove(name); - // @todo remove group chat here + closeChat(G); } } protected void GroupJoin(object o, GroupOperationEventArgs e) { - master.botClient.client.Groups.RequestCurrentGroups(); + getClient().Groups.RequestCurrentGroups(); } protected void GroupLeave(object o, GroupOperationEventArgs e) { - master.botClient.client.Groups.RequestCurrentGroups(); + getClient().Groups.RequestCurrentGroups(); } protected void addAvatar(UUID id, string name) { - if (avatarsKey2Name.ContainsKey(id) == true) + if (avatarsName2Key.ContainsValue(id) == true) { return; } - avatarsKey2Name.Add(id, name); avatarsName2Key.Add(name, id); } @@ -428,6 +594,14 @@ namespace SecondBotEvents.Services } } + protected void AvatarUUIDNamePicker(object o, AvatarPickerReplyEventArgs e) + { + foreach(KeyValuePair Av in e.Avatars) + { + addAvatar(Av.Key, Av.Value); + } + } + protected void AvatarFriendNames(object o, FriendNamesEventArgs e) { foreach (KeyValuePair pair in e.Names) @@ -436,33 +610,6 @@ namespace SecondBotEvents.Services } } - protected void cleanGroupChat(UUID groupID) - { - if(groupsKey2Name.ContainsKey(groupID) == false) - { - return; - } - // @todo clean group chat here - } - - protected void cleanAvatarChat(UUID avatarID) - { - if (avatarsKey2Name.ContainsKey(avatarID) == false) - { - return; - } - // @todo clean avatar chat here - } - - protected void cleanLocalChat() - { - if (localChatHistory.Count <= myConfig.GetLocalChatHistoryLimit()) - { - return; - } - localChatHistory.RemoveAt(0); - } - protected void ImEvent(object o, InstantMessageEventArgs e) { switch(e.IM.Dialog) @@ -512,15 +659,18 @@ namespace SecondBotEvents.Services master.BotClientNoticeEvent -= BotClientRestart; if (master.botClient != null) { - if (master.botClient.client != null) + if (getClient() != null) { - master.botClient.client.Groups.CurrentGroups -= GroupCurrent; - master.botClient.client.Groups.GroupJoinedReply -= GroupJoin; - master.botClient.client.Groups.GroupLeaveReply -= GroupLeave; - master.botClient.client.Avatars.UUIDNameReply -= AvatarUUIDName; - master.botClient.client.Friends.FriendNames -= AvatarFriendNames; - master.botClient.client.Self.IM -= ImEvent; - master.botClient.client.Self.ChatFromSimulator -= ChatFromSim; + getClient().Groups.CurrentGroups -= GroupCurrent; + getClient().Groups.GroupJoinedReply -= GroupJoin; + getClient().Groups.GroupLeaveReply -= GroupLeave; + getClient().Avatars.UUIDNameReply -= AvatarUUIDName; + getClient().Friends.FriendNames -= AvatarFriendNames; + getClient().Self.IM -= ImEvent; + getClient().Self.ChatFromSimulator -= ChatFromSim; + getClient().Avatars.AvatarPickerReply -= AvatarUUIDNamePicker; + getClient().Groups.GroupMembersReply -= GroupMembers; + getClient().Groups.GroupRoleDataReply -= GroupRoles; } } Console.WriteLine("DataStore Service [Stopping]"); diff --git a/SecondBotEvents/Services/DiscordService.cs b/SecondBotEvents/Services/DiscordService.cs index 0a42d4c..58534e3 100644 --- a/SecondBotEvents/Services/DiscordService.cs +++ b/SecondBotEvents/Services/DiscordService.cs @@ -97,13 +97,13 @@ namespace SecondBotEvents.Services { Console.WriteLine("Discord service [Avi link - Restarting]"); acceptChat = false; - master.botClient.client.Network.LoggedOut += BotLoggedOut; - master.botClient.client.Network.SimConnected += BotLoggedIn; + getClient().Network.LoggedOut += BotLoggedOut; + getClient().Network.SimConnected += BotLoggedIn; } protected void BotLoggedOut(object o, LoggedOutEventArgs e) { - master.botClient.client.Network.SimConnected += BotLoggedIn; + getClient().Network.SimConnected += BotLoggedIn; acceptChat = false; Console.WriteLine("Discord service [Avi link - standby]"); } @@ -164,8 +164,8 @@ namespace SecondBotEvents.Services protected void BotLoggedIn(object o, SimConnectedEventArgs e) { acceptChat = true; - master.botClient.client.Network.SimConnected -= BotLoggedIn; - master.botClient.client.Self.IM += BotImMessage; + getClient().Network.SimConnected -= BotLoggedIn; + getClient().Self.IM += BotImMessage; Console.WriteLine("Discord service [Avi link - Active]"); } diff --git a/SecondBotEvents/Services/HttpService.cs b/SecondBotEvents/Services/HttpService.cs index 21d6e86..f1b92e6 100644 --- a/SecondBotEvents/Services/HttpService.cs +++ b/SecondBotEvents/Services/HttpService.cs @@ -53,20 +53,20 @@ namespace SecondBotEvents.Services { acceptBotCommands = false; Console.WriteLine("HTTP service [Attached to new client]"); - master.botClient.client.Network.LoggedOut += BotLoggedOut; - master.botClient.client.Network.SimConnected += BotLoggedIn; + getClient().Network.LoggedOut += BotLoggedOut; + getClient().Network.SimConnected += BotLoggedIn; } protected void BotLoggedOut(object o, LoggedOutEventArgs e) { acceptBotCommands = false; - master.botClient.client.Network.SimConnected += BotLoggedIn; + getClient().Network.SimConnected += BotLoggedIn; Console.WriteLine("HTTP service [Bot commands disabled]"); } protected void BotLoggedIn(object o, SimConnectedEventArgs e) { - master.botClient.client.Network.SimConnected -= BotLoggedIn; + getClient().Network.SimConnected -= BotLoggedIn; acceptBotCommands = true; Console.WriteLine("HTTP service [Bot commands enabled]"); } diff --git a/SecondBotEvents/Services/InteractionService.cs b/SecondBotEvents/Services/InteractionService.cs index 545fe3a..2e11135 100644 --- a/SecondBotEvents/Services/InteractionService.cs +++ b/SecondBotEvents/Services/InteractionService.cs @@ -65,8 +65,8 @@ namespace SecondBotEvents.Services { botConnected = false; Console.WriteLine("Interaction Service [Attached to new client]"); - master.botClient.client.Network.LoggedOut += BotLoggedOut; - master.botClient.client.Network.SimConnected += BotLoggedIn; + getClient().Network.LoggedOut += BotLoggedOut; + getClient().Network.SimConnected += BotLoggedIn; } protected void jsonOuput(bool status, string eventype, string from, string why="", Dictionary setMisc = null) @@ -100,16 +100,16 @@ namespace SecondBotEvents.Services { return; } - master.botClient.client.Self.TeleportLureRespond(e.IM.FromAgentID, e.IM.IMSessionID, false); + getClient().Self.TeleportLureRespond(e.IM.FromAgentID, e.IM.IMSessionID, false); return; } jsonOuput(true, mode, e.IM.FromAgentName); if (e.IM.Dialog == InstantMessageDialog.RequestLure) { - master.botClient.client.Self.SendTeleportLure(e.IM.FromAgentID); + getClient().Self.SendTeleportLure(e.IM.FromAgentID); return; } - master.botClient.client.Self.TeleportLureRespond(e.IM.FromAgentID, e.IM.IMSessionID, true); + getClient().Self.TeleportLureRespond(e.IM.FromAgentID, e.IM.IMSessionID, true); } @@ -133,7 +133,7 @@ namespace SecondBotEvents.Services Dictionary details = new Dictionary(); details.Add("itemuuid", e.ObjectID.ToString()); details.Add("itemtype", e.AssetType.ToString()); - InventoryItem itm = master.botClient.client.Inventory.FetchItem(e.ObjectID, master.botClient.client.Self.AgentID, 2000); + InventoryItem itm = getClient().Inventory.FetchItem(e.ObjectID, getClient().Self.AgentID, 2000); if(itm != null) { details.Add("itemname", itm.Name); @@ -147,7 +147,7 @@ namespace SecondBotEvents.Services { return; } - master.botClient.client.Friends.AcceptFriendship(e.AgentID, e.SessionID); + getClient().Friends.AcceptFriendship(e.AgentID, e.SessionID); jsonOuput(true, "FriendRequest", e.AgentName); } @@ -155,17 +155,17 @@ namespace SecondBotEvents.Services protected void BotLoggedOut(object o, LoggedOutEventArgs e) { botConnected = false; - master.botClient.client.Network.SimConnected += BotLoggedIn; + getClient().Network.SimConnected += BotLoggedIn; Console.WriteLine("Interaction Service [Standby]"); } protected void BotLoggedIn(object o, SimConnectedEventArgs e) { - master.botClient.client.Network.SimConnected -= BotLoggedIn; - master.botClient.client.Friends.FriendshipOffered += BotFriendRequested; - master.botClient.client.Inventory.InventoryObjectOffered += BotInventoryOffer; - master.botClient.client.Groups.GroupInvitation += BotGroupInviteOffer; - master.botClient.client.Self.IM += BotTeleportOffer; + getClient().Network.SimConnected -= BotLoggedIn; + getClient().Friends.FriendshipOffered += BotFriendRequested; + getClient().Inventory.InventoryObjectOffered += BotInventoryOffer; + getClient().Groups.GroupInvitation += BotGroupInviteOffer; + getClient().Self.IM += BotTeleportOffer; botConnected = true; Console.WriteLine("Interaction Service [Active]"); } @@ -191,11 +191,11 @@ namespace SecondBotEvents.Services master.BotClientNoticeEvent -= BotClientRestart; if (master.botClient != null) { - if (master.botClient.client != null) + if (getClient() != null) { - master.botClient.client.Friends.FriendshipOffered -= BotFriendRequested; - master.botClient.client.Inventory.InventoryObjectOffered -= BotInventoryOffer; - master.botClient.client.Groups.GroupInvitation -= BotGroupInviteOffer; + getClient().Friends.FriendshipOffered -= BotFriendRequested; + getClient().Inventory.InventoryObjectOffered -= BotInventoryOffer; + getClient().Groups.GroupInvitation -= BotGroupInviteOffer; } } Console.WriteLine("Interaction Service [Stopping]");