//删除房间
        public bool DeleteGameServer(ushort wServerID)
        {
            //查找房间
            if (m_GameServerItemMap.ContainsKey(wServerID) == false)
            {
                return(false);
            }

            CGameServerItem pGameServerItem = m_GameServerItemMap[wServerID];

            //设置数据
            m_dwAllOnLineCount -= pGameServerItem.m_GameServer.dwOnLineCount;

            //删除通知
            //ASSERT(m_pIServerListDataSink!=0);
            if (m_pIServerListDataSink != null)
            {
                m_pIServerListDataSink.OnGameItemDelete(pGameServerItem);
            }

            //删除数据
            pGameServerItem = null;

            //删除数据
            m_GameServerItemMap.Remove(wServerID);

            return(false);
        }
        public static CGameServerItem getGameServerByKindAndServerType(ushort wKindID, ushort wServerType) //WQ add
        {
            CGameServerItem pMinPlayerCoutServer = null;
            CServerListData pListData            = GameNet.CServerListData.shared();

            foreach (var cGameServerItem in pListData.m_GameServerItemMap)
            {
                CGameServerItem pActListItem = cGameServerItem.Value;

                if (pActListItem.m_GameServer.wKindID != wKindID || pActListItem.m_GameServer.wServerType != wServerType)
                {
                    continue;
                }
                if (pMinPlayerCoutServer == null)
                {
                    pMinPlayerCoutServer = pActListItem;
                    continue;
                }
                if (pMinPlayerCoutServer.m_GameServer.dwOnLineCount >
                    pActListItem.m_GameServer.dwOnLineCount)
                {
                    pMinPlayerCoutServer = pActListItem;
                }
            }
            return(pMinPlayerCoutServer);
        }
        public bool connectGameServerByServerID(int iServerID)
        {
            CGameServerItem pServer = CServerListData.shared().SearchGameServer((ushort)iServerID);

            if (pServer != null)
            {
                connectGameServer(pServer);
            }
            else
            {
                Debug.Assert(false, "GameManager::connectGameServerByServerID");
            }
            return(true);
        }
        public bool connectGameServerByKindIDAndServerType(ushort wKindID, ushort wServerType) //WQ add
        {
            CGameServerItem pMinPlayerCoutServer = CServerListData.getGameServerByKindAndServerType(wKindID, wServerType);

            if (pMinPlayerCoutServer != null)
            {
                connectGameServer(pMinPlayerCoutServer);
            }
            else
            {
                Debug.Assert(false, "GameManager::connectGameServerByKindIDAndServerType");
            }
            return(true);
        }
        public bool connectGameServerByKindID(ushort wKindID)
        {
            CGameServerItem pMinPlayerCoutServer = CServerListData.getGameServerByKind(wKindID);

            if (pMinPlayerCoutServer != null)
            {
                connectGameServer(pMinPlayerCoutServer);
            }
            else
            {
                Debug.Assert(false, "GameManager::connectGameServerByKindID");
            }
            return(true);
        }
        //设置人数
        public void SetServerOnLineCount(ushort wServerID, uint dwOnLineCount)
        {
            //搜索房间
            CGameServerItem pGameServerItem = SearchGameServer(wServerID);

            //设置人数
            if (pGameServerItem != null)
            {
                //设置变量
                m_dwAllOnLineCount -= pGameServerItem.m_GameServer.dwOnLineCount;
                m_dwAllOnLineCount += dwOnLineCount;

                //设置变量
                pGameServerItem.m_GameServer.dwOnLineCount = dwOnLineCount;

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

                //查找类型
                CGameKindItem pGameKindItem = SearchGameKind(pGameServerItem.m_GameServer.wKindID);
                if (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;
                        }
                    }
                    //设置变量
                    pGameKindItem.m_GameKind.dwOnLineCount = dwGameKindOnline;

                    //事件通知
                    //ASSERT(m_pIServerListDataSink!=0);
                    if (m_pIServerListDataSink != null)
                    {
                        m_pIServerListDataSink.OnGameItemUpdate(pGameKindItem);
                    }
                }
            }
        }
        public bool connectGameServer(CGameServerItem pGameServerItem)
        {
            Debug.Log("GameManagerBase::connectGameServer");
            if (mServerItem.IsService())
            {
                disconnectServer();
            }

            Debug.Log("GameManagerBase::connectGameServer connectServer");
            mGameServerItem = pGameServerItem;

            connectServer();

            RestTick();

            return(true);
        }
//登录完成
        bool onSocketSubMacthSignupInfo(byte[] data, int size)
        {
            //校验数据
            if (size % sizeof(ushort) != 0)
            {
                return(false);
            }

            //提取数据
            tagSignupMatchInfo tempInfo = new tagSignupMatchInfo();
            int    structSize           = Marshal.SizeOf(tempInfo);
            var    buf          = new byte[structSize];
            ushort wSignupCount = (ushort)(size / structSize);

            tagSignupMatchInfo[] pSignupMatchInfo = new tagSignupMatchInfo[wSignupCount];
            //获取对象
            //ASSERT(CServerListData::shared() != NULL);
            CServerListData pServerListData = CServerListData.shared();

            //查找房间
            CGameServerItem pGameServerItem = null;

            for (int i = 0; i < wSignupCount; i++)
            {
                Buffer.BlockCopy(data, i * structSize, buf, 0, structSize);
                pSignupMatchInfo[i] = (tagSignupMatchInfo)StructConverterByteArray.BytesToStruct(buf, typeof(tagSignupMatchInfo));

                //设置报名
                pGameServerItem = pServerListData.SearchGameServer(pSignupMatchInfo[i].wServerID);
                if (pGameServerItem != null && pGameServerItem.m_GameMatch.dwMatchID == pSignupMatchInfo[i].dwMatchID)
                {
                    pGameServerItem.m_bSignuped = true;
                }
            }

            return(true);
        }
        //比赛列表
        bool onSocketListMatch(byte[] data, int size)
        {
            tagGameMatch tempStruct = new tagGameMatch();
            int          itemSize   = Marshal.SizeOf(tempStruct);

            if (size % itemSize != 0)
            {
                return(false);
            }

            //变量定义
            ushort wItemCount = (ushort)(size / itemSize);

            var buf = new byte[itemSize];

            tagGameMatch[] pGameMatch = new tagGameMatch[wItemCount];

            //获取对象
            CGameServerItem pGameServerItem = null;

            for (int i = 0; i < wItemCount; i++)
            {
                Buffer.BlockCopy(data, i * itemSize, buf, 0, itemSize);
                pGameMatch[i] = (tagGameMatch)StructConverterByteArray.BytesToStruct(buf, typeof(tagGameMatch));

                //更新数据
                pGameServerItem = CServerListData.shared().SearchGameServer(pGameMatch[i].wServerID);
                if (pGameServerItem != null)
                {
                    pGameServerItem.m_GameMatch = (tagGameMatch)StructConverterByteArray.BytesToStruct(buf, typeof(tagGameMatch));
                    //memcpy(&pGameServerItem.m_GameMatch, pGameMatch++, sizeof(pGameServerItem.m_GameMatch));
                }
            }

            return(true);
        }
        } //构造函数

        public static CGameServerItem getGameServerByKind(ushort wKindID)
        {
            CGameServerItem pMinPlayerCoutServer = null;
            CServerListData pListData            = GameNet.CServerListData.shared();

            foreach (var cGameServerItem in pListData.m_GameServerItemMap)
            {
                if (cGameServerItem.Value.m_GameServer.wKindID != wKindID)
                {
                    continue;
                }
                if (pMinPlayerCoutServer == null)
                {
                    pMinPlayerCoutServer = cGameServerItem.Value;
                    continue;
                }
                if (pMinPlayerCoutServer.m_GameServer.dwOnLineCount >
                    cGameServerItem.Value.m_GameServer.dwOnLineCount)
                {
                    pMinPlayerCoutServer = cGameServerItem.Value;
                }
            }
            return(pMinPlayerCoutServer);
        }
        //加入房间
        public void Button_JoinRoom(int roomId)
        {
            PlayerPrefs.SetInt("PubOrPrivate", (int)RoomType.Type_Private);
            PlayerPrefs.Save();

            m_iJoinRoomId = roomId;
            var             iServerId   = roomId / 10000 - 10;
            CGameServerItem pGameServer = GameManagerBaseNet.InstanceBase().SearchGameServer(iServerId);

            if (pGameServer != null && pGameServer.IsPrivateRoom())
            {
                GameManagerBaseNet.InstanceBase().connectGameServerByServerID(iServerId);
                m_eLinkAction = Type_LinkAction.Type_Link_Join;

                m_cbGameTypeIdex = HNGameManager.GameType;//WQ add

                Debug.Log("Button_JoinRoom: m_cbGameTypeIdex=" + m_cbGameTypeIdex);
            }
            else
            {
                //NoticeMsg::Instance().ShowTopMsgByScript("JoinRoomNumError");
                Debug.Log("Join Room error!!!");
            }
        }
        //插入房间
        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);
        }