//-------------------------------------------------------------------------------------
void EntityMailboxAbstract::newMail(Mercury::Bundle& bundle)
{
	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("EntityMailboxAbstract::newMail: not found component!\n");
		}
	}

	bundle << id_;
	
	// 如果是发往客户端的包则无需附加这样一个类型
	if(componentID_ > 0)
		bundle << type_;
}
//-------------------------------------------------------------------------------------
void EntityMailboxAbstract::newMail(Mercury::Bundle& bundle)
{
	// 如果是server端的mailbox
	if(g_componentType != CLIENT_TYPE && g_componentType != BOTS_TYPE)
	{
		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_;
	}
}
Exemple #3
0
//-------------------------------------------------------------------------------------
void Space::onSpaceDataChanged(const std::string& key, const std::string& value, bool isdel)
{
	// 通知脚本
	if(!isdel)
	{
		SCRIPT_OBJECT_CALL_ARGS3(Cellapp::getSingleton().getEntryScript().get(), const_cast<char*>("onSpaceData"), 
			const_cast<char*>("Iss"), this->id(), key.c_str(), value.c_str());
	}
	else
	{
		SCRIPT_OBJECT_CALL_ARGS3(Cellapp::getSingleton().getEntryScript().get(), const_cast<char*>("onSpaceData"), 
			const_cast<char*>("IsO"), this->id(), key.c_str(), Py_None);
	}

	SPACE_ENTITIES::const_iterator iter = this->entities().begin();
	for(; iter != this->entities().end(); iter++)
	{
		const Entity* pEntity = (*iter).get();

		if(pEntity == NULL || pEntity->isDestroyed() || !pEntity->hasWitness())
			continue;

		Mercury::Bundle* pForwardBundle = Mercury::Bundle::ObjPool().createObject();

		if(!isdel)
		{
			pForwardBundle->newMessage(ClientInterface::setSpaceData);
			(*pForwardBundle) << this->id();
			(*pForwardBundle) << key;
			(*pForwardBundle) << value;
		}
		else
		{
			pForwardBundle->newMessage(ClientInterface::delSpaceData);
			(*pForwardBundle) << this->id();
			(*pForwardBundle) << key;
		}

		Mercury::Bundle* pSendBundle = Mercury::Bundle::ObjPool().createObject();
		MERCURY_ENTITY_MESSAGE_FORWARD_CLIENT(pEntity->id(), (*pSendBundle), (*pForwardBundle));

		if(!isdel)
			pEntity->pWitness()->sendToClient(ClientInterface::setSpaceData, pSendBundle);
		else
			pEntity->pWitness()->sendToClient(ClientInterface::delSpaceData, pSendBundle);

		Mercury::Bundle::ObjPool().reclaimObject(pForwardBundle);
	}
}
Exemple #4
0
//-------------------------------------------------------------------------------------
void Base::reqTeleportOther(Mercury::Channel* pChannel, ENTITY_ID reqTeleportEntityID, 
							COMPONENT_ID reqTeleportEntityCellAppID, COMPONENT_ID reqTeleportEntityBaseAppID)
{
	DEBUG_MSG("Base::reqTeleportOther: reqTeleportEntityID=%d, reqTeleportEntityCellAppID=%"PRAppID".\n",
		reqTeleportEntityID, reqTeleportEntityCellAppID);

	if(this->getCellMailbox() == NULL || this->getCellMailbox()->getChannel() == NULL)
	{
		ERROR_MSG("%s::reqTeleportOther: %d, teleport is error, cellMailbox is NULL, reqTeleportEntityID, reqTeleportEntityCellAppID=%"PRAppID".\n",
			this->getScriptName(), this->getID(), reqTeleportEntityID, reqTeleportEntityCellAppID);
		return;
	}

	Components::ComponentInfos* cinfos = Components::getSingleton().findComponent(reqTeleportEntityCellAppID);
	if(cinfos == NULL || cinfos->pChannel == NULL)
	{
		ERROR_MSG("%s::reqTeleportOther: %d, teleport is error, not found cellapp, reqTeleportEntityID, reqTeleportEntityCellAppID=%"PRAppID".\n",
			this->getScriptName(), this->getID(), reqTeleportEntityID, reqTeleportEntityCellAppID);
		return;
	}

	Mercury::Bundle bundle;
	bundle.newMessage(CellappInterface::teleportFromBaseapp);
	bundle << reqTeleportEntityID;
	CellappInterface::teleportFromBaseappArgs3::staticAddToBundle(bundle, this->getCellMailbox()->getComponentID(), this->getID(), reqTeleportEntityBaseAppID);
	bundle.send(Baseapp::getSingleton().getNetworkInterface(), cinfos->pChannel);
}
//-------------------------------------------------------------------------------------
void DebugHelper::onMessage(uint32 logType, const char * str, uint32 length)
{
    if(g_componentType == MACHINE_TYPE ||
            g_componentType == CONSOLE_TYPE || g_componentType == MESSAGELOG_TYPE)
        return;

    if(length <= 0)
        return;

    Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject();

    int8 v = Mercury::g_trace_packet;
    Mercury::g_trace_packet = 0;
    pBundle->newMessage(MessagelogInterface::writeLog);

    (*pBundle) << logType;
    (*pBundle) << g_componentType;
    (*pBundle) << g_componentID;
    (*pBundle) << g_componentOrder;

    int64 t = time(NULL);
    (*pBundle) << t;
    (*pBundle) << g_kbetime;
    (*pBundle) << str;

    bufferedLogPackets_.push_back(pBundle);

    Mercury::g_trace_packet = v;
    if(!syncStarting_)
    {
        if(pDispatcher_)
            pDispatcher_->addFrequentTask(this);
        syncStarting_ = true;
    }
}
Exemple #6
0
void EntityApp<E>::onExecScriptCommand(Mercury::Channel* pChannel, KBEngine::MemoryStream& s)
{
	std::string cmd;
	s.readBlob(cmd);

	PyObject* pycmd = PyUnicode_DecodeUTF8(cmd.data(), cmd.size(), NULL);
	if(pycmd == NULL)
	{
		SCRIPT_ERROR_CHECK();
		return;
	}

	DEBUG_MSG(boost::format("EntityApp::onExecScriptCommand: size(%1%), command=%2%.\n") % 
		cmd.size() % cmd);

	std::string retbuf = "";
	PyObject* pycmd1 = PyUnicode_AsEncodedString(pycmd, "utf-8", NULL);

	if(script_.run_simpleString(PyBytes_AsString(pycmd1), &retbuf) == 0)
	{
		// 将结果返回给客户端
		Mercury::Bundle bundle;
		ConsoleInterface::ConsoleExecCommandCBMessageHandler msgHandler;
		bundle.newMessage(msgHandler);
		ConsoleInterface::ConsoleExecCommandCBMessageHandlerArgs1::staticAddToBundle(bundle, retbuf);
		bundle.send(this->getNetworkInterface(), pChannel);
	}

	Py_DECREF(pycmd);
	Py_DECREF(pycmd1);
}
Exemple #7
0
//-------------------------------------------------------------------------------------		
void ServerApp::queryWatcher(Mercury::Channel* pChannel, MemoryStream& s)
{
	AUTO_SCOPED_PROFILE("watchers");

	std::string path;
	s >> path;

	MemoryStream::SmartPoolObjectPtr readStreamPtr = MemoryStream::createSmartPoolObj();
	WatcherPaths::root().readWatchers(path, readStreamPtr.get()->get());

	MemoryStream::SmartPoolObjectPtr readStreamPtr1 = MemoryStream::createSmartPoolObj();
	WatcherPaths::root().readChildPaths(path, path, readStreamPtr1.get()->get());

	Mercury::Bundle bundle;
	ConsoleInterface::ConsoleWatcherCBMessageHandler msgHandler;
	bundle.newMessage(msgHandler);

	uint8 type = 0;
	bundle << type;
	bundle.append(readStreamPtr.get()->get());
	bundle.send(getNetworkInterface(), pChannel);

	Mercury::Bundle bundle1;
	bundle1.newMessage(msgHandler);

	type = 1;
	bundle1 << type;
	bundle1.append(readStreamPtr1.get()->get());
	bundle1.send(getNetworkInterface(), pChannel);
}
Exemple #8
0
//-------------------------------------------------------------------------------------
void Loginapp::onChannelDeregister(Mercury::Channel * pChannel)
{
	// 如果是外部通道则处理
	if(!pChannel->isInternal())
	{
		const std::string& extra = pChannel->extra();

		// 通知billing从队列中清除他的请求, 避免拥塞
		if(extra.size() > 0)
		{
			Components::COMPONENTS& cts = Components::getSingleton().getComponents(DBMGR_TYPE);
			Components::ComponentInfos* dbmgrinfos = NULL;

			if(cts.size() > 0)
				dbmgrinfos = &(*cts.begin());

			if(dbmgrinfos == NULL || dbmgrinfos->pChannel == NULL || dbmgrinfos->cid == 0)
			{
			}
			else
			{
				Mercury::Bundle bundle;
				bundle.newMessage(DbmgrInterface::eraseClientReq);
				bundle << extra;
				bundle.send(this->getNetworkInterface(), dbmgrinfos->pChannel);
			}
		}
	}

	ServerApp::onChannelDeregister(pChannel);
}
Exemple #9
0
//-------------------------------------------------------------------------------------
void Loginapp::onReqCreateAccountResult(Mercury::Channel* pChannel, MemoryStream& s)
{
	SERVER_ERROR_CODE failedcode;
	std::string accountName;
	std::string password;
	std::string retdatas = "";

	s >> failedcode >> accountName >> password;
	s.readBlob(retdatas);

	DEBUG_MSG(boost::format("Loginapp::onReqCreateAccountResult: accountName=%1%, failedcode=%2%.\n") %
		accountName.c_str() % failedcode);

	PendingLoginMgr::PLInfos* ptinfos = pendingCreateMgr_.remove(accountName);
	if(ptinfos == NULL)
		return;

	Mercury::Channel* pClientChannel = this->getNetworkInterface().findChannel(ptinfos->addr);
	if(pClientChannel == NULL)
		return;

	pClientChannel->extra("");

	Mercury::Bundle bundle;
	bundle.newMessage(ClientInterface::onCreateAccountResult);
	bundle << failedcode;
	bundle.appendBlob(retdatas);

	bundle.send(this->getNetworkInterface(), pClientChannel);

	SAFE_RELEASE(ptinfos);
}
Exemple #10
0
//-------------------------------------------------------------------------------------
void ClientObject::sendTick()
{
	// 向服务器发送tick
	uint64 check = uint64( Mercury::g_channelExternalTimeout * stampsPerSecond() ) / 2;
	if (timestamp() - lastSentActiveTickTime_ > check)
	{
		lastSentActiveTickTime_ = timestamp();

		Mercury::Bundle bundle;
		if(connectedGateway_)
			bundle.newMessage(BaseappInterface::onClientActiveTick);
		else
			bundle.newMessage(LoginappInterface::onClientActiveTick);
		bundle.send(*pChannel_->endpoint());
	}
}
Exemple #11
0
//-------------------------------------------------------------------------------------
void Baseapp::createInNewSpace(Base* base, PyObject* cell)
{
	ENTITY_ID id = base->getID();
	std::string entityType = base->ob_type->tp_name;
	std::string strCellData = script::Pickler::pickle(base->getCellData());
	uint32 cellDataLength = strCellData.length();

	Mercury::Bundle bundle;

	bundle.newMessage(CellappmgrInterface::reqCreateInNewSpace);

	bundle << entityType;
	bundle << id;
	bundle << componentID_;
	bundle << cellDataLength;

	if(cellDataLength > 0)
		bundle.append(strCellData.data(), cellDataLength);
	
	Components::COMPONENTS& components = Components::getSingleton().getComponents(CELLAPPMGR_TYPE);
	Components::COMPONENTS::iterator iter = components.begin();
	if(iter != components.end())
	{
		bundle.send(this->getNetworkInterface(), (*iter).pChannel);
		return;
	}
	
	ERROR_MSG("Baseapp::createInNewSpace: not found cellappmgr.\n");
}
Exemple #12
0
//-------------------------------------------------------------------------------------
void Baseapp::onGetEntityAppFromDbmgr(Mercury::Channel* pChannel, int32 uid, std::string& username, 
						int8 componentType, uint64 componentID, 
						uint32 intaddr, uint16 intport, uint32 extaddr, uint16 extport)
{
	if(pChannel->isExternal())
		return;

	EntityApp<Base>::onRegisterNewApp(pChannel, uid, username, componentType, componentID, 
									intaddr, intport, extaddr, extport);

	KBEngine::COMPONENT_TYPE tcomponentType = (KBEngine::COMPONENT_TYPE)componentType;

	Components::COMPONENTS cts = Componentbridge::getComponents().getComponents(DBMGR_TYPE);
	KBE_ASSERT(cts.size() >= 1);
	
	Components::ComponentInfos* cinfos = Componentbridge::getComponents().findComponent(tcomponentType, uid, componentID);
	cinfos->pChannel = NULL;

	int ret = Components::getSingleton().connectComponent(tcomponentType, uid, componentID);
	KBE_ASSERT(ret != -1);

	Mercury::Bundle bundle;

	switch(tcomponentType)
	{
	case BASEAPP_TYPE:
		bundle.newMessage(BaseappInterface::onRegisterNewApp);
		BaseappInterface::onRegisterNewAppArgs8::staticAddToBundle(bundle, getUserUID(), getUsername(), BASEAPP_TYPE, componentID_, 
			this->getNetworkInterface().intaddr().ip, this->getNetworkInterface().intaddr().port, 
			this->getNetworkInterface().extaddr().ip, this->getNetworkInterface().extaddr().port);
		break;
	case CELLAPP_TYPE:
		bundle.newMessage(CellappInterface::onRegisterNewApp);
		CellappInterface::onRegisterNewAppArgs8::staticAddToBundle(bundle, getUserUID(), getUsername(), BASEAPP_TYPE, componentID_, 
			this->getNetworkInterface().intaddr().ip, this->getNetworkInterface().intaddr().port, 
			this->getNetworkInterface().extaddr().ip, this->getNetworkInterface().extaddr().port);
		break;
	default:
		KBE_ASSERT(false && "no support!\n");
		break;
	};
	
	bundle.send(this->getNetworkInterface(), cinfos->pChannel);
}
Exemple #13
0
//-------------------------------------------------------------------------------------
bool ClientObject::loginGateWay()
{
	// 请求登录网关
	Mercury::Bundle bundle;
	bundle.newMessage(BaseappInterface::loginGateway);
	bundle << name_;
	bundle << password_;
	bundle.send(*pChannel_->endpoint());
	return true;
}
Exemple #14
0
//-------------------------------------------------------------------------------------
void Baseapp::onClientEntityEnterWorld(Proxy* base)
{
	base->initClientCellPropertys();

	Mercury::Bundle bundle;
	bundle.newMessage(ClientInterface::onEntityEnterWorld);
	bundle << base->getID();
	bundle << base->getSpaceID();
	base->getClientMailbox()->postMail(bundle);
}
Exemple #15
0
//-------------------------------------------------------------------------------------
bool ClientObject::createAccount()
{
	// 创建账号
	Mercury::Bundle bundle;
	bundle.newMessage(LoginappInterface::reqCreateAccount);
	bundle << name_;
	bundle << password_;
	bundle.send(*pChannel_->endpoint());
	return true;
}
Exemple #16
0
//-------------------------------------------------------------------------------------
void Loginapp::reqAccountResetPassword(Mercury::Channel* pChannel, std::string& accountName)
{
	AUTO_SCOPED_PROFILE("reqAccountResetPassword");

	accountName = KBEngine::strutil::kbe_trim(accountName);
	INFO_MSG(boost::format("Loginapp::reqAccountResetPassword: accountName(%1%)\n") %
		accountName);

	Components::COMPONENTS& cts = Components::getSingleton().getComponents(DBMGR_TYPE);
	Components::ComponentInfos* dbmgrinfos = NULL;

	if(cts.size() > 0)
		dbmgrinfos = &(*cts.begin());

	if(dbmgrinfos == NULL || dbmgrinfos->pChannel == NULL || dbmgrinfos->cid == 0)
	{
		ERROR_MSG(boost::format("Loginapp::_createAccount: create(%1%), not found dbmgr!\n") % 
			accountName);

		Mercury::Bundle bundle;
		bundle.newMessage(ClientInterface::onReqAccountResetPasswordCB);
		SERVER_ERROR_CODE retcode = SERVER_ERR_SRV_NO_READY;
		bundle << retcode;
		bundle.send(this->getNetworkInterface(), pChannel);
		return;
	}

	{
		Mercury::Bundle bundle;
		bundle.newMessage(DbmgrInterface::accountReqResetPassword);
		bundle << accountName;
		bundle.send(this->getNetworkInterface(), dbmgrinfos->pChannel);
	}

	{
		Mercury::Bundle bundle;
		bundle.newMessage(ClientInterface::onReqAccountResetPasswordCB);
		SERVER_ERROR_CODE retcode = SERVER_SUCCESS;
		bundle << retcode;
		bundle.send(this->getNetworkInterface(), pChannel);
	}
}
Exemple #17
0
void EntityApp<E>::onExecScriptCommand(Mercury::Channel* pChannel, std::string& strcommand)
{
	DEBUG_MSG("EntityApp::onExecScriptCommand: command size(%d).\n", strcommand.size());

	std::string retbuf = "";
	if(script_.run_simpleString(strcommand, &retbuf) == 0)
	{
		// 将结果返回给客户端
		Mercury::Bundle bundle;
		ConsoleInterface::ConsoleExecCommandCBMessageHandler msgHandler;
		bundle.newMessage(msgHandler);
		ConsoleInterface::ConsoleExecCommandCBMessageHandlerArgs1::staticAddToBundle(bundle, retbuf);
		bundle.send(this->getNetworkInterface(), pChannel);
	}
}
Exemple #18
0
void CLogWindow::OnBnClickedButton1()
{
	// TODO: Add your control notification handler code here
	// 请求服务器拉取日志
	CguiconsoleDlg* dlg = static_cast<CguiconsoleDlg*>(theApp.m_pMainWnd);
	
	HTREEITEM item = dlg->hasCheckApp(MESSAGELOG_TYPE);
	if(item == NULL)
	{
		::AfxMessageBox(L"messagelog no select!");
		return;
	}

	Mercury::Address addr = dlg->getTreeItemAddr(item);

	Mercury::Channel* pChannel = dlg->networkInterface().findChannel(addr);
	if(pChannel == NULL)
	{
		::AfxMessageBox(L"messagelog is error!");
		return;
	}

	Mercury::Bundle bundle;
	bundle.newMessage(MessagelogInterface::registerLogWatcher);

	bundle << getSelLogTypes();
	
	CString apporder;
	m_appIDEdit.GetWindowTextW(apporder);

	char* cs = KBEngine::strutil::wchar2char(apporder.GetBuffer(0));
	COMPONENT_ORDER order = atoi(cs);
	free(cs);

	bundle << order;

	int8 count = 0;
	std::vector<KBEngine::COMPONENT_TYPE> vec = getSelComponents();
	count = vec.size();
	bundle << count;
	std::vector<KBEngine::COMPONENT_TYPE>::iterator iter = vec.begin();
	for(; iter != vec.end(); iter++)
	{
		bundle << (*iter);
	}

	bundle.send(dlg->networkInterface(), pChannel);
}
Exemple #19
0
//-------------------------------------------------------------------------------------
void Base::reqBackupCellData()
{
	if(isGetingCellData_)
		return;

	EntityMailbox* mb = this->getCellMailbox();
	if(mb == NULL)
		return;

	Mercury::Bundle bundle;
	bundle.newMessage(CellappInterface::reqBackupEntityCellData);
	bundle << this->getID();
	mb->postMail(bundle);

	isGetingCellData_ = true;
}
Exemple #20
0
//-------------------------------------------------------------------------------------
bool Base::destroyCellEntity(void)
{
	if(isDestroyed())	
	{
		return false;																					
	}

	if(cellMailbox_  == NULL || cellMailbox_->getChannel() == NULL)
		return false;

	Mercury::Bundle bundle;
	bundle.newMessage(CellappInterface::onDestroyCellEntityFromBaseapp);
	bundle << id_;
	bundle.send(Baseapp::getSingleton().getNetworkInterface(), cellMailbox_->getChannel());
	return true;
}
Exemple #21
0
//-------------------------------------------------------------------------------------
void EntityIDClient::onAlloc(void)
{
	if(hasReqServerAlloc() || getSize() > ID_ENOUGH_LIMIT || idList_.size() > 0)
		return;
	
	Mercury::Bundle bundle;
	bundle.newMessage(DbmgrInterface::onReqAllocEntityID);
	DbmgrInterface::onReqAllocEntityIDArgs2::staticAddToBundle(bundle, pApp_->componentType(), pApp_->componentID());

	Components::COMPONENTS cts =  Components::getSingleton().getComponents(DBMGR_TYPE);
	KBE_ASSERT(cts.size() > 0);
	Components::ComponentInfos* cinfos = &(*cts.begin());
	KBE_ASSERT(cinfos->pChannel != NULL);

	bundle.send(pApp_->getNetworkInterface(), cinfos->pChannel);
	ERROR_MSG("EntityIDClient::onAlloc: not enough(%d) entityIDs!\n", ID_ENOUGH_LIMIT);
}
Exemple #22
0
//-------------------------------------------------------------------------------------
bool ClientObject::login()
{
	if(error_ != C_ERROR_NONE)
		return false;

	Mercury::Bundle bundle;

	std::string bindatas = "bots client";

	// 提交账号密码请求登录
	bundle.newMessage(LoginappInterface::login);
	CLIENT_CTYPE tclient = CLIENT_TYPE_BOTS;
	bundle << tclient;
	bundle.appendBlob(bindatas);
	bundle << name_;
	bundle << password_;
	bundle.send(*pChannel_->endpoint());
	return true;
}
Exemple #23
0
//-------------------------------------------------------------------------------------
void Base::forwardEntityMessageToCellappFromClient(Mercury::Channel* pChannel, MemoryStream& s)
{
	if(pChannel->proxyID() != this->getID())
	{
		WARNING_MSG("Base::forwardEntityMessageToCellappFromClient: not srcEntity(%d/%d).\n", 
			pChannel->proxyID(), this->getID());
		return;
	}

	EntityMailbox* mb = this->getCellMailbox();
	if(mb == NULL)
		return;

	// 将这个消息再打包转寄给cellapp, cellapp会对这个包中的每个消息进行判断
	// 检查是否是entity消息, 否则不合法.
	Mercury::Bundle bundle;
	bundle.newMessage(CellappInterface::forwardEntityMessageToCellappFromClient);
	bundle << this->getID();
	bundle.append(s);
	this->getCellMailbox()->postMail(bundle);
}
Exemple #24
0
//-------------------------------------------------------------------------------------
void Loginapp::onReqCreateMailAccountResult(Mercury::Channel* pChannel, MemoryStream& s)
{
	SERVER_ERROR_CODE failedcode;
	std::string accountName;
	std::string password;
	std::string retdatas = "";

	s >> failedcode >> accountName >> password;
	s.readBlob(retdatas);

	DEBUG_MSG(boost::format("Loginapp::onReqCreateMailAccountResult: accountName=%1%, failedcode=%2%.\n") %
		accountName.c_str() % failedcode);

	if(failedcode == SERVER_SUCCESS)
	{
		threadPool_.addTask(new SendActivateEMailTask(accountName, retdatas, 
			g_kbeSrvConfig.getLoginApp().http_cbhost, 
			g_kbeSrvConfig.getLoginApp().http_cbport));
	}

	PendingLoginMgr::PLInfos* ptinfos = pendingCreateMgr_.remove(accountName);
	if(ptinfos == NULL)
		return;

	Mercury::Channel* pClientChannel = this->getNetworkInterface().findChannel(ptinfos->addr);
	if(pClientChannel == NULL)
		return;

	pClientChannel->extra("");
	retdatas = "";

	Mercury::Bundle bundle;
	bundle.newMessage(ClientInterface::onCreateAccountResult);
	bundle << failedcode;
	bundle.appendBlob(retdatas);

	bundle.send(this->getNetworkInterface(), pClientChannel);

	SAFE_RELEASE(ptinfos);
}
Exemple #25
0
//-------------------------------------------------------------------------------------
void Base::onCellWriteToDBCompleted()
{
	PyObject* pyResult = PyObject_CallMethod(this, 
		const_cast<char*>("onPreArchive"), const_cast<char*>(""));

	if(pyResult != NULL)
		Py_DECREF(pyResult);
	else
		PyErr_PrintEx(0);

	hasDB(true);

	onWriteToDB();

	isArchiveing_ = false;

	MemoryStream* s = MemoryStream::ObjPool().createObject();
	addPersistentsDataToStream(ED_FLAG_ALL, s);

	Components::COMPONENTS cts = Components::getSingleton().getComponents(DBMGR_TYPE);
	Components::ComponentInfos* dbmgrinfos = NULL;

	if(cts.size() > 0)
		dbmgrinfos = &(*cts.begin());

	if(dbmgrinfos == NULL || dbmgrinfos->pChannel == NULL || dbmgrinfos->cid == 0)
	{
		ERROR_MSG("Base::onCellWriteToDBCompleted: not found dbmgr!\n");
		return;
	}

	Mercury::Bundle bundle;
	bundle.newMessage(DbmgrInterface::writeEntity);
	bundle << this->getID();
	bundle << this->getScriptModule()->getUType();
	bundle.append(*s);
	bundle.send(Baseapp::getSingleton().getNetworkInterface(), dbmgrinfos->pChannel);
	MemoryStream::ObjPool().reclaimObject(s);
}
Exemple #26
0
//-------------------------------------------------------------------------------------
void Baseapp::createCellEntity(EntityMailboxAbstract* createToCellMailbox, Base* base)
{
	if(base->getCellMailbox())
	{
		ERROR_MSG("Baseapp::createCellEntity: %s %d has a cell!\n", base->getScriptName(), base->getID());
		return;
	}

	Mercury::Bundle bundle;
	bundle.newMessage(CellappInterface::onCreateCellEntityFromBaseapp);

	ENTITY_ID id = base->getID();
	std::string entityType = base->ob_type->tp_name;
	std::string strCellData = script::Pickler::pickle(base->getCellData());
	uint32 cellDataLength = strCellData.length();
	EntityMailbox* clientMailbox = base->getClientMailbox();
	bool hasClient = (clientMailbox != NULL);
	
	bundle << createToCellMailbox->getID();				// 在这个mailbox所在的cellspace上创建
	bundle << entityType;
	bundle << id;
	bundle << componentID_;
	bundle << hasClient;
	bundle << cellDataLength;

	if(cellDataLength > 0)
		bundle.append(strCellData.data(), cellDataLength);

	if(createToCellMailbox->getChannel() == NULL)
	{
		ERROR_MSG("Baseapp::createCellEntity: not found cellapp(createToCellMailbox:componentID=%"PRAppID", entityID=%d), create is error!\n", 
			createToCellMailbox->getComponentID(), createToCellMailbox->getID());
		base->onCreateCellFailure();
		return;
	}

	bundle.send(this->getNetworkInterface(), createToCellMailbox->getChannel());
}
Exemple #27
0
//-------------------------------------------------------------------------------------
void Baseapp::createBaseAnywhere(const char* entityType, PyObject* params, PyObject* pyCallback)
{
	std::string strInitData = "";
	uint32 initDataLength = 0;
	if(params != NULL && PyDict_Check(params))
	{
		strInitData = script::Pickler::pickle(params);
		initDataLength = strInitData.length();
	}

	Mercury::Bundle bundle;
	bundle.newMessage(BaseappmgrInterface::reqCreateBaseAnywhere);

	bundle << entityType;
	bundle << initDataLength;
	if(initDataLength > 0)
		bundle.append(strInitData.data(), initDataLength);

	bundle << componentID_;

	CALLBACK_ID callbackID = 0;
	if(pyCallback != NULL)
	{
		callbackID = callbackMgr().save(pyCallback);
	}

	bundle << callbackID;

	Components::COMPONENTS& components = Components::getSingleton().getComponents(BASEAPPMGR_TYPE);
	Components::COMPONENTS::iterator iter = components.begin();
	if(iter != components.end())
	{
		bundle.send(this->getNetworkInterface(), (*iter).pChannel);
		return;
	}

	ERROR_MSG("Baseapp::createBaseAnywhere: not found baseappmgr.\n");
}
Exemple #28
0
//-------------------------------------------------------------------------------------
void Space::_addSpaceGeometryMappingToEntityClient(const Entity* pEntity)
{
	if(!hasGeometry_)
	{
		ERROR_MSG(boost::format("KBEngine::addSpaceGeometryMapping: spaceID=%1%, respath=%2%, hasGeometry = false!\n") %
			getID() % loadGeometryPath_);

		return;
	}

	if(!pEntity)
	{
		return;
	}

	if(pEntity->isDestroyed())
	{
		return;
	}

	if(!pEntity->hasWitness())
	{
		WARNING_MSG(boost::format("Space::_addSpaceGeometryMappingToEntityClient: entity %1% no client!\n") % 
			pEntity->getID());

		return;
	}

	Mercury::Bundle* pForwardBundle = Mercury::Bundle::ObjPool().createObject();
	pForwardBundle->newMessage(ClientInterface::addSpaceGeometryMapping);
	(*pForwardBundle) << this->getID();
	(*pForwardBundle) << loadGeometryPath_;

	Mercury::Bundle* pSendBundle = Mercury::Bundle::ObjPool().createObject();
	MERCURY_ENTITY_MESSAGE_FORWARD_CLIENT(pEntity->getID(), (*pSendBundle), (*pForwardBundle));
	pEntity->pWitness()->sendToClient(ClientInterface::addSpaceGeometryMapping, pSendBundle);
	Mercury::Bundle::ObjPool().reclaimObject(pForwardBundle);
}
Exemple #29
0
//-------------------------------------------------------------------------------------
void Space::_addSpaceDatasToEntityClient(const Entity* pEntity)
{
	if(!pEntity)
	{
		return;
	}

	if(pEntity->isDestroyed())
	{
		return;
	}

	if(!pEntity->hasWitness())
	{
		WARNING_MSG(fmt::format("Space::_addSpaceDatasToEntityClient: entity {} no client!\n", 
			pEntity->id()));

		return;
	}

	Mercury::Bundle* pForwardBundle = Mercury::Bundle::ObjPool().createObject();

	pForwardBundle->newMessage(ClientInterface::initSpaceData);
	(*pForwardBundle) << this->id();

	SPACE_DATA::iterator iter = datas_.begin();
	for(; iter != datas_.end(); iter++)
	{
		(*pForwardBundle) << iter->first;
		(*pForwardBundle) << iter->second;
	}

	Mercury::Bundle* pSendBundle = Mercury::Bundle::ObjPool().createObject();
	MERCURY_ENTITY_MESSAGE_FORWARD_CLIENT(pEntity->id(), (*pSendBundle), (*pForwardBundle));

	pEntity->pWitness()->sendToClient(ClientInterface::initSpaceData, pSendBundle);
	Mercury::Bundle::ObjPool().reclaimObject(pForwardBundle);
}
Exemple #30
0
//-------------------------------------------------------------------------------------
void Baseapp::executeRawDatabaseCommand(const char* datas, uint32 size, PyObject* pycallback)
{
	if(datas == NULL)
	{
		ERROR_MSG("Baseapp::executeRawDatabaseCommand: execute is error!\n");
		return;
	}

	Components::COMPONENTS cts = Components::getSingleton().getComponents(DBMGR_TYPE);
	Components::ComponentInfos* dbmgrinfos = NULL;

	if(cts.size() > 0)
		dbmgrinfos = &(*cts.begin());

	if(dbmgrinfos == NULL || dbmgrinfos->pChannel == NULL || dbmgrinfos->cid == 0)
	{
		ERROR_MSG("Baseapp::executeRawDatabaseCommand: not found dbmgr!\n");
		return;
	}

	DEBUG_MSG("KBEngine::executeRawDatabaseCommand:%s.\n", datas);

	Mercury::Bundle bundle;
	bundle.newMessage(DbmgrInterface::executeRawDatabaseCommand);
	bundle << componentID_ << componentType_;

	CALLBACK_ID callbackID = 0;

	if(pycallback && PyCallable_Check(pycallback))
		callbackID = callbackMgr().save(pycallback);

	bundle << callbackID;
	bundle << size;
	bundle.append(datas, size);
	bundle.send(this->getNetworkInterface(), dbmgrinfos->pChannel);
}