Example #1
0
 /// <summary>
 /// Add handler for IPacket type receve
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="callback"></param>
 public void SetHandler<T>(Action<ClientType, T> callback) where T : class, IPacket
 {
     var cb = PacketCallback<ClientType>.Create<T>(callback);
     lock (_callbackLock)
     {
         if (_packetCallbacks.ContainsKey(cb.Type))
             _packetCallbacks[cb.Type] = cb;
         else
             _packetCallbacks.Add(cb.Type, cb);
     }
 }
Example #2
0
        private bool RaisePacketHandler(Type packetType, ClientType client, IPacket data)
        {
            PacketCallback<ClientType> callback = null;
            lock (_callbackLock)
            {
                if (_packetCallbacks.ContainsKey(packetType))
                    callback = _packetCallbacks[packetType];
            }

            if (callback == null)
            {
                return false;
            }

            callback?.Raise(client, data);
            return true;
        }
Example #3
0
        private bool RaisePacketHandler(Type packetType, ClientType client, IPacket data)
        {
            PacketCallback <ClientType> callback = null;

            lock (CallbackLock) {
                if (PacketCallbacks.ContainsKey(packetType))
                {
                    callback = PacketCallbacks[packetType];
                }
            }
            if (callback == null)
            {
                return(false);
            }
            else
            {
                callback?.Raise(client, data);
                return(true);
            }
        }