示例#1
0
//-------------------------------------------------------------------------------------
void Dbmgr::onRegisterNewApp(Mercury::Channel* pChannel, int32 uid, std::string& username, 
						int8 componentType, uint64 componentID, int8 globalorderID, int8 grouporderID,
						uint32 intaddr, uint16 intport, uint32 extaddr, uint16 extport)
{
	ServerApp::onRegisterNewApp(pChannel, uid, username, componentType, componentID, globalorderID, grouporderID,
						intaddr, intport, extaddr, extport);

	KBEngine::COMPONENT_TYPE tcomponentType = (KBEngine::COMPONENT_TYPE)componentType;
	
	std::string digest = EntityDef::md5().getDigestStr();
	int32 startGroupOrder = 1;
	int32 startGlobalOrder = Componentbridge::getComponents().getGlobalOrderLog()[getUserUID()];

	if(grouporderID > 0)
		startGroupOrder = grouporderID;

	if(globalorderID > 0)
		startGlobalOrder = globalorderID;

	// 下一步:
	// 如果是连接到dbmgr则需要等待接收app初始信息
	// 例如:初始会分配entityID段以及这个app启动的顺序信息(是否第一个baseapp启动)
	if(tcomponentType == BASEAPP_TYPE || 
		tcomponentType == CELLAPP_TYPE || 
		tcomponentType == LOGINAPP_TYPE)
	{
		Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject();
		
		switch(tcomponentType)
		{
		case BASEAPP_TYPE:
			{
				if(grouporderID <= 0)
					startGroupOrder = Componentbridge::getComponents().getBaseappGroupOrderLog()[getUserUID()];


				onGlobalDataClientLogon(pChannel, BASEAPP_TYPE);

				std::pair<ENTITY_ID, ENTITY_ID> idRange = idServer_.allocRange();
				(*pBundle).newMessage(BaseappInterface::onDbmgrInitCompleted);
				BaseappInterface::onDbmgrInitCompletedArgs6::staticAddToBundle((*pBundle), g_kbetime, idRange.first, 
					idRange.second, startGlobalOrder, startGroupOrder, digest);
			}
			break;
		case CELLAPP_TYPE:
			{
				if(grouporderID <= 0)
					startGroupOrder = Componentbridge::getComponents().getCellappGroupOrderLog()[getUserUID()];

				onGlobalDataClientLogon(pChannel, CELLAPP_TYPE);

				std::pair<ENTITY_ID, ENTITY_ID> idRange = idServer_.allocRange();
				(*pBundle).newMessage(CellappInterface::onDbmgrInitCompleted);
				CellappInterface::onDbmgrInitCompletedArgs6::staticAddToBundle((*pBundle), g_kbetime, idRange.first, 
					idRange.second, startGlobalOrder, startGroupOrder, digest);
			}
			break;
		case LOGINAPP_TYPE:
			if(grouporderID <= 0)
				startGroupOrder = Componentbridge::getComponents().getLoginappGroupOrderLog()[getUserUID()];

			(*pBundle).newMessage(LoginappInterface::onDbmgrInitCompleted);
			LoginappInterface::onDbmgrInitCompletedArgs3::staticAddToBundle((*pBundle), 
				startGlobalOrder, startGroupOrder, digest);

			break;
		default:
			break;
		}

		(*pBundle).send(networkInterface_, pChannel);
		Mercury::Bundle::ObjPool().reclaimObject(pBundle);
	}

	// 如果是baseapp或者cellapp则将自己注册到所有其他baseapp和cellapp
	if(tcomponentType == BASEAPP_TYPE || 
		tcomponentType == CELLAPP_TYPE)
	{
		KBEngine::COMPONENT_TYPE broadcastCpTypes[2] = {BASEAPP_TYPE, CELLAPP_TYPE};
		for(int idx = 0; idx < 2; idx++)
		{
			Components::COMPONENTS& cts = Components::getSingleton().getComponents(broadcastCpTypes[idx]);
			Components::COMPONENTS::iterator fiter = cts.begin();
			for(; fiter != cts.end(); fiter++)
			{
				if((*fiter).cid == componentID)
					continue;

				Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject();
				ENTITTAPP_COMMON_MERCURY_MESSAGE(broadcastCpTypes[idx], (*pBundle), onGetEntityAppFromDbmgr);
				
				if(tcomponentType == BASEAPP_TYPE)
				{
					BaseappInterface::onGetEntityAppFromDbmgrArgs10::staticAddToBundle((*pBundle), 
						uid, username, componentType, componentID, startGlobalOrder, startGroupOrder,
							intaddr, intport, extaddr, extport);
				}
				else
				{
					CellappInterface::onGetEntityAppFromDbmgrArgs10::staticAddToBundle((*pBundle), 
						uid, username, componentType, componentID, startGlobalOrder, startGroupOrder,
							intaddr, intport, extaddr, extport);
				}
				
				KBE_ASSERT((*fiter).pChannel != NULL);
				(*pBundle).send(networkInterface_, (*fiter).pChannel);
				Mercury::Bundle::ObjPool().reclaimObject(pBundle);
			}
		}
	}
}
示例#2
0
//-------------------------------------------------------------------------------------
void Dbmgr::onRegisterNewApp(Mercury::Channel* pChannel, int32 uid, std::string& username,
                             int8 componentType, uint64 componentID, int8 globalorderID, int8 grouporderID,
                             uint32 intaddr, uint16 intport, uint32 extaddr, uint16 extport, std::string& extaddrEx)
{
    ServerApp::onRegisterNewApp(pChannel, uid, username, componentType, componentID, globalorderID, grouporderID,
                                intaddr, intport, extaddr, extport, extaddrEx);

    KBEngine::COMPONENT_TYPE tcomponentType = (KBEngine::COMPONENT_TYPE)componentType;

    int32 startGroupOrder = 1;
    int32 startGlobalOrder = Componentbridge::getComponents().getGlobalOrderLog()[getUserUID()];

    if(grouporderID > 0)
        startGroupOrder = grouporderID;

    if(globalorderID > 0)
        startGlobalOrder = globalorderID;

    if(pSyncAppDatasHandler_ == NULL)
        pSyncAppDatasHandler_ = new SyncAppDatasHandler(this->getNetworkInterface());

    // 下一步:
    // 如果是连接到dbmgr则需要等待接收app初始信息
    // 例如:初始会分配entityID段以及这个app启动的顺序信息(是否第一个baseapp启动)
    if(tcomponentType == BASEAPP_TYPE ||
            tcomponentType == CELLAPP_TYPE ||
            tcomponentType == LOGINAPP_TYPE)
    {
        switch(tcomponentType)
        {
        case BASEAPP_TYPE:
        {
            if(grouporderID <= 0)
                startGroupOrder = Componentbridge::getComponents().getBaseappGroupOrderLog()[getUserUID()];
        }
        break;
        case CELLAPP_TYPE:
        {
            if(grouporderID <= 0)
                startGroupOrder = Componentbridge::getComponents().getCellappGroupOrderLog()[getUserUID()];
        }
        break;
        case LOGINAPP_TYPE:
            if(grouporderID <= 0)
                startGroupOrder = Componentbridge::getComponents().getLoginappGroupOrderLog()[getUserUID()];

            break;
        default:
            break;
        }
    }

    pSyncAppDatasHandler_->pushApp(componentID, startGroupOrder, startGlobalOrder);

    // 如果是baseapp或者cellapp则将自己注册到所有其他baseapp和cellapp
    if(tcomponentType == BASEAPP_TYPE ||
            tcomponentType == CELLAPP_TYPE)
    {
        KBEngine::COMPONENT_TYPE broadcastCpTypes[2] = {BASEAPP_TYPE, CELLAPP_TYPE};
        for(int idx = 0; idx < 2; idx++)
        {
            Components::COMPONENTS& cts = Components::getSingleton().getComponents(broadcastCpTypes[idx]);
            Components::COMPONENTS::iterator fiter = cts.begin();
            for(; fiter != cts.end(); fiter++)
            {
                if((*fiter).cid == componentID)
                    continue;

                Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject();
                ENTITTAPP_COMMON_MERCURY_MESSAGE(broadcastCpTypes[idx], (*pBundle), onGetEntityAppFromDbmgr);

                if(tcomponentType == BASEAPP_TYPE)
                {
                    BaseappInterface::onGetEntityAppFromDbmgrArgs11::staticAddToBundle((*pBundle),
                            uid, username, componentType, componentID, startGlobalOrder, startGroupOrder,
                            intaddr, intport, extaddr, extport, g_kbeSrvConfig.getConfig().externalAddress);
                }
                else
                {
                    CellappInterface::onGetEntityAppFromDbmgrArgs11::staticAddToBundle((*pBundle),
                            uid, username, componentType, componentID, startGlobalOrder, startGroupOrder,
                            intaddr, intport, extaddr, extport, g_kbeSrvConfig.getConfig().externalAddress);
                }

                KBE_ASSERT((*fiter).pChannel != NULL);
                (*pBundle).send(networkInterface_, (*fiter).pChannel);
                Mercury::Bundle::ObjPool().reclaimObject(pBundle);
            }
        }
    }
}