Changeset a9a1295 in network-game
- Timestamp:
- Nov 10, 2014, 3:15:39 AM (10 years ago)
- Branches:
- master
- Children:
- c941e07
- Parents:
- ace001a (diff), 426fb84 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- server
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
server/DataAccess.cpp
race001a ra9a1295 178 178 { 179 179 // each array is the score for one game 180 // the columns are result, team, blue score, and red score180 // the columns are result, team, blue score, red score, and time the game ended 181 181 // for result 0 is defeat and 1 is victory 182 182 // for team, 1 is blue and 2 is red … … 197 197 int i=0; 198 198 while ( ( row = mysql_fetch_row(result)) != NULL ) { 199 gameHistory[i] = new int[ 4];199 gameHistory[i] = new int[5]; 200 200 201 201 int userTeam = atoi(row[2]); 202 int blueScore = atoi(row[4]); 203 int redScore = atoi(row[3]); 202 int blueScore = atoi(row[3]); 203 int redScore = atoi(row[4]); 204 time_t timeFinished = atoi(row[5]); 204 205 int gameResult = -1; 205 206 … … 222 223 gameHistory[i][2] = blueScore; 223 224 gameHistory[i][3] = redScore; 225 gameHistory[i][4] = timeFinished; 224 226 225 227 i++; … … 236 238 } 237 239 238 int DataAccess::saveGameHistory(int playerId, int team, int blueScore, int redScore )240 int DataAccess::saveGameHistory(int playerId, int team, int blueScore, int redScore, time_t timeFinished) 239 241 { 240 242 ostringstream oss; 241 243 242 244 cout << "Saving game to db" << endl; 243 oss << playerId << ", " << team << ", " << blueScore << ", " << redScore ;244 245 return insert("gameHistory", "user_id, user_team, blue_score, red_score ", oss.str());245 oss << playerId << ", " << team << ", " << blueScore << ", " << redScore << ", " << timeFinished; 246 247 return insert("gameHistory", "user_id, user_team, blue_score, red_score, time_finished", oss.str()); 246 248 } 247 249 -
server/DataAccess.h
race001a ra9a1295 23 23 int* getPlayerRecord(int playerId); 24 24 int** getPlayerGameHistory(int playerId, unsigned int& numGames); 25 int saveGameHistory(int playerId, int team, int blueScore, int redScore );25 int saveGameHistory(int playerId, int team, int blueScore, int redScore, time_t timeFinished); 26 26 27 27 int insert(string table, string rows, string values); -
server/server.cpp
race001a ra9a1295 200 200 map<unsigned int, Player*>::iterator it; 201 201 202 time_t timeFinished = time(NULL); 202 203 for (it = game->getPlayers().begin(); it != game->getPlayers().end(); it++) { 203 204 Player* p = it->second; … … 211 212 p->losses++; 212 213 da.updatePlayer(p); 213 da.saveGameHistory(p->getId(), winningTeam, game->getBlueScore(), game->getRedScore() );214 da.saveGameHistory(p->getId(), winningTeam, game->getBlueScore(), game->getRedScore(), timeFinished); 214 215 } 215 216 } … … 613 614 memcpy(serverMsg.buffer+12, &numGames, 4); 614 615 for (unsigned int i=0; i<numGames; i++) { 615 memcpy(serverMsg.buffer+16+i*16, &gameHistory[i][0], 4); 616 memcpy(serverMsg.buffer+20+i*16, &gameHistory[i][1], 4); 617 memcpy(serverMsg.buffer+24+i*16, &gameHistory[i][2], 4); 618 memcpy(serverMsg.buffer+28+i*16, &gameHistory[i][3], 4); 616 memcpy(serverMsg.buffer+16+i*20, &gameHistory[i][0], 4); 617 memcpy(serverMsg.buffer+20+i*20, &gameHistory[i][1], 4); 618 memcpy(serverMsg.buffer+24+i*20, &gameHistory[i][2], 4); 619 memcpy(serverMsg.buffer+28+i*20, &gameHistory[i][3], 4); 620 memcpy(serverMsg.buffer+32+i*20, &gameHistory[i][4], 4); 619 621 delete[] gameHistory[i]; 620 622 }
Note:
See TracChangeset
for help on using the changeset viewer.