Skip to content

Commit

Permalink
fixed:
Browse files Browse the repository at this point in the history
onGlobalData多次接收bug
#36
  • Loading branch information
kbengine committed Jul 1, 2014
1 parent 484a424 commit 1d103fe
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 52 deletions.
30 changes: 2 additions & 28 deletions kbe/src/server/dbmgr/dbmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ void Dbmgr::onRegisterNewApp(Mercury::Channel* pChannel, int32 uid, std::string&

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

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

Expand All @@ -315,64 +314,39 @@ void Dbmgr::onRegisterNewApp(Mercury::Channel* pChannel, int32 uid, std::string&
if(pSyncAppDatasHandler_ == NULL)
pSyncAppDatasHandler_ = new SyncAppDatasHandler(this->getNetworkInterface());

pSyncAppDatasHandler_->pushApp(componentID);

// 下一步:
// 如果是连接到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()];

// 由pSyncAppDatasHandler_同步
//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()];

// 由pSyncAppDatasHandler_同步
//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);
}

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

// 如果是baseapp或者cellapp则将自己注册到所有其他baseapp和cellapp
if(tcomponentType == BASEAPP_TYPE ||
tcomponentType == CELLAPP_TYPE)
Expand Down
81 changes: 61 additions & 20 deletions kbe/src/server/dbmgr/sync_app_datas_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,24 @@ SyncAppDatasHandler::~SyncAppDatasHandler()
}

//-------------------------------------------------------------------------------------
void SyncAppDatasHandler::pushApp(COMPONENT_ID cid)
void SyncAppDatasHandler::pushApp(COMPONENT_ID cid, int32 startGroupOrder, int32 startGlobalOrder)
{
lastRegAppTime_ = timestamp();
if(std::find(apps_.begin(), apps_.end(), cid) != apps_.end())
return;
std::vector<ComponentInitInfo>::iterator iter = apps_.begin();
for(; iter != apps_.end(); iter++)
{
if((*iter).cid == cid)
{
ERROR_MSG(boost::format("SyncAppDatasHandler::pushApp: cid(%1%) is exist!\n") % cid);
return;
}
}

apps_.push_back(cid);
ComponentInitInfo cinfo;
cinfo.cid = cid;
cinfo.startGroupOrder = startGroupOrder;
cinfo.startGlobalOrder = startGlobalOrder;
apps_.push_back(cinfo);
}

//-------------------------------------------------------------------------------------
Expand All @@ -76,32 +87,62 @@ bool SyncAppDatasHandler::process()
return true;

bool hasDone = false;

std::string digest = EntityDef::md5().getDigestStr();

std::vector<COMPONENT_ID>::iterator iter = apps_.begin();
// 如果是连接到dbmgr则需要等待接收app初始信息
// 例如:初始会分配entityID段以及这个app启动的顺序信息(是否第一个baseapp启动)
std::vector<ComponentInitInfo>::iterator iter = apps_.begin();
for(; iter != apps_.end(); iter++)
{
COMPONENT_ID componentID = (*iter);
Components::ComponentInfos* cinfos = Componentbridge::getComponents().findComponent(componentID);
ComponentInitInfo cInitInfo = (*iter);
Components::ComponentInfos* cinfos = Componentbridge::getComponents().findComponent(cInitInfo.cid);

if(cinfos == NULL)
continue;

switch(cinfos->componentType)
COMPONENT_TYPE tcomponentType = cinfos->componentType;

if(tcomponentType == BASEAPP_TYPE ||
tcomponentType == CELLAPP_TYPE ||
tcomponentType == LOGINAPP_TYPE)
{
case BASEAPP_TYPE:
{
Dbmgr::getSingleton().onGlobalDataClientLogon(cinfos->pChannel, cinfos->componentType);
hasDone = true;
}
break;
case CELLAPP_TYPE:
Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject();

switch(tcomponentType)
{
Dbmgr::getSingleton().onGlobalDataClientLogon(cinfos->pChannel, cinfos->componentType);
hasDone = true;
case BASEAPP_TYPE:
{
Dbmgr::getSingleton().onGlobalDataClientLogon(cinfos->pChannel, BASEAPP_TYPE);

std::pair<ENTITY_ID, ENTITY_ID> idRange = Dbmgr::getSingleton().idServer().allocRange();
(*pBundle).newMessage(BaseappInterface::onDbmgrInitCompleted);
BaseappInterface::onDbmgrInitCompletedArgs6::staticAddToBundle((*pBundle), g_kbetime, idRange.first,
idRange.second, cInitInfo.startGlobalOrder, cInitInfo.startGroupOrder, digest);
}
break;
case CELLAPP_TYPE:
{
Dbmgr::getSingleton().onGlobalDataClientLogon(cinfos->pChannel, CELLAPP_TYPE);

std::pair<ENTITY_ID, ENTITY_ID> idRange = Dbmgr::getSingleton().idServer().allocRange();
(*pBundle).newMessage(CellappInterface::onDbmgrInitCompleted);
CellappInterface::onDbmgrInitCompletedArgs6::staticAddToBundle((*pBundle), g_kbetime, idRange.first,
idRange.second, cInitInfo.startGlobalOrder, cInitInfo.startGroupOrder, digest);
}
break;
case LOGINAPP_TYPE:
(*pBundle).newMessage(LoginappInterface::onDbmgrInitCompleted);
LoginappInterface::onDbmgrInitCompletedArgs3::staticAddToBundle((*pBundle),
cInitInfo.startGlobalOrder, cInitInfo.startGroupOrder, digest);

break;
default:
break;
}
break;
default:
break;

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

Expand Down
15 changes: 11 additions & 4 deletions kbe/src/server/dbmgr/sync_app_datas_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,23 @@ namespace KBEngine{
class SyncAppDatasHandler : public Task
{
public:
struct ComponentInitInfo
{
COMPONENT_ID cid;
int32 startGroupOrder;
int32 startGlobalOrder;
};

SyncAppDatasHandler(Mercury::NetworkInterface & networkInterface);
~SyncAppDatasHandler();

bool process();

void pushApp(COMPONENT_ID cid);
void pushApp(COMPONENT_ID cid, int32 startGroupOrder, int32 startGlobalOrder);
private:
Mercury::NetworkInterface & networkInterface_;
uint64 lastRegAppTime_;
std::vector<COMPONENT_ID> apps_;
Mercury::NetworkInterface & networkInterface_;
uint64 lastRegAppTime_;
std::vector<ComponentInitInfo> apps_;

};

Expand Down

0 comments on commit 1d103fe

Please sign in to comment.