RemoteChannelBase GetRemoteChannelFromPacket(RemoteChannelType type, ushort channelId)
        {
            RemoteChannel      channel;
            StateRemoteChannel stateChannel;

            if (type == RemoteChannelType.Core)
            {
                return((channelId == GlobalChannel.Id) ? GlobalChannel : HiddenChannel);
            }
            else if (type == RemoteChannelType.State)
            {
                if (!StateChannels.TryGetValue(channelId, out stateChannel))
                {
                    NetLogger.LogError("Failed to retreive state channel of id {0}, it doesn't exist!", channelId);
                }

                return(stateChannel);
            }
            else
            {
                if (!Channels.TryGetValue(channelId, out channel))
                {
                    NetLogger.LogError("Failed to retreive channel of id {0}, it doesn't exist!", channelId);
                }

                return(channel);
            }
        }
        internal RemoteChannelBase(ushort id, RemoteChannelType type, NetMessenger messenger)
        {
            this.Id        = id;
            this.Type      = type;
            this.Messenger = messenger;

            Events           = new ConcurrentDictionary <string, RemoteEvent>();
            Functions        = new ConcurrentDictionary <string, RemoteFunction>();
            WaitingFunctions = new ConcurrentDictionary <ushort, RemoteFunctionCallback>();
        }
        void HandleRemotePacket(NetInboundPacket packet)
        {
            // Read the remote header
            RemoteChannelType type      = (RemoteChannelType)packet.ReadByte();
            ushort            channelId = packet.ReadUInt16();

            // Attempt to locate the channel
            RemoteChannelBase channel = GetRemoteChannelFromPacket(type, channelId);

            if (channel != null)
            {
                inboundRemotes.Enqueue(new InboundRemote(packet, channel));
            }
        }