示例#1
0
        /// <summary>
        /// Register a callback to a name with the given metadata.
        /// </summary>
        public void Register(string eventName, SocketIOCallback callback, bool onlyOnce, bool autoDecodePayload)
        {
            List <EventDescriptor> events;

            if (!Table.TryGetValue(eventName, out events))
            {
                Table.Add(eventName, events = new List <EventDescriptor>(1));
            }

            // Find a matching desriptor
            var desc = events.Find((d) => d.OnlyOnce == onlyOnce && d.AutoDecodePayload == autoDecodePayload);

            // If not found, create one
            if (desc == null)
            {
                events.Add(new EventDescriptor(onlyOnce, autoDecodePayload, callback));
            }
            else // if found, add the new callback
            {
                desc.Callbacks.Add(callback);
            }

            // Log
            Log();
        }
 /// <summary>
 /// 
 /// </summary>
 public void Unregister(string eventName, SocketIOCallback callback)
 {
     List<EventDescriptor> events;
     if (Table.TryGetValue(eventName, out events))
         for (int i = 0; i < events.Count; ++i)
             events[i].Callbacks.Remove(callback);
 }
        /// <summary>
        /// Constructor to create an EventDescriptor instance and set the meta-datas.
        /// </summary>
        public EventDescriptor(bool onlyOnce, bool autoDecodePayload, SocketIOCallback callback)
        {
            this.OnlyOnce = onlyOnce;
            this.AutoDecodePayload = autoDecodePayload;
            this.Callbacks = new List<SocketIOCallback>(1);

            if (callback != null)
                Callbacks.Add(callback);
        }
 public EventDescriptor(bool onlyOnce, bool autoDecodePayload, SocketIOCallback callback)
 {
     this.OnlyOnce          = onlyOnce;
     this.AutoDecodePayload = autoDecodePayload;
     this.Callbacks         = new List <SocketIOCallback>(1);
     if (callback != null)
     {
         this.Callbacks.Add(callback);
     }
 }
示例#5
0
 public void Unregister(string eventName, SocketIOCallback callback)
 {
     if (Table.TryGetValue(eventName, out List <EventDescriptor> value))
     {
         for (int i = 0; i < value.Count; i++)
         {
             value[i].Callbacks.Remove(callback);
         }
     }
 }
示例#6
0
        /// <summary>
        ///
        /// </summary>
        public void Unregister(string eventName, SocketIOCallback callback)
        {
            List <EventDescriptor> events;

            if (Table.TryGetValue(eventName, out events))
            {
                for (int i = 0; i < events.Count; ++i)
                {
                    events[i].Callbacks.Remove(callback);
                }
            }
        }
示例#7
0
        public void Unregister(string eventName, SocketIOCallback callback)
        {
            List <EventDescriptor> list;

            if (this.Table.TryGetValue(eventName, out list))
            {
                for (int i = 0; i < list.Count; i++)
                {
                    list[i].Callbacks.Remove(callback);
                }
            }
        }
        /// <summary>
        /// Register a callback to a name with the given metadata.
        /// </summary>
        public void Register(string eventName, SocketIOCallback callback, bool onlyOnce, bool autoDecodePayload)
        {
            List<EventDescriptor> events;
            if (!Table.TryGetValue(eventName, out events))
                Table.Add(eventName, events = new List<EventDescriptor>(1));

            // Find a matching desriptor
            var desc = events.Find((d) => d.OnlyOnce == onlyOnce && d.AutoDecodePayload == autoDecodePayload);

            // If not found, create one
            if (desc == null)
                events.Add(new EventDescriptor(onlyOnce, autoDecodePayload, callback));
            else // if found, add the new callback
                desc.Callbacks.Add(callback);
        }
示例#9
0
        /// <summary>
        /// Will call the callback delegates with the given parameters and remove the callbacks if this descriptor marked with a true OnlyOnce property.
        /// </summary>
        public void Call(Socket socket, Packet packet, params object[] args)
        {
            int callbackCount = Callbacks.Count;

            if (CallbackArray == null || CallbackArray.Length < callbackCount)
            {
                Array.Resize(ref CallbackArray, callbackCount);
            }

            // Copy the callback delegates to an array, because in one of the callbacks we can modify the list(by calling On/Once/Off in an event handler)
            // This way we can prevent some strange bug
            Callbacks.CopyTo(CallbackArray);

            // Go through the delegates and call them
            for (int i = 0; i < callbackCount; ++i)
            {
                try
                {
                    // Call the delegate.
                    SocketIOCallback callback = CallbackArray[i];
                    if (callback != null)
                    {
                        callback(socket, packet, args);
                    }
                }
                catch (Exception ex)
                {
                    // Do not try to emit a new Error when we already tried to deliver an Error, possible causing a
                    //  stack overflow
                    if (args == null || args.Length == 0 || !(args[0] is Error))
                    {
                        (socket as ISocket).EmitError(SocketIOErrors.User, ex.Message + " " + ex.StackTrace);
                    }

                    HTTPManager.Logger.Exception("EventDescriptor", "Call", ex);
                }

                // If these callbacks has to be called only once, remove them from the main list
                if (this.OnlyOnce)
                {
                    Callbacks.Remove(CallbackArray[i]);
                }

                // Don't keep any reference avoiding memory leaks
                CallbackArray[i] = null;
            }
        }
示例#10
0
        public void Register(string eventName, SocketIOCallback callback, bool onlyOnce, bool autoDecodePayload)
        {
            if (!Table.TryGetValue(eventName, out List <EventDescriptor> value))
            {
                Table.Add(eventName, value = new List <EventDescriptor>(1));
            }
            EventDescriptor eventDescriptor = value.Find((EventDescriptor d) => d.OnlyOnce == onlyOnce && d.AutoDecodePayload == autoDecodePayload);

            if (eventDescriptor == null)
            {
                value.Add(new EventDescriptor(onlyOnce, autoDecodePayload, callback));
            }
            else
            {
                eventDescriptor.Callbacks.Add(callback);
            }
        }
示例#11
0
        /// <summary>
        /// Will call the callback delegates with the given parameters and remove the callbacks if this descriptor marked with a true OnlyOnce property.
        /// </summary>
        public void Call(Socket socket, Packet packet, params object[] args)
        {
            if (CallbackArray == null || CallbackArray.Length < Callbacks.Count)
            {
                Array.Resize(ref CallbackArray, Callbacks.Count);
            }

            // Copy the callback delegates to an array, because in one of the callbacks we can modify the list(by calling On/Once/Off in an event handler)
            // This way we can prevent some strange bug
            Callbacks.CopyTo(CallbackArray);

            // Go through the delegates and call them
            for (int i = 0; i < CallbackArray.Length; ++i)
            {
                try
                {
                    // Call the delegate.
                    SocketIOCallback callback = CallbackArray[i];
                    if (callback != null)
                    {
                        callback(socket, packet, args);
                    }
                }
                catch (Exception ex)
                {
                    (socket as ISocket).EmitError(SocketIOErrors.User, ex.Message + " " + ex.StackTrace);

                    HTTPManager.Logger.Exception("EventDescriptor", "Call", ex);

                    SocketIOController.Instance.LogInWaitingUI(ex.Message + " " + ex.StackTrace);
                    SocketIOController.Instance.LoginBattleUI(ex.Message + " " + ex.StackTrace);
                }

                // If these callbacks has to be called only once, remove them from the main list
                if (this.OnlyOnce)
                {
                    Callbacks.Remove(CallbackArray[i]);
                }

                // Don't keep any reference avoiding memory leaks
                CallbackArray[i] = null;
            }
        }
示例#12
0
 public void On(string eventName, SocketIOCallback callback, bool autoDecodePayload)
 {
     this.EventCallbacks.Register(eventName, callback, false, autoDecodePayload);
 }
示例#13
0
 /// <summary>
 /// Register a callback for a given name
 /// </summary>
 public void On(string eventName, SocketIOCallback callback)
 {
     EventCallbacks.Register(eventName, callback, false, this.AutoDecodePayload);
 }
示例#14
0
        public void On(SocketIOEventTypes type, SocketIOCallback callback, bool autoDecodePayload)
        {
            string nameFor = EventNames.GetNameFor(type);

            EventCallbacks.Register(nameFor, callback, onlyOnce: false, autoDecodePayload);
        }
示例#15
0
 public void Once(string eventName, SocketIOCallback callback)
 {
     this.EventCallbacks.Register(eventName, callback, true, this.AutoDecodePayload);
 }
示例#16
0
 public void Register(string eventName, SocketIOCallback callback, bool onlyOnce, bool autoDecodePayload)
 {
示例#17
0
 public void Once(string eventName, SocketIOCallback callback)
 {
     EventCallbacks.Register(eventName, callback, onlyOnce: true, AutoDecodePayload);
 }
示例#18
0
 /// <summary>
 /// Remove the specified callback.
 /// </summary>
 public void Off(SocketIOEventTypes type, SocketIOCallback callback)
 {
     EventCallbacks.Unregister(EventNames.GetNameFor(type), callback);
 }
示例#19
0
 public void Off(string eventName, SocketIOCallback fn)
 {
     m_SocketManager.Socket.Off(eventName, fn);
 }
示例#20
0
        public void On(SocketIOEventTypes type, SocketIOCallback callback)
        {
            string nameFor = EventNames.GetNameFor(type);

            this.EventCallbacks.Register(nameFor, callback, false, this.AutoDecodePayload);
        }
示例#21
0
 /// <summary>
 /// Remove the specified callback.
 /// </summary>
 public void Off(string eventName, SocketIOCallback callback)
 {
     EventCallbacks.Unregister(eventName, callback);
 }
示例#22
0
 /// <summary>
 /// Remove the specified callback.
 /// </summary>
 public void Off(string eventName, SocketIOCallback callback)
 {
     EventCallbacks.Unregister(eventName, callback);
 }
示例#23
0
 public void Once(string eventName, SocketIOCallback callback, bool autoDecodePayload)
 {
     EventCallbacks.Register(eventName, callback, true, autoDecodePayload);
 }
示例#24
0
 /// <summary>
 /// Register a callback for a given name
 /// </summary>
 public void On(string eventName, SocketIOCallback callback)
 {
     EventCallbacks.Register(eventName, callback, false, this.AutoDecodePayload);
 }
示例#25
0
 public void On(string socket_event, SocketIOCallback socket_callback)
 {
     socket.On(socket_event, socket_callback);
 }
示例#26
0
 public void Off(SocketIOEventTypes eventTypes, SocketIOCallback fn)
 {
     m_SocketManager.Socket.Off(eventTypes, fn);
 }
示例#27
0
        public void On(SocketIOEventTypes type, SocketIOCallback callback, bool autoDecodePayload)
        {
            string eventName = EventNames.GetNameFor(type);

            EventCallbacks.Register(eventName, callback, false, autoDecodePayload);
        }
示例#28
0
        public void On(SocketIOEventTypes type, SocketIOCallback callback, bool autoDecodePayload)
        {
            string eventName = EventNames.GetNameFor(type);

            EventCallbacks.Register(eventName, callback, false, autoDecodePayload);
        }
示例#29
0
 public void Once(SocketIOEventTypes type, SocketIOCallback callback, bool autoDecodePayload)
 {
     EventCallbacks.Register(EventNames.GetNameFor(type), callback, true, autoDecodePayload);
 }
示例#30
0
 public void Once(string eventName, SocketIOCallback callback, bool autoDecodePayload)
 {
     EventCallbacks.Register(eventName, callback, true, autoDecodePayload);
 }
示例#31
0
 /// <summary>
 /// Remove the specified callback.
 /// </summary>
 public void Off(SocketIOEventTypes type, SocketIOCallback callback)
 {
     EventCallbacks.Unregister(EventNames.GetNameFor(type), callback);
 }
示例#32
0
 public void Once(SocketIOEventTypes type, SocketIOCallback callback, bool autoDecodePayload)
 {
     EventCallbacks.Register(EventNames.GetNameFor(type), callback, true, autoDecodePayload);
 }