- Timestamp:
- Oct 6, 2008, 1:30:50 PM (16 years ago)
- Location:
- code/branches/network/src/network/packet
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/packet/Acknowledgement.cc
r1769 r1890 40 40 #define _ACKID _PACKETID + sizeof(network::packet::ENUM::Type) 41 41 42 Acknowledgement::Acknowledgement( unsigned int id, int clientID )42 Acknowledgement::Acknowledgement( unsigned int id, unsigned int clientID ) 43 43 : Packet() 44 44 { 45 45 flags_ = flags_ | PACKET_FLAGS_ACK; 46 data_=new u nsigned char[ getSize() ];46 data_=new uint8_t[ getSize() ]; 47 47 *(ENUM::Type *)(data_ + _PACKETID ) = ENUM::Acknowledgement; 48 *(u nsigned int *)(data_ + _ACKID ) = id;48 *(uint32_t *)(data_ + _ACKID ) = id; 49 49 clientID_=clientID; 50 50 } 51 51 52 Acknowledgement::Acknowledgement( u nsigned char *data,int clientID )52 Acknowledgement::Acknowledgement( uint8_t *data, unsigned int clientID ) 53 53 : Packet(data, clientID) 54 54 { … … 60 60 61 61 unsigned int Acknowledgement::getSize() const{ 62 return _ACKID + sizeof(u nsigned int);62 return _ACKID + sizeof(uint32_t); 63 63 } 64 64 … … 70 70 71 71 unsigned int Acknowledgement::getAckID(){ 72 return *(u nsigned int *)(data_ + _ACKID);72 return *(uint32_t *)(data_ + _ACKID); 73 73 } 74 74 -
code/branches/network/src/network/packet/Acknowledgement.h
r1763 r1890 40 40 { 41 41 public: 42 Acknowledgement( unsigned int id, int clientID );43 Acknowledgement( u nsigned char* data,int clientID );42 Acknowledgement( unsigned int id, unsigned int clientID ); 43 Acknowledgement( uint8_t* data, unsigned int clientID ); 44 44 ~Acknowledgement(); 45 45 -
code/branches/network/src/network/packet/Chat.cc
r1800 r1890 37 37 #define _PACKETID 0 38 38 const int _PLAYERID = _PACKETID + sizeof(ENUM::Type); 39 #define _MESSAGELENGTH _PLAYERID + sizeof(u nsigned int)40 #define _MESSAGE _MESSAGELENGTH + sizeof(u nsigned int)39 #define _MESSAGELENGTH _PLAYERID + sizeof(uint32_t) 40 #define _MESSAGE _MESSAGELENGTH + sizeof(uint32_t) 41 41 42 42 Chat::Chat( std::string message, unsigned int playerID ) … … 52 52 } 53 53 54 Chat::Chat( u nsigned char *data,int clientID )54 Chat::Chat( uint8_t* data, unsigned int clientID ) 55 55 : Packet(data, clientID) 56 56 { 57 messageLength_ = *(u nsigned int *)(data + _MESSAGELENGTH );57 messageLength_ = *(uint32_t *)(data + _MESSAGELENGTH ); 58 58 } 59 59 … … 67 67 68 68 bool Chat::process(){ 69 bool b = Host::incomingChat(std::string((const char*)data_+_MESSAGE), *(u nsigned int *)(data_+_PLAYERID));69 bool b = Host::incomingChat(std::string((const char*)data_+_MESSAGE), *(uint32_t *)(data_+_PLAYERID)); 70 70 delete this; 71 71 return b; -
code/branches/network/src/network/packet/Chat.h
r1793 r1890 16 16 public: 17 17 Chat( std::string message, unsigned int playerID ); 18 Chat( u nsigned char* data,int clientID );18 Chat( uint8_t* data, unsigned int clientID ); 19 19 ~Chat(); 20 20 … … 25 25 unsigned char *getMessage(); 26 26 private: 27 u nsigned int messageLength_;28 int clientID_;27 uint32_t messageLength_; 28 unsigned int clientID_; 29 29 }; 30 30 -
code/branches/network/src/network/packet/ClassID.cc
r1763 r1890 40 40 #define _PACKETID 0 41 41 #define _CLASSID _PACKETID + sizeof(ENUM::Type) 42 #define _CLASSNAMELENGTH _CLASSID + sizeof(u nsigned int)42 #define _CLASSNAMELENGTH _CLASSID + sizeof(uint32_t) 43 43 #define _CLASSNAME _CLASSNAMELENGTH + sizeof(classNameLength_) 44 44 … … 57 57 } 58 58 59 ClassID::ClassID( u nsigned char *data,int clientID )59 ClassID::ClassID( uint8_t* data, unsigned int clientID ) 60 60 : Packet(data, clientID) 61 61 { … … 68 68 69 69 unsigned int ClassID::getSize() const{ 70 return sizeof(network::packet::ENUM::Type) + 2*sizeof(u nsigned int) + classNameLength_;70 return sizeof(network::packet::ENUM::Type) + 2*sizeof(uint32_t) + classNameLength_; 71 71 } 72 72 … … 82 82 83 83 unsigned int ClassID::getClassID(){ 84 return *(u nsigned int *)&data_[ _CLASSID ];84 return *(uint32_t *)(data_ + _CLASSID); 85 85 } 86 86 -
code/branches/network/src/network/packet/ClassID.h
r1763 r1890 43 43 public: 44 44 ClassID( unsigned int classID, std::string className ); 45 ClassID( u nsigned char* data,int clientID );45 ClassID( uint8_t* data, unsigned int clientID ); 46 46 ~ClassID(); 47 47 … … 53 53 unsigned char *getClassName(); 54 54 private: 55 u nsigned int classNameLength_;55 uint32_t classNameLength_; 56 56 }; 57 57 -
code/branches/network/src/network/packet/DeleteObjects.cc
r1775 r1890 40 40 #define _PACKETID 0 41 41 #define _QUANTITY _PACKETID + sizeof(ENUM::Type) 42 #define _OBJECTIDS _QUANTITY + sizeof(u nsigned int)42 #define _OBJECTIDS _QUANTITY + sizeof(uint32_t) 43 43 44 44 DeleteObjects::DeleteObjects() … … 48 48 } 49 49 50 DeleteObjects::DeleteObjects( u nsigned char *data,int clientID )50 DeleteObjects::DeleteObjects( uint8_t *data, unsigned int clientID ) 51 51 : Packet(data, clientID) 52 52 { … … 61 61 if(number==0) 62 62 return false; 63 unsigned int size = sizeof(ENUM::Type) + sizeof(u nsigned int)*number;64 data_ = new u nsigned char[size];63 unsigned int size = sizeof(ENUM::Type) + sizeof(uint32_t)*(number+1); 64 data_ = new uint8_t[size]; 65 65 *(ENUM::Type *)(data_ + _PACKETID ) = ENUM::DeleteObjects; 66 *(u nsigned int *)(data_ + _QUANTITY) = number;66 *(uint32_t *)(data_ + _QUANTITY) = number; 67 67 for(unsigned int i=0; i<number; i++){ 68 *(u nsigned 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(); 69 69 } 70 70 return true; … … 73 73 unsigned int DeleteObjects::getSize() const{ 74 74 assert(data_); 75 return _OBJECTIDS + sizeof(unsigned int) + *(unsigned int*)(data_+_QUANTITY);75 return _OBJECTIDS + *(uint32_t*)(data_+_QUANTITY)*sizeof(uint32_t); 76 76 } 77 77 78 78 bool DeleteObjects::process(){ 79 79 for(unsigned int i=0; i<*(unsigned int *)(data_+_QUANTITY); i++){ 80 COUT(3) << "deleting object with id: " << *(u nsigned int*)(data_+_OBJECTIDS+i*sizeof(unsigned int)) << std::endl;81 Synchronisable::deleteObject( *(u nsigned 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)) ); 82 82 } 83 83 return true; -
code/branches/network/src/network/packet/DeleteObjects.h
r1775 r1890 41 41 public: 42 42 DeleteObjects( ); 43 DeleteObjects( u nsigned char* data,int clientID );43 DeleteObjects( uint8_t* data, unsigned int clientID ); 44 44 ~DeleteObjects(); 45 45 -
code/branches/network/src/network/packet/Packet.cc
r1775 r1890 67 67 } 68 68 69 Packet::Packet(u nsigned char *data,int clientID){69 Packet::Packet(uint8_t *data, unsigned int clientID){ 70 70 flags_ = PACKET_FLAG_DEFAULT; 71 71 packetDirection_ = ENUM::Incoming; … … 75 75 } 76 76 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 }*/83 77 84 78 Packet::Packet(const Packet &p){ … … 88 82 clientID_ = p.clientID_; 89 83 if(p.data_){ 90 data_ = new u nsigned char[p.getSize()];84 data_ = new uint8_t[p.getSize()]; 91 85 memcpy(data_, p.data_, p.getSize()); 92 86 }else … … 139 133 140 134 Packet *Packet::createPacket(ENetPacket *packet, ENetPeer *peer){ 141 u nsigned char*data = packet->data;135 uint8_t *data = packet->data; 142 136 unsigned int clientID = ClientInformation::findClient(&peer->address)->getID(); 143 137 Packet *p; -
code/branches/network/src/network/packet/Packet.h
r1775 r1890 31 31 #include <map> 32 32 #include <enet/enet.h> 33 34 #include "util/Integers.h" 33 35 34 36 namespace network { … … 75 77 protected: 76 78 Packet(); 77 Packet(u nsigned char *data,int clientID);79 Packet(uint8_t *data, unsigned int clientID); 78 80 // Packet(ENetPacket *packet, ENetPeer *peer); 79 81 enet_uint32 flags_; 80 int clientID_;82 unsigned int clientID_; 81 83 ENUM::Direction packetDirection_; 82 u nsigned char*data_;84 uint8_t *data_; 83 85 private: 84 86 static std::map<ENetPacket *, Packet *> packetMap_; -
code/branches/network/src/network/packet/Welcome.cc
r1763 r1890 42 42 #define _PACKETID 0 43 43 #define _CLIENTID _PACKETID + sizeof(ENUM::Type) 44 #define _SHIPID _CLIENTID + sizeof(u nsigned int)44 #define _SHIPID _CLIENTID + sizeof(uint32_t) 45 45 46 46 Welcome::Welcome( unsigned int clientID, unsigned int shipID ) … … 49 49 flags_ = flags_ | PACKET_FLAGS_CLASSID; 50 50 assert(getSize()); 51 data_=new u nsigned char[ getSize() ];51 data_=new uint8_t[ getSize() ]; 52 52 assert(data_); 53 53 *(packet::ENUM::Type *)(data_ + _PACKETID ) = packet::ENUM::Welcome; 54 *(u nsigned int *)&data_[ _CLIENTID ] = clientID;55 *(u nsigned int *)&data_[ _SHIPID ] = shipID;54 *(uint32_t *)&data_[ _CLIENTID ] = clientID; 55 *(uint32_t *)&data_[ _SHIPID ] = shipID; 56 56 } 57 57 58 Welcome::Welcome( u nsigned char *data,int clientID )58 Welcome::Welcome( uint8_t* data, unsigned int clientID ) 59 59 : Packet(data, clientID) 60 60 { … … 65 65 } 66 66 67 u nsigned char*Welcome::getData(){67 uint8_t *Welcome::getData(){ 68 68 return data_; 69 69 } 70 70 71 71 unsigned int Welcome::getSize() const{ 72 return sizeof(network::packet::ENUM::Type) + 2*sizeof(u nsigned int);72 return sizeof(network::packet::ENUM::Type) + 2*sizeof(uint32_t); 73 73 } 74 74 75 75 bool Welcome::process(){ 76 76 unsigned int shipID, clientID; 77 clientID = *(u nsigned int *)&data_[ _CLIENTID ];78 shipID = *(u nsigned int *)&data_[ _SHIPID ];77 clientID = *(uint32_t *)&data_[ _CLIENTID ]; 78 shipID = *(uint32_t *)&data_[ _SHIPID ]; 79 79 Host::setClientID(clientID); 80 80 Host::setShipID(shipID); -
code/branches/network/src/network/packet/Welcome.h
r1763 r1890 41 41 public: 42 42 Welcome( unsigned int clientID, unsigned int shipID ); 43 Welcome( u nsigned char* data,int clientID );43 Welcome( uint8_t* data, unsigned int clientID ); 44 44 virtual ~Welcome(); 45 45 46 u nsigned char*getData();46 uint8_t *getData(); 47 47 inline unsigned int getSize() const; 48 48 bool process();
Note: See TracChangeset
for help on using the changeset viewer.