internal static NetworkChannelMessage ReadMessage(NetworkChannel channel, byte[] headerBuf)
        {
            int num = 0;

            NetworkChannelMessage.MessageType messageType = (NetworkChannelMessage.MessageType)Serialization.DeserializeUInt32(headerBuf, ref num);
            if (!NetworkChannelMessage.IsValidType(messageType))
            {
                throw new NetworkUnexpectedMessageException(channel.PartnerNodeName, string.Format("Unknown Type{0}", messageType));
            }
            int num2 = (int)Serialization.DeserializeUInt32(headerBuf, ref num);

            if (num2 < 16 || num2 > 1052672)
            {
                throw new NetworkUnexpectedMessageException(channel.PartnerNodeName, string.Format("Invalid msgLen: {0}", num2));
            }
            ExTraceGlobals.NetworkChannelTracer.TraceDebug <NetworkChannelMessage.MessageType, string, string>((long)channel.GetHashCode(), "ReadMessage: Received {0} from {1} on {2}", messageType, channel.RemoteEndPointString, channel.LocalEndPointString);
            byte[] array = new byte[num2];
            Array.Copy(headerBuf, 0, array, 0, 16);
            int len = num2 - 16;

            channel.Read(array, 16, len);
            NetworkChannelMessage.MessageType messageType2 = messageType;
            if (messageType2 <= NetworkChannelMessage.MessageType.BlockModeCompressedData)
            {
                if (messageType2 == NetworkChannelMessage.MessageType.PassiveStatus)
                {
                    return(new PassiveStatusMsg(channel, array));
                }
                if (messageType2 != NetworkChannelMessage.MessageType.BlockModeCompressedData)
                {
                    goto IL_118;
                }
            }
            else
            {
                if (messageType2 == NetworkChannelMessage.MessageType.Ping)
                {
                    return(new PingMessage(channel, array));
                }
                if (messageType2 != NetworkChannelMessage.MessageType.GranularLogData)
                {
                    if (messageType2 != NetworkChannelMessage.MessageType.EnterBlockMode)
                    {
                        goto IL_118;
                    }
                    return(new EnterBlockModeMsg(channel, array));
                }
            }
            throw new NetworkUnexpectedMessageException(channel.PartnerNodeName, string.Format("ReadMessage() does not support message type: {0}.", messageType));
IL_118:
            throw new NetworkUnexpectedMessageException(channel.PartnerNodeName, string.Format("Unknown message type: 0x{0:X}", (int)messageType));
        }
Exemple #2
0
        internal void ThrowUnexpectedMessage(NetworkChannelMessage msg)
        {
            NetworkUnexpectedMessageException ex = new NetworkUnexpectedMessageException(this.PartnerNodeName, msg.ToString());

            throw ex;
        }
Exemple #3
0
 internal NetworkChannelMessage GetMessage()
 {
     this.Read(this.m_tempHeaderBuf, 0, 16);
     return(NetworkChannelMessage.ReadMessage(this, this.m_tempHeaderBuf));
 }