source: network-game/common/Player.cpp@ 3b8adee

Last change on this file since 3b8adee was 3b8adee, checked in by dportnoy <dmp1488@…>, 12 years ago

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

  • Property mode set to 100644
File size: 853 bytes
Line 
1#include "Player.h"
2
3#include <iostream>
4#include <sstream>
5#include <cstring>
6
7using namespace std;
8
9Player::Player(string name, string password)
10{
11 this->name = name;
12 this->password = password;
13 this->pos.x = 200;
14 this->pos.y = 200;
15
16 cout << "Created new player: " << this->name << endl;
17}
18
19Player::Player(string name, sockaddr_in addr)
20{
21 this->name = name;
22 this->password = "";
23 this->pos.x = 200;
24 this->pos.y = 200;
25 this->addr = addr;
26
27 cout << "Created new played: " << this->name << endl;
28}
29
30Player::~Player()
31{
32}
33
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
50void Player::setAddr(sockaddr_in addr)
51{
52 this->addr = addr;
53}
Note: See TracBrowser for help on using the repository browser.