Exemplo n.º 1
0
//-------------------------------------------------------------------------------------
bool FixedDict::checkDataChanged(const char* keyName, PyObject* value, bool isDelete)
{
	FixedDictType::FIXEDDICT_KEYTYPE_MAP& keyTypes = _dataType->getKeyTypes();
	FixedDictType::FIXEDDICT_KEYTYPE_MAP::const_iterator iter = keyTypes.begin();
	
	for(; iter != keyTypes.end(); ++iter)
	{
		if((*iter).first == keyName)
		{
			if(isDelete)
			{
				char err[255];
				kbe_snprintf(err, 255, "can't delete from FIXED_DICT key[%s].\n", keyName);
				PyErr_SetString(PyExc_TypeError, err);
				PyErr_PrintEx(0);
				return false;
			}
			else
			{
				DataType* dataType = (*iter).second->dataType;
				if(!dataType->isSameType(value)){
					return false;
				}
			}

			return true;
		}
	}

	char err[255];
	kbe_snprintf(err, 255, "set FIXED_DICT to a unknown key[%s].\n", keyName);
	PyErr_SetString(PyExc_TypeError, err);
	PyErr_PrintEx(0);
	return false;
}
Exemplo n.º 2
0
//-------------------------------------------------------------------------------------
bool KBEEntityLogTableMysql::logEntity(DBInterface * dbi, const char* ip, uint32 port, DBID dbid,
					COMPONENT_ID componentID, ENTITY_ID entityID, ENTITY_SCRIPT_UID entityType)
{
	std::string sqlstr = "insert into kbe_entitylog (entityDBID, entityType, entityID, ip, port, componentID) values(";

	char* tbuf = new char[MAX_BUF * 3];

	kbe_snprintf(tbuf, MAX_BUF, "%"PRDBID, dbid);
	sqlstr += tbuf;
	sqlstr += ",";
	
	kbe_snprintf(tbuf, MAX_BUF, "%u", entityType);
	sqlstr += tbuf;
	sqlstr += ",";

	kbe_snprintf(tbuf, MAX_BUF, "%d", entityID);
	sqlstr += tbuf;
	sqlstr += ",\"";

	mysql_real_escape_string(static_cast<DBInterfaceMysql*>(dbi)->mysql(), 
		tbuf, ip, strlen(ip));

	sqlstr += tbuf;
	sqlstr += "\",";

	kbe_snprintf(tbuf, MAX_BUF, "%u", port);
	sqlstr += tbuf;
	sqlstr += ",";
	
	kbe_snprintf(tbuf, MAX_BUF, "%"PRDBID, componentID);
	sqlstr += tbuf;
	sqlstr += ")";

	SAFE_RELEASE_ARRAY(tbuf);

	try
	{
		if(!dbi->query(sqlstr.c_str(), sqlstr.size(), false))
		{
			// 1062 int err = dbi->getlasterror(); 
			return false;
		}
	}
	catch (std::exception & e)
	{
		DBException& dbe = static_cast<DBException&>(e);
		if(dbe.isLostConnection())
		{
			if(dbi->processException(e))
				return true;
		}

		return false;
	}

	return true;
}
Exemplo n.º 3
0
//-------------------------------------------------------------------------------------
DBInterface* DBUtil::createInterface(const std::string& name, bool showinfo)
{
	DBInterfaceInfo* pDBInfo = g_kbeSrvConfig.dbInterface(name);
	if (!pDBInfo)
	{
		ERROR_MSG(fmt::format("DBUtil::createInterface: not found dbInterface({})\n",
			name));

		return NULL;
	}

	DBInterface* dbinterface = NULL;

	if (strcmp(pDBInfo->db_type, "mysql") == 0)
	{
		dbinterface = new DBInterfaceMysql(name.c_str(), pDBInfo->db_unicodeString_characterSet, pDBInfo->db_unicodeString_collation);
	}
	else if (strcmp(pDBInfo->db_type, "redis") == 0)
	{
		dbinterface = new DBInterfaceRedis(name.c_str());
	}

	if(dbinterface == NULL)
	{
		ERROR_MSG(fmt::format("DBUtil::createInterface: create db_interface error! type={}\n",
			pDBInfo->db_type));

		return NULL;
	}
	
	kbe_snprintf(dbinterface->db_type_, MAX_BUF, "%s", pDBInfo->db_type);
	dbinterface->db_port_ = pDBInfo->db_port;
	kbe_snprintf(dbinterface->db_ip_, MAX_IP, "%s", pDBInfo->db_ip);
	kbe_snprintf(dbinterface->db_username_, MAX_BUF, "%s", pDBInfo->db_username);
	dbinterface->db_numConnections_ = pDBInfo->db_numConnections;
	kbe_snprintf(dbinterface->db_password_, MAX_BUF, "%s", pDBInfo->db_password);

	if (!dbinterface->attach(pDBInfo->db_name))
	{
		ERROR_MSG(fmt::format("DBUtil::createInterface: attach to database failed!\n\tdbinterface={0:p}\n\targs={1}\n",
			(void*)&dbinterface, dbinterface->c_str()));

		delete dbinterface;
		return NULL;
	}
	else
	{
		if(showinfo)
		{
			INFO_MSG(fmt::format("DBUtil::createInterface[{0:p}]: {1}\n", (void*)&dbinterface, 
				dbinterface->c_str()));
		}
	}

	return dbinterface;
}
Exemplo n.º 4
0
//-------------------------------------------------------------------------------------
void TelnetCProfileHandler::sendStream(MemoryStream* s)
{
	if(isDestroyed_) return;
	
	std::string datas;
	uint32 timinglen;
	ArraySize size;

	(*s) >> timinglen >> size;

	datas = "ncalls\ttottime\tpercall\tcumtime\tpercall\tfilename:lineno(function)\r\n";

	while(size-- > 0)
	{
		uint32 count;
		float lastTime;
		float sumTime;
		float lastIntTime;
		float sumIntTime;
		std::string name;

		(*s) >> name >> count >> lastTime >> sumTime >> lastIntTime >> sumIntTime;

		char buf[256];
		kbe_snprintf(buf, 256, "%u", count);
		datas += buf;
		datas += "\t";

		kbe_snprintf(buf, 256, "%.3f", sumTime);
		datas += buf;
		datas += "\t";

		kbe_snprintf(buf, 256, "%.3f", lastTime);
		datas += buf;
		datas += "\t";

		kbe_snprintf(buf, 256, "%.3f", sumIntTime);
		datas += buf;
		datas += "\t";

		kbe_snprintf(buf, 256, "%.3f", lastIntTime);
		datas += buf;
		datas += "\t";

		datas += name;
		datas += "\r\n";
	};

	pTelnetHandler_->onProfileEnd(datas);
}
Exemplo n.º 5
0
//-------------------------------------------------------------------------------------
bool ProfileVal::initializeWatcher()
{
	if(initWatcher_)
		return false;

	initWatcher_ = true;

	char buf[MAX_BUF];
	kbe_snprintf(buf, MAX_BUF, "cprofiles/%s/%s/lastTime", pProfileGroup_->name(), name_.c_str());
	WATCH_OBJECT(buf, &lastTime_, &TimeStamp::stamp);

	kbe_snprintf(buf, MAX_BUF, "cprofiles/%s/%s/sumTime", pProfileGroup_->name(), name_.c_str());
	WATCH_OBJECT(buf, &sumTime_, &TimeStamp::stamp);

	kbe_snprintf(buf, MAX_BUF, "cprofiles/%s/%s/lastIntTime", pProfileGroup_->name(), name_.c_str());
	WATCH_OBJECT(buf, &lastIntTime_, &TimeStamp::stamp);

	kbe_snprintf(buf, MAX_BUF, "cprofiles/%s/%s/sumIntTime", pProfileGroup_->name(), name_.c_str());
	WATCH_OBJECT(buf, &sumIntTime_, &TimeStamp::stamp);

	kbe_snprintf(buf, MAX_BUF, "cprofiles/%s/%s/lastQuantity", pProfileGroup_->name(), name_.c_str());
	WATCH_OBJECT(buf, lastQuantity_);

	kbe_snprintf(buf, MAX_BUF, "cprofiles/%s/%s/sumQuantity", pProfileGroup_->name(), name_.c_str());
	WATCH_OBJECT(buf, sumQuantity_);

	kbe_snprintf(buf, MAX_BUF, "cprofiles/%s/%s/count", pProfileGroup_->name(), name_.c_str());
	WATCH_OBJECT(buf, count_);

	kbe_snprintf(buf, MAX_BUF, "cprofiles/%s/%s/inProgress", pProfileGroup_->name(), name_.c_str());
	WATCH_OBJECT(buf, inProgress_);

	return true;
}
Exemplo n.º 6
0
//-------------------------------------------------------------------------------------
bool KBEEmailVerificationTableMysql::logAccount(DBInterface * dbi, int8 type, const std::string& name, 
												const std::string& datas, const std::string& code)
{
	std::string sqlstr = "insert into kbe_email_verification (accountName, type, datas, code, logtime) values(";

	char* tbuf = new char[MAX_BUF > datas.size() ? MAX_BUF * 3 : 
		(code.size() > datas.size() ? code.size() * 3 : datas.size() * 3)];

	mysql_real_escape_string(static_cast<DBInterfaceMysql*>(dbi)->mysql(), 
		tbuf, name.c_str(), name.size());

	sqlstr += "\"";
	sqlstr += tbuf;
	sqlstr += "\",";

	kbe_snprintf(tbuf, MAX_BUF, "%d,", type);
	sqlstr += tbuf;
	
	mysql_real_escape_string(static_cast<DBInterfaceMysql*>(dbi)->mysql(), 
		tbuf, datas.c_str(), datas.size());

	sqlstr += "\"";
	sqlstr += tbuf;
	sqlstr += "\",";
	
	mysql_real_escape_string(static_cast<DBInterfaceMysql*>(dbi)->mysql(), 
		tbuf, code.c_str(), code.size());

	sqlstr += "\"";
	sqlstr += tbuf;
	sqlstr += "\",";

	kbe_snprintf(tbuf, MAX_BUF, "%"PRTime, time(NULL));

	sqlstr += tbuf;
	sqlstr += ")";

	SAFE_RELEASE_ARRAY(tbuf);

	if(!dbi->query(sqlstr.c_str(), sqlstr.size(), false))
	{
		ERROR_MSG(fmt::format("KBEEmailVerificationTableMysql::logAccount({}): sql({}) is failed({})!\n", 
				code, sqlstr, dbi->getstrerror()));

		return false;
	}

	return true;
}
Exemplo n.º 7
0
//-------------------------------------------------------------------------------------
DBInterface* DBUtil::createInterface(bool showinfo)
{
	ENGINE_COMPONENT_INFO& dbcfg = g_kbeSrvConfig.getDBMgr();
	DBInterface* dbinterface = NULL;

	if(strcmp(dbcfg.db_type, "mysql") == 0)
	{
		dbinterface = new DBInterfaceMysql(dbcfg.db_unicodeString_characterSet, dbcfg.db_unicodeString_collation);
	}
	else if(strcmp(dbcfg.db_type, "redis") == 0)
	{
		dbinterface = new DBInterfaceRedis();
	}

	if(dbinterface == NULL)
	{
		ERROR_MSG(fmt::format("DBUtil::createInterface: create db_interface error! type={}\n",
			dbcfg.db_type));

		return NULL;
	}
	
	kbe_snprintf(dbinterface->db_type_, MAX_BUF, "%s", dbcfg.db_type);
	dbinterface->db_port_ = dbcfg.db_port;	
	kbe_snprintf(dbinterface->db_ip_, MAX_IP, "%s", dbcfg.db_ip);
	kbe_snprintf(dbinterface->db_username_, MAX_BUF, "%s", dbcfg.db_username);
	dbinterface->db_numConnections_ = dbcfg.db_numConnections;
	kbe_snprintf(dbinterface->db_password_, MAX_BUF, "%s", dbcfg.db_password);

	if(!dbinterface->attach(DBUtil::dbname()))
	{
		ERROR_MSG(fmt::format("DBUtil::createInterface: attach to database failed!\n\tdbinterface={0:p}\n\targs={1}\n",
			(void*)&dbinterface, dbinterface->c_str()));

		delete dbinterface;
		return NULL;
	}
	else
	{
		if(showinfo)
		{
			INFO_MSG(fmt::format("DBUtil::createInterface[{0:p}]: {1}\n", (void*)&dbinterface, 
				dbinterface->c_str()));
		}
	}

	return dbinterface;
}
Exemplo n.º 8
0
//-------------------------------------------------------------------------------------
bool DBUtil::initialize()
{
	ENGINE_COMPONENT_INFO& dbcfg = g_kbeSrvConfig.getDBMgr();

	if(dbcfg.db_passwordEncrypt)
	{
		// 如果小于64则表示目前还是明文密码
		if(strlen(dbcfg.db_password) < 64)
		{
			WARNING_MSG(boost::format("DBUtil::createInterface: db password is not encrypted!\nplease use password(rsa):\n%1%\n") 
				% KBEKey::getSingleton().encrypt(dbcfg.db_password));
		}
		else
		{
			std::string out = KBEKey::getSingleton().decrypt(dbcfg.db_password);

			if(out.size() == 0)
				return false;

			kbe_snprintf(dbcfg.db_password, MAX_BUF, "%s", out.c_str());
		}
	}

	return true;
}
Exemplo n.º 9
0
//-------------------------------------------------------------------------------------
bool PyProfile::stop(std::string profile)
{
	PyProfile::PROFILES::iterator iter = profiles_.find(profile);
	if(iter == profiles_.end())
	{
		ERROR_MSG(boost::format("PyProfile::stop: profile(%1%) is not exists!\n") % profile);
		return false;
	}

	PyObject* pyRet = PyObject_CallMethod(iter->second.get(), const_cast<char*>("disable"),
		const_cast<char*>(""));
	
	if(!pyRet)
	{
		SCRIPT_ERROR_CHECK();
		return false;
	}
	
	Py_DECREF(pyRet);

	char buf[MAX_BUF];
	kbe_snprintf(buf, MAX_BUF, "print(\"PyProfile::stop: profile=%s.\")", profile.c_str());
	pScript_->run_simpleString(buf, NULL);
	return true;
}
Exemplo n.º 10
0
//-------------------------------------------------------------------------------------
bool KBEEmailVerificationTableMysql::delAccount(DBInterface * dbi, int8 type, const std::string& name)
{
	std::string sqlstr = "delete from kbe_email_verification where accountName=";

	char* tbuf = new char[MAX_BUF * 3];

	mysql_real_escape_string(static_cast<DBInterfaceMysql*>(dbi)->mysql(), 
		tbuf, name.c_str(), name.size());

	sqlstr += "\"";
	sqlstr += tbuf;
	sqlstr += "\" and type=";
	
	kbe_snprintf(tbuf, MAX_BUF, "%d", type);
	sqlstr += tbuf;

	SAFE_RELEASE_ARRAY(tbuf);

	if(!dbi->query(sqlstr.c_str(), sqlstr.size(), false))
	{
		ERROR_MSG(fmt::format("KBEEmailVerificationTableMysql::delAccount({}): sql({}) is failed({})!\n", 
				name, sqlstr, dbi->getstrerror()));

		return false;
	}

	return true;
}
Exemplo n.º 11
0
//-------------------------------------------------------------------------------------
bool KBEAccountTableMysql::logAccount(DBInterface * dbi, ACCOUNT_INFOS& info)
{
	std::string sqlstr = "insert into kbe_accountinfos (accountName, password, entityDBID) values(";

	char* tbuf = new char[MAX_BUF * 3];

	mysql_real_escape_string(static_cast<DBInterfaceMysql*>(dbi)->mysql(), 
		tbuf, info.name.c_str(), info.name.size());

	sqlstr += "\"";
	sqlstr += tbuf;
	sqlstr += "\",";

	mysql_real_escape_string(static_cast<DBInterfaceMysql*>(dbi)->mysql(), 
		tbuf, info.password.c_str(), info.password.size());

	sqlstr += "md5(\"";
	sqlstr += tbuf;
	sqlstr += "\"),";

	kbe_snprintf(tbuf, MAX_BUF, "%"PRDBID, info.dbid);

	sqlstr += tbuf;
	sqlstr += ")";

	SAFE_RELEASE_ARRAY(tbuf);

	// 如果查询失败则返回存在, 避免可能产生的错误
	if(!dbi->query(sqlstr.c_str(), sqlstr.size(), false))
		return false;

	return true;
}
Exemplo n.º 12
0
// 获得系统产生的最后一次错误描述
inline char* kbe_strerror(int ierrorno = 0)
{
#if KBE_PLATFORM == PLATFORM_WIN32
	if(ierrorno == 0)
		ierrorno = GetLastError();

	static char lpMsgBuf[256] = {0};
	
	/*
	FormatMessage(
		FORMAT_MESSAGE_FROM_SYSTEM |
		FORMAT_MESSAGE_IGNORE_INSERTS,
		NULL,
		ierrorno,
		MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
		(LPTSTR) &lpMsgBuf,
		1024,
		NULL
	); 
	*/
	kbe_snprintf(lpMsgBuf, 256, "errorno=%d",  ierrorno);
	return lpMsgBuf;
#else
	if(ierrorno != 0)
		return strerror(ierrorno);
	return strerror(errno);
#endif
}
Exemplo n.º 13
0
//-------------------------------------------------------------------------------------
void ServerApp::hello(Network::Channel* pChannel, MemoryStream& s)
{
	std::string verInfo, scriptVerInfo, encryptedKey;

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

	char buf[MAX_BUF];
	std::string encryptedKey_str;

	if (encryptedKey.size() > 3 && encryptedKey.size() <= 65535)
	{
		for (int i = 0; i < (int)encryptedKey.size(); ++i)
		{
			memset(buf, 0, MAX_BUF);
			kbe_snprintf(buf, MAX_BUF / 2, "%02hhX ", (unsigned char)encryptedKey.data()[i]);
			encryptedKey_str += buf;
		}
	}
	else
	{
		encryptedKey = "";
		encryptedKey_str = "None";
	}

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

	if(verInfo != KBEVersion::versionString())
		onVersionNotMatch(pChannel);
	else if(scriptVerInfo != KBEVersion::scriptVersionString())
		onScriptVersionNotMatch(pChannel);
	else
		onHello(pChannel, verInfo, scriptVerInfo, encryptedKey);
}
Exemplo n.º 14
0
void myassert(const char * exp, const char * func, const char * file, unsigned int line)
{
    kbe_snprintf(_g_buf, DBG_PT_SIZE, "assertion failed: %s, file %s, line %d, at: %s\n", exp, file, line, func);
    dbghelper.print_msg(_g_buf);
    printf("%s", _g_buf);
    abort();
}
Exemplo n.º 15
0
void DebugHelper::critical_msg(const char * str, ...)
{
    if(str == NULL)
        return;

    KBEngine::thread::ThreadGuard tg(&this->logMutex);

#ifdef NO_USE_LOG4CXX
#else
    va_list ap;
    va_start(ap, str);
#if KBE_PLATFORM == PLATFORM_WIN32
    uint32 size = _vsnprintf(_g_buf, DBG_PT_SIZE, str, ap);
#else
    uint32 size = vsnprintf(_g_buf, DBG_PT_SIZE, str, ap);
#endif
    va_end(ap);
    char buf[DBG_PT_SIZE];
    kbe_snprintf(buf, DBG_PT_SIZE, "%s(%d) -> %s\n\t%s\n", _currFile.c_str(), _currLine, _currFuncName.c_str(), _g_buf);
    LOG4CXX_FATAL(g_logger, buf);
#endif

    setFile("", "", 0);

    onMessage(LOG_CRITICAL, _g_buf, size);
}
Exemplo n.º 16
0
//-------------------------------------------------------------------------------------
const char* DBInterfaceMysql::c_str()
{
	static char strdescr[MAX_BUF];
	kbe_snprintf(strdescr, MAX_BUF, "dbtype=mysql, ip=%s, port=%u, currdatabase=%s, username=%s, connected=%s.\n", 
		db_ip_, db_port_, db_name_, db_username_, pMysql_ == NULL ? "no" : "yes");

	return strdescr;
}
Exemplo n.º 17
0
//-------------------------------------------------------------------------------------
void Proxy::giveClientTo(Proxy* proxy)
{
	if(clientMailbox_ == NULL || clientMailbox_->getChannel() == NULL)
	{
		char err[255];																				
		kbe_snprintf(err, 255, "Proxy[%s]::giveClientTo: no has client.", getScriptName());			
		PyErr_SetString(PyExc_TypeError, err);														
		PyErr_PrintEx(0);	
		onGiveClientToFailure();
		return;
	}

	Mercury::Channel* lpChannel = clientMailbox_->getChannel();

	if(proxy)
	{
		EntityMailbox* mb = proxy->getClientMailbox();
		if(mb != NULL)
		{
			ERROR_MSG(boost::format("Proxy::giveClientTo: %1%[%2%] give client to %3%[%4%], %5% have clientMailbox.\n") % 
					getScriptName() %
					getID() %
					proxy->getScriptName() % 
					proxy->getID() %
					proxy->getScriptName());

			onGiveClientToFailure();
			return;
		}

		if(getCellMailbox())
		{
			// 通知cell丢失客户端
			Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject();
			(*pBundle).newMessage(CellappInterface::onResetWitness);
			(*pBundle) << this->getID();
			getCellMailbox()->postMail((*pBundle));
			Mercury::Bundle::ObjPool().reclaimObject(pBundle);
		}

		entitiesEnabled_ = false;
		getClientMailbox()->addr(Mercury::Address::NONE);
		Py_DECREF(getClientMailbox());
		proxy->onGiveClientTo(lpChannel);
		setClientMailbox(NULL);
		addr(Mercury::Address::NONE);
		
		if(proxy->getClientMailbox() != NULL)
		{
			// 通知client销毁当前entity
			Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject();
			(*pBundle).newMessage(ClientInterface::onEntityDestroyed);
			(*pBundle) << this->getID();
			proxy->getClientMailbox()->postMail((*pBundle));
			Mercury::Bundle::ObjPool().reclaimObject(pBundle);
		}
	}
}
Exemplo n.º 18
0
//-------------------------------------------------------------------------------------
void Messagelog::writeLog(Mercury::Channel* pChannel, KBEngine::MemoryStream& s)
{
	uint32 logtype;
	COMPONENT_TYPE componentType = UNKNOWN_COMPONENT_TYPE;
	COMPONENT_ID componentID = 0;
	COMPONENT_ORDER componentOrder = 0;
	int64 t;
	GAME_TIME kbetime = 0;
	std::string str;
	std::stringstream logstream;

	s >> logtype;
	s >> componentType;
	s >> componentID;
	s >> componentOrder;
	s >> t >> kbetime;
	s >> str;

	time_t tt = static_cast<time_t>(t);	
    tm* aTm = localtime(&tt);
    //       YYYY   year
    //       MM     month (2 digits 01-12)
    //       DD     day (2 digits 01-31)
    //       HH     hour (2 digits 00-23)
    //       MM     minutes (2 digits 00-59)
    //       SS     seconds (2 digits 00-59)

	if(aTm == NULL)
	{
		ERROR_MSG("Messagelog::writeLog: log is error!\n");
		return;
	}

	char timebuf[MAX_BUF];
    kbe_snprintf(timebuf, MAX_BUF, " [%-4d-%02d-%02d %02d:%02d:%02d %02d] ", aTm->tm_year+1900, aTm->tm_mon+1, 
		aTm->tm_mday, aTm->tm_hour, aTm->tm_min, aTm->tm_sec, kbetime);

	logstream << KBELOG_TYPE_NAME_EX(logtype);
	logstream << " ";
	logstream << COMPONENT_NAME_EX_1(componentType);
	logstream << " ";
	logstream << componentID;
	logstream << " ";
	logstream << (int)componentOrder;
	logstream << timebuf;
	logstream << "- ";
	logstream << str;
	DebugHelper::getSingleton().changeLogger(COMPONENT_NAME_EX(componentType));
	PRINT_MSG(logstream.str());
	DebugHelper::getSingleton().changeLogger("default");

	LOG_WATCHERS::iterator iter = logWatchers_.begin();
	for(; iter != logWatchers_.end(); iter++)
	{
		iter->second.onMessage(logtype, componentType, componentID, componentOrder, t, kbetime, str, logstream);
	}
}
Exemplo n.º 19
0
//-------------------------------------------------------------------------------------
void DebugHelper::initHelper(COMPONENT_TYPE componentType)
{
#ifndef NO_USE_LOG4CXX
    g_logger = log4cxx::Logger::getLogger(COMPONENT_NAME_EX(componentType));
    char helpConfig[256];

    if(componentType == CLIENT_TYPE)
    {
        kbe_snprintf(helpConfig, 256, "log4j.properties");
    }
    else
    {
        kbe_snprintf(helpConfig, 256, "server/log4cxx_properties/%s.properties", COMPONENT_NAME_EX(componentType));
    }

    log4cxx::PropertyConfigurator::configure(Resmgr::getSingleton().matchRes(helpConfig).c_str());
#endif
}
Exemplo n.º 20
0
	SqlStatementQuery(DBInterface* dbi, std::string tableName, DBID parentDBID, 
		DBID dbid, DB_OP_TABLE_ITEM_DATAS& tableItemDatas):
	  SqlStatement(dbi, tableName, parentDBID, dbid, tableItemDatas),
	  sqlstr1_()
	{

		// select id,xxx from tbl_SpawnPoint where id=123;
		sqlstr_ = "select ";
		sqlstr1_ += " from "ENTITY_TABLE_PERFIX"_";
		sqlstr1_ += tableName;
		
		char strdbid[MAX_BUF];

		if(parentDBID <= 0)
		{
			sqlstr1_ += " where id=";
			kbe_snprintf(strdbid, MAX_BUF, "%"PRDBID, dbid);
		}
		else
		{
			sqlstr1_ += " where "TABLE_PARENTID_CONST_STR"=";
			kbe_snprintf(strdbid, MAX_BUF, "%"PRDBID, parentDBID);
		}
		
		// 无论哪种情况都查询出ID字段
		sqlstr_ += "id,";

		sqlstr1_ += strdbid;

		DB_OP_TABLE_ITEM_DATAS::iterator tableValIter = tableItemDatas.begin();
		for(; tableValIter != tableItemDatas.end(); tableValIter++)
		{
			KBEShared_ptr<DB_OP_TABLE_ITEM_DATA> pSotvs = (*tableValIter);
			
			sqlstr_ += pSotvs->sqlkey;
			sqlstr_ += ",";
		}

		if(sqlstr_.at(sqlstr_.size() - 1) == ',')
			sqlstr_.erase(sqlstr_.size() - 1);

		sqlstr_ += sqlstr1_;
	}
Exemplo n.º 21
0
//-------------------------------------------------------------------------------------
bool DBInterfaceMysql::dropEntityTableFromDB(const char* tablename)
{
	KBE_ASSERT(tablename != NULL);
  
	DEBUG_MSG(boost::format("DBInterfaceMysql::dropEntityTableFromDB: %1%.\n") % tablename);

	char sql_str[MAX_BUF];
	kbe_snprintf(sql_str, MAX_BUF, "Drop table if exists %s;", tablename);
	return query(sql_str, strlen(sql_str));
}
Exemplo n.º 22
0
//-------------------------------------------------------------------------------------
bool DBInterfaceMysql::dropEntityTableItemFromDB(const char* tablename, const char* tableItemName)
{
	KBE_ASSERT(tablename != NULL && tableItemName != NULL);
  
	DEBUG_MSG(boost::format("DBInterfaceMysql::dropEntityTableItemFromDB: %1% %2%.\n") % 
		tablename % tableItemName);

	char sql_str[MAX_BUF];
	kbe_snprintf(sql_str, MAX_BUF, "alter table %s drop column %s;", tablename, tableItemName);
	return query(sql_str, strlen(sql_str));
}
Exemplo n.º 23
0
const std::string & versionString()
{
	if(g_versionString.size() == 0)
	{
		char buf[ 256 ];
		kbe_snprintf( buf, 256, "%d.%d.%d",
				KBE_VERSION_MAJOR, KBE_VERSION_MINOR, KBE_VERSION_PATCH );
		g_versionString = buf;
	}
	return g_versionString;
}
Exemplo n.º 24
0
//-------------------------------------------------------------------------------------
bool KBEEntityLogTableMysql::eraseEntityLog(DBInterface * dbi, DBID dbid, ENTITY_SCRIPT_UID entityType)
{
	std::string sqlstr = "delete from kbe_entitylog where entityDBID=";

	char tbuf[MAX_BUF];

	kbe_snprintf(tbuf, MAX_BUF, "%"PRDBID, dbid);
	sqlstr += tbuf;

	sqlstr += " and entityType=";
	kbe_snprintf(tbuf, MAX_BUF, "%u", entityType);
	sqlstr += tbuf;

	if(!dbi->query(sqlstr.c_str(), sqlstr.size(), false))
	{
		return false;
	}

	return true;
}
Exemplo n.º 25
0
//-------------------------------------------------------------------------------------
bool KBEEntityLogTableMysql::queryEntity(DBInterface * dbi, DBID dbid, EntityLog& entitylog, ENTITY_SCRIPT_UID entityType)
{
	std::string sqlstr = "select entityID,ip,port,componentID from kbe_entitylog where entityDBID=";

	char tbuf[MAX_BUF];
	kbe_snprintf(tbuf, MAX_BUF, "%"PRDBID, dbid);
	sqlstr += tbuf;
	
	sqlstr += " and entityType=";
	kbe_snprintf(tbuf, MAX_BUF, "%u", entityType);
	sqlstr += tbuf;

	if(!dbi->query(sqlstr.c_str(), sqlstr.size(), false))
	{
		return true;
	}
	
	entitylog.dbid = dbid;
	entitylog.componentID = 0;
	entitylog.entityID = 0;
	entitylog.ip = 0;
	entitylog.port = 0;

	MYSQL_RES * pResult = mysql_store_result(static_cast<DBInterfaceMysql*>(dbi)->mysql());
	if(pResult)
	{
		MYSQL_ROW arow;
		while((arow = mysql_fetch_row(pResult)) != NULL)
		{
			StringConv::str2value(entitylog.entityID, arow[0]);
			StringConv::str2value(entitylog.ip, arow[1]);
			StringConv::str2value(entitylog.port, arow[2]);
			StringConv::str2value(entitylog.componentID, arow[3]);
			break;
		}

		mysql_free_result(pResult);
	}

	return entitylog.componentID > 0;
}
Exemplo n.º 26
0
//-------------------------------------------------------------------------------------
DBInterface* DBUtil::createInterface(bool showinfo)
{
	ENGINE_COMPONENT_INFO& dbcfg = g_kbeSrvConfig.getDBMgr();
	DBInterface* dbinterface = NULL;

	if(strcmp(dbcfg.db_type, "mysql") == 0)
	{
		dbinterface = new DBInterfaceMysql;
	}

	kbe_snprintf(dbinterface->db_type_, MAX_BUF, "%s", dbcfg.db_type);
	dbinterface->db_port_ = dbcfg.db_port;	
	kbe_snprintf(dbinterface->db_ip_, MAX_IP, "%s", dbcfg.db_ip);
	kbe_snprintf(dbinterface->db_username_, MAX_BUF, "%s", dbcfg.db_username);
	kbe_snprintf(dbinterface->db_password_, MAX_BUF, "%s", dbcfg.db_password);
	dbinterface->db_numConnections_ = dbcfg.db_numConnections;
	
	if(dbinterface == NULL)
	{
		ERROR_MSG("DBUtil::createInterface: can't create dbinterface!\n");
		return NULL;
	}

	if(!dbinterface->attach(DBUtil::dbname()))
	{
		ERROR_MSG("DBUtil::createInterface: can't attach to database!\n\tdbinterface=%p\n\targs=%s", 
			&dbinterface, dbinterface->c_str());

		delete dbinterface;
		return NULL;
	}
	else
	{
		if(showinfo)
		{
			INFO_MSG("DBUtil::createInterface[%p]: %s\n", &dbinterface, dbinterface->c_str());
		}
	}

	return dbinterface;
}
Exemplo n.º 27
0
//-------------------------------------------------------------------------------------
const char * Channel::c_str() const
{
	static char dodgyString[ MAX_BUF ] = {"None"};
	char tdodgyString[ MAX_BUF ] = {0};

	if(pEndPoint_ && !pEndPoint_->addr().isNone())
		pEndPoint_->addr().writeToString(tdodgyString, MAX_BUF);

	kbe_snprintf(dodgyString, MAX_BUF, "%s/%d", tdodgyString, id_);

	return dodgyString;
}
Exemplo n.º 28
0
	SqlStatementInsert(DBInterface* dbi, std::string tableName, DBID parentDBID, 
		DBID dbid, DB_OP_TABLE_ITEM_DATAS& tableItemDatas):
	  SqlStatement(dbi, tableName, parentDBID, dbid, tableItemDatas)
	{
		// insert into tbl_Account (sm_accountName) values("fdsafsad\0\fdsfasfsa\0fdsafsda");
		sqlstr_ = "insert into "ENTITY_TABLE_PERFIX"_";
		sqlstr_ += tableName;
		sqlstr_ += " (";
		sqlstr1_ = ")  values(";
		
		if(parentDBID > 0)
		{
			sqlstr_ += TABLE_PARENTID_CONST_STR;
			sqlstr_ += ",";
			
			char strdbid[MAX_BUF];
			kbe_snprintf(strdbid, MAX_BUF, "%"PRDBID, parentDBID);
			sqlstr1_ += strdbid;
			sqlstr1_ += ",";
		}

		DB_OP_TABLE_ITEM_DATAS::iterator tableValIter = tableItemDatas.begin();
		for(; tableValIter != tableItemDatas.end(); tableValIter++)
		{
			KBEShared_ptr<DB_OP_TABLE_ITEM_DATA> pSotvs = (*tableValIter);

			if(dbid > 0)
			{
			}
			else
			{
				sqlstr_ += pSotvs->sqlkey;
				if(pSotvs->extraDatas.size() > 0)
					sqlstr1_ += pSotvs->extraDatas;
				else
					sqlstr1_ += pSotvs->sqlval;

				sqlstr_ += ",";
				sqlstr1_ += ",";
			}
		}
		
		if(parentDBID > 0 || sqlstr_.at(sqlstr_.size() - 1) == ',')
			sqlstr_.erase(sqlstr_.size() - 1);

		if(parentDBID > 0 || sqlstr1_.at(sqlstr1_.size() - 1) == ',')
			sqlstr1_.erase(sqlstr1_.size() - 1);

		sqlstr1_ += ")";
		sqlstr_ += sqlstr1_;
	}
Exemplo n.º 29
0
//-------------------------------------------------------------------------------------
void DebugHelper::critical_msg(std::string s)
{
	KBEngine::thread::ThreadGuard tg(&this->logMutex); 

	char buf[DBG_PT_SIZE];
	kbe_snprintf(buf, DBG_PT_SIZE, "%s(%d) -> %s\n\t%s\n", _currFile.c_str(), _currLine, _currFuncName.c_str(), s.c_str());

#ifdef NO_USE_LOG4CXX
#else
	LOG4CXX_FATAL(g_logger, buf);
#endif

	onMessage(KBELOG_CRITICAL, buf, strlen(buf));
	backtrace_msg();
}
Exemplo n.º 30
0
//-------------------------------------------------------------------------------------
bool MessageHandlers::initializeWatcher()
{
    std::vector< std::string >::iterator siter = exposedMessages_.begin();
    for(; siter != exposedMessages_.end(); siter++)
    {
        MessageHandlerMap::iterator iter = msgHandlers_.begin();
        for(; iter != msgHandlers_.end(); iter++)
        {
            if((*siter) == iter->second->name)
            {
                iter->second->exposed = true;
            }
        }
    }

    MessageHandlerMap::iterator iter = msgHandlers_.begin();
    for(; iter != msgHandlers_.end(); iter++)
    {
        char buf[MAX_BUF];
        kbe_snprintf(buf, MAX_BUF, "network/messages/%s/id", iter->second->name.c_str());
        WATCH_OBJECT(buf, iter->second->msgID);

        kbe_snprintf(buf, MAX_BUF, "network/messages/%s/len", iter->second->name.c_str());
        WATCH_OBJECT(buf, iter->second->msgLen);

        kbe_snprintf(buf, MAX_BUF, "network/messages/%s/sentSize", iter->second->name.c_str());
        WATCH_OBJECT(buf, iter->second, &MessageHandler::sendsize);

        kbe_snprintf(buf, MAX_BUF, "network/messages/%s/sentCount", iter->second->name.c_str());
        WATCH_OBJECT(buf, iter->second, &MessageHandler::sendcount);

        kbe_snprintf(buf, MAX_BUF, "network/messages/%s/sentAvgSize", iter->second->name.c_str());
        WATCH_OBJECT(buf, iter->second, &MessageHandler::sendavgsize);

        kbe_snprintf(buf, MAX_BUF, "network/messages/%s/recvSize", iter->second->name.c_str());
        WATCH_OBJECT(buf, iter->second, &MessageHandler::recvsize);

        kbe_snprintf(buf, MAX_BUF, "network/messages/%s/recvCount", iter->second->name.c_str());
        WATCH_OBJECT(buf, iter->second, &MessageHandler::recvsize);

        kbe_snprintf(buf, MAX_BUF, "network/messages/%s/recvAvgSize", iter->second->name.c_str());
        WATCH_OBJECT(buf, iter->second, &MessageHandler::recvavgsize);
    }

    return true;
}