Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1890


Ignore:
Timestamp:
Oct 6, 2008, 1:30:50 PM (16 years ago)
Author:
scheusso
Message:

first efforts to make the network module 64bit compatible
gamestates are still missing

Location:
code/branches/network/src/network/packet
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/network/packet/Acknowledgement.cc

    r1769 r1890  
    4040#define _ACKID              _PACKETID + sizeof(network::packet::ENUM::Type)
    4141 
    42 Acknowledgement::Acknowledgement( unsigned int id, int clientID )
     42Acknowledgement::Acknowledgement( unsigned int id, unsigned int clientID )
    4343 : Packet()
    4444{
    4545  flags_ = flags_ | PACKET_FLAGS_ACK;
    46   data_=new unsigned char[ getSize() ];
     46  data_=new uint8_t[ getSize() ];
    4747  *(ENUM::Type *)(data_ + _PACKETID ) = ENUM::Acknowledgement;
    48   *(unsigned int *)(data_ + _ACKID ) = id;
     48  *(uint32_t *)(data_ + _ACKID ) = id;
    4949  clientID_=clientID;
    5050}
    5151
    52 Acknowledgement::Acknowledgement( unsigned char *data, int clientID )
     52Acknowledgement::Acknowledgement( uint8_t *data, unsigned int clientID )
    5353  : Packet(data, clientID)
    5454{
     
    6060
    6161unsigned int Acknowledgement::getSize() const{
    62   return _ACKID + sizeof(unsigned int);
     62  return _ACKID + sizeof(uint32_t);
    6363}
    6464
     
    7070
    7171unsigned int Acknowledgement::getAckID(){
    72   return *(unsigned int *)(data_ + _ACKID);
     72  return *(uint32_t *)(data_ + _ACKID);
    7373}
    7474
  • code/branches/network/src/network/packet/Acknowledgement.h

    r1763 r1890  
    4040{
    4141public:
    42   Acknowledgement( unsigned int id, int clientID );
    43   Acknowledgement( unsigned char* data, int clientID );
     42  Acknowledgement( unsigned int id, unsigned int clientID );
     43  Acknowledgement( uint8_t* data, unsigned int clientID );
    4444  ~Acknowledgement();
    4545 
  • code/branches/network/src/network/packet/Chat.cc

    r1800 r1890  
    3737#define   _PACKETID         0
    3838const int _PLAYERID     =   _PACKETID + sizeof(ENUM::Type);
    39 #define   _MESSAGELENGTH    _PLAYERID + sizeof(unsigned int)
    40 #define   _MESSAGE          _MESSAGELENGTH + sizeof(unsigned int)
     39#define   _MESSAGELENGTH    _PLAYERID + sizeof(uint32_t)
     40#define   _MESSAGE          _MESSAGELENGTH + sizeof(uint32_t)
    4141
    4242Chat::Chat( std::string message, unsigned int playerID )
     
    5252}
    5353
    54 Chat::Chat( unsigned char *data, int clientID )
     54Chat::Chat( uint8_t* data, unsigned int clientID )
    5555  : Packet(data, clientID)
    5656{
    57   messageLength_ = *(unsigned int *)(data + _MESSAGELENGTH );
     57  messageLength_ = *(uint32_t *)(data + _MESSAGELENGTH );
    5858}
    5959
     
    6767
    6868bool Chat::process(){
    69   bool b = Host::incomingChat(std::string((const char*)data_+_MESSAGE), *(unsigned int *)(data_+_PLAYERID));
     69  bool b = Host::incomingChat(std::string((const char*)data_+_MESSAGE), *(uint32_t *)(data_+_PLAYERID));
    7070  delete this;
    7171  return b;
  • code/branches/network/src/network/packet/Chat.h

    r1793 r1890  
    1616public:
    1717  Chat( std::string message, unsigned int playerID );
    18   Chat( unsigned char* data, int clientID );
     18  Chat( uint8_t* data, unsigned int clientID );
    1919  ~Chat();
    2020 
     
    2525  unsigned char *getMessage();
    2626private:
    27   unsigned int messageLength_;
    28   int clientID_;
     27  uint32_t messageLength_;
     28  unsigned int clientID_;
    2929};
    3030
  • code/branches/network/src/network/packet/ClassID.cc

    r1763 r1890  
    4040#define _PACKETID             0
    4141#define _CLASSID              _PACKETID + sizeof(ENUM::Type)
    42 #define _CLASSNAMELENGTH      _CLASSID + sizeof(unsigned int)
     42#define _CLASSNAMELENGTH      _CLASSID + sizeof(uint32_t)
    4343#define _CLASSNAME            _CLASSNAMELENGTH + sizeof(classNameLength_)
    4444 
     
    5757}
    5858
    59 ClassID::ClassID( unsigned char *data, int clientID )
     59ClassID::ClassID( uint8_t* data, unsigned int clientID )
    6060  : Packet(data, clientID)
    6161{
     
    6868
    6969unsigned int ClassID::getSize() const{
    70   return sizeof(network::packet::ENUM::Type) + 2*sizeof(unsigned int) + classNameLength_;
     70  return sizeof(network::packet::ENUM::Type) + 2*sizeof(uint32_t) + classNameLength_;
    7171}
    7272
     
    8282
    8383unsigned int ClassID::getClassID(){
    84   return *(unsigned int *)&data_[ _CLASSID ];
     84  return *(uint32_t *)(data_ + _CLASSID);
    8585}
    8686
  • code/branches/network/src/network/packet/ClassID.h

    r1763 r1890  
    4343public:
    4444  ClassID( unsigned int classID, std::string className );
    45   ClassID( unsigned char* data, int clientID );
     45  ClassID( uint8_t* data, unsigned int clientID );
    4646  ~ClassID();
    4747 
     
    5353  unsigned char *getClassName();
    5454private:
    55   unsigned int classNameLength_;
     55  uint32_t classNameLength_;
    5656};
    5757
  • code/branches/network/src/network/packet/DeleteObjects.cc

    r1775 r1890  
    4040#define _PACKETID           0
    4141#define _QUANTITY           _PACKETID + sizeof(ENUM::Type)
    42 #define _OBJECTIDS          _QUANTITY + sizeof(unsigned int)
     42#define _OBJECTIDS          _QUANTITY + sizeof(uint32_t)
    4343 
    4444DeleteObjects::DeleteObjects()
     
    4848}
    4949
    50 DeleteObjects::DeleteObjects( unsigned char *data, int clientID )
     50DeleteObjects::DeleteObjects( uint8_t *data, unsigned int clientID )
    5151  : Packet(data, clientID)
    5252{
     
    6161  if(number==0)
    6262    return false;
    63   unsigned int size = sizeof(ENUM::Type) + sizeof(unsigned int)*number;
    64   data_ = new unsigned char[size];
     63  unsigned int size = sizeof(ENUM::Type) + sizeof(uint32_t)*(number+1);
     64  data_ = new uint8_t[size];
    6565  *(ENUM::Type *)(data_ + _PACKETID ) = ENUM::DeleteObjects;
    66   *(unsigned int *)(data_ + _QUANTITY) = number;
     66  *(uint32_t *)(data_ + _QUANTITY) = number;
    6767  for(unsigned int i=0; i<number; i++){
    68     *(unsigned int *)(data_ + sizeof(ENUM::Type) + i*sizeof(unsigned int)) = Synchronisable::popDeletedObject();
     68    *(uint32_t *)(data_ + sizeof(ENUM::Type) + (i+1)*sizeof(uint32_t)) = Synchronisable::popDeletedObject();
    6969  }
    7070  return true;
     
    7373unsigned int DeleteObjects::getSize() const{
    7474  assert(data_);
    75   return _OBJECTIDS + sizeof(unsigned int) + *(unsigned int*)(data_+_QUANTITY);
     75  return _OBJECTIDS + *(uint32_t*)(data_+_QUANTITY)*sizeof(uint32_t);
    7676}
    7777
    7878bool DeleteObjects::process(){
    7979  for(unsigned int i=0; i<*(unsigned int *)(data_+_QUANTITY); i++){
    80     COUT(3) << "deleting object with id: " << *(unsigned int*)(data_+_OBJECTIDS+i*sizeof(unsigned int)) << std::endl;
    81     Synchronisable::deleteObject( *(unsigned int*)(data_+_OBJECTIDS+i*sizeof(unsigned int)) );
     80    COUT(3) << "deleting object with id: " << *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) << std::endl;
     81    Synchronisable::deleteObject( *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) );
    8282  }
    8383  return true;
  • code/branches/network/src/network/packet/DeleteObjects.h

    r1775 r1890  
    4141public:
    4242  DeleteObjects( );
    43   DeleteObjects( unsigned char* data, int clientID );
     43  DeleteObjects( uint8_t* data, unsigned int clientID );
    4444  ~DeleteObjects();
    4545 
  • code/branches/network/src/network/packet/Packet.cc

    r1775 r1890  
    6767}
    6868
    69 Packet::Packet(unsigned char *data, int clientID){
     69Packet::Packet(uint8_t *data, unsigned int clientID){
    7070  flags_ = PACKET_FLAG_DEFAULT;
    7171  packetDirection_ = ENUM::Incoming;
     
    7575}
    7676
    77 /*Packet::Packet(ENetPacket *packet, ENetPeer *peer){
    78   packetDirection_ = ENUM::Incoming;
    79   enetPacket_ = packet;
    80   clientID_ = ClientInformation::findClient(&peer->address)->getID();
    81   data_ = packet->data;
    82 }*/
    8377
    8478Packet::Packet(const Packet &p){
     
    8882  clientID_ = p.clientID_;
    8983  if(p.data_){
    90     data_ = new unsigned char[p.getSize()];
     84    data_ = new uint8_t[p.getSize()];
    9185    memcpy(data_, p.data_, p.getSize());
    9286  }else
     
    139133
    140134Packet *Packet::createPacket(ENetPacket *packet, ENetPeer *peer){
    141   unsigned char *data = packet->data;
     135  uint8_t *data = packet->data;
    142136  unsigned int clientID = ClientInformation::findClient(&peer->address)->getID();
    143137  Packet *p;
  • code/branches/network/src/network/packet/Packet.h

    r1775 r1890  
    3131#include <map>
    3232#include <enet/enet.h>
     33
     34#include "util/Integers.h"
    3335
    3436namespace network {
     
    7577  protected:
    7678    Packet();
    77     Packet(unsigned char *data, int clientID);
     79    Packet(uint8_t *data, unsigned int clientID);
    7880//    Packet(ENetPacket *packet, ENetPeer *peer);
    7981    enet_uint32 flags_;
    80     int clientID_;
     82    unsigned int clientID_;
    8183    ENUM::Direction packetDirection_;
    82     unsigned char *data_;
     84    uint8_t *data_;
    8385  private:
    8486    static std::map<ENetPacket *, Packet *> packetMap_;
  • code/branches/network/src/network/packet/Welcome.cc

    r1763 r1890  
    4242#define _PACKETID             0
    4343#define _CLIENTID             _PACKETID + sizeof(ENUM::Type)
    44 #define _SHIPID               _CLIENTID + sizeof(unsigned int)
     44#define _SHIPID               _CLIENTID + sizeof(uint32_t)
    4545 
    4646  Welcome::Welcome( unsigned int clientID, unsigned int shipID )
     
    4949  flags_ = flags_ | PACKET_FLAGS_CLASSID;
    5050  assert(getSize());
    51   data_=new unsigned char[ getSize() ];
     51  data_=new uint8_t[ getSize() ];
    5252  assert(data_);
    5353  *(packet::ENUM::Type *)(data_ + _PACKETID ) = packet::ENUM::Welcome;
    54   *(unsigned int *)&data_[ _CLIENTID ] = clientID;
    55   *(unsigned int *)&data_[ _SHIPID ] = shipID;
     54  *(uint32_t *)&data_[ _CLIENTID ] = clientID;
     55  *(uint32_t *)&data_[ _SHIPID ] = shipID;
    5656}
    5757
    58 Welcome::Welcome( unsigned char *data, int clientID )
     58Welcome::Welcome( uint8_t* data, unsigned int clientID )
    5959  : Packet(data, clientID)
    6060{
     
    6565}
    6666
    67 unsigned char *Welcome::getData(){
     67uint8_t *Welcome::getData(){
    6868  return data_;
    6969}
    7070
    7171unsigned int Welcome::getSize() const{
    72   return sizeof(network::packet::ENUM::Type) + 2*sizeof(unsigned int);
     72  return sizeof(network::packet::ENUM::Type) + 2*sizeof(uint32_t);
    7373}
    7474
    7575bool Welcome::process(){
    7676  unsigned int shipID, clientID;
    77   clientID = *(unsigned int *)&data_[ _CLIENTID ];
    78   shipID = *(unsigned int *)&data_[ _SHIPID ];
     77  clientID = *(uint32_t *)&data_[ _CLIENTID ];
     78  shipID = *(uint32_t *)&data_[ _SHIPID ];
    7979  Host::setClientID(clientID);
    8080  Host::setShipID(shipID);
  • code/branches/network/src/network/packet/Welcome.h

    r1763 r1890  
    4141public:
    4242  Welcome( unsigned int clientID, unsigned int shipID );
    43   Welcome( unsigned char* data, int clientID );
     43  Welcome( uint8_t* data, unsigned int clientID );
    4444  virtual ~Welcome();
    4545 
    46   unsigned char *getData();
     46  uint8_t *getData();
    4747  inline unsigned int getSize() const;
    4848  bool process();
Note: See TracChangeset for help on using the changeset viewer.