//------------------------------------------------------------------------------------- void EntityMailboxAbstract::newMail(Network::Bundle& bundle) { // If it is a server-side mailbox if(g_componentType != CLIENT_TYPE && g_componentType != BOTS_TYPE) { // If the ID is 0, then this is a client-side component, otherwise the server-side. if(componentID_ == 0) { bundle.newMessage(ClientInterface::onRemoteMethodCall); } else { Components::ComponentInfos* cinfos = Components::getSingleton().findComponent(componentID_); if(cinfos != NULL) { // Post a component found in the past, if the mailbox needs to transit such as e.base.cell, by baseapp transferred cellapp if(cinfos->componentType == BASEAPP_TYPE) { bundle.newMessage(BaseappInterface::onEntityMail); } else { bundle.newMessage(CellappInterface::onEntityMail); } } else { ERROR_MSG(fmt::format("EntityMailboxAbstract::newMail: not found component({}), entityID({})!\n", componentID_, id_)); } } bundle << id_; // If the package is sent to the client is not necessary to attach such a type if(componentID_ > 0) bundle << type_; } else { // If the mailbox is on the client calls the server-side method calls the cell or base switch(type_) { case MAILBOX_TYPE_BASE: bundle.newMessage(BaseappInterface::onRemoteMethodCall); break; case MAILBOX_TYPE_CELL: bundle.newMessage(BaseappInterface::onRemoteCallCellMethodFromClient); break; default: KBE_ASSERT(false && "no support!\n"); break; }; bundle << id_; } }
//------------------------------------------------------------------------------------- void EntityMailboxAbstract::newMail(Network::Bundle& bundle) { // 如果是server端的mailbox if(g_componentType != CLIENT_TYPE && g_componentType != BOTS_TYPE) { // 如果ID为0,则这是一个客户端组件,否则为服务端。 if(componentID_ == 0) { bundle.newMessage(ClientInterface::onRemoteMethodCall); } else { Components::ComponentInfos* cinfos = Components::getSingleton().findComponent(componentID_); if(cinfos != NULL) { // 找到对应的组件投递过去, 如果这个mailbox还需要中转比如 e.base.cell , 则由baseapp转往cellapp if(cinfos->componentType == BASEAPP_TYPE) { bundle.newMessage(BaseappInterface::onEntityMail); } else { bundle.newMessage(CellappInterface::onEntityMail); } } else { ERROR_MSG(fmt::format("EntityMailboxAbstract::newMail: not found component({})!\n", componentID_)); } } bundle << id_; // 如果是发往客户端的包则无需附加这样一个类型 if(componentID_ > 0) bundle << type_; } else { // 如果是客户端上的mailbox调用服务端方法只存在调用cell或者base switch(type_) { case MAILBOX_TYPE_BASE: bundle.newMessage(BaseappInterface::onRemoteMethodCall); break; case MAILBOX_TYPE_CELL: bundle.newMessage(BaseappInterface::onRemoteCallCellMethodFromClient); break; default: KBE_ASSERT(false && "no support!\n"); break; }; bundle << id_; } }
//------------------------------------------------------------------------------------- void Loginapp::onClientActiveTick(Network::Channel* pChannel) { if(!pChannel->isExternal()) return; onAppActiveTick(pChannel, CLIENT_TYPE, 0); Network::Bundle* pBundle = Network::Bundle::createPoolObject(); pBundle->newMessage(ClientInterface::onAppActiveTickCB); pChannel->send(pBundle); }
//------------------------------------------------------------------------------------- void LogWatcher::onMessage(uint32 logtype, COMPONENT_TYPE componentType, COMPONENT_ID componentID, COMPONENT_ORDER componentOrder, int64 tm, GAME_TIME kbetime, const std::string& str, const std::stringstream& sstr) { if(!VALID_COMPONENT(componentType) || componentBitmap_[componentType] == 0) return; if((logtypes_ & logtype) <= 0) return; if(appOrder_ > 0 && appOrder_ != componentOrder) return; Network::Channel* pChannel = Messagelog::getSingleton().networkInterface().findChannel(addr_); if(pChannel == NULL) return; Network::Bundle bundle; ConsoleInterface::ConsoleLogMessageHandler msgHandler; bundle.newMessage(msgHandler); bundle << sstr.str().c_str(); bundle.send(Messagelog::getSingleton().networkInterface(), pChannel); }
//------------------------------------------------------------------------------------- thread::TPTask::TPTaskState DataDownload::presentMainThread() { if(error_) { ERROR_MSG(fmt::format("DataDownload::presentMainThread: proxy({}), downloadID({}), type({}), thread error.\n", entityID(), id(), type())); return thread::TPTask::TPTASK_STATE_COMPLETED; } uint32 datasize = GAME_PACKET_MAX_SIZE_TCP - sizeof(int16) - sizeof(uint32); if(remainSent_ > 0 && currSent_ < remainSent_) { Network::Bundle* pBundle = Network::Bundle::ObjPool().createObject(); if(!sentStart_) { pBundle->newMessage(ClientInterface::onStreamDataStarted); (*pBundle) << this->id(); (*pBundle) << totalBytes_; (*pBundle) << descr_; (*pBundle) << type(); sentStart_ = true; if(!send(ClientInterface::onStreamDataStarted, pBundle)) { DEBUG_MSG(fmt::format("DataDownload::presentMainThread: proxy({}), downloadID({}), type({}), thread exit.\n", entityID(), id(), type())); return thread::TPTask::TPTASK_STATE_COMPLETED; } return thread::TPTask::TPTASK_STATE_CONTINUE_MAINTHREAD; } pBundle->newMessage(ClientInterface::onStreamDataRecv); (*pBundle) << id(); if(remainSent_ - currSent_ > datasize) { (*pBundle) << datasize; (*pBundle).append(getOutStream() + currSent_, datasize); currSent_ += datasize; totalSentBytes_ += datasize; if(!send(ClientInterface::onStreamDataRecv, pBundle)) { DEBUG_MSG(fmt::format("DataDownload::presentMainThread: proxy({}), downloadID({}), type({}), thread exit.\n", entityID(), id(), type())); error_ = true; return thread::TPTask::TPTASK_STATE_COMPLETED; } } else { datasize = remainSent_ - currSent_; (*pBundle) << datasize; (*pBundle).append(getOutStream() + currSent_, datasize); if(!send(ClientInterface::onStreamDataRecv, pBundle)) { DEBUG_MSG(fmt::format("DataDownload::presentMainThread: proxy({}), downloadID({}), type({}), thread exit.\n", entityID(), id(), type())); error_ = true; return thread::TPTask::TPTASK_STATE_COMPLETED; } totalSentBytes_ += datasize; currSent_ = remainSent_; } } if(totalSentBytes_ == totalBytes_) { DEBUG_MSG(fmt::format("DataDownload::presentMainThread: proxy({0}), downloadID({1}), type({6}), sentBytes={5},{2}/{3} ({4:.2f}%).\n", entityID(), id(), totalSentBytes_, this->totalBytes(), 100.0f, datasize, type())); pDataDownloads_->onDownloadCompleted(this); Network::Bundle* pBundle = Network::Bundle::ObjPool().createObject(); pBundle->newMessage(ClientInterface::onStreamDataCompleted); (*pBundle) << this->id(); send(ClientInterface::onStreamDataCompleted, pBundle); return thread::TPTask::TPTASK_STATE_COMPLETED; } DEBUG_MSG(fmt::format("DataDownload::presentMainThread: proxy({0}), downloadID({1}), type({6}), sentBytes={5},{2}/{3} ({4:.2f}%).\n", entityID(), id(), totalSentBytes_, this->totalBytes(), (((float)totalSentBytes_ / (float)this->totalBytes()) * 100.0f), datasize, type())); if(currSent_ == remainSent_) { DEBUG_MSG(fmt::format("DataDownload::presentMainThread: proxy({}), downloadID({}), type({}), thread-continue.\n", entityID(), id(), type())); return thread::TPTask::TPTASK_STATE_CONTINUE_CHILDTHREAD; } return thread::TPTask::TPTASK_STATE_CONTINUE_MAINTHREAD; }