Changeset 01d0d00 in network-game for common


Ignore:
Timestamp:
Dec 27, 2012, 7:04:49 PM (12 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
0333211, 3a79253
Parents:
5066e27
Message:

The server now uses a map to store players with player ids as keys

Location:
common
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • common/Player.cpp

    r5066e27 r01d0d00  
    77using namespace std;
    88
     9Player::Player()
     10{
     11   this->id = 0;
     12   this->name = "";
     13   this->password = "";
     14   this->pos.x = 0;
     15   this->pos.y = 0;
     16}
     17
     18Player::Player(const Player& p)
     19{
     20   this->id = p.id;
     21   this->name = p.name;
     22   this->password = p.password;
     23   this->pos.x = p.pos.x;
     24   this->pos.y = p.pos.y;
     25   this->addr = p.addr;
     26}
     27
    928Player::Player(string name, string password)
    1029{
     30   this->id = 0;
    1131   this->name = name;
    1232   this->password = password;
    1333   this->pos.x = 200;
    1434   this->pos.y = 200;
    15 
    16    cout << "Created new player: " << this->name << endl;
    1735}
    1836
    1937Player::Player(string name, sockaddr_in addr)
    2038{
     39   this->id = 0;
    2140   this->name = name;
    2241   this->password = "";
     
    2443   this->pos.y = 200;
    2544   this->addr = addr;
    26 
    27    cout << "Created new played: " << this->name << endl;
    2845}
    2946
     
    3653   ostringstream oss;
    3754
     55   oss.write((char*)&(this->id), sizeof(int));
    3856   oss << this->name;
    3957   oss.write("\0", 1);
     
    4967   iss.str(buffer);
    5068
     69   iss.read((char*)&(this->id), sizeof(int));
    5170   iss >> this->name;
    5271   iss.read((char*)&(this->pos.x), sizeof(int));
    5372   iss.read((char*)&(this->pos.y), sizeof(int));
     73}
     74
     75void Player::setId(int id)
     76{
     77   this->id = id;
    5478}
    5579
  • common/Player.h

    r5066e27 r01d0d00  
    1919class Player {
    2020public:
     21   Player();
     22   Player(const Player& p);
    2123   Player(string name, string password);
    2224   Player(string name, sockaddr_in addr); // this will be deleted
     25
    2326   ~Player();
    2427
     
    2629   void deserialize(char* buffer);
    2730
     31   void setId(int id);
    2832   void setAddr(sockaddr_in addr);
    2933
     34   int id;
    3035   string name;
    3136   string password;
Note: See TracChangeset for help on using the changeset viewer.