示例#1
0
        /// <summary>
        /// Main entry point for logging in with a bot.
        /// </summary>
        /// <param name="session">Current session UUID</param>
        /// <param name="f">Login first name</param>
        /// <param name="l">Login last name</param>
        /// <param name="p">MD5-encoded password</param>
        /// <param name="s">Start location is "last", "home" or could be a <seealso cref="T:OpenMetaverse.URI"/></param>

        public RestBot(UUID session, string f, string l, string p, string s)
        {
            //setting up some class variables
            sessionid             = session;
            myStatus              = Status.Offline;
            Client                = new GridClient();
            First                 = f;
            Last                  = l;
            MD5Password           = p;
            uptime                = DateTime.Now;
            Start                 = (s == String.Empty) ? "last" : s;
            ReloginTimer          = new System.Timers.Timer();
            ReloginTimer.Elapsed += new ElapsedEventHandler(ReloginTimer_Elapsed);

            // Some callbacks..
            DebugUtilities.WriteDebug(session.ToString() + " Initializing callbacks");

            // Client.Network.OnDisconnected += new NetworkManager.DisconnectedCallback(Network_OnDisconnected);
            Client.Network.Disconnected += Network_OnDisconnected;             // new syntax

            // Timer used to update an active plugin.
            updateTimer          = new System.Timers.Timer(500);
            updateTimer.Elapsed +=
                new System.Timers.ElapsedEventHandler(updateTimer_Elapsed);

            // Initialize StatefulPlugins
            DebugUtilities.WriteDebug(session.ToString() + " Initializing plugins");
            StatefulPlugins = new Dictionary <string, StatefulPlugin>();
            foreach (Type t in RestBot.StatefulPluginDefinitions)
            {
                ConstructorInfo?info = t.GetConstructor(Type.EmptyTypes);
                if (info == null)
                {
                    DebugUtilities
                    .WriteDebug(session.ToString() +
                                " could not get constructor for type " +
                                t.ToString());
                    continue;
                }
                StatefulPlugin sp = (StatefulPlugin)info.Invoke(new object[0]);

                // Add it to the dictionary
                RegisterStatefulPlugin(sp.MethodName, sp);
                DebugUtilities
                .WriteDebug(session.ToString() + " * added " + sp.MethodName);

                // Initialize all the handlers, etc
                sp.Initialize(this);
            }
            updateTimer.Start();

            /// The strange lambda assignment is due to insane new rules regarding constructors
            /// in recent versions of C#. (gwyneth 20220213)
            /// <see href="https://stackoverflow.com/a/70146798/1035977" />
            OnBotStatus = new BotStatusCallback((sender, e) => {});
        }
示例#2
0
 /// <summary>
 /// Register a stateful RESTbot plugin.
 /// </summary>
 /// <param="method">Method name to register</param>
 /// <param="sp">Stateful plugin object</param>
 public void RegisterStatefulPlugin(string method, StatefulPlugin sp)
 {
     StatefulPlugins.Add(method, sp);
 }
示例#3
0
 public void RegisterStatefulPlugin(string method, StatefulPlugin sp)
 {
     StatefulPlugins.Add(method, sp);
 }