Ejemplo n.º 1
0
        public static ServerTcpMessage[] Unpack(/*ServerType serverType,*/ byte[] responseData)
        {
            DebugUtils.Assert(responseData != null && responseData.Length > 0, "Response data is null!");

            using (ByteStreamReader reader = new ByteStreamReader(responseData))
            {
                long serverId = reader.ReadLong();
                ClientTcpMessage.sessionId = reader.ReadInt(); //if sessionId is 4 bytes, that's OK.
                int msgNum = reader.ReadByte();
                ServerTcpMessage[] responseMessages = new ServerTcpMessage[msgNum];
                for (int i = 0; i < msgNum; i++)
                {
                    int  len  = reader.ReadShort();
                    int  code = reader.ReadInt();
                    long seq  = reader.ReadLong();

                    if (Enum.IsDefined(typeof(MsgCode), code))
                    {
                        responseMessages[i] = new ServerTcpMessage((MsgCode)code, seq, reader.ReadBytes(len));
                        DebugUtils.Log(DebugUtils.Type.Protocol, "Receive network message, protocol code " + code);
                    }
                    else
                    {
                        DebugUtils.LogError(DebugUtils.Type.Protocol, "For now, the client can't recognize the received protocol code " + code);
                    }
                }

                return(responseMessages);
            }
        }