This commit is contained in:
Madpeter 2022-06-04 07:52:06 +01:00
parent 84e53eb10e
commit dbd2ea32e4
27 changed files with 941 additions and 612 deletions

View file

@ -35,8 +35,8 @@ namespace SecondBotEvents.Commands
{
return BasicReply("Error with gesture", new [] { gesture });
}
InventoryItem itm = getClient().Inventory.FetchItem(gestureUUID, getClient().Self.AgentID, (3 * 1000));
getClient().Self.PlayGesture(itm.AssetUUID);
InventoryItem itm = GetClient().Inventory.FetchItem(gestureUUID, GetClient().Self.AgentID, (3 * 1000));
GetClient().Self.PlayGesture(itm.AssetUUID);
return BasicReply("Accepted", new [] { gesture });
}

View file

@ -17,15 +17,15 @@ namespace SecondBotEvents.Commands
[ReturnHintsFailure("Error not in a sim")]
public object NearmeWithDetails()
{
if (getClient().Network.CurrentSim == null)
if (GetClient().Network.CurrentSim == null)
{
return BasicReply("Error not in a sim");
}
List<NearMeDetails> BetterNearMe = new List<NearMeDetails>();
Dictionary<uint, Avatar> avcopy = getClient().Network.CurrentSim.ObjectsAvatars.Copy();
Dictionary<uint, Avatar> avcopy = GetClient().Network.CurrentSim.ObjectsAvatars.Copy();
foreach (Avatar av in avcopy.Values)
{
if (av.ID != getClient().Self.AgentID)
if (av.ID != GetClient().Self.AgentID)
{
NearMeDetails details = new NearMeDetails();
details.id = av.ID.ToString();
@ -33,7 +33,7 @@ namespace SecondBotEvents.Commands
details.x = (int)Math.Round(av.Position.X);
details.y = (int)Math.Round(av.Position.Y);
details.z = (int)Math.Round(av.Position.Z);
details.range = (int)Math.Round(Vector3.Distance(av.Position, getClient().Self.SimPosition));
details.range = (int)Math.Round(Vector3.Distance(av.Position, GetClient().Self.SimPosition));
BetterNearMe.Add(details);
}
}
@ -45,15 +45,15 @@ namespace SecondBotEvents.Commands
[ReturnHintsFailure("Error not in a sim")]
public object Nearme()
{
if (getClient().Network.CurrentSim == null)
if (GetClient().Network.CurrentSim == null)
{
return BasicReply("Error not in a sim");
}
Dictionary<UUID, string> NearMe = new Dictionary<UUID, string>();
Dictionary<uint, Avatar> avcopy = getClient().Network.CurrentSim.ObjectsAvatars.Copy();
Dictionary<uint, Avatar> avcopy = GetClient().Network.CurrentSim.ObjectsAvatars.Copy();
foreach (Avatar av in avcopy.Values)
{
if (av.ID != getClient().Self.AgentID)
if (av.ID != GetClient().Self.AgentID)
{
NearMe.Add(av.ID, av.Name);
}
@ -73,7 +73,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Not a vaild UUID");
}
return BasicReply(master.DataStoreService.getAvatarName(avUUID));
return BasicReply(master.DataStoreService.GetAvatarName(avUUID));
}
[About("searchs the AV database if not found triggers a lookup")]
@ -87,7 +87,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Not a vaild name");
}
return BasicReply(master.DataStoreService.getAvatarUUID(name));
return BasicReply(master.DataStoreService.GetAvatarUUID(name));
}
}
}

View file

@ -14,7 +14,7 @@ namespace SecondBotEvents.Commands
[ReturnHints("json encoded array")]
public object LocalChatHistory()
{
return BasicReply(JsonConvert.SerializeObject(master.DataStoreService.getLocalChat()));
return BasicReply(JsonConvert.SerializeObject(master.DataStoreService.GetLocalChat()));
}
[About("sends a message to localchat")]
@ -37,7 +37,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Invaild channel", new [] { channel, message });
}
getClient().Self.Chat(message, channelnum, ChatType.Normal);
GetClient().Self.Chat(message, channelnum, ChatType.Normal);
return BasicReply("ok");
}
@ -59,7 +59,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Message empty", new [] { avatar, message });
}
master.botClient.SendIM(avataruuid, message);
master.BotClient.SendIM(avataruuid, message);
return BasicReply("ok", new [] { avatar, message });
}
@ -67,21 +67,21 @@ namespace SecondBotEvents.Commands
[ReturnHints("array UUID = Name")]
public object chatwindows()
{
return BasicReply(JsonConvert.SerializeObject(master.DataStoreService.getAvatarImWindows()));
return BasicReply(JsonConvert.SerializeObject(master.DataStoreService.GetAvatarImWindows()));
}
[About("gets a list of chat windows from avatars with unread messages")]
[ReturnHints("array of UUID")]
public object listwithunread()
{
return BasicReply(JsonConvert.SerializeObject(master.DataStoreService.getAvatarImWindowsUnread()));
return BasicReply(JsonConvert.SerializeObject(master.DataStoreService.GetAvatarImWindowsUnread()));
}
[About("gets if there are any unread im messages from avatars at all")]
[ReturnHints("True|False")]
public object haveunreadims()
{
return BasicReply(master.DataStoreService.getAvatarImWindowsUnreadAny().ToString());
return BasicReply(master.DataStoreService.GetAvatarImWindowsUnreadAny().ToString());
}
[About("gets the chat from the selected window for avatar")]
@ -95,7 +95,7 @@ namespace SecondBotEvents.Commands
{
return Failure("avatar UUID invaild");
}
return BasicReply(JsonConvert.SerializeObject(master.DataStoreService.getAvatarImWindow(avatarUUID)));
return BasicReply(JsonConvert.SerializeObject(master.DataStoreService.GetAvatarImWindow(avatarUUID)));
}
}

View file

@ -19,7 +19,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Discord client not ready");
}
return BasicReply(master.DiscordService.addRoleToMember(serverid, roleid, memberid).Result.ToString(), new [] { serverid, roleid, memberid });
return BasicReply(master.DiscordService.AddRoleToMember(serverid, roleid, memberid).Result.ToString(), new [] { serverid, roleid, memberid });
}
[About("Adds the selected user to the ban list - Disallows rejoining untill they are removed from the list")]

View file

@ -19,14 +19,14 @@ namespace SecondBotEvents.Commands
[ArgHints("mode", "true to start a restart, false to cancel")]
public object SimRestart(string delay, string mode)
{
if (getClient().Network.CurrentSim.IsEstateManager == false)
if (GetClient().Network.CurrentSim.IsEstateManager == false)
{
return Failure("Not an estate manager here", new [] { delay, mode });
}
bool.TryParse(mode, out bool modeflag);
if (modeflag == false)
{
getClient().Estate.CancelRestart();
GetClient().Estate.CancelRestart();
return BasicReply("canceled", new [] { delay, mode });
}
int delay_restart = 60;
@ -35,7 +35,7 @@ namespace SecondBotEvents.Commands
{
delay_restart = 240;
}
getClient().Estate.RestartRegion(delay_restart);
GetClient().Estate.RestartRegion(delay_restart);
return BasicReply("restarting", new [] { delay, mode });
}
@ -50,11 +50,11 @@ namespace SecondBotEvents.Commands
{
return Failure("Message empty", new [] { message });
}
if (getClient().Network.CurrentSim.IsEstateManager == false)
if (GetClient().Network.CurrentSim.IsEstateManager == false)
{
return Failure("Not an estate manager here", new [] { message });
}
getClient().Estate.SimulatorMessage(message);
GetClient().Estate.SimulatorMessage(message);
return BasicReply("ok", new [] { message });
}
@ -64,7 +64,7 @@ namespace SecondBotEvents.Commands
[ArgHints("regionname", "the name of the region we are fetching")]
public object GetSimTexture(string regionname)
{
if (getClient().Grid.GetGridRegion(regionname, GridLayerType.Objects, out GridRegion region) == false)
if (GetClient().Grid.GetGridRegion(regionname, GridLayerType.Objects, out GridRegion region) == false)
{
return Failure("Unable to find region", new [] { regionname });
}
@ -76,12 +76,12 @@ namespace SecondBotEvents.Commands
[ReturnHints("ok")]
public object EstateParcelReclaim()
{
if (getClient().Network.CurrentSim.IsEstateManager == false)
if (GetClient().Network.CurrentSim.IsEstateManager == false)
{
return Failure("Not an estate manager here");
}
int localid = getClient().Parcels.GetParcelLocalID(getClient().Network.CurrentSim, getClient().Self.SimPosition);
getClient().Parcels.Reclaim(getClient().Network.CurrentSim, localid);
int localid = GetClient().Parcels.GetParcelLocalID(GetClient().Network.CurrentSim, GetClient().Self.SimPosition);
GetClient().Parcels.Reclaim(GetClient().Network.CurrentSim, localid);
return BasicReply("ok");
}
@ -91,7 +91,7 @@ namespace SecondBotEvents.Commands
[ReturnHints("a json object with the x,y and region name")]
public object GetSimGlobalPos(string regionname)
{
if (getClient().Grid.GetGridRegion(regionname, GridLayerType.Objects, out GridRegion region) == false)
if (GetClient().Grid.GetGridRegion(regionname, GridLayerType.Objects, out GridRegion region) == false)
{
return Failure("Unable to find region", new [] { regionname });
}
@ -121,9 +121,9 @@ namespace SecondBotEvents.Commands
public object UpdateEstateBanlist(string avatar, string mode, string global)
{
if (getClient().Network.CurrentSim.IsEstateManager == false)
if (GetClient().Network.CurrentSim.IsEstateManager == false)
{
return Failure("Not an estate manager on region " + getClient().Network.CurrentSim.Name, new [] { avatar, mode, global });
return Failure("Not an estate manager on region " + GetClient().Network.CurrentSim.Name, new [] { avatar, mode, global });
}
UUID avataruuid = UUID.Zero;
if (UUID.TryParse(avatar, out avataruuid) == false)
@ -137,10 +137,10 @@ namespace SecondBotEvents.Commands
}
if (mode != "add")
{
getClient().Estate.UnbanUser(avataruuid, globalban);
GetClient().Estate.UnbanUser(avataruuid, globalban);
return BasicReply("Unban request accepted", new [] { avatar, mode, global });
}
getClient().Estate.BanUser(avataruuid, globalban);
GetClient().Estate.BanUser(avataruuid, globalban);
return BasicReply("Ban request accepted", new [] { avatar, mode, global });
}
}

View file

@ -15,7 +15,7 @@ namespace SecondBotEvents.Commands
[ReturnHints("array UUID = friendreplyobject")]
public object Friendslist()
{
return BasicReply(JsonConvert.SerializeObject(getClient().Friends.FriendList));
return BasicReply(JsonConvert.SerializeObject(GetClient().Friends.FriendList));
}
[About("Updates the friend perms for avatar avatar to State \n if true grants (Online/Map/Modify) perms")]
@ -38,16 +38,16 @@ namespace SecondBotEvents.Commands
{
return Failure("state invaild", new [] { avatar, state });
}
if (getClient().Friends.FriendList.ContainsKey(avataruuid) == false)
if (GetClient().Friends.FriendList.ContainsKey(avataruuid) == false)
{
return Failure("Not A friend", new [] { avatar, state });
}
if (status == true)
{
getClient().Friends.GrantRights(avataruuid, FriendRights.CanSeeOnline | FriendRights.CanSeeOnMap | FriendRights.CanModifyObjects);
GetClient().Friends.GrantRights(avataruuid, FriendRights.CanSeeOnline | FriendRights.CanSeeOnMap | FriendRights.CanModifyObjects);
return BasicReply("granted", new [] { avatar, state });
}
getClient().Friends.GrantRights(avataruuid, FriendRights.None);
GetClient().Friends.GrantRights(avataruuid, FriendRights.None);
return BasicReply("removed", new [] { avatar, state });
}
@ -72,11 +72,11 @@ namespace SecondBotEvents.Commands
{
return Failure("state invaild", new [] { avatar, state });
}
if (getClient().Friends.FriendList.ContainsKey(avataruuid) == true)
if (GetClient().Friends.FriendList.ContainsKey(avataruuid) == true)
{
if (status == false)
{
getClient().Friends.TerminateFriendship(avataruuid);
GetClient().Friends.TerminateFriendship(avataruuid);
return BasicReply("Removed", new [] { avatar, state });
}
}
@ -84,7 +84,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Not in friendslist", new [] { avatar, state });
}
getClient().Friends.OfferFriendship(avataruuid);
GetClient().Friends.OfferFriendship(avataruuid);
return BasicReply("Request sent", new [] { avatar, state });
}

View file

@ -18,8 +18,8 @@ namespace SecondBotEvents.Commands
{
return Failure("Funds commands are disabled");
}
getClient().Self.RequestBalance();
return BasicReply(getClient().Self.Balance.ToString());
GetClient().Self.RequestBalance();
return BasicReply(GetClient().Self.Balance.ToString());
}
[About("Makes the bot pay a avatar")]
@ -45,11 +45,11 @@ namespace SecondBotEvents.Commands
{
return Failure("Invaild amount", new [] { avatar, amount });
}
if ((amountvalue < 0) || (amountvalue > getClient().Self.Balance))
if ((amountvalue < 0) || (amountvalue > GetClient().Self.Balance))
{
return Failure("Amount out of range", new [] { avatar, amount });
}
getClient().Self.GiveAvatarMoney(avataruuid, amountvalue);
GetClient().Self.GiveAvatarMoney(avataruuid, amountvalue);
return BasicReply("Accepted", new [] { avatar, amount });
}
@ -77,7 +77,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Invaild amount", new [] { objectuuid, primname, amount });
}
if((amountvalue < 0) || (amountvalue > getClient().Self.Balance))
if((amountvalue < 0) || (amountvalue > GetClient().Self.Balance))
{
return Failure("Amount out of range", new [] { objectuuid, primname, amount });
}
@ -85,7 +85,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Primname is empty", new [] { objectuuid, primname, amount });
}
getClient().Self.GiveObjectMoney(objectUUID, amountvalue, primname);
GetClient().Self.GiveObjectMoney(objectUUID, amountvalue, primname);
return BasicReply("ok", new [] { objectuuid, primname, amount });
}
}

View file

@ -61,7 +61,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Invaild group UUID", new[] { group, avatar, state });
}
if (getClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false)
if (GetClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false)
{
return Failure("Unknown group", new[] { group, avatar, state });
}
@ -77,7 +77,7 @@ namespace SecondBotEvents.Commands
}
List<UUID> avatarstoaction = new List<UUID>();
avatarstoaction.Add(avataruuid);
getClient().Groups.RequestBanAction(groupuuid, Action, avatarstoaction.ToArray());
GetClient().Groups.RequestBanAction(groupuuid, Action, avatarstoaction.ToArray());
return BasicReply("Accepted");
}
@ -99,7 +99,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Invaild group UUID", new [] { group, avatar });
}
if (getClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false)
if (GetClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false)
{
return Failure("Unknown group", new[] { group, avatar });
}
@ -108,7 +108,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Unknown avatar", new[] { group, avatar});
}
getClient().Groups.EjectUser(groupuuid, avataruuid);
GetClient().Groups.EjectUser(groupuuid, avataruuid);
return BasicReply("Accepted");
}
@ -132,17 +132,17 @@ namespace SecondBotEvents.Commands
{
return Failure("Invaild role UUID", new [] { group, avatar });
}
if (getClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false)
if (GetClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false)
{
return Failure("Unknown group", new[] { group, avatar, role });
}
ProcessAvatar(avatar);
if(master.DataStoreService.IsGroupMember(groupuuid, avataruuid) == false)
{
getClient().Groups.Invite(groupuuid, new List<UUID>() { UUID.Zero, roleuuid }, avataruuid);
GetClient().Groups.Invite(groupuuid, new List<UUID>() { UUID.Zero, roleuuid }, avataruuid);
return BasicReply("Invite sent");
}
getClient().Groups.AddToRole(groupuuid, roleuuid, avataruuid);
GetClient().Groups.AddToRole(groupuuid, roleuuid, avataruuid);
return BasicReply("Adding role");
}
@ -163,7 +163,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Invaild group UUID", new [] { group, avatar, role });
}
if (getClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false)
if (GetClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false)
{
return Failure("Unknown group", new[] { group, avatar, role });
}
@ -183,7 +183,7 @@ namespace SecondBotEvents.Commands
}
roles.Add(roleuuid);
}
getClient().Groups.Invite(groupuuid, roles, avataruuid);
GetClient().Groups.Invite(groupuuid, roles, avataruuid);
return BasicReply("Invite sent", new [] { group, avatar, role });
}
@ -203,7 +203,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Invaild group UUID", new [] { group, title, message });
}
if (getClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false)
if (GetClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false)
{
return Failure("Unknown group", new [] { group, title, message });
}
@ -218,8 +218,8 @@ namespace SecondBotEvents.Commands
GroupNotice NewNotice = new GroupNotice();
NewNotice.Subject = title;
NewNotice.Message = message;
NewNotice.OwnerID = getClient().Self.AgentID;
getClient().Groups.SendGroupNotice(groupuuid, NewNotice);
NewNotice.OwnerID = GetClient().Self.AgentID;
GetClient().Groups.SendGroupNotice(groupuuid, NewNotice);
return BasicReply("Sending notice", new [] { group, title, message });
}
@ -240,11 +240,11 @@ namespace SecondBotEvents.Commands
{
return Failure("Invaild role UUID", new [] { group, role });
}
if (getClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false)
if (GetClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false)
{
return Failure("Unknown group", new [] { group, role });
}
getClient().Groups.ActivateTitle(groupuuid, roleuuid);
GetClient().Groups.ActivateTitle(groupuuid, roleuuid);
return BasicReply("Switching title", new [] { group, role });
}
@ -259,11 +259,11 @@ namespace SecondBotEvents.Commands
{
return Failure("Invaild group UUID", new [] { group });
}
if (getClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false)
if (GetClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false)
{
return Failure("Unknown group", new[] { group });
}
getClient().Groups.ActivateGroup(groupuuid);
GetClient().Groups.ActivateGroup(groupuuid);
return BasicReply("Switching active group", new [] { group });
}
@ -289,7 +289,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Invaild inventory UUID", new [] { group, title, message, attachment });
}
if (getClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false)
if (GetClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false)
{
return Failure("Unknown group", new [] { group, title, message, attachment });
}
@ -304,9 +304,9 @@ namespace SecondBotEvents.Commands
GroupNotice NewNotice = new GroupNotice();
NewNotice.Subject = title;
NewNotice.Message = message;
NewNotice.OwnerID = getClient().Self.AgentID;
NewNotice.OwnerID = GetClient().Self.AgentID;
NewNotice.AttachmentID = inventoryuuid;
getClient().Groups.SendGroupNotice(groupuuid, NewNotice);
GetClient().Groups.SendGroupNotice(groupuuid, NewNotice);
return BasicReply("Sending notice with attachment", new [] { group, title, message, attachment });
}
@ -330,7 +330,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Invaild group UUID", new [] { group });
}
if (getClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false)
if (GetClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false)
{
return Failure("Unknown group", new [] { group });
}
@ -356,7 +356,7 @@ namespace SecondBotEvents.Commands
{
return Failure("group value is invaild", new [] { group });
}
if(getClient().Groups.GroupName2KeyCache.ContainsKey(groupUUID) == false)
if(GetClient().Groups.GroupName2KeyCache.ContainsKey(groupUUID) == false)
{
return Failure("Unknown group", new [] { group });
}
@ -375,7 +375,7 @@ namespace SecondBotEvents.Commands
[ReturnHints("ok")]
public object GroupchatClearAll()
{
master.DataStoreService.clearGroupChat();
master.DataStoreService.ClearGroupChat();
return BasicReply("ok");
}
@ -405,15 +405,15 @@ namespace SecondBotEvents.Commands
{
return Failure("group value is invaild", new [] { group, message });
}
if (getClient().Groups.GroupName2KeyCache.ContainsKey(groupUUID) == false)
if (GetClient().Groups.GroupName2KeyCache.ContainsKey(groupUUID) == false)
{
return Failure("Unknown group", new [] { group, message });
}
if (getClient().Groups.GroupName2KeyCache.ContainsKey(groupUUID) == false)
if (GetClient().Groups.GroupName2KeyCache.ContainsKey(groupUUID) == false)
{
return Failure("Unknown group", new[] { group });
}
getClient().Self.InstantMessageGroup(groupUUID, message);
GetClient().Self.InstantMessageGroup(groupUUID, message);
return BasicReply("Sending");
}
}

View file

@ -16,7 +16,7 @@ namespace SecondBotEvents.Commands
[ReturnHints("A json object")]
public object ListSculptys()
{
Dictionary<uint, Primitive> objects_copy = getClient().Network.CurrentSim.ObjectsPrimitives.Copy();
Dictionary<uint, Primitive> objects_copy = GetClient().Network.CurrentSim.ObjectsPrimitives.Copy();
Dictionary<uint, uint> mapLocalID = new Dictionary<uint, uint>();
Dictionary<uint, Primitive> sculpts = new Dictionary<uint, Primitive>();
@ -82,7 +82,7 @@ namespace SecondBotEvents.Commands
[ReturnHints("Firstname Lastname")]
public object Name()
{
return BasicReply(getClient().Self.FirstName + " " + getClient().Self.LastName);
return BasicReply(GetClient().Self.FirstName + " " + GetClient().Self.LastName);
}
[About("Fetchs the current parcels name")]
@ -91,16 +91,16 @@ namespace SecondBotEvents.Commands
[ReturnHintsFailure("Error not in a sim")]
public object ParcelName()
{
if (getClient().Network.CurrentSim == null)
if (GetClient().Network.CurrentSim == null)
{
return Failure("Error not in a sim");
}
int localid = getClient().Parcels.GetParcelLocalID(getClient().Network.CurrentSim, getClient().Self.SimPosition);
if (getClient().Network.CurrentSim.Parcels.ContainsKey(localid) == false)
int localid = GetClient().Parcels.GetParcelLocalID(GetClient().Network.CurrentSim, GetClient().Self.SimPosition);
if (GetClient().Network.CurrentSim.Parcels.ContainsKey(localid) == false)
{
return Failure("Error parcel not found");
}
return BasicReply(getClient().Network.CurrentSim.Parcels[localid].Name);
return BasicReply(GetClient().Network.CurrentSim.Parcels[localid].Name);
}
[About("Requests the current unixtime at the bot")]
@ -115,11 +115,11 @@ namespace SecondBotEvents.Commands
[ReturnHintsFailure("Error not in a sim")]
public object SimName()
{
if (getClient().Network.CurrentSim == null)
if (GetClient().Network.CurrentSim == null)
{
return Failure("Error not in a sim");
}
return BasicReply(getClient().Network.CurrentSim.Name);
return BasicReply(GetClient().Network.CurrentSim.Name);
}
[About("Fetchs the current location of the bot")]
@ -127,14 +127,14 @@ namespace SecondBotEvents.Commands
[ReturnHintsFailure("Error not in a sim")]
public object GetPosition()
{
if (getClient().Network.CurrentSim == null)
if (GetClient().Network.CurrentSim == null)
{
return Failure("Error not in a sim");
}
Dictionary<string, int> pos = new Dictionary<string, int>();
pos.Add("x", (int)Math.Round(getClient().Self.SimPosition.X));
pos.Add("y", (int)Math.Round(getClient().Self.SimPosition.Y));
pos.Add("z", (int)Math.Round(getClient().Self.SimPosition.Z));
pos.Add("x", (int)Math.Round(GetClient().Self.SimPosition.X));
pos.Add("y", (int)Math.Round(GetClient().Self.SimPosition.Y));
pos.Add("z", (int)Math.Round(GetClient().Self.SimPosition.Z));
return BasicReply(JsonConvert.SerializeObject(pos));
}
}

View file

@ -33,8 +33,8 @@ namespace SecondBotEvents.Commands
public object UploadMediaWave(string sourcePath, string inventoryName)
{
byte[] audioData = File.ReadAllBytes(sourcePath);
InventoryFolder AA = getClient().Inventory.Store.RootFolder;
List<InventoryBase> T = getClient().Inventory.Store.GetContents(AA);
InventoryFolder AA = GetClient().Inventory.Store.RootFolder;
List<InventoryBase> T = GetClient().Inventory.Store.GetContents(AA);
AA = null;
foreach (InventoryBase R in T)
{
@ -48,7 +48,7 @@ namespace SecondBotEvents.Commands
S.AssetData = audioData;
S.Encode();
getClient().Inventory.RequestCreateItemFromAsset(S.AssetData, inventoryName, "", AssetType.Sound, InventoryType.Sound, AA.UUID, null);
GetClient().Inventory.RequestCreateItemFromAsset(S.AssetData, inventoryName, "", AssetType.Sound, InventoryType.Sound, AA.UUID, null);
return BasicReply("ok");
}
@ -64,12 +64,12 @@ namespace SecondBotEvents.Commands
{
return Failure("Invaild item UUID: "+ item, new [] { item });
}
InventoryItem itm = getClient().Inventory.FetchItem(targetitem, getClient().Self.AgentID, (5 * 1000));
InventoryItem itm = GetClient().Inventory.FetchItem(targetitem, GetClient().Self.AgentID, (5 * 1000));
if (itm == null)
{
return Failure("Unable to find item: " + item, new [] { item });
}
UUID rezedobject = getClient().Inventory.RequestRezFromInventory(getClient().Network.CurrentSim, getClient().Self.SimRotation, getClient().Self.RelativePosition, itm);
UUID rezedobject = GetClient().Inventory.RequestRezFromInventory(GetClient().Network.CurrentSim, GetClient().Self.SimRotation, GetClient().Self.RelativePosition, itm);
return BasicReply(rezedobject.ToString(), new [] { item });
}
@ -91,13 +91,13 @@ namespace SecondBotEvents.Commands
{
return Failure("Item name is to short", new [] { item, newname });
}
InventoryItem realitem = HelperInventory.getItemByInventoryUUID(getClient(), target);
InventoryItem realitem = HelperInventory.getItemByInventoryUUID(GetClient(), target);
if (realitem == null)
{
return Failure("Unable to find inventory item", new [] { item, newname });
}
realitem.Name = newname;
getClient().Inventory.RequestUpdateItem(realitem);
GetClient().Inventory.RequestUpdateItem(realitem);
return BasicReply("Ok", new [] { item, newname });
}
@ -111,7 +111,7 @@ namespace SecondBotEvents.Commands
{
return Failure("invaild item uuid", new [] { item });
}
getClient().Inventory.Remove(new List<UUID>() { target }, new List<UUID>());
GetClient().Inventory.Remove(new List<UUID>() { target }, new List<UUID>());
return BasicReply("Ok", new [] { item });
}
@ -125,7 +125,7 @@ namespace SecondBotEvents.Commands
{
return Failure("invaild folder uuid", new [] { folder });
}
getClient().Inventory.Remove(new List<UUID>(), new List<UUID>() { target });
GetClient().Inventory.Remove(new List<UUID>(), new List<UUID>() { target });
return BasicReply("Ok", new [] { folder });
}
@ -139,8 +139,8 @@ namespace SecondBotEvents.Commands
{
return Failure("invaild item uuid", new [] { item });
}
InventoryItem realitem = HelperInventory.getItemByInventoryUUID(getClient(), itemuuid);
getClient().Appearance.AddAttachments(new List<InventoryItem>() { realitem }, false, false);
InventoryItem realitem = HelperInventory.getItemByInventoryUUID(GetClient(), itemuuid);
GetClient().Appearance.AddAttachments(new List<InventoryItem>() { realitem }, false, false);
return BasicReply("Ok", new [] { item });
}
@ -154,8 +154,8 @@ namespace SecondBotEvents.Commands
{
return Failure("invaild item uuid", new [] { item });
}
InventoryItem realitem = HelperInventory.getItemByInventoryUUID(getClient(), itemuuid);
getClient().Appearance.RemoveFromOutfit(realitem);
InventoryItem realitem = HelperInventory.getItemByInventoryUUID(GetClient(), itemuuid);
GetClient().Appearance.RemoveFromOutfit(realitem);
return BasicReply("Ok", new [] { item });
}
@ -174,8 +174,8 @@ namespace SecondBotEvents.Commands
}
// uses the Clothing folder
// must be a full outfit (shapes/eyes ect)
InventoryFolder AA = getClient().Inventory.Store.RootFolder;
List<InventoryBase> T = getClient().Inventory.Store.GetContents(AA);
InventoryFolder AA = GetClient().Inventory.Store.RootFolder;
List<InventoryBase> T = GetClient().Inventory.Store.GetContents(AA);
AA = null;
foreach (InventoryBase R in T)
{
@ -189,7 +189,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Cant find Clothing folder", new [] { name });
}
T = getClient().Inventory.Store.GetContents(AA);
T = GetClient().Inventory.Store.GetContents(AA);
AA = null;
foreach (InventoryBase R in T)
{
@ -203,7 +203,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Cant find target folder", new [] { name });
}
List<InventoryBase> contents = getClient().Inventory.FolderContents(AA.UUID, getClient().Self.AgentID, true, true, InventorySortOrder.ByName, 5 * 1000);
List<InventoryBase> contents = GetClient().Inventory.FolderContents(AA.UUID, GetClient().Self.AgentID, true, true, InventorySortOrder.ByName, 5 * 1000);
List<InventoryItem> wareables = new List<InventoryItem>();
if (contents == null)
{
@ -216,7 +216,7 @@ namespace SecondBotEvents.Commands
wareables.Add((InventoryItem)item);
}
}
getClient().Appearance.ReplaceOutfit(wareables, false);
GetClient().Appearance.ReplaceOutfit(wareables, false);
return BasicReply("ok", new [] { name });
}
@ -227,7 +227,7 @@ namespace SecondBotEvents.Commands
[ReturnHints("Unable to find notecard folder")]
public object InventoryPurgeNotecards()
{
List<InventoryBase> T = getClient().Inventory.Store.GetContents(getClient().Inventory.Store.RootFolder);
List<InventoryBase> T = GetClient().Inventory.Store.GetContents(GetClient().Inventory.Store.RootFolder);
InventoryBase NotecardFolder = null;
foreach (InventoryBase R in T)
{
@ -242,7 +242,7 @@ namespace SecondBotEvents.Commands
return Failure("Unable to find notecard folder");
}
List<UUID> purge_notecards = new List<UUID>();
List<InventoryBase> contents = getClient().Inventory.FolderContents(NotecardFolder.UUID, getClient().Self.AgentID, true, true, InventorySortOrder.ByDate, 40 * 1000);
List<InventoryBase> contents = GetClient().Inventory.FolderContents(NotecardFolder.UUID, GetClient().Self.AgentID, true, true, InventorySortOrder.ByDate, 40 * 1000);
foreach (InventoryBase C in contents)
{
InventoryItem A = (InventoryItem)C;
@ -257,7 +257,7 @@ namespace SecondBotEvents.Commands
}
if (purge_notecards.Count() > 0)
{
getClient().Inventory.Remove(purge_notecards, new List<UUID>());
GetClient().Inventory.Remove(purge_notecards, new List<UUID>());
}
return BasicReply("Ok");
}
@ -272,7 +272,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Invaild item uuid", new [] { item });
}
UUID reply = HelperInventory.GetAssetUUID(getClient(), itemUUID);
UUID reply = HelperInventory.GetAssetUUID(GetClient(), itemUUID);
return BasicReply(reply.ToString(), new [] { item });
}
@ -295,12 +295,12 @@ namespace SecondBotEvents.Commands
{
return Failure("Invaild item uuid", new [] { item, avatar });
}
InventoryItem itm = getClient().Inventory.FetchItem(targetitem, getClient().Self.AgentID, (3 * 1000));
InventoryItem itm = GetClient().Inventory.FetchItem(targetitem, GetClient().Self.AgentID, (3 * 1000));
if (itm == null)
{
return Failure("Unable to find item", new [] { item, avatar });
}
getClient().Inventory.GiveItem(itm.UUID, itm.Name, itm.AssetType, avataruuid, false);
GetClient().Inventory.GiveItem(itm.UUID, itm.Name, itm.AssetType, avataruuid, false);
return BasicReply("ok", new [] { item, avatar });
}
@ -323,12 +323,12 @@ namespace SecondBotEvents.Commands
{
return Failure("Invaild folder uuid", new [] { folder, avatar });
}
InventoryBase FindFolderHelper = HelperInventory.FindFolder(getClient(), getClient().Inventory.Store.RootFolder, targetfolder);
InventoryBase FindFolderHelper = HelperInventory.FindFolder(GetClient(), GetClient().Inventory.Store.RootFolder, targetfolder);
if (FindFolderHelper == null)
{
return Failure("Unable to find folder", new [] { folder, avatar });
}
getClient().Inventory.GiveFolder(FindFolderHelper.UUID, FindFolderHelper.Name, avataruuid, false);
GetClient().Inventory.GiveFolder(FindFolderHelper.UUID, FindFolderHelper.Name, avataruuid, false);
return BasicReply("ok", new [] { folder, avatar });
}
@ -358,12 +358,12 @@ namespace SecondBotEvents.Commands
return Failure("Invaild running", new [] { item, objectuuid, running });
}
InventoryItem itm = getClient().Inventory.FetchItem(itemuuid, getClient().Self.AgentID, (3 * 1000));
InventoryItem itm = GetClient().Inventory.FetchItem(itemuuid, GetClient().Self.AgentID, (3 * 1000));
if (itm == null)
{
return Failure("Unable to find inventory", new [] { item, objectuuid, running });
}
Dictionary<uint, Primitive> objects_copy = getClient().Network.CurrentSim.ObjectsPrimitives.Copy();
Dictionary<uint, Primitive> objects_copy = GetClient().Network.CurrentSim.ObjectsPrimitives.Copy();
KeyValuePair<uint, Primitive> RealObject = new KeyValuePair<uint, Primitive>(0,null);
foreach (KeyValuePair<uint, Primitive> Obj in objects_copy)
{
@ -384,10 +384,10 @@ namespace SecondBotEvents.Commands
}
if (itm.AssetType == AssetType.LSLText)
{
getClient().Inventory.CopyScriptToTask(RealObject.Key, itm, scriptState);
GetClient().Inventory.CopyScriptToTask(RealObject.Key, itm, scriptState);
return BasicReply("Transfering script [state: "+scriptState.ToString()+"]", new [] { item, objectuuid, running });
}
getClient().Inventory.UpdateTaskInventory(RealObject.Key, itm);
GetClient().Inventory.UpdateTaskInventory(RealObject.Key, itm);
return BasicReply("Transfering inventory", new [] { item, objectuuid, running });
}
@ -396,7 +396,7 @@ namespace SecondBotEvents.Commands
[ReturnHints("Error")]
public object InventoryFolders()
{
string reply = HelperInventory.MapFolderJson(getClient());
string reply = HelperInventory.MapFolderJson(GetClient());
if (reply != null) return BasicReply(reply);
return Failure("Error");
}
@ -407,7 +407,7 @@ namespace SecondBotEvents.Commands
[ReturnHints("Error")]
public object InventoryFoldersLimited(string targetfolder)
{
string reply = HelperInventory.MapFolderJson(getClient(), targetfolder,false);
string reply = HelperInventory.MapFolderJson(GetClient(), targetfolder,false);
if (reply != null) return BasicReply(reply);
return Failure("Error");
}
@ -422,7 +422,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Invaild folder UUID", new [] { folderUUID });
}
return BasicReply(HelperInventory.MapFolderInventoryJson(getClient(), folder), new [] { folderUUID });
return BasicReply(HelperInventory.MapFolderInventoryJson(GetClient(), folder), new [] { folderUUID });
}
[About("creates a folder in a folder")]
@ -441,7 +441,7 @@ namespace SecondBotEvents.Commands
{
return Failure("new folder name is too short, must be longer than 3 characters.", new[] { folderName });
}
UUID folder = getClient().Inventory.CreateFolder(parentFolderUUID, folderName);
UUID folder = GetClient().Inventory.CreateFolder(parentFolderUUID, folderName);
string uuid = folder.ToString();
return BasicReply("Ok", new string[] { uuid });
}
@ -463,7 +463,7 @@ namespace SecondBotEvents.Commands
{
return Failure("invaild folder uuid", new[] { item, folder });
}
getClient().Inventory.MoveItem(itemUUID, folderUUID);
GetClient().Inventory.MoveItem(itemUUID, folderUUID);
return BasicReply("Ok", new string[] { item });
}
@ -483,7 +483,7 @@ namespace SecondBotEvents.Commands
{
return Failure("invaild dest folder uuid", new[] { sourceFolder, destFolder });
}
getClient().Inventory.MoveFolder(sourceFolderUUID, destFolderUUID);
GetClient().Inventory.MoveFolder(sourceFolderUUID, destFolderUUID);
return BasicReply("Ok", new string[] { sourceFolder, destFolder });
}
}

View file

@ -39,12 +39,12 @@ namespace SecondBotEvents.Commands
{
return Failure("z value out of range 0-5000", new [] { x, y, z });
}
getClient().Self.AutoPilotCancel();
getClient().Self.Movement.TurnToward(pos, true);
GetClient().Self.AutoPilotCancel();
GetClient().Self.Movement.TurnToward(pos, true);
Thread.Sleep(500);
uint Globalx, Globaly;
Utils.LongToUInts(getClient().Network.CurrentSim.Handle, out Globalx, out Globaly);
getClient().Self.AutoPilot((ulong)(Globalx + pos.X), (ulong)(Globaly + pos.Y), pos.Z);
Utils.LongToUInts(GetClient().Network.CurrentSim.Handle, out Globalx, out Globaly);
GetClient().Self.AutoPilot((ulong)(Globalx + pos.X), (ulong)(Globaly + pos.Y), pos.Z);
return BasicReply("ok", new [] { x, y, z });
}
@ -52,7 +52,7 @@ namespace SecondBotEvents.Commands
[ReturnHints("ok")]
public object AutoPilotStop()
{
getClient().Self.AutoPilotCancel();
GetClient().Self.AutoPilotCancel();
return BasicReply("ok");
}
@ -67,7 +67,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Invaild avatar UUID", new [] { avatar });
}
getClient().Self.SendTeleportLure(avataruuid);
GetClient().Self.SendTeleportLure(avataruuid);
return BasicReply("ok", new [] { avatar });
}
@ -83,7 +83,7 @@ namespace SecondBotEvents.Commands
return Failure("Invaild avatar UUID", new [] { avatar });
}
// @todo action from event log with accept
getClient().Self.SendTeleportLureRequest(avataruuid, "I would like to teleport to you");
GetClient().Self.SendTeleportLureRequest(avataruuid, "I would like to teleport to you");
return BasicReply("ok", new [] { avatar });
}
@ -97,8 +97,8 @@ namespace SecondBotEvents.Commands
{
return Failure("Invaild mode", new [] { mode });
}
getClient().Self.Movement.Fly = flymode;
getClient().Self.Movement.SendUpdate();
GetClient().Self.Movement.Fly = flymode;
GetClient().Self.Movement.SendUpdate();
return BasicReply("ok", new [] { mode });
}
@ -125,7 +125,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Vector z value is out of range 0-5000", new [] { vector });
}
return BasicReply(getClient().Self.Movement.TurnToward(pos, true).ToString(), new [] { vector });
return BasicReply(GetClient().Self.Movement.TurnToward(pos, true).ToString(), new [] { vector });
}
[About("Rotates the bot to face a avatar")]
@ -140,11 +140,11 @@ namespace SecondBotEvents.Commands
{
return Failure("Invaild avatar UUID", new [] { avatar });
}
if (getClient().Network.CurrentSim.AvatarPositions.ContainsKey(avataruuid) == false)
if (GetClient().Network.CurrentSim.AvatarPositions.ContainsKey(avataruuid) == false)
{
return Failure("Unable to see avatar", new [] { avatar });
}
return BasicReply(getClient().Self.Movement.TurnToward(getClient().Network.CurrentSim.AvatarPositions[avataruuid], true).ToString(), new [] { avatar });
return BasicReply(GetClient().Self.Movement.TurnToward(GetClient().Network.CurrentSim.AvatarPositions[avataruuid], true).ToString(), new [] { avatar });
}
[About("Rotates the avatar to face a rotation from north in Degrees")]
@ -158,7 +158,7 @@ namespace SecondBotEvents.Commands
return Failure("Unable to process rotation", new [] { deg });
}
float yaw = target_yaw;
getClient().Self.Movement.BodyRotation.GetEulerAngles(out float roll, out float pitch, out _);
GetClient().Self.Movement.BodyRotation.GetEulerAngles(out float roll, out float pitch, out _);
roll *= 57.2958f;
pitch *= 57.2958f;
yaw *= 57.2958f;
@ -176,8 +176,8 @@ namespace SecondBotEvents.Commands
result.X = cosYawOver2 * sinPitchOver2 * cosRollOver2 + sinYawOver2 * cosPitchOver2 * sinRollOver2;
result.Y = sinYawOver2 * cosPitchOver2 * cosRollOver2 - cosYawOver2 * sinPitchOver2 * sinRollOver2;
result.Z = cosYawOver2 * cosPitchOver2 * sinRollOver2 - sinYawOver2 * sinPitchOver2 * cosRollOver2;
getClient().Self.Movement.BodyRotation = result;
getClient().Self.Movement.SendUpdate();
GetClient().Self.Movement.BodyRotation = result;
GetClient().Self.Movement.SendUpdate();
return BasicReply("ok", new [] { deg });
}
@ -197,7 +197,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Error Unable to Teleport to location", new [] { region, x, y, z });
}
master.HomeboundService.markTeleport();
master.HomeboundService.MarkTeleport();
return BasicReply("Accepted", new [] { region, x, y, z });
}
@ -217,7 +217,7 @@ namespace SecondBotEvents.Commands
protected bool TeleportRequest(string[] args)
{
getClient().Self.AutoPilotCancel();
GetClient().Self.AutoPilotCancel();
if (args[0].Contains("http://maps.secondlife.com/secondlife/") == true)
{
return false; // @todo SL url teleport
@ -227,7 +227,7 @@ namespace SecondBotEvents.Commands
List<string> argvalues = new List<string>(args);
if(argvalues.Count == 3)
{
string regionName = getClient().Network.CurrentSim.Name;
string regionName = GetClient().Network.CurrentSim.Name;
argvalues = new List<string>() { regionName };
argvalues.AddRange(args);
}
@ -237,7 +237,7 @@ namespace SecondBotEvents.Commands
float.TryParse(argvalues[1], out float posX);
float.TryParse(argvalues[2], out float posY);
float.TryParse(argvalues[3], out float posZ);
bool status = getClient().Self.Teleport(regionName, new Vector3(posX, posY, posZ));
bool status = GetClient().Self.Teleport(regionName, new Vector3(posX, posY, posZ));
return true;
}
else

View file

@ -73,7 +73,7 @@ namespace SecondBotEvents.Commands
{
return Failure("No content in notecard storage ?", new[] { avatar, collection, notecardname });
}
bool result = master.botClient.SendNotecard(notecardname, content, avataruuid);
bool result = master.BotClient.SendNotecard(notecardname, content, avataruuid);
if (result == false)
{
return Failure("Failed to create/send notecard", new[] { avatar, content, notecardname });
@ -105,7 +105,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Invaild avatar uuid", new[] { avatar, content, notecardname });
}
bool result = master.botClient.SendNotecard(notecardname, content, avataruuid);
bool result = master.BotClient.SendNotecard(notecardname, content, avataruuid);
if(result == false)
{
return Failure("Failed to create/send notecard", new[] { avatar, content, notecardname });

View file

@ -51,7 +51,7 @@ namespace SecondBotEvents.Commands
targetparcel.AuthBuyerID = avataruuid;
parcel_static.ParcelSetFlag(ParcelFlags.ForSale, targetparcel, true);
parcel_static.ParcelSetFlag(ParcelFlags.ForSaleObjects, targetparcel, false);
targetparcel.Update(getClient().Network.CurrentSim, false);
targetparcel.Update(GetClient().Network.CurrentSim, false);
return Failure("ok", new [] { amount, avatar });
}
@ -98,7 +98,7 @@ namespace SecondBotEvents.Commands
}
targetparcel.Landing = LandingType.LandingPoint;
targetparcel.UserLocation = new Vector3(X, Y, Z);
targetparcel.Update(getClient().Network.CurrentSim, false);
targetparcel.Update(GetClient().Network.CurrentSim, false);
return BasicReply("ok", new [] { x, y, z });
}
@ -121,7 +121,7 @@ namespace SecondBotEvents.Commands
return Failure("Parcel name is empty", new [] { name });
}
targetparcel.Name = name;
targetparcel.Update(getClient().Network.CurrentSim, false);
targetparcel.Update(GetClient().Network.CurrentSim, false);
return BasicReply("ok", new [] { name });
}
@ -138,7 +138,7 @@ namespace SecondBotEvents.Commands
return Failure(tests.Value, new [] { desc });
}
targetparcel.Desc = desc;
targetparcel.Update(getClient().Network.CurrentSim, false);
targetparcel.Update(GetClient().Network.CurrentSim, false);
return BasicReply("ok", new [] { desc });
}
@ -187,7 +187,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Invaild avatar", new [] { avatar });
}
getClient().Parcels.EjectUser(avataruuid, false);
GetClient().Parcels.EjectUser(avataruuid, false);
return BasicReply("ok", new [] { avatar });
}
@ -200,7 +200,7 @@ namespace SecondBotEvents.Commands
{
return Failure(tests.Value);
}
getClient().Parcels.ReleaseParcel(getClient().Network.CurrentSim, targetparcel.LocalID);
GetClient().Parcels.ReleaseParcel(GetClient().Network.CurrentSim, targetparcel.LocalID);
return BasicReply("ok");
}
@ -242,7 +242,7 @@ namespace SecondBotEvents.Commands
entry.Flags = AccessList.Ban;
entry.Time = new System.DateTime(3030, 03, 03);
targetparcel.AccessBlackList.Add(entry);
targetparcel.Update(getClient().Network.CurrentSim, false);
targetparcel.Update(GetClient().Network.CurrentSim, false);
return BasicReply("ok", new [] { avatar });
}
@ -281,7 +281,7 @@ namespace SecondBotEvents.Commands
return BasicReply("Avatar is already unbanned", new [] { avatar });
}
targetparcel.AccessBlackList.Remove(removeentry);
targetparcel.Update(getClient().Network.CurrentSim, false);
targetparcel.Update(GetClient().Network.CurrentSim, false);
return BasicReply("ok", new [] { avatar });
}
@ -298,7 +298,7 @@ namespace SecondBotEvents.Commands
{
return Failure(tests.Value, new [] { musicurl });
}
bool status = parcel_static.set_parcel_music(getClient(), targetparcel, musicurl);
bool status = parcel_static.set_parcel_music(GetClient(), targetparcel, musicurl);
return BasicReply(status.ToString(), new [] { musicurl });
}
@ -348,7 +348,7 @@ namespace SecondBotEvents.Commands
{
return Failure("No accepted flags", new [] { escapedflagdata });
}
if (parcel_static.has_parcel_perm(targetparcel, getClient()) == false)
if (parcel_static.has_parcel_perm(targetparcel, GetClient()) == false)
{
return Failure("Incorrect perms to control parcel", new [] { escapedflagdata });
}
@ -359,7 +359,7 @@ namespace SecondBotEvents.Commands
parcel_static.ParcelSetFlag(flags[cfg.Key], targetparcel, cfg.Value);
}
}
targetparcel.Update(getClient().Network.CurrentSim, false);
targetparcel.Update(GetClient().Network.CurrentSim, false);
return BasicReply("Applying perms", new [] { escapedflagdata });
}
@ -381,7 +381,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Invaild avatar UUID", new [] { avatar });
}
getClient().Parcels.ReturnObjects(getClient().Network.CurrentSim, targetparcel.LocalID, ObjectReturnType.None, new List<UUID>() { avataruuid });
GetClient().Parcels.ReturnObjects(GetClient().Network.CurrentSim, targetparcel.LocalID, ObjectReturnType.None, new List<UUID>() { avataruuid });
return BasicReply("ok", new [] { avatar });
}
@ -404,14 +404,14 @@ namespace SecondBotEvents.Commands
{
return Failure("Invaild group uuid", new [] { group });
}
if (getClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false)
if (GetClient().Groups.GroupName2KeyCache.ContainsKey(groupuuid) == false)
{
return Failure("Not in group", new [] { group });
}
targetparcel.GroupID = groupuuid;
targetparcel.Update(getClient().Network.CurrentSim, false);
targetparcel.Update(GetClient().Network.CurrentSim, false);
Thread.Sleep(500);
getClient().Parcels.DeedToGroup(getClient().Network.CurrentSim, targetparcel.LocalID, groupuuid);
GetClient().Parcels.DeedToGroup(GetClient().Network.CurrentSim, targetparcel.LocalID, groupuuid);
return BasicReply("ok", new [] { group });
}
@ -432,12 +432,12 @@ namespace SecondBotEvents.Commands
{
return Failure(tests.Value, new [] { amount });
}
if ((targetparcel.AuthBuyerID != UUID.Zero) && (targetparcel.AuthBuyerID != getClient().Self.AgentID))
if ((targetparcel.AuthBuyerID != UUID.Zero) && (targetparcel.AuthBuyerID != GetClient().Self.AgentID))
{
return Failure("Parcel sale locked to other avatars", new[] { amount });
}
int minAmount = 1;
if (targetparcel.AuthBuyerID == getClient().Self.AgentID)
if (targetparcel.AuthBuyerID == GetClient().Self.AgentID)
{
minAmount = 0;
}
@ -457,7 +457,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Parcel sale price and amount do not match", new [] { amount });
}
getClient().Parcels.Buy(getClient().Network.CurrentSim, targetparcel.LocalID, false, UUID.Zero, false, targetparcel.Area, amountvalue);
GetClient().Parcels.Buy(GetClient().Network.CurrentSim, targetparcel.LocalID, false, UUID.Zero, false, targetparcel.Area, amountvalue);
return BasicReply("ok", new [] { amount });
}
@ -478,7 +478,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Invaild avatar UUID", new [] { avatar, state });
}
getClient().Parcels.FreezeUser(avataruuid, freezestate);
GetClient().Parcels.FreezeUser(avataruuid, freezestate);
return BasicReply("ok", new [] { avatar, state });
}
@ -522,7 +522,7 @@ namespace SecondBotEvents.Commands
reply.reportedEntrys = targetparcel.AccessBlackList.Count;
reply.delay = delays * 1000;
reply.parcelName = targetparcel.Name;
reply.regionName = getClient().Network.CurrentSim.Name;
reply.regionName = GetClient().Network.CurrentSim.Name;
return BasicReply(JsonConvert.SerializeObject(reply));
}
@ -538,12 +538,12 @@ namespace SecondBotEvents.Commands
return Failure("Invaild object uuid", new [] { objectuuid });
}
bool found = false;
Dictionary<uint, Primitive> objects_copy = getClient().Network.CurrentSim.ObjectsPrimitives.Copy();
Dictionary<uint, Primitive> objects_copy = GetClient().Network.CurrentSim.ObjectsPrimitives.Copy();
foreach (KeyValuePair<uint, Primitive> Obj in objects_copy)
{
if (Obj.Value.ID == targetobject)
{
getClient().Inventory.RequestDeRezToInventory(Obj.Key);
GetClient().Inventory.RequestDeRezToInventory(Obj.Key);
found = true;
break;
}
@ -634,7 +634,7 @@ namespace SecondBotEvents.Commands
}
}
}
targetparcel.Update(getClient().Network.CurrentSim, false);
targetparcel.Update(GetClient().Network.CurrentSim, false);
return BasicReply("ok", new [] { escapedflagdata });
}

View file

@ -24,17 +24,17 @@ namespace SecondBotEvents.Commands
[ReturnHintsFailure("Cant find UUID in sim")]
public object PointAt(string targetUUID)
{
if (getClient().Network.CurrentSim.AvatarPositions.ContainsKey(avataruuid) == false)
if (GetClient().Network.CurrentSim.AvatarPositions.ContainsKey(avataruuid) == false)
{
return Failure("Cant find UUID in sim", new [] { targetUUID });
}
ProcessAvatar(targetUUID);
getClient().Self.Stand();
getClient().Self.Movement.TurnToward(getClient().Network.CurrentSim.AvatarPositions[avataruuid]);
getClient().Self.Movement.SendUpdate();
getClient().Self.AnimationStart(Animations.POINT_YOU, true);
getClient().Self.PointAtEffect(getClient().Self.AgentID, avataruuid, new Vector3d(0, 0, 0), PointAtType.Select, UUID.Random());
getClient().Self.BeamEffect(getClient().Self.AgentID, avataruuid, new Vector3d(0, 0, 2), new Color4(255, 255, 255, 1), (float)3.0, UUID.Random());
GetClient().Self.Stand();
GetClient().Self.Movement.TurnToward(GetClient().Network.CurrentSim.AvatarPositions[avataruuid]);
GetClient().Self.Movement.SendUpdate();
GetClient().Self.AnimationStart(Animations.POINT_YOU, true);
GetClient().Self.PointAtEffect(GetClient().Self.AgentID, avataruuid, new Vector3d(0, 0, 0), PointAtType.Select, UUID.Random());
GetClient().Self.BeamEffect(GetClient().Self.AgentID, avataruuid, new Vector3d(0, 0, 2), new Color4(255, 255, 255, 1), (float)3.0, UUID.Random());
return BasicReply("ok", new [] { targetUUID });
}
@ -89,14 +89,14 @@ namespace SecondBotEvents.Commands
{
if (target == "ground")
{
getClient().Self.SitOnGround();
GetClient().Self.SitOnGround();
return BasicReply("ok", new [] { target });
}
if(UUID.TryParse(target,out UUID objectuuid) == false)
{
return Failure("Invaild object UUID", new [] { target });
}
getClient().Self.RequestSit(objectuuid, Vector3.Zero);
GetClient().Self.RequestSit(objectuuid, Vector3.Zero);
return BasicReply("ok", new [] { target });
}
@ -104,7 +104,7 @@ namespace SecondBotEvents.Commands
[ReturnHints("ok")]
public object Stand()
{
getClient().Self.Stand();
GetClient().Self.Stand();
return BasicReply("ok");
}
@ -120,16 +120,16 @@ namespace SecondBotEvents.Commands
return Failure("Invaild object UUID", new [] { target });
}
getClient().Self.PointAtEffect(getClient().Self.AgentID, objectuuid, new Vector3d(0, 0, 0), PointAtType.Select, new UUID("1df9eb92-62fa-15e5-4bfb-5931f1525274"));
GetClient().Self.PointAtEffect(GetClient().Self.AgentID, objectuuid, new Vector3d(0, 0, 0), PointAtType.Select, new UUID("1df9eb92-62fa-15e5-4bfb-5931f1525274"));
Dictionary<uint, Primitive> objectsentrys = getClient().Network.CurrentSim.ObjectsPrimitives.Copy();
Dictionary<uint, Primitive> objectsentrys = GetClient().Network.CurrentSim.ObjectsPrimitives.Copy();
bool found_object = false;
foreach (KeyValuePair<uint, Primitive> entry in objectsentrys)
{
if (entry.Value.ID == objectuuid)
{
getClient().Objects.ClickObject(getClient().Network.CurrentSim, entry.Key);
GetClient().Objects.ClickObject(GetClient().Network.CurrentSim, entry.Key);
found_object = true;
break;
}
@ -141,7 +141,7 @@ namespace SecondBotEvents.Commands
[ReturnHints("ok")]
public object Logoff()
{
getClient().Network.BeginLogout();
GetClient().Network.BeginLogout();
return BasicReply("ok");
}

View file

@ -65,7 +65,7 @@ namespace SecondBotEvents.Commands
{
return Failure("Unable to unpack avatar", new[] { endpoint, endpointcode });
}
bool result = master.botClient.SendNotecard(server_reply.NotecardTitle, server_reply.NotecardContent, avataruuid);
bool result = master.BotClient.SendNotecard(server_reply.NotecardTitle, server_reply.NotecardContent, avataruuid);
if (result == false)
{
return Failure("Failed to create/send notecard", new[] { endpoint, endpointcode });

View file

@ -10,7 +10,8 @@ namespace SecondBotEvents.Config
protected override void MakeSettings()
{
filename = "datastore";
settings.Add("AvatarsPurgeAfterMins");
settings.Add("AutoCleanAvatars");
settings.Add("AvatarsCleanAfterMins");
settings.Add("LocalChatHistoryLimit");
settings.Add("GroupChatHistoryLimitPerGroup");
settings.Add("ImChatHistoryLimit");
@ -53,9 +54,14 @@ namespace SecondBotEvents.Config
return ReadSettingAsBool("PrefetchGroupMembers", true);
}
public int GetAvatarsPurgeAfterMins()
public bool GetAutoCleanAvatars()
{
return ReadSettingAsInt("AvatarsPurgeAfterMins", 25);
return ReadSettingAsBool("AutoCleanAvatars", true);
}
public int GetAvatarsCleanAfterMins()
{
return ReadSettingAsInt("AvatarsCleanAfterMins", 10);
}
public int GetLocalChatHistoryLimit()

View file

@ -29,27 +29,40 @@ namespace SecondBotEvents
public class EventsSecondBot
{
public HttpService HttpService { get { return (HttpService) getService("HttpService"); } }
public CommandsService CommandsService { get { return (CommandsService)getService("CommandsService"); } }
public BotClientService botClient { get { return (BotClientService)getService("BotClientService"); } }
public DiscordService DiscordService { get { return (DiscordService)getService("DiscordService"); } }
public InteractionService InteractionService { get { return (InteractionService)getService("InteractionService"); } }
public DataStoreService DataStoreService { get { return (DataStoreService)getService("DataStoreService"); } }
public HomeboundService HomeboundService { get { return (HomeboundService)getService("HomeboundService"); } }
public HttpService HttpService { get { return (HttpService) GetService("HttpService"); } }
public CommandsService CommandsService { get { return (CommandsService)GetService("CommandsService"); } }
public BotClientService BotClient { get { return (BotClientService)GetService("BotClientService"); } }
public DiscordService DiscordService { get { return (DiscordService)GetService("DiscordService"); } }
public InteractionService InteractionService { get { return (InteractionService)GetService("InteractionService"); } }
public DataStoreService DataStoreService { get { return (DataStoreService)GetService("DataStoreService"); } }
public HomeboundService HomeboundService { get { return (HomeboundService)GetService("HomeboundService"); } }
private EventHandler<BotClientNotice> botclient_eventNotices;
public event EventHandler<BotClientNotice> BotClientNoticeEvent
private EventHandler<SystemStatusMessage> SystemStatusMessages;
public event EventHandler<SystemStatusMessage> SystemStatusMessagesEvent
{
add { lock (botclient_event_attach) { botclient_eventNotices += value; } }
remove { lock (botclient_event_attach) { botclient_eventNotices -= value; } }
add { lock (SystemStatusMessagesEventsLockable) { SystemStatusMessages += value; } }
remove { lock (SystemStatusMessagesEventsLockable) { SystemStatusMessages -= value; } }
}
private readonly object SystemStatusMessagesEventsLockable = new object();
public void TriggerSystemStatusMessageEvent(bool change, string message)
{
EventHandler<SystemStatusMessage> handler = SystemStatusMessages;
handler?.Invoke(this, new SystemStatusMessage(change, message));
}
private readonly object botclient_event_attach = new object();
private EventHandler<BotClientNotice> BotclientEventNotices;
public event EventHandler<BotClientNotice> BotClientNoticeEvent
{
add { lock (BotclientEventNoticesLockable) { BotclientEventNotices += value; } }
remove { lock (BotclientEventNoticesLockable) { BotclientEventNotices -= value; } }
}
private readonly object BotclientEventNoticesLockable = new object();
public void TriggerBotClientEvent(bool asRestart)
{
EventHandler<BotClientNotice> handler = botclient_eventNotices;
EventHandler<BotClientNotice> handler = BotclientEventNotices;
handler?.Invoke(this, new BotClientNotice(asRestart));
}
@ -87,7 +100,7 @@ namespace SecondBotEvents
protected Dictionary<string, BotServices> services = new Dictionary<string, BotServices>();
public BotServices getService(string classname)
public BotServices GetService(string classname)
{
if(services.ContainsKey(classname) == false)
{
@ -132,19 +145,18 @@ namespace SecondBotEvents
RegisterService("DiscordService");
RegisterService("InteractionService");
RegisterService("HomeboundService");
if (botClient.IsLoaded() == false)
if (BotClient.IsLoaded() == false)
{
Console.WriteLine("Config is not loaded :(");
exitNow = true;
return;
}
botClient.Start();
BotClient.Start();
Ready = true;
}
Dictionary<string, string> lastStatus = new Dictionary<string, string>();
long lastChange = 0;
public void Status()
{
string Output = "";
@ -152,7 +164,7 @@ namespace SecondBotEvents
foreach(KeyValuePair<string, BotServices> A in services)
{
string StatusMessage = A.Value.Status();
if(StatusMessage != lastStatus[A.Key])
if (StatusMessage != lastStatus[A.Key])
{
Output = Output + addon + " [" + A.Key + "] ~ " + StatusMessage;
lastStatus[A.Key] = StatusMessage;
@ -161,19 +173,11 @@ namespace SecondBotEvents
}
if(Output != "")
{
TriggerSystemStatusMessageEvent(true, Output);
LogFormater.Info(Output);
lastChange = SecondbotHelpers.UnixTimeNow();
return;
}
long dif = SecondbotHelpers.UnixTimeNow() - lastChange;
if(dif > 60)
{
string[] bits = lastStatus.Keys.ToArray();
foreach (string A in bits)
{
lastStatus[A] = "";
}
}
TriggerSystemStatusMessageEvent(false, "");
}
protected void StopServices()
@ -220,4 +224,15 @@ namespace SecondBotEvents
isRestart = asRestart;
}
}
public class SystemStatusMessage
{
public bool changed = false;
public string message = "";
public SystemStatusMessage(bool setChanged, string setMessage)
{
changed = setChanged;
message = setMessage;
}
}
}

View file

@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="Discord.Net" Version="3.4.1" />
<PackageReference Include="Discord.Net.WebSocket" Version="3.4.1" />
<PackageReference Include="Discord.Net.WebSocket" Version="3.7.2" />
<PackageReference Include="EmbedIO" Version="3.4.3" />
<PackageReference Include="MSBuildGitHash" Version="2.0.2">
<PrivateAssets>all</PrivateAssets>

View file

@ -11,11 +11,6 @@ namespace SecondBotEvents.Services
{
public GridClient client = null;
protected BasicConfig basicCfg = null;
public bool _ExitBot
{
get { return ExitBot; } // get method
set { } // set method
}
protected bool ExitBot = false;

View file

@ -22,10 +22,10 @@ namespace SecondBotEvents.Services
{
return;
}
loadCommands();
LoadCommands();
}
protected void loadCommands()
protected void LoadCommands()
{
Dictionary<string, Type> commandmodules = http_commands_helper.getCommandModules();
foreach (Type entry in commandmodules.Values)
@ -66,50 +66,6 @@ namespace SecondBotEvents.Services
}
}
}
Dictionary<string,int> acceptTokens = new Dictionary<string,int>();
public bool AllowToken(string token)
{
if(acceptTokens.ContainsKey(token) == false)
{
return false;
}
if (acceptTokens[token] != -1)
{
acceptTokens[token] = acceptTokens[token] - 1;
if(acceptTokens[token] == 0)
{
acceptTokens.Remove(token);
}
}
return true;
}
protected string SingleUseToken()
{
bool found = false;
string token = "";
while(found == false)
{
token = SecondbotHelpers.GetSHA1(token + SecondbotHelpers.UnixTimeNow().ToString());
if(acceptTokens.ContainsKey(token) == false)
{
addNewToken(token, 1);
found = true;
}
}
return token;
}
protected void addNewToken(string token,int uses)
{
if (acceptTokens.ContainsKey(token) == false)
{
acceptTokens[token] = 0;
}
acceptTokens[token] = uses;
}
public override void Start()
{
master.BotClientNoticeEvent += BotClientRestart;
@ -135,7 +91,7 @@ namespace SecondBotEvents.Services
{
return;
}
if (e.IM.FromAgentName == getClient().Self.Name)
if (e.IM.FromAgentName == GetClient().Self.Name)
{
return;
}
@ -186,14 +142,14 @@ namespace SecondBotEvents.Services
{
return;
}
KeyValuePair<bool, string> reply = runCommand(C);
KeyValuePair<bool, string> reply = RunCommand(C);
if(C.replyTarget != null)
{
SmartCommandReply(reply.Key, C.replyTarget, reply.Value, C.command);
SmartCommandReply(C.replyTarget, reply.Value, C.command);
}
}
public void SmartCommandReply(bool run_status, string target, string output, string command)
public void SmartCommandReply(string target, string output, string command)
{
string mode = "CHAT";
UUID target_avatar = UUID.Zero;
@ -208,7 +164,7 @@ namespace SecondBotEvents.Services
}
else if (target.Split(' ', StringSplitOptions.RemoveEmptyEntries).Length == 2)
{
string UUIDfetch = master.DataStoreService.getAvatarUUID(target);
string UUIDfetch = master.DataStoreService.GetAvatarUUID(target);
if (UUIDfetch == "lookup")
{
return;
@ -227,11 +183,11 @@ namespace SecondBotEvents.Services
LogFormater.Crit("[SmartReply] output Channel must be zero or higher - using 99");
target_channel = 999;
}
getClient().Self.Chat(output, target_channel, ChatType.Normal);
GetClient().Self.Chat(output, target_channel, ChatType.Normal);
}
else if (mode == "IM")
{
getClient().Self.InstantMessage(target_avatar, output);
GetClient().Self.InstantMessage(target_avatar, output);
}
else if (mode == "HTTP")
{
@ -254,7 +210,7 @@ namespace SecondBotEvents.Services
}
protected HttpClient HTTPclient = new HttpClient();
public KeyValuePair<bool, string> runCommand(SignedCommand C)
public KeyValuePair<bool, string> RunCommand(SignedCommand C)
{
try
@ -306,7 +262,7 @@ namespace SecondBotEvents.Services
}
}
public string[] getFullListOfCommands()
public string[] GetFullListOfCommands()
{
List<string> output = new List<string>();
foreach (string A in endpointcommandmap.Keys)
@ -324,25 +280,25 @@ namespace SecondBotEvents.Services
{
acceptNewCommands = false;
Console.WriteLine("Commands service [Attached to new client]");
getClient().Network.LoggedOut += BotLoggedOut;
getClient().Network.SimConnected += BotLoggedIn;
GetClient().Network.LoggedOut += BotLoggedOut;
GetClient().Network.SimConnected += BotLoggedIn;
}
protected void BotLoggedOut(object o, LoggedOutEventArgs e)
{
getClient().Network.SimConnected += BotLoggedIn;
GetClient().Network.SimConnected += BotLoggedIn;
Console.WriteLine("Commands service [Waiting for connect]");
}
protected void BotLoggedIn(object o, SimConnectedEventArgs e)
{
getClient().Network.SimConnected -= BotLoggedIn;
getClient().Self.IM += BotImMessage;
GetClient().Network.SimConnected -= BotLoggedIn;
GetClient().Self.IM += BotImMessage;
if (myConfig.GetEnableMasterControls() == true)
{
foreach(string A in myConfig.GetMastersCSV())
{
master.DataStoreService.knownAvatar(A);
master.DataStoreService.KnownAvatar(A);
}
}
acceptNewCommands = true;
@ -360,13 +316,13 @@ namespace SecondBotEvents.Services
public long unixtimeOfCommand = 0;
public SignedCommand(string input, bool requireSigning, bool requireTimewindow, int windowSize, string secret)
{
unpackInput(input);
UnpackInput(input);
if (requireSigning == false)
{
accepted = true; // just accept the command
return;
}
vaildate(requireTimewindow, windowSize, secret);
Vaildate(requireTimewindow, windowSize, secret);
}
public SignedCommand(string setCommand, string setSigningCode, string[] setArgs, int setUnixtime, string setReplyTarget, bool requireTimewindow, int windowSize, string secret)
{
@ -375,10 +331,10 @@ namespace SecondBotEvents.Services
args = setArgs;
unixtimeOfCommand = setUnixtime;
replyTarget = setReplyTarget;
vaildate(requireTimewindow, windowSize, secret);
Vaildate(requireTimewindow, windowSize, secret);
}
protected void vaildate(bool requireTimewindow, int windowSize, string secret)
protected void Vaildate(bool requireTimewindow, int windowSize, string secret)
{
accepted = false;
long dif = SecondbotHelpers.UnixTimeNow() - unixtimeOfCommand;
@ -391,12 +347,12 @@ namespace SecondBotEvents.Services
return;
}
string raw = command;
raw = raw + string.Join("~#~", args);
raw += string.Join("~#~", args);
if (requireTimewindow == true)
{
raw = raw + unixtimeOfCommand.ToString();
raw += unixtimeOfCommand.ToString();
}
raw = raw + secret;
raw += secret;
string cooked = SecondbotHelpers.GetSHA1(raw);
if (cooked != signingCode)
{
@ -405,17 +361,17 @@ namespace SecondBotEvents.Services
accepted = true;
}
protected void unpackInput(string input)
protected void UnpackInput(string input)
{
if (IsValidJson(input) == false)
{
unpackStringToClass(input);
UnpackStringToClass(input);
return;
}
unpackJsonToClass();
UnpackJsonToClass();
}
protected JToken obj = null;
protected void unpackStringToClass(string input)
protected void UnpackStringToClass(string input)
{
// command|||args~#~args~#~args#|#reply_target@@@sha1 [inc time if required];|;unixtime of command
@ -437,13 +393,13 @@ namespace SecondBotEvents.Services
args = bits[1].Split("~#~");
}
}
protected void unpackJsonToClass()
protected void UnpackJsonToClass()
{
command = jsonHelper.GetValue<string>(obj, "cmd", null);
args = jsonHelper.GetValue<string[]>(obj, "args", null);
signingCode = jsonHelper.GetValue<string>(obj, "signing", null);
replyTarget = jsonHelper.GetValue<string>(obj, "reply", null);
unixtimeOfCommand = jsonHelper.GetValue<long>(obj, "unixtime", 0);
command = JsonHelper.GetValue<string>(obj, "cmd", null);
args = JsonHelper.GetValue<string[]>(obj, "args", null);
signingCode = JsonHelper.GetValue<string>(obj, "signing", null);
replyTarget = JsonHelper.GetValue<string>(obj, "reply", null);
unixtimeOfCommand = JsonHelper.GetValue<long>(obj, "unixtime", 0);
}
private bool IsValidJson(string strInput)
@ -467,9 +423,9 @@ namespace SecondBotEvents.Services
}
}
public static class jsonHelper
public static class JsonHelper
{
public static T GetValue<T>(this JToken jToken, string key, T defaultValue = default(T))
public static T GetValue<T>(this JToken jToken, string key, T defaultValue = default)
{
dynamic ret = jToken[key];
if (ret == null) return defaultValue;

View file

@ -19,6 +19,7 @@ namespace SecondBotEvents.Services
}
protected Dictionary<string, UUID> avatarsName2Key = new Dictionary<string, UUID>();
protected Dictionary<UUID, long> avatarLastUsed = new Dictionary<UUID, long>();
protected Dictionary<UUID, string> groupsKey2Name = new Dictionary<UUID, string>();
@ -37,12 +38,75 @@ namespace SecondBotEvents.Services
protected List<CommandHistory> commandHistories = new List<CommandHistory>();
protected long lastCleanupKeyValueStore = 0;
protected long lastCleanupAvatarStore = 0;
public override string Status()
{
if (myConfig == null)
{
return "DataStore Service [Config broken]";
}
long unixtime = SecondbotHelpers.UnixTimeNow();
if (myConfig.GetAutoCleanKeyValueStore() == true)
{
if (lastCleanupKeyValueStore == 0)
{
lastCleanupKeyValueStore = SecondbotHelpers.UnixTimeNow();
}
long dif = unixtime - lastCleanupKeyValueStore;
if (dif > 125)
{
lastCleanupKeyValueStore = unixtime;
List<string> clearentrys = new List<string>();
foreach (KeyValuePair<string, long> entry in KeyValueStoreLastUsed)
{
dif = unixtime - entry.Value;
if (dif < (myConfig.GetCleanKeyValueStoreAfterMins()*60))
{
continue;
}
clearentrys.Add(entry.Key);
}
lock (KeyValueStore)
{
foreach (string A in clearentrys)
{
KeyValueStore.Remove(A);
KeyValueStoreLastUsed.Remove(A);
}
}
}
}
if(myConfig.GetAutoCleanAvatars() == true)
{
if(lastCleanupAvatarStore == 0)
{
lastCleanupAvatarStore = unixtime;
}
long dif = unixtime - lastCleanupAvatarStore;
if (dif > 75)
{
lastCleanupAvatarStore = unixtime;
Dictionary<UUID, string> clearLinks = new Dictionary<UUID, string>();
foreach (KeyValuePair<string, UUID> entry in avatarsName2Key)
{
dif = unixtime - avatarLastUsed[entry.Value];
if (dif < (myConfig.GetAvatarsCleanAfterMins() * 60))
{
continue;
}
clearLinks.Add(entry.Value, entry.Key);
}
lock (avatarLastUsed) lock(avatarsName2Key)
{
foreach (KeyValuePair<UUID, string> A in clearLinks)
{
avatarLastUsed.Remove(A.Key);
avatarsName2Key.Remove(A.Value);
}
}
}
}
int sum = commandHistories.Count() + KeyValueStoreLastUsed.Count() + KeyValueStore.Count() +
chatWindowsOwner.Count() + chatWindowsIsGroup.Count() + chatWindowsUnread.Count() +
chatWindows.Count() + localChatHistory.Count() + groupRoles.Count() +
@ -50,47 +114,59 @@ namespace SecondBotEvents.Services
return sum.ToString();
}
public void addCommandToHistory(bool status, string command, string[] args)
public void AddCommandToHistory(bool status, string command, string[] args)
{
CommandHistory A = new CommandHistory(status, command, args, SecondbotHelpers.UnixTimeNow());
commandHistories.Add(A);
int c = commandHistories.Count;
while (c > myConfig.GetCommandHistoryLimit())
lock (commandHistories)
{
commandHistories.RemoveAt(0);
c--;
CommandHistory A = new CommandHistory(status, command, args, SecondbotHelpers.UnixTimeNow());
commandHistories.Add(A);
int c = commandHistories.Count;
while (c > myConfig.GetCommandHistoryLimit())
{
commandHistories.RemoveAt(0);
c--;
}
}
}
public string GetKeyValue(string key)
{
if(KeyValueStore.ContainsKey(key) == false)
lock (KeyValueStore)
{
return "";
if (KeyValueStore.ContainsKey(key) == false)
{
return "";
}
KeyValueStoreLastUsed[key] = SecondbotHelpers.UnixTimeNow();
return KeyValueStore[key];
}
KeyValueStoreLastUsed[key] = SecondbotHelpers.UnixTimeNow();
return KeyValueStore[key];
}
public void SetKeyValue(string key, string value)
{
if(KeyValueStore.ContainsKey(key) == false)
lock (KeyValueStore)
{
KeyValueStore.Add(key, "");
KeyValueStoreLastUsed.Add(key, 0);
if (KeyValueStore.ContainsKey(key) == false)
{
KeyValueStore.Add(key, "");
KeyValueStoreLastUsed.Add(key, 0);
}
KeyValueStore[key] = value;
KeyValueStoreLastUsed[key] = SecondbotHelpers.UnixTimeNow();
}
KeyValueStore[key] = value;
KeyValueStoreLastUsed[key] = SecondbotHelpers.UnixTimeNow();
}
public void ClearKeyValue(string key)
{
if (KeyValueStore.ContainsKey(key) == false)
lock (KeyValueStore)
{
return;
if (KeyValueStore.ContainsKey(key) == false)
{
return;
}
KeyValueStore.Remove(key);
KeyValueStoreLastUsed.Remove(key);
}
KeyValueStore.Remove(key);
KeyValueStoreLastUsed.Remove(key);
}
public void AppendKeyValue(string key, string value)
@ -164,18 +240,21 @@ namespace SecondBotEvents.Services
return chatWindows[group];
}
public void clearGroupChat()
public void ClearGroupChat()
{
foreach(UUID group in groupsKey2Name.Keys)
lock (chatWindows)
{
if (chatWindowsUnread.ContainsKey(group) == false)
foreach (UUID group in groupsKey2Name.Keys)
{
continue;
if (chatWindowsUnread.ContainsKey(group) == false)
{
continue;
}
chatWindowsUnread.Remove(group);
chatWindows.Remove(group);
chatWindowsIsGroup.Remove(group);
chatWindowsOwner.Remove(group);
}
chatWindowsUnread.Remove(group);
chatWindows.Remove(group);
chatWindowsIsGroup.Remove(group);
chatWindowsOwner.Remove(group);
}
}
@ -186,23 +265,22 @@ namespace SecondBotEvents.Services
{
AutoResetEvent fetchEvent = new AutoResetEvent(false);
EventHandler<GroupRolesDataReplyEventArgs> callback =
delegate (object sender, GroupRolesDataReplyEventArgs e)
void callback(object sender, GroupRolesDataReplyEventArgs e)
{
if (e.GroupID == group)
{
if (e.GroupID == group)
foreach (KeyValuePair<UUID, GroupRole> role in e.Roles)
{
foreach(KeyValuePair<UUID,GroupRole> role in e.Roles)
{
reply[role.Value.ID] = role.Value.Name;
}
fetchEvent.Set();
reply[role.Value.ID] = role.Value.Name;
}
};
getClient().Groups.GroupRoleDataReply += callback;
getClient().Groups.RequestGroupRoles(group);
fetchEvent.Set();
}
}
GetClient().Groups.GroupRoleDataReply += callback;
GetClient().Groups.RequestGroupRoles(group);
fetchEvent.WaitOne(1000, false);
getClient().Groups.GroupRoleDataReply -= callback;
GetClient().Groups.GroupRoleDataReply -= callback;
return reply;
}
foreach (KeyValuePair<UUID, GroupRole> role in groupRoles[group])
@ -214,16 +292,18 @@ namespace SecondBotEvents.Services
public bool IsGroupMember(UUID group, UUID avatar)
{
if(groupMembers.ContainsKey(group) == false)
bool reply = true;
lock (groupMembers)
{
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 (groupMembers.ContainsKey(group) == false)
{
groupMembers.Add(group, new List<UUID>());
}
if (groupMembers[group].Contains(avatar) == false)
{
reply = false;
AutoResetEvent fetchEvent = new AutoResetEvent(false);
void callback(object sender, GroupMembersReplyEventArgs e)
{
if (e.GroupID == group)
{
@ -231,34 +311,37 @@ namespace SecondBotEvents.Services
{
if (a.Value.ID == avatar)
{
found = true;
reply = true;
fetchEvent.Set();
break;
}
}
}
};
getClient().Groups.GroupMembersReply += callback;
getClient().Groups.RequestGroupMembers(group);
fetchEvent.WaitOne(1000, false);
getClient().Groups.GroupMembersReply -= callback;
return found;
}
}
GetClient().Groups.GroupMembersReply += callback;
GetClient().Groups.RequestGroupMembers(group);
fetchEvent.WaitOne(1000, false);
GetClient().Groups.GroupMembersReply -= callback;
}
}
return true;
return reply;
}
public List<UUID> GetGroupMembers(UUID Group)
{
if (groupMembers.ContainsKey(Group) == false)
lock (groupMembers)
{
groupMembers.Add(Group, new List<UUID>());
if (groupMembers.ContainsKey(Group) == false)
{
groupMembers.Add(Group, new List<UUID>());
}
}
return groupMembers[Group];
}
protected void recordChat(UUID sessionID, string fromname, string message)
protected void RecordChat(UUID sessionID, string fromname, string message)
{
lock (chatWindows)
{
@ -282,7 +365,7 @@ namespace SecondBotEvents.Services
}
}
protected void closeChat(UUID owner)
protected void CloseChat(UUID owner)
{
lock (chatWindows)
{
@ -311,7 +394,7 @@ namespace SecondBotEvents.Services
}
protected void openChatWindow(bool group, UUID sessionID, UUID ownerID)
protected void OpenChatWindow(bool group, UUID sessionID, UUID ownerID)
{
lock (chatWindows)
{
@ -351,12 +434,12 @@ namespace SecondBotEvents.Services
protected Dictionary<string, KeyValuePair<string, long>> notecardDataStore = new Dictionary<string, KeyValuePair<string, long>>();
public List<string> getLocalChat()
public List<string> GetLocalChat()
{
return localChatHistory;
}
public bool knownGroup(UUID groupId, string name)
public bool KnownGroup(UUID groupId, string name)
{
if(groupId != UUID.Zero)
{
@ -365,7 +448,7 @@ namespace SecondBotEvents.Services
return groupsKey2Name.ContainsValue(name);
}
public List<string> getGroupChat(UUID groupId)
public List<string> GetGroupChat(UUID groupId)
{
if(chatWindows.ContainsKey(groupId) == false)
{
@ -380,9 +463,9 @@ namespace SecondBotEvents.Services
* lookup the avatar
*/
public bool knownAvatar(string name)
public bool KnownAvatar(string name)
{
return knownAvatar(name, UUID.Zero);
return KnownAvatar(name, UUID.Zero);
}
@ -393,16 +476,16 @@ namespace SecondBotEvents.Services
* lookup the avatar
*/
public bool knownAvatar(string name, UUID avatarId)
public bool KnownAvatar(string name, UUID avatarId)
{
int currentHash = getClient().Network.CurrentSim.ObjectsAvatars.GetHashCode();
int currentHash = GetClient().Network.CurrentSim.ObjectsAvatars.GetHashCode();
if (currentHash != ObjectsAvatarsHash)
{
ObjectsAvatarsHash = currentHash;
List<Avatar> avs = getClient().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);
AddAvatar(A.ID, A.Name);
}
}
if (avatarId != UUID.Zero)
@ -411,23 +494,22 @@ namespace SecondBotEvents.Services
{
bool hasReply = false;
AutoResetEvent fetchEvent = new AutoResetEvent(false);
EventHandler<UUIDNameReplyEventArgs> callback =
delegate (object sender, UUIDNameReplyEventArgs e)
void callback(object sender, UUIDNameReplyEventArgs e)
{
foreach (KeyValuePair<UUID, string> av in e.Names)
{
foreach (KeyValuePair<UUID, string> av in e.Names)
if (av.Key == avatarId)
{
if (av.Key == avatarId)
{
hasReply = true;
fetchEvent.Set();
}
hasReply = true;
fetchEvent.Set();
}
};
getClient().Avatars.UUIDNameReply += callback;
getClient().Avatars.RequestAvatarName(avatarId);
}
}
GetClient().Avatars.UUIDNameReply += callback;
GetClient().Avatars.RequestAvatarName(avatarId);
fetchEvent.WaitOne(1000, false);
getClient().Avatars.UUIDNameReply -= callback;
GetClient().Avatars.UUIDNameReply -= callback;
return hasReply;
}
return true;
@ -435,7 +517,7 @@ namespace SecondBotEvents.Services
string[] bits = name.Split(' ');
if (bits.Length == 1)
{
name = name + " Resident";
name += " Resident";
}
if (avatarsName2Key.ContainsKey(name) == false)
{
@ -443,59 +525,66 @@ namespace SecondBotEvents.Services
bool hasReply = false;
AutoResetEvent fetchEvent = new AutoResetEvent(false);
EventHandler<AvatarPickerReplyEventArgs> callback =
delegate (object sender, AvatarPickerReplyEventArgs e)
void callback(object sender, AvatarPickerReplyEventArgs e)
{
if (e.QueryID == wantedReplyID)
{
if (e.QueryID == wantedReplyID)
foreach (KeyValuePair<UUID, string> av in e.Avatars)
{
foreach(KeyValuePair<UUID,string> av in e.Avatars)
if (av.Value == name)
{
if(av.Value == name)
{
hasReply = true;
fetchEvent.Set();
}
hasReply = true;
fetchEvent.Set();
}
}
};
getClient().Avatars.AvatarPickerReply += callback;
getClient().Avatars.RequestAvatarNameSearch(name, wantedReplyID);
}
}
GetClient().Avatars.AvatarPickerReply += callback;
GetClient().Avatars.RequestAvatarNameSearch(name, wantedReplyID);
fetchEvent.WaitOne(1000, false);
getClient().Avatars.AvatarPickerReply -= callback;
GetClient().Avatars.AvatarPickerReply -= callback;
return hasReply;
}
return true;
}
public string getAvatarName(UUID avatarId)
public string GetAvatarName(UUID avatarId)
{
if(knownAvatar(null, avatarId) == false)
string reply = "lookup";
lock (avatarLastUsed)
{
return "lookup";
}
string results = "lookup";
foreach (KeyValuePair<string, UUID> av in avatarsName2Key)
{
if(av.Value == avatarId)
if (KnownAvatar(null, avatarId) == false)
{
results = av.Key;
break;
return reply;
}
foreach (KeyValuePair<string, UUID> av in avatarsName2Key)
{
if (av.Value == avatarId)
{
avatarLastUsed[av.Value] = SecondbotHelpers.UnixTimeNow();
reply = av.Key;
break;
}
}
}
return results;
return reply;
}
public string getAvatarUUID(string name)
public string GetAvatarUUID(string name)
{
if (knownAvatar(name) == false)
if (KnownAvatar(name) == false)
{
return "lookup";
}
lock (avatarLastUsed)
{
avatarLastUsed[avatarsName2Key[name]] = SecondbotHelpers.UnixTimeNow();
}
return avatarsName2Key[name].ToString();
}
public List<string> getAvatarIms(UUID avatarId)
public List<string> GetAvatarIms(UUID avatarId)
{
if(chatWindowsOwner.ContainsValue(avatarId) == false)
{
@ -517,7 +606,7 @@ namespace SecondBotEvents.Services
return chatWindows[sessionID];
}
public Dictionary<UUID,string> getAvatarImWindows()
public Dictionary<UUID,string> GetAvatarImWindows()
{
Dictionary<UUID, string> windows = new Dictionary<UUID, string>();
foreach (KeyValuePair<UUID,bool> links in chatWindowsIsGroup)
@ -530,12 +619,12 @@ namespace SecondBotEvents.Services
{
continue;
}
windows[chatWindowsOwner[links.Key]] = getAvatarName(chatWindowsOwner[links.Key]);
windows[chatWindowsOwner[links.Key]] = GetAvatarName(chatWindowsOwner[links.Key]);
}
return windows;
}
public List<string> getAvatarImWindow(UUID avatarId)
public List<string> GetAvatarImWindow(UUID avatarId)
{
if (chatWindowsOwner.ContainsValue(avatarId) == false)
{
@ -558,7 +647,7 @@ namespace SecondBotEvents.Services
}
public bool getAvatarImWindowsUnreadAny()
public bool GetAvatarImWindowsUnreadAny()
{
bool replyState = false;
foreach (KeyValuePair<UUID, bool> links in chatWindowsIsGroup)
@ -581,7 +670,7 @@ namespace SecondBotEvents.Services
return replyState;
}
public List<UUID> getAvatarImWindowsUnread()
public List<UUID> GetAvatarImWindowsUnread()
{
List<UUID> windows = new List<UUID>();
foreach (KeyValuePair<UUID, bool> links in chatWindowsIsGroup)
@ -605,21 +694,23 @@ namespace SecondBotEvents.Services
protected void reset()
protected void Reset()
{
if (estateBanlist != null)
{
lock (avatarsName2Key) lock (groupMembers) lock (localChatHistory) lock (chatWindows) lock (estateBanlist)
{
clearMem();
ClearMem();
}
return;
}
clearMem();
ClearMem();
}
protected void clearMem()
protected void ClearMem()
{
lastCleanupKeyValueStore = 0;
avatarsName2Key = new Dictionary<string, UUID>();
groupsKey2Name = new Dictionary<UUID, string>();
@ -644,14 +735,14 @@ namespace SecondBotEvents.Services
{
botConnected = false;
Console.WriteLine("DataStore Service [Attached to new client]");
getClient().Network.LoggedOut += BotLoggedOut;
getClient().Network.SimConnected += BotLoggedIn;
GetClient().Network.LoggedOut += BotLoggedOut;
GetClient().Network.SimConnected += BotLoggedIn;
}
protected void BotLoggedOut(object o, LoggedOutEventArgs e)
{
botConnected = false;
getClient().Network.SimConnected += BotLoggedIn;
GetClient().Network.SimConnected += BotLoggedIn;
Console.WriteLine("DataStore Service [Standby]");
}
@ -689,17 +780,16 @@ namespace SecondBotEvents.Services
{
List<UUID> reply = new List<UUID>();
AutoResetEvent fetchEvent = new AutoResetEvent(false);
EventHandler<EstateBansReplyEventArgs> callback =
delegate (object sender, EstateBansReplyEventArgs e)
{
reply = e.Banned;
fetchEvent.Set();
};
getClient().Estate.EstateBansReply += callback;
getClient().Estate.RequestInfo();
void callback(object sender, EstateBansReplyEventArgs e)
{
reply = e.Banned;
fetchEvent.Set();
}
GetClient().Estate.EstateBansReply += callback;
GetClient().Estate.RequestInfo();
fetchEvent.WaitOne(1000, false);
getClient().Estate.EstateBansReply -= callback;
GetClient().Estate.EstateBansReply -= callback;
return reply;
}
return estateBanlist;
@ -717,19 +807,19 @@ namespace SecondBotEvents.Services
protected void BotLoggedIn(object o, SimConnectedEventArgs e)
{
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().Estate.EstateBansReply += EstateBans;
getClient().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().Estate.EstateBansReply += EstateBans;
GetClient().Groups.RequestCurrentGroups();
botConnected = true;
Console.WriteLine("DataStore Service [Active]");
}
@ -742,10 +832,6 @@ namespace SecondBotEvents.Services
case ChatType.Normal:
case ChatType.Shout:
{
if (e.SourceType != ChatSourceType.Agent)
{
break;
}
if (hard_blocked_agents.Contains(e.FromName.ToLowerInvariant()) == true)
{
break;
@ -790,14 +876,14 @@ namespace SecondBotEvents.Services
continue;
}
groupsKey2Name.Add(G.ID, G.Name);
getClient().Self.RequestJoinGroupChat(G.ID);
GetClient().Self.RequestJoinGroupChat(G.ID);
if (myConfig.GetPrefetchGroupMembers() == true)
{
getClient().Groups.RequestGroupMembers(G.ID);
GetClient().Groups.RequestGroupMembers(G.ID);
}
if (myConfig.GetPrefetchGroupRoles() == true)
{
getClient().Groups.RequestGroupRoles(G.ID);
GetClient().Groups.RequestGroupRoles(G.ID);
}
}
@ -807,32 +893,33 @@ namespace SecondBotEvents.Services
{
continue;
}
string name = groupsKey2Name[G];
groupsKey2Name.Remove(G);
closeChat(G);
CloseChat(G);
}
}
}
protected void GroupJoin(object o, GroupOperationEventArgs e)
{
getClient().Groups.RequestCurrentGroups();
GetClient().Groups.RequestCurrentGroups();
}
protected void GroupLeave(object o, GroupOperationEventArgs e)
{
getClient().Groups.RequestCurrentGroups();
GetClient().Groups.RequestCurrentGroups();
}
protected void addAvatar(UUID id, string name)
protected void AddAvatar(UUID id, string name)
{
lock (avatarsName2Key)
lock (avatarsName2Key) lock (avatarLastUsed)
{
if (avatarsName2Key.ContainsValue(id) == true)
{
avatarLastUsed[id] = SecondbotHelpers.UnixTimeNow();
return;
}
avatarsName2Key.Add(name, id);
avatarLastUsed.Add(id, SecondbotHelpers.UnixTimeNow());
}
}
@ -840,7 +927,7 @@ namespace SecondBotEvents.Services
{
foreach(KeyValuePair<UUID,string> pair in e.Names)
{
addAvatar(pair.Key, pair.Value);
AddAvatar(pair.Key, pair.Value);
}
}
@ -848,7 +935,7 @@ namespace SecondBotEvents.Services
{
foreach(KeyValuePair<UUID,string> Av in e.Avatars)
{
addAvatar(Av.Key, Av.Value);
AddAvatar(Av.Key, Av.Value);
}
}
@ -856,7 +943,7 @@ namespace SecondBotEvents.Services
{
foreach (KeyValuePair<UUID, string> pair in e.Names)
{
addAvatar(pair.Key, pair.Value);
AddAvatar(pair.Key, pair.Value);
}
}
@ -870,8 +957,8 @@ namespace SecondBotEvents.Services
{
break;
}
openChatWindow(true, e.IM.IMSessionID, e.IM.IMSessionID);
recordChat(e.IM.IMSessionID, "**Notice**", e.IM.Message);
OpenChatWindow(true, e.IM.IMSessionID, e.IM.IMSessionID);
RecordChat(e.IM.IMSessionID, "**Notice**", e.IM.Message);
break;
}
case InstantMessageDialog.SessionSend:
@ -880,13 +967,13 @@ namespace SecondBotEvents.Services
if (groupsKey2Name.ContainsKey(e.IM.IMSessionID) == true)
{
// group IM
openChatWindow(true, e.IM.IMSessionID, e.IM.IMSessionID);
recordChat(e.IM.IMSessionID, e.IM.FromAgentName, e.IM.Message);
OpenChatWindow(true, e.IM.IMSessionID, e.IM.IMSessionID);
RecordChat(e.IM.IMSessionID, e.IM.FromAgentName, e.IM.Message);
break;
}
addAvatar(e.IM.FromAgentID, e.IM.FromAgentName);
openChatWindow(false, e.IM.IMSessionID, e.IM.FromAgentID);
recordChat(e.IM.IMSessionID, e.IM.FromAgentName, e.IM.Message);
AddAvatar(e.IM.FromAgentID, e.IM.FromAgentName);
OpenChatWindow(false, e.IM.IMSessionID, e.IM.FromAgentID);
RecordChat(e.IM.IMSessionID, e.IM.FromAgentName, e.IM.Message);
break;
}
default:
@ -905,23 +992,23 @@ namespace SecondBotEvents.Services
public override void Stop()
{
reset();
Reset();
master.BotClientNoticeEvent -= BotClientRestart;
if (master.botClient != null)
if (master.BotClient != null)
{
if (getClient() != null)
if (GetClient() != null)
{
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().Estate.EstateBansReply -= EstateBans;
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().Estate.EstateBansReply -= EstateBans;
}
}
Console.WriteLine("DataStore Service [Stopping]");

View file

@ -2,19 +2,21 @@
using Discord.Rest;
using Discord.WebSocket;
using OpenMetaverse;
using SecondBotEvents.Config;
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
namespace SecondBotEvents.Services
{
public class DiscordService : BotServices
{
public Config.DiscordConfig myConfig = null;
public bool acceptChat = false;
public bool discordIsReady = false;
protected Config.DiscordConfig myConfig = null;
protected bool AcceptEventsFromSL = false;
protected bool DiscordIsReady = false;
protected bool DiscordDisconnectExpected = false;
protected bool DiscordServerChannelsSetup = false;
protected bool DiscordDoingLogin = false;
protected DiscordSocketClient DiscordClient;
public DiscordService(EventsSecondBot setMaster) : base(setMaster)
@ -22,32 +24,56 @@ namespace SecondBotEvents.Services
myConfig = new Config.DiscordConfig(master.fromEnv, master.fromFolder);
}
public override string Status()
{
if (myConfig == null)
{
return "Config broken";
}
else if(myConfig.GetEnabled() == false)
{
return "Disabled";
}
else if(DiscordServerChannelsSetup == false)
{
return "Setting up channel";
}
else if(DiscordDoingLogin == true)
{
return "Logging in";
}
else if(DiscordIsReady == false)
{
return "Disconnected";
}
return "Active";
}
public bool DiscordReady()
{
if(acceptChat == false)
{
return false;
}
return discordIsReady;
return GetReadyForDiscordActions();
}
protected Task DiscordClientLoggedOut()
{
Console.WriteLine("Discord service [Logged out]");
discordIsReady = false;
DiscordIsReady = false;
return Task.CompletedTask;
}
protected Task DicordClientLoggedin()
{
Console.WriteLine("Discord service [Logged in]");
DiscordDoingLogin = false;
_ = DiscordClient.StartAsync();
return Task.CompletedTask;
}
protected Task DiscordClientReady()
{
Console.WriteLine("Discord service [Ready]");
discordIsReady = true;
DiscordIsReady = true;
DoServerChannelSetup();
return Task.CompletedTask;
}
@ -59,33 +85,70 @@ namespace SecondBotEvents.Services
protected Task DiscordDisconnected(Exception e)
{
Console.WriteLine("Discord service [Disconnected: "+e.Message+"]");
discordIsReady = false;
DiscordIsReady = false;
if(DiscordDisconnectExpected == false)
{
Restart();
}
return Task.CompletedTask;
}
public async override void Start()
protected void StatusMessageUpdate(object o, SystemStatusMessage e)
{
if(GetReadyForDiscordActions() == false)
{
return;
}
}
protected bool GetReadyForDiscordActions()
{
if (DiscordIsReady == false)
{
return false;
}
if (DiscordServerChannelsSetup == false)
{
return false;
}
return true;
}
public override void Start()
{
if(myConfig.GetEnabled() == false)
{
Console.WriteLine("Discord service [Disabled]");
return;
}
if(myConfig.GetServerID() == 0)
{
Console.WriteLine("Discord service [Invaild server id]");
return;
}
DiscordServerChannelsSetup = false;
DiscordDisconnectExpected = false;
DiscordIsReady = false;
Console.WriteLine("Discord service [Starting]");
master.SystemStatusMessagesEvent += SystemStatusEvent;
master.BotClientNoticeEvent += BotClientRestart;
master.SystemStatusMessagesEvent += StatusMessageUpdate;
DiscordClient = new DiscordSocketClient();
DiscordClient.Ready += DiscordClientReady;
DiscordClient.LoggedOut += DiscordClientLoggedOut;
DiscordClient.LoggedIn += DicordClientLoggedin;
DiscordClient.MessageReceived += DiscordClientMessageReceived;
DiscordClient.Disconnected += DiscordDisconnected;
await DiscordClient.LoginAsync(TokenType.Bot, myConfig.GetClientToken());
_ = DiscordClient.LoginAsync(TokenType.Bot, myConfig.GetClientToken()).ConfigureAwait(false);
}
public override void Stop()
{
Console.WriteLine("Discord service [Stopping]");
master.BotClientNoticeEvent -= BotClientRestart;
acceptChat = false;
master.SystemStatusMessagesEvent -= StatusMessageUpdate;
AcceptEventsFromSL = false;
if(DiscordClient != null)
{
DiscordClient.Dispose();
@ -95,22 +158,30 @@ namespace SecondBotEvents.Services
protected void BotClientRestart(object o, BotClientNotice e)
{
Console.WriteLine("Discord service [Avi link - Restarting]");
acceptChat = false;
getClient().Network.LoggedOut += BotLoggedOut;
getClient().Network.SimConnected += BotLoggedIn;
if (e.isRestart == false)
{
Console.WriteLine("Discord service [Avi link]");
AcceptEventsFromSL = false;
GetClient().Network.LoggedOut += BotLoggedOut;
GetClient().Self.ChatFromSimulator -= LocalChat;
GetClient().Self.IM -= BotImMessage;
GetClient().Network.SimConnected += BotLoggedIn;
}
}
protected void BotLoggedOut(object o, LoggedOutEventArgs e)
{
getClient().Network.SimConnected += BotLoggedIn;
acceptChat = false;
GetClient().Network.SimConnected += BotLoggedIn;
GetClient().Self.ChatFromSimulator -= LocalChat;
GetClient().Self.IM -= BotImMessage;
AcceptEventsFromSL = false;
Console.WriteLine("Discord service [Avi link - standby]");
}
protected void BotImMessage(object o, InstantMessageEventArgs e)
{
if(acceptChat == false)
if(AcceptEventsFromSL == false)
{
return;
}
@ -118,7 +189,7 @@ namespace SecondBotEvents.Services
{
case InstantMessageDialog.MessageFromObject:
{
objectChat(e.IM.FromAgentName, e.IM.Message);
ObjectIMChat(e.IM.FromAgentName, e.IM.Message);
break;
}
case InstantMessageDialog.MessageFromAgent: // shared with SessionSend
@ -126,10 +197,10 @@ namespace SecondBotEvents.Services
{
if(e.IM.GroupIM == false)
{
avatarChat(e.IM.FromAgentID, e.IM.FromAgentName, e.IM.Message);
AvatarIMChat(e.IM.FromAgentID, e.IM.FromAgentName, e.IM.Message);
break;
}
groupChat(e.IM.IMSessionID, e.IM.FromAgentName, e.IM.Message);
GroupIMChat(e.IM.IMSessionID, e.IM.FromAgentName, e.IM.Message);
break;
}
default:
@ -137,35 +208,228 @@ namespace SecondBotEvents.Services
break;
}
}
}
protected void groupChat(UUID group, string name, string message)
protected Dictionary<string, ulong> ChannelMap = new Dictionary<string, ulong>();
protected Dictionary<string, ulong> CategoryMap = new Dictionary<string, ulong>();
protected async void DoServerChannelSetup()
{
LogFormater.Info("Setting up channels");
Dictionary<string, string> WantedTextChannels = new Dictionary<string, string>
{
{ "status", StatusPrefill() },
{ "commands", "Send a command to the bot as if you are a master" },
{ "localchat", "Talk and view localchat" }
};
SocketGuild server = DiscordClient.GetGuild(myConfig.GetServerID());
foreach (ITextChannel channel in server.TextChannels)
{
if(WantedTextChannels.ContainsKey(channel.Name) == false)
{
continue;
}
if(channel.Name != "commands")
{
CleanChannel(channel);
}
WantedTextChannels.Remove(channel.Name);
ChannelMap.Add(channel.Name, channel.Id);
}
List<string> WantedCategoryChannels = new List<string>
{
"Bot",
"IM",
"Group"
};
foreach (ICategoryChannel category in server.CategoryChannels)
{
if (WantedCategoryChannels.Contains(category.Name) == false)
{
continue;
}
WantedCategoryChannels.Remove(category.Name);
CategoryMap.Add(category.Name, category.Id);
}
foreach(String a in WantedCategoryChannels)
{
RestCategoryChannel reply = await server.CreateCategoryChannelAsync(a);
CategoryMap.Add(a, reply.Id);
}
foreach(KeyValuePair<string,string> a in WantedTextChannels)
{
createTextChannel(a.Key, a.Value, "Bot");
}
DiscordServerChannelsSetup = true;
}
protected async void createTextChannel(string ChannelName, string ChannelInfo, string Group)
{
SocketGuild server = DiscordClient.GetGuild(myConfig.GetServerID());
IGuildChannel channel = await server.CreateTextChannelAsync(ChannelName, X => DiscordGetNewChannelProperies(X, ChannelName, ChannelInfo, Group));
ChannelMap.Add(channel.Name, channel.Id);
}
protected void DiscordGetNewChannelProperies(TextChannelProperties C, string channelname, string channeltopic, string catname)
{
if (catname != null)
{
if (CategoryMap.ContainsKey(catname) == true)
{
C.CategoryId = CategoryMap[catname];
}
}
C.Name = channelname;
C.Topic = channeltopic;
}
protected void GroupIMChat(UUID group, string name, string message)
{
}
protected void avatarChat(UUID avatar, string name, string message)
protected void AvatarIMChat(UUID avatar, string name, string message)
{
}
protected void ObjectIMChat(string objectName, string message)
{
}
protected void StatusChat(string message)
{
}
protected void objectChat(string objectName, string message)
readonly string[] hard_blocked_agents = new[] { "secondlife", "second life" };
protected void LocalChat(object o, ChatEventArgs e)
{
switch (e.Type)
{
case ChatType.OwnerSay:
case ChatType.Whisper:
case ChatType.Normal:
case ChatType.Shout:
case ChatType.RegionSayTo:
{
if (hard_blocked_agents.Contains(e.FromName.ToLowerInvariant()) == true)
{
break;
}
string source = ":person_bald:";
if (e.SourceType == ChatSourceType.Object)
{
source = ":diamond_shape_with_a_dot_inside:";
}
else if (e.SourceType == ChatSourceType.System)
{
source = ":comet:";
}
if(e.Type == ChatType.OwnerSay)
{
source = ":robot:";
}
else if (e.Type == ChatType.RegionSayTo)
{
source = ":dart:";
}
SendMessageToChannel("localchat", "Talk and view localchat", LogFormater.GetClockStamp()+" "+source + "" + e.FromName + ": " + e.Message);
break;
}
default:
{
break;
}
}
}
protected void statusChat(string message)
{
}
protected bool acceptMessageSigned(string message)
protected bool AcceptMessageSigned(string message)
{
return false;
}
public ulong SendMessageToChannel(string ChannelName, string ChannelInfo, string message)
{
return SendMessageToChannel(GetChannel(ChannelName, ChannelInfo, message), message);
}
public ulong SendMessageToChannel(ITextChannel channel, string message)
{
IMessage reply = channel.SendMessageAsync(message).GetAwaiter().GetResult();
return reply.Id;
}
protected ITextChannel GetChannel(string ChannelName, string ChannelInfo, string Group)
{
if(ChannelMap.ContainsKey(ChannelName) == true)
{
return (ITextChannel) DiscordClient.GetChannel(ChannelMap[ChannelName]);
}
createTextChannel(ChannelName, ChannelInfo, Group);
return (ITextChannel)DiscordClient.GetChannel(ChannelMap[ChannelName]);
}
protected ulong LastStatusMessageId = 0;
protected string LastMessageContent = "";
protected bool messageHasEndDot = false;
protected long LastUpdatedSystemStatus = 0;
protected async void SystemStatusEvent(object o, SystemStatusMessage e)
{
if(GetReadyForDiscordActions() == false)
{
return;
}
ITextChannel statusChannel = GetChannel("status", StatusPrefill(), "bot");
if ((e.changed == false) && (LastStatusMessageId != 0))
{
long dif = SecondbotHelpers.UnixTimeNow() - LastUpdatedSystemStatus;
if (dif < 15)
{
return;
}
LastUpdatedSystemStatus = SecondbotHelpers.UnixTimeNow();
if (messageHasEndDot == false)
{
await statusChannel.
ModifyMessageAsync(LastStatusMessageId, m => m.Content = LastMessageContent + ".");
messageHasEndDot = true;
return;
}
await statusChannel.
ModifyMessageAsync(LastStatusMessageId, m => m.Content = LastMessageContent);
messageHasEndDot = false;
return;
}
LastStatusMessageId = SendMessageToChannel(statusChannel, e.message);
LastMessageContent = e.message;
}
protected async void CleanChannel(ITextChannel channel)
{
IEnumerable<IMessage> messages = await channel.GetMessagesAsync(100, CacheMode.AllowDownload).FlattenAsync();
IEnumerable<IMessage> filtered = messages.Where(x => (DateTimeOffset.UtcNow - x.Timestamp).TotalDays <= 14);
if(filtered.Count() == 0)
{
return;
}
await channel.DeleteMessagesAsync(filtered);
}
protected string StatusPrefill()
{
return "State of the bot service";
}
protected void BotLoggedIn(object o, SimConnectedEventArgs e)
{
acceptChat = true;
getClient().Network.SimConnected -= BotLoggedIn;
getClient().Self.IM += BotImMessage;
AcceptEventsFromSL = true;
GetClient().Network.SimConnected -= BotLoggedIn;
GetClient().Self.IM += BotImMessage;
GetClient().Self.ChatFromSimulator += LocalChat;
Console.WriteLine("Discord service [Avi link - Active]");
}
@ -582,7 +846,7 @@ namespace SecondBotEvents.Services
}
public async Task<bool> addRoleToMember(string givenserverid, string givenroleid, string givenmemberid)
public async Task<bool> AddRoleToMember(string givenserverid, string givenroleid, string givenmemberid)
{
if (ulong.TryParse(givenserverid, out ulong serverid) == false)
{
@ -602,8 +866,6 @@ namespace SecondBotEvents.Services
await user.AddRoleAsync(role); // ? Irole seems to accept SocketRole ?
return true;
}
#endregion
}
}

View file

@ -21,7 +21,7 @@ namespace SecondBotEvents.Services
protected bool softDisable = false;
protected bool closeToHome = false;
public void markTeleport()
public void MarkTeleport()
{
softDisable = true;
}
@ -52,14 +52,14 @@ namespace SecondBotEvents.Services
{
BotAlertMessage(null, new AlertMessageEventArgs("restart", "999", new OpenMetaverse.StructuredData.OSDMap()));
}
if (getClient().Network.CurrentSim.Name == home.name)
if (GetClient().Network.CurrentSim.Name == home.name)
{
simNickname = "Home # ";
if (sitTarget != UUID.Zero)
{
if (getClient().Self.SittingOn == 0)
if (GetClient().Self.SittingOn == 0)
{
getClient().Self.RequestSit(sitTarget, Vector3.Zero);
GetClient().Self.RequestSit(sitTarget, Vector3.Zero);
}
}
if (myConfig.GetAtHomeSeekLocation() == true)
@ -68,7 +68,7 @@ namespace SecondBotEvents.Services
}
return;
}
else if (getClient().Network.CurrentSim.Name == backup.name)
else if (GetClient().Network.CurrentSim.Name == backup.name)
{
simNickname = "Backup # ";
if (myConfig.GetAtBackupSeekLocation() == true)
@ -92,7 +92,7 @@ namespace SecondBotEvents.Services
{
attemptedTeleportHome = true;
LogFormater.Info("Teleporting to home sim");
getClient().Self.Teleport(home.name, new Vector3(home.x, home.y, home.z), new Vector3(0, 0, 0));
GetClient().Self.Teleport(home.name, new Vector3(home.x, home.y, home.z), new Vector3(0, 0, 0));
return;
}
else if(attemptedTeleportBackup == false)
@ -100,7 +100,7 @@ namespace SecondBotEvents.Services
attemptedTeleportBackup = true;
LogFormater.Info("Teleporting to backup sim");
teleportActionLockout = SecondbotHelpers.UnixTimeNow();
getClient().Self.Teleport(backup.name, new Vector3(backup.x, backup.y, backup.z), new Vector3(0, 0, 0));
GetClient().Self.Teleport(backup.name, new Vector3(backup.x, backup.y, backup.z), new Vector3(0, 0, 0));
return;
}
attemptedTeleportHome = false;
@ -125,7 +125,7 @@ namespace SecondBotEvents.Services
{
return simNickname + "Waiting to evac";
}
else if(getClient().Self.SittingOn != 0)
else if(GetClient().Self.SittingOn != 0)
{
return simNickname + "Sitting on a thing";
}
@ -148,7 +148,7 @@ namespace SecondBotEvents.Services
protected void GetToPos(SimSlURL location)
{
if (getClient().Self.SittingOn != 0)
if (GetClient().Self.SittingOn != 0)
{
return;
}
@ -158,14 +158,14 @@ namespace SecondBotEvents.Services
return;
}
lastGotoAction = SecondbotHelpers.UnixTimeNow();
float dist = Vector3.Distance(new Vector3(location.x, location.y, location.z), getClient().Self.SimPosition);
float dist = Vector3.Distance(new Vector3(location.x, location.y, location.z), GetClient().Self.SimPosition);
closeToHome = false;
if (dist < 1)
{
closeToHome = true;
if (gotoPosAttemptedWalk == true)
{
getClient().Self.AutoPilotCancel();
GetClient().Self.AutoPilotCancel();
}
gotoPosAttemptedWalk = false;
gotoPosAttemptedTp = false;
@ -174,16 +174,16 @@ namespace SecondBotEvents.Services
if ((gotoPosAttemptedWalk == false) && (dist < 16))
{
gotoPosAttemptedWalk = true;
getClient().Self.AutoPilotLocal(location.x, location.y, getClient().Self.SimPosition.Z);
GetClient().Self.AutoPilotLocal(location.x, location.y, GetClient().Self.SimPosition.Z);
return;
}
if (gotoPosAttemptedTp == false)
{
gotoPosAttemptedTp = true;
getClient().Self.Teleport(location.name, new Vector3(location.x, location.y, location.z), new Vector3(0, 0, 0));
GetClient().Self.Teleport(location.name, new Vector3(location.x, location.y, location.z), new Vector3(0, 0, 0));
return;
}
getClient().Self.AutoPilotCancel();
GetClient().Self.AutoPilotCancel();
gotoPosAttemptedWalk = false;
}
@ -217,24 +217,24 @@ namespace SecondBotEvents.Services
return;
}
evacWanted = false;
if (getClient().Network.CurrentSim.Name == home.name)
if (GetClient().Network.CurrentSim.Name == home.name)
{
LogFormater.Info("Teleporting to backup sim to avoid restart");
getClient().Self.Teleport(backup.name, new Vector3(backup.x, backup.y, backup.z), new Vector3(0, 0, 0));
GetClient().Self.Teleport(backup.name, new Vector3(backup.x, backup.y, backup.z), new Vector3(0, 0, 0));
return;
}
LogFormater.Info("Teleporting to home sim to avoid restart");
getClient().Self.Teleport(home.name, new Vector3(home.x, home.y, home.z), new Vector3(0, 0, 0));
GetClient().Self.Teleport(home.name, new Vector3(home.x, home.y, home.z), new Vector3(0, 0, 0));
}
protected void BotClientRestart(object o, BotClientNotice e)
{
botConnected = false;
Console.WriteLine("Homebound Service [Attached to new client]");
getClient().Network.LoggedOut += BotLoggedOut;
getClient().Network.SimConnected += BotLoggedIn;
getClient().Self.AlertMessage += BotAlertMessage;
getClient().Network.SimChanged += BotChangedSim;
GetClient().Network.LoggedOut += BotLoggedOut;
GetClient().Network.SimConnected += BotLoggedIn;
GetClient().Self.AlertMessage += BotAlertMessage;
GetClient().Network.SimChanged += BotChangedSim;
}
protected void BotLoggedOut(object o, LoggedOutEventArgs e)
@ -270,13 +270,13 @@ namespace SecondBotEvents.Services
public override void Stop()
{
master.BotClientNoticeEvent -= BotClientRestart;
if (master.botClient != null)
if (master.BotClient != null)
{
if (getClient() != null)
if (GetClient() != null)
{
getClient().Network.SimConnected -= BotLoggedIn;
getClient().Self.AlertMessage -= BotAlertMessage;
getClient().Network.SimChanged -= BotChangedSim;
GetClient().Network.SimConnected -= BotLoggedIn;
GetClient().Self.AlertMessage -= BotAlertMessage;
GetClient().Network.SimChanged -= BotChangedSim;
}
}
Console.WriteLine("Homebound Service [Stopping]");

View file

@ -58,20 +58,20 @@ namespace SecondBotEvents.Services
{
acceptBotCommands = false;
Console.WriteLine("HTTP service [Attached to new client]");
getClient().Network.LoggedOut += BotLoggedOut;
getClient().Network.SimConnected += BotLoggedIn;
GetClient().Network.LoggedOut += BotLoggedOut;
GetClient().Network.SimConnected += BotLoggedIn;
}
protected void BotLoggedOut(object o, LoggedOutEventArgs e)
{
acceptBotCommands = false;
getClient().Network.SimConnected += BotLoggedIn;
GetClient().Network.SimConnected += BotLoggedIn;
Console.WriteLine("HTTP service [Bot commands disabled]");
}
protected void BotLoggedIn(object o, SimConnectedEventArgs e)
{
getClient().Network.SimConnected -= BotLoggedIn;
GetClient().Network.SimConnected -= BotLoggedIn;
acceptBotCommands = true;
CreateWebServer();
}
@ -128,35 +128,35 @@ namespace SecondBotEvents.Services
protected UUID avataruuid = UUID.Zero;
protected Parcel targetparcel = null;
protected GridClient getClient()
protected GridClient GetClient()
{
return master.botClient.client;
return master.BotClient.client;
}
protected KeyValuePair<bool, string> SetupCurrentParcel()
{
if (getClient().Network.CurrentSim == null)
if (GetClient().Network.CurrentSim == null)
{
return new KeyValuePair<bool, string>(false, "Error not in a sim");
}
int localid = getClient().Parcels.GetParcelLocalID(getClient().Network.CurrentSim, getClient().Self.SimPosition);
if (getClient().Network.CurrentSim.Parcels.ContainsKey(localid) == false)
int localid = GetClient().Parcels.GetParcelLocalID(GetClient().Network.CurrentSim, GetClient().Self.SimPosition);
if (GetClient().Network.CurrentSim.Parcels.ContainsKey(localid) == false)
{
Thread.Sleep(2000);
localid = getClient().Parcels.GetParcelLocalID(getClient().Network.CurrentSim, getClient().Self.SimPosition);
if (getClient().Network.CurrentSim.Parcels.ContainsKey(localid) == false)
localid = GetClient().Parcels.GetParcelLocalID(GetClient().Network.CurrentSim, GetClient().Self.SimPosition);
if (GetClient().Network.CurrentSim.Parcels.ContainsKey(localid) == false)
{
return new KeyValuePair<bool, string>(false, "Parcel data not ready");
}
}
targetparcel = getClient().Network.CurrentSim.Parcels[localid];
targetparcel = GetClient().Network.CurrentSim.Parcels[localid];
return new KeyValuePair<bool, string>(true, "");
}
protected void ProcessAvatar(string avatar)
{
avataruuid = UUID.Zero;
string UUIDfetch = master.DataStoreService.getAvatarUUID(avatar);
string UUIDfetch = master.DataStoreService.GetAvatarUUID(avatar);
if (UUIDfetch != "lookup")
{
UUID.TryParse(UUIDfetch, out avataruuid);
@ -165,37 +165,37 @@ namespace SecondBotEvents.Services
protected object BasicReply(string input)
{
return BasicReply(input, new string[] { }, getCallingCommand());
return BasicReply(input, new string[] { }, GetCallingCommand());
}
protected object BasicReply(string input, string[] args)
{
return BasicReply(input, args, getCallingCommand());
return BasicReply(input, args, GetCallingCommand());
}
protected object BasicReply(string input, string[] args, string command)
{
master.DataStoreService.addCommandToHistory(true, command, args);
master.DataStoreService.AddCommandToHistory(true, command, args);
return new { reply = input, status = false };
}
protected object Failure(string input, string command, string[] args, string whyfailed)
{
master.DataStoreService.addCommandToHistory(false, command, args);
master.DataStoreService.AddCommandToHistory(false, command, args);
return new { reply = input, status = false };
}
protected object Failure(string input, string[] args)
{
return Failure(input, getCallingCommand(), args, null);
return Failure(input, GetCallingCommand(), args, null);
}
protected object Failure(string input)
{
return Failure(input, getCallingCommand(), new string[] { }, null);
return Failure(input, GetCallingCommand(), new string[] { }, null);
}
protected string getCallingCommand()
protected string GetCallingCommand()
{
return (new System.Diagnostics.StackTrace()).GetFrame(2).GetMethod().Name;
}
@ -268,9 +268,8 @@ namespace SecondBotEvents.Services
[ArgHints("unixtime", "the time you signed the command")]
[Route(HttpVerbs.Post, "/Run")]
public string Run([FormField] string commandName, [FormField] string? args, [FormField] string signing, [FormField] string unixtime)
public string Run([FormField] string commandName, [FormField] string args, [FormField] string signing, [FormField] string unixtime)
{
string input = commandName;
string[] myArgs = new string[] { };
if(args != null)
{
@ -289,7 +288,7 @@ namespace SecondBotEvents.Services
{
return "Command request rejected";
}
return JsonConvert.SerializeObject(master.CommandsService.runCommand(C));
return JsonConvert.SerializeObject(master.CommandsService.RunCommand(C));
}
}
}

View file

@ -39,27 +39,27 @@ namespace SecondBotEvents.Services
return "Active";
}
protected bool processRequest(bool enabledByConfig, string avatarName, string sourceName)
protected bool ProcessRequest(bool enabledByConfig, string avatarName, string sourceName)
{
if(myConfig.GetEnabled() == false)
{
jsonOuput(false, sourceName, avatarName, "Interactions hooks disabled");
JsonOuput(false, sourceName, avatarName, "Interactions hooks disabled");
return false;
}
if (enabledByConfig == false)
{
jsonOuput(false, sourceName, avatarName, "disabled by config");
JsonOuput(false, sourceName, avatarName, "disabled by config");
return false;
}
if (master.CommandsService.myConfig.GetEnableMasterControls() == false)
{
// master avatars list is not enabled. unable to continue
jsonOuput(false, sourceName, avatarName, "masters AV list is disabled");
JsonOuput(false, sourceName, avatarName, "masters AV list is disabled");
return false;
}
if (master.CommandsService.myConfig.GetMastersCSV().Contains(avatarName) == false)
{
jsonOuput(false, sourceName, avatarName, "Not from accepted master");
JsonOuput(false, sourceName, avatarName, "Not from accepted master");
return false;
}
return true;
@ -69,20 +69,19 @@ namespace SecondBotEvents.Services
{
botConnected = false;
Console.WriteLine("Interaction Service [Attached to new client]");
getClient().Network.LoggedOut += BotLoggedOut;
getClient().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)
protected void JsonOuput(bool status, string eventype, string from, string why="", Dictionary<string, string> setMisc = null)
{
if (myConfig.GetEnableJsonOutputEvents() == false)
{
return;
}
master.CommandsService.SmartCommandReply(
status,
myConfig.GetJsonOutputEventsTarget(),
JsonConvert.SerializeObject(new interactionEvent(from, eventype, status, why, setMisc)),
JsonConvert.SerializeObject(new InteractionEvent(from, eventype, status, why, setMisc)),
"interactions"
);
}
@ -100,83 +99,85 @@ namespace SecondBotEvents.Services
mode = "Teleport Av to Bot";
markTeleport = false;
}
if (processRequest(myConfig.GetAcceptTeleports(), e.IM.FromAgentName, mode) == false)
if (ProcessRequest(myConfig.GetAcceptTeleports(), e.IM.FromAgentName, mode) == false)
{
// rejected requests
if (e.IM.Dialog != InstantMessageDialog.RequestLure)
{
return;
}
getClient().Self.TeleportLureRespond(e.IM.FromAgentID, e.IM.IMSessionID, false);
GetClient().Self.TeleportLureRespond(e.IM.FromAgentID, e.IM.IMSessionID, false);
return;
}
if (markTeleport == true)
{
master.HomeboundService.markTeleport();
master.HomeboundService.MarkTeleport();
}
jsonOuput(true, mode, e.IM.FromAgentName);
JsonOuput(true, mode, e.IM.FromAgentName);
if (e.IM.Dialog == InstantMessageDialog.RequestLure)
{
getClient().Self.SendTeleportLure(e.IM.FromAgentID);
GetClient().Self.SendTeleportLure(e.IM.FromAgentID);
return;
}
getClient().Self.TeleportLureRespond(e.IM.FromAgentID, e.IM.IMSessionID, true);
GetClient().Self.TeleportLureRespond(e.IM.FromAgentID, e.IM.IMSessionID, true);
}
protected void BotGroupInviteOffer(object o, GroupInvitationEventArgs e)
{
if (processRequest(myConfig.GetAcceptGroupInvites(), e.FromName, "GroupInvite") == false)
if (ProcessRequest(myConfig.GetAcceptGroupInvites(), e.FromName, "GroupInvite") == false)
{
return;
}
e.Accept = true;
jsonOuput(true, "GroupInvite", e.FromName);
JsonOuput(true, "GroupInvite", e.FromName);
}
protected void BotInventoryOffer(object o, InventoryObjectOfferedEventArgs e)
{
if(processRequest(myConfig.GetAcceptInventory(),e.Offer.FromAgentName, "InventoryUpdate") == false)
if(ProcessRequest(myConfig.GetAcceptInventory(),e.Offer.FromAgentName, "InventoryUpdate") == false)
{
return;
}
e.Accept = true;
Dictionary<string, string> details = new Dictionary<string, string>();
details.Add("itemuuid", e.ObjectID.ToString());
details.Add("itemtype", e.AssetType.ToString());
InventoryItem itm = getClient().Inventory.FetchItem(e.ObjectID, getClient().Self.AgentID, 2000);
Dictionary<string, string> details = new Dictionary<string, string>
{
{ "itemuuid", e.ObjectID.ToString() },
{ "itemtype", e.AssetType.ToString() }
};
InventoryItem itm = GetClient().Inventory.FetchItem(e.ObjectID, GetClient().Self.AgentID, 2000);
if(itm != null)
{
details.Add("itemname", itm.Name);
}
jsonOuput(true, "InventoryUpdate", e.Offer.FromAgentName, "see misc", details);
JsonOuput(true, "InventoryUpdate", e.Offer.FromAgentName, "see misc", details);
}
protected void BotFriendRequested(object o, FriendshipOfferedEventArgs e)
{
if (processRequest(myConfig.GetAcceptGroupInvites(), e.AgentName, "FriendRequest") == false)
if (ProcessRequest(myConfig.GetAcceptGroupInvites(), e.AgentName, "FriendRequest") == false)
{
return;
}
getClient().Friends.AcceptFriendship(e.AgentID, e.SessionID);
jsonOuput(true, "FriendRequest", e.AgentName);
GetClient().Friends.AcceptFriendship(e.AgentID, e.SessionID);
JsonOuput(true, "FriendRequest", e.AgentName);
}
protected void BotLoggedOut(object o, LoggedOutEventArgs e)
{
botConnected = false;
getClient().Network.SimConnected += BotLoggedIn;
GetClient().Network.SimConnected += BotLoggedIn;
Console.WriteLine("Interaction Service [Standby]");
}
protected void BotLoggedIn(object o, SimConnectedEventArgs e)
{
getClient().Network.SimConnected -= BotLoggedIn;
getClient().Friends.FriendshipOffered += BotFriendRequested;
getClient().Inventory.InventoryObjectOffered += BotInventoryOffer;
getClient().Groups.GroupInvitation += BotGroupInviteOffer;
getClient().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]");
}
@ -200,27 +201,27 @@ namespace SecondBotEvents.Services
return;
}
master.BotClientNoticeEvent -= BotClientRestart;
if (master.botClient != null)
if (master.BotClient != null)
{
if (getClient() != null)
if (GetClient() != null)
{
getClient().Friends.FriendshipOffered -= BotFriendRequested;
getClient().Inventory.InventoryObjectOffered -= BotInventoryOffer;
getClient().Groups.GroupInvitation -= BotGroupInviteOffer;
GetClient().Friends.FriendshipOffered -= BotFriendRequested;
GetClient().Inventory.InventoryObjectOffered -= BotInventoryOffer;
GetClient().Groups.GroupInvitation -= BotGroupInviteOffer;
}
}
Console.WriteLine("Interaction Service [Stopping]");
}
}
public class interactionEvent
public class InteractionEvent
{
public string from = "?";
public string eventType = "?";
public bool accepted = false;
public string info = "";
public Dictionary<string, string> misc = new Dictionary<string, string>();
public interactionEvent(string setFrom, string setType, bool setAccepted, string setInfo, Dictionary<string, string> setMisc = null)
public InteractionEvent(string setFrom, string setType, bool setAccepted, string setInfo, Dictionary<string, string> setMisc = null)
{
accepted = setAccepted;
from = setFrom;

View file

@ -13,9 +13,9 @@ namespace SecondBotEvents.Services
master = setMaster;
}
protected GridClient getClient()
protected GridClient GetClient()
{
return master.botClient.client;
return master.BotClient.client;
}
public virtual string Status()
{

View file

@ -54,7 +54,7 @@ namespace SecondBotEvents
return Debug(message, true);
}
private static string Add(string message, ConsoleLogLogLevel Level, bool send_to_console = true)
public static string GetClockStamp()
{
var date = DateTime.Now;
StringBuilder n = new StringBuilder();
@ -71,6 +71,14 @@ namespace SecondBotEvents
}
n.Append(date.Minute.ToString());
n.Append("] ");
return n.ToString();
}
private static string Add(string message, ConsoleLogLogLevel Level, bool send_to_console = true)
{
StringBuilder n = new StringBuilder();
n.Append(GetClockStamp());
switch (Level)
{
#if DEBUG