- Timestamp:
- Jun 22, 2013, 1:26:58 PM (11 years ago)
- Branches:
- master
- Children:
- 7ca5d21
- Parents:
- 109e8a3
- Location:
- server
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
server/DataAccess.cpp
r109e8a3 r521c88b 24 24 } 25 25 26 int DataAccess::insertPlayer(string username, string password )26 int DataAccess::insertPlayer(string username, string password, Player::PlayerClass playerClass) 27 27 { 28 28 ostringstream oss; … … 46 46 string encrypted(crypt(password.c_str(), salt.c_str())); 47 47 48 oss << "'" << username << "', '" << encrypted << "' ";48 oss << "'" << username << "', '" << encrypted << "', " << playerClass; 49 49 50 return insert("users", "name, password ", oss.str());50 return insert("users", "name, password, class", oss.str()); 51 51 } 52 52 … … 84 84 cout << "Creating a new player" << endl; 85 85 p = new Player(string(row[1]), string(row[2])); 86 p->setClass((Player::PlayerClass)atoi(row[3])); 87 cout << "Class from db: " << atoi(row[3]) << endl; 88 cout << "Player class: " << p->playerClass << endl; 86 89 cout << "Created new player" << endl; 87 90 }else { -
server/DataAccess.h
r109e8a3 r521c88b 16 16 ~DataAccess(); 17 17 18 int insertPlayer(string username, string password );18 int insertPlayer(string username, string password, Player::PlayerClass playerClass); 19 19 int updatePlayer(string username, string password); 20 20 -
server/server.cpp
r109e8a3 r521c88b 529 529 string username(clientMsg.buffer); 530 530 string password(strchr(clientMsg.buffer, '\0')+1); 531 Player::PlayerClass playerClass; 532 533 memcpy(&playerClass, clientMsg.buffer+username.length()+password.length()+2, 4); 531 534 532 535 cout << "username: " << username << endl; 533 536 cout << "password: " << password << endl; 534 537 535 int error = da.insertPlayer(username, password); 538 if (playerClass == Player::CLASS_WARRIOR) 539 cout << "class: WARRIOR" << endl; 540 else if (playerClass == Player::CLASS_RANGER) 541 cout << "class: RANGER" << endl; 542 else 543 cout << "Unknown player class detected" << endl; 544 545 int error = da.insertPlayer(username, password, playerClass); 536 546 537 547 if (!error) … … 574 584 // choose a random team (either 0 or 1) 575 585 p->team = rand() % 2; 576 577 // choose a random class578 int intClass = rand() % 2;579 switch (intClass) {580 case 0:581 p->setClass(Player::CLASS_WARRIOR);582 break;583 case 1:584 p->setClass(Player::CLASS_RANGER);585 break;586 }587 586 588 587 // tell the new player about all the existing players
Note:
See TracChangeset
for help on using the changeset viewer.