Changeset 3257 for code/branches/core4/src/network/packet
- Timestamp:
- Jun 30, 2009, 3:14:45 PM (16 years ago)
- Location:
- code/branches/core4/src/network/packet
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core4/src/network/packet/Acknowledgement.cc
r3214 r3257 37 37 #define PACKET_FLAGS_ACK 0 38 38 #define _PACKETID 0 39 #define _ACKID _PACKETID + sizeof(packet:: ENUM::Type)39 #define _ACKID _PACKETID + sizeof(packet::Type::Value) 40 40 41 41 Acknowledgement::Acknowledgement( unsigned int id, unsigned int clientID ) … … 44 44 flags_ = flags_ | PACKET_FLAGS_ACK; 45 45 data_=new uint8_t[ getSize() ]; 46 *( ENUM::Type *)(data_ + _PACKETID ) = ENUM::Acknowledgement;46 *(Type::Value *)(data_ + _PACKETID ) = Type::Acknowledgement; 47 47 *(uint32_t *)(data_ + _ACKID ) = id; 48 48 clientID_=clientID; -
code/branches/core4/src/network/packet/Chat.cc
r3214 r3257 38 38 #define PACKET_FLAGS_CHAT PacketFlag::Reliable 39 39 #define _PACKETID 0 40 const int _PLAYERID = _PACKETID + sizeof( ENUM::Type);40 const int _PLAYERID = _PACKETID + sizeof(Type::Value); 41 41 #define _MESSAGELENGTH _PLAYERID + sizeof(uint32_t) 42 42 #define _MESSAGE _MESSAGELENGTH + sizeof(uint32_t) … … 48 48 messageLength_ = message.length()+1; 49 49 data_=new unsigned char[ getSize() ]; 50 *( ENUM::Type *)(data_ + _PACKETID ) = ENUM::Chat;50 *(Type::Value *)(data_ + _PACKETID ) = Type::Chat; 51 51 *(unsigned int *)(data_ + _PLAYERID ) = playerID; 52 52 *(unsigned int *)(data_ + _MESSAGELENGTH ) = messageLength_; -
code/branches/core4/src/network/packet/ClassID.cc
r3214 r3257 74 74 //set the appropriate packet id 75 75 assert(this->data_); 76 *( ENUM::Type *)(this->data_ + _PACKETID ) = ENUM::ClassID;76 *(Type::Value *)(this->data_ + _PACKETID ) = Type::ClassID; 77 77 78 78 uint8_t *temp=data_+sizeof(uint32_t); -
code/branches/core4/src/network/packet/DeleteObjects.cc
r3214 r3257 39 39 #define PACKET_FLAG_DELETE PacketFlag::Reliable 40 40 #define _PACKETID 0 41 #define _QUANTITY _PACKETID + sizeof( ENUM::Type)41 #define _QUANTITY _PACKETID + sizeof(Type::Value) 42 42 #define _OBJECTIDS _QUANTITY + sizeof(uint32_t) 43 43 … … 62 62 return false; 63 63 COUT(4) << "sending DeleteObjects: "; 64 unsigned int size = sizeof( ENUM::Type) + sizeof(uint32_t)*(number+1);64 unsigned int size = sizeof(Type::Value) + sizeof(uint32_t)*(number+1); 65 65 data_ = new uint8_t[size]; 66 66 uint8_t *tdata = data_; 67 *reinterpret_cast< ENUM::Type*>(tdata) = ENUM::DeleteObjects;68 tdata += sizeof( ENUM::Type);67 *reinterpret_cast<Type::Value*>(tdata) = Type::DeleteObjects; 68 tdata += sizeof(Type::Value); 69 69 *(uint32_t *)tdata = number; 70 70 tdata += sizeof(uint32_t); -
code/branches/core4/src/network/packet/FunctionCalls.cc
r3214 r3257 49 49 currentMemBlocks_ = 1; 50 50 data_=new uint8_t[ FUNCTIONCALLS_MEM_ALLOCATION ]; 51 *( ENUM::Type *)(data_ + _PACKETID ) = ENUM::FunctionCalls;51 *(Type::Value *)(data_ + _PACKETID ) = Type::FunctionCalls; 52 52 *(uint32_t*)(data_+sizeof(uint32_t)) = 0; // set nrOfCalls to 0 53 53 } -
code/branches/core4/src/network/packet/FunctionIDs.cc
r3214 r3257 68 68 //set the appropriate packet id 69 69 assert(this->data_); 70 *( ENUM::Type *)(this->data_ + _PACKETID ) = ENUM::FunctionIDs;70 *(Type::Value *)(this->data_ + _PACKETID ) = Type::FunctionIDs; 71 71 72 72 uint8_t *temp=data_+sizeof(uint32_t); -
code/branches/core4/src/network/packet/Gamestate.h
r3214 r3257 47 47 class _NetworkExport GamestateHeader{ 48 48 public: 49 GamestateHeader(uint8_t *data){ assert(data); data_ = data; *(uint32_t*)data_ = ENUM::Gamestate; }49 GamestateHeader(uint8_t *data){ assert(data); data_ = data; *(uint32_t*)data_ = Type::Gamestate; } 50 50 GamestateHeader(uint8_t *data, GamestateHeader* h) 51 51 { assert(data); data_=data; memcpy(data_, h->data_, getSize()); } -
code/branches/core4/src/network/packet/Packet.cc
r3214 r3257 63 63 Packet::Packet(){ 64 64 flags_ = PACKET_FLAG_DEFAULT; 65 packetDirection_ = ENUM::Outgoing;65 packetDirection_ = Direction::Outgoing; 66 66 clientID_=0; 67 67 data_=0; … … 76 76 Packet::Packet(uint8_t *data, unsigned int clientID){ 77 77 flags_ = PACKET_FLAG_DEFAULT; 78 packetDirection_ = ENUM::Incoming;78 packetDirection_ = Direction::Incoming; 79 79 clientID_=clientID; 80 80 data_=data; … … 125 125 126 126 bool Packet::send(){ 127 if(packetDirection_ != ENUM::Outgoing && packetDirection_ != ENUM::Bidirectional ){127 if(packetDirection_ != Direction::Outgoing && packetDirection_ != Direction::Bidirectional ){ 128 128 assert(0); 129 129 return false; … … 147 147 } 148 148 #ifndef NDEBUG 149 switch( *( ENUM::Type *)(data_ + _PACKETID) )149 switch( *(Type::Value *)(data_ + _PACKETID) ) 150 150 { 151 case ENUM::Acknowledgement:152 case ENUM::Chat:153 case ENUM::ClassID:154 case ENUM::Gamestate:155 case ENUM::Welcome:156 case ENUM::DeleteObjects:157 case ENUM::FunctionIDs:158 case ENUM::FunctionCalls:151 case Type::Acknowledgement: 152 case Type::Chat: 153 case Type::ClassID: 154 case Type::Gamestate: 155 case Type::Welcome: 156 case Type::DeleteObjects: 157 case Type::FunctionIDs: 158 case Type::FunctionCalls: 159 159 break; 160 160 default: … … 175 175 unsigned int clientID = ClientInformation::findClient(&peer->address)->getID(); 176 176 Packet *p = 0; 177 COUT(6) << "packet type: " << *( ENUM::Type *)&data[_PACKETID] << std::endl;178 switch( *( ENUM::Type *)(data + _PACKETID) )177 COUT(6) << "packet type: " << *(Type::Value *)&data[_PACKETID] << std::endl; 178 switch( *(Type::Value *)(data + _PACKETID) ) 179 179 { 180 case ENUM::Acknowledgement:180 case Type::Acknowledgement: 181 181 COUT(5) << "ack" << std::endl; 182 182 p = new Acknowledgement( data, clientID ); 183 183 break; 184 case ENUM::Chat:184 case Type::Chat: 185 185 COUT(5) << "chat" << std::endl; 186 186 p = new Chat( data, clientID ); 187 187 break; 188 case ENUM::ClassID:188 case Type::ClassID: 189 189 COUT(5) << "classid" << std::endl; 190 190 p = new ClassID( data, clientID ); 191 191 break; 192 case ENUM::Gamestate:192 case Type::Gamestate: 193 193 COUT(5) << "gamestate" << std::endl; 194 194 // TODO: remove brackets 195 195 p = new Gamestate( data, clientID ); 196 196 break; 197 case ENUM::Welcome:197 case Type::Welcome: 198 198 COUT(5) << "welcome" << std::endl; 199 199 p = new Welcome( data, clientID ); 200 200 break; 201 case ENUM::DeleteObjects:201 case Type::DeleteObjects: 202 202 COUT(5) << "deleteobjects" << std::endl; 203 203 p = new DeleteObjects( data, clientID ); 204 204 break; 205 case ENUM::FunctionCalls:205 case Type::FunctionCalls: 206 206 COUT(5) << "functionCalls" << std::endl; 207 207 p = new FunctionCalls( data, clientID ); 208 208 break; 209 case ENUM::FunctionIDs:209 case Type::FunctionIDs: 210 210 COUT(5) << "functionIDs" << std::endl; 211 211 p = new FunctionIDs( data, clientID ); -
code/branches/core4/src/network/packet/Packet.h
r3214 r3257 36 36 namespace packet{ 37 37 38 namespace ENUM{39 enum Direction{38 namespace Direction{ 39 enum Value{ 40 40 Incoming, 41 41 Outgoing, 42 42 Bidirectional 43 43 }; 44 enum Type{ 44 } 45 namespace Type{ 46 enum Value{ 45 47 Acknowledgement, 46 48 Chat, … … 84 86 uint32_t flags_; 85 87 unsigned int clientID_; 86 ENUM::DirectionpacketDirection_;88 Direction::Value packetDirection_; 87 89 /** Pointer to the data. Be careful when deleting it because it might 88 90 point to a location that was allocated by ENet. -
code/branches/core4/src/network/packet/Welcome.cc
r3214 r3257 41 41 #define PACKET_FLAGS_CLASSID PacketFlag::Reliable 42 42 #define _PACKETID 0 43 #define _CLIENTID _PACKETID + sizeof( ENUM::Type)43 #define _CLIENTID _PACKETID + sizeof(Type::Value) 44 44 #define _ENDIANTEST _CLIENTID + sizeof(uint32_t) 45 45 … … 51 51 data_=new uint8_t[ getSize() ]; 52 52 assert(data_); 53 *(packet:: ENUM::Type *)(data_ + _PACKETID ) = packet::ENUM::Welcome;53 *(packet::Type::Value *)(data_ + _PACKETID ) = packet::Type::Welcome; 54 54 *(uint32_t *)(data_ + _CLIENTID ) = static_cast<uint32_t>(clientID); 55 55 *(uint32_t *)(data_ + _ENDIANTEST ) = 0xFEDC4321; … … 70 70 71 71 unsigned int Welcome::getSize() const{ 72 return sizeof(packet:: ENUM::Type) + 2*sizeof(uint32_t);72 return sizeof(packet::Type::Value) + 2*sizeof(uint32_t); 73 73 } 74 74
Note: See TracChangeset
for help on using the changeset viewer.