public void HandleMessage(byte[] data, int size) { if (data.Length == 0 || 0 == size) { LogSystem.LogError("Error, HandleMessage data is 0 "); return; } GlobalServerMsg protocolId = (GlobalServerMsg)data[0]; bool is_compressed = false; switch (protocolId) { case GlobalServerMsg.SERVER_MSG_BATCH_COMPRESS: { protocolId = GlobalServerMsg.SERVER_MSG_BATCH_COMPRESS; is_compressed = true; } break; case GlobalServerMsg.SERVER_IDLE: { return; //不处理 } case GlobalServerMsg.SERVER_CP_LOGIN_SUCCEED: is_compressed = true; protocolId = GlobalServerMsg.SERVER_LOGIN_SUCCEED; break; case GlobalServerMsg.SERVER_CP_PROPERTY_TABLE: is_compressed = true; protocolId = GlobalServerMsg.SERVER_PROPERTY_TABLE; break; case GlobalServerMsg.SERVER_CP_RECORD_TABLE: is_compressed = true; protocolId = GlobalServerMsg.SERVER_RECORD_TABLE; break; case GlobalServerMsg.SERVER_CP_CUSTOM: is_compressed = true; protocolId = GlobalServerMsg.SERVER_CUSTOM; break; case GlobalServerMsg.SERVER_CP_ADD_OBJECT: is_compressed = true; protocolId = GlobalServerMsg.SERVER_ADD_OBJECT; break; case GlobalServerMsg.SERVER_CP_RECORD_ADDROW: is_compressed = true; protocolId = GlobalServerMsg.SERVER_RECORD_ADDROW; break; case GlobalServerMsg.SERVER_CP_VIEW_ADD: is_compressed = true; protocolId = GlobalServerMsg.SERVER_VIEW_ADD; break; case GlobalServerMsg.SERVER_CP_ALL_DEST: is_compressed = true; protocolId = GlobalServerMsg.SERVER_ALL_DEST; break; case GlobalServerMsg.SERVER_CP_ALL_DEST_EX: is_compressed = true; protocolId = GlobalServerMsg.SERVER_ALL_DEST_EX; break; case GlobalServerMsg.SERVER_CP_ALL_PROP: is_compressed = true; protocolId = GlobalServerMsg.SERVER_ALL_PROP; break; case GlobalServerMsg.SERVER_CP_ADD_MORE_OBJECT: is_compressed = true; protocolId = GlobalServerMsg.SERVER_ADD_MORE_OBJECT; break; case GlobalServerMsg.SERVER_CP_LOCATION_GRID: is_compressed = true; protocolId = GlobalServerMsg.SERVER_LOCATION_GRID; break; case GlobalServerMsg.SERVER_CP_MOVING_GRID: is_compressed = true; protocolId = GlobalServerMsg.SERVER_MOVING_GRID; break; case GlobalServerMsg.SERVER_CP_ALL_DEST_GRID: is_compressed = true; protocolId = GlobalServerMsg.SERVER_ALL_DEST_GRID; break; default: is_compressed = false; break; } if (is_compressed) { int origin_size = QuickLZ.sizeDecompressed(data); if (origin_size > (65535 - 1)) { LogSystem.Log("(GameReceiver::ProcessMessage)decompress size error"); return; } data = QuickLZ.decompress(data); data[0] = System.Convert.ToByte(protocolId); size = origin_size + 1; } if (GlobalServerMsg.SERVER_MSG_BATCH_COMPRESS == (GlobalServerMsg)data[0]) { byte nRecvPrior = 0; int nRecvCount = 0; for (int i = 1; i < size; ++i) { if ((0xEE == data[i]) && (0xEE == nRecvPrior)) { nRecvCount--; if (nRecvCount > 0) { HandleMessage(m_pBuffer_Batch, nRecvCount); } nRecvPrior = 0; nRecvCount = 0; continue; } else if ((0 == data[i]) && (0xEE == nRecvPrior)) { } else { if (nRecvCount < m_pBuffer_Batch.Length) { m_pBuffer_Batch[nRecvCount++] = data[i]; } else { // 出错了 } } nRecvPrior = data[i]; } return; } if (m_bSimpleProtocal) { InnerSimpleProtocal(ref data, size); } //LogSystem.Log( "Receive msg id = " , protocolId ); //根据不同的协议ID进行消息分发 ExcuteEvent(protocolId, data, size); }
public void HandleMessage(byte[] data, int size) { if (data.Length == 0 || 0 == size) { Log.TraceError("Error, HandleMessage data is 0 "); return; } //byte[] byteTemp = new byte[size]; //System.Array.Copy(data, 0, byteTemp, 0, size); //init LoadArchive //LoadArchive loadAr = new LoadArchive(byteTemp, 0, byteTemp.Length); //LoadArchive loadAr = new LoadArchive(data, 0, size); int protocolId = data[0]; /*int protocolId = 0; * bool bRet = loadAr.ReadInt8(ref protocolId); * if (!bRet) * { * //Log.Trace("SocketReceiveHandle::HandleMessage parse get protocol id failed!"); * return; * }*/ //if (protocolId == GlobalServerMsg.SERVER_IDLE) //{ // //不处理 // return; //} /* * LoadArchive loadAr = new LoadArchive(data, 0, data.Length); * loadAr.Seek(1); * * int nArgNum = 0; * loadAr.ReadInt16(ref nArgNum); * int nType = 0; * loadAr.ReadInt8(ref nType); * int value = 0; * loadAr.ReadInt32(ref value); * * if (value.Equals(1401)) * { * loadAr.ReadInt8(ref nType); * int type = 0; * loadAr.ReadInt32(ref type); * if (type.Equals(1)) * { * Log.Trace("Receive msg id = " + value); * } * } */ ExcuteEvent(protocolId, data); if (protocolId.Equals(GlobalServerMsg.SERVER_CP_CUSTOM)) { byte[] content = new byte[data.Length - 1]; System.Array.Copy(data, 1, content, 0, content.Length); byte[] contentBytes = QuickLZ.decompress(content); byte[] dataTemp = new byte[contentBytes.Length + 1]; System.Array.Copy(data, 0, dataTemp, 0, 1); //拷贝消息id System.Array.Copy(contentBytes, 0, dataTemp, 1, contentBytes.Length); //拷贝解压后消息体(除去消息头) data = dataTemp; } if (protocolId.Equals(GlobalServerMsg.SERVER_CUSTOM) || protocolId.Equals(GlobalServerMsg.SERVER_CP_CUSTOM)) { LoadArchive loadAr = new LoadArchive(data, 0, data.Length); loadAr.Seek(1); int nArgNum = 0; loadAr.ReadInt16(ref nArgNum); int nType = 0; loadAr.ReadInt8(ref nType); loadAr.ReadInt32(ref protocolId); } CustomSystem.Instance.dispacthEvent(0, protocolId); }