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