コード例 #1
0
 public override string Process(RestBot b, Dictionary<string, string> Parameters)
 {
     UUID groupUUID;
     DebugUtilities.WriteDebug("TR - Entering group key parser");
     try
     {
         bool check = false;
         if ( Parameters.ContainsKey("key") ) {
             DebugUtilities.WriteDebug("TR - Attempting to parse from POST");
             check = UUID.TryParse(Parameters["key"].ToString().Replace("_"," "), out groupUUID);
             DebugUtilities.WriteDebug("TR - Succesfully parsed POST");
         } else {
             return "<error>arguments</error>";
         }
         if ( check ) {
             DebugUtilities.WriteDebug("TR - Activating group");
             string response = activateGroup(b, groupUUID);
             DebugUtilities.WriteDebug("TR - Complete");
             return "<active>" + response.Trim() + "</active>\n";
         } else {
             return "<error>parsekey</error>";
         }
     }
     catch ( Exception e )
     {
         DebugUtilities.WriteError(e.Message);
         return "<error>parsekey</error>";
     }
 }
コード例 #2
0
        /// <summary>
        /// Internal method to send a message to a group the 'bot is in.
        /// </summary>
        /// <param name="b">A currently active RestBot</param>
        /// <param name="groupUUID">Group UUID</param>
        /// <param name="message">Message to send to the group IM</param>
        /// <returns>String with "message sent", if successful; "timeout" otherwise</returns>
        private string sendIMGroup(RestBot b, UUID groupUUID, string message)
        {
            DebugUtilities.WriteInfo(session.ToString() + " " + MethodName + " Sending message '" + message + "' to group UUID " + groupUUID.ToString());
            b.Client.Self.GroupChatJoined += Self_GroupChatJoined;

            if (!b.Client.Self.GroupChatSessions.ContainsKey(groupUUID))
            {
                WaitForSessionStart.Reset();
                b.Client.Self.RequestJoinGroupChat(groupUUID);
            }
            else
            {
                WaitForSessionStart.Set();
            }

            if (WaitForSessionStart.WaitOne(20000, false))
            {
                b.Client.Self.InstantMessageGroup(groupUUID, message);
            }
            else
            {
                DebugUtilities.WriteInfo(session.ToString() + " " + MethodName + " Timeout waiting for group session start");
                return("timeout");
            }

            b.Client.Self.GroupChatJoined -= Self_GroupChatJoined;
            DebugUtilities.WriteInfo(session.ToString() + " " + MethodName + " Instant Messaged group " + groupUUID.ToString() + " with message: " + message);

            return("message sent");
        }
コード例 #3
0
        /// <summary>
        /// Returns the UUID of a group, given its name
        /// </summary>
        /// <param name="b">A currently active RestBot</param>
        /// <param name="groupName">Group name to search for</param>
        /// <returns>UUID for the group name, if it exists; UUID.Zero otherwise</returns>
        public UUID GroupName2UUID(RestBot b, String groupName)
        {
            UUID tryUUID;

            if (UUID.TryParse(groupName, out tryUUID))
            {
                return(tryUUID);
            }
            if (null == GroupsCache)
            {
                ReloadGroupsCache(b);
                if (null == GroupsCache)
                {
                    return(UUID.Zero);
                }
            }
            lock (GroupsCache) {
                if (GroupsCache.Count > 0)
                {
                    foreach (Group currentGroup in GroupsCache.Values)
                    {
                        if (currentGroup.Name.ToLower() == groupName.ToLower())
                        {
                            return(currentGroup.ID);
                        }
                    }
                }
            }
            return(UUID.Zero);
        }
コード例 #4
0
ファイル: Utilities.cs プロジェクト: GwynethLlewelyn/restbot
        getKey(RestBot b, String avatarFirstName, String avatarLastName)
        {
            String avatarFullName =
                avatarFirstName.ToString() + " " + avatarLastName.ToString();

            return(getKey(b, avatarFullName));            // it will be set to lowercase by getKey() (gwyneth 20220126).
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: GwynethLlewelyn/restbot
        }         // end ParseArguments

        /// <summary>
        /// Register all RestPlugins to the RestBot static plugin dictionary
        /// </summary>
        /// <param name="assembly">Given assembly to search for</param>
        static void RegisterAllCommands(Assembly assembly)
        {
            foreach (Type t in assembly.GetTypes())
            {
                try
                {
                    if (t.IsSubclassOf(typeof(RestPlugin)))
                    {
                        ConstructorInfo?info = t.GetConstructor(Type.EmptyTypes); // ask for parameter-less constructor for this class, if it exists (gwyneth 20220425)
                        if (info == null)
                        {
                            // Not a serious warning, some plugins might be incorrectly configured but still work well
                            DebugUtilities.WriteWarning($"Couldn't get constructor without parameters for plugin {t.GetType().Name}!");
                        }
                        else
                        {
                            RestPlugin plugin = (RestPlugin)info.Invoke(new object[0]);
                            RestBot.AddPlugin(plugin);
                        }
                    }
                }
                catch (Exception e)
                {
                    DebugUtilities.WriteError(e.Message);
                }
            }
        }
コード例 #6
0
        Process(RestBot b, Dictionary <string, string> Parameters)
        {
            UUID agentKey;

            try
            {
                bool check = false;
                if (Parameters.ContainsKey("key"))
                {
                    check =
                        UUID
                        .TryParse(Parameters["key"].ToString().Replace("_", " "),
                                  out agentKey);
                }
                else
                {
                    return("<error>arguments</error>");
                }
                if (check)
                {
                    bool response = getOnline(b, agentKey);
                    return($"<online>{response.ToString()}</online>");
                }
                else
                {
                    return("<error>unknown</error>");
                }
            }
            catch (Exception e)
            {
                DebugUtilities.WriteError(e.Message);
                return("<error>parsekey</error>");
            }
        }
コード例 #7
0
        // Accessory functions
        /// <summary>
        /// Fetch an inventory item
        /// </summary>
        /// <param name="b">RESTbot object</param>
        /// <param name="itemID">UUID of inventory item to fetch</param>
        /// <returns>An InventoryItem object if it exists, null if not</returns>
        /// <remarks>C# 8+ is stricter when returning nulls, thus the <c>InventoryItem?</c> method type.</remarks>
        private InventoryItem?FetchItem(RestBot b, UUID itemID)
        {
            InventoryItem? fetchItem      = null;
            AutoResetEvent fetchItemEvent = new AutoResetEvent(false);

            EventHandler <ItemReceivedEventArgs> itemReceivedCallback =
                delegate(object?sender, ItemReceivedEventArgs e)
            {
                if (e.Item.UUID == itemID)
                {
                    fetchItem = e.Item;
                    fetchItemEvent.Set();
                }
            };

            b.Client.Inventory.ItemReceived += itemReceivedCallback;

            b.Client.Inventory.RequestFetchInventory(itemID, b.Client.Self.AgentID);

            fetchItemEvent.WaitOne(INVENTORY_FETCH_TIMEOUT, false);

            b.Client.Inventory.ItemReceived -= itemReceivedCallback;

            return(fetchItem);
        }
コード例 #8
0
        private void PrintFolder(RestBot b, InventoryFolder f, StringBuilder result)
        {
            List <InventoryBase>?contents =
                Manager?
                .FolderContents(f.UUID,
                                b.Client.Self.AgentID,
                                true,
                                true,
                                InventorySortOrder.ByName,
                                3000);

            if (contents != null)
            {
                foreach (InventoryBase i in contents)
                {
                    result
                    .AppendFormat("<item><name>{0}</name><itemid>{1}</itemid></item>",
                                  i.Name,
                                  i.UUID);
                    if (i is InventoryFolder)
                    {
                        InventoryFolder folder = (InventoryFolder)i;
                        PrintFolder(b, folder, result);
                    }
                }
            }
        }
コード例 #9
0
        public override void Initialize(RestBot bot)
        {
            session = bot.sessionid;
            me = bot;
            DebugUtilities.WriteDebug(session + " " + MethodName + " startup");

            base.Initialize(bot);
        }
コード例 #10
0
        /// <summary>
        /// Initialises the plugin.
        /// </summary>
        /// <param name="bot">A currently active RestBot</param>
        /// <returns>void</returns>
        public override void Initialize(RestBot bot)
        {
            session = bot.sessionid;
            DebugUtilities.WriteDebug($"{session} {MethodName} startup");

            // bot.Client.Network.RegisterCallback(PacketType.AvatarPropertiesReply, new NetworkManager.PacketCallback(AvatarPropertiesReply)); // obsolete
            bot.Client.Avatars.AvatarPropertiesReply += AvatarPropertiesReply;
        }
コード例 #11
0
        /// <summary>
        /// Initialises the plugin.
        /// </summary>
        /// <param name="bot">A currently active RestBot</param>
        /// <returns>void</returns>
        public override void Initialize(RestBot bot)
        {
            session = bot.sessionid;
            DebugUtilities.WriteDebug($"{session} {MethodName} startup");

            // bot.Client.Network.RegisterCallback(PacketType.DirPeopleReply, new NetworkManager.PacketCallback(Avatars_OnDirPeopleReply)); // obsolete, now uses DirectoryManager
            bot.Client.Directory.DirPeopleReply += Avatars_OnDirPeopleReply;
        }
コード例 #12
0
        public override string Process(RestBot b, Dictionary<string, string> Paramaters)
        {
            b.Client.Settings.ALWAYS_DECODE_OBJECTS=true;

            string dilation = b.Client.Network.CurrentSim.Stats.Dilation.ToString();
            b.Client.Settings.ALWAYS_DECODE_OBJECTS = false;
            return("<dilation>" + dilation + "</dilation>\n");
        }
コード例 #13
0
        public override void Initialize(RestBot bot)
        {
            session = bot.sessionid;
            me      = bot;
            DebugUtilities.WriteDebug($"{session} {MethodName} startup");

            base.Initialize(bot);
        }
コード例 #14
0
        /// <summary>
        /// Initialises the plugin.
        /// </summary>
        /// <param name="bot">A currently active RestBot</param>
        /// <returns>void</returns>
        public override void Initialize(RestBot bot)
        {
            session = bot.sessionid;
            DebugUtilities.WriteDebug($"{session} {MethodName} startup");

            // bot.Client.Avatars.OnAvatarProperties += new AvatarManager.AvatarPropertiesCallback(Avatars_OnAvatarProperties); // obsolete
            bot.Client.Avatars.AvatarPropertiesReply += Avatars_OnAvatarProperties;
        }
コード例 #15
0
 /// <summary>
 /// Clears the group cache for this 'bot, and reloads it with all
 /// the current groups that this 'bot is in.
 /// </summary>
 /// <param name="b">A currently active RestBot</param>
 /// <returns>void</returns>
 public void ReloadGroupsCache(RestBot b)
 {
     b.Client.Groups.CurrentGroups += Groups_CurrentGroups;
     b.Client.Groups.RequestCurrentGroups();
     GroupsEvent.WaitOne(10000, false);
     b.Client.Groups.CurrentGroups -= Groups_CurrentGroups;
     GroupsEvent.Reset();
 }
コード例 #16
0
        /// <summary>
        /// Initialises the plugin.
        /// </summary>
        /// <param name="bot">A currently active RestBot</param>
        public override void Initialize(RestBot bot)
        {
            session = bot.sessionid;                    // why is this saved? It's never used... (gwyneth 20220213)
            me      = bot;
            DebugUtilities.WriteDebug($"{session} {MethodName} startup");

            base.Initialize(bot);               // wtf is this for? (gwyneth 20220212)
        }
コード例 #17
0
		/// <summary>
		/// Initialises the plugin.
		/// </summary>
		/// <param name="bot">A currently active RestBot</param>
		public override void Initialize(RestBot bot)
		{
			// ListenCallbacks = new Dictionary<UUID, String>();
			session = bot.sessionid;
			DebugUtilities.WriteDebug($"{session} {MethodName} startup");

			base.Initialize(bot);
		}
コード例 #18
0
        Process(RestBot b, Dictionary <string, string> Parameters)
        {
            UUID folderID;

            DebugUtilities.WriteDebug("Entering folder key parser");
            try
            {
                bool check = false;
                if (Parameters.ContainsKey("key"))
                {
                    DebugUtilities.WriteDebug("Attempting to parse from POST");
                    check =
                        UUID
                        .TryParse(Parameters["key"].ToString().Replace("_", " "),
                                  out folderID);
                    DebugUtilities.WriteDebug("Succesfully parsed POST");
                }
                else
                {
                    folderID = UUID.Zero;                     // start with root folder
                    check    = true;
                }

                if (
                    check                     // means that we have a correctly parsed key OR no key
                    )
                //  which is fine too (attempts root folder)
                {
                    DebugUtilities.WriteDebug("Entering loop");

                    Manager   = b.Client.Inventory;
                    Inventory = Manager.Store;

                    StringBuilder response = new StringBuilder();

                    InventoryFolder startFolder = new InventoryFolder(folderID);

                    if (folderID == UUID.Zero)
                    {
                        startFolder = Inventory.RootFolder;
                    }

                    PrintFolder(b, startFolder, response);
                    DebugUtilities.WriteDebug("Complete");

                    return($"<inventory>{response}</inventory>");
                }
                else
                {
                    return($"<error>{MethodName}: parsekey</error>");
                }
            }
            catch (Exception e)
            {
                DebugUtilities.WriteError(e.Message);
                return($"<error>{MethodName}: {e.Message}</error>");
            }
        }
コード例 #19
0
ファイル: Utilities.cs プロジェクト: GwynethLlewelyn/restbot
        }         // end Avatars_OnDirPeopleReply()

        /// <summary>
        /// name2key (avatar name to UUID)
        /// </summary>
        /// <param name="b">RESTbot object</param>
        /// <param name="name">Name of avatar to check</param>
        /// <returns>UUID of corresponding avatar, if it exists</returns>
        public static UUID getKey(RestBot b, String name)
        {
            DebugUtilities.WriteInfo("getKey(): Looking up key for " + name);
            b.Client.Directory.DirPeopleReply += Avatars_OnDirPeopleReply;
            name = name.ToLower();
            DebugUtilities.WriteDebug("getKey(): Looking up: " + name);
            DebugUtilities
            .WriteDebug("getKey(): Key not in cache, requesting directory lookup");                     // how do you know? (gwyneth 20220128)
            lock (KeyLookupEvents)
            {
                KeyLookupEvents.Add(name, new AutoResetEvent(false));
            }
            DebugUtilities
            .WriteDebug("getKey(): Lookup Event added, KeyLookupEvents now has a total of " +
                        KeyLookupEvents.Count.ToString() +
                        " entries");
            DirFindQueryPacket find = new DirFindQueryPacket();

            find.AgentData.AgentID    = b.Client.Self.AgentID;          // was Network and not Self
            find.AgentData.SessionID  = b.Client.Self.SessionID;
            find.QueryData.QueryFlags = 1;

            //find.QueryData.QueryText = Helpers.StringToField(name);
            find.QueryData.QueryText  = Utils.StringToBytes(name);
            find.QueryData.QueryID    = new UUID("00000000000000000000000000000001");
            find.QueryData.QueryStart = 0;

            b.Client.Network.SendPacket((Packet)find);
            DebugUtilities
            .WriteDebug("getKey(): Packet sent - KLE has " +
                        KeyLookupEvents.Count.ToString() +
                        " entries.. now waiting");
            if (!KeyLookupEvents[name].WaitOne(15000, true))
            {
                DebugUtilities
                .WriteWarning("getKey(): timed out on avatar name lookup for " +
                              name);
            }
            DebugUtilities.WriteDebug("getKey(): Waiting done!");
            lock (KeyLookupEvents)
            {
                KeyLookupEvents.Remove(name);
            }
            DebugUtilities
            .WriteDebug($"getKey(): Done with KLE, now has {KeyLookupEvents.Count.ToString()} entries");
            UUID response = new UUID();             // hopefully this sets the response to UUID.Zero first... (gwyneth 20220128)

            if (avatarKeys.ContainsKey(name))
            {
                response = avatarKeys[name];
                lock (avatarKeys)
                {
                    avatarKeys.Remove(name);
                }
            }
            b.Client.Directory.DirPeopleReply -= Avatars_OnDirPeopleReply;
            return(response);
        }         // end getKey()
コード例 #20
0
        /// <summary>
        /// Handler event for this plugin.
        /// </summary>
        /// <param name="b">A currently active RestBot</param>
        /// <param name="Parameters">not used</param>
        public override string Process(RestBot b, Dictionary <string, string> Parameters)
        {
            b.Client.Settings.ALWAYS_DECODE_OBJECTS = true;

            string dilation = b.Client.Network.CurrentSim.Stats.Dilation.ToString();

            b.Client.Settings.ALWAYS_DECODE_OBJECTS = false;
            return($"<{MethodName}>{dilation}</{MethodName}>");
        }
コード例 #21
0
        /// <summary>
        /// Look up the profile for a UUID
        /// </summary>
        /// <param name="b">RESTbot object</param>
        /// <param name="key">UUID of avatar to retrieve profile</param>
        /// <returns>Full profile as a string, or null if profile is empty/does not exist</returns>
        /// <remarks>C# 8+ is stricter when returning nulls, thus the <c>string?</c> method type.</remarks>
        public string?getProfile(RestBot b, UUID key)
        {
            DebugUtilities
            .WriteInfo(session +
                       " " +
                       MethodName +
                       " Looking up profile for " +
                       key.ToString());

            lock (ProfileLookupEvents)
            {
                ProfileLookupEvents.Add(key, new AutoResetEvent(false));
            }
            b.Client.Avatars.RequestAvatarProperties(key);

            ProfileLookupEvents[key].WaitOne(15000, true);

            lock (ProfileLookupEvents)
            {
                ProfileLookupEvents.Remove(key);
            }
            if (avatarProfile.ContainsKey(key))
            {
                Avatar.AvatarProperties p = avatarProfile[key];
                string response           = $@"
	<profile>
		<publish>{p.AllowPublish.ToString()}</publish>
		<firstlife>
			<text>
				{p.FirstLifeText.Replace(">", "%3C").Replace("<", "%3E")}
			</text>
			<image>{p.FirstLifeImage.ToString()}</image>
		</firstlife>
		<partner>{p.Partner.ToString()}</partner>
		<born>{p.BornOn}</born>
		<about>
			{p.AboutText.Replace(">", "%3C").Replace("<", "%3E")}
		</about>
		<charter>{p.CharterMember}</charter>
		<profileimage>{p.ProfileImage.ToString()}</profileimage>
		<mature>{p.MaturePublish.ToString()}</mature>
		<identified>{p.Identified.ToString()}</identified>
		<transacted>{p.Transacted.ToString()}</transacted>
		<url>{p.ProfileURL}</url>
	</profile>"    ;
                lock (avatarProfile)
                {
                    avatarProfile.Remove(key);
                }
                return(response);
            }
            else
            {
                return(null);
            }
        }
コード例 #22
0
ファイル: Program.cs プロジェクト: GwynethLlewelyn/restbot
 /// <summary>
 /// Grab all the subclass type definitions of StatefulPlugin out of an assembly
 /// </summary>
 /// <param name="assembly">Given assembly to search for</param>
 static void RegisterAllStatefulPlugins(Assembly assembly)
 {
     foreach (Type t in assembly.GetTypes())
     {
         if (t.IsSubclassOf(typeof(StatefulPlugin)))
         {
             RestBot.AddStatefulPluginDefinition(t);
         }
     }
 }
コード例 #23
0
        /// <summary>
        /// Handler event for this plugin.
        /// </summary>
        /// <param name="b">A currently active RestBot</param>
        /// <param name="Parameters">A dictionary containing the group UUID and the message to send to group IM</param>
        /// <returns>XML with information on the sent group IM message, if successful;
        /// XML error otherwise</returns>
        public override string Process(RestBot b, Dictionary <string, string> Parameters)
        {
            UUID   groupUUID;
            string message;

            try
            {
                bool check = false;
                if (Parameters.ContainsKey("key"))
                {
                    check = UUID.TryParse(Parameters["key"].ToString().Replace("_", " "), out groupUUID);
                }
                else
                {
                    return("<error>arguments: no key</error>");
                }
                if (check)
                {
                    if (Parameters.ContainsKey("message"))
                    {
                        message = Parameters["message"].ToString().Replace("%20", " ").Replace("+", " ");
                    }
                    else
                    {
                        return("<error>arguments: no message</error>");
                    }
                }
                else
                {
                    return("<error>parsekey</error>");
                }

                message = message.TrimEnd();
                if (message.Length > 1023)
                {
                    message = message.Remove(1023);
                    DebugUtilities.WriteDebug(session + " " + MethodName + " Message truncated at 1024 characters");
                }

                string response = sendIMGroup(b, groupUUID, message);

                if (string.IsNullOrEmpty(response))
                {
                    return("<error>group message not sent, or answer was empty</error>");
                }

                return("<message>" + response.Trim() + "</message>");
            }
            catch (Exception e)
            {
                DebugUtilities.WriteError(e.Message);
                return("<error>loads of errors</error>");
            }
        }
コード例 #24
0
        Process(RestBot b, Dictionary <string, string> Parameters)
        {
            uint
                regionX,
                regionY;

            Utils
            .LongToUInts(b.Client.Network.CurrentSim.Handle,
                         out regionX,
                         out regionY);

            try
            {
                string target = String.Empty;

                if (Parameters.ContainsKey("target"))
                {
                    target =
                        Parameters["target"]
                        .ToString()
                        .Replace("%20", " ")
                        .Replace("+", " ");
                }
                else
                {
                    return($"<error>{MethodName}: missing argument for target</error>");
                }

                if (target.Length == 0 || target == "off")
                {
                    Active        = false;
                    targetLocalID = 0;
                    b.Client.Self.AutoPilotCancel();
                    return($"<{MethodName}>off</{MethodName}>");
                }
                else
                {
                    if (Follow(target))
                    {
                        return($"<{MethodName}>on</{MethodName}>");
                    }
                    else
                    {
                        return($"<error>cannot follow {target}</error>");
                    }
                }
            }
            catch (Exception e)
            {
                DebugUtilities.WriteError(e.Message);
                return($"<error>{MethodName}: {e.Message}</error>");
            }
        }
コード例 #25
0
 Process(RestBot b, Dictionary <string, string> Parameters)
 {
     try
     {
         return($"<{MethodName}><CurrentSim>{b.Client.Network.CurrentSim.ToString()}</CurrentSim><Position>{b.Client.Self.SimPosition.X},{b.Client.Self.SimPosition.Y},{b.Client.Self.SimPosition.Z}</Position></{MethodName}>");
     }
     catch (Exception e)
     {
         DebugUtilities.WriteError(e.Message);
         return($"<error>{MethodName}: {e.Message}</error>");
     }
 }
コード例 #26
0
 Process(RestBot b, Dictionary <string, string> Parameters)
 {
     try
     {
         b.Client.Self.Stand();
         return($"<{MethodName}>standing</{MethodName}>");
     }
     catch (Exception e)
     {
         DebugUtilities.WriteError(e.Message);
         return($"<error>{MethodName}: {e.Message}</error>");
     }
 }
コード例 #27
0
        /// <summary>
        /// Handler event for this plugin.
        /// </summary>
        /// <param name="b">A currently active RestBot</param>
        /// <param name="Parameters">none</param>
        /// <remarks>This will return (some) avatar data associated with the current session ID</remarks>
        /// if that session is known to exist.</remarks>
        public override string Process(RestBot b, Dictionary <string, string> Parameters)
        {
            if (b == null)                      // should be impossible
            {
                return("<error>invalid request</error>");
            }

            /// Note: the description below is outdated! (gwyneth 20220504)
            /// <value>Constructs a XML response with the following data:
            /// <list type="bullet">
            ///   <item>
            ///     <description>Avatar first name</description>
            ///   </item>
            ///   <item>
            ///     <description>Avatar last name</description>
            ///   </item>
            ///   <item>
            ///     <description>Avatar last namekey (UUID)</description>
            ///   </item>
            ///   <item>
            ///     <description>Current status, same as returned by the "status" member function</description>
            ///   </item>
            ///   <item>
            ///     <description>Session ID (redundant)</description>
            ///   </item>
            ///   <item>
            ///     <description>Uptime (not sure if it's just seconds since login, or date/time of login; assuming the latter)</description>
            ///   </item>
            ///   <item>
            ///     <description>Start position: can be "home", "last", or an URI describing region and position</description>
            ///   </item>
            /// </list>
            /// </value>
            string response = $@"<{MethodName}>
	<FirstName>{b.First}</FirstName>
	<LastName>{b.Last}</LastName>
	<name>{b.First} {b.Last}</name>
	<key>{b.Client.Self.AgentID.ToString()}</key>
	<status>{b.myStatus.ToString()}</status>
	<session_id>{b.sessionid.ToString()}</session_id>
	<uptime>{b.getUptimeISO8601()}</uptime>
	<start>{b.Start}</start>
	<CurrentSim>{b.Client.Network.CurrentSim.ToString()}</CurrentSim>
	<Position>{b.Client.Self.SimPosition.X},{b.Client.Self.SimPosition.Y},{b.Client.Self.SimPosition.Z}</Position>
	<Rotation>{b.Client.Self.SimRotation.X},{b.Client.Self.SimRotation.Y},{b.Client.Self.SimRotation.Z},{b.Client.Self.SimRotation.W}</Rotation>
</{MethodName}>
";

            return(response);
        } // end Process
コード例 #28
0
 public override string Process(RestBot b, Dictionary<string, string> Parameters)
 {
     try
     {
         return String.Format("<location><CurrentSim>{0}</CurrentSim><Position>{1},{2},{3}</Position></location>",
             b.Client.Network.CurrentSim.ToString(), b.Client.Self.SimPosition.X,
             b.Client.Self.SimPosition.Y, b.Client.Self.SimPosition.Z);
     }
     catch (Exception e)
     {
         DebugUtilities.WriteError(e.Message);
         return "<error>" + e.Message + "</error>";
     }
 }
コード例 #29
0
        public string getGroups(RestBot b, UUID key)
        {
            DebugUtilities.WriteInfo(session + " " + MethodName + " Looking up groups for " + key.ToString());

            lock ( GroupsLookupEvents ) {
                GroupsLookupEvents.Add(key, new AutoResetEvent(false) );
            }
            b.Client.Avatars.RequestAvatarProperties(key);

            GroupsLookupEvents[key].WaitOne(15000, true);

            lock ( GroupsLookupEvents ) {
                GroupsLookupEvents.Remove(key);
            }

            if (null == avatarGroups)
            {
                DebugUtilities.WriteInfo(session + " " + MethodName + " Groups cache failed.");
                return null;
            }
            if (0 == avatarGroups.Count)
            {
                DebugUtilities.WriteInfo(session + " " + MethodName + " No groups");
                return null;
            }
            if ( avatarGroups.ContainsKey(key) ) {
                string response = "<groups>\n";

                foreach (AvatarGroup g in avatarGroups[key])
                {
                    response += "<group>\n";
                    response += "<name>" + g.GroupName.Replace(">", "%3C").Replace("<", "%3E") + "</name>\n";
                    response += "<key>" + g.GroupID.ToString() + "</key>\n";
                    response += "<title>" + g.GroupTitle.Replace(">", "%3C").Replace("<", "%3E") + "</title>\n";
                    response += "<notices>" + g.AcceptNotices.ToString() + "</notices>\n";
                    response += "<powers>" + g.GroupPowers.ToString() + "</powers>\n";
                    response += "<insignia>" + g.GroupInsigniaID.ToString() + "</insignia>\n";
                    response += "</group>\n";
                }
                response += "</groups>\n";

                lock ( avatarGroups ) {
                    avatarGroups.Remove(key);
                }
                return response;
            } else {
                return null;
            }
        }
コード例 #30
0
 /// <summary>Initialisation</summary>
 public override void Initialize(RestBot bot)
 {
     session = bot.sessionid;
     // double-checking this, because I really, really want to force a configuration override to turn this off!
     // (gwyneth 20220412)
     if (Program.config != null && Program.config.plugin.reaper == true)
     {
         DebugUtilities.WriteDebug($"{session} {MethodName} startup");
         Reaper.Init(); //start up the reaper if we havent already (the check to see if we have is in this function)
     }
     else
     {
         DebugUtilities.WriteDebug(session + " REAPER not starting due to configuration override");
     }
 }
コード例 #31
0
        public override string Process(RestBot b, Dictionary <string, string> Parameters)
        {
            try
            {
                string type   = String.Empty;
                bool   check  = true;
                float  radius = 0.0f;

                if (Parameters.ContainsKey("type"))
                {
                    type = Parameters["type"].ToString().Replace("+", " ");
                }
                else
                {
                    check = false;
                }

                if (Parameters.ContainsKey("radius"))
                {
                    check &= float.TryParse(Parameters["radius"], out radius);
                }
                else
                {
                    check = false;
                }

                if (!check)
                {
                    return("<error>parameters have to be type, radius</error>");
                }

                // *** get current location ***
                Vector3 location = b.Client.Self.SimPosition;

                Primitive found = b.Client.Network.CurrentSim.ObjectsPrimitives.Find(
                    delegate(Primitive prim) {
                    return(prim.Properties.Name == type);
                });


                return($"<nearby_prim><pos>{found.Position.X},{found.Position.Y},{found.Position.Z}</pos></nearby_prim>");
            }
            catch (Exception e)
            {
                DebugUtilities.WriteError(e.Message);
                return($"<error>{MethodName}: {e.Message}</error>");
            }
        }
コード例 #32
0
        /// <summary>
        /// name2key (avatar name to UUID)
        /// </summary>
        /// <param name="b">RESTbot object</param>
        /// <param name="name">Name of avatar to check</param>
        /// <returns>UUID of corresponding avatar, if it exists</returns>
        public UUID getKey(RestBot b, String name)
        {
            DebugUtilities
            .WriteInfo($"{session} {MethodName} Looking up key for {name}");
            name = name.ToLower();
            DebugUtilities.WriteDebug($"Looking up: {name}");
            DebugUtilities
            .WriteDebug("Key not in cache, requesting directory lookup");
            lock (KeyLookupEvents)
            {
                KeyLookupEvents.Add(name, new AutoResetEvent(false));
            }
            DebugUtilities
            .WriteDebug($"Lookup Event added, KeyLookupEvents now has a total of {KeyLookupEvents.Count.ToString()} entries");
            DirFindQueryPacket find = new DirFindQueryPacket();

            find.AgentData.AgentID    = b.Client.Self.AgentID;          // was Network and not Self
            find.AgentData.SessionID  = b.Client.Self.SessionID;
            find.QueryData.QueryFlags = 1;

            //find.QueryData.QueryText = Helpers.StringToField(name);
            find.QueryData.QueryText  = Utils.StringToBytes(name);
            find.QueryData.QueryID    = new UUID("00000000000000000000000000000001");
            find.QueryData.QueryStart = 0;

            b.Client.Network.SendPacket((Packet)find);
            DebugUtilities
            .WriteDebug($"Packet sent - KLE has {KeyLookupEvents.Count.ToString()} entries... now waiting");
            KeyLookupEvents[name].WaitOne(15000, true);
            DebugUtilities.WriteDebug("Waiting done!");
            lock (KeyLookupEvents)
            {
                KeyLookupEvents.Remove(name);
            }
            DebugUtilities
            .WriteDebug($"Done with KLE, now has {KeyLookupEvents.Count.ToString()} entries");
            UUID response = new UUID();

            if (avatarKeys.ContainsKey(name))
            {
                response = avatarKeys[name];
                lock (avatarKeys)
                {
                    avatarKeys.Remove(name);
                }
            }
            return(response);
        }
コード例 #33
0
 Process(RestBot b, Dictionary <string, string> Parameters)
 {
     try
     {
         return(String
                .Format("<position>{0},{1},{2}</position>",
                        b.Client.Self.SimPosition.X,
                        b.Client.Self.SimPosition.Y,
                        b.Client.Self.SimPosition.Z));
     }
     catch (Exception e)
     {
         DebugUtilities.WriteError(e.Message);
         return($"<error>{e.Message}</error>");
     }
 }
コード例 #34
0
        /// <summary>
        /// Handler event for this plugin.
        /// </summary>
        /// <param name="b">A currently active RestBot</param>
        /// <param name="Parameters">not used</param>
        /// <remarks><para>This will list all currently known sessions.</para>
        /// <para>Also note that there is a way to retrieve all sessions (same method name)
        /// without requiring a valid bot session, just for my own purposes; <see cref="Program.Main" /></para>
        /// </remarks>
        public override string Process(RestBot b, Dictionary <string, string> Parameters)
        {
            bool check = false;

            if (Program.Sessions.Count != 0)                                     // no sessions? that's fine, no need to abort
            {
                check = true;
            }

            string response = $"<{MethodName}>";

            if (check)                                          // optimisation: if empty, no need to run the foreach (gwyneth 20220424)
            {
                foreach (KeyValuePair <OpenMetaverse.UUID, RESTBot.Session> kvp in Program.Sessions)
                {
                    if (kvp.Value.Bot != null && kvp.Value.Bot.Client != null && kvp.Value.Bot.Client.Self != null && kvp.Value.Bot.Client.Network != null)
                    {
                        response += $@"
	<session>
		<session_id>{kvp.Key.ToString()}</session_id>
		<key>{kvp.Value.Bot.Client.Self.AgentID.ToString()}</key>
		<name>{kvp.Value.Bot.Client.Self.FirstName} {kvp.Value.Bot.Client.Self.LastName}</name>
		<FirstName>{kvp.Value.Bot.Client.Self.FirstName}</FirstName>
		<LastName>{kvp.Value.Bot.Client.Self.LastName}</LastName>
		<status>{kvp.Value.Bot.myStatus.ToString()}</status>
		<uptime>{kvp.Value.Bot.getUptimeISO8601()}</uptime>
		<start>{kvp.Value.Bot.Start}</start>
		<CurrentSim>{kvp.Value.Bot.Client.Network.CurrentSim.ToString()}</CurrentSim>
		<Position>{kvp.Value.Bot.Client.Self.SimPosition.X},{kvp.Value.Bot.Client.Self.SimPosition.Y},{kvp.Value.Bot.Client.Self.SimPosition.Z}</Position>
		<Rotation>{kvp.Value.Bot.Client.Self.SimRotation.X},{kvp.Value.Bot.Client.Self.SimRotation.Y},{kvp.Value.Bot.Client.Self.SimRotation.Z},{kvp.Value.Bot.Client.Self.SimRotation.W}</Rotation>
	</session>"    ;
                    }
                    else
                    {
                        // Somehow, we have a session ID that has no bot assigned;
                        // this should never be the case, but... (gwyneth 20220426)
                        response += $"<session><session_id>{kvp.Key.ToString()}</session_id><key>{UUID.Zero.ToString()}</key></session>";
                    }
                }
            }
            else
            {
                response += "no sessions";
            }
            response += $"</{MethodName}>";
            return(response);
        }         // end Process
コード例 #35
0
        /// <summary>
        /// Handler event for this plugin.
        /// </summary>
        /// <param name="b">A currently active RestBot</param>
        /// <param name="Parameters">not used</param>
        /// <remarks>This will list statistics only for the simulator where the 'bot currently is.</remarks>
        public override string Process(RestBot b, Dictionary <string, string> Parameters)
        {
            bool check = false;

            while (!check)
            {
                if (b.Client.Network.CurrentSim.Stats.FPS != 0)
                {
                    check = true;
                }
            }
            string response = $@"<{MethodName}>
	<dilation>{b.Client.Network.CurrentSim.Stats.Dilation.ToString()}</dilation>
	<inbps>{b.Client.Network.CurrentSim.Stats.IncomingBPS.ToString()}</inbps>
	<outbps>{b.Client.Network.CurrentSim.Stats.OutgoingBPS.ToString()}</outbps>
	<resentout>{b.Client.Network.CurrentSim.Stats.ResentPackets.ToString()}</resentout>
	<resentin>{b.Client.Network.CurrentSim.Stats.ReceivedResends.ToString()}</resentin>
	<queue>{b.Client.Network.InboxCount.ToString()}</queue>
	<fps>{b.Client.Network.CurrentSim.Stats.FPS.ToString()}</fps>
	<physfps>{b.Client.Network.CurrentSim.Stats.PhysicsFPS.ToString()}</physfps>
	<agentupdates>{b.Client.Network.CurrentSim.Stats.AgentUpdates.ToString()}</agentupdates>
	<objects>{b.Client.Network.CurrentSim.Stats.Objects.ToString()}</objects>
	<scriptedobjects>{b.Client.Network.CurrentSim.Stats.ScriptedObjects.ToString()}</scriptedobjects>
	<agents>{b.Client.Network.CurrentSim.Stats.Agents.ToString()}</agents>
	<childagents>{b.Client.Network.CurrentSim.Stats.ChildAgents.ToString()}</childagents>
	<activescripts>{b.Client.Network.CurrentSim.Stats.ActiveScripts.ToString()}</activescripts>
	<lslips>{b.Client.Network.CurrentSim.Stats.LSLIPS.ToString()}</lslips>
	<inpps>{b.Client.Network.CurrentSim.Stats.INPPS.ToString()}</inpps>
	<outpps>{b.Client.Network.CurrentSim.Stats.OUTPPS.ToString()}</outpps>
	<pendingdownloads>{b.Client.Network.CurrentSim.Stats.PendingDownloads.ToString()}</pendingdownloads>
	<pendinguploads>{b.Client.Network.CurrentSim.Stats.PendingUploads.ToString()}</pendinguploads>
	<virtualsize>{b.Client.Network.CurrentSim.Stats.VirtualSize.ToString()}</virtualsize>
	<residentsize>{b.Client.Network.CurrentSim.Stats.ResidentSize.ToString()}</residentsize>
	<pendinglocaluploads>{b.Client.Network.CurrentSim.Stats.PendingLocalUploads.ToString()}</pendinglocaluploads>
	<unackedbytes>{b.Client.Network.CurrentSim.Stats.UnackedBytes.ToString()}</unackedbytes>
	<time>
		<frame>{b.Client.Network.CurrentSim.Stats.FrameTime.ToString()}</frame>
		<image>{b.Client.Network.CurrentSim.Stats.ImageTime.ToString()}</image>
		<physics>{b.Client.Network.CurrentSim.Stats.PhysicsTime.ToString()}</physics>
		<script>{b.Client.Network.CurrentSim.Stats.ScriptTime.ToString()}</script>
		<other>{b.Client.Network.CurrentSim.Stats.OtherTime.ToString()}</other>
	</time>
</{MethodName}>";

            return(response);
        }
コード例 #36
0
 public override string Process(RestBot b, Dictionary<string, string> Paramaters)
 {
     bool check = false;
     while ( !check ) {
         if ( b.Client.Network.CurrentSim.Stats.FPS != 0 ) {
             check = true;
         }
     }
     string response = "<stats>\n";
     response += "<dilation>" + b.Client.Network.CurrentSim.Stats.Dilation.ToString() + "</dilation>\n";
     response += "<inbps>" + b.Client.Network.CurrentSim.Stats.IncomingBPS.ToString() + "</inbps>\n";
     response += "<outbps>" + b.Client.Network.CurrentSim.Stats.OutgoingBPS.ToString() + "</outbps>\n";
     response += "<resentout>" + b.Client.Network.CurrentSim.Stats.ResentPackets.ToString() + "</resentout>\n";
     response += "<resentin>" + b.Client.Network.CurrentSim.Stats.ReceivedResends.ToString() + "</resentin>\n";
     response += "<queue>" + b.Client.Network.InboxCount.ToString() + "</queue>\n";
     response += "<fps>" + b.Client.Network.CurrentSim.Stats.FPS.ToString() + "</fps>\n";
     response += "<physfps>" + b.Client.Network.CurrentSim.Stats.PhysicsFPS.ToString() + "</physfps>\n";
     response += "<agentupdates>" + b.Client.Network.CurrentSim.Stats.AgentUpdates.ToString() + "</agentupdates>\n";
     response += "<objects>" + b.Client.Network.CurrentSim.Stats.Objects.ToString() + "</objects>\n";
     response += "<scriptedobjects>" + b.Client.Network.CurrentSim.Stats.ScriptedObjects.ToString() + "</scriptedobjects>\n";
     response += "<agents>" + b.Client.Network.CurrentSim.Stats.Agents.ToString() + "</agents>\n";
     response += "<childagents>" + b.Client.Network.CurrentSim.Stats.ChildAgents.ToString() + "</childagents>\n";
     response += "<activescripts>" + b.Client.Network.CurrentSim.Stats.ActiveScripts.ToString() + "</activescripts>\n";
     response += "<lslips>" + b.Client.Network.CurrentSim.Stats.LSLIPS.ToString() + "</lslips>\n";
     response += "<inpps>" + b.Client.Network.CurrentSim.Stats.INPPS.ToString() + "</inpps>\n";
     response += "<outpps>" + b.Client.Network.CurrentSim.Stats.OUTPPS.ToString() + "</outpps>\n";
     response += "<pendingdownloads>" + b.Client.Network.CurrentSim.Stats.PendingDownloads.ToString() + "</pendingdownloads>\n";
     response += "<pendinguploads>" + b.Client.Network.CurrentSim.Stats.PendingUploads.ToString() + "</pendinguploads>\n";
     response += "<virtualsize>" + b.Client.Network.CurrentSim.Stats.VirtualSize.ToString() + "</virtualsize>\n";
     response += "<residentsize>" + b.Client.Network.CurrentSim.Stats.ResidentSize.ToString() + "</residentsize>\n";
     response += "<pendinglocaluploads>" + b.Client.Network.CurrentSim.Stats.PendingLocalUploads.ToString() + "</pendinglocaluploads>\n";
     response += "<unackedbytes>" + b.Client.Network.CurrentSim.Stats.UnackedBytes.ToString() + "</unackedbytes>\n";
     response += "<time>\n";
     response += "<frame>" + b.Client.Network.CurrentSim.Stats.FrameTime.ToString() + "</frame>\n";
     response += "<image>" + b.Client.Network.CurrentSim.Stats.ImageTime.ToString() + "</image>\n";
     response += "<physics>" + b.Client.Network.CurrentSim.Stats.PhysicsTime.ToString() + "</physics>\n";
     response += "<script>" + b.Client.Network.CurrentSim.Stats.ScriptTime.ToString() + "</script>\n";
     response += "<other>" + b.Client.Network.CurrentSim.Stats.OtherTime.ToString() + "</other>\n";
     response += "</time>\n";
     response += "</stats>\n";
     return (response);
 }
コード例 #37
0
        public override string Process(RestBot b, Dictionary<string, string> Paramaters)
        {
            try
            {
                string type = String.Empty;
                bool check = true;
                float radius = 0.0f;

                if (Paramaters.ContainsKey("type"))
                {
                    type = Paramaters["type"].ToString().Replace("+", " ");
                }
                else check = false;

                if (Paramaters.ContainsKey("radius"))
                {
                    check &= float.TryParse(Paramaters["radius"], out radius);
                }
                else check = false;

                if (!check)
                {
                    return "<error>parameters have to be type, radius</error>";
                }

                // *** get current location ***
                Vector3 location = b.Client.Self.SimPosition;

                Primitive found = b.Client.Network.CurrentSim.ObjectsPrimitives.Find(
                    delegate(Primitive prim) {
                        return prim.Properties.Name == type;
                    });

                return "<nearby_prim>" + String.Format("<pos>{1},{2},{3}</pos>",
                    found.Position.X, found.Position.Y, found.Position.Z) + "</nearby_prim>";
            }
            catch (Exception e)
            {
                DebugUtilities.WriteError(e.Message);
                return "<error>" + e.Message + "</error>";
            }
        }
コード例 #38
0
        public override string Process(RestBot b, Dictionary<string, string> Parameters)
        {
            uint regionX, regionY;
            Utils.LongToUInts(b.Client.Network.CurrentSim.Handle, out regionX, out regionY);

            try
            {
                double x = 0.0f, y = 0.0f, z = 0.0f, distance = 0.0f;
                bool check = true;
                bool run = false;

                if (Parameters.ContainsKey("x"))
                {
                    check &= double.TryParse(Parameters["x"], out x);
                    DebugUtilities.WriteDebug("Parse: " + Parameters["x"] + " into " + x);
                }
                else check = false;

                if (Parameters.ContainsKey("y"))
                {
                    check &= double.TryParse(Parameters["y"], out y);
                }
                else check = false;

                if (Parameters.ContainsKey("z"))
                {
                    check &= double.TryParse(Parameters["z"], out z);
                }
                else check = false;

                if (Parameters.ContainsKey("distance"))
                {
                    check &= double.TryParse(Parameters["distance"], out distance);
                }

                if (Parameters.ContainsKey("run"))
                {
                    check &= bool.TryParse(Parameters["run"], out run);
                }

                if (!check)
                {
                    return "<error>parameters have to be x, y, z, [distance, run]</error>";
                }

                if (run)
                {
                    b.Client.Self.Movement.AlwaysRun = true;
                }
                else
                {
                    b.Client.Self.Movement.AlwaysRun = false;
                }
                goalPos = new Vector3((float)x, (float)y, (float)z);
                b.Client.Self.Movement.TurnToward(goalPos);
                b.Client.Self.Movement.SendUpdate(false);

                prevDistance = Vector3.Distance(goalPos, me.Client.Self.SimPosition);
                // Convert the local coordinates to global ones by adding the region handle parts to x and y
                b.Client.Self.AutoPilot(goalPos.X + regionX, goalPos.Y + regionY, goalPos.Z);
                Active = true;

                while (Active)
                {
                    Thread.Sleep(1 * 1000);
                }
                DebugUtilities.WriteSpecial("End Thread!");
                return String.Format("<move>{0},{1},{2}</move>", b.Client.Self.GlobalPosition.X, b.Client.Self.GlobalPosition.Y, b.Client.Self.GlobalPosition.Z);
            }
            catch (Exception e)
            {
                DebugUtilities.WriteError(e.Message);
                return "<error>" + e.Message + "</error>";
            }
        }
コード例 #39
0
        public UUID getKey(RestBot b, String name)
        {
            DebugUtilities.WriteInfo(session + " " + MethodName + " Looking up key for " + name);
            name = name.ToLower();
            DebugUtilities.WriteDebug("Looking up: " + name);
            DebugUtilities.WriteDebug("Key not in cache, requesting directory lookup");
            lock ( KeyLookupEvents) {
                KeyLookupEvents.Add(name, new AutoResetEvent(false));
            }
            DebugUtilities.WriteDebug("Lookup Event added, KeyLookupEvents now has a total of " + KeyLookupEvents.Count.ToString() + " entries");
            DirFindQueryPacket find = new DirFindQueryPacket();
            find.AgentData.AgentID = b.Client.Self.AgentID;	// was Network and not Self
            find.AgentData.SessionID = b.Client.Self.SessionID;
            find.QueryData.QueryFlags = 1;
            //find.QueryData.QueryText = Helpers.StringToField(name);
            find.QueryData.QueryText = Utils.StringToBytes(name);
            find.QueryData.QueryID = new UUID("00000000000000000000000000000001");
            find.QueryData.QueryStart = 0;

            b.Client.Network.SendPacket((Packet) find);
            DebugUtilities.WriteDebug("Packet sent - KLE has " + KeyLookupEvents.Count.ToString() + " entries.. now waiting");
            KeyLookupEvents[name].WaitOne(15000,true);
            DebugUtilities.WriteDebug("Waiting done!");
            lock (KeyLookupEvents) {
                KeyLookupEvents.Remove(name);
            }
            DebugUtilities.WriteDebug("Done with KLE, now has " + KeyLookupEvents.Count.ToString() + " entries");
            UUID response = new UUID();
            if ( avatarKeys.ContainsKey(name) ) {
                response = avatarKeys[name];
                lock ( avatarKeys ) {
                    avatarKeys.Remove(name);
                }
            }
            return response;
        }
コード例 #40
0
        public override string Process(RestBot b, Dictionary<string, string> Paramaters)
        {
            try
            {
                string type = String.Empty;
                bool check = true;
                float radius = 0.0f;

                if (Paramaters.ContainsKey("type"))
                {
                    type = Paramaters["type"].ToString().Replace("+", " ");
                }
                else check = false;

                if (Paramaters.ContainsKey("radius"))
                {
                    check &= float.TryParse(Paramaters["radius"], out radius);
                }
                else check = false;

                if (!check)
                {
                    return "<error>parameters have to be type, radius</error>";
                }

                // *** get current location ***
                Vector3 location = b.Client.Self.SimPosition;

                // *** find all objects in radius ***
                List<Primitive> prims = b.Client.Network.CurrentSim.ObjectsPrimitives.FindAll(
                    delegate(Primitive prim)
                    {
                        Vector3 pos = prim.Position;
                        return ((prim.ParentID == 0) && (pos != Vector3.Zero) && (Vector3.Distance(pos, location) < radius));
                    }
                );

                // *** request properties of these objects ***
                bool complete = RequestObjectProperties(prims, 0);

                String resultSet = String.Empty;

                foreach (Primitive p in prims)
                {
                    string name = p.Properties != null ? p.Properties.Name : null;
                    if (String.IsNullOrEmpty(type) || ((name != null) && (name.Contains(type))))
                    {
                        resultSet += String.Format("<prim><name>{0}</name><pos>{1},{2},{3}</pos></prim>", name, p.Position.X, p.Position.Y, p.Position.Z);
                    }
                }
                return "<nearby_prims>" + resultSet + "</nearby_prims>";
            }
            catch (Exception e)
            {
                DebugUtilities.WriteError(e.Message);
                return "<error>" + e.Message + "</error>";
            }
        }
コード例 #41
0
        public override string Process(RestBot b, Dictionary<string, string> Parameters)
        {
            UUID avatar = UUID.Zero;
            UUID group = UUID.Zero;
            UUID role = UUID.Zero;
            List<UUID> roles = new List<UUID>();

            try
            {
                bool check = false;
                if ( Parameters.ContainsKey("avatar") )
                {
                    check = UUID.TryParse(Parameters["avatar"].ToString().Replace("_"," "), out avatar);
                }
                else
                {
                    return "<error>arguments: no avatar key</error>";
                }
                if ( check )
                {
                    if ( Parameters.ContainsKey("group") )
                    {
                        check = UUID.TryParse(Parameters["group"].ToString().Replace("_"," "), out group);
                    }
                    else
                    {
                        return "<error>arguments: no group key</error>";
                    }

                    // to-do: avatars can be invited to multiple roles.
                    if ( Parameters.ContainsKey("role") )
                    {
                        if (! UUID.TryParse(Parameters["role"].ToString().Replace("_"," "), out role) )
                        {
                            // just a warning, role is optional
                            DebugUtilities.WriteDebug(session + " " + MethodName + " no role found, but that's ok");
                        }
                        roles.Add(role);
                    }
                    else
                    {
                        roles.Add(UUID.Zero); // no roles to add
                    }
                }
                else
                {
                    return "<error>parsekey</error>";
                }

                DebugUtilities.WriteDebug(session + " " + MethodName + " Group UUID: " + group + " Avatar UUID to join group: " + avatar + " Role UUID for avatar to join: " + roles.ToString() + " (NULL_KEY is fine)");

                b.Client.Groups.Invite(group, roles, avatar);

                return "<invitation>invited " + avatar + " to " + group + "</invitation>\n";
            }
            catch ( Exception e )
            {
                DebugUtilities.WriteError(e.Message);
                return "<error>loads of errors</error>";
            }
        }
コード例 #42
0
        private string activateGroup(RestBot b, UUID groupUUID)
        {
            DebugUtilities.WriteInfo(session.ToString() + " " + MethodName + " Activating group " + groupUUID.ToString());
            EventHandler<PacketReceivedEventArgs> pcallback = AgentDataUpdateHandler;
            b.Client.Network.RegisterCallback(PacketType.AgentDataUpdate, pcallback);
            b.Client.Groups.ActivateGroup(groupUUID);

            if ( ! GroupsEvent.WaitOne(15000, true) ) {
                DebugUtilities.WriteWarning(session + " " + MethodName + " timed out on setting active group");
            }

            // ignore everything and just reset the event
            b.Client.Network.UnregisterCallback(PacketType.AgentDataUpdate, pcallback);
            GroupsEvent.Reset();

            if (String.IsNullOrEmpty(activeGroup))
                  	DebugUtilities.WriteWarning(session + " " + MethodName + " Failed to activate the group " + groupUUID);

            return activeGroup;
        }
コード例 #43
0
        public override string Process(RestBot b, Dictionary<string, string> Parameters)
        {
            try
            {
                string sim = "";
                float x = 128.0f, y = 128.0f, z = 30.0f;
                bool check = true;

                if (Parameters.ContainsKey("sim"))
                {
                    sim = Parameters["sim"].ToString();
                }
                else check = false;

                if (Parameters.ContainsKey("x"))
                {
                    check &= float.TryParse(Parameters["x"], out x);
                }
                else check = false;

                if (Parameters.ContainsKey("y"))
                {
                    check &= float.TryParse(Parameters["y"], out y);
                }
                else check = false;

                if (Parameters.ContainsKey("z"))
                {
                    check &= float.TryParse(Parameters["z"], out z);
                }
                else check = false;

                if (!check)
                {
                    return "<error>parameters have to be simulator name, x, y, z</error>";
                }

                if (b.Client.Self.Teleport(sim, new Vector3(x, y, z)))
                    return "<teleport>" + b.Client.Network.CurrentSim + "</teleport>";
                else
                    return "<error>Teleport failed: " + b.Client.Self.TeleportMessage + "</error>";
            }
            catch (Exception e)
            {
                DebugUtilities.WriteError(e.Message);
                return "<error>" + e.Message + "</error>";
            }
        }
コード例 #44
0
ファイル: RestPlugin.cs プロジェクト: GwynethLlewelyn/restbot
 /// <summary>
 /// Process the request through this method
 /// </summary>
 /// <param name="b">The RestBot that is doing the processing</param>
 /// <param name="Paramaters">QueryString and POST parameters</param>
 /// <returns>XML output</returns>
 public abstract string Process(RestBot b, Dictionary<string, string> Paramaters);
コード例 #45
0
        public override string Process(RestBot b, Dictionary<string, string> Parameters)
        {
            try
            {
                string name = "";
                bool check = true;

                if (Parameters.ContainsKey("target"))
                {
                    name = Parameters["target"].ToString().Replace("+", " ");
                }
                else check = false;

                if (!check)
                {
                    return "<error>parameters have to be target name</error>";
                }

                lock (b.Client.Network.Simulators)
                {
                    for (int i = 0; i < b.Client.Network.Simulators.Count; i++)
                    {
                        DebugUtilities.WriteDebug("Found Avatars: " + b.Client.Network.Simulators[i].ObjectsAvatars.Count);
                        Avatar target = b.Client.Network.Simulators[i].ObjectsAvatars.Find(
                            delegate(Avatar avatar)
                            {
                                DebugUtilities.WriteDebug("Found avatar: " + avatar.Name);
                                return avatar.Name == name;
                            }
                        );

                        if (target != null)
                        {
                            return String.Format("<goal_position>{0},{1},{2}</goal_position><curr_position>{3},{4},{5}</curr_position>",
                                target.Position.X, target.Position.Y, target.Position.Z, b.Client.Self.SimPosition.X, b.Client.Self.SimPosition.Y, b.Client.Self.SimPosition.Z);
                        }
                        else
                        {
                            DebugUtilities.WriteError("Error obtaining the avatar: " + name);
                        }
                    }
                }
                return "<error>avatar_position failed.</error>";
            }
            catch (Exception e)
            {
                DebugUtilities.WriteError(e.Message);
                return "<error>" + e.Message + "</error>";
            }
        }
コード例 #46
0
        public string getProfile(RestBot b, UUID key)
        {
            DebugUtilities.WriteInfo(session + " " + MethodName + " Looking up profile for " + key.ToString());

            lock ( ProfileLookupEvents ) {
                ProfileLookupEvents.Add(key, new AutoResetEvent(false) );
            }
            b.Client.Avatars.RequestAvatarProperties(key);

            ProfileLookupEvents[key].WaitOne(15000, true);

            lock ( ProfileLookupEvents ) {
                ProfileLookupEvents.Remove(key);
            }
            if ( avatarProfile.ContainsKey(key) ) {
                Avatar.AvatarProperties p = avatarProfile[key];
                string response = "<profile>\n";
                response += "<publish>" + p.AllowPublish.ToString() + "</publish>\n";
                response += "<firstlife>\n";
                response += "<text>" + p.FirstLifeText.Replace(">", "%3C").Replace("<", "%3E") + "</text>\n";
                response += "<image>" + p.FirstLifeImage.ToString() + "</image>\n";
                response += "</firstlife>\n";
                response += "<partner>" + p.Partner.ToString() + "</partner>\n";
                response += "<born>" + p.BornOn + "</born>\n";
                response += "<about>" + p.AboutText.Replace(">", "%3C").Replace("<", "%3E") + "</about>\n";
                response += "<charter>" + p.CharterMember + "</charter>\n";
                response += "<profileimage>" + p.ProfileImage.ToString() + "</profileimage>\n";
                response += "<mature>" + p.MaturePublish.ToString() + "</mature>\n";
                response += "<identified>" + p.Identified.ToString() + "</identified>\n";
                response += "<transacted>" + p.Transacted.ToString() + "</transacted>\n";
                response += "<url>" + p.ProfileURL + "</url>\n";
                response += "</profile>\n";
                lock ( avatarProfile ) {
                    avatarProfile.Remove(key);
                }
                return response;
            } else {
                return null;
            }
        }
コード例 #47
0
 public override void Initialize(RestBot bot)
 {
     session = bot.sessionid;
     DebugUtilities.WriteDebug(session + " " + MethodName + " startup");
     // bot.Client.Avatars.OnAvatarProperties += new AvatarManager.AvatarPropertiesCallback(Avatars_OnAvatarProperties); // obsolete
     bot.Client.Avatars.AvatarPropertiesReply += Avatars_OnAvatarProperties;
 }
コード例 #48
0
        public override string Process(RestBot b, Dictionary<string, string> Paramaters)
        {
            UUID agentKey;
            try
            {
                bool check = false;
                if (Paramaters.ContainsKey("key")) {
                    check = UUID.TryParse(Paramaters["key"].ToString().Replace("_"," "), out agentKey);
                } else {
                    return "<error>arguments</error>";
                }
                if ( check ) {
                    string response = getProfile(b, agentKey);
                    if ( response == null ) {
                        return "<error>not found</error>";
                    } else {
                        return response;
                    }
                } else {
                    return "<error>unknown</error>";
                }

            }
            catch ( Exception e )
            {
                DebugUtilities.WriteError(e.Message);
                return "<error>parsekey</error>";
            }
        }
コード例 #49
0
 public override string Process(RestBot b, Dictionary<string, string> Parameters)
 {
     try
     {
         return String.Format("<position>{0},{1},{2}</error>", b.Client.Self.SimPosition.X, b.Client.Self.SimPosition.Y, b.Client.Self.SimPosition.Z);
     }
     catch (Exception e)
     {
         DebugUtilities.WriteError(e.Message);
         return "<error>" + e.Message + "</error>";
     }
 }
コード例 #50
0
        private string sendIMGroup(RestBot b, UUID groupUUID, string message)
        {
            DebugUtilities.WriteInfo(session.ToString() + " " + MethodName + " Sending message '" + message + "' to group UUID " + groupUUID.ToString());
            b.Client.Self.GroupChatJoined += Self_GroupChatJoined;

            if (!b.Client.Self.GroupChatSessions.ContainsKey(groupUUID))
            {
                WaitForSessionStart.Reset();
                b.Client.Self.RequestJoinGroupChat(groupUUID);
            }
            else
            {
                WaitForSessionStart.Set();
            }

            if (WaitForSessionStart.WaitOne(20000, false))
            {
                b.Client.Self.InstantMessageGroup(groupUUID, message);
            }
            else
            {
                DebugUtilities.WriteInfo(session.ToString() + " " + MethodName + " Timeout waiting for group session start");
                return "timeout";
            }

            b.Client.Self.GroupChatJoined -= Self_GroupChatJoined;
            DebugUtilities.WriteInfo(session.ToString() + " " + MethodName + " Instant Messaged group " + groupUUID.ToString() + " with message: " + message);

            return "message sent";
        }
コード例 #51
0
ファイル: RestPlugin.cs プロジェクト: GwynethLlewelyn/restbot
 /// <summary>
 /// An optionally overridable method for setting up events and callbacks from a RestBot
 /// </summary>
 /// <param name="bot"></param>
 public virtual void Initialize(RestBot bot)
 {
 }
コード例 #52
0
 public override void Initialize(RestBot bot)
 {
     session = bot.sessionid;
     DebugUtilities.WriteDebug(session + " " + MethodName + " startup");
     // bot.Client.Network.RegisterCallback(PacketType.AvatarPropertiesReply, new NetworkManager.PacketCallback(AvatarPropertiesReply)); // obsolete
     bot.Client.Avatars.AvatarPropertiesReply += AvatarPropertiesReply;
 }
コード例 #53
0
        public override string Process(RestBot b, Dictionary<string, string> Parameters)
        {
            Utils.LongToUInts(b.Client.Network.CurrentSim.Handle, out regionX, out regionY);

            try
            {
                double x = 0.0f, y = 0.0f, z = 0.0f;
                bool check = true;
                bool run = false;
                string avatarName = String.Empty;

                if (Parameters.ContainsKey("avatar"))
                {
                    avatarName = Parameters["avatar"].ToString().Replace("+", " ");
                }
                else check = false;

                if (!check)
                {
                    return "<error>parameters have to be x, y, z, [distance, run]</error>";
                }

                if (run)
                {
                    b.Client.Self.Movement.AlwaysRun = true;
                }
                else
                {
                    b.Client.Self.Movement.AlwaysRun = false;
                }

                lock (b.Client.Network.Simulators)
                {
                    for (int i = 0; i < b.Client.Network.Simulators.Count; i++)
                    {
                        DebugUtilities.WriteDebug("Found Avatars: " + b.Client.Network.Simulators[i].ObjectsAvatars.Count);
                        target = b.Client.Network.Simulators[i].ObjectsAvatars.Find(
                            delegate(Avatar avatar)
                            {
                                DebugUtilities.WriteDebug("Found avatar: " + avatar.Name);
                                return avatar.Name == avatarName;
                            }
                        );

                        if (target != null)
                        {
                            goalPos = target.Position;
                        }
                        else
                        {
                            DebugUtilities.WriteError("Error obtaining the avatar: " + avatarName);
                            return String.Format("<error>Error obtaining the avatar</error>");
                        }
                    }
                }

                goalPos = new Vector3((float)x, (float)y, (float)z);
                b.Client.Self.Movement.TurnToward(goalPos);
                b.Client.Self.Movement.SendUpdate(false);

                prevDistance = Vector3.Distance(goalPos, me.Client.Self.SimPosition);
                if (prevDistance > 30)
                {
                    b.Client.Self.Movement.AlwaysRun = true;
                }
                else
                {
                    b.Client.Self.Movement.AlwaysRun = false;
                }
                // Convert the local coordinates to global ones by adding the region handle parts to x and y
                b.Client.Self.AutoPilot(goalPos.X + regionX, goalPos.Y + regionY, goalPos.Z);
                Active = true;

                while (Active)
                {
                    Thread.Sleep(1 * 1000);
                }
                DebugUtilities.WriteSpecial("End Thread!");
                return String.Format("<move>{0},{1},{2}</move>", b.Client.Self.GlobalPosition.X, b.Client.Self.GlobalPosition.Y, b.Client.Self.GlobalPosition.Z);
            }
            catch (Exception e)
            {
                DebugUtilities.WriteError(e.Message);
                return "<error>" + e.Message + "</error>";
            }
        }
コード例 #54
0
        public bool getOnline(RestBot b, UUID key)
        {
            DebugUtilities.WriteInfo(session + " " + MethodName + " Looking up online status for " + key.ToString());

            lock ( OnlineLookupEvents ) {
                OnlineLookupEvents.Add(key, new AutoResetEvent(false) );
            }

            // obsolete
            /*
            AvatarPropertiesRequestPacket p = new AvatarPropertiesRequestPacket();
            p.AgentData.AgentID = b.Client.Network.AgentID;
            p.AgentData.SessionID = b.Client.Network.SessionID;
            p.AgentData.AvatarID = key;

            b.Client.Network.SendPacket( (Packet) p);
            */
            b.Client.Avatars.RequestAvatarProperties(key);

            OnlineLookupEvents[key].WaitOne(15000, true);

            lock ( OnlineLookupEvents ) {
                OnlineLookupEvents.Remove(key);
            }
            bool response = avatarOnline[key];
            lock ( avatarOnline ) {
                avatarOnline.Remove(key);
            }
            return response;
        }
コード例 #55
0
        public override string Process(RestBot b, Dictionary<string, string> Parameters)
        {
            uint regionX, regionY;
            Utils.LongToUInts(b.Client.Network.CurrentSim.Handle, out regionX, out regionY);

            try
            {
                string target = String.Empty;

                if (Parameters.ContainsKey("target"))
                {
                    target = Parameters["target"].ToString().Replace("%20", " ").Replace("+", " ");
                }
                else
                {
                    return "<error>arguments</error>";
                }

                if (target.Length == 0 || target == "off")
                {
                    Active = false;
                    targetLocalID = 0;
                    b.Client.Self.AutoPilotCancel();
                    return "<follow>off</follow>";
                }
                else
                {
                    if (Follow(target))
                        return "<follow>on</follow>";
                    else
                        return "<follow>error</follow>";
                }
            }
            catch (Exception e)
            {
                DebugUtilities.WriteError(e.Message);
                return "<follow>error: " + e.Message + "</follow>";
            }
        }
コード例 #56
0
        private string getName(RestBot b, UUID id)
        {
            DebugUtilities.WriteInfo(session.ToString() + " " + MethodName + " Looking up name for " + id.ToString());
            lock (NameLookupEvents) {
                NameLookupEvents.Add(id, new AutoResetEvent(false));
            }

            b.Client.Avatars.RequestAvatarName(id);

            if ( ! NameLookupEvents[id].WaitOne(15000, true) ) {
                DebugUtilities.WriteWarning(session + " " + MethodName + " timed out on avatar name lookup");
            }
            lock (NameLookupEvents) {
                NameLookupEvents.Remove(id);
            }
            string response = null;
            if ( avatarNames.ContainsKey(id) ) {
                response = avatarNames[id]; // .Name removed
                lock ( avatarNames ) {
                    avatarNames.Remove(id);
                }
            } else {
                response = String.Empty;
            }
            return response;
        }
コード例 #57
0
        public override string Process(RestBot b, Dictionary<string, string> Parameters)
        {
            string message;
            string subject;
            UUID groupUUID = UUID.Zero;
            UUID attachmentUUID = UUID.Zero;
            GroupNotice notice;

            try
            {
                if ( Parameters.ContainsKey("subject") )
                {
                    subject = Parameters["subject"].ToString().Replace("%20"," ").Replace("+"," ");
                }
                else
                {
                    return "<error>No notice subject</error>";
                }

                if ( Parameters.ContainsKey("message") )
                {
                    message = Parameters["message"].ToString().Replace("%20"," ").Replace("+"," ");
                }
                else
                {
                    return "<error>No notice message</error>";
                }

                if ( Parameters.ContainsKey("group") )
                {
                    if (! UUID.TryParse(Parameters["group"].ToString().Replace("_"," "), out groupUUID) )
                    {
                        return "<error>parsekey group</error>";
                    }
                }
                else
                {
                    return "<error>arguments: no group key</error>";
                }

                if ( Parameters.ContainsKey("attachment") )
                {
                    if (!  UUID.TryParse(Parameters["attachment"].ToString().Replace("_"," "), out attachmentUUID) )
                    {
                        return "<error>parsekey attachment</error>";
                    }
                }
                else
                {
                    // just a warning, attachment can be empty
                    DebugUtilities.WriteWarning(session + " " + MethodName + " Notice has no attachment (no problem)");
                }

                DebugUtilities.WriteDebug(session + " " + MethodName + " Attempting to create a notice");

                /* This doesn't work as it should!
                if (! b.Client.Inventory.Store.Contains(attachmentUUID))
                {
                    DebugUtilities.WriteWarning(session + " " + MethodName + " Item UUID " + attachmentUUID.ToString() + " not found on inventory (are you using an Asset UUID by mistake?)");
                    attachmentUUID = UUID.Zero;
                }
                */

                notice = new GroupNotice();

                notice.Subject = subject;
                notice.Message = message;
                notice.AttachmentID = attachmentUUID; // this is the inventory UUID, not the asset UUID
                notice.OwnerID = b.Client.Self.AgentID;

                b.Client.Groups.SendGroupNotice(groupUUID, notice);

                DebugUtilities.WriteDebug(session + " " + MethodName + " Sent Notice from avatar " + notice.OwnerID.ToString() + " to group: " + groupUUID.ToString() + " subject: '" + notice.Subject.ToString() + "' message: '" + notice.Message.ToString() + "' Optional attachment: " + notice.AttachmentID.ToString() + " Serialisation: " + Utils.BytesToString(notice.SerializeAttachment()));

                return "<notice>sent</notice>\n";
            }
            catch ( Exception e )
            {
                DebugUtilities.WriteError(e.Message);
                return "<error>loads of errors</error>";
            }
        }
コード例 #58
0
 public override string Process(RestBot b, Dictionary<string, string> Paramaters)
 {
     string avname = null;
     if ( Paramaters.ContainsKey("name") ) {
         avname = Paramaters["name"].ToString().Replace("%20"," ").Replace("+"," ");
     } else {
         return "<error>arguments</error>";
     }
     if ( avname != null ) {
         string response = getKey(b,avname).ToString();
         return "<key>" + response + "</key>\n";
     } else {
         return "<error>nokey</error>";
     }
 }
コード例 #59
0
        public override string Process(RestBot b, Dictionary<string, string> Parameters)
        {
            UUID groupUUID;
            string message;

            try
            {
                bool check = false;
                if ( Parameters.ContainsKey("key") )
                {
                    check = UUID.TryParse(Parameters["key"].ToString().Replace("_"," "), out groupUUID);
                }
                else
                {
                    return "<error>arguments: no key</error>";
                }
                if ( check )
                {
                    if ( Parameters.ContainsKey("message") )
                    {
                        message = Parameters["message"].ToString().Replace("%20"," ").Replace("+"," ");
                    }
                    else
                    {
                        return "<error>arguments: no message</error>";
                    }

                }
                else
                {
                    return "<error>parsekey</error>";
                }

                message = message.TrimEnd();
                if (message.Length > 1023)
                {
                    message = message.Remove(1023);
                    DebugUtilities.WriteDebug(session + " " + MethodName + " Message truncated at 1024 characters");
                }

                string response = sendIMGroup(b, groupUUID, message);

                return "<message>" + response.Trim() + "</message>\n";
            }
            catch ( Exception e )
            {
                DebugUtilities.WriteError(e.Message);
                return "<error>loads of errors</error>";
            }
        }
コード例 #60
0
 public override void Initialize(RestBot bot)
 {
     session = bot.sessionid;
     DebugUtilities.WriteDebug(session + " " + MethodName + " startup");
     // bot.Client.Network.RegisterCallback(PacketType.DirPeopleReply, new NetworkManager.PacketCallback(Avatars_OnDirPeopleReply)); // obsolete, now uses DirectoryManager
     bot.Client.Directory.DirPeopleReply += Avatars_OnDirPeopleReply;
 }