コード例 #1
0
ファイル: py_gc.cpp プロジェクト: 1564143452/kbengine
//-------------------------------------------------------------------------------------
void PyGC::set_debug(uint32 flsgs)
{
	PyObject* pyRet = PyObject_CallFunction(set_debugMethod_, 
			const_cast<char*>("i"), flsgs);
	
	SCRIPT_ERROR_CHECK();
	
	if(pyRet)
	{
		S_RELEASE(pyRet);
	}
}
コード例 #2
0
ファイル: script.cpp プロジェクト: ChowZenki/kbengine
//-------------------------------------------------------------------------------------
int Script::run_simpleString(std::string command, std::string* retBufferPtr)
{
	if(retBufferPtr != NULL)
	{
		if(!pyStdouterrHook_->install()){												
			ERROR_MSG("Script::Run_SimpleString::pyStdouterrHook_->install() is failed!\n");
			SCRIPT_ERROR_CHECK();
			return -1;
		}
			
		pyStdouterrHook_->setHookBuffer(retBufferPtr);
		PyRun_SimpleString(command.c_str());
		SCRIPT_ERROR_CHECK();														// 检查是否有错误产生
		pyStdouterrHook_->uninstall();
		return 0;
	}

	PyRun_SimpleString(command.c_str());
	SCRIPT_ERROR_CHECK();															// 检查是否有错误产生
	return 0;
}
コード例 #3
0
ファイル: proxy.cpp プロジェクト: sdsgwangpeng/kbengine
//-------------------------------------------------------------------------------------
int32 Proxy::onLogOnAttempt(const char* addr, uint32 port, const char* password)
{
	PyObject* pyResult = PyObject_CallMethod(this, 
		const_cast<char*>("onLogOnAttempt"), const_cast<char*>("uku"), 
		PyUnicode_FromString(addr), 
		PyLong_FromLong(port),
		PyUnicode_FromString(password)
	);
	
	int32 ret = LOG_ON_REJECT;
	if(pyResult != NULL)
	{
		ret = PyLong_AsLong(pyResult);
		SCRIPT_ERROR_CHECK();
		Py_DECREF(pyResult);
	}
	else
		SCRIPT_ERROR_CHECK();

	return ret;
}
コード例 #4
0
ファイル: clientobjectbase.cpp プロジェクト: Sumxx/kbengine
//-------------------------------------------------------------------------------------	
client::Entity* ClientObjectBase::createEntityCommon(const char* entityType, PyObject* params,
	bool isInitializeScript, ENTITY_ID eid, bool initProperty,
	EntityMailbox* base, EntityMailbox* cell)
{
	KBE_ASSERT(eid > 0);

	ScriptDefModule* sm = EntityDef::findScriptModule(entityType);
	if(sm == NULL)
	{
		PyErr_Format(PyExc_TypeError, "ClientObjectBase::createEntityCommon: entity [%s] not found.\n", entityType);
		PyErr_PrintEx(0);
		return NULL;
	}
	else if(!sm->hasClient())
	{
		PyErr_Format(PyExc_TypeError, "ClientObjectBase::createEntityCommon: entity [%s] not found.\n", entityType);
		PyErr_PrintEx(0);
		return NULL;
	}

	PyObject* obj = sm->createObject();
	
	client::Entity* entity = new(obj) client::Entity(eid, sm, base, cell);

	entity->pClientApp(this);

	if(initProperty)
		entity->initProperty();

	// 将entity加入entities
	pEntities_->add(eid, entity); 

	// 初始化脚本
	if(isInitializeScript)
		entity->initializeEntity(params);

	SCRIPT_ERROR_CHECK();

	if(g_debugEntity)
	{
		INFO_MSG(boost::format("ClientObjectBase::createEntityCommon: new %1% (%2%) refc=%3%.\n") % entityType % eid % obj->ob_refcnt);
	}
	else
	{
		INFO_MSG(boost::format("ClientObjectBase::createEntityCommon: new %1% (%2%)\n") % entityType % eid);
	}

	EventData_CreatedEntity eventdata;
	eventdata.pEntity = entity->getAspect();
	eventHandler_.fire(&eventdata);

	return entity;
}
コード例 #5
0
ファイル: python_app.cpp プロジェクト: aabbox/kbengine
	virtual void handleTimeout(TimerHandle handle, void * pUser)
	{
		int id = ScriptTimersUtil::getIDForHandle(scriptTimers_, handle);

		PyObject *pyRet = PyObject_CallFunction(pyCallback_, "i", id);
		if (pyRet == NULL)
		{
			SCRIPT_ERROR_CHECK();
			return;
		}
		return;
	}
コード例 #6
0
ファイル: copy.cpp プロジェクト: Weooh/kbengine
//-------------------------------------------------------------------------------------
PyObject* Copy::deepcopy(PyObject* pyobj)
{
	PyObject* pyRet = PyObject_CallFunction(deepcopyMethod_, 
		const_cast<char*>("(O)"), pyobj);
	
	if(!pyRet)
	{
		SCRIPT_ERROR_CHECK();
		Py_RETURN_NONE;
	}
	
	return pyRet;
}
コード例 #7
0
ファイル: pystruct.cpp プロジェクト: 1564143452/kbengine
//-------------------------------------------------------------------------------------
PyObject* PyStruct::unpack(PyObject* fmt, PyObject* args)
{
	PyObject* pyRet = PyObject_CallFunction(unpack_, 
			const_cast<char*>("(OO)"), fmt, args);
	
	if (!pyRet)
	{
		ERROR_MSG("PyStruct::unpack: is failed.\n");
	}
	
	SCRIPT_ERROR_CHECK();
	return pyRet;	
}
コード例 #8
0
ファイル: proxy.cpp プロジェクト: JustDo1989/kbengine
//-------------------------------------------------------------------------------------
int32 Proxy::onLogOnAttempt(const char* addr, uint32 port, const char* password)
{
	SCOPED_PROFILE(SCRIPTCALL_PROFILE);

	PyObject* pyResult = PyObject_CallMethod(this, 
		const_cast<char*>("onLogOnAttempt"), const_cast<char*>("sks"), 
		addr, 
		port,
		password
	);
	
	int32 ret = LOG_ON_REJECT;
	if(pyResult != NULL)
	{
		ret = PyLong_AsLong(pyResult);
		SCRIPT_ERROR_CHECK();
		Py_DECREF(pyResult);
	}
	else
		SCRIPT_ERROR_CHECK();

	return ret;
}
コード例 #9
0
ファイル: blob.cpp プロジェクト: AddictXQ/kbengine
//-------------------------------------------------------------------------------------
void Blob::initialize(PyObject* pyBytesInitData)
{
	char *buffer;
	Py_ssize_t length;

	if(PyBytes_AsStringAndSize(pyBytesInitData, &buffer, &length) < 0)
	{
		SCRIPT_ERROR_CHECK();
		return;
	}

	if(length > 0)
		stream_.append(buffer, length);
}
コード例 #10
0
ファイル: clientapp.cpp プロジェクト: 249198000/kbengine
//-------------------------------------------------------------------------------------
bool ClientApp::installPyModules()
{
	registerScript(client::Entity::getScriptType());
	onInstallPyModules();

	// 注册设置脚本输出类型
	APPEND_SCRIPT_MODULE_METHOD(getScript().getModule(),	scriptLogType,	__py_setScriptLogType,	METH_VARARGS,	0)
	if(PyModule_AddIntConstant(this->getScript().getModule(), "LOG_TYPE_NORMAL", log4cxx::ScriptLevel::SCRIPT_INT))
	{
		ERROR_MSG( "ClientApp::installPyModules: Unable to set KBEngine.LOG_TYPE_NORMAL.\n");
	}

	if(PyModule_AddIntConstant(this->getScript().getModule(), "LOG_TYPE_INFO", log4cxx::ScriptLevel::SCRIPT_INFO))
	{
		ERROR_MSG( "ClientApp::installPyModules: Unable to set KBEngine.LOG_TYPE_INFO.\n");
	}

	if(PyModule_AddIntConstant(this->getScript().getModule(), "LOG_TYPE_ERR", log4cxx::ScriptLevel::SCRIPT_ERR))
	{
		ERROR_MSG( "ClientApp::installPyModules: Unable to set KBEngine.LOG_TYPE_ERR.\n");
	}

	if(PyModule_AddIntConstant(this->getScript().getModule(), "LOG_TYPE_DBG", log4cxx::ScriptLevel::SCRIPT_DBG))
	{
		ERROR_MSG( "ClientApp::installPyModules: Unable to set KBEngine.LOG_TYPE_DBG.\n");
	}

	if(PyModule_AddIntConstant(this->getScript().getModule(), "LOG_TYPE_WAR", log4cxx::ScriptLevel::SCRIPT_WAR))
	{
		ERROR_MSG( "ClientApp::installPyModules: Unable to set KBEngine.LOG_TYPE_WAR.\n");
	}

	registerPyObjectToScript("entities", pEntities_);

	// 安装入口模块
	PyObject *entryScriptFileName = PyUnicode_FromString(g_kbeConfig.entryScriptFile());
	if(entryScriptFileName != NULL)
	{
		entryScript_ = PyImport_Import(entryScriptFileName);
		SCRIPT_ERROR_CHECK();
		S_RELEASE(entryScriptFileName);

		if(entryScript_.get() == NULL)
		{
			return false;
		}
	}

	return true;
}
コード例 #11
0
ファイル: pickler.cpp プロジェクト: 321543223/kbengine
//-------------------------------------------------------------------------------------
PyObject* Pickler::unpickle(const std::string& str)
{
	PyObject* pyRet = PyObject_CallFunction(unPicklerMethod_, 
			const_cast<char*>("(y#)"), str.data(), str.length());
	
	if (!pyRet)
	{
		ERROR_MSG(fmt::format("Pickler::unpickle: failed to unpickle[{}] len={}.\n",
			str.c_str(), str.length()));
	}
	
	SCRIPT_ERROR_CHECK();
	return pyRet;	
}
コード例 #12
0
ファイル: pyprofile.cpp プロジェクト: KitoHo/kbengine
//-------------------------------------------------------------------------------------
bool PyProfile::start(std::string profile)
{
	PyProfile::PROFILES::iterator iter = profiles_.find(profile);
	if(iter != profiles_.end())
	{
		ERROR_MSG(boost::format("PyProfile::start: profile(%1%) already exists!\n") % profile);
		return false;
	}

	PyObject* pyRet = PyObject_CallFunction(profileMethod_, 
		const_cast<char*>(""));
	
	if(!pyRet)
	{
		SCRIPT_ERROR_CHECK();
		return false;
	}
	
	PyObject* pyRet1 = PyObject_CallMethod(pyRet, const_cast<char*>("enable"),
		const_cast<char*>(""));

	if(!pyRet1)
	{
		SCRIPT_ERROR_CHECK();
		Py_DECREF(pyRet);
		return false;
	}

	Py_DECREF(pyRet1);

	profiles_[profile] = pyRet;

	char buf[MAX_BUF];
	kbe_snprintf(buf, MAX_BUF, "print(\"PyProfile::start: profile=%s.\")", profile.c_str());
	pScript_->run_simpleString(buf, NULL);
	return true;
}
コード例 #13
0
ファイル: pyprofile.cpp プロジェクト: KitoHo/kbengine
//-------------------------------------------------------------------------------------
void PyProfile::addToStream(std::string profile, MemoryStream* s)
{
	PyProfile::PROFILES::iterator iter = profiles_.find(profile);
	if(iter == profiles_.end())
	{
		ERROR_MSG(boost::format("PyProfile::getstats: profile(%1%) is not exists!\n") % profile);
		return;
	}

	if(!pScript_->pyStdouterrHook()->install()){												
		ERROR_MSG("PyProfile::addToStream: pyStdouterrHook_->install() is failed!\n");
		SCRIPT_ERROR_CHECK();
		return;
	}

	std::string retBufferPtr;
	pScript_->pyStdouterrHook()->setHookBuffer(&retBufferPtr);
	pScript_->pyStdouterrHook()->setPrint(false);
	PyObject* pyRet = PyObject_CallMethod(iter->second.get(), const_cast<char*>("print_stats"),
		const_cast<char*>("s"), const_cast<char*>("time"));
	
	pScript_->pyStdouterrHook()->setPrint(true);
	pScript_->pyStdouterrHook()->uninstall();

	SCRIPT_ERROR_CHECK();

	if(!pyRet)
	{
		return;
	}
	
	(*s) << retBufferPtr;

	// DEBUG_MSG(boost::format("PyProfile::addToStream:%1%") % retBufferPtr);

	Py_DECREF(pyRet);
}
コード例 #14
0
ファイル: loginapp.cpp プロジェクト: 1564143452/kbengine
//-------------------------------------------------------------------------------------
void Loginapp::onReqCreateAccountResult(Network::Channel* pChannel, MemoryStream& s)
{
	SERVER_ERROR_CODE failedcode;
	std::string accountName;
	std::string password;
	std::string retdatas = "";

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

	// 把请求交由脚本处理
	SCOPED_PROFILE(SCRIPTCALL_PROFILE);
	PyObject* pyResult = PyObject_CallMethod(getEntryScript().get(), 
										const_cast<char*>("onCreateAccountCallbackFromDB"), 
										const_cast<char*>("sHy#"), 
										accountName.c_str(),
										failedcode,
										retdatas.c_str(), retdatas.length());

	if(pyResult != NULL)
	{
		Py_DECREF(pyResult);
	}
	else
	{
		SCRIPT_ERROR_CHECK();
	}

	DEBUG_MSG(fmt::format("Loginapp::onReqCreateAccountResult: accountName={}, failedcode={}.\n",
		accountName.c_str(), failedcode));

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

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

	pClientChannel->extra("");

	Network::Bundle* pBundle = Network::Bundle::createPoolObject();
	(*pBundle).newMessage(ClientInterface::onCreateAccountResult);
	(*pBundle) << failedcode;
	(*pBundle).appendBlob(retdatas);

	pClientChannel->send(pBundle);
	SAFE_RELEASE(ptinfos);
}
コード例 #15
0
ファイル: entity.cpp プロジェクト: fengqk/kbengine
//-------------------------------------------------------------------------------------
void Entity::onRemoteMethodCall(Mercury::Channel* pChannel, MemoryStream& s)
{
	SCOPED_PROFILE(SCRIPTCALL_PROFILE);

	if(isDestroyed())																				
	{																										
		ERROR_MSG(boost::format("%1%::onRemoteMethodCall: %2% is destroyed!\n") %											
			getScriptName() % getID());

		s.read_skip(s.opsize());
		return;																							
	}

	ENTITY_METHOD_UID utype = 0;
	s >> utype;
	
	DEBUG_MSG(boost::format("Entity::onRemoteMethodCall: entityID %1%, methodType %2%.\n") % 
				id_ % utype);
	
	MethodDescription* md = scriptModule_->findCellMethodDescription(utype);
	
	if(md == NULL)
	{
		ERROR_MSG(boost::format("Entity::onRemoteMethodCall: can't found method. utype=%1%, callerID:%2%.\n") % utype % id_);
		return;
	}

	md->currCallerID(this->getID());

	PyObject* pyFunc = PyObject_GetAttrString(this, const_cast<char*>
						(md->getName()));

	if(md != NULL)
	{
		PyObject* pyargs = md->createFromStream(&s);
		if(pyargs)
		{
			md->call(pyFunc, pyargs);
			Py_XDECREF(pyargs);
		}
		else
		{
			SCRIPT_ERROR_CHECK();
		}
	}
	
	Py_XDECREF(pyFunc);
}
コード例 #16
0
ファイル: pyprofile.cpp プロジェクト: KitoHo/kbengine
//-------------------------------------------------------------------------------------
void PyProfile::print_stats(const std::string& sort, const std::string& profileName)
{
	PyProfile::PROFILES::iterator iter = profiles_.find(profileName.c_str());
	if(iter == profiles_.end())
	{
		return;
	}

	PyObject* pyRet = PyObject_CallMethod(iter->second.get(), const_cast<char*>("print_stats"),
		const_cast<char*>("s"), const_cast<char*>(sort.c_str()));
	
	if(pyRet)
		Py_DECREF(pyRet);
	else
		SCRIPT_ERROR_CHECK();
}
コード例 #17
0
ファイル: entity_app.hpp プロジェクト: MapleEve/kbengine
void EntityApp<E>::reloadScript(bool fullReload)
{
	EntityDef::reload(fullReload);
	onReloadScript(fullReload);

	// 所有脚本都加载完毕
	PyObject* pyResult = PyObject_CallMethod(getEntryScript().get(), 
										const_cast<char*>("onInit"), 
										const_cast<char*>("i"), 
										1);

	if(pyResult != NULL)
		Py_DECREF(pyResult);
	else
		SCRIPT_ERROR_CHECK();
}
コード例 #18
0
//-------------------------------------------------------------------------------------
void Baseapp::_onCreateBaseAnywhereCallback(Mercury::Channel* pChannel, CALLBACK_ID callbackID, 
	std::string& entityType, ENTITY_ID eid, COMPONENT_ID componentID)
{
	if(callbackID == 0)
		return;

	PyObjectPtr pyCallback = callbackMgr().take(callbackID);
	PyObject* pyargs = PyTuple_New(1);

	if(pChannel != NULL)
	{
		ScriptDefModule* sm = EntityDef::findScriptModule(entityType.c_str());
		if(sm == NULL)
		{
			ERROR_MSG("Baseapp::onCreateBaseAnywhereCallback: can't found entityType:%s.\n", entityType.c_str());
			Py_DECREF(pyargs);
			return;
		}
		
		// 如果entity属于另一个baseapp创建则设置它的mailbox
		Mercury::Channel* pOtherBaseappChannel = Components::getSingleton().findComponent(componentID)->pChannel;
		KBE_ASSERT(pOtherBaseappChannel != NULL);
		PyObject* mb = static_cast<EntityMailbox*>(new EntityMailbox(sm, NULL, componentID, eid, MAILBOX_TYPE_BASE));
		PyTuple_SET_ITEM(pyargs, 0, mb);
		PyObject_CallObject(pyCallback.get(), pyargs);
		//Py_DECREF(mb);
		int i=0;
		i++;
	}
	else
	{
		Base* base = pEntities_->find(eid);
		if(base == NULL)
		{
			ERROR_MSG("Baseapp::onCreateBaseAnywhereCallback: can't found entity:%ld.\n", eid);
			Py_DECREF(pyargs);
			return;
		}

		Py_INCREF(base);
		PyTuple_SET_ITEM(pyargs, 0, base);
		PyObject_CallObject(pyCallback.get(), pyargs);
	}

	SCRIPT_ERROR_CHECK();
	Py_DECREF(pyargs);
}
コード例 #19
0
ファイル: interfaces.cpp プロジェクト: 1564143452/kbengine
//-------------------------------------------------------------------------------------
void Interfaces::reqCreateAccount(Network::Channel* pChannel, KBEngine::MemoryStream& s)
{
	std::string registerName, accountName, password, datas;
	COMPONENT_ID cid;
	uint8 accountType = 0;

	s >> cid >> registerName >> password >> accountType;
	s.readBlob(datas);
	
	if(accountType == (uint8)ACCOUNT_TYPE_MAIL)
	{
	}

	REQCREATE_MAP::iterator iter = reqCreateAccount_requests_.find(registerName);
	if(iter != reqCreateAccount_requests_.end())
	{
		return;
	}

	CreateAccountTask* pinfo = new CreateAccountTask();
	pinfo->commitName = registerName;
	pinfo->accountName = registerName;
	pinfo->getDatas = "";
	pinfo->password = password;
	pinfo->postDatas = datas;
	pinfo->retcode = SERVER_ERR_OP_FAILED;
	pinfo->baseappID = cid;
	pinfo->dbmgrID = pChannel->componentID();
	pinfo->address = pChannel->addr();
	pinfo->enable = true;

	reqCreateAccount_requests_[pinfo->commitName] = pinfo;

	// 把请求交由脚本处理
	SCOPED_PROFILE(SCRIPTCALL_PROFILE);
	PyObject* pyResult = PyObject_CallMethod(getEntryScript().get(), 
										const_cast<char*>("onRequestCreateAccount"), 
										const_cast<char*>("ssy#"), 
										registerName.c_str(), 
										password.c_str(),
										datas.c_str(), datas.length());

	if(pyResult != NULL)
		Py_DECREF(pyResult);
	else
		SCRIPT_ERROR_CHECK();
}
コード例 #20
0
//-------------------------------------------------------------------------------------
void TelnetHandler::processPythonCommand(std::string command)
{
	if(pTelnetServer_->pScript() == NULL || command.size() == 0)
		return;
	
	command += "\n";
	PyObject* pycmd = PyUnicode_DecodeUTF8(command.data(), command.size(), NULL);
	if(pycmd == NULL)
	{
		SCRIPT_ERROR_CHECK();
		return;
	}

	DEBUG_MSG(fmt::format("TelnetHandler::processPythonCommand: size({}), command={}.\n", 
		command.size(), command));

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

	pTelnetServer_->pScript()->run_simpleString(PyBytes_AsString(pycmd1), &retbuf);

	// 把返回值中的'\n'替換成'\r\n',以解决在vt100终端中显示不正确的问题
	std::string::size_type pos = 0;
	while ((pos = retbuf.find('\n', pos)) != std::string::npos)
	{
		if (retbuf[pos - 1] != '\r')
		{
			retbuf.insert(pos, "\r");
			pos++;
		}
		pos++;
	}

	if(retbuf.size() > 0)
	{
		// 将结果返回给客户端
		Network::Bundle* pBundle = Network::Bundle::createPoolObject();
		(*pBundle) << retbuf;
		pEndPoint_->send(pBundle);
		Network::Bundle::reclaimPoolObject(pBundle);
		sendEnter();
	}

	Py_DECREF(pycmd);
	Py_DECREF(pycmd1);
}
コード例 #21
0
//-------------------------------------------------------------------------------------
void ScriptCallbackHandler::handleTimeout( TimerHandle handle, void * pUser )
{
	AUTO_SCOPED_PROFILE("callCallbacks");

	//int id = scriptCallbacks_.getIDForHandle(handle);

	PyObject * pObject = pObject_;

	Py_INCREF( pObject );
	
	PyObject * pResult =
		PyObject_CallFunction( pObject, const_cast<char*>(""));

	Py_XDECREF( pResult );
	Py_DECREF( pObject );
	SCRIPT_ERROR_CHECK();
}
コード例 #22
0
ファイル: method.cpp プロジェクト: sdsgwangpeng/kbengine
//-------------------------------------------------------------------------------------
PyObject* MethodDescription::call(PyObject* func, PyObject* args)
{
	PyObject* pyResult = NULL;
	if (!PyCallable_Check(func))
	{
		PyErr_Format(PyExc_TypeError, "MethodDescription::call: Script[%s] call attempted on a error object!", 
			getName());
	}
	else
	{
		if(checkArgs(args))
			pyResult = PyObject_CallObject(func, args);
	}

	SCRIPT_ERROR_CHECK();
	return pyResult;
}
コード例 #23
0
ファイル: pickler.cpp プロジェクト: 321543223/kbengine
//-------------------------------------------------------------------------------------
std::string Pickler::pickle(PyObject* pyobj, int8 protocol)
{
	PyObject* pyRet = PyObject_CallFunction(picklerMethod_, 
		const_cast<char*>("(Oi)"), pyobj, protocol);
	
	SCRIPT_ERROR_CHECK();
	
	if(pyRet)
	{
		std::string str;
		str.assign(PyBytes_AsString(pyRet), PyBytes_Size(pyRet));
		S_RELEASE(pyRet);
		return str;
	}
	
	return "";
}
コード例 #24
0
ファイル: python_app.cpp プロジェクト: nichunen/kbengine
//-------------------------------------------------------------------------------------
void PythonApp::reloadScript(bool fullReload)
{
	onReloadScript(fullReload);

	// SCOPED_PROFILE(SCRIPTCALL_PROFILE);

	// 所有脚本都加载完毕
	PyObject* pyResult = PyObject_CallMethod(getEntryScript().get(), 
										const_cast<char*>("onInit"), 
										const_cast<char*>("i"), 
										1);

	if(pyResult != NULL)
		Py_DECREF(pyResult);
	else
		SCRIPT_ERROR_CHECK();
}
コード例 #25
0
ファイル: clientapp.cpp プロジェクト: 249198000/kbengine
//-------------------------------------------------------------------------------------
void ClientApp::onTargetChanged()
{ 
	// 所有脚本都加载完毕
	PyObject* pyResult = PyObject_CallMethod(getEntryScript().get(), 
										const_cast<char*>("onTargetChanged"), 
										const_cast<char*>("i"), 
										targetID_);

	if(pyResult != NULL)
	{
		Py_DECREF(pyResult);
	}
	else
	{
		SCRIPT_ERROR_CHECK();
	}
}
コード例 #26
0
ファイル: interfaces.cpp プロジェクト: 1564143452/kbengine
//-------------------------------------------------------------------------------------
void Interfaces::charge(Network::Channel* pChannel, KBEngine::MemoryStream& s)
{
	OrdersCharge* pOrdersCharge = new OrdersCharge();

	pOrdersCharge->timeout = timestamp() + uint64(g_kbeSrvConfig.interfaces_orders_timeout_ * stampsPerSecond());

	pOrdersCharge->dbmgrID = pChannel->componentID();
	pOrdersCharge->address = pChannel->addr();

	s >> pOrdersCharge->baseappID;
	s >> pOrdersCharge->ordersID;
	s >> pOrdersCharge->dbid;
	s.readBlob(pOrdersCharge->postDatas);
	s >> pOrdersCharge->cbid;

	INFO_MSG(fmt::format("Interfaces::charge: componentID={4}, chargeID={0}, dbid={1}, cbid={2}, datas={3}!\n",
		pOrdersCharge->ordersID, pOrdersCharge->dbid, pOrdersCharge->cbid, pOrdersCharge->postDatas, pOrdersCharge->baseappID));

	ORDERS::iterator iter = orders_.find(pOrdersCharge->ordersID);
	if(iter != orders_.end())
	{
		ERROR_MSG(fmt::format("Interfaces::charge: chargeID={} is exist!\n", pOrdersCharge->ordersID));
		delete pOrdersCharge;
		return;
	}

	ChargeTask* pinfo = new ChargeTask();
	pinfo->orders = *pOrdersCharge;
	pinfo->pOrders = pOrdersCharge;
	orders_[pOrdersCharge->ordersID].reset(pOrdersCharge);
	
	// 把请求交由脚本处理
	SCOPED_PROFILE(SCRIPTCALL_PROFILE);
	PyObject* pyResult = PyObject_CallMethod(getEntryScript().get(), 
										const_cast<char*>("onRequestCharge"), 
										const_cast<char*>("sKy#"), 
										pOrdersCharge->ordersID.c_str(),
										pOrdersCharge->dbid, 
										pOrdersCharge->postDatas.c_str(), pOrdersCharge->postDatas.length());

	if(pyResult != NULL)
		Py_DECREF(pyResult);
	else
		SCRIPT_ERROR_CHECK();
}
コード例 #27
0
//-------------------------------------------------------------------------------------
void PyFileDescriptor::callback()
{
	if(pyCallback_ != NULL)
	{
		PyObject* pyResult = PyObject_CallFunction(pyCallback_.get(), 
											const_cast<char*>("i"), 
											fd_);

		if(pyResult != NULL)
			Py_DECREF(pyResult);
		else
			SCRIPT_ERROR_CHECK();
	}
	else
	{
		ERROR_MSG(boost::format("PyFileDescriptor::callback: can't found callback:%1%.\n") % fd_);
	}
}
コード例 #28
0
ファイル: data_download.cpp プロジェクト: lmb0989/kbengine
//-------------------------------------------------------------------------------------
StringDataDownload::StringDataDownload(PyObjectPtr objptr, 
							const std::string & descr, int16 id):
DataDownload(objptr, descr, id)
{
	PyObject* pyobj = PyUnicode_AsUTF8String(objptr.get());
	if(pyobj == NULL)
	{
		SCRIPT_ERROR_CHECK();
		error_ = true;
	}	
	else
	{
		totalBytes_ = (uint32)PyBytes_GET_SIZE(pyobj);
		stream_ = new char[totalBytes_ + 1];
		memcpy(getOutStream(), PyBytes_AS_STRING(pyobj), totalBytes_);
		Py_DECREF(pyobj);
	}
}
コード例 #29
0
//-------------------------------------------------------------------------------------
bool Dbmgr::initializeEnd()
{
	// 添加一个timer, 每秒检查一些状态
	loopCheckTimerHandle_ = this->dispatcher().addTimer(1000000, this,
							reinterpret_cast<void *>(TIMEOUT_CHECK_STATUS));

	mainProcessTimer_ = this->dispatcher().addTimer(1000000 / 50, this,
							reinterpret_cast<void *>(TIMEOUT_TICK));

	// 添加globalData, baseAppData, cellAppData支持
	pGlobalData_ = new GlobalDataServer(GlobalDataServer::GLOBAL_DATA);
	pBaseAppData_ = new GlobalDataServer(GlobalDataServer::BASEAPP_DATA);
	pCellAppData_ = new GlobalDataServer(GlobalDataServer::CELLAPP_DATA);
	pGlobalData_->addConcernComponentType(CELLAPP_TYPE);
	pGlobalData_->addConcernComponentType(BASEAPP_TYPE);
	pBaseAppData_->addConcernComponentType(BASEAPP_TYPE);
	pCellAppData_->addConcernComponentType(CELLAPP_TYPE);

	INFO_MSG(fmt::format("Dbmgr::initializeEnd: digest({})\n", 
		EntityDef::md5().getDigestStr()));
	
	SCOPED_PROFILE(SCRIPTCALL_PROFILE);

	// 所有脚本都加载完毕
	PyObject* pyResult = PyObject_CallMethod(getEntryScript().get(), 
										const_cast<char*>("onDBMgrReady"), 
										const_cast<char*>(""));

	if(pyResult != NULL)
		Py_DECREF(pyResult);
	else
		SCRIPT_ERROR_CHECK();

	pTelnetServer_ = new TelnetServer(&this->dispatcher(), &this->networkInterface());
	pTelnetServer_->pScript(&this->getScript());

	bool ret = pTelnetServer_->start(g_kbeSrvConfig.getDBMgr().telnet_passwd,
		g_kbeSrvConfig.getDBMgr().telnet_deflayer,
		g_kbeSrvConfig.getDBMgr().telnet_port);

	Components::getSingleton().extraData4(pTelnetServer_->port());
	
	return ret && initInterfacesHandler() && initDB();
}
コード例 #30
0
ファイル: interfaces.cpp プロジェクト: 1564143452/kbengine
//-------------------------------------------------------------------------------------
PyObject* Interfaces::__py_accountLoginResponse(PyObject* self, PyObject* args)
{
	const char *commitName;
	const char *realAccountName;
    char *extraDatas = NULL;
    Py_ssize_t extraDatas_size = 0;
	KBEngine::SERVER_ERROR_CODE errCode;

	if (!PyArg_ParseTuple(args, "ssy#H", &commitName, &realAccountName, &extraDatas, &extraDatas_size, &errCode))
		return NULL;

	Interfaces::getSingleton().accountLoginResponse(std::string(commitName),
		std::string(realAccountName),
		(extraDatas && extraDatas_size > 0) ? std::string(extraDatas, extraDatas_size) : std::string(""),
		errCode);

	SCRIPT_ERROR_CHECK();
	S_Return;
}