Scriptable interface must be implemented by all Eryan scripts
Example #1
0
 /// <summary>
 /// Unload the userDomain
 /// </summary>
 public void unloadUserDomain()
 {
     scriptName = null;
     script = null;
     running = false;
 }
Example #2
0
        /// <summary>
        /// Bot's logic loop
        /// </summary>
        public void update()
        {
            if (paused)
            {
                //Console.WriteLine("Not running");
                return;
            }

            if (script == null)
            {
                if(scriptName != null)
                {
                    script = loadScript(this.scriptName);
                }
                return;
            }

            if (!running)
            {
                Console.WriteLine("Not running, Click Run");
                return;
            }

            if (!initialized)
            {
                script.initializeInputs(bot);
                script.onStart();
                initialized = !initialized;
            }

            //Loaded script needs to be on its own thread...maybe not

            int sleep = 0;

                //Run background scripts
            foreach (Scriptable bgScript in bot.BACKGROUNDSCRIPTS)
            {
                try
                {
                    if (bgScript.Name.Equals("Autologer"))
                    {
                        if (!((Script.Scripts.AutoLoger)bgScript).HasCredentials)
                            ((Script.Scripts.AutoLoger)bgScript).userCredentials(bot.Accountmanager);
                    }

                    if(bgScript.Enabled)
                        bgScript.run();
                }

                catch (Exception e)
                {
                    Console.WriteLine("background script f****d up");
                    Console.WriteLine(e.ToString());
                }

            }
            try
            {
                if (script.enabled)
                {
                    script.initializeInputs(bot);
                    sleep = script.run();
                }
                else
                    sleep = 600;
            }
            catch (Exception e)
            {
                Console.WriteLine("user script f****d up");
                Console.WriteLine(e.ToString());
            }

            if (sleep < 1)
                sleep = 300;

            Thread.Sleep(sleep);

            Console.WriteLine("Bot pid = " + getPid());
        }
Example #3
0
        /// <summary>
        /// Loads the script assembly
        /// </summary>
        /// <param name="name">Name of the assembly to be loaded, namespace must be Script and main class must be named Script</param>
        /// <returns></returns>
        public Scriptable loadScript(string name)
        {
            assembly = null;

            try
            {
                assembly = Assembly.Load(loadFile(name));
            }
            catch (System.IO.FileNotFoundException e)
            {
                Console.WriteLine(e.ToString());
                return null;
            }

            if (assembly == null)
            {
                Console.WriteLine("Couldn't load assembly");
                return null;
            }

            Type script = assembly.GetType("Script.Script");

            if (script == null)
            {
                Console.WriteLine("Script Type is null");
                return null;
            }

            Scriptable scriptInstance =  null;

            try
            {
                scriptInstance = (Scriptable)Activator.CreateInstance(script);
            }
            catch(Exception e)
            {
                Console.WriteLine("Load Error" + e.ToString());
            }

            this.script = scriptInstance;
            return scriptInstance;
        }