Exemplo n.º 1
0
        //房间配置
        public CParameterServer GetParameterServer(tagGameServer pGameServer)
        {
            //寻找现存

            if (m_ParameterServerMap.ContainsKey(pGameServer.wServerID))
            {
                return(m_ParameterServerMap[pGameServer.wServerID]);
            }


            //创建对象
            CParameterServer pParameterServer = new CParameterServer();

            //设置数组
            m_ParameterServerMap[pGameServer.wServerID] = pParameterServer;

            return(pParameterServer);
        }
Exemplo n.º 2
0
        //房间信息
        bool onSocketListServer(byte[] data, int size)
        {
            ////更新数据
            tagGameServer tempStruct = new tagGameServer();
            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);
                tagGameServer pGameServer = (tagGameServer)StructConverterByteArray.BytesToStruct(pNetInfo, typeof(tagGameServer));
                pServerListData.InsertGameServer(pGameServer);
            }

            return(true);
        }
Exemplo n.º 3
0
        //插入房间
        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);
        }