/** 发送数据 **/
        //有问题
        public bool send(int main, int sub, byte[] data, int size)
        {
            if (!isAlive())
            {
                return(false);
            }
            //构造数据
            byte[] cbDataBuffer = new byte[Packet.SOCKET_TCP_BUFFER];

            Packet.TCP_Head pHead = new Packet.TCP_Head();

            pHead.CommandInfo.wMainCmdID = (ushort)main;
            pHead.CommandInfo.wSubCmdID  = (ushort)sub;

            byte[] structData = StructConverterByteArray.StructToBytes(pHead);
            Buffer.BlockCopy(structData, 0, cbDataBuffer, 0, structData.Length);
            if (size > 0)
            {
                Buffer.BlockCopy(data, 0, cbDataBuffer, structData.Length, size);
                //memcpy(pHead + 1, data, dataSize);
            }
            //加密数据
            uint wSendSize = EncryptBuffer(ref cbDataBuffer, (uint)(Packet.SizeOfTCP_Head + size), (uint)cbDataBuffer.Length);

            mSocket.send(cbDataBuffer, (int)wSendSize);
            return(true);
        }
        //////////////////////////////////////////////////////////////////////////
        // ISocketEngineSink

        public override void onEventTCPSocketLink()
        {
            //变量定义


            switch (mMissionType)
            {
            case Type.MISSION_SEND_CHAT_DATA:
            {
                CMD_GP_CHAT kNetInfo = new CMD_GP_CHAT();
                kNetInfo.Init();

                GlobalUserInfo    pGlobalUserInfo = GlobalUserInfo.GetInstance();
                tagGlobalUserData pGlobalUserData = pGlobalUserInfo.GetGlobalUserData();
                kNetInfo.dwUserID = pGlobalUserData.dwUserID;

                Buffer.BlockCopy(pGlobalUserData.szNickName, 0, kNetInfo.szNickName, 0, pGlobalUserData.szNickName.Length);

                var szChatData = Encoding.UTF8.GetBytes(m_chatText);
                Buffer.BlockCopy(szChatData, 0, kNetInfo.szChatData, 0, szChatData.Length);

                Buffer.BlockCopy(pGlobalUserData.szHeadHttp, 0, kNetInfo.szHeadHttp, 0, pGlobalUserData.szHeadHttp.Length);

                var buf = StructConverterByteArray.StructToBytes(kNetInfo);
                send(MsgDefine.MDM_GP_USER_SERVICE, MsgDefine.SUB_GP_LOBBY_CHAT, buf, buf.Length);

                break;
            }

            default:
                stop();
                break;
            }
        }
Beispiel #3
0
        //功能函数
        //插入数据
        public bool AddPacket(byte[] pData, ushort wDataType)
        {
            if ((pData.Length + Marshal.SizeOf(m_ttagDataDescribe) + m_wDataSize) > m_wMaxBytes)
            {
                return(false);
            }

            //插入数据
            tagDataDescribe pDataDescribe = new tagDataDescribe();

            pDataDescribe.wDataSize     = (ushort)pData.Length;
            pDataDescribe.wDataDescribe = wDataType;
            var buf = StructConverterByteArray.StructToBytes(pDataDescribe);

            Buffer.BlockCopy(buf, 0, m_pcbBuffer, m_wDataSize, buf.Length);
            //tagDataDescribe* pDataDescribe = (tagDataDescribe*)(m_pcbBuffer + m_wDataSize);
            //pDataDescribe->wDataSize = wDataSize;
            //pDataDescribe->wDataDescribe = wDataType;

            //插入数据
            if (pData.Length > 0)
            {
                Buffer.BlockCopy(pData, 0, m_pcbBuffer, m_wDataSize + buf.Length, pData.Length);
                //memcpy(pDataDescribe + 1, pData, wDataSize);
            }

            //设置数据
            m_wDataSize += (ushort)(buf.Length + pData.Length);

            return(true);
        }
        public virtual void OnSocketSubPrivateInfo(CMD_GR_Private_Info pNetInfo)
        {
            Loom.QueueOnMainThread(() =>
            {
                m_kPrivateInfo = pNetInfo;

                if (m_eLinkAction == Type_LinkAction.Type_Link_Create)
                {
                    var buf = StructConverterByteArray.StructToBytes(m_kCreatePrivateNet);
                    CServerItem.get().SendSocketData(GameServerDefines.MDM_GR_PRIVATE, GameServerDefines.SUB_GR_CREATE_PRIVATE, buf, (ushort)buf.Length);
                    //zeromemory(&m_kCreatePrivateNet, sizeof(m_kCreatePrivateNet));
                    m_kCreatePrivateNet = new CMD_GR_Create_Private();
                }
                if (m_eLinkAction == Type_LinkAction.Type_Link_Join)
                {
                    CMD_GR_Join_Private kSendNet;
                    kSendNet.dwRoomNum           = (uint)m_iJoinRoomId; //utility::parseInt(m_kJoinNumTxt); // lin Temp do this
                    kSendNet.cbGameTypeIdex      = m_cbGameTypeIdex;    //WQ add
                    kSendNet.cbChoosedModelIndex = (byte)PlayerPrefs.GetInt("ChoosedModelIndex");

                    Debug.Log("OnSocketSubPrivateInfo Type_Link_Join: m_cbGameTypeIdex=" + m_cbGameTypeIdex);

                    var buf = StructConverterByteArray.StructToBytes(kSendNet);
                    CServerItem.get().SendSocketData(GameServerDefines.MDM_GR_PRIVATE, GameServerDefines.SUB_GR_JOIN_PRIVATE, buf, (ushort)buf.Length);
                }
                m_eLinkAction = Type_LinkAction.Type_Link_NULL;
            });
        }
        public void Button_DismissPrivateNot()
        {
            CMD_GR_Dismiss_Private kNetInfo = new CMD_GR_Dismiss_Private();

            kNetInfo.bDismiss = 0;
            var buf = StructConverterByteArray.StructToBytes(kNetInfo);

            CServerItem.get().SendSocketData(GameServerDefines.MDM_GR_PRIVATE, GameServerDefines.SUB_GR_PRIVATE_DISMISS, buf, (ushort)buf.Length);
        }
        public void CB_InGameServerID(int iUserID)
        {
            CMD_GP_UserInGameServerID kNetInfo = new CMD_GP_UserInGameServerID();

            kNetInfo.dwUserID = (uint)iUserID;
            var buf = StructConverterByteArray.StructToBytes(kNetInfo);

            send(MsgDefine.MDM_GP_USER_SERVICE, MsgDefine.SUB_GP_QUERY_INGAME_SEVERID, buf, buf.Length);
        }
        public void HNMJButton_PengAction()
        {
            CMD_C_OperateCard OperateCard = new CMD_C_OperateCard();

            OperateCard.cbOperateCode = HNMJLogic_Defines.WIK_PENG;
            OperateCard.cbOperateCard = 0;
            var buf = StructConverterByteArray.StructToBytes(OperateCard);

            SendSocketData(HNMJ_Defines.SUB_C_OPERATE_CARD, buf, (ushort)buf.Length);
        }
        public void ChiAction(byte nChiAction)
        {
            CMD_C_OperateCard OperateCard = new CMD_C_OperateCard();

            OperateCard.cbOperateCode = nChiAction;

            OperateCard.cbOperateCard = 0;
            var buf = StructConverterByteArray.StructToBytes(OperateCard);

            SendSocketData(HNMJ_Defines.SUB_C_OPERATE_CARD, buf, (ushort)buf.Length);
        }
        //插入类型
        public bool InsertGameKind(tagGameKind pGameKind)
        {
            //效验参数
            //ASSERT(pGameKind!=0);
            //if (pGameKind == null) return false;

            //变量定义
            CGameKindItem pGameKindItem = null;
            bool          bInsert       = false;

            if (m_GameKindItemMap.ContainsKey(pGameKind.wKindID))
            {
                pGameKindItem = m_GameKindItemMap[pGameKind.wKindID];
            }
            else
            {
                pGameKindItem = new CGameKindItem();
                bInsert       = true;
            }

            if (pGameKindItem == null)
            {
                return(false);
            }

            //设置数据
            var buf = StructConverterByteArray.StructToBytes(pGameKind);

            pGameKindItem.m_GameKind = (tagGameKind)StructConverterByteArray.BytesToStruct(buf, typeof(tagGameKind));
            //memcpy(&pGameKindItem.m_GameKind, pGameKind, sizeof(tagGameKind));

            //插入处理
            if (bInsert == true)
            {
                //设置索引
                m_GameKindItemMap[pGameKind.wKindID] = pGameKindItem;

                //插入子项
                if (m_pIServerListDataSink != null)
                {
                    m_pIServerListDataSink.OnGameItemInsert(pGameKindItem);
                }
            }
            else
            {
                //更新子项
                if (m_pIServerListDataSink != null)
                {
                    m_pIServerListDataSink.OnGameItemUpdate(pGameKindItem);
                }
            }

            return(true);
        }
        //插入函数
        //插入种类
        public bool InsertGameType(tagGameType pGameType)
        {
            //if (pGameType == null) return false;


            //变量定义
            CGameTypeItem pGameTypeItem = null;
            bool          bInsert       = false;

            if (m_GameTypeItemMap.ContainsKey(pGameType.wTypeID))
            {
                pGameTypeItem = m_GameTypeItemMap[pGameType.wTypeID];
            }
            else
            {
                pGameTypeItem = new CGameTypeItem();
                bInsert       = true;
            }

            if (pGameTypeItem == null)
            {
                return(false);
            }

            //设置数据
            var buf = StructConverterByteArray.StructToBytes(pGameType);

            pGameTypeItem.m_GameType = (tagGameType)StructConverterByteArray.BytesToStruct(buf, typeof(tagGameType));
            //memcpy(&pGameTypeItem.m_GameType, pGameType, sizeof(tagGameType));


            //插入处理
            if (bInsert == true)
            {
                //设置索引
                m_GameTypeItemMap[pGameType.wTypeID] = pGameTypeItem;

                //界面更新
                if (m_pIServerListDataSink != null)
                {
                    m_pIServerListDataSink.OnGameItemInsert(pGameTypeItem);
                }
            }
            else
            {
                //界面更新
                if (m_pIServerListDataSink != null)
                {
                    m_pIServerListDataSink.OnGameItemUpdate(pGameTypeItem);
                }
            }

            return(true);
        }
        public void Button_EmosShow(int emoIdex)
        {
            showPlane(TYPE_EMOS, emoIdex, m_pLocal.GetChairID());

            //mChen
            CMD_GF_C_UserExpressionIdx UserExpression = new CMD_GF_C_UserExpressionIdx();

            UserExpression.wItemIndex  = (ushort)emoIdex;
            UserExpression.wSendUserID = m_pLocal.GetChairID();
            var buf = StructConverterByteArray.StructToBytes(UserExpression);

            CServerItem.get().SendSocketData(GameServerDefines.MDM_GF_FRAME, GameServerDefines.SUB_GF_USER_EXPRESSION_INDEX, buf, (ushort)buf.Length);
        }
        public void SendOutCard(byte Cardvalue)
        {
            if (m_nGameState != MJState.HNMJ_STATE_PLAYING)
            {
                return;
            }

            CMD_C_OutCard OutCard = new CMD_C_OutCard();

            OutCard.cbCardData = Cardvalue;//m_pLocal.getTouchCardVlaue(pCard);//temp set the card value!!Lin
            var buf = StructConverterByteArray.StructToBytes(OutCard);

            SendSocketData(HNMJ_Defines.SUB_C_OUT_CARD, buf, (ushort)buf.Length);
        }
        public void SendInventoryConsumption(byte ItemID, ushort wAwardGlod = 10, byte cbCostType = 0)
        {
            Debug.LogWarning("------------SendInventoryConsumption");
            CMD_C_InventoryConsumptionInfo kNetInfo = new CMD_C_InventoryConsumptionInfo();

            kNetInfo.dwUserID   = GlobalUserInfo.getUserID();
            kNetInfo.cbItemID   = ItemID;
            kNetInfo.wAmount    = wAwardGlod;
            kNetInfo.cbCostType = cbCostType;
            //发送数据
            var buf = StructConverterByteArray.StructToBytes(kNetInfo);

            SendSocketData(HNMJ_Defines.SUB_C_CONSUMPTION_INVENTORY, buf, (ushort)buf.Length);
        }
Beispiel #14
0
        //////////////////////////////////////////////////////////////////////////
        ///
        /// // 登陆
        public bool sendLoginVisitor(CMD_GP_VisitorLogon VisitorAccount)
        {
            GlobalUserInfo    pGlobalUserInfo = GameNet.GlobalUserInfo.GetInstance();
            tagGlobalUserData pGlobalUserData = pGlobalUserInfo.GetGlobalUserData();

            Buffer.BlockCopy(mVisitorAccount.szPassWord, 0, pGlobalUserData.szPassword, 0,
                             mVisitorAccount.szPassWord.Length);

            //发送数据
            var buf = StructConverterByteArray.StructToBytes(mVisitorAccount);

            send(MsgDefine.MDM_GP_LOGON, MsgDefine.SUB_GP_LOGON_VISITOR, buf, buf.Length);
            return(true);
        }
        public void Button_LansShow(int lansIndex)
        {
            showPlane(TYPE_LANS, lansIndex, m_pLocal.GetChairID());

            //mChen
            CMD_GF_C_UserChatIdx UserChat = new CMD_GF_C_UserChatIdx();

            UserChat.wItemIndex  = (ushort)lansIndex;
            UserChat.wSendUserID = m_pLocal.GetChairID();
            var buf = StructConverterByteArray.StructToBytes(UserChat);

            CServerItem.get()
            .SendSocketData(GameServerDefines.MDM_GF_FRAME, GameServerDefines.SUB_GF_USER_CHAT_INDEX, buf,
                            (ushort)buf.Length);
        }
        //发送聊天数据给服务器
        public void SendChatData(byte[] chatdata)
        {
            CMD_C_CHAT chat = new CMD_C_CHAT();

            chat.UserStatus = CServerItem.get().GetMeUserItem().GetUserStatus();
            chat.ChatData   = chatdata;
            if (chat.ChatData.Length <= 100 && chat.ChatData.Length > 0)
            {
                var buf = StructConverterByteArray.StructToBytes(chat);
                SendSocketData(HNMJ_Defines.SUB_C_CHAT_PLAY, buf, (ushort)buf.Length);
            }
            else
            {
                Debug.Log("文字数据不存在或过长");
            }
        }
Beispiel #17
0
        //发送注册信息
        public bool sendRegisterPacket(CMD_GP_RegisterAccounts RegisterAccount)
        {
            GlobalUserInfo    pGlobalUserInfo = GameNet.GlobalUserInfo.GetInstance();
            tagGlobalUserData pGlobalUserData = pGlobalUserInfo.GetGlobalUserData();

            Buffer.BlockCopy(RegisterAccount.szLogonPass, 0, pGlobalUserData.szPassword, 0,
                             RegisterAccount.szLogonPass.Length);

            // for Match Time
            Debug.Log("發送註冊信息");
            RegisterAccount.wKindID = GameScene.KIND_ID_JianDe;

            //发送数据
            var buf = StructConverterByteArray.StructToBytes(RegisterAccount);

            send(MsgDefine.MDM_GP_LOGON, MsgDefine.SUB_GP_REGISTER_ACCOUNTS, buf, buf.Length);
            return(true);
        }
        public void SendAwardData(uint dwAwardGlod = 10, byte cbCostType = 0)
        {
            Debug.LogWarning("------------SendAwardData");
            //变量定义
            GlobalUserInfo    pGlobalUserInfo = GlobalUserInfo.GetInstance();
            tagGlobalUserData pGlobalUserData = pGlobalUserInfo.GetGlobalUserData();

            CMD_C_AwardDone kNetInfo = new CMD_C_AwardDone();

            kNetInfo.Init();
            kNetInfo.dwUserID    = pGlobalUserData.dwUserID;
            kNetInfo.dwAwardGold = dwAwardGlod;
            kNetInfo.cbCostType  = cbCostType;
            Buffer.BlockCopy(pGlobalUserData.szPassword, 0, kNetInfo.szPassword, 0, pGlobalUserData.szPassword.Length);
            var buf = StructConverterByteArray.StructToBytes(kNetInfo);

            SendSocketData(HNMJ_Defines.SUB_C_AWARD_DONE, buf, (ushort)buf.Length);
        }
Beispiel #19
0
        //发送登陆信息
        public bool sendLoginAccount(CMD_GP_LogonAccounts LoginAccount)
        {
            GlobalUserInfo    pGlobalUserInfo = GameNet.GlobalUserInfo.GetInstance();
            tagGlobalUserData pGlobalUserData = pGlobalUserInfo.GetGlobalUserData();

            Buffer.BlockCopy(LoginAccount.szPassword, 0, pGlobalUserData.szPassword, 0, LoginAccount.szPassword.Length);

            // for Match Time
            Debug.Log("登錄設置kindid");
            LoginAccount.wKindID = GameScene.KIND_ID_JianDe;

            //发送数据
            //var buf = StructConverterByteArray.StructToBytes<CMD_GP_LogonAccounts>(LoginAccount);
            var buf = StructConverterByteArray.StructToBytes(LoginAccount);

            send(MsgDefine.MDM_GP_LOGON, MsgDefine.SUB_GP_LOGON_ACCOUNTS, buf, buf.Length);
            return(true);
        }
        //////////////////////////////////////////////////////////////////////////
        // ISocketEngineSink

        public override void onEventTCPSocketLink()
        {
            //变量定义
            GlobalUserInfo    pGlobalUserInfo = GlobalUserInfo.GetInstance();
            tagGlobalUserData pGlobalUserData = pGlobalUserInfo.GetGlobalUserData();

            switch (mMissionType)
            {       // 查询
            case Type.MISSION_RAFFLE:
            {
                CMD_GP_RaffleDone kNetInfo = new CMD_GP_RaffleDone();
                kNetInfo.Init();

                kNetInfo.dwUserID     = pGlobalUserData.dwUserID;
                kNetInfo.dwRaffleGold = m_dwRaffleGold;

                Buffer.BlockCopy(pGlobalUserData.szPassword, 0, kNetInfo.szPassword, 0, pGlobalUserData.szPassword.Length);
                ///strncpy(kNetInfo.szPassword, pGlobalUserData->szPassword, countarray(kNetInfo.szPassword));

                var MachineID = DF.shared().GetMachineID();
                if (MachineID != null)
                {
                    Buffer.BlockCopy(MachineID, 0, kNetInfo.szMachineID, 0, MachineID.Length);
                }
                ///strncpy(kNetInfo.szMachineID, DF::shared()->GetMachineID(), countarray(kNetInfo.szMachineID));

                var buf = StructConverterByteArray.StructToBytes(kNetInfo);
                send(MsgDefine.MDM_GP_USER_SERVICE, MsgDefine.SUB_GP_RAFFLE_DONE, buf, buf.Length);
                ///send(MDM_GP_USER_SERVICE, SUB_GP_RAFFLE_DONE, &kNetInfo, sizeof(CMD_GP_CheckInDone));

                break;
            }

            default:
                stop();
                break;
            }
        }
        //加密数据
        public uint EncryptBuffer(ref byte[] pcbDataBuffer, uint wDataSize, uint wBufferSize)
        {
            uint wEncryptSize = (uint)(wDataSize - Packet.SizeOfTCP_Commend);
            uint wSnapCount   = 0;

            if ((wEncryptSize % sizeof(uint)) != 0)
            {
                wSnapCount = (uint)(sizeof(uint) - wEncryptSize % sizeof(uint));

                Array.Clear(pcbDataBuffer, (int)(Packet.SizeOfTCP_Info + wEncryptSize), (int)wSnapCount);
                // memset(pcbDataBuffer + Packet.SizeOfTCP_Info + wEncryptSize, 0, wSnapCount);
            }

            //效验码与字节映射
            Byte cbCheckCode = 0;
            uint i           = 0;

            for (i = Packet.SizeOfTCP_Info; i < wDataSize; i++)
            {
                cbCheckCode += pcbDataBuffer[i];
                //cocos2d::log("CSocketEngine::EncryptBuffer MapSendByte -- 1 -- %d  ", pcbDataBuffer[i]);

                pcbDataBuffer[i] = MapSendByte(pcbDataBuffer[i]);

                //cocos2d::log("CSocketEngine::EncryptBuffer MapSendByte -- 2 -- %d  ", pcbDataBuffer[i]);
            }

            //填写信息头
#if true
            Packet.TCP_Info pHeadTCPInfo;// = (Packet.TCP_Info)StructConverterByteArray.BytesToStruct(pcbDataBuffer, typeof(Packet.TCP_Info));
            pHeadTCPInfo.cbCheckCode = (byte)(~cbCheckCode + 1);
            pHeadTCPInfo.wPacketSize = (ushort)wDataSize;
            pHeadTCPInfo.cbDataKind  = Packet.DK_ENCRYPT;
            var headTCPInfoBuf = StructConverterByteArray.StructToBytes(pHeadTCPInfo);
            Buffer.BlockCopy(headTCPInfoBuf, 0, pcbDataBuffer, 0, headTCPInfoBuf.Length);
#else
            Packet.TCP_Head pHead = new Packet.TCP_Head();
            pHead.TCPInfo.cbCheckCode = (byte)(~cbCheckCode + 1);
            pHead.TCPInfo.wPacketSize = wDataSize;
            pHead.TCPInfo.cbDataKind  = Packet.DK_ENCRYPT;
#endif
            //创建密钥
            uint dwXorKey = m_dwSendXorKey;
            if (m_dwSendPacketCount == 0)
            {
                //随机映射种子
                //dwXorKey = (uint)DateTime.Now.Ticks;//不知道函数定义
                dwXorKey       = 1000;
                dwXorKey       = SeedRandMap((ushort)dwXorKey);
                dwXorKey      |= ((uint)SeedRandMap((ushort)(dwXorKey >> 16))) << 16;
                dwXorKey      ^= Packet.g_dwPacketKey;
                m_dwSendXorKey = dwXorKey;
                m_dwRecvXorKey = dwXorKey;
                //Debug.Log("1new recv key: "+ m_dwRecvXorKey);
            }

            //加密数据

            ushort pwSeed;
            uint   pdwXor;

            uint wEncrypCount = (ushort)((wEncryptSize + wSnapCount) / sizeof(uint));

            for (uint j = 0; j < wEncrypCount; j++)
            {
                pdwXor  = BitConverter.ToUInt32(pcbDataBuffer, (int)(Packet.SizeOfTCP_Info + 4 * j));
                pdwXor ^= dwXorKey;
                var newValue = BitConverter.GetBytes(pdwXor);
                Buffer.BlockCopy(newValue, 0, pcbDataBuffer, (int)(Packet.SizeOfTCP_Info + 4 * j), 4);
                pwSeed    = BitConverter.ToUInt16(pcbDataBuffer, (int)(Packet.SizeOfTCP_Info + 4 * j));
                dwXorKey  = SeedRandMap(pwSeed);
                pwSeed    = BitConverter.ToUInt16(pcbDataBuffer, (int)(Packet.SizeOfTCP_Info + 4 * j + 2));
                dwXorKey |= ((uint)SeedRandMap(pwSeed)) << 16;

                dwXorKey ^= Packet.g_dwPacketKey;
            }

            //插入密钥
            if (m_dwSendPacketCount == 0)
            {
                byte[] tempBuf = (byte[])pcbDataBuffer.Clone();
                Buffer.BlockCopy(tempBuf, Packet.SizeOfIPC_Head, pcbDataBuffer, Packet.SizeOfIPC_Head + sizeof(uint), (int)wDataSize);
                //memmove(pcbDataBuffer + Packet.SizeOfTCP_Head+Packet.SizeOf(uint), pcbDataBuffer + Packet.SizeOfTCP_Head, wDataSize);

                var sendKeyBuf = BitConverter.GetBytes(m_dwSendXorKey);
                Buffer.BlockCopy(sendKeyBuf, 0, pcbDataBuffer, Packet.SizeOfIPC_Head, sizeof(uint));
                //*((uint*)(pcbDataBuffer + Packet.SizeOfTCP_Head)) = m_dwSendXorKey;//
                //byte[] temp = System.BitConverter.GetBytes(m_dwSendXorKey);

                //pcbDataBuffer[Packet.SizeOfTCP_Head] = (byte)(m_dwSendXorKey >> 24);
                // pcbDataBuffer[Packet.SizeOfTCP_Head + 1] = (byte)(m_dwSendXorKey >> 16);
                //pcbDataBuffer[Packet.SizeOfTCP_Head + 2] = (byte)(m_dwSendXorKey >> 8);
                // pcbDataBuffer[Packet.SizeOfTCP_Head + 3] = (byte)(m_dwSendXorKey);

                //pHead.TCPInfo.wPacketSize += sizeof(uint);
                Packet.TCP_Info pHeadTCPInfoTmp = (Packet.TCP_Info)StructConverterByteArray.BytesToStruct(pcbDataBuffer, typeof(Packet.TCP_Info));
                pHeadTCPInfoTmp.wPacketSize += sizeof(uint);
                var headTCPInfoBufTmp = StructConverterByteArray.StructToBytes(pHeadTCPInfoTmp);
                Buffer.BlockCopy(headTCPInfoBufTmp, 0, pcbDataBuffer, 0, headTCPInfoBufTmp.Length);
                //var pHeadData = StructConverterByteArray.StructToBytes(pHead);
                //Buffer.BlockCopy(pHeadData, 0, pcbDataBuffer, 0, pHeadData.Length);

                wDataSize += sizeof(uint);
            }

            //cocos2d::log("CSocketEngine::EncryptBuffer cbCheckCode -- %d   m_dwSendXorKey --- %x ----   wDataSize ---- %d", pHead->TCPInfo.cbCheckCode, m_dwSendXorKey, wDataSize);

            //设置变量
            m_dwSendPacketCount++;
            m_dwSendXorKey = dwXorKey;

            return(wDataSize);
        }
        //插入房间
        public bool InsertGameServer(tagGameServer pGameServer)
        {
            //效验参数
            //ASSERT(pGameServer!=0);
            //if (pGameServer == null) return false;

            //变量定义
            CGameServerItem pGameServerItem = null;
            bool            bInsert         = false;

            if (m_GameServerItemMap.ContainsKey(pGameServer.wServerID))
            {
                pGameServerItem = m_GameServerItemMap[pGameServer.wServerID];
            }
            else
            {
                pGameServerItem = new CGameServerItem();
                bInsert         = true;
            }

            if (pGameServerItem == null)
            {
                return(false);
            }

            //设置数据
            var buf = StructConverterByteArray.StructToBytes(pGameServer);

            pGameServerItem.m_GameServer =
                (tagGameServer)StructConverterByteArray.BytesToStruct(buf, typeof(tagGameServer));
            //memcpy(&pGameServerItem.m_GameServer, pGameServer, sizeof(tagGameServer));
            m_dwAllOnLineCount += pGameServer.dwOnLineCount;

            pGameServerItem.m_pGameKindItem = SearchGameKind(pGameServer.wKindID);

            //查找类型
            if (bInsert == true && pGameServerItem.m_pGameKindItem != null)
            {
                //变量定义
                uint dwGameKindOnline = 0;
                foreach (var cGameServerItem in m_GameServerItemMap)
                {
                    //获取房间
                    CGameServerItem pGameServerItem2 = cGameServerItem.Value;

                    //设置房间
                    if ((pGameServerItem2 != null) &&
                        (pGameServerItem2.m_GameServer.wKindID == pGameServerItem.m_GameServer.wKindID))
                    {
                        dwGameKindOnline += pGameServerItem2.m_GameServer.dwOnLineCount;
                    }
                }

                //设置变量
                pGameServerItem.m_pGameKindItem.m_GameKind.dwOnLineCount = dwGameKindOnline;

                //事件通知
                //ASSERT(m_pIServerListDataSink!=0);
                if (m_pIServerListDataSink != null)
                {
                    m_pIServerListDataSink.OnGameItemUpdate(pGameServerItem.m_pGameKindItem);
                }
            }


            //插入处理
            if (bInsert == true)
            {
                //设置索引
                m_GameServerItemMap[pGameServer.wServerID] = pGameServerItem;

                //插入子项
                if (m_pIServerListDataSink != null)
                {
                    m_pIServerListDataSink.OnGameItemInsert(pGameServerItem);
                }
            }
            else
            {
                //更新子项
                if (m_pIServerListDataSink != null)
                {
                    m_pIServerListDataSink.OnGameItemUpdate(pGameServerItem);
                }
            }

            return(true);
        }