tags:

views:

130

answers:

3

I only want it to update server_record. Dont send any messgaes. What can I remove so it dont say "New record of players online is: 2839". Can I remove everything under query.str("");? I have no idea what char buffer[50]; do. I dont wanna mess anything up. And How can u get current time in c++? I want to insert the current time in the table too. To se when record was set.

void Game::checkPlayersRecord()
{
if(getPlayersOnline() > lastPlayersRecord){
 Database* db = Database::instance();
 DBQuery query;

 lastPlayersRecord = getPlayersOnline();
 query << "UPDATE `server_record` SET `record` = " << lastPlayersRecord << ";";
 db->executeQuery(query.str());
 query.str("");

 char buffer[50];
 sprintf(buffer, "New record of players online is: %d", lastPlayersRecord);
 AutoList<Player>::listiterator it = Player::listPlayer.list.begin();
    while(it != Player::listPlayer.list.end()){
        (*it).second->sendTextMessage(MSG_EVENT_ADVANCE, buffer);
        ++it;
    }
}
}
+4  A: 

Better get someone who knows this stuff. What you're asking isn't exactly rocket science, but is still pretty easy to get wrong if done by an inexperienced person.

Vilx-
A: 

Upon casual inspection, yes, delete everything under (but not including) query.str(""); Hopefully you have a way of testing it before pushing this change live and breaking the app. :)

Cory Petosky
A: 

It's pretty obvious what these blocks do, so unless they have some hidden stuff, this is the part which updates the database with the record value.

void Game::checkPlayersRecord()
{
    if(getPlayersOnline() > lastPlayersRecord){
     Database* db = Database::instance();
     DBQuery query;

     lastPlayersRecord = getPlayersOnline();
     query << "UPDATE `server_record` SET `record` = " << lastPlayersRecord << ";";
     db->executeQuery(query.str());
     query.str("");
    }
}
Nicholaz