Exemplo n.º 1
0
        public void SetHandler <T>(Action <TClientType, T> callback) where T : class, IPacket
        {
            PacketCallback <TClientType> cb = PacketCallback <TClientType> .Create(callback);

            lock (_callbackLock) {
                if (_packetCallbacks.ContainsKey(cb.Type))
                {
                    _packetCallbacks[cb.Type] = cb;
                }
                else
                {
                    _packetCallbacks.Add(cb.Type, cb);
                }
            }
        }
Exemplo n.º 2
0
        private bool RaisePacketHandler(Type packetType, TClientType client, IPacket data)
        {
            PacketCallback <TClientType> callback = null;

            lock (_callbackLock) {
                if (_packetCallbacks.ContainsKey(packetType))
                {
                    callback = _packetCallbacks[packetType];
                }
            }

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

            callback.Raise(client, data);
            return(true);
        }