|
| 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 | +} |
0 commit comments