Skip to content

Commit 3a871c8

Browse files
committed
修正存在多个loginapp的时候无法正常登陆的问题
1 parent 51182b9 commit 3a871c8

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

kbe/src/server/baseappmgr/baseappmgr.cpp

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Baseappmgr::Baseappmgr(Mercury::EventDispatcher& dispatcher,
4949
forward_baseapp_messagebuffer_(ninterface, BASEAPP_TYPE),
5050
bestBaseappID_(0),
5151
baseapps_(),
52+
pending_logins_(),
5253
baseappsInitProgress_(0.f)
5354
{
5455
}
@@ -291,8 +292,17 @@ void Baseappmgr::registerPendingAccountToBaseapp(Mercury::Channel* pChannel,
291292
std::string& password, DBID entityDBID, uint32 flags, uint64 deadline,
292293
COMPONENT_TYPE componentType)
293294
{
295+
Components::ComponentInfos* cinfos = Components::getSingleton().findComponent(pChannel);
296+
if(cinfos == NULL || cinfos->pChannel == NULL)
297+
{
298+
ERROR_MSG("Baseappmgr::registerPendingAccountToBaseapp: not found loginapp!\n");
299+
return;
300+
}
301+
302+
pending_logins_[loginName] = cinfos->cid;
303+
294304
ENTITY_ID eid = 0;
295-
Components::ComponentInfos* cinfos =
305+
cinfos =
296306
Components::getSingleton().findComponent(BASEAPP_TYPE, bestBaseappID_);
297307

298308
if(cinfos == NULL || cinfos->pChannel == NULL)
@@ -330,7 +340,16 @@ void Baseappmgr::registerPendingAccountToBaseappAddr(Mercury::Channel* pChannel,
330340
DEBUG_MSG(fmt::format("Baseappmgr::registerPendingAccountToBaseappAddr:{0}, componentID={1}, entityID={2}.\n",
331341
accountName, componentID, entityID));
332342

333-
Components::ComponentInfos* cinfos = Components::getSingleton().findComponent(componentID);
343+
Components::ComponentInfos* cinfos = Components::getSingleton().findComponent(pChannel);
344+
if(cinfos == NULL || cinfos->pChannel == NULL)
345+
{
346+
ERROR_MSG("Baseappmgr::registerPendingAccountToBaseapp: not found loginapp!\n");
347+
return;
348+
}
349+
350+
pending_logins_[loginName] = cinfos->cid;
351+
352+
cinfos = Components::getSingleton().findComponent(componentID);
334353
if(cinfos == NULL || cinfos->pChannel == NULL)
335354
{
336355
ERROR_MSG(fmt::format("Baseappmgr::registerPendingAccountToBaseappAddr: not found baseapp({}).\n", componentID));
@@ -356,26 +375,30 @@ void Baseappmgr::onPendingAccountGetBaseappAddr(Mercury::Channel* pChannel,
356375
void Baseappmgr::sendAllocatedBaseappAddr(Mercury::Channel* pChannel,
357376
std::string& loginName, std::string& accountName, const std::string& addr, uint16 port)
358377
{
359-
Components::COMPONENTS& components = Components::getSingleton().getComponents(LOGINAPP_TYPE);
360-
size_t componentSize = components.size();
378+
KBEUnordered_map< std::string, COMPONENT_ID >::iterator iter = pending_logins_.find(loginName);
379+
if(iter == pending_logins_.end())
380+
{
381+
ERROR_MSG("Baseappmgr::sendAllocatedBaseappAddr: not found loginapp, pending_logins is error!\n");
382+
return;
383+
}
361384

362-
if(componentSize == 0)
385+
Components::ComponentInfos* cinfos = Components::getSingleton().findComponent(iter->second);
386+
if(cinfos == NULL || cinfos->pChannel == NULL)
363387
{
364-
ERROR_MSG("Baseappmgr::sendAllocatedBaseappAddr: not found loginapp.\n");
388+
ERROR_MSG("Baseappmgr::sendAllocatedBaseappAddr: not found loginapp!\n");
365389
return;
366390
}
367391

368-
Components::COMPONENTS::iterator iter = components.begin();
369-
Mercury::Channel* lpChannel = (*iter).pChannel;
370-
371392
Mercury::Bundle* pBundleToLoginapp = Mercury::Bundle::ObjPool().createObject();
372393
(*pBundleToLoginapp).newMessage(LoginappInterface::onLoginAccountQueryBaseappAddrFromBaseappmgr);
373394

374395
LoginappInterface::onLoginAccountQueryBaseappAddrFromBaseappmgrArgs4::staticAddToBundle((*pBundleToLoginapp), loginName,
375396
accountName, addr, port);
376397

377-
(*pBundleToLoginapp).send(this->networkInterface(), lpChannel);
398+
(*pBundleToLoginapp).send(this->networkInterface(), cinfos->pChannel);
378399
Mercury::Bundle::ObjPool().reclaimObject(pBundleToLoginapp);
400+
401+
pending_logins_.erase(iter);
379402
}
380403

381404
//-------------------------------------------------------------------------------------

kbe/src/server/baseappmgr/baseappmgr.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ class Baseappmgr : public ServerApp,
138138

139139
std::map< COMPONENT_ID, Baseapp > baseapps_;
140140

141+
KBEUnordered_map< std::string, COMPONENT_ID > pending_logins_;
142+
141143
float baseappsInitProgress_;
142144
};
143145

0 commit comments

Comments
 (0)