示例#1
0
        public static T ReadNext <T>(BinaryReader reader) where T : NetPacket
        {
            NetPacket packet = ReadNext(reader);

            if (!typeof(T).IsAssignableFrom(packet.GetType()))
            {
                throw new System.Exception("Invalid packet type \"" + packet.GetType() + "\" expected \"" + typeof(T) + "\"");
            }

            return((T)packet);
        }
示例#2
0
        protected virtual void OnPacket(NetPacket packet)
        {
            var type = packet.GetType();

            if (onPacketDelegateDict.TryGetValue(type, out var callbacks))
            {
                foreach (var callback in callbacks)
                {
                    callback.Invoke(packet);
                }
            }
        }