Changeset edfd1d0 in network-game for common


Ignore:
Timestamp:
Dec 25, 2012, 6:27:14 PM (12 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
4c202e0
Parents:
baaf6c8
Message:

Moved the Player class to the common directory, added a position to Player, added a new message type for sending player info, and made the server broadcast player positions everytime it receives and replies to a message

Location:
common
Files:
1 added
2 edited
2 moved

Legend:

Unmodified
Added
Removed
  • common/Common.h

    rbaaf6c8 redfd1d0  
    22#define _COMMON_H
    33
    4 void set_nonblock(int sock)
     4#include <fcntl.h>
     5#include <assert.h>
     6
     7void set_nonblock(int sock);
     8
     9typedef struct
    510{
    6    #ifdef WIN32
    7       unsigned long mode = 1;
    8       ioctlsocket(sock, FIONBIO, &mode);
    9    #else
    10       int flags;
    11       flags = fcntl(sock, F_GETFL,0);
    12       assert(flags != -1);
    13       fcntl(sock, F_SETFL, flags | O_NONBLOCK);
    14    #endif
    15 }
     11   int x;
     12   int y;
     13} PLAYER_POS;
    1614
    1715#endif
  • common/Message.h

    rbaaf6c8 redfd1d0  
    66#define MSG_TYPE_LOGOUT       3
    77#define MSG_TYPE_CHAT         4
     8#define MSG_TYPE_PLAYER       5
    89
    910typedef struct
  • common/Player.cpp

    rbaaf6c8 redfd1d0  
    1010   this->name = name;
    1111   this->password = password;
     12   this->pos.x = 200;
     13   this->pos.y = 200;
    1214
    1315   cout << "Created new player: " << this->name << endl;
     
    1820   this->name = name;
    1921   this->password = "";
     22   this->pos.x = 200;
     23   this->pos.y = 200;
    2024   this->addr = addr;
    2125
     
    3135   this->addr = addr;
    3236}
     37
     38void Player::clearSensitiveInfo()
     39{
     40   this->password = "";
     41   this->addr.sin_family = 0;
     42   this->addr.sin_port = 0;
     43   this->addr.sin_addr.s_addr = 0;
     44}
  • common/Player.h

    rbaaf6c8 redfd1d0  
    44#include <netinet/in.h>
    55#include <string>
     6
     7#include "Common.h"
    68
    79using namespace std;
     
    1416
    1517   void setAddr(sockaddr_in addr);
     18   void clearSensitiveInfo();
    1619
    1720   string name;
    1821   string password;
    1922   sockaddr_in addr;
     23   PLAYER_POS pos;
    2024};
    2125
Note: See TracChangeset for help on using the changeset viewer.