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 static void purge()
 {
     if (__gServerListData != null)
     {
         __gServerListData = null;
     }
 }
 //静态函数
 //获取对象
 public static CServerListData shared()
 {
     if (__gServerListData == null)
     {
         __gServerListData = new CServerListData();
     }
     return(__gServerListData);
 }
//列表完成
        bool onSocketListFinish(byte[] data, int size)
        {
            if (CServerListData.shared() != null)
            {
                CServerListData.shared().OnEventListFinish();
            }

            return(true);
        }
        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);
        }
        //WQ add. for HideSeek
        //大厅列表
        bool onSocketListLobby(byte[] data, int size)
        {
            ////更新数据
            tagGameLobby tempStruct = new tagGameLobby();
            int          itemSize   = Marshal.SizeOf(tempStruct);

            if (size % itemSize != 0)
            {
                return(false);
            }
            byte[] pNetInfo   = new byte[itemSize];
            int    iItemCount = size / itemSize;

            for (int i = 0; i < iItemCount; i++)
            {
                Buffer.BlockCopy(data, i * itemSize, pNetInfo, 0, itemSize);
                tagGameLobby sGameLobby = (tagGameLobby)StructConverterByteArray.BytesToStruct(pNetInfo, typeof(tagGameLobby));
                CServerListData.shared().InsertGameLobby(sGameLobby);
            }

            //Create CGPLobbyMission
            Loom.QueueOnMainThread(() =>
            {
                if (CServerListData.shared().GetGameLobbyCount() > 0)
                {
                    tagGameLobby gameLobby = CServerListData.shared().getARandGameLobby();
                    if (gameLobby.wLobbyPort != 0)
                    {
                        CGPLobbyMission kGPLobbyMission = CGPLobbyMission.CreateInstance(gameLobby.szServerAddr, gameLobby.wLobbyPort);
                        if (kGPLobbyMission != null && !kGPLobbyMission.isAlive())
                        {
                            kGPLobbyMission.SendChatData("StartChatConnect!");//只是为了连接上
                        }
                    }
                    else
                    {
                        Debug.LogError("onSocketListLobby: incorrect wLobbyPort=0");
                    }
                }
            });

            return(true);
        }
//类型信息
        bool onSocketListKind(byte[] data, int size)
        {
            ////更新数据
            tagGameKind tempStruct = new tagGameKind();
            int         itemSize   = Marshal.SizeOf(tempStruct);

            if (size % itemSize != 0)
            {
                return(false);
            }
            byte[]          pNetInfo        = new byte[itemSize];
            int             iItemCount      = size / itemSize;
            CServerListData pServerListData = CServerListData.shared();

            for (int i = 0; i < iItemCount; i++)
            {
                Buffer.BlockCopy(data, i * itemSize, pNetInfo, 0, itemSize);
                tagGameKind pGameKind = (tagGameKind)StructConverterByteArray.BytesToStruct(pNetInfo, typeof(tagGameKind));
                pServerListData.InsertGameKind(pGameKind);
            }
            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 CGameServerItem SearchGameServer(int iServerID)
 {
     return(CServerListData.shared().SearchGameServer((ushort)iServerID));
 }
        /*----------------IServerListDataSink------------------------*/

        public HomeScene()
        {
            CServerListData.shared().SetServerListDataSink(this);
            UserInfo.getInstance().addUpPlayerInfoCB(this, upPlayerInfo);
            UserInfo.getInstance().addLoginSucessCB(this, LogonSucess);
        }