This commit is contained in:
Madpeter 2022-05-29 23:08:34 +01:00
parent 0e9bce1ad5
commit feacb83182
9 changed files with 303 additions and 223 deletions

View file

@ -103,7 +103,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Token not accepted");
}
if(name != null)
if(name == null)
{
return Failure("Not a vaild name");
}

View file

@ -21,24 +21,6 @@ namespace SecondBotEvents.Commands
return BasicReply("world", "Hello");
}
[About("Delays a thead by X ms<br/>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}")]

View file

@ -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>() { 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<UUID> roles = new List<UUID>();
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<UUID>() { 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<string, string> grouppackage = new Dictionary<string, string>();
foreach (KeyValuePair<UUID, Group> 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<br/>Replys with GroupRoleDetails object formated as follows <ul><li>UpdateUnderway (Bool)</li><li>RoleDataAge (Int) [default -1]</li><li>Roles (KeyPair array of UUID=Name)</li></ul><br/>")]
[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<bool, string> 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<bool, string>(allok, failed_on);
}
}
public class GroupRoleDetails
{
public bool UpdateUnderway { get; set; }
public Dictionary<string,string> 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; }
}
}

View file

@ -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()

View file

@ -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())

View file

@ -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<string, UUID> avatarsName2Key = new Dictionary<string, UUID>();
protected Dictionary<UUID, string> avatarsKey2Name = new Dictionary<UUID, string>();
protected Dictionary<UUID, string> groupsKey2Name = new Dictionary<UUID, string>();
protected Dictionary<string, UUID> groupsName2Key = new Dictionary<string, UUID>();
protected Dictionary<UUID, List<UUID>> groupMembers = new Dictionary<UUID, List<UUID>>();
protected Dictionary<UUID, Dictionary<UUID, GroupRole>> groupRoles = new Dictionary<UUID, Dictionary<UUID, GroupRole>>();
protected List<string> localChatHistory = new List<string>();
protected Dictionary<UUID, List<string>> chatWindows = new Dictionary<UUID, List<string>>(); // sess, list chat
protected Dictionary<UUID, bool> chatWindowsUnread = new Dictionary<UUID, bool>(); // sess, bool
protected Dictionary<UUID, bool> chatWindowsIsGroup = new Dictionary<UUID, bool>(); // sess, bool
protected Dictionary<UUID, UUID> chatWindowsOwner = new Dictionary<UUID, UUID>(); // sess, owner id
public Dictionary<UUID, string> GetGroups()
{
return groupsKey2Name;
}
public bool IsGroupMember(UUID Group, UUID avatar)
{
if(groupMembers.ContainsKey(Group) == false)
{
groupMembers.Add(Group, new List<UUID>());
}
if(groupMembers[Group].Contains(avatar) == false)
{
bool found = false;
AutoResetEvent fetchEvent = new AutoResetEvent(false);
EventHandler<GroupMembersReplyEventArgs> callback =
delegate (object sender, GroupMembersReplyEventArgs e)
{
if (e.GroupID == Group)
{
foreach (KeyValuePair<UUID, GroupMember> 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<UUID> GetGroupMembers(UUID Group)
{
if (groupMembers.ContainsKey(Group) == false)
{
groupMembers.Add(Group, new List<UUID>());
}
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<UUID,UUID> 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<string> 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<Avatar> avs = master.botClient.client.Network.CurrentSim.ObjectsAvatars.Copy().Values.ToList();
List<Avatar> 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<UUIDNameReplyEventArgs> callback =
delegate (object sender, UUIDNameReplyEventArgs e)
{
foreach (KeyValuePair<UUID, string> 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<AvatarPickerReplyEventArgs> callback =
delegate (object sender, AvatarPickerReplyEventArgs e)
{
if (e.QueryID == wantedReplyID)
{
foreach(KeyValuePair<UUID,string> 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<string, UUID> 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<string, UUID>();
avatarsKey2Name = new Dictionary<UUID, string>();
groupsKey2Name = new Dictionary<UUID, string>();
groupsName2Key = new Dictionary<string, UUID>();
groupMembers = new Dictionary<UUID, List<UUID>>();
groupRoles = new Dictionary<UUID, Dictionary<UUID, string>>();
localChatHistory = new List<string>();
notecardDataStore = new Dictionary<string, KeyValuePair<string, long>>();
}
chatWindows = new Dictionary<UUID, List<string>>(); // sess, list chat
chatWindowsUnread = new Dictionary<UUID, bool>(); // sess, bool
chatWindowsIsGroup = new Dictionary<UUID, bool>(); // sess, bool
chatWindowsOwner = new Dictionary<UUID, UUID>(); // 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<UUID, string>());
}
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<UUID>());
foreach (KeyValuePair<UUID,GroupMember> 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<UUID,string> Av in e.Avatars)
{
addAvatar(Av.Key, Av.Value);
}
}
protected void AvatarFriendNames(object o, FriendNamesEventArgs e)
{
foreach (KeyValuePair<UUID, string> 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]");

View file

@ -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]");
}

View file

@ -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]");
}

View file

@ -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<string, string> 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<string, string> details = new Dictionary<string, string>();
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]");