Skip to content

Commit 0f2f866

Browse files
committed
修正:
cellApp收到GlobalData数据后立即使用,GlobalData: SpaceMgr这是注册了一个baseMailbox,但此时还无法和baseApp通信 kbengine#35
1 parent 0b352cc commit 0f2f866

6 files changed

Lines changed: 205 additions & 7 deletions

File tree

‎kbe/src/server/dbmgr/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ SRCS = \
66
dbtasks \
77
db_threadpool \
88
buffered_dbtasks \
9-
main
9+
main \
10+
sync_app_datas_handler
1011

1112
ASMS =
1213

‎kbe/src/server/dbmgr/dbmgr.cpp‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ along with KBEngine. If not, see <http://www.gnu.org/licenses/>.
2323
#include "dbmgr_interface.hpp"
2424
#include "dbtasks.hpp"
2525
#include "billinghandler.hpp"
26+
#include "sync_app_datas_handler.hpp"
2627
#include "db_mysql/kbe_table_mysql.hpp"
2728
#include "network/common.hpp"
2829
#include "network/tcp_packet.hpp"
@@ -66,7 +67,8 @@ Dbmgr::Dbmgr(Mercury::EventDispatcher& dispatcher,
6667
numExecuteRawDatabaseCommand_(0),
6768
numCreatedAccount_(0),
6869
pBillingAccountHandler_(NULL),
69-
pBillingChargeHandler_(NULL)
70+
pBillingChargeHandler_(NULL),
71+
pSyncAppDatasHandler_(NULL)
7072
{
7173
}
7274

@@ -187,7 +189,7 @@ bool Dbmgr::initializeEnd()
187189

188190
INFO_MSG(boost::format("Dbmgr::initializeEnd: digest(%1%)\n") %
189191
EntityDef::md5().getDigestStr());
190-
192+
191193
return initBillingHandler() && initDB();
192194
}
193195

@@ -310,6 +312,11 @@ void Dbmgr::onRegisterNewApp(Mercury::Channel* pChannel, int32 uid, std::string&
310312
if(globalorderID > 0)
311313
startGlobalOrder = globalorderID;
312314

315+
if(pSyncAppDatasHandler_ == NULL)
316+
pSyncAppDatasHandler_ = new SyncAppDatasHandler(this->getNetworkInterface());
317+
318+
pSyncAppDatasHandler_->pushApp(componentID);
319+
313320
// 下一步:
314321
// 如果是连接到dbmgr则需要等待接收app初始信息
315322
// 例如:初始会分配entityID段以及这个app启动的顺序信息(是否第一个baseapp启动)
@@ -326,8 +333,8 @@ void Dbmgr::onRegisterNewApp(Mercury::Channel* pChannel, int32 uid, std::string&
326333
if(grouporderID <= 0)
327334
startGroupOrder = Componentbridge::getComponents().getBaseappGroupOrderLog()[getUserUID()];
328335

329-
330-
onGlobalDataClientLogon(pChannel, BASEAPP_TYPE);
336+
// 由pSyncAppDatasHandler_同步
337+
//onGlobalDataClientLogon(pChannel, BASEAPP_TYPE);
331338

332339
std::pair<ENTITY_ID, ENTITY_ID> idRange = idServer_.allocRange();
333340
(*pBundle).newMessage(BaseappInterface::onDbmgrInitCompleted);
@@ -339,8 +346,9 @@ void Dbmgr::onRegisterNewApp(Mercury::Channel* pChannel, int32 uid, std::string&
339346
{
340347
if(grouporderID <= 0)
341348
startGroupOrder = Componentbridge::getComponents().getCellappGroupOrderLog()[getUserUID()];
342-
343-
onGlobalDataClientLogon(pChannel, CELLAPP_TYPE);
349+
350+
// 由pSyncAppDatasHandler_同步
351+
//onGlobalDataClientLogon(pChannel, CELLAPP_TYPE);
344352

345353
std::pair<ENTITY_ID, ENTITY_ID> idRange = idServer_.allocRange();
346354
(*pBundle).newMessage(CellappInterface::onDbmgrInitCompleted);

‎kbe/src/server/dbmgr/dbmgr.hpp‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ namespace KBEngine{
4949

5050
class DBInterface;
5151
class BillingHandler;
52+
class SyncAppDatasHandler;
5253

5354
class Dbmgr : public ServerApp,
5455
public Singleton<Dbmgr>
@@ -218,6 +219,8 @@ class Dbmgr : public ServerApp,
218219
void accountNewPassword(Mercury::Channel* pChannel, ENTITY_ID entityID, std::string& accountName,
219220
std::string& password, std::string& newpassword);
220221

222+
SyncAppDatasHandler* pSyncAppDatasHandler()const { return pSyncAppDatasHandler_; }
223+
void pSyncAppDatasHandler(SyncAppDatasHandler* p){ pSyncAppDatasHandler_ = p; }
221224
protected:
222225
TimerHandle loopCheckTimerHandle_;
223226
TimerHandle mainProcessTimer_;
@@ -248,6 +251,8 @@ class Dbmgr : public ServerApp,
248251

249252
BillingHandler* pBillingAccountHandler_;
250253
BillingHandler* pBillingChargeHandler_;
254+
255+
SyncAppDatasHandler* pSyncAppDatasHandler_;
251256
};
252257

253258
}

‎kbe/src/server/dbmgr/dbmgr90.vcproj‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@
221221
RelativePath="main.cpp"
222222
>
223223
</File>
224+
<File
225+
RelativePath=".\sync_app_datas_handler.cpp"
226+
>
227+
</File>
224228
<Filter
225229
Name="Resource Files"
226230
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
@@ -261,6 +265,10 @@
261265
RelativePath=".\dbtasks.hpp"
262266
>
263267
</File>
268+
<File
269+
RelativePath=".\sync_app_datas_handler.hpp"
270+
>
271+
</File>
264272
</Filter>
265273
<File
266274
RelativePath=".\ReadMe.txt"
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
This source file is part of KBEngine
3+
For the latest info, see http://www.kbengine.org/
4+
5+
Copyright (c) 2008-2012 KBEngine.
6+
7+
KBEngine is free software: you can redistribute it and/or modify
8+
it under the terms of the GNU Lesser General Public License as published by
9+
the Free Software Foundation, either version 3 of the License, or
10+
(at your option) any later version.
11+
12+
KBEngine is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
GNU Lesser General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General Public License
18+
along with KBEngine. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
#include "dbmgr.hpp"
22+
#include "sync_app_datas_handler.hpp"
23+
#include "entitydef/scriptdef_module.hpp"
24+
#include "entitydef/entity_macro.hpp"
25+
#include "network/fixed_messages.hpp"
26+
#include "math/math.hpp"
27+
#include "network/bundle.hpp"
28+
#include "network/channel.hpp"
29+
#include "server/componentbridge.hpp"
30+
#include "server/components.hpp"
31+
32+
#include "baseapp/baseapp_interface.hpp"
33+
#include "cellapp/cellapp_interface.hpp"
34+
#include "baseappmgr/baseappmgr_interface.hpp"
35+
#include "cellappmgr/cellappmgr_interface.hpp"
36+
#include "loginapp/loginapp_interface.hpp"
37+
38+
namespace KBEngine{
39+
40+
//-------------------------------------------------------------------------------------
41+
SyncAppDatasHandler::SyncAppDatasHandler(Mercury::NetworkInterface & networkInterface):
42+
Task(),
43+
networkInterface_(networkInterface),
44+
lastRegAppTime_(0),
45+
apps_()
46+
{
47+
networkInterface.mainDispatcher().addFrequentTask(this);
48+
}
49+
50+
//-------------------------------------------------------------------------------------
51+
SyncAppDatasHandler::~SyncAppDatasHandler()
52+
{
53+
// networkInterface_.mainDispatcher().cancelFrequentTask(this);
54+
DEBUG_MSG("SyncAppDatasHandler::~SyncAppDatasHandler()\n");
55+
56+
Dbmgr::getSingleton().pSyncAppDatasHandler(NULL);
57+
}
58+
59+
//-------------------------------------------------------------------------------------
60+
void SyncAppDatasHandler::pushApp(COMPONENT_ID cid)
61+
{
62+
lastRegAppTime_ = timestamp();
63+
if(std::find(apps_.begin(), apps_.end(), cid) != apps_.end())
64+
return;
65+
66+
apps_.push_back(cid);
67+
}
68+
69+
//-------------------------------------------------------------------------------------
70+
bool SyncAppDatasHandler::process()
71+
{
72+
if(lastRegAppTime_ == 0)
73+
return true;
74+
75+
if(timestamp() - lastRegAppTime_ < uint64( 3 * stampsPerSecond() ) )
76+
return true;
77+
78+
bool hasDone = false;
79+
80+
std::vector<COMPONENT_ID>::iterator iter = apps_.begin();
81+
for(; iter != apps_.end(); iter++)
82+
{
83+
COMPONENT_ID componentID = (*iter);
84+
Components::ComponentInfos* cinfos = Componentbridge::getComponents().findComponent(componentID);
85+
86+
if(cinfos == NULL)
87+
continue;
88+
89+
switch(cinfos->componentType)
90+
{
91+
case BASEAPP_TYPE:
92+
{
93+
Dbmgr::getSingleton().onGlobalDataClientLogon(cinfos->pChannel, cinfos->componentType);
94+
hasDone = true;
95+
}
96+
break;
97+
case CELLAPP_TYPE:
98+
{
99+
Dbmgr::getSingleton().onGlobalDataClientLogon(cinfos->pChannel, cinfos->componentType);
100+
hasDone = true;
101+
}
102+
break;
103+
default:
104+
break;
105+
}
106+
}
107+
108+
apps_.clear();
109+
lastRegAppTime_ = timestamp();
110+
111+
if(!hasDone)
112+
{
113+
return true;
114+
}
115+
116+
delete this;
117+
return false;
118+
}
119+
120+
//-------------------------------------------------------------------------------------
121+
122+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
This source file is part of KBEngine
3+
For the latest info, see http://www.kbengine.org/
4+
5+
Copyright (c) 2008-2012 KBEngine.
6+
7+
KBEngine is free software: you can redistribute it and/or modify
8+
it under the terms of the GNU Lesser General Public License as published by
9+
the Free Software Foundation, either version 3 of the License, or
10+
(at your option) any later version.
11+
12+
KBEngine is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
GNU Lesser General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General Public License
18+
along with KBEngine. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
#ifndef __SYNC_APP_DATAS_HANDLER__
22+
#define __SYNC_APP_DATAS_HANDLER__
23+
24+
// common include
25+
#include "helper/debug_helper.hpp"
26+
#include "cstdkbe/cstdkbe.hpp"
27+
// #define NDEBUG
28+
// windows include
29+
#if KBE_PLATFORM == PLATFORM_WIN32
30+
#else
31+
// linux include
32+
#endif
33+
34+
namespace KBEngine{
35+
36+
class SyncAppDatasHandler : public Task
37+
{
38+
public:
39+
SyncAppDatasHandler(Mercury::NetworkInterface & networkInterface);
40+
~SyncAppDatasHandler();
41+
42+
bool process();
43+
44+
void pushApp(COMPONENT_ID cid);
45+
private:
46+
Mercury::NetworkInterface & networkInterface_;
47+
uint64 lastRegAppTime_;
48+
std::vector<COMPONENT_ID> apps_;
49+
50+
};
51+
52+
53+
}
54+
#endif

0 commit comments

Comments
 (0)