Changeset 11071 for code/trunk/src/libraries/network/packet
- Timestamp:
- Jan 17, 2016, 10:29:21 PM (9 years ago)
- Location:
- code/trunk
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/network/packet/Acknowledgement.cc
r8858 r11071 38 38 #define PACKET_FLAGS_ACK 0 39 39 #define _PACKETID 0 40 #define _ACKID _PACKETID + sizeof(packet::Type ::Value)40 #define _ACKID _PACKETID + sizeof(packet::Type) 41 41 42 42 Acknowledgement::Acknowledgement( unsigned int id, unsigned int peerID ) … … 45 45 flags_ = flags_ | PACKET_FLAGS_ACK; 46 46 data_=new uint8_t[ getSize() ]; 47 *(Type ::Value*)(data_ + _PACKETID ) = Type::Acknowledgement;47 *(Type *)(data_ + _PACKETID ) = Type::Acknowledgement; 48 48 *(uint32_t *)(data_ + _ACKID ) = id; 49 49 peerID_=peerID; -
code/trunk/src/libraries/network/packet/Acknowledgement.h
r7801 r11071 46 46 ~Acknowledgement(); 47 47 48 inline unsigned int getSize() const;49 virtual bool process(orxonox::Host* host) ;48 virtual inline unsigned int getSize() const override; 49 virtual bool process(orxonox::Host* host) override; 50 50 51 51 unsigned int getAckID(); -
code/trunk/src/libraries/network/packet/Chat.cc
r8858 r11071 40 40 /* Some lengths */ 41 41 #define _PACKETID 0 42 #define _SOURCEID _PACKETID + sizeof(Type ::Value)42 #define _SOURCEID _PACKETID + sizeof(Type) 43 43 #define _TARGETID _SOURCEID + sizeof(uint32_t) 44 44 #define _MESSAGELENGTH _TARGETID + sizeof(uint32_t) … … 57 57 data_=new unsigned char[ getSize() ]; 58 58 59 *(Type ::Value*)(data_ + _PACKETID ) = Type::Chat;59 *(Type *)(data_ + _PACKETID ) = Type::Chat; 60 60 *(unsigned int *)(data_ + _SOURCEID ) = sourceID; 61 61 *(unsigned int *)(data_ + _TARGETID ) = targetID; -
code/trunk/src/libraries/network/packet/Chat.h
r8858 r11071 49 49 50 50 /* get size of packet */ 51 inline unsigned int getSize() const;51 virtual inline unsigned int getSize() const override; 52 52 53 53 /* process chat message packet and remove it afterwards */ 54 virtual bool process(orxonox::Host* host) ;54 virtual bool process(orxonox::Host* host) override; 55 55 56 56 /* Get the length of the message (not the full size of the packet) */ -
code/trunk/src/libraries/network/packet/ClassID.cc
r9667 r11071 52 52 uint32_t network_id; 53 53 flags_ = flags_ | PACKET_FLAGS_CLASSID; 54 std::queue<std::pair<uint32_t, std::string> 54 std::queue<std::pair<uint32_t, std::string>> tempQueue; 55 55 56 56 //calculate total needed size (for all strings and integers) 57 std::map<std::string, Identifier*>::const_iterator it = IdentifierManager::getInstance().getIdentifierByStringMap().begin(); 58 for(;it != IdentifierManager::getInstance().getIdentifierByStringMap().end();++it){ 59 id = it->second; 60 if(id == NULL || !id->hasFactory()) 57 for(const auto& mapEntry : IdentifierManager::getInstance().getIdentifierByStringMap()){ 58 id = mapEntry.second; 59 if(id == nullptr || !id->hasFactory()) 61 60 continue; 62 61 const std::string& classname = id->getName(); … … 71 70 //set the appropriate packet id 72 71 assert(this->data_); 73 *(Type ::Value*)(this->data_ + _PACKETID ) = Type::ClassID;72 *(Type *)(this->data_ + _PACKETID ) = Type::ClassID; 74 73 75 74 uint8_t *temp=data_+sizeof(uint32_t); … … 144 143 id=ClassByString( std::string((const char*)classname) ); 145 144 orxout(internal_info, context::packets) << "processing classid: " << networkID << " name: " << classname << " id: " << id << endl; 146 if(id== NULL){145 if(id==nullptr){ 147 146 orxout(user_error, context::packets) << "Received a bad classname" << endl; 148 147 abort(); -
code/trunk/src/libraries/network/packet/ClassID.h
r7801 r11071 47 47 ~ClassID(); 48 48 49 uint32_t getSize() const;50 virtual bool process(orxonox::Host* host) ;49 virtual uint32_t getSize() const override; 50 virtual bool process(orxonox::Host* host) override; 51 51 52 52 private: -
code/trunk/src/libraries/network/packet/DeleteObjects.cc
r8858 r11071 39 39 #define PACKET_FLAG_DELETE PacketFlag::Reliable 40 40 #define _PACKETID 0 41 #define _QUANTITY _PACKETID + sizeof(Type ::Value)41 #define _QUANTITY _PACKETID + sizeof(Type) 42 42 #define _OBJECTIDS _QUANTITY + sizeof(uint32_t) 43 43 … … 63 63 return false; 64 64 orxout(verbose, context::packets) << "sending DeleteObjects: "; 65 unsigned int size = sizeof(Type ::Value) + sizeof(uint32_t)*(number+1);65 unsigned int size = sizeof(Type) + sizeof(uint32_t)*(number+1); 66 66 data_ = new uint8_t[size]; 67 67 uint8_t *tdata = data_; 68 *reinterpret_cast<Type ::Value*>(tdata) = Type::DeleteObjects;69 tdata += sizeof(Type ::Value);68 *reinterpret_cast<Type*>(tdata) = Type::DeleteObjects; 69 tdata += sizeof(Type); 70 70 *(uint32_t *)tdata = number; 71 71 tdata += sizeof(uint32_t); -
code/trunk/src/libraries/network/packet/DeleteObjects.h
r7801 r11071 48 48 bool fetchIDs(); 49 49 50 inline unsigned int getSize() const;51 virtual bool process(orxonox::Host* host) ;50 virtual inline unsigned int getSize() const override; 51 virtual bool process(orxonox::Host* host) override; 52 52 53 53 private: -
code/trunk/src/libraries/network/packet/FunctionCalls.cc
r10624 r11071 96 96 assert(this->functionCalls_.size()); 97 97 data_=new uint8_t[ currentSize_ ]; 98 *(Type ::Value*)(data_ + _PACKETID ) = Type::FunctionCalls; // Set the Packet ID98 *(Type *)(data_ + _PACKETID ) = Type::FunctionCalls; // Set the Packet ID 99 99 *(uint32_t*)(data_+sizeof(uint32_t)) = this->functionCalls_.size(); // set nrOfCalls 100 100 *(uint32_t*)(data_+2*sizeof(uint32_t)) = this->minGamestateID_; // set minGamestateID_ -
code/trunk/src/libraries/network/packet/FunctionCalls.h
r10624 r11071 52 52 ~FunctionCalls(); 53 53 54 inline unsigned int getSize() const54 virtual inline unsigned int getSize() const override 55 55 { assert(!this->isDataENetAllocated()); return currentSize_; } 56 virtual bool process(orxonox::Host* host) ;56 virtual bool process(orxonox::Host* host) override; 57 57 58 58 void addCall( uint32_t networkID, uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5); 59 virtual bool send(orxonox::Host* host) ;59 virtual bool send(orxonox::Host* host) override; 60 60 private: 61 61 std::queue<orxonox::FunctionCall> functionCalls_; -
code/trunk/src/libraries/network/packet/FunctionIDs.cc
r10624 r11071 53 53 uint32_t networkID; 54 54 flags_ = flags_ | PACKET_FLAGS_FUNCTIONIDS; 55 std::queue<std::pair<uint32_t, std::string> 55 std::queue<std::pair<uint32_t, std::string>> tempQueue; 56 56 57 57 //calculate total needed size (for all strings and integers) … … 71 71 //set the appropriate packet id 72 72 assert(this->data_); 73 *(Type ::Value*)(this->data_ + _PACKETID ) = Type::FunctionIDs;73 *(Type *)(this->data_ + _PACKETID ) = Type::FunctionIDs; 74 74 75 75 uint8_t *temp=data_+sizeof(uint32_t); -
code/trunk/src/libraries/network/packet/FunctionIDs.h
r7801 r11071 47 47 ~FunctionIDs(); 48 48 49 virtual uint32_t getSize() const ;50 virtual bool process(orxonox::Host* host) ;49 virtual uint32_t getSize() const override; 50 virtual bool process(orxonox::Host* host) override; 51 51 52 52 private: -
code/trunk/src/libraries/network/packet/Gamestate.cc
r9667 r11071 106 106 { 107 107 uint32_t tempsize=0, currentsize=0; 108 assert(data_== 0);108 assert(data_==nullptr); 109 109 uint32_t size = calcGamestateSize(id, mode); 110 110 … … 126 126 mem += GamestateHeader::getSize(); 127 127 ObjectList<Synchronisable>::iterator it; 128 for(it = ObjectList<Synchronisable> ::begin(); it; ++it)128 for(it = ObjectList<Synchronisable>().begin(); it; ++it) 129 129 { 130 130 … … 133 133 tempsize = it->getData(mem, this->sizes_, id, mode); 134 134 if ( tempsize != 0 ) 135 dataVector_. push_back( obj(it->getObjectID(), it->getContextID(), tempsize, mem-data_));135 dataVector_.emplace_back(it->getObjectID(), it->getContextID(), tempsize, mem-data_); 136 136 137 137 #ifndef NDEBUG … … 213 213 { 214 214 std::list<uint32_t> v1; 215 ObjectList<Synchronisable>::iterator it; 216 for (it = ObjectList<Synchronisable>::begin(); it != ObjectList<Synchronisable>::end(); ++it) 217 { 218 if (it->getObjectID() == OBJECTID_UNKNOWN) 219 { 220 if (it->objectMode_ != 0x0) 215 for (Synchronisable* synchronisable : ObjectList<Synchronisable>()) 216 { 217 if (synchronisable->getObjectID() == OBJECTID_UNKNOWN) 218 { 219 if (synchronisable->objectMode_ != 0x0) 221 220 { 222 221 orxout(user_error, context::packets) << "Found object with OBJECTID_UNKNOWN on the client with objectMode != 0x0!" << endl; 223 222 orxout(user_error, context::packets) << "Possible reason for this error: Client created a synchronized object without the Server's approval." << endl; 224 orxout(user_error, context::packets) << "Objects class: " << it->getIdentifier()->getName() << endl;223 orxout(user_error, context::packets) << "Objects class: " << synchronisable->getIdentifier()->getName() << endl; 225 224 assert(false); 226 225 } … … 228 227 else 229 228 { 230 std::list<uint32_t>::iterator it2; 231 for (it2 = v1.begin(); it2 != v1.end(); ++it2) 229 for (uint32_t id : v1) 232 230 { 233 if ( it->getObjectID() == *it2)231 if (synchronisable->getObjectID() == id) 234 232 { 235 233 orxout(user_error, context::packets) << "Found duplicate objectIDs on the client!" << endl … … 239 237 } 240 238 } 241 v1.push_back( it->getObjectID());239 v1.push_back(synchronisable->getObjectID()); 242 240 } 243 241 } … … 608 606 609 607 if(dest_length==0) 610 return NULL;608 return nullptr; 611 609 612 610 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()]; … … 645 643 646 644 if(dest_length==0) 647 return NULL;645 return nullptr; 648 646 649 647 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()]; … … 762 760 uint32_t size = 0; 763 761 uint32_t nrOfVariables = 0; 764 // get the start of the Synchronisable list765 ObjectList<Synchronisable>::iterator it;766 762 // get total size of gamestate 767 for( it = ObjectList<Synchronisable>::begin(); it; ++it){768 size+= it->getSize(id, mode); // size of the actual data of the synchronisable769 nrOfVariables += it->getNrOfVariables();763 for(Synchronisable* synchronisable : ObjectList<Synchronisable>()){ 764 size+=synchronisable->getSize(id, mode); // size of the actual data of the synchronisable 765 nrOfVariables += synchronisable->getNrOfVariables(); 770 766 } 771 767 // orxout() << "allocating " << nrOfVariables << " ints" << endl; -
code/trunk/src/libraries/network/packet/Gamestate.h
r7801 r11071 48 48 { 49 49 50 static const uint8_t GAMESTATE_MODE_SERVER = 0x1;51 static const uint8_t GAMESTATE_MODE_CLIENT = 0x2;50 static constexpr uint8_t GAMESTATE_MODE_SERVER = 0x1; 51 static constexpr uint8_t GAMESTATE_MODE_CLIENT = 0x2; 52 52 53 53 class _NetworkExport GamestateHeader 54 54 { 55 55 public: 56 GamestateHeader(){ data_= 0; }56 GamestateHeader(){ data_=nullptr; } 57 57 GamestateHeader(uint8_t* data) 58 { assert(data); data_ = data; *( uint32_t*)data_ = Type::Gamestate; }58 { assert(data); data_ = data; *(Type*)data_ = Type::Gamestate; } 59 59 /*GamestateHeader(uint8_t* data, GamestateHeader* h) 60 60 { assert(data); data_=data; memcpy(data_, h->data_, getSize()); }*/ 61 61 void setData(uint8_t* data) 62 { assert(data); data_ = data; *( uint32_t*)data_ = Type::Gamestate; }62 { assert(data); data_ = data; *(Type*)data_ = Type::Gamestate; } 63 63 static inline uint32_t getSize() 64 64 { return 21; } … … 138 138 // void rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength); 139 139 // inline uint32_t findObject( const SynchronisableHeader& header, uint8_t* mem, uint32_t dataLength, uint32_t startPosition = 0 ); 140 virtual uint32_t getSize() const ;141 virtual bool process(orxonox::Host* host) ;140 virtual uint32_t getSize() const override; 141 virtual bool process(orxonox::Host* host) override; 142 142 uint32_t calcGamestateSize(uint32_t id, uint8_t mode=0x0); 143 143 // inline void diffObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes ); -
code/trunk/src/libraries/network/packet/Packet.cc
r8858 r11071 34 34 #define WIN32_LEAN_AND_MEAN 35 35 #include <enet/enet.h> 36 #include <boost/static_assert.hpp>37 36 #include <boost/thread/mutex.hpp> 38 37 … … 54 53 55 54 // Make sure we assume the right values 56 BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::Reliable) == static_cast<int>(ENET_PACKET_FLAG_RELIABLE));57 BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::Unsequenced) == static_cast<int>(ENET_PACKET_FLAG_UNSEQUENCED));58 BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::NoAllocate) == static_cast<int>(ENET_PACKET_FLAG_NO_ALLOCATE));55 static_assert(static_cast<int>(PacketFlag::Reliable) == static_cast<int>(ENET_PACKET_FLAG_RELIABLE), "check enum"); 56 static_assert(static_cast<int>(PacketFlag::Unsequenced) == static_cast<int>(ENET_PACKET_FLAG_UNSEQUENCED), "check enum"); 57 static_assert(static_cast<int>(PacketFlag::NoAllocate) == static_cast<int>(ENET_PACKET_FLAG_NO_ALLOCATE), "check enum"); 59 58 60 59 #define PACKET_FLAG_DEFAULT PacketFlag::NoAllocate … … 69 68 packetDirection_ = Direction::Outgoing; 70 69 peerID_=0; 71 data_= 0;72 enetPacket_= 0;70 data_=nullptr; 71 enetPacket_=nullptr; 73 72 bDataENetAllocated_ = false; 74 73 } … … 80 79 peerID_=peerID; 81 80 data_=data; 82 enetPacket_= 0;81 enetPacket_=nullptr; 83 82 bDataENetAllocated_ = false; 84 83 } … … 95 94 memcpy(data_, p.data_, p.getSize()); 96 95 }else 97 data_= 0;96 data_=nullptr; 98 97 bDataENetAllocated_ = p.bDataENetAllocated_; 99 98 } … … 122 121 // Destroy the ENetPacket if necessary. 123 122 // Note: For the case ENet used the callback to destroy the packet, we have already set 124 // enetPacket_ to NULLto avoid destroying it again.123 // enetPacket_ to nullptr to avoid destroying it again. 125 124 if (this->enetPacket_) 126 125 { … … 158 157 } 159 158 #ifndef NDEBUG 160 switch( *(Type ::Value*)(data_ + _PACKETID) )159 switch( *(Type *)(data_ + _PACKETID) ) 161 160 { 162 161 case Type::Acknowledgement: … … 175 174 #endif 176 175 // ENetPacket *temp = enetPacket_; 177 // enetPacket_ = 0; // otherwise we have a double free because enet already handles the deallocation of the packet176 // enetPacket_ = nullptr; // otherwise we have a double free because enet already handles the deallocation of the packet 178 177 if( this->flags_ & PacketFlag::Reliable ) 179 178 host->addPacket( enetPacket_, peerID_, NETWORK_CHANNEL_DEFAULT); … … 191 190 // if( peerID==static_cast<unsigned int>(-2)) 192 191 // peerID = NETWORK_PEER_ID_SERVER; 193 Packet *p = 0;194 // orxout(verbose_ultra, context::packets) << "packet type: " << *(Type ::Value*)&data[_PACKETID] << endl;195 switch( *(Type ::Value*)(data + _PACKETID) )192 Packet *p = nullptr; 193 // orxout(verbose_ultra, context::packets) << "packet type: " << *(Type *)&data[_PACKETID] << endl; 194 switch( *(Type *)(data + _PACKETID) ) 196 195 { 197 196 case Type::Acknowledgement: … … 251 250 assert(it != packetMap_.end()); 252 251 // Make sure we don't delete it again in the destructor 253 it->second->enetPacket_ = 0;252 it->second->enetPacket_ = nullptr; 254 253 delete it->second; 255 254 packetMap_.erase(it); -
code/trunk/src/libraries/network/packet/Packet.h
r8327 r11071 38 38 { 39 39 40 namespaceDirection40 enum class Direction 41 41 { 42 enum Value 43 { 44 Incoming, 45 Outgoing, 46 Bidirectional 47 }; 48 } 49 namespace Type 42 Incoming, 43 Outgoing, 44 Bidirectional 45 }; 46 enum class Type : uint8_t 50 47 { 51 enum Value 52 { 53 Acknowledgement, 54 Chat, 55 ClassID, 56 DeleteObjects, 57 FunctionIDs, 58 FunctionCalls, 59 Gamestate, 60 Welcome 61 }; 62 } 48 Acknowledgement, 49 Chat, 50 ClassID, 51 DeleteObjects, 52 FunctionIDs, 53 FunctionCalls, 54 Gamestate, 55 Welcome 56 }; 63 57 64 58 /** … … 98 92 unsigned int peerID_; 99 93 uint32_t requiredGamestateID_; 100 Direction ::ValuepacketDirection_;94 Direction packetDirection_; 101 95 /** Pointer to the data. Be careful when deleting it because it might 102 96 point to a location that was allocated by ENet. -
code/trunk/src/libraries/network/packet/ServerInformation.cc
r10622 r11071 87 87 } // namespace packet 88 88 89 std::ostream& operator<<(std::ostream& out, const ENetAddress& address)90 {91 char addr[64];92 if (!enet_address_get_host_ip(&address, addr, 64))93 out << addr;94 return out;95 }96 89 } // namespace orxonox 90 91 std::ostream& operator<<(std::ostream& out, const ENetAddress& address) 92 { 93 char addr[64]; 94 if (!enet_address_get_host_ip(&address, addr, 64)) 95 out << addr; 96 return out; 97 } -
code/trunk/src/libraries/network/packet/ServerInformation.h
r10622 r11071 50 50 void send( ENetPeer* peer ); 51 51 void setServerName(std::string name) { this->serverName_ = name; } 52 std::string getServerName() { return this->serverName_; }52 std::string getServerName() const { return this->serverName_; } 53 53 void setServerIP( std::string IP ) { this->serverIP_ = IP; } 54 std::string getServerIP() { return this->serverIP_; }54 std::string getServerIP() const { return this->serverIP_; } 55 55 void setClientNumber( int clientNumber ) { this->clientNumber_ = clientNumber; } 56 int getClientNumber() { return this->clientNumber_; }57 uint32_t getServerRTT() { return this->serverRTT_; }56 int getClientNumber() const { return this->clientNumber_; } 57 uint32_t getServerRTT() const { return this->serverRTT_; } 58 58 59 59 private: … … 66 66 } 67 67 68 _NetworkExport std::ostream& operator<<(std::ostream& out, const ENetAddress& address);69 68 } 70 69 70 _NetworkExport std::ostream& operator<<(std::ostream& out, const ENetAddress& address); 71 71 72 #endif // SERVERINFORMATION_H -
code/trunk/src/libraries/network/packet/Welcome.cc
r8858 r11071 41 41 #define PACKET_FLAGS_CLASSID PacketFlag::Reliable 42 42 #define _PACKETID 0 43 #define _CLIENTID _PACKETID + sizeof(Type ::Value)43 #define _CLIENTID _PACKETID + sizeof(Type) 44 44 #define _ENDIANTEST _CLIENTID + sizeof(uint32_t) 45 45 … … 51 51 data_=new uint8_t[ getSize() ]; 52 52 assert(data_); 53 *(packet::Type ::Value*)(data_ + _PACKETID ) = packet::Type::Welcome;53 *(packet::Type *)(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::Type ::Value) + 2*sizeof(uint32_t);72 return sizeof(packet::Type) + 2*sizeof(uint32_t); 73 73 } 74 74 -
code/trunk/src/libraries/network/packet/Welcome.h
r8706 r11071 45 45 virtual ~Welcome(); 46 46 47 uint8_t *getData();48 inline unsigned int getSize() const;49 virtual bool process(orxonox::Host* host) ;47 virtual uint8_t *getData() override; 48 virtual inline unsigned int getSize() const override; 49 virtual bool process(orxonox::Host* host) override; 50 50 51 51 private:
Note: See TracChangeset
for help on using the changeset viewer.