Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // !rank
- //
- if( Command == "rank" &&m_GHost->m_AllowRank)
- {
- string StatsUser = User;
- if( !Payload.empty( ) )
- StatsUser = Payload;
- MYSQL *mysql;
- MYSQL_ROW row;
- MYSQL_ROW row2;
- MYSQL_ROW row3;
- //string test="";
- unsigned int num_fields;
- unsigned int num_rows;
- string nameTable[1000];
- int counter=0;
- int counter2=0;
- bool runAlways=true;
- string nrOfPlayers="";
- string CFGFile = "ghost.cfg";
- // read config file
- CConfig *CFG=new CConfig();
- CFG->Read( CFGFile );
- string serverName = CFG->GetString( "db_mysql_server", string( ) );
- string databaseName = CFG->GetString( "db_mysql_database", string());
- string userName = CFG->GetString( "db_mysql_user", string( ) );
- string password = CFG->GetString( "db_mysql_password", string( ) );
- int portNr = CFG->GetInt( "db_mysql_port", int() );
- fprintf(stderr, "***%s***\n", serverName.c_str( ));
- fprintf(stderr, "***%s***\n", databaseName.c_str( ));
- fprintf(stderr, "***%s***\n", userName.c_str( ));
- fprintf(stderr, "***%d***\n", portNr);
- m_GHost->m_CheckDbOn=true;
- mysql = mysql_init(NULL);
- if (NULL == mysql_real_connect(mysql,serverName.c_str( ),userName.c_str( ),password.c_str( ),databaseName.c_str( ),0,NULL,0))
- {
- fprintf(stderr,"Problem encountered connecting to the database!");
- QueueChatCommand("Problem encountered connecting to the database!");
- m_GHost->m_CheckDbOn=false;
- mysql_close(mysql);
- }
- if(m_GHost->m_CheckDbOn)
- {
- string record="select score from scores where name='"+StatsUser+"'";
- if(mysql_real_query(mysql,record.c_str(),record.size())!=0)
- {
- mysql_error(mysql);
- }
- else
- {
- MYSQL_RES *result=mysql_store_result(mysql);
- if( result )
- {
- num_fields = mysql_num_fields(result);
- row = mysql_fetch_row( result );
- if(row!=NULL)
- m_GHost->m_Experience=row[0];
- else
- m_GHost->m_Experience="ERROR";
- mysql_free_result( result );
- }
- else
- {
- if(mysql_field_count(mysql) == 0)
- {
- num_rows = mysql_affected_rows(mysql);
- }
- else
- {
- fprintf(stderr, "Error: %s\n", mysql_error(mysql));
- }
- }
- }
- string record2="select name,score from scores order by score desc";
- if(mysql_real_query(mysql,record2.c_str(),record2.size())!=0)
- {
- mysql_error(mysql);
- }
- else
- {
- MYSQL_RES *result2=mysql_store_result(mysql);
- if( result2 )
- {
- num_fields = mysql_num_fields(result2);
- while ((row2 = mysql_fetch_row(result2)))
- {
- nameTable[counter]=row2[0];
- counter++;
- }
- mysql_free_result( result2 );
- }
- else
- {
- mysql_error(mysql);
- }
- }
- string record3="select count(name) from scores";
- if(mysql_real_query(mysql,record3.c_str(),record3.size())!=0)
- {
- mysql_error(mysql);
- }
- else
- {
- MYSQL_RES *result3=mysql_store_result(mysql);
- if( result3 )
- {
- num_fields = mysql_num_fields(result3);
- while ((row3 = mysql_fetch_row(result3)))
- {
- nrOfPlayers=row3[0];
- }
- mysql_free_result( result3 );
- }
- else
- {
- mysql_error(mysql);
- }
- }
- mysql_close(mysql);
- if(row!=NULL)
- {
- std::transform(StatsUser.begin(), StatsUser.end(), StatsUser.begin(), std::tolower);
- while(runAlways)
- {
- if(StatsUser==nameTable[counter2])
- {
- runAlways=false;
- counter2=counter2+1;
- m_GHost->m_RankPos= UTIL_ToString(counter2);
- }
- else
- {
- counter2++;
- }
- }
- m_GHost->m_TotalPlayersInDb=nrOfPlayers;
- //QueueChatCommand("/w Guard /x ***"+StatsUser+"'s stats are: Experience: "+m_GHost->m_Experience.c_str()+".***");
- //display wins/losses/total games played
- if( !StatsUser.empty( ) && StatsUser.size( ) < 16 && StatsUser[0] != '/' )
- {
- m_PairedDPSChecks.push_back( PairedDPSCheck( Whisper ? User : string( ), m_GHost->m_DB->ThreadedDotAPlayerSummaryCheck( StatsUser ) ) );
- runAlways=true;
- }
- }
- else
- QueueChatCommand("/w Guard /x "+StatsUser+" User not found in database!");
- }
- }
- //
- //!best10
- //
- if( Command == "best10" &&m_GHost->m_AllowRank )
- {
- MYSQL *mysql;
- MYSQL_ROW row;
- string nameTable[1000];
- string scoreTable[1000];
- int num_fields;
- string finalResult="";
- int counter=0;
- string CFGFile = "ghost.cfg";
- // read config file
- CConfig *CFG=new CConfig();
- CFG->Read( CFGFile );
- string serverName = CFG->GetString( "db_mysql_server", string( ) );
- string databaseName = CFG->GetString( "db_mysql_database", string() );
- string userName = CFG->GetString( "db_mysql_user", string( ) );
- string password = CFG->GetString( "db_mysql_password", string( ) );
- int portNr = CFG->GetInt( "db_mysql_port", int() );
- fprintf(stderr, "***%s***\n", serverName.c_str( ));
- fprintf(stderr, "***%s***\n", databaseName.c_str( ));
- fprintf(stderr, "***%s***\n", userName.c_str( ));
- fprintf(stderr, "***%d***\n", portNr);
- m_GHost->m_CheckDbOn=true;
- mysql = mysql_init(NULL);
- if (NULL == mysql_real_connect(mysql,serverName.c_str( ),userName.c_str( ),password.c_str( ),databaseName.c_str( ),0,NULL,0))
- {
- fprintf(stderr,"Problem encountered connecting to the database!");
- QueueChatCommand("Problem encountered connecting to the database!");
- m_GHost->m_CheckDbOn=false;
- mysql_close(mysql);
- }
- if(m_GHost->m_CheckDbOn)
- {
- string record="select name,score from scores order by score desc";
- if(mysql_real_query(mysql,record.c_str(),record.size())!=0)
- {
- mysql_error(mysql);
- }
- else
- {
- MYSQL_RES *result=mysql_store_result(mysql);
- if( result )
- {
- num_fields = mysql_num_fields(result);
- while ((row = mysql_fetch_row(result)))
- {
- nameTable[counter]=row[0];
- counter++;
- }
- mysql_free_result( result );
- }
- else
- {
- mysql_error(mysql);
- }
- }
- mysql_close(mysql);
- for(int i=0;i<10;i++)
- {
- finalResult=finalResult+" "+nameTable[i]+"("+UTIL_ToString(i+1)+")"+"*";
- }
- QueueChatCommand("/w Guard /x *"+finalResult);
- counter=0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement