示例#1
0
void ExportBaseData(SharedDatabase *db) {
	Log.Out(Logs::General, Logs::Status, "Exporting Base Data...");

	FILE *f = fopen("export/BaseData.txt", "w");
	if(!f) {
		Log.Out(Logs::General, Logs::Error, "Unable to open export/BaseData.txt to write, skipping.");
		return;
	}

	const std::string query = "SELECT * FROM base_data ORDER BY level, class";
	auto results = db->QueryDatabase(query);
	if(results.Success()) {
        for (auto row = results.begin();row != results.end();++row) {
			std::string line;
			unsigned int fields = results.ColumnCount();
			for(unsigned int rowIndex = 0; rowIndex < fields; ++rowIndex) {
				if(rowIndex != 0)
					line.push_back('^');

				if(row[rowIndex] != nullptr) {
					line += row[rowIndex];
				}
			}

			fprintf(f, "%s\n", line.c_str());
		}
	} else {
	}

	fclose(f);
}
示例#2
0
void ExportSpells(SharedDatabase *db) {
	Log.Out(Logs::General, Logs::Status, "Exporting Spells...");

	FILE *f = fopen("export/spells_us.txt", "w");
	if(!f) {
		Log.Out(Logs::General, Logs::Error, "Unable to open export/spells_us.txt to write, skipping.");
		return;
	}

	const std::string query = "SELECT * FROM spells_new ORDER BY id";
	auto results = db->QueryDatabase(query);

	if(results.Success()) {
        for (auto row = results.begin(); row != results.end(); ++row) {
			std::string line;
			unsigned int fields = results.ColumnCount();
			for(unsigned int i = 0; i < fields; ++i) {
				if(i != 0) {
					line.push_back('^');
				}

				if(row[i] != nullptr) {
					line += row[i];
				}
			}

			fprintf(f, "%s\n", line.c_str());
		}
	} else {
	}

	fclose(f);
}
示例#3
0
文件: main.cpp 项目: 9thsector/Server
void ExportDBStrings(SharedDatabase *db) {
	Log.Out(Logs::General, Logs::Status, "Exporting DB Strings...");

	FILE *f = fopen("export/dbstr_us.txt", "w");
	if(!f) {
		Log.Out(Logs::General, Logs::Error, "Unable to open export/dbstr_us.txt to write, skipping.");
		return;
	}

	fprintf(f, "Major^Minor^String(New)\n");
	const std::string query = "SELECT * FROM db_str ORDER BY id, type";
	auto results = db->QueryDatabase(query);
	if(results.Success()) {
		for(auto row = results.begin(); row != results.end(); ++row) {
			std::string line;
			unsigned int fields = results.ColumnCount();
			for(unsigned int rowIndex = 0; rowIndex < fields; ++rowIndex) {
				if(rowIndex != 0)
					line.push_back('^');

				if(row[rowIndex] != nullptr) {
					line += row[rowIndex];
				}
			}

			fprintf(f, "%s\n", line.c_str());
		}
	}

	fclose(f);
}
示例#4
0
DBTYPE DBQueryResult::ColumnType( uint32 index ) const
{
#ifdef COLUMN_BOUNDS_CHECKING
    if( index >= ColumnCount() )
    {
        sLog.Error( "DBCore Query Result", "ColumnType: Column index %d exceeds number of columns (%s) in row\n", index, ColumnCount() );
        return DBTYPE_STR;     //nothing better to do...
    }
#endif

    uint32 columnType = mFields[ index ]->type;

    /* tricky needs to be checked */
    if ( columnType > MYSQL_TYPE_BIT )
        columnType -= ( MYSQL_TYPE_NEWDECIMAL - MYSQL_TYPE_BIT - 1 );

    DBTYPE result = ( IsUnsigned( index ) ? MYSQL_DBTYPE_TABLE_UNSIGNED : MYSQL_DBTYPE_TABLE_SIGNED )[ columnType ];

    /* if result is (wide) binary string, set result to DBTYPE_BYTES. */
    if( ( DBTYPE_STR == result
          || DBTYPE_WSTR == result )
        && IsBinary( index ) )
    {
        result = DBTYPE_BYTES;
    }

    /* debug check */
    assert( DBTYPE_ERROR != result );
    return result;
}
示例#5
0
///Display board (debug only)
void ConnectBoard::Display(const bool& verbose){
	for(int h = height_-1; h >= 0; h--){
		fprintf(stderr,"\n");
		for(int w = 0; w < width_; w++){
			int node = (h*width_) + w;
			if(data_[node].used && data_[node].is_me)fprintf(stderr,"1 ");
			else if(data_[node].used && !data_[node].is_me)fprintf(stderr,"2 ");
			else fprintf(stderr,"0 ");
		}
	}

	//Don't display extra information.
	if(!verbose)return;

	fprintf(stderr,"\n------column count-------\n");
	for(int w = 0; w < width_; w++){
		fprintf(stderr,"%d ",ColumnCount(w));
	}
	int value = GetValue(true);
	fprintf(stderr,"\n------n connections(me): %d-------\n",value);
	for(int w = 0; w < connectSize_; w++){
		fprintf(stderr,"[%d]%d ",w,n_Connect_[w]);
	}

	value = GetValue(false);
	fprintf(stderr,"\n------n connections(them): %d-------\n",value);

	for(int w = 0; w < connectSize_; w++){
		fprintf(stderr,"[%d]%d ",w,n_Connect_[w]);
	}
	fprintf(stderr,"\n");
}
示例#6
0
///Add move to board
bool ConnectBoard::AddMove(const int &column, const bool& is_me){
	
	if(data_ == NULL){
		fprintf(stderr,"Cannot add move to board, data_ is NULL.");
		return false;
	}
	if(!ValidColumn(column))return false;
	
	int colCt = ColumnCount(column);
	if(colCt == height_){
		fprintf(stderr,"Cannot add more tokens to column %d, height full",column);
		return false;
	}
	int node = GetNodeIndex(colCt,column);
	if(!ValidNode(node)){
		fprintf(stderr,"Cannot add node to board %d",column);
		return false;
	}
	
	data_[node].used = true;
	data_[node].is_me = is_me;

	/*
		Using the lookup kernel noted below we make the assumption that new moves added to the board
		have possible parents where there are 1's and possible child where there are 0's.

		The 'if' statement below (in the 'for' loop) could be collapsed to a single 
		statement but it serves readability by leaving both outcomes explicitly written.
	*/
	{
		//Lookup kernel, tells new node what parents to look for first, then what child.
		int reverseKernel[] = {1, 1, 0,		//		| 1 0 0 |
							   1,-1, 0,		// ==>  | 1   0 |
							   1, 0, 0};	//		| 1 1 0 |

		for(int r = -1; r < 2; r++){
			for(int c = -1; c < 2; c++){
				int rk = (r+1)*3 + (c + 1);
				int rki = 8 - rk;
				if(reverseKernel[rk]==1){
					int parentNode = GetNodeIndex(colCt + r,column + c);
					if(ValidNode(parentNode) && data_[parentNode].is_me == is_me && data_[parentNode].used){
					//	fprintf(stderr,"Adding parentnode[%d] to child[%d]\n",parentNode,node);
						data_[node].parent[rk] = &data_[parentNode];
						data_[parentNode].child[rki] = &data_[node];
					}
				} else if(reverseKernel[rk]==0){
					int childNode = GetNodeIndex(colCt + r,column + c);
					if(ValidNode(childNode) && data_[childNode].is_me == is_me && data_[childNode].used){
					//	fprintf(stderr,"Adding childnode[%d] to parent[%d]\n",childNode,node);
						data_[node].child[rk] = &data_[childNode];
						data_[childNode].parent[rki] = &data_[node];
					}
				}
			}
		}
	}
	return true;
}
示例#7
0
double DBResultRow::GetDouble( uint32 index ) const
{
#ifdef COLUMN_BOUNDS_CHECKING
    if( index >= ColumnCount() )
    {
        sLog.Error( "DBCore Result Row", "GetDouble: Column index %u exceeds number of columns (%u) in row", index, ColumnCount() );
        return 0;       //nothing better to do...
    }
#endif
    return strtod( GetText( index ), NULL );
}
示例#8
0
bool DBResultRow::GetBool( uint32 index ) const
{
#ifdef COLUMN_BOUNDS_CHECKING
    if( index >= ColumnCount() )
    {
        sLog.Error( "DBCore Result Row", "GetInt: Column index %u exceeds number of columns (%u) in row", index, ColumnCount() );
        return 0;       //nothing better to do...
    }
#endif
    return GetText(index)[0] == 1;
}
示例#9
0
uint32 DBResultRow::ColumnLength( uint32 index ) const
{
#ifdef COLUMN_BOUNDS_CHECKING
    if( index >= ColumnCount() )
    {
        sLog.Error( "DBCore Result Row", "GetColumnLength: Column index %u exceeds number of columns (%u) in row", index, ColumnCount() );
        return 0;       //nothing better to do...
    }
#endif
    return mLengths[ index ];
}
示例#10
0
void DBQueryResult::SetResult( MYSQL_RES** res, uint32 colCount )
{
    SafeDeleteArray( mFields );

    if( NULL != mResult )
        mysql_free_result( mResult );

    mResult = *res;
    *res = NULL;
    mColumnCount = colCount;

    if( NULL != mResult )
    {
        mFields = new MYSQL_FIELD*[ ColumnCount() ];

        // we are
        for( uint32 i = 0; i < ColumnCount(); ++i )
            mFields[ i ] = mysql_fetch_field( mResult );
    }
}
示例#11
0
const char* DBQueryResult::ColumnName( uint32 index ) const
{
#ifdef COLUMN_BOUNDS_CHECKING
    if( index >= ColumnCount() )
    {
        sLog.Error( "DBCore Query Result", "ColumnName: Column index %d exceeds number of columns (%s) in row\n", index, ColumnCount() );
        return "(ERROR)";      //nothing better to do...
    }
#endif
    return mFields[ index ]->name;
}
示例#12
0
uint32 DBResultRow::GetUInt( uint32 index ) const
{
#ifdef COLUMN_BOUNDS_CHECKING
    if( index >= ColumnCount() )
    {
        sLog.Error( "DBCore Result Row", "GetUInt: Column index %u exceeds number of columns (%u) in row", index, ColumnCount() );
        return 0;       //nothing better to do...
    }
#endif
    //use base 0 on the obscure chance that this is a string column with an 0x hex number in it.
    return strtoul( GetText( index ), NULL, 0 );
}
示例#13
0
float DBResultRow::GetFloat( uint32 index ) const
{
#ifdef COLUMN_BOUNDS_CHECKING
    if( index >= ColumnCount() )
    {
        sLog.Error( "DBCore Result Row", "GetFloat: Column index %u exceeds number of columns (%u) in row", index, ColumnCount() );
        return 0;       //nothing better to do...
    }
#endif

#ifdef WIN32
    return (float)atof( GetText( index ) );
#else
    return strtof( GetText( index ), NULL );
#endif
}
示例#14
0
uint32 DBRowDescriptor::FindColumn( const char* name ) const
{
	uint32 cc = ColumnCount();
    PyString* stringName = new PyString( name );
    
	for( uint32 i = 0; i < cc; i++ )
    {
		if( stringName->hash() == GetColumnName( i )->hash() )
        {
            PyDecRef( stringName );
			return i;
        }
    }

    PyDecRef( stringName );
	return cc;
}
示例#15
0
void Client::TradeskillSearchResults(const std::string query, unsigned long objtype, unsigned long someid) {

    auto results = database.QueryDatabase(query);
	if (!results.Success()) {
		return;
	}

	if(results.RowCount() < 1)
		return; //search gave no results... not an error

	if(results.ColumnCount() != 6) {
		Log.Out(Logs::General, Logs::Error, "Error in TradeskillSearchResults query '%s': Invalid column count in result", query.c_str());
		return;
	}

	for(auto row = results.begin(); row != results.end(); ++row) {
		if(row == nullptr || row[0] == nullptr || row[1] == nullptr || row[2] == nullptr || row[3] == nullptr || row[5] == nullptr)
			continue;

		uint32 recipe = (uint32)atoi(row[0]);
		const char *name = row[1];
		uint32 trivial = (uint32) atoi(row[2]);
		uint32 comp_count = (uint32) atoi(row[3]);
		uint32 tradeskill = (uint16) atoi(row[5]);

		// Skip the recipes that exceed the threshold in skill difference
		// Recipes that have either been made before or were
		// explicitly learned are excempt from that limit
		if (RuleB(Skills, UseLimitTradeskillSearchSkillDiff)
            && ((int32)trivial - (int32)GetSkill((SkillUseTypes)tradeskill)) > RuleI(Skills, MaxTradeskillSearchSkillDiff)
            && row[4] == nullptr)
				continue;

		EQApplicationPacket* outapp = new EQApplicationPacket(OP_RecipeReply, sizeof(RecipeReply_Struct));
		RecipeReply_Struct *reply = (RecipeReply_Struct *) outapp->pBuffer;

		reply->object_type = objtype;
		reply->some_id = someid;
		reply->component_count = comp_count;
		reply->recipe_id = recipe;
		reply->trivial = trivial;
		strn0cpy(reply->recipe_name, name, sizeof(reply->recipe_name));
		FastQueuePacket(&outapp);
	}

}
示例#16
0
// Remove a single move from the board.
bool ConnectBoard::RemoveMove(const int &column, const bool& is_me){
	if(data_ == NULL){
		fprintf(stderr,"Cannot remove move to board, data_ is NULL.");
		return false;
	}
	if(!ValidColumn(column))return false;

	int colCt = ColumnCount(column)-1;
	int node = GetNodeIndex(colCt,column);
	if(!ValidNode(node))return false;


	if(!data_[node].used){
		fprintf(stderr,"Cannot remove token from column %d, column is empty",column);
		return false;
	}
	if(data_[node].is_me != is_me){
		fprintf(stderr,"Cannot remove token from column %d, users do not match",column);
		return false;
	}
	data_[node].used = false;
	
	//Orphan this node's child and remove it from its parents.
	{
		for(int f = 0; f < 9; f++){
			int fi = 8-f;
			if(data_[node].parent[f] != NULL){
				data_[node].parent[f]->child[fi] = NULL;
			}
			if(data_[node].child[f] != NULL){
				data_[node].child[f]->parent[fi] = NULL;
			}
			data_[node].child[f] = NULL;
			data_[node].parent[f] = NULL;
		}
	}
	return true;
}