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); }
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); } } }