Beispiel #1
0
//-------------------------------------------------------------------------------------
bool Dbmgr::initializeEnd()
{
	// 添加一个timer, 每秒检查一些状态
	loopCheckTimerHandle_ = this->getMainDispatcher().addTimer(1000000, this,
							reinterpret_cast<void *>(TIMEOUT_CHECK_STATUS));

	mainProcessTimer_ = this->getMainDispatcher().addTimer(1000000 / g_kbeSrvConfig.gameUpdateHertz(), this,
							reinterpret_cast<void *>(TIMEOUT_TICK));

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

	ENGINE_COMPONENT_INFO& dbcfg = g_kbeSrvConfig.getDBMgr();
	pDBInterface_ = DBUtil::create(dbcfg.db_type, dbcfg.db_ip, dbcfg.db_port, 
		dbcfg.db_username, dbcfg.db_password, dbcfg.db_numConnections);

	if(pDBInterface_ == NULL)
	{
		ERROR_MSG("Dbmgr::initializeEnd: can't create dbinterface!\n");
		return false;
	}

	if(!pDBInterface_->attach(dbcfg.db_name))
	{
		ERROR_MSG("Dbmgr::initializeEnd: can't attach to database! %s.\n", pDBInterface_->c_str());
		return false;
	}
	else
	{
		INFO_MSG("Dbmgr::initializeEnd: %s!\n", pDBInterface_->c_str());
	}

	return EntityTables::getSingleton().load(pDBInterface_) && EntityTables::getSingleton().syncToDB();
}
Beispiel #2
0
int run_client ( run_mode_t run_mode ) {

  INFO_MSG ( "Client starting\n" );

  pthread_t thread[run_mode.thread_amount];
  pthread_t statistic_thread;
  client_task_t client_task;
  statistic_task_t statistic_task;
  
  if ( 0 != make_client_task ( &run_mode, &client_task ) ) {

    DEBUG_MSG ( "make_client_task error\n" );
    return 1;
  }

  statistic_task.reporting_timeout = run_mode.reporting_timeout;
  statistic_task.statistic_p = &client_task.statistic;

  pthread_create ( &statistic_thread, NULL, statistics, (void *) &statistic_task );

  int i;
  for ( i = 0; i < run_mode.thread_amount; ++i ) {
    sleep ( 0 );
    if ( 0 != pthread_create( &thread[i], NULL, client, (void *) &client_task ) ) {

      DEBUG_MSG ( "thread create problem\n");
      return 1;
    }
  }

  for ( i = 0; i < run_mode.thread_amount; ++i )
    pthread_join ( thread[i], NULL );

  pthread_join ( statistic_thread, NULL );
 

  DEBUG_MSG ( "client finish\n" );

  return 0;
}
Beispiel #3
0
void initprog() {
    INFO_MSG("Program initialisation");
//Initialisation des Pipeblocks
    totalexectime=0;
    nbcycle=0;
    vpipeline[IF].ins.value=-1;
    vpipeline[IF].dico_entry=-1;
    vpipeline[IF].step=IF;
    vpipeline[ID].ins.value=-1;
    vpipeline[ID].dico_entry=-1;
    vpipeline[ID].step=ID;
    vpipeline[EX].ins.value=-1;
    vpipeline[EX].dico_entry=-1;
    vpipeline[EX].step=EX;
    vpipeline[MEM].ins.value=-1;
    vpipeline[MEM].dico_entry=-1;
    vpipeline[MEM].step=MEM;
    vpipeline[WB].ins.value=-1;
    vpipeline[WB].dico_entry=-1;
    vpipeline[WB].step=WB;


    int j;
    for (j=0; j < NBREG+3; ++j)
    {
        reg_mips[j]=0;             //Initialisation des registres pour debug avant load
    }

    //Initialisation de stack
    reg_mips[29]=0xFFFFF000-4;
    //Initialisation de PC
    //Recuperation de la plage .text
    int k;

    for (k = 0; k < memory->nseg; k++) {
        if(strcmp(memory->seg[k].name,".text")==0) {
            reg_mips[PC]=memory->seg[k].start._32;
        }
    }
}
Beispiel #4
0
//-------------------------------------------------------------------------------------
void Loginapp::reqAccountResetPassword(Mercury::Channel* pChannel, std::string& accountName)
{
	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);
	}
}
Beispiel #5
0
//-------------------------------------------------------------------------------------
void Machine::onFindInterfaceAddr(Mercury::Channel* pChannel, int32 uid, std::string& username, int8 componentType, 
								  int8 findComponentType, uint32 finderAddr, uint16 finderRecvPort)
{
	INFO_MSG("Machine::onFindInterfaceAddr: uid:%d, username:%s, componentType:%s, "
		"find:%s, finderaddr:%s, finderRecvPort:%u.\n", 
		uid, username.c_str(), COMPONENT_NAME_EX((COMPONENT_TYPE)componentType),  COMPONENT_NAME_EX((COMPONENT_TYPE)findComponentType), 
		inet_ntoa((struct in_addr&)finderAddr), ntohs(finderRecvPort));

	Mercury::EndPoint ep;
	ep.socket(SOCK_DGRAM);

	if (!ep.good())
	{
		ERROR_MSG("Machine::onFindInterfaceAddr: Failed to create socket.\n");
		return;
	}
	
	const Components::ComponentInfos* pinfos = 
		Componentbridge::getComponents().findComponent((KBEngine::COMPONENT_TYPE)findComponentType, uid, 0);
	
	Mercury::Bundle bundle;

	if(pinfos == NULL)
	{
		WARNING_MSG("Machine::onFindInterfaceAddr: %s not found %s.\n", COMPONENT_NAME_EX((COMPONENT_TYPE)componentType), 
			COMPONENT_NAME_EX((COMPONENT_TYPE)findComponentType));

		MachineInterface::onBroadcastInterfaceArgs8::staticAddToBundle(bundle, 0, 
			"", UNKNOWN_COMPONENT_TYPE, 0, 0, 0, 0, 0);
	}
	else
		MachineInterface::onBroadcastInterfaceArgs8::staticAddToBundle(bundle, pinfos->uid, 
			pinfos->username, findComponentType, pinfos->cid, pinfos->pIntAddr->ip, pinfos->pIntAddr->port,
			pinfos->pExtAddr->ip, pinfos->pExtAddr->port);
	
	if(finderAddr != 0 && finderRecvPort != 0)
		bundle.sendto(ep, finderRecvPort, finderAddr);
	else
		bundle.send(this->getNetworkInterface(), pChannel);
}
Beispiel #6
0
void EntityApp<E>::onDbmgrInitCompleted(Mercury::Channel* pChannel, 
						GAME_TIME gametime, ENTITY_ID startID, ENTITY_ID endID, int32 startGlobalOrder, int32 startGroupOrder, const std::string& digest)
{
	INFO_MSG(boost::format("EntityApp::onDbmgrInitCompleted: entityID alloc(%1%-%2%), startGlobalOrder=%3%, startGroupOrder=%4%, digest=%5%.\n") %
		startID % endID % startGlobalOrder % startGroupOrder % digest);

	startGlobalOrder_ = startGlobalOrder;
	startGroupOrder_ = startGroupOrder;
	g_componentGlobalOrder = startGlobalOrder;
	g_componentGroupOrder = startGroupOrder;

	idClient_.onAddRange(startID, endID);
	g_kbetime = gametime;

	if(digest != EntityDef::md5().getDigestStr())
	{
		ERROR_MSG(boost::format("EntityApp::onDbmgrInitCompleted: digest not match. curr(%1%) != dbmgr(%2%)\n") %
			EntityDef::md5().getDigestStr() % digest);

		this->shutDown();
	}
}
//-------------------------------------------------------------------------------------
bool NetworkInterface::deregisterChannel(Channel* pChannel)
{
	const Address & addr = pChannel->addr();
	KBE_ASSERT(pChannel->endpoint() != NULL);

	if(pChannelDeregisterHandler_)
	{
		pChannelDeregisterHandler_->onChannelDeregister(pChannel);
	}

	INFO_MSG("NetworkInterface::deregisterChannel: del channel: %s\n", pChannel->c_str());

	if (!channelMap_.erase(addr))
	{
		CRITICAL_MSG( "NetworkInterface::deregisterChannel: "
				"Channel not found %s!\n",
			pChannel->c_str() );
		return false;
	}
	
	return true;
}
Beispiel #8
0
//-------------------------------------------------------------------------------------
void InterfacesHandler_ThirdParty::onChargeCB(KBEngine::MemoryStream& s)
{
    std::string chargeID;
    std::string datas;
    CALLBACK_ID cbid;
    COMPONENT_ID cid;
    DBID dbid;
    SERVER_ERROR_CODE retcode;

    s >> cid;
    s >> chargeID;
    s >> dbid;
    s.readBlob(datas);
    s >> cbid;
    s >> retcode;

    INFO_MSG(fmt::format("InterfacesHandler_ThirdParty::onChargeCB: chargeID={0}, dbid={3}, cbid={1}, cid={4}, datas={2}!\n",
                         chargeID, cbid, datas, dbid, cid));

    Components::ComponentInfos* cinfos = Components::getSingleton().findComponent(BASEAPP_TYPE, cid);
    if(cinfos == NULL || cinfos->pChannel == NULL || cinfos->pChannel->isDestroyed())
    {
        ERROR_MSG(fmt::format("InterfacesHandler_ThirdParty::onChargeCB: baseapp not found!, chargeID={}, cid={}.\n",
                              chargeID, cid));

        return;
    }

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

    (*pBundle).newMessage(BaseappInterface::onChargeCB);
    (*pBundle) << chargeID;
    (*pBundle) << dbid;
    (*pBundle).appendBlob(datas);
    (*pBundle) << cbid;
    (*pBundle) << retcode;

    cinfos->pChannel->send(pBundle);
}
Beispiel #9
0
//-------------------------------------------------------------------------------------
void Loginapp::onReqAccountResetPasswordCB(Network::Channel* pChannel, std::string& accountName, std::string& email,
	SERVER_ERROR_CODE failedcode, std::string& code)
{
	INFO_MSG(fmt::format("Loginapp::onReqAccountResetPasswordCB: {}, email={}, failedcode={}!\n", 
		accountName, email, failedcode));

	if(failedcode == SERVER_SUCCESS)
	{
		Components::COMPONENTS& loginapps = Components::getSingleton().getComponents(LOGINAPP_TYPE);

		std::string http_host = "localhost";
		if(startGroupOrder_ == 1)
		{
			if(strlen((const char*)&g_kbeSrvConfig.getLoginApp().externalAddress) > 0)
				http_host = g_kbeSrvConfig.getBaseApp().externalAddress;
			else
				http_host = inet_ntoa((struct in_addr&)Loginapp::getSingleton().networkInterface().extaddr().ip);
		}
		else
		{
			Components::COMPONENTS::iterator iter = loginapps.begin();
			for(; iter != loginapps.end(); ++iter)
			{
				if((*iter).groupOrderid == 1)
				{
					if(strlen((const char*)&(*iter).externalAddressEx) > 0)
						http_host = (*iter).externalAddressEx;
					else
						http_host = inet_ntoa((struct in_addr&)(*iter).pExtAddr->ip);
				}
			}
		}

		threadPool_.addTask(new SendResetPasswordEMailTask(email, code, 
			http_host,  
			g_kbeSrvConfig.getLoginApp().http_cbport));
	}
}
void CNavigationMap::handleKeyEvent( const KeyEvent & event )
{
	//if( !InputDevices::isKeyDown( KeyEvent::KEY_LEFTMOUSE ) )
	//	return;

	POINT pt = WorldManager::instance().currentCursorPosition();
	INFO_MSG("Êó±ê×ø±ê£º%d,%d\n", pt.x,pt.y );
	if( pt.x<m_LeftTop.x || pt.x>m_RightDown.x || pt.y<m_LeftTop.y || pt.y>m_RightDown.y)
		return;
	
	float xratio = (pt.x - m_center.x) / m_fNavWidth;
	float zratio = (pt.y - m_center.y) / m_fNavWidth;

	BoundingBox spaceBB(ChunkManager::instance().cameraSpace()->gridBounds());
	const Vector3& minB = spaceBB.minBounds();
	const Vector3& maxB = spaceBB.maxBounds();
	//INFO_MSG("%f,%f,%f\n", spaceBB.width(), spaceBB.height(), spaceBB.depth());
	float fWidth = spaceBB.width();
	float fDepth = spaceBB.depth();
	
	Vector3 camerapos = Moo::rc().invView().applyToOrigin();

	camerapos.x = fWidth*xratio/2.0f;
	camerapos.z = -fDepth*zratio/2.0f;

	Vector3 cameradir = Moo::rc().invView().applyToUnitAxisVector(2);
	CCustomWorldCamera::Instance().TeleportCamera( camerapos, cameradir);

	//Vector3 worldRay = WorldManager::instance().getWorldRay(pt);

	//Vector3 start =  Moo::rc().invView().applyToOrigin();
	//Vector3 extent = start + worldRay * Moo::rc().camera().farPlane();

	//CustomCollision sc;
	//float fRet = ChunkManager::instance().cameraSpace()->collide( start, extent, sc );

	//Vector3 vMousePt = start + worldRay * sc.getCollideDist() ;
}
Beispiel #11
0
//-------------------------------------------------------------------------------------
void ServerApp::onRegisterNewApp(Mercury::Channel* pChannel, int32 uid, std::string& username, 
						int8 componentType, uint64 componentID, int8 globalorderID, int8 grouporderID,
						uint32 intaddr, uint16 intport, uint32 extaddr, uint16 extport, std::string& extaddrEx)
{
	if(pChannel->isExternal())
		return;

	INFO_MSG(boost::format("ServerApp::onRegisterNewApp: uid:%1%, username:%2%, componentType:%3%, "
			"componentID:%4%, globalorderID=%10%, grouporderID=%11%, intaddr:%5%, intport:%6%, extaddr:%7%, extport:%8%,  from %9%.\n") %
			uid % 
			username.c_str() % 
			COMPONENT_NAME_EX((COMPONENT_TYPE)componentType) % 
			componentID %
			inet_ntoa((struct in_addr&)intaddr) %
			ntohs(intport) %
			(extaddr != 0 ? inet_ntoa((struct in_addr&)extaddr) : "nonsupport") %
			ntohs(extport) %
			pChannel->c_str() %
			((int32)globalorderID) % 
			((int32)grouporderID));

	Components::ComponentInfos* cinfos = Componentbridge::getComponents().findComponent((
		KBEngine::COMPONENT_TYPE)componentType, uid, componentID);

	pChannel->componentID(componentID);

	if(cinfos == NULL)
	{
		Componentbridge::getComponents().addComponent(uid, username.c_str(), 
			(KBEngine::COMPONENT_TYPE)componentType, componentID, globalorderID, grouporderID, intaddr, intport, extaddr, extport, extaddrEx, 0,
			0.f, 0.f, 0, 0, 0, 0, 0, pChannel);
	}
	else
	{
		KBE_ASSERT(cinfos->pIntAddr->ip == intaddr && cinfos->pIntAddr->port == intport);
		cinfos->pChannel = pChannel;
	}
}
Beispiel #12
0
//-------------------------------------------------------------------------------------
void Cellapp::executeRawDatabaseCommand(const char* datas, uint32 size, PyObject* pycallback, ENTITY_ID eid)
{
	if(datas == NULL)
	{
		ERROR_MSG("KBEngine::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("KBEngine::executeRawDatabaseCommand: not found dbmgr!\n");
		return;
	}

	INFO_MSG(boost::format("KBEngine::executeRawDatabaseCommand%1%:%2%.\n") % (eid > 0 ? (boost::format("(entityID=%1%)") % eid).str() : "") % datas);

	Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject();
	(*pBundle).newMessage(DbmgrInterface::executeRawDatabaseCommand);
	(*pBundle) << eid;
	(*pBundle) << componentID_ << componentType_;

	CALLBACK_ID callbackID = 0;

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

	(*pBundle) << callbackID;
	(*pBundle) << size;
	(*pBundle).append(datas, size);
	(*pBundle).send(this->getNetworkInterface(), dbmgrinfos->pChannel);
	Mercury::Bundle::ObjPool().reclaimObject(pBundle);
}
Beispiel #13
0
Elf32_Sym *find_symbol(char *name, Elf32_Ehdr *elf_h)
{
	int i;
	char *tname;

	Elf32_Shdr *symtab_sect = find_section(".symtab", elf_h);
	Elf32_Shdr *strtab_sect = find_section(".strtab", elf_h);

	DEBUG_MSG("Searching for symbol %s in elf @ 0x%x\n", name, (npi_t)elf_h);

	if (symtab_sect == NULL) {
		ERROR_MSG("Found no .symtab section\n");
		return NULL;
	}

	if (strtab_sect == NULL) {
		ERROR_MSG("Found no .strtab section\n");
		return NULL;
	}

	if (symtab_sect->sh_entsize != sizeof(Elf32_Sym)) {
		ERROR_MSG("Wrong .symtab entry size\n");
		return NULL;
	}

	Elf32_Sym *syms = (Elf32_Sym *)((u_int32_t)elf_h + symtab_sect->sh_offset);

	u_int32_t n = symtab_sect->sh_size / symtab_sect->sh_entsize;
	INFO_MSG("Found %i entries in .symtab (sect at address 0x%x)\n", n, (unsigned int)syms);

	for (i = 0; i < n; i++) {
		tname = get_shstr(elf_h, strtab_sect, syms[i].st_name);
		if (strcmp(tname, name) == 0) {
			return &syms[i];
		}
	}
	return NULL;
}
Beispiel #14
0
//-------------------------------------------------------------------------------------
void ServerApp::onRegisterNewApp(Network::Channel* pChannel, int32 uid, std::string& username, 
						COMPONENT_TYPE componentType, COMPONENT_ID componentID, COMPONENT_ORDER globalorderID, COMPONENT_ORDER grouporderID,
						uint32 intaddr, uint16 intport, uint32 extaddr, uint16 extport, std::string& extaddrEx)
{
	if(pChannel->isExternal())
		return;

	INFO_MSG(fmt::format("ServerApp::onRegisterNewApp: uid:{0}, username:{1}, componentType:{2}, "
			"componentID:{3}, globalorderID={9}, grouporderID={10}, intaddr:{4}, intport:{5}, extaddr:{6}, extport:{7},  from {8}.\n",
			uid,
			username.c_str(),
			COMPONENT_NAME_EX((COMPONENT_TYPE)componentType), 
			componentID,
			inet_ntoa((struct in_addr&)intaddr),
			ntohs(intport),
			(extaddr != 0 ? inet_ntoa((struct in_addr&)extaddr) : "nonsupport"),
			ntohs(extport),
			pChannel->c_str(),
			((int32)globalorderID),
			((int32)grouporderID)));

	Components::ComponentInfos* cinfos = Components::getSingleton().findComponent((
		KBEngine::COMPONENT_TYPE)componentType, uid, componentID);

	pChannel->componentID(componentID);

	if(cinfos == NULL)
	{
		Components::getSingleton().addComponent(uid, username.c_str(), 
			(KBEngine::COMPONENT_TYPE)componentType, componentID, globalorderID, grouporderID, intaddr, intport, extaddr, extport, extaddrEx, 0,
			0.f, 0.f, 0, 0, 0, 0, 0, pChannel);
	}
	else
	{
		KBE_ASSERT(cinfos->pIntAddr->ip == intaddr && cinfos->pIntAddr->port == intport);
		cinfos->pChannel = pChannel;
	}
}
Beispiel #15
0
//-------------------------------------------------------------------------------------
bool Dbmgr::initializeEnd()
{
	// 添加一个timer, 每秒检查一些状态
	loopCheckTimerHandle_ = this->getMainDispatcher().addTimer(1000000, this,
							reinterpret_cast<void *>(TIMEOUT_CHECK_STATUS));

	mainProcessTimer_ = this->getMainDispatcher().addTimer(1000000 / g_kbeSrvConfig.gameUpdateHertz(), 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(boost::format("Dbmgr::initializeEnd: digest(%1%)\n") % 
		EntityDef::md5().getDigestStr());

	return initBillingHandler() && initDB();
}
Beispiel #16
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()));
	
	return initInterfacesHandler() && initDB();
}
Beispiel #17
0
//-------------------------------------------------------------------------------------
void ServerApp::hello(Network::Channel* pChannel, MemoryStream& s)
{
	std::string verInfo, scriptVerInfo, encryptedKey;

	s >> verInfo >> scriptVerInfo;
	s.readBlob(encryptedKey);

	char buf[1024];

	if(encryptedKey.size() > 3)
	{
		char *c = buf;

		for (int i=0; i < (int)encryptedKey.size(); ++i)
		{
			c += sprintf(c, "%02hhX ", (unsigned char)encryptedKey.data()[i]);
		}

		c[-1] = '\0';
	}
	else
	{
		encryptedKey = "";
		sprintf(buf, "None");
		buf[4] = '\0';
	}

	INFO_MSG(fmt::format("ServerApp::onHello: verInfo={}, scriptVerInfo={}, encryptedKey={}, addr:{}\n", 
		verInfo, scriptVerInfo, buf, pChannel->c_str()));

	if(verInfo != KBEVersion::versionString())
		onVersionNotMatch(pChannel);
	else if(scriptVerInfo != KBEVersion::scriptVersionString())
		onScriptVersionNotMatch(pChannel);
	else
		onHello(pChannel, verInfo, scriptVerInfo, encryptedKey);
}
Beispiel #18
0
//-------------------------------------------------------------------------------------
void Logger::registerLogWatcher(Network::Channel* pChannel, KBEngine::MemoryStream& s)
{
	LogWatcher* pLogwatcher = &logWatchers_[pChannel->addr()];
	if(!pLogwatcher->createFromStream(&s))
	{
		ERROR_MSG(fmt::format("Logger::registerLogWatcher: addr={} is failed!\n",
			pChannel->addr().c_str()));

		logWatchers_.erase(pChannel->addr());
		s.done();
		return;
	}

	pLogwatcher->addr(pChannel->addr());

	INFO_MSG(fmt::format("Logger::registerLogWatcher: addr={0} is successfully!\n",
		pChannel->addr().c_str()));

	bool first;
	s >> first;

	if(first)
		sendInitLogs(*pLogwatcher);
}
Beispiel #19
0
//-------------------------------------------------------------------------------------
void ServerApp::reqKillServer(Network::Channel* pChannel, MemoryStream& s)
{
	if(pChannel->isExternal())
		return;

	COMPONENT_ID componentID;
	COMPONENT_TYPE componentType;
	std::string username;
	int32 uid;
	std::string reason;

	s >> componentID >> componentType >> username >> uid >> reason;

	INFO_MSG(fmt::format("ServerApp::reqKillServer: requester(uid:{}, username:{}, componentType:{}, "
				"componentID:{}, reason:{}, from {})\n",
				uid, 
				username, 
				COMPONENT_NAME_EX((COMPONENT_TYPE)componentType),
				componentID,
				reason,
				pChannel->c_str()));

	CRITICAL_MSG("The application was killed!\n");
}
Beispiel #20
0
//-------------------------------------------------------------------------------------
void Dbmgr::accountNewPassword(Mercury::Channel* pChannel, ENTITY_ID entityID, std::string& accountName, 
							   std::string& password, std::string& newpassword)
{
	INFO_MSG(boost::format("Dbmgr::accountNewPassword: accountName=%1%.\n") % accountName);
	pBillingAccountHandler_->accountNewPassword(pChannel, entityID, accountName, password, newpassword);
}
Beispiel #21
0
/* Load and initialise the modules */
eemo_rv eemo_conf_load_modules(void)
{
	unsigned int mod_count = 0;
	config_setting_t* modules_conf = NULL;
	int i = 0;
	int loaded_modules = 0;

	/* Get a reference to the module configuration */
	modules_conf = config_lookup(eemo_conf_get_config_t(), "modules");

	if (modules_conf == NULL)
	{
		ERROR_MSG("No modules have been configured");

		return ERV_NO_MODULES;
	}

	/* Initialise list of modules */
	modules = NULL;

	/* Determine the number of configured modules */
	mod_count = config_setting_length(modules_conf);

	/* Now load the configured modules one-by-one */
	for (i = 0; i < mod_count; i++)
	{
		config_setting_t* mod_conf = NULL;
		eemo_module_spec* new_mod = NULL;
		const char* lib_path = NULL;
		eemo_plugin_get_fn_table_fn mod_getfn = NULL;
		void* mod_entry = NULL;

		/* Retrieve the module to load */
		mod_conf = config_setting_get_elem(modules_conf, i);

		if (mod_conf == NULL)
		{
			ERROR_MSG("Failed to enumerate next configured module");

			continue;
		}

		/* Retrieve the module path setting */
		if ((config_setting_lookup_string(mod_conf, "lib", &lib_path) != CONFIG_TRUE) || (lib_path == NULL))
		{
			ERROR_MSG("No library specified in module section for '%s'", config_setting_name(mod_conf));

			continue;
		}

		new_mod = (eemo_module_spec*) malloc(sizeof(eemo_module_spec));

		if (new_mod == NULL)
		{
			ERROR_MSG("Error allocating memory for a new module");

			continue;
		}

		new_mod->mod_path = strdup(lib_path);

		if (new_mod->mod_path == NULL)
		{
			ERROR_MSG("Error allocating memory for a new module");

			free(new_mod);

			continue;
		}

		new_mod->mod_conf_base = (char*) malloc((strlen("modules.") + 
		                                         strlen(config_setting_name(mod_conf)) + 
							 strlen(".modconf") + 1) * sizeof(char));

		if (new_mod->mod_conf_base == NULL)
		{
			ERROR_MSG("Error allocating memory for a new module");

			free(new_mod->mod_path);
			free(new_mod);

			continue;
		}

		sprintf(new_mod->mod_conf_base, "modules.%s.modconf", config_setting_name(mod_conf));

		/* Now try to load the module */
		new_mod->mod_handle = dlopen(new_mod->mod_path, RTLD_NOW | RTLD_LOCAL);

		if (new_mod->mod_handle == NULL)
		{
			ERROR_MSG("Failed to load module %s (%s)", new_mod->mod_path, dlerror());

			free(new_mod->mod_path);
			free(new_mod->mod_conf_base);
			free(new_mod);

			continue;
		}

		INFO_MSG("Loaded module %s", new_mod->mod_path);

		/* Retrieve the module entry point */

		/* FIXME: we need to use this ugly memcpy kludge in order to avoid the compiler complaining about
		 *        data pointers getting converted to function pointers. The reason for this is that dlsym
		 *        returns a void* which is a data pointer. In effect, dlsym violates the ANSI C standard
		 *        here... See http://pubs.opengroup.org/onlinepubs/009695399/functions/dlsym.html */

		mod_entry = dlsym(new_mod->mod_handle, "eemo_plugin_get_fn_table");
		memcpy(&mod_getfn, &mod_entry, sizeof(void*));

		if (mod_getfn == NULL)
		{
			ERROR_MSG("Failed to resolve entry point eemo_plugin_get_fn_table in %s", new_mod->mod_path);

			free(new_mod->mod_path);
			free(new_mod->mod_conf_base);
			free(new_mod);

			continue;
		}

		/* Retrieve the module function table */
		if ((mod_getfn)(&new_mod->mod_fn_table) != ERV_OK)
		{
			ERROR_MSG("Failed to retrieve the function table in %s", new_mod->mod_path);

			dlclose(new_mod->mod_handle);
			free(new_mod->mod_path);
			free(new_mod->mod_conf_base);
			free(new_mod);

			continue;
		}

		/* Check the function table version */
		if (new_mod->mod_fn_table->fn_table_version > EEMO_PLUGIN_FN_VERSION)
		{
			ERROR_MSG("Unsupported plugin module API version %d in module %s",
				new_mod->mod_fn_table->fn_table_version,
				new_mod->mod_path);

			dlclose(new_mod->mod_handle);
			free(new_mod->mod_path);
			free(new_mod->mod_conf_base);
			free(new_mod);

			continue;
		}

		/* Initialise the module */
		if ((new_mod->mod_fn_table->plugin_init)(&eemo_function_table, new_mod->mod_conf_base) != ERV_OK)
		{
			ERROR_MSG("Failed to initialise module %s", (new_mod->mod_fn_table->plugin_getdescription)());

			dlclose(new_mod->mod_handle);
			free(new_mod->mod_path);
			free(new_mod->mod_conf_base);
			free(new_mod);

			continue;
		}

		INFO_MSG("Initialised module %s", (new_mod->mod_fn_table->plugin_getdescription)());

		/* Add it to the list of modules */
		LL_APPEND(modules, new_mod);

		loaded_modules++;
	}

	if (loaded_modules == 0)
	{
		ERROR_MSG("Failed to load any modules");

		return ERV_NO_MODULES;
	}

	return ERV_OK;
}
Beispiel #22
0
//-------------------------------------------------------------------------------------
void Dbmgr::accountReqBindMail(Mercury::Channel* pChannel, ENTITY_ID entityID, std::string& accountName, 
							   std::string& password, std::string& email)
{
	INFO_MSG(boost::format("Dbmgr::accountReqBindMail: accountName=%1%, email=%2%.\n") % accountName % email);
	pBillingAccountHandler_->accountReqBindMail(pChannel, entityID, accountName, password, email);
}
Beispiel #23
0
//-------------------------------------------------------------------------------------
void Dbmgr::accountBindMail(Mercury::Channel* pChannel, std::string& username, std::string& scode)
{
	INFO_MSG(boost::format("Dbmgr::accountBindMail: username=%1%, scode=%2%.\n") % username % scode);
	pBillingAccountHandler_->accountBindMail(pChannel, username, scode);
}
Beispiel #24
0
//-------------------------------------------------------------------------------------
void Dbmgr::accountActivate(Mercury::Channel* pChannel, std::string& scode)
{
	INFO_MSG(boost::format("Dbmgr::accountActivate: code=%1%.\n") % scode);
	pBillingAccountHandler_->accountActivate(pChannel, scode);
}
Beispiel #25
0
//-------------------------------------------------------------------------------------
void Dbmgr::accountResetPassword(Mercury::Channel* pChannel, std::string& accountName, std::string& newpassword, std::string& code)
{
	INFO_MSG(boost::format("Dbmgr::accountResetPassword: accountName=%1%.\n") % accountName);
	pBillingAccountHandler_->accountResetPassword(pChannel, accountName, newpassword, code);
}
pivacy_cardemu_emulator::pivacy_cardemu_emulator()
{
	pivacy_ui_lib_init();
	
	reset();
	
	/* Load credentials */
	std::string credential_dir;
	
	if ((pivacy_conf_get_string("emulation.credentials", "directory", credential_dir, NULL) != PRV_OK) || credential_dir.empty())
	{
		ERROR_MSG("Failed to retrieve credential directory from the configuration");
		
		return;
	}
	
	/* 
	 * Enumerate all files in the directory and tried to load all
	 * files with the extension .xml as if they were a pivacy
	 * credential
	 */
	DIR* dir = opendir(credential_dir.c_str());
	
	if (dir == NULL)
	{
		ERROR_MSG("Failed to open directory %s, cannot load credentials", credential_dir.c_str());
		
		return;
	}
	
	struct dirent* entry = NULL;
	
	while ((entry = readdir(dir)) != NULL)
	{
		// Check if this is the . or .. entry
		if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, ".."))
		{
			continue;
		}
		
		// Convert the name of the entry to a C++ string
		std::string name(entry->d_name);
		bool is_regular_file = false;

#if defined(_DIRENT_HAVE_D_TYPE) && defined(_BSD_SOURCE)
		// Determine the type of the entry
		switch(entry->d_type)
		{
		case DT_DIR:
			// Do nothing
			break;
		case DT_REG:
			// This is a regular file
			is_regular_file = true;
			break;
		default:
			// Do nothing
			break;
		}
#else
		// The entry type has to be determined using lstat
		struct stat entry_status;

		std::string full_path = credential_dir + "/" + name;

		if (!lstat(full_path.c_str(), &entry_status))
		{
			if (S_ISDIR(entry_status.st_mode))
			{
				// Do nothing
			}
			else if (S_ISREG(entry_status.st_mode))
			{
				is_regular_file = true;
			}
			else
			{
				// Do nothing
			}
		}
#endif

		if (is_regular_file)
		{
			// Attempt to read the file as if it were a credential
			pivacy_credential* cred = pivacy_credential_xml_rw::i()->read_pivacy_credential(credential_dir + "/" + name);
			
			if (cred != NULL)
			{
				// Attempt to read the public key belonging to the credential
				if (cred->get_issuer_public_key(credential_dir) != NULL)
				{
					INFO_MSG("Successfully loaded credential %s issued by %s", cred->get_name().c_str(), cred->get_issuer().c_str());
				}
				
				credentials.push_back(cred);
			}
		}
	}

	ui_connected = false;
	
	pivacy_conf_get_bool("ui", "enable", use_ui, true);
	pivacy_conf_get_bool("ui", "optional", ui_optional, false);
	
	INFO_MSG("The Pivacy UI is %s", use_ui ? "enabled" : "disabled");
	INFO_MSG("Use of the Pivacy UI is %s", ui_optional ? "optional" : "mandatory");
	
	ui_connected = (pivacy_ui_connect() == PRV_OK);
	
	if (ui_connected)
	{
		pivacy_ui_show_status(PIVACY_STATE_WAIT);
	}
}
Beispiel #27
0
//-------------------------------------------------------------------------------------
void GlobalDataServer::broadcastDataChange(Mercury::Channel* pChannel, COMPONENT_TYPE componentType, 
										const std::string& key, const std::string& value, bool isDelete)
{
	INFO_MSG(boost::format("GlobalDataServer::broadcastDataChange: writer(%1%), key_size=%2%, val_size=%3%, isdelete=%4%.\n") %
		COMPONENT_NAME_EX(componentType) % key.size() % value.size() % (int)isDelete);

	std::vector<COMPONENT_TYPE>::iterator iter = concernComponentTypes_.begin();
	for(; iter != concernComponentTypes_.end(); iter++)
	{
		COMPONENT_TYPE ct = (*iter);
		Components::COMPONENTS& channels = Components::getSingleton().getComponents(ct);
		Components::COMPONENTS::iterator iter1 = channels.begin();
		
		for(; iter1 != channels.end(); iter1++)
		{
			Mercury::Channel* lpChannel = iter1->pChannel;
			KBE_ASSERT(lpChannel != NULL);

			if(pChannel == lpChannel)
				continue;

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

			switch(dataType_)
			{
			case GLOBAL_DATA:
				if(componentType == CELLAPP_TYPE)
				{
					(*pBundle).newMessage(CellappInterface::onBroadcastGlobalDataChange);
				}
				else if(componentType == BASEAPP_TYPE)
				{
					(*pBundle).newMessage(BaseappInterface::onBroadcastGlobalDataChange);
				}
				else
				{
					KBE_ASSERT(false && "componentType is error!\n");
				}
				break;
			case GLOBAL_BASES:
				(*pBundle).newMessage(BaseappInterface::onBroadcastGlobalBasesChange);
				break;
			case CELLAPP_DATA:
				(*pBundle).newMessage(CellappInterface::onBroadcastCellAppDataChange);
				break;
			default:
				KBE_ASSERT(false && "dataType is error!\n");
				break;
			};

			
			(*pBundle) << isDelete;
			ArraySize slen = key.size();
			(*pBundle) << slen;
			(*pBundle).assign(key.data(), slen);

			if(!isDelete)
			{
				slen = value.size();
				(*pBundle) << slen;
				(*pBundle).assign(value.data(), slen);
			}

			(*pBundle).send(*lpChannel->endpoint());
			Mercury::Bundle::ObjPool().reclaimObject(pBundle);
		}
	}
}
Beispiel #28
0
//-------------------------------------------------------------------------------------
bool ThreadPool::addTask(TPTask* tptask)
{
    THREAD_MUTEX_LOCK(threadStateList_mutex_);
    if(currentFreeThreadCount_ > 0)
    {
        std::list<TPThread*>::iterator itr = freeThreadList_.begin();
        TPThread* tptd = (TPThread*)(*itr);
        freeThreadList_.erase(itr);
        busyThreadList_.push_back(tptd);
        --currentFreeThreadCount_;

        //INFO_MSG("ThreadPool::currFree:%d, currThreadCount:%d, busy:[%d]\n",
        //		 currentFreeThreadCount_, currentThreadCount_, busyThreadList_count_);

        tptd->task(tptask);												// 给线程设置新任务

#if KBE_PLATFORM == PLATFORM_WIN32
        if(tptd->sendCondSignal()== 0) {
#else
        if(tptd->sendCondSignal()!= 0) {
#endif
            ERROR_MSG("ThreadPool::addTask: pthread_cond_signal is error!\n");
            THREAD_MUTEX_UNLOCK(threadStateList_mutex_);
            return false;
        }

        THREAD_MUTEX_UNLOCK(threadStateList_mutex_);
        return true;
    }

    bufferTask(tptask);

    if(isThreadCountMax())
    {
        THREAD_MUTEX_UNLOCK(threadStateList_mutex_);

        //WARNING_MSG(fmt::format("ThreadPool::addTask: can't createthread, the poolsize is full({}).\n,
        //	maxThreadCount_));

        return false;
    }

    for(uint32 i=0; i<extraNewAddThreadCount_; i++)
    {
        TPThread* tptd = createThread(300);									// 设定5分钟未使用则退出的线程
        if(!tptd)
        {
#if KBE_PLATFORM == PLATFORM_WIN32
            ERROR_MSG("ThreadPool::addTask: the ThreadPool create thread is error! ... \n");
#else
            ERROR_MSG(fmt::format("ThreadPool::addTask: the ThreadPool create thread is error:{0}\n",
                                  kbe_strerror()));
#endif
        }

        allThreadList_.push_back(tptd);										// 所有的线程列表
        freeThreadList_.push_back(tptd);									// 闲置的线程列表
        ++currentThreadCount_;
        ++currentFreeThreadCount_;

    }

    INFO_MSG(fmt::format("ThreadPool::addTask: new Thread, currThreadCount: {0}\n",
                         currentThreadCount_));

    THREAD_MUTEX_UNLOCK(threadStateList_mutex_);
    return true;
}

//-------------------------------------------------------------------------------------
bool ThreadPool::hasThread(TPThread* pTPThread)
{
    bool ret = true;

    THREAD_MUTEX_LOCK(threadStateList_mutex_);

    std::list<TPThread*>::iterator itr1 = find(allThreadList_.begin(), allThreadList_.end(), pTPThread);
    if(itr1 == allThreadList_.end())
        ret = false;

    THREAD_MUTEX_UNLOCK(threadStateList_mutex_);

    return ret;
}
Beispiel #29
0
//-------------------------------------------------------------------------------------
void Resmgr::pirnt(void)
{
    INFO_MSG(boost::format("Resmgr::initialize: KBE_ROOT=%1%\n") % kb_env_.root.c_str());
    INFO_MSG(boost::format("Resmgr::initialize: KBE_RES_PATH=%1%\n") % kb_env_.res_path.c_str());
    INFO_MSG(boost::format("Resmgr::initialize: KBE_HYBRID_PATH=%1%\n") % kb_env_.hybrid_path.c_str());
}
Beispiel #30
0
//-------------------------------------------------------------------------------------
void Resmgr::pirnt(void)
{
	INFO_MSG("Resmgr::initialize: KBE_ROOT=%s\n", kb_env_.root.c_str());
	INFO_MSG("Resmgr::initialize: KBE_RES_PATH=%s\n", kb_env_.res_path.c_str());
	INFO_MSG("Resmgr::initialize: KBE_HYBRID_PATH=%s\n", kb_env_.hybrid_path.c_str());
}