Changeset 84754c0 in network-game for server/DataAccess.cpp


Ignore:
Timestamp:
Oct 17, 2014, 1:14:36 AM (10 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
master
Children:
c666518
Parents:
fb894b4
Message:

Change updatePlayer to take a Player object and update many fields of that object

File:
1 edited

Legend:

Unmodified
Added
Removed
  • server/DataAccess.cpp

    rfb894b4 r84754c0  
    7272}
    7373
    74 // this is no longer used anywhere
    75 int DataAccess::updatePlayer(string username, string password)
     74int DataAccess::updatePlayer(Player* p)
    7675{
    7776   ostringstream values, where;
    7877
    79    values << "password='" << password << "'";
     78   values << "level=" << p->level << ", experience=" << p->experience << ", honor=" << p->honor << ", wins=" << p->wins << ", losses=" << p->losses << "";
    8079   
    81    where << "name='" << username << "'";
     80   where << "id=" << p->getId() << "";
    8281
    8382   return update("users", values.str(), where.str());
     
    114113         cout << "Class from db: " << atoi(row[3]) << endl;
    115114      }
     115      p->level = atoi(row[4]);
     116      p->experience = atoi(row[5]);
     117      p->honor = atoi(row[6]);
     118      p->wins = atoi(row[7]);
     119      p->losses = atoi(row[8]);
    116120      cout << "Player class: " << p->playerClass << endl;
    117       if (row[7] == NULL)
    118           cout << "wins: NULL" << endl;
    119       else
    120           cout << "wins: " << atoi(row[7]) << endl;
    121       if (row[8] == NULL)
    122           cout << "losses: NULL" << endl;
    123       else
    124           cout << "losses: " << atoi(row[8]) << endl;
     121      cout << "level: " << p->level << endl;
     122      cout << "experience: " << p->experience << endl;
     123      cout << "honor: " << p->honor << endl;
     124      cout << "wins: " << p->wins << endl;
     125      cout << "losses: " << p->losses << endl;
    125126      cout << "Loaded player from db" << endl;
    126127   }else {
     
    140141list<Player*>* DataAccess::getPlayers()
    141142{
     143   // This method doesn't seem to ever get used. Decide whether it's actually needed
    142144   MYSQL_RES *result;
    143145   MYSQL_ROW row;
     
    154156      cout << row[0] << ", " << row[1] << ", " << row[2] << endl;
    155157      lstPlayers->push_back(new Player(row[1], row[2]));
     158
     159      // need to assign all the other db values to the player
    156160   }
    157161
     
    310314   query_state = mysql_query(connection, oss.str().c_str());
    311315
     316
    312317   if (query_state != 0) {
    313318      cout << mysql_error(connection) << endl;
Note: See TracChangeset for help on using the changeset viewer.