Skip to content

Commit 9bc1a06

Browse files
committed
数据存储继续完善
1 parent 197b75d commit 9bc1a06

13 files changed

Lines changed: 208 additions & 22 deletions

‎kbe/src/lib/db_mysql/kbe_table_mysql.cpp‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ along with KBEngine. If not, see <http://www.gnu.org/licenses/>.
2424
#include "dbmgr_lib/entity_table.hpp"
2525
#include "entitydef/entitydef.hpp"
2626
#include "entitydef/scriptdef_module.hpp"
27-
#include "entitydef/entity_macro.hpp"
28-
#include "network/fixed_messages.hpp"
29-
#include "math/math.hpp"
3027

3128
namespace KBEngine {
3229

@@ -87,23 +84,6 @@ KBEAccountTableMysql::KBEAccountTableMysql():
8784
EntityTable()
8885
{
8986
tableName("kbe_accountinfos");
90-
91-
ScriptDefModule* scriptModule = EntityDef::findScriptModule(DBUtil::accountScriptName());
92-
ScriptDefModule::PROPERTYDESCRIPTION_MAP& propertyDescrs = scriptModule->getPersistentPropertyDescriptions();
93-
ScriptDefModule::PROPERTYDESCRIPTION_MAP::const_iterator iter = propertyDescrs.begin();
94-
95-
if(scriptModule->hasCell())
96-
{
97-
Vector3 pos, dir;
98-
ADD_POSDIR_TO_STREAM(accountDefMemoryStream_, pos, dir);
99-
}
100-
101-
for(; iter != propertyDescrs.end(); iter++)
102-
{
103-
PropertyDescription* propertyDescription = iter->second;
104-
accountDefMemoryStream_ << propertyDescription->getUType();
105-
propertyDescription->addPersistentToStream(&accountDefMemoryStream_, NULL);
106-
}
10787
}
10888

10989
//-------------------------------------------------------------------------------------

‎kbe/src/lib/db_mysql/kbe_table_mysql.hpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class KBEAccountTableMysql : public EntityTable
7676
bool hasAccount(std::string& name);
7777

7878
MemoryStream& accountDefMemoryStream(){ return accountDefMemoryStream_; }
79+
void accountDefMemoryStream(MemoryStream& s){accountDefMemoryStream_.append(s.data() + s.rpos(), s.opsize()); }
7980
protected:
8081
MemoryStream accountDefMemoryStream_;
8182
};

‎kbe/src/lib/entitydef/datatype.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,9 +1302,19 @@ PyObject* FixedDictType::impl_createObjFromDict(PyObject* dictData)
13021302
//-------------------------------------------------------------------------------------
13031303
PyObject* FixedDictType::impl_getDictFromObj(PyObject* pyobj)
13041304
{
1305+
bool isFixedDict = false;
1306+
if(PyObject_TypeCheck(pyobj, FixedDict::getScriptType()))
1307+
{
1308+
isFixedDict = true;
1309+
pyobj = impl_createObjFromDict(pyobj);
1310+
}
1311+
13051312
PyObject* pyRet = PyObject_CallFunction(pygetDictFromObj_,
13061313
const_cast<char*>("(O)"), pyobj);
13071314

1315+
if(isFixedDict)
1316+
Py_DECREF(pyobj);
1317+
13081318
if(pyRet == NULL)
13091319
{
13101320
SCRIPT_ERROR_CHECK();

‎kbe/src/lib/entitydef/property.cpp‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,15 @@ int FixedDictDescription::onSetValue(PyObject* parentObj, PyObject* value)
237237
//-------------------------------------------------------------------------------------
238238
void FixedDictDescription::addPersistentToStream(MemoryStream* mstream, PyObject* pyValue)
239239
{
240+
// 允许使用默认值来创建一个流
241+
if(pyValue == NULL)
242+
{
243+
pyValue = newDefaultVal();
244+
dataType_->addToStream(mstream, pyValue);
245+
Py_DECREF(pyValue);
246+
return;
247+
}
248+
240249
static_cast<FixedDictType*>(dataType_)->addToStreamEx(mstream, pyValue, true);
241250
}
242251

‎kbe/src/server/baseapp/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ SRCS = \
66
baseapp_interface \
77
backup_sender \
88
forward_message_over_handler \
9+
sync_entitystreamtemplate_handler \
910
main \
1011
proxy
1112

‎kbe/src/server/baseapp/baseapp.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ along with KBEngine. If not, see <http://www.gnu.org/licenses/>.
2626
#include "archiver.hpp"
2727
#include "backup_sender.hpp"
2828
#include "forward_message_over_handler.hpp"
29+
#include "sync_entitystreamtemplate_handler.hpp"
2930
#include "network/common.hpp"
3031
#include "network/tcp_packet.hpp"
3132
#include "network/udp_packet.hpp"
@@ -191,6 +192,7 @@ bool Baseapp::initializeEnd()
191192

192193
pBackupSender_.reset(new BackupSender());
193194
pArchiver_.reset(new Archiver());
195+
new SyncEntityStreamTemplateHandler(this->getNetworkInterface());
194196
return true;
195197
}
196198

‎kbe/src/server/baseapp/baseapp90.vcproj‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@
215215
RelativePath=".\proxy.cpp"
216216
>
217217
</File>
218+
<File
219+
RelativePath=".\sync_entitystreamtemplate_handler.cpp"
220+
>
221+
</File>
218222
<Filter
219223
Name="Resource Files"
220224
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
@@ -267,6 +271,10 @@
267271
RelativePath=".\proxy_interface_macros.hpp"
268272
>
269273
</File>
274+
<File
275+
RelativePath=".\sync_entitystreamtemplate_handler.hpp"
276+
>
277+
</File>
270278
</Filter>
271279
<File
272280
RelativePath=".\base.ipp"
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#include "baseapp.hpp"
2+
#include "sync_entitystreamtemplate_handler.hpp"
3+
#include "entitydef/scriptdef_module.hpp"
4+
#include "entitydef/entity_macro.hpp"
5+
#include "network/fixed_messages.hpp"
6+
#include "math/math.hpp"
7+
#include "network/bundle.hpp"
8+
#include "network/channel.hpp"
9+
10+
#include "../../server/dbmgr/dbmgr_interface.hpp"
11+
12+
namespace KBEngine{
13+
14+
//-------------------------------------------------------------------------------------
15+
SyncEntityStreamTemplateHandler::SyncEntityStreamTemplateHandler(Mercury::NetworkInterface & networkInterface):
16+
Task(),
17+
networkInterface_(networkInterface)
18+
{
19+
networkInterface.mainDispatcher().addFrequentTask(this);
20+
21+
MemoryStream accountDefMemoryStream;
22+
23+
ENGINE_COMPONENT_INFO& dbcfg = g_kbeSrvConfig.getDBMgr();
24+
25+
ScriptDefModule* scriptModule = EntityDef::findScriptModule(dbcfg.dbAccountEntityScriptType);
26+
ScriptDefModule::PROPERTYDESCRIPTION_MAP& propertyDescrs = scriptModule->getPersistentPropertyDescriptions();
27+
ScriptDefModule::PROPERTYDESCRIPTION_MAP::const_iterator iter = propertyDescrs.begin();
28+
29+
if(scriptModule->hasCell())
30+
{
31+
Vector3 pos, dir;
32+
ADD_POSDIR_TO_STREAM(accountDefMemoryStream, pos, dir);
33+
}
34+
35+
for(; iter != propertyDescrs.end(); iter++)
36+
{
37+
PropertyDescription* propertyDescription = iter->second;
38+
accountDefMemoryStream << propertyDescription->getUType();
39+
propertyDescription->addPersistentToStream(&accountDefMemoryStream, NULL);
40+
}
41+
}
42+
43+
//-------------------------------------------------------------------------------------
44+
SyncEntityStreamTemplateHandler::~SyncEntityStreamTemplateHandler()
45+
{
46+
// networkInterface_.mainDispatcher().cancelFrequentTask(this);
47+
DEBUG_MSG("SyncEntityStreamTemplateHandler::~SyncEntityStreamTemplateHandler()\n");
48+
}
49+
50+
//-------------------------------------------------------------------------------------
51+
bool SyncEntityStreamTemplateHandler::process()
52+
{
53+
Components::COMPONENTS cts = Components::getSingleton().getComponents(DBMGR_TYPE);
54+
Mercury::Channel* pChannel = NULL;
55+
56+
if(cts.size() > 0)
57+
{
58+
Components::COMPONENTS::iterator ctiter = cts.begin();
59+
if((*ctiter).pChannel == NULL)
60+
return true;
61+
62+
pChannel = (*ctiter).pChannel;
63+
}
64+
65+
if(pChannel == NULL)
66+
return true;
67+
68+
MemoryStream accountDefMemoryStream;
69+
70+
ENGINE_COMPONENT_INFO& dbcfg = g_kbeSrvConfig.getDBMgr();
71+
72+
ScriptDefModule* scriptModule = EntityDef::findScriptModule(dbcfg.dbAccountEntityScriptType);
73+
ScriptDefModule::PROPERTYDESCRIPTION_MAP& propertyDescrs = scriptModule->getPersistentPropertyDescriptions();
74+
ScriptDefModule::PROPERTYDESCRIPTION_MAP::const_iterator iter = propertyDescrs.begin();
75+
76+
if(scriptModule->hasCell())
77+
{
78+
Vector3 pos, dir;
79+
ADD_POSDIR_TO_STREAM(accountDefMemoryStream, pos, dir);
80+
}
81+
82+
for(; iter != propertyDescrs.end(); iter++)
83+
{
84+
PropertyDescription* propertyDescription = iter->second;
85+
accountDefMemoryStream << propertyDescription->getUType();
86+
propertyDescription->addPersistentToStream(&accountDefMemoryStream, NULL);
87+
}
88+
89+
Mercury::Bundle::SmartPoolObjectPtr bundleptr = Mercury::Bundle::createSmartPoolObj();
90+
91+
(*bundleptr)->newMessage(DbmgrInterface::syncEntityStreamTemplate);
92+
(*bundleptr)->append(accountDefMemoryStream);
93+
(*bundleptr)->send(networkInterface_, pChannel);
94+
delete this;
95+
return false;
96+
}
97+
98+
//-------------------------------------------------------------------------------------
99+
100+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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_ENTITY_STREAM_TEMPLATE_HANDLER__
22+
#define __SYNC_ENTITY_STREAM_TEMPLATE_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 SyncEntityStreamTemplateHandler : public Task
37+
{
38+
public:
39+
SyncEntityStreamTemplateHandler(Mercury::NetworkInterface & networkInterface);
40+
~SyncEntityStreamTemplateHandler();
41+
42+
bool process();
43+
private:
44+
Mercury::NetworkInterface & networkInterface_;
45+
46+
};
47+
48+
49+
}
50+
#endif

‎kbe/src/server/cellapp/forward_message_over_handler.cpp‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
namespace KBEngine{
99

1010
//-------------------------------------------------------------------------------------
11-
FMH_Baseapp_onEntityGetCellFrom_onCreateInNewSpaceFromBaseapp::FMH_Baseapp_onEntityGetCellFrom_onCreateInNewSpaceFromBaseapp(Entity* e, SPACE_ID spaceID, PyObject* params):
11+
FMH_Baseapp_onEntityGetCellFrom_onCreateInNewSpaceFromBaseapp::
12+
FMH_Baseapp_onEntityGetCellFrom_onCreateInNewSpaceFromBaseapp(Entity* e, SPACE_ID spaceID, PyObject* params):
1213
_e(e),
1314
_spaceID(spaceID),
1415
params_(params)
@@ -36,7 +37,8 @@ void FMH_Baseapp_onEntityGetCellFrom_onCreateInNewSpaceFromBaseapp::process()
3637
}
3738

3839
//-------------------------------------------------------------------------------------
39-
FMH_Baseapp_onEntityGetCellFrom_onCreateCellEntityFromBaseapp::FMH_Baseapp_onEntityGetCellFrom_onCreateCellEntityFromBaseapp(
40+
FMH_Baseapp_onEntityGetCellFrom_onCreateCellEntityFromBaseapp::
41+
FMH_Baseapp_onEntityGetCellFrom_onCreateCellEntityFromBaseapp(
4042
std::string& entityType,
4143
ENTITY_ID createToEntityID, ENTITY_ID entityID, uint32 cellDataLength,
4244
std::string& strEntityCellData, bool hasClient, COMPONENT_ID componentID, SPACE_ID spaceID):

0 commit comments

Comments
 (0)