Beispiel #1
0
//-------------------------------------------------------------------------------------
void Baseappmgr::reqCreateBaseAnywhereFromDBIDQueryBestBaseappID(Network::Channel* pChannel, MemoryStream& s)
{
    Components::ComponentInfos* cinfos =
        Components::getSingleton().findComponent(pChannel);

    // 此时肯定是在运行状态中,但有可能在等待创建space
    // 所以初始化进度没有完成, 在只有一个baseapp的情况下如果这
    // 里不进行设置将是一个相互等待的状态
    if (cinfos)
        cinfos->state = COMPONENT_STATE_RUN;

    updateBestBaseapp();

    if (bestBaseappID_ == 0 && numLoadBalancingApp() == 0)
    {
        ERROR_MSG(fmt::format("Baseappmgr::reqCreateBaseAnywhereFromDBIDQueryBestBaseappID: Unable to allocate baseapp for load balancing! baseappSize={}.\n",
                              baseapps_.size()));
    }

    Network::Bundle* pBundle = Network::Bundle::createPoolObject();
    (*pBundle).newMessage(BaseappInterface::onGetCreateBaseAnywhereFromDBIDBestBaseappID);

    (*pBundle) << bestBaseappID_;
    (*pBundle).append((char*)s.data() + s.rpos(), (int)s.length());
    cinfos->pChannel->send(pBundle);
    s.done();
}
Beispiel #2
0
//-------------------------------------------------------------------------------------
void Baseappmgr::reqCreateBaseAnywhere(Network::Channel* pChannel, MemoryStream& s)
{
    Components::ComponentInfos* cinfos =
        Components::getSingleton().findComponent(pChannel);

    // 此时肯定是在运行状态中,但有可能在等待创建space
    // 所以初始化进度没有完成, 在只有一个baseapp的情况下如果这
    // 里不进行设置将是一个相互等待的状态
    if(cinfos)
        cinfos->state = COMPONENT_STATE_RUN;

    updateBestBaseapp();

    if (bestBaseappID_ == 0 && numLoadBalancingApp() == 0)
    {
        ERROR_MSG(fmt::format("Baseappmgr::reqCreateBaseAnywhere: Unable to allocate baseapp for load balancing! baseappSize={}.\n",
                              baseapps_.size()));
    }

    cinfos = Components::getSingleton().findComponent(BASEAPP_TYPE, bestBaseappID_);
    if (cinfos == NULL || cinfos->pChannel == NULL || cinfos->state != COMPONENT_STATE_RUN)
    {
        Network::Bundle* pBundle = Network::Bundle::createPoolObject();
        ForwardItem* pFI = new AppForwardItem();
        pFI->pBundle = pBundle;
        (*pBundle).newMessage(BaseappInterface::onCreateBaseAnywhere);
        (*pBundle).append((char*)s.data() + s.rpos(), (int)s.length());
        s.done();

        int runstate = -1;
        if (cinfos)
            runstate = (int)cinfos->state;

        WARNING_MSG(fmt::format("Baseappmgr::reqCreateBaseAnywhere: not found baseapp({}, runstate={}, pChannel={}), message is buffered.\n",
                                bestBaseappID_, runstate, (cinfos && cinfos->pChannel ? cinfos->pChannel->c_str() : "NULL")));

        pFI->pHandler = NULL;
        forward_anywhere_baseapp_messagebuffer_.push(pFI);
        return;
    }

    //DEBUG_MSG("Baseappmgr::reqCreateBaseAnywhere: %s opsize=%d, selBaseappIdx=%d.\n",
    //	pChannel->c_str(), s.opsize(), currentBaseappIndex);

    Network::Bundle* pBundle = Network::Bundle::createPoolObject();
    (*pBundle).newMessage(BaseappInterface::onCreateBaseAnywhere);

    (*pBundle).append((char*)s.data() + s.rpos(), (int)s.length());
    cinfos->pChannel->send(pBundle);
    s.done();

    // 预先将实体数量增加
    std::map< COMPONENT_ID, Baseapp >::iterator baseapps_iter = baseapps_.find(bestBaseappID_);
    if (baseapps_iter != baseapps_.end())
    {
        baseapps_iter->second.incNumEntities();
    }
}
Beispiel #3
0
//-------------------------------------------------------------------------------------
void Cellappmgr::reqCreateInNewSpace(Network::Channel* pChannel, MemoryStream& s) 
{
	std::string entityType;
	ENTITY_ID id;
	COMPONENT_ID componentID;
	bool hasClient;

	// 如果cellappIndex为0,则代表不强制指定cellapp
	// 非0的情况下,选择的cellapp可以用1,2,3,4来代替
	// 假如预期有4个cellapp, 假如不够4个, 只有3个, 那么4代表1
	uint32 cellappIndex = 0;

	s >> entityType;
	s >> id;
	s >> cellappIndex;
	s >> componentID;
	s >> hasClient;

	static SPACE_ID spaceID = 1;

	Network::Bundle* pBundle = Network::Bundle::createPoolObject();
	(*pBundle).newMessage(CellappInterface::onCreateInNewSpaceFromBaseapp);
	(*pBundle) << entityType;
	(*pBundle) << id;
	(*pBundle) << spaceID++;
	(*pBundle) << componentID;
	(*pBundle) << hasClient;

	(*pBundle).append(&s);
	s.done();

	uint32 cellappSize = cellapp_cids_.size();

	if (cellappSize > 0)
	{
		updateBestCellapp();

		// 选择特定的cellapp创建space
		if (cellappIndex > 0)
		{
			uint32 index = (cellappIndex - 1) % cellappSize;
			bestCellappID_ = cellapp_cids_[index];
		}
		else if (bestCellappID_ == 0 && numLoadBalancingApp() == 0)
		{
			ERROR_MSG(fmt::format("Cellappmgr::reqCreateInNewSpace: Unable to allocate cellapp for load balancing! entityType={}, entityID={}, componentID={}, cellappSize={}.\n",
				entityType, id, componentID, cellappSize));
		}
	}

	Components::ComponentInfos* cinfos = NULL;
	if (bestCellappID_ > 0)
		cinfos = Components::getSingleton().findComponent(CELLAPP_TYPE, bestCellappID_);

	if (cinfos == NULL || cinfos->pChannel == NULL || cinfos->state != COMPONENT_STATE_RUN)
	{
		WARNING_MSG("Cellappmgr::reqCreateInNewSpace: not found cellapp, message is buffered.\n");

		ForwardItem* pFI = new AppForwardItem();
		pFI->pHandler = NULL;
		pFI->pBundle = pBundle;

		if (cellappIndex == 0 || bestCellappID_ == 0)
			forward_anywhere_cellapp_messagebuffer_.push(pFI);
		else
			forward_cellapp_messagebuffer_.push(bestCellappID_, pFI);

		return;
	}
	else
	{
		cinfos->pChannel->send(pBundle);
	}

	std::map< COMPONENT_ID, Cellapp >::iterator cellapp_iter = cellapps_.find(bestCellappID_);
	DEBUG_MSG(fmt::format("Cellappmgr::reqCreateInNewSpace: entityType={}, entityID={}, componentID={}, cellapp(cid={}, load={}, numEntities={}).\n",
		entityType, id, componentID, bestCellappID_, cellapp_iter->second.load(), cellapp_iter->second.numEntities()));

	// 预先将实体数量增加
	if (cellapp_iter != cellapps_.end())
	{
		cellapp_iter->second.incNumEntities();
	}
}
Beispiel #4
0
//-------------------------------------------------------------------------------------
void Baseappmgr::registerPendingAccountToBaseapp(Network::Channel* pChannel, MemoryStream& s)
{
    std::string loginName;
    std::string accountName;
    std::string password;
    std::string datas;
    DBID entityDBID;
    uint32 flags;
    uint64 deadline;
    COMPONENT_TYPE componentType;

    s >> loginName >> accountName >> password >> entityDBID >> flags >> deadline >> componentType;
    s.readBlob(datas);

    Components::ComponentInfos* cinfos = Components::getSingleton().findComponent(pChannel);
    if(cinfos == NULL || cinfos->pChannel == NULL)
    {
        ERROR_MSG("Baseappmgr::registerPendingAccountToBaseapp: not found loginapp!\n");
        return;
    }

    pending_logins_[loginName] = cinfos->cid;

    updateBestBaseapp();

    if (bestBaseappID_ == 0 && numLoadBalancingApp() == 0)
    {
        ERROR_MSG(fmt::format("Baseappmgr::registerPendingAccountToBaseapp: Unable to allocate baseapp for load balancing! baseappSize={}, accountName={}.\n",
                              baseapps_.size(), loginName));
    }

    ENTITY_ID eid = 0;
    cinfos = Components::getSingleton().findComponent(BASEAPP_TYPE, bestBaseappID_);

    if (cinfos == NULL || cinfos->pChannel == NULL || cinfos->state != COMPONENT_STATE_RUN)
    {
        Network::Bundle* pBundle = Network::Bundle::createPoolObject();
        ForwardItem* pFI = new AppForwardItem();

        pFI->pBundle = pBundle;
        (*pBundle).newMessage(BaseappInterface::registerPendingLogin);
        (*pBundle) << loginName << accountName << password << eid << entityDBID << flags << deadline << componentType;
        pBundle->appendBlob(datas);

        int runstate = -1;
        if (cinfos)
            runstate = (int)cinfos->state;

        WARNING_MSG(fmt::format("Baseappmgr::registerPendingAccountToBaseapp: not found baseapp({}, runstate={}, pChannel={}), message is buffered.\n",
                                bestBaseappID_, runstate, (cinfos && cinfos->pChannel ? cinfos->pChannel->c_str() : "NULL")));

        pFI->pHandler = NULL;
        forward_anywhere_baseapp_messagebuffer_.push(pFI);
        return;
    }

    std::map< COMPONENT_ID, Baseapp >::iterator baseapps_iter = baseapps_.find(bestBaseappID_);

    DEBUG_MSG(fmt::format("Baseappmgr::registerPendingAccountToBaseapp:{}. allocBaseapp={}, numEntities={}.\n",
                          accountName, bestBaseappID_, (bestBaseappID_ > 0 ? baseapps_iter->second.numEntities() : 0)));

    Network::Bundle* pBundle = Network::Bundle::createPoolObject();
    (*pBundle).newMessage(BaseappInterface::registerPendingLogin);
    (*pBundle) << loginName << accountName << password << eid << entityDBID << flags << deadline << componentType;
    pBundle->appendBlob(datas);
    cinfos->pChannel->send(pBundle);

    // 预先将实体数量增加
    if (baseapps_iter != baseapps_.end())
    {
        baseapps_iter->second.incNumProxices();
    }
}