Changeset 521c88b in network-game for server


Ignore:
Timestamp:
Jun 22, 2013, 1:26:58 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
7ca5d21
Parents:
109e8a3
Message:

Upon player registration, the server stores the selected player class and no longer generates a random player class every time the player logs in

Location:
server
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • server/DataAccess.cpp

    r109e8a3 r521c88b  
    2424}
    2525
    26 int DataAccess::insertPlayer(string username, string password)
     26int DataAccess::insertPlayer(string username, string password, Player::PlayerClass playerClass)
    2727{
    2828   ostringstream oss;
     
    4646   string encrypted(crypt(password.c_str(), salt.c_str()));
    4747
    48    oss << "'" << username << "', '" << encrypted << "'";
     48   oss << "'" << username << "', '" << encrypted << "', " << playerClass;
    4949
    50    return insert("users", "name, password", oss.str());
     50   return insert("users", "name, password, class", oss.str());
    5151}
    5252
     
    8484      cout << "Creating a new player" << endl;
    8585      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;
    8689      cout << "Created new player" << endl;
    8790   }else {
  • server/DataAccess.h

    r109e8a3 r521c88b  
    1616   ~DataAccess();
    1717
    18    int insertPlayer(string username, string password);
     18   int insertPlayer(string username, string password, Player::PlayerClass playerClass);
    1919   int updatePlayer(string username, string password);
    2020
  • server/server.cpp

    r109e8a3 r521c88b  
    529529         string username(clientMsg.buffer);
    530530         string password(strchr(clientMsg.buffer, '\0')+1);
     531         Player::PlayerClass playerClass;
     532
     533         memcpy(&playerClass, clientMsg.buffer+username.length()+password.length()+2, 4);
    531534
    532535         cout << "username: " << username << endl;
    533536         cout << "password: " << password << endl;
    534537
    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);
    536546
    537547         if (!error)
     
    574584            // choose a random team (either 0 or 1)
    575585            p->team = rand() % 2;
    576 
    577             // choose a random class
    578             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             }
    587586
    588587            // tell the new player about all the existing players
Note: See TracChangeset for help on using the changeset viewer.