Exemplo n.º 1
0
        public static bool ClearTimeout(object a)
        {
            if (!(a is Undefined))
            {
                int i;

                if (int.TryParse(a.ToString(), out i))
                {
                    return(JSTimers.Remove(i));
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        public void ResetScript()
        {
            JSTimers.ClearTimers(this.ScriptName);
            this.EVENT_ONANNOUNCERECEIVED   = null;
            this.EVENT_ONANNOUNCERECEIVING  = null;
            this.EVENT_ONCOMMANDSENDING     = null;
            this.EVENT_ONCONNECTED          = null;
            this.EVENT_ONCONNECTING         = null;
            this.EVENT_ONCUSTOMDATARECEIVED = null;
            this.EVENT_ONDISCONNECTED       = null;
            this.EVENT_ONEMOTERECEIVED      = null;
            this.EVENT_ONEMOTERECEIVING     = null;
            this.EVENT_ONEMOTESENDING       = null;
            this.EVENT_ONLOAD                     = null;
            this.EVENT_ONNUDGERECEIVING           = null;
            this.EVENT_ONPMRECEIVED               = null;
            this.EVENT_ONPMRECEIVING              = null;
            this.EVENT_ONPMSENDING                = null;
            this.EVENT_ONREDIRECTING              = null;
            this.EVENT_ONSCRIBBLERECEIVED         = null;
            this.EVENT_ONSCRIBBLERECEIVING        = null;
            this.EVENT_ONSONGCHANGED              = null;
            this.EVENT_ONTEXTRECEIVED             = null;
            this.EVENT_ONTEXTRECEIVING            = null;
            this.EVENT_ONTEXTSENDING              = null;
            this.EVENT_ONTIMER                    = null;
            this.EVENT_ONTOPICRECEIVING           = null;
            this.EVENT_ONURLRECEIVING             = null;
            this.EVENT_ONUSERAVATARRECEIVING      = null;
            this.EVENT_ONUSERFONTCHANGING         = null;
            this.EVENT_ONUSERJOINED               = null;
            this.EVENT_ONUSERJOINING              = null;
            this.EVENT_ONUSERLEVELCHANGED         = null;
            this.EVENT_ONUSERLISTRECEIVED         = null;
            this.EVENT_ONUSERMESSAGERECEIVING     = null;
            this.EVENT_ONUSERONLINESTATUSCHANGED  = null;
            this.EVENT_ONUSERPARTED               = null;
            this.EVENT_ONUSERPARTING              = null;
            this.EVENT_ONUSERWRITINGSTATUSCHANGED = null;
            this.EVENT_ONVOICECLIPRECEIVED        = null;
            this.EVENT_ONVOICECLIPRECEIVING       = null;

            for (int i = (this.Rooms.Count - 1); i > -1; i--)
            {
                for (int x = (this.Rooms[i].UserList.Count - 1); x > -1; x--)
                {
                    this.Rooms[i].UserList[x].SetToNull();
                    this.Rooms[i].UserList.RemoveAt(x);
                }

                this.Rooms.RemoveAt(i);
            }

            Type[] types = Assembly.GetExecutingAssembly().GetTypes();

            this.JS            = new ScriptEngine();
            this.JS.ScriptName = this.ScriptName;
            this.JS.EmbedGlobalClass(typeof(JSGlobal));
            this.JS.EmbedStatics(types.Where(x => x.Namespace == "cb0t.Scripting.Statics" && x.IsSubclassOf(typeof(ObjectInstance))).ToArray());
            this.JS.EmbedInstances(types.Where(x => x.Namespace == "cb0t.Scripting.Instances" && x.IsSubclassOf(typeof(ClrFunction))).ToArray());
            this.JS.EmbedObjectPrototypes(types.Where(x => x.Namespace == "cb0t.Scripting.ObjectPrototypes" && x.IsSubclassOf(typeof(ClrFunction))).ToArray());

            foreach (Room room in RoomPool.Rooms)
            {
                this.Rooms.Add(new Objects.JSRoom(this.JS.Object.InstancePrototype, room.EndPoint, room.Credentials));

                foreach (User user in room.UserPool)
                {
                    this.Rooms[this.Rooms.Count - 1].UserList.Add(new Objects.JSUser(this.JS.Object.InstancePrototype, user, room.EndPoint));
                }
            }
        }
Exemplo n.º 3
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);
                            }
                        }