Esempio n. 1
0
        public bool CanScribble(IUser client)
        {
            if (this.CanScript)
            {
                JSScript[] scripts = ScriptManager.Scripts.ToArray();

                foreach (JSScript s in scripts)
                {
                    try
                    {
                        Objects.JSUser u      = new Objects.JSUser(s.JS.Object.InstancePrototype, client, s.ScriptName);
                        bool           result = s.JS.CallGlobalFunction <bool>("onScribbleCheck", u);

                        if (!result)
                        {
                            return(false);
                        }
                    }
                    catch (Jurassic.JavaScriptException e)
                    {
                        ErrorDispatcher.SendError(s.ScriptName, e.Message, e.LineNumber);
                    }
                    catch { }
                }
            }

            return(true);
        }
        public bool LoadScript(String path)
        {
            Server.Users.Ares(x => this.local_users.Add(new Objects.JSUser(this.JS.Object.InstancePrototype, x, this.ScriptName)));
            Server.Users.Web(x => this.local_users.Add(new Objects.JSUser(this.JS.Object.InstancePrototype, x, this.ScriptName)));

            if (Server.Link.IsLinked)
            {
                Server.Link.ForEachLeaf(x =>
                {
                    this.leaves.Add(new Objects.JSLeaf(this.JS.Object.InstancePrototype, x, this.ScriptName));

                    x.ForEachUser(z => this.leaves[this.leaves.Count - 1].users.Add(
                                      new Objects.JSUser(this.JS.Object.InstancePrototype, z, this.ScriptName)));
                });
            }

            try
            {
                this.JS.ExecuteFile(path);
                return(true);
            }
            catch (JavaScriptException e)
            {
                ErrorDispatcher.SendError(this.ScriptName, e.Message, e.LineNumber);
            }
            catch { }

            return(false);
        }
Esempio n. 3
0
        public void CycleTick()
        {
            if (this.CanScript)
            {
                if (Server.Time > this._second_timer)
                {
                    this._second_timer = Server.Time;
                    JSScript[] scripts = ScriptManager.Scripts.ToArray();

                    foreach (JSScript s in scripts)
                    {
                        try
                        {
                            s.JS.CallGlobalFunction("onTimer");
                        }
                        catch (Jurassic.JavaScriptException e)
                        {
                            ErrorDispatcher.SendError(s.ScriptName, e.Message, e.LineNumber);
                        }
                        catch { }
                    }
                }

                ScriptManager.DequeueCallbacks();
                TimerList.UpdateTimers();
                LiveScript.CheckTasks();
            }
        }
Esempio n. 4
0
        public bool CanScribble(IUser client, bool isPM = false)
        {
            if (this.CanScript)
            {
                JSScript[] scripts = ScriptManager.Scripts.ToArray();

                foreach (JSScript s in scripts)
                {
                    try
                    {
                        // Adding the isPM shouldnt break any existing scripts due to how javascript works
                        Objects.JSUser u      = new Objects.JSUser(s.JS.Object.InstancePrototype, client, s.ScriptName);
                        bool           result = s.JS.CallGlobalFunction <bool>("onScribbleCheck", u, isPM);

                        if (!result)
                        {
                            return(false);
                        }
                    }
                    catch (Jurassic.JavaScriptException e)
                    {
                        ErrorDispatcher.SendError(s.ScriptName, e.Message, e.LineNumber);
                    }
                    catch { }
                }
            }

            return(true);
        }
Esempio n. 5
0
 public void ServerStarted()
 {
     this._second_timer = 0;
     this.CanScript     = Server.Scripting.ScriptEnabled;
     TimerList.Reset();
     LiveScript.Reset();
     ErrorDispatcher.Reset();
     ScriptManager.AutoRun();
 }
        public static bool Load(String f, bool update_autorun)
        {
            FileInfo file = null;

            try
            {
                file = new FileInfo(f);
                file = new FileInfo(Path.Combine(Server.DataPath, file.Name, file.Name));
            }
            catch { return(false); }

            if (file.Name == "room")
            {
                return(false);
            }

            int index = Scripts.FindIndex(x => x.ScriptName == file.Name);

            if (index > 0)
            {
                Scripts[index].KillScript();
                Scripts.RemoveAt(index);
            }

            JSScript script = new JSScript(file.Name);

            if (File.Exists(file.FullName))
            {
                Scripts.Add(script);

                if (script.LoadScript(file.FullName))
                {
                    try
                    {
                        script.JS.CallGlobalFunction("onLoad");
                    }
                    catch (Jurassic.JavaScriptException e)
                    {
                        ErrorDispatcher.SendError(script.ScriptName, e.Message, e.LineNumber);
                    }
                    catch { }

                    if (update_autorun)
                    {
                        UpdateAutorun();
                    }

                    return(true);
                }
            }

            return(false);
        }
Esempio n. 7
0
        public void Joined(IUser client)
        {
            if (this.CanScript)
            {
                ScriptManager.Scripts.ForEach(x =>
                {
                    if (!client.Link.IsLinked)
                    {
                        x.local_users.RemoveAll(z => z.Name == client.Name);
                        x.local_users.Add(new Objects.JSUser(x.JS.Object.InstancePrototype, client, x.ScriptName));
                    }
                    else
                    {
                        x.leaves.ForEach(z =>
                        {
                            if (z.Ident == client.Link.Ident)
                            {
                                z.users.RemoveAll(y => y.Name == client.Name);
                                z.users.Add(new Objects.JSUser(x.JS.Object.InstancePrototype, client, x.ScriptName));
                            }
                        });
                    }
                });

                JSScript[] scripts = ScriptManager.Scripts.ToArray();

                foreach (JSScript s in scripts)
                {
                    Objects.JSUser u = s.GetUser(client);

                    if (u != null)
                    {
                        try
                        {
                            s.JS.CallGlobalFunction("onJoin", u);
                        }
                        catch (Jurassic.JavaScriptException e)
                        {
                            ErrorDispatcher.SendError(s.ScriptName, e.Message, e.LineNumber);
                        }
                    }
Esempio n. 8
0
        public static void Include(ScriptEngine eng, object a)
        {
            if (!(a is Undefined))
            {
                String filename = a.ToString();

                if (filename.Length > 3 && filename.EndsWith(".js"))
                {
                    if (bad_chars.Count <String>(x => filename.Contains(x)) == 0)
                    {
                        try
                        {
                            String path = Path.Combine(Server.DataPath, eng.UserData as string, filename);
                            eng.ExecuteFile(path);
                        }
                        catch (Jurassic.JavaScriptException e)
                        {
                            ErrorDispatcher.SendError(filename, e.Message, e.LineNumber);
                        }
                    }
                }
        public static void UpdateTimers()
        {
            ulong time = Server.Ticks;

            if (list.Count > 0)
            {
                for (int i = (list.Count - 1); i > -1; i--)
                {
                    if (list[i].StartTime <= (time - (ulong)list[i].Interval))
                    {
                        Instances.JSTimerInstance timer = list[i];
                        list.RemoveAt(i);
                        JSScript script = ScriptManager.Scripts.Find(x => x.ScriptName == timer.Engine.ScriptName);

                        if (script != null)
                        {
                            if (script.timer_idents.Contains(timer.IDENT))
                            {
                                try
                                {
                                    if (timer.Callback != null)
                                    {
                                        timer.Callback.Call(timer.Engine.Global);
                                    }
                                }
                                catch (JavaScriptException e)
                                {
                                    ErrorDispatcher.SendError(timer.ScriptName, e.Message, e.LineNumber);
                                }
                                catch { }
                            }
                        }
                    }
                }
            }
        }