Example #1
0
        public static object GetControlByID(ScriptEngine eng, object a)
        {
            if (!(a is Undefined))
            {
                String id = a.ToString();

                if (!String.IsNullOrEmpty(id))
                {
                    JSScript script = ScriptManager.Scripts.Find(x => x.ScriptName == eng.ScriptName);

                    if (script != null)
                    {
                        foreach (ICustomUI item in script.Elements)
                        {
                            if (!String.IsNullOrEmpty(item.ID))
                            {
                                if (item.ID == id)
                                {
                                    return(item);
                                }
                            }
                        }
                    }
                }
            }

            return(null);
        }
Example #2
0
        public static Objects.JSRoom GetRoom(ScriptEngine eng, object a)
        {
            if (!(a is Undefined))
            {
                String str = a.ToString();

                if (!String.IsNullOrEmpty(str))
                {
                    JSScript script = ScriptManager.Scripts.Find(x => x.ScriptName == eng.ScriptName);

                    if (script != null)
                    {
                        foreach (Objects.JSRoom r in script.Rooms)
                        {
                            if (r.R_Name == str)
                            {
                                return(r);
                            }
                        }

                        foreach (Objects.JSRoom r in script.Rooms)
                        {
                            if (r.R_Name.StartsWith(str))
                            {
                                return(r);
                            }
                        }
                    }
                }
            }

            return(null);
        }
Example #3
0
        public static void DoRoomsTask(ScriptEngine eng, object a)
        {
            if (a is UserDefinedFunction)
            {
                UserDefinedFunction f      = (UserDefinedFunction)a;
                JSScript            script = ScriptManager.Scripts.Find(x => x.ScriptName == eng.ScriptName);

                if (script != null)
                {
                    foreach (Objects.JSRoom r in script.Rooms)
                    {
                        try { f.Call(script.JS.Global, r); }
                        catch (Jurassic.JavaScriptException je)
                        {
                            ScriptManager.ErrorHandler(f.Engine.ScriptName, je.LineNumber, je.Message);
                        }
                    }
                }
Example #4
0
        public static bool DoInclude(ScriptEngine eng, object a)
        {
            if (!(a is Undefined))
            {
                String file = a.ToString();

                if (!String.IsNullOrEmpty(file))
                {
                    JSScript script = ScriptManager.Scripts.Find(x => x.ScriptName == eng.ScriptName);

                    if (script != null)
                    {
                        file = new String(file.Where(x => !Path.GetInvalidFileNameChars().Contains(x)).ToArray());
                        file = Path.Combine(script.ScriptPath, file);

                        if (new FileInfo(file).Directory.FullName != new DirectoryInfo(script.ScriptPath).FullName)
                        {
                            return(false);
                        }

                        try
                        {
                            script.JS.ExecuteFile(file);
                        }
                        catch (Jurassic.JavaScriptException je)
                        {
                            ScriptManager.ErrorHandler(script.ScriptName, je.LineNumber, je.Message);
                        }
                        catch { }

                        return(true);
                    }
                }
            }

            return(false);
        }
Example #5
0
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (e.Node == null)
            {
                return;
            }

            while (this.panel1.Controls.Count > 0)
            {
                this.panel1.Controls.RemoveAt(0);
            }

            if (e.Node.Equals(this.treeView1.Nodes[0]))
            {
                this.panel1.Controls.Add(this.client_settings);
            }
            else if (e.Node.Equals(this.treeView1.Nodes[1]))
            {
                this.panel1.Controls.Add(this.global_settings);
            }
            else if (e.Node.Equals(this.treeView1.Nodes[2]))
            {
                this.panel1.Controls.Add(this.hashlink_settings);
            }
            else if (e.Node.Equals(this.treeView1.Nodes[3]))
            {
                this.panel1.Controls.Add(this.personal_settings);
            }
            else if (e.Node.Equals(this.treeView1.Nodes[4]))
            {
                this.panel1.Controls.Add(this.audio_settings);
            }
            else if (e.Node.Equals(this.treeView1.Nodes[5]))
            {
                this.panel1.Controls.Add(this.filter_settings);
            }
            else if (e.Node.Equals(this.treeView1.Nodes[6]))
            {
                this.panel1.Controls.Add(this.menu_settings);
            }
            else if (e.Node.Equals(this.treeView1.Nodes[7]))
            {
                this.panel1.Controls.Add(this.privacy_settings);
            }
            else
            {
                String             script_name = e.Node.Text;
                Scripting.JSScript script      = Scripting.ScriptManager.Scripts.Find(x => x.ScriptName == script_name);

                if (script != null)
                {
                    if (script.UI.UIPanel != null)
                    {
                        this.panel1.Controls.Add(script.UI.UIPanel);

                        Scripting.ScriptManager.PendingUIEvents.Enqueue(new Scripting.JSUIEventItem
                        {
                            Arg       = script.ScriptName,
                            EventType = Scripting.JSUIEventType.UISelected
                        });
                    }
                }
            }
        }
Example #6
0
        public static void EventCycle(ulong time)
        {
            JSTimers.ServiceTimers(time);

            if (PendingTerminators.Pending)
            {
                IPEndPoint ep = null;

                while (PendingTerminators.TryDequeue(out ep))
                {
                    ClearUsers(ep);
                    ScriptEvents.OnRoomClosed(ep);

                    foreach (JSScript script in Scripts)
                    {
                        script.Rooms.RemoveAll(x => x.EndPoint.Equals(ep));
                    }
                }
            }

            if (PendingUIText.Pending)
            {
                JSOutboundTextItem item = null;

                while (PendingUIText.TryDequeue(out item))
                {
                    Room r = RoomPool.Rooms.Find(x => x.EndPoint.Equals(item.EndPoint));

                    if (r != null)
                    {
                        if (item.Type == JSOutboundTextItemType.Command)
                        {
                            String str = ScriptEvents.OnCommandSending(r, item.Text);

                            if (!String.IsNullOrEmpty(str))
                            {
                                r.SendCommand(str);
                            }
                        }
                        else if (item.Type == JSOutboundTextItemType.Public)
                        {
                            String str = ScriptEvents.OnTextSending(r, item.Text);

                            if (!String.IsNullOrEmpty(str))
                            {
                                r.SendText(str);
                            }
                        }
                        else if (item.Type == JSOutboundTextItemType.Emote)
                        {
                            String str = ScriptEvents.OnEmoteSending(r, item.Text);

                            if (!String.IsNullOrEmpty(str))
                            {
                                r.SendEmote(str);
                            }
                        }
                        else if (item.Type == JSOutboundTextItemType.Private)
                        {
                            String str = ScriptEvents.OnPmSending(r, item.Name, item.Text);

                            if (!String.IsNullOrEmpty(str))
                            {
                                r.SendPM(item.Name, str);
                            }
                        }
                        else if (item.Type == JSOutboundTextItemType.Link)
                        {
                            if (ScriptEvents.OnLinkClicked(r, item.Text))
                            {
                                try
                                {
                                    Process.Start(item.Text);
                                }
                                catch { }
                            }
                        }
                        else if (item.Type == JSOutboundTextItemType.ChatScreenCallback)
                        {
                            ScriptEvents.OnScreenCallback(r, item.Name, item.Text);
                        }
                    }
                }
            }

            if (PendingUIEvents.Pending)
            {
                JSUIEventItem item = null;

                while (PendingUIEvents.TryDequeue(out item))
                {
                    if (item.EventType == JSUIEventType.KeyPressed)
                    {
                        item.Element.KeyPressCallback((int)item.Arg);
                    }
                    else if (item.EventType == JSUIEventType.ValueChanged)
                    {
                        item.Element.ValueChangedCallback();
                    }
                    else if (item.EventType == JSUIEventType.Click)
                    {
                        item.Element.ClickCallback();
                    }
                    else if (item.EventType == JSUIEventType.Select)
                    {
                        item.Element.SelectCallback();
                    }
                    else if (item.EventType == JSUIEventType.ItemDoubleClick)
                    {
                        item.Element.ItemDoubleClickCallback();
                    }
                    else if (item.EventType == JSUIEventType.SelectedItemChanged)
                    {
                        item.Element.SelectedItemChangedCallback();
                    }
                    else if (item.EventType == JSUIEventType.UISelected)
                    {
                        ScriptEvents.OnUISelected((String)item.Arg);
                    }
                    else if (item.EventType == JSUIEventType.RoomOpened)
                    {
                        ScriptEvents.OnRoomOpened((IPEndPoint)item.Arg);
                    }
                    else if (item.EventType == JSUIEventType.RoomClosed)
                    {
                        ScriptEvents.OnRoomClosed((IPEndPoint)item.Arg);
                    }
                }
            }

            if (PendingPopupCallbacks.Pending)
            {
                JSUIPopupCallback item = null;

                while (PendingPopupCallbacks.TryDequeue(out item))
                {
                    JSScript script = Scripts.Find(x => x.ScriptName == item.Callback.Engine.ScriptName);

                    if (script != null)
                    {
                        Objects.JSRoom room = script.Rooms.Find(x => x.EndPoint.Equals(item.Room));

                        if (room != null)
                        {
                            try { item.Callback.Call(script.JS.Global, room); }
                            catch (Jurassic.JavaScriptException je)
                            {
                                ScriptManager.ErrorHandler(script.ScriptName, je.LineNumber, je.Message);
                            }
                        }