Changeset 3b8adee in network-game for common/Player.cpp


Ignore:
Timestamp:
Dec 26, 2012, 3:10:05 PM (12 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
60776f2
Parents:
4c202e0
Message:

Added serialize and deserialize methods to Player and modified the server to use the serialize method when broadcasting user data

File:
1 edited

Legend:

Unmodified
Added
Removed
  • common/Player.cpp

    r4c202e0 r3b8adee  
    22
    33#include <iostream>
     4#include <sstream>
     5#include <cstring>
    46
    57using namespace std;
     
    3032}
    3133
     34void Player::serialize(char* buffer)
     35{
     36   ostringstream oss;
     37
     38   oss << this->name;
     39
     40   memcpy(buffer, oss.str().c_str(), this->name.length()+1);
     41}
     42
     43void Player::deserialize(char* buffer)
     44{
     45   istringstream iss;
     46
     47   iss >> this->name;
     48}
     49
    3250void Player::setAddr(sockaddr_in addr)
    3351{
    3452   this->addr = addr;
    3553}
    36 
    37 void Player::clearSensitiveInfo()
    38 {
    39    this->password = "";
    40    this->addr.sin_family = 0;
    41    this->addr.sin_port = 0;
    42    this->addr.sin_addr.s_addr = 0;
    43 }
Note: See TracChangeset for help on using the changeset viewer.