Changeset 7777 for code/branches/network5/src/libraries/network/packet
- Timestamp:
- Dec 19, 2010, 2:27:06 PM (15 years ago)
- Location:
- code/branches/network5/src/libraries/network/packet
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network5/src/libraries/network/packet/Acknowledgement.cc
r6417 r7777 31 31 #include "util/Debug.h" 32 32 #include "network/GamestateHandler.h" 33 #include "network/Host.h" 33 34 34 35 namespace orxonox { … … 39 40 #define _ACKID _PACKETID + sizeof(packet::Type::Value) 40 41 41 Acknowledgement::Acknowledgement( unsigned int id, unsigned int clientID )42 Acknowledgement::Acknowledgement( unsigned int id, unsigned int peerID ) 42 43 : Packet() 43 44 { … … 46 47 *(Type::Value *)(data_ + _PACKETID ) = Type::Acknowledgement; 47 48 *(uint32_t *)(data_ + _ACKID ) = id; 48 clientID_=clientID;49 peerID_=peerID; 49 50 } 50 51 51 Acknowledgement::Acknowledgement( uint8_t *data, unsigned int clientID )52 : Packet(data, clientID)52 Acknowledgement::Acknowledgement( uint8_t *data, unsigned int peerID ) 53 : Packet(data, peerID) 53 54 { 54 55 } … … 62 63 } 63 64 64 bool Acknowledgement::process( ){65 bool Acknowledgement::process(orxonox::Host* host){ 65 66 COUT(5) << "processing ACK with ID: " << getAckID() << endl; 66 bool b = GamestateHandler::ackGamestate(getAckID(), clientID_);67 bool b = host->ackGamestate(getAckID(), peerID_); 67 68 delete this; 68 69 return b; -
code/branches/network5/src/libraries/network/packet/Acknowledgement.h
r6073 r7777 42 42 { 43 43 public: 44 Acknowledgement( unsigned int id, unsigned int clientID );45 Acknowledgement( uint8_t* data, unsigned int clientID );44 Acknowledgement( unsigned int id, unsigned int peerID ); 45 Acknowledgement( uint8_t* data, unsigned int peerID ); 46 46 ~Acknowledgement(); 47 47 48 48 inline unsigned int getSize() const; 49 bool process();49 virtual bool process(orxonox::Host* host); 50 50 51 51 unsigned int getAckID(); -
code/branches/network5/src/libraries/network/packet/Chat.cc
r7163 r7777 80 80 } 81 81 82 bool Chat::process( ){83 bool b = Host::incomingChat(std::string((const char*)data_+_MESSAGE), *(uint32_t *)(data_+_PLAYERID));82 bool Chat::process(orxonox::Host* host){ 83 bool b = host->incomingChat(std::string((const char*)data_+_MESSAGE), *(uint32_t *)(data_+_PLAYERID)); 84 84 delete this; 85 85 return b; -
code/branches/network5/src/libraries/network/packet/Chat.h
r7163 r7777 52 52 53 53 /* process chat message packet and remove it afterwards */ 54 bool process();54 virtual bool process(orxonox::Host* host); 55 55 56 56 /* Get the length of the message (not the full size of the packet) */ -
code/branches/network5/src/libraries/network/packet/ClassID.cc
r7163 r7777 120 120 121 121 122 bool ClassID::process( ){122 bool ClassID::process(orxonox::Host* host){ 123 123 int nrOfClasses; 124 124 uint8_t *temp = data_+sizeof(uint32_t); //skip the packetid -
code/branches/network5/src/libraries/network/packet/ClassID.h
r6417 r7777 48 48 49 49 uint32_t getSize() const; 50 bool process();50 virtual bool process(orxonox::Host* host); 51 51 52 52 private: -
code/branches/network5/src/libraries/network/packet/DeleteObjects.cc
r6417 r7777 57 57 } 58 58 59 bool DeleteObjects::fetchIDs(){ 59 bool DeleteObjects::fetchIDs() 60 { 60 61 unsigned int number = Synchronisable::getNumberOfDeletedObject(); 61 62 if(number==0) … … 79 80 } 80 81 81 unsigned int DeleteObjects::getSize() const{ 82 unsigned int DeleteObjects::getSize() const 83 { 82 84 assert(data_); 83 85 return _OBJECTIDS + *(uint32_t*)(data_+_QUANTITY)*sizeof(uint32_t); 84 86 } 85 87 86 bool DeleteObjects::process(){ 87 for(unsigned int i=0; i<*(unsigned int *)(data_+_QUANTITY); i++){ 88 bool DeleteObjects::process(orxonox::Host* host) 89 { 90 for(unsigned int i=0; i<*(unsigned int *)(data_+_QUANTITY); i++) 91 { 88 92 COUT(4) << "deleting object with id: " << *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) << std::endl; 89 93 Synchronisable::deleteObject( *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) ); -
code/branches/network5/src/libraries/network/packet/DeleteObjects.h
r6073 r7777 32 32 #include "Packet.h" 33 33 34 namespace orxonox { 35 namespace packet { 34 namespace orxonox 35 { 36 namespace packet 37 { 36 38 /** 37 39 @author … … 47 49 48 50 inline unsigned int getSize() const; 49 bool process();51 virtual bool process(orxonox::Host* host); 50 52 51 53 private: -
code/branches/network5/src/libraries/network/packet/FunctionCalls.cc
r7759 r7777 58 58 59 59 60 bool FunctionCalls::process(){ 60 bool FunctionCalls::process(orxonox::Host* host) 61 { 61 62 assert(isDataENetAllocated()); 62 63 … … 70 71 FunctionCall fctCall; 71 72 fctCall.loadData(temp); 72 if( this->minGamestateID_ > GamestateHandler::getInstance()->getLastProcessedGamestateID(this->getClientID()) || !fctCall.execute() )73 if( this->minGamestateID_ > host->getLastProcessedGamestateID(this->getPeerID()) || !fctCall.execute() ) 73 74 { 74 FunctionCallManager::bufferIncomingFunctionCall( fctCall, minGamestateID_, this->get ClientID() );75 FunctionCallManager::bufferIncomingFunctionCall( fctCall, minGamestateID_, this->getPeerID() ); 75 76 } 76 77 } … … 80 81 } 81 82 82 void FunctionCalls::addCallStatic( uint32_t networkID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){ 83 void FunctionCalls::addCallStatic( uint32_t networkID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5) 84 { 83 85 assert(!isDataENetAllocated()); 84 86 … … 88 90 } 89 91 90 void FunctionCalls::addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){ 92 void FunctionCalls::addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5) 93 { 91 94 assert(!isDataENetAllocated()); 92 95 … … 96 99 } 97 100 98 bool FunctionCalls::send( )101 bool FunctionCalls::send(orxonox::Host* host) 99 102 { 100 this->minGamestateID_ = GamestateHandler::getInstance()->getCurrentGamestateID();103 this->minGamestateID_ = host->getCurrentGamestateID(); 101 104 assert(this->functionCalls_.size()); 102 105 data_=new uint8_t[ currentSize_ ]; … … 114 117 assert( temp==data_+currentSize_ ); 115 118 116 Packet::send( );119 Packet::send(host); 117 120 return true; 118 121 } -
code/branches/network5/src/libraries/network/packet/FunctionCalls.h
r7759 r7777 54 54 inline unsigned int getSize() const 55 55 { assert(!this->isDataENetAllocated()); return currentSize_; } 56 bool process();56 virtual bool process(orxonox::Host* host); 57 57 58 58 void addCallStatic( uint32_t networkID, const MultiType* mt1=0, const MultiType* mt2=0, const MultiType* mt3=0, const MultiType* mt4=0, const MultiType* mt5=0); 59 59 void addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1=0, const MultiType* mt2=0, const MultiType* mt3=0, const MultiType* mt4=0, const MultiType* mt5=0); 60 virtual bool send( );60 virtual bool send(orxonox::Host* host); 61 61 private: 62 62 std::queue<orxonox::FunctionCall> functionCalls_; -
code/branches/network5/src/libraries/network/packet/FunctionIDs.cc
r6417 r7777 46 46 47 47 48 FunctionIDs::FunctionIDs( ) : Packet(){ 48 FunctionIDs::FunctionIDs( ) : Packet() 49 { 49 50 unsigned int nrOfFunctions=0; 50 51 unsigned int packetSize=2*sizeof(uint32_t); //space for the packetID and for the nroffunctions … … 55 56 //calculate total needed size (for all strings and integers) 56 57 ObjectList<NetworkFunctionBase>::iterator it; 57 for(it = ObjectList<NetworkFunctionBase>::begin(); it; ++it){ 58 for(it = ObjectList<NetworkFunctionBase>::begin(); it; ++it) 59 { 58 60 const std::string& functionname = it->getName(); 59 61 networkID = it->getNetworkID(); … … 76 78 // now save all classids and classnames 77 79 std::pair<uint32_t, std::string> tempPair; 78 while( !tempQueue.empty() ){ 80 while( !tempQueue.empty() ) 81 { 79 82 tempPair = tempQueue.front(); 80 83 tempQueue.pop(); … … 98 101 } 99 102 100 uint32_t FunctionIDs::getSize() const{ 103 uint32_t FunctionIDs::getSize() const 104 { 101 105 assert(this->data_); 102 106 uint8_t *temp = data_+sizeof(uint32_t); // packet identification … … 114 118 115 119 116 bool FunctionIDs::process(){ 120 bool FunctionIDs::process(orxonox::Host* host) 121 { 117 122 int nrOfFunctions; 118 123 uint8_t *temp = data_+sizeof(uint32_t); //skip the packetid … … 127 132 temp += sizeof(uint32_t); 128 133 129 for( int i=0; i<nrOfFunctions; i++){ 134 for( int i=0; i<nrOfFunctions; i++) 135 { 130 136 networkID = *(uint32_t*)temp; 131 137 stringsize = *(uint32_t*)(temp+sizeof(uint32_t)); -
code/branches/network5/src/libraries/network/packet/FunctionIDs.h
r6417 r7777 47 47 ~FunctionIDs(); 48 48 49 uint32_t getSize() const;50 bool process();49 virtual uint32_t getSize() const; 50 virtual bool process(orxonox::Host* host); 51 51 52 52 private: -
code/branches/network5/src/libraries/network/packet/Gamestate.cc
r7759 r7777 36 36 #include "network/synchronisable/Synchronisable.h" 37 37 #include "network/GamestateHandler.h" 38 #include "network/Host.h" 38 39 39 40 namespace orxonox { … … 44 45 45 46 // #define PACKET_FLAG_GAMESTATE PacketFlag::Unsequenced 46 //#define PACKET_FLAG_GAMESTATE 047 #define PACKET_FLAG_GAMESTATE PacketFlag::Reliable47 #define PACKET_FLAG_GAMESTATE 0 48 // #define PACKET_FLAG_GAMESTATE PacketFlag::Reliable 48 49 49 50 inline bool memzero( uint8_t* data, uint32_t datalength) … … 138 139 assert(0); // if we don't use multithreading this part shouldn't be neccessary 139 140 // start allocate additional memory 140 COUT(3) << "G .St.Man: need additional memory" << std::endl;141 COUT(3) << "Gamestate: need additional memory" << std::endl; 141 142 ObjectList<Synchronisable>::iterator temp = it; 142 143 uint32_t addsize=tempsize; … … 165 166 //stop write gamestate header 166 167 167 COUT(5) << "G .ST.Man: Gamestate size: " << currentsize << std::endl;168 COUT(5) << "G .ST.Man: 'estimated' (and corrected) Gamestate size: " << size << std::endl;168 COUT(5) << "Gamestate: Gamestate size: " << currentsize << std::endl; 169 COUT(5) << "Gamestate: 'estimated' (and corrected) Gamestate size: " << size << std::endl; 169 170 return true; 170 171 } … … 173 174 bool Gamestate::spreadData(uint8_t mode) 174 175 { 175 COUT( 4) << "processing gamestate with id " << header_.getID() << endl;176 COUT(5) << "processing gamestate with id " << header_.getID() << endl; 176 177 assert(data_); 177 178 assert(!header_.isCompressed()); … … 204 205 } 205 206 } 207 assert(mem-data_ == GamestateHeader::getSize()+header_.getDataSize()); 208 206 209 // In debug mode, check first, whether there are no duplicate objectIDs 207 210 #ifndef NDEBUG … … 269 272 270 273 271 bool Gamestate::process( )272 { 273 return GamestateHandler::addGamestate(this, getClientID());274 bool Gamestate::process(orxonox::Host* host) 275 { 276 return host->addGamestate(this, getPeerID()); 274 277 } 275 278 … … 585 588 586 589 587 Gamestate *g = new Gamestate(newData, get ClientID());590 Gamestate *g = new Gamestate(newData, getPeerID()); 588 591 (g->header_) = header_; 589 592 g->header_.setBaseID( base->getID() ); … … 757 760 758 761 759 uint32_t Gamestate::calcGamestateSize( int32_t id, uint8_t mode)762 uint32_t Gamestate::calcGamestateSize(uint32_t id, uint8_t mode) 760 763 { 761 764 uint32_t size = 0; -
code/branches/network5/src/libraries/network/packet/Gamestate.h
r7758 r7777 42 42 #include "Packet.h" 43 43 44 namespace orxonox { 44 namespace orxonox 45 { 45 46 46 namespace packet { 47 namespace packet 48 { 49 50 static const uint8_t GAMESTATE_MODE_SERVER = 0x1; 51 static const uint8_t GAMESTATE_MODE_CLIENT = 0x2; 47 52 48 class _NetworkExport GamestateHeader{ 53 class _NetworkExport GamestateHeader 54 { 49 55 public: 50 56 GamestateHeader(){ data_=0; } … … 58 64 { return 21; } 59 65 60 inline int32_t getID() const61 { assert(data_); return *( int32_t*)(data_+4); }62 inline void setID( int32_t id)63 { assert(data_); *( int32_t*)(data_+4) = id; }66 inline uint32_t getID() const 67 { assert(data_); return *(uint32_t*)(data_+4); } 68 inline void setID(uint32_t id) 69 { assert(data_); *(uint32_t*)(data_+4) = id; } 64 70 65 inline int32_t getBaseID() const66 { assert(data_); return *( int32_t*)(data_+8); }67 inline void setBaseID( int32_t id)68 { assert(data_); *( int32_t*)(data_+8) = id; }71 inline uint32_t getBaseID() const 72 { assert(data_); return *(uint32_t*)(data_+8); } 73 inline void setBaseID(uint32_t id) 74 { assert(data_); *(uint32_t*)(data_+8) = id; } 69 75 70 76 inline uint32_t getDataSize() const … … 103 109 @author Oliver Scheuss 104 110 */ 105 class _NetworkExport Gamestate: public Packet{ 111 class _NetworkExport Gamestate: public Packet 112 { 106 113 public: 107 114 Gamestate(); … … 114 121 bool collectData(int id, uint8_t mode=0x0); 115 122 bool spreadData( uint8_t mode=0x0); 116 inline int32_t getID() const { return header_.getID(); }123 inline uint32_t getID() const { return header_.getID(); } 117 124 inline bool isDiffed() const { return header_.isDiffed(); } 118 125 inline bool isCompressed() const { return header_.isCompressed(); } … … 132 139 // inline uint32_t findObject( const SynchronisableHeader& header, uint8_t* mem, uint32_t dataLength, uint32_t startPosition = 0 ); 133 140 virtual uint32_t getSize() const; 134 virtual inline bool process();135 uint32_t calcGamestateSize( int32_t id, uint8_t mode=0x0);141 virtual bool process(orxonox::Host* host); 142 uint32_t calcGamestateSize(uint32_t id, uint8_t mode=0x0); 136 143 // inline void diffObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes ); 137 144 // inline void copyObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes ); -
code/branches/network5/src/libraries/network/packet/Packet.cc
r7773 r7777 68 68 flags_ = PACKET_FLAG_DEFAULT; 69 69 packetDirection_ = Direction::Outgoing; 70 clientID_=0;70 peerID_=0; 71 71 data_=0; 72 72 enetPacket_=0; … … 74 74 } 75 75 76 Packet::Packet(uint8_t *data, unsigned int clientID)76 Packet::Packet(uint8_t *data, unsigned int peerID) 77 77 { 78 78 flags_ = PACKET_FLAG_DEFAULT; 79 79 packetDirection_ = Direction::Incoming; 80 clientID_=clientID;80 peerID_=peerID; 81 81 data_=data; 82 82 enetPacket_=0; … … 89 89 flags_=p.flags_; 90 90 packetDirection_ = p.packetDirection_; 91 clientID_ = p.clientID_;91 peerID_ = p.peerID_; 92 92 if(p.data_){ 93 93 data_ = new uint8_t[p.getSize()]; … … 125 125 } 126 126 127 bool Packet::send( ){127 bool Packet::send(orxonox::Host* host){ 128 128 if(packetDirection_ != Direction::Outgoing && packetDirection_ != Direction::Bidirectional ){ 129 129 assert(0); … … 169 169 // enetPacket_ = 0; // otherwise we have a double free because enet already handles the deallocation of the packet 170 170 if( this->flags_ & PacketFlag::Reliable ) 171 Host::addPacket( enetPacket_, clientID_, NETWORK_CHANNEL_DEFAULT);171 host->addPacket( enetPacket_, peerID_, NETWORK_CHANNEL_DEFAULT); 172 172 else 173 Host::addPacket( enetPacket_, clientID_, NETWORK_CHANNEL_UNRELIABLE);173 host->addPacket( enetPacket_, peerID_, NETWORK_CHANNEL_UNRELIABLE); 174 174 return true; 175 175 } … … 178 178 uint8_t *data = packet->data; 179 179 assert(ClientInformation::findClient(&peer->address)->getID() != static_cast<unsigned int>(-2) || !Host::isServer()); 180 unsigned int clientID = ClientInformation::findClient(&peer->address)->getID();180 unsigned int peerID = ClientInformation::findClient(&peer->address)->getID(); 181 181 Packet *p = 0; 182 182 // COUT(6) << "packet type: " << *(Type::Value *)&data[_PACKETID] << std::endl; … … 185 185 case Type::Acknowledgement: 186 186 // COUT(5) << "ack" << std::endl; 187 p = new Acknowledgement( data, clientID );187 p = new Acknowledgement( data, peerID ); 188 188 break; 189 189 case Type::Chat: 190 190 // COUT(5) << "chat" << std::endl; 191 p = new Chat( data, clientID );191 p = new Chat( data, peerID ); 192 192 break; 193 193 case Type::ClassID: 194 194 // COUT(5) << "classid" << std::endl; 195 p = new ClassID( data, clientID );195 p = new ClassID( data, peerID ); 196 196 break; 197 197 case Type::Gamestate: 198 198 // COUT(5) << "gamestate" << std::endl; 199 p = new Gamestate( data, clientID );199 p = new Gamestate( data, peerID ); 200 200 break; 201 201 case Type::Welcome: 202 202 // COUT(5) << "welcome" << std::endl; 203 p = new Welcome( data, clientID );203 p = new Welcome( data, peerID ); 204 204 break; 205 205 case Type::DeleteObjects: 206 206 // COUT(5) << "deleteobjects" << std::endl; 207 p = new DeleteObjects( data, clientID );207 p = new DeleteObjects( data, peerID ); 208 208 break; 209 209 case Type::FunctionCalls: 210 210 // COUT(5) << "functionCalls" << std::endl; 211 p = new FunctionCalls( data, clientID );211 p = new FunctionCalls( data, peerID ); 212 212 break; 213 213 case Type::FunctionIDs: 214 214 // COUT(5) << "functionIDs" << std::endl; 215 p = new FunctionIDs( data, clientID );215 p = new FunctionIDs( data, peerID ); 216 216 break; 217 217 default: -
code/branches/network5/src/libraries/network/packet/Packet.h
r7772 r7777 68 68 virtual unsigned char *getData(){ return data_; }; 69 69 virtual unsigned int getSize() const =0; 70 virtual bool process( )=0;70 virtual bool process(orxonox::Host* host)=0; 71 71 inline uint32_t getFlags() 72 72 { return flags_; } 73 inline int getClientID() 74 { return clientID_; } 75 inline void setClientID( int id ) 76 { clientID_ = id; } 73 inline int getPeerID() 74 { return peerID_; } 75 inline void setPeerID( int id ) 76 { peerID_ = id; } 77 inline bool isReliable() 78 { return this->flags_ & PacketFlag::Reliable; } 79 inline uint32_t getRequiredGamestateID() 80 { return this->requiredGamestateID_; } 77 81 78 virtual bool send( );82 virtual bool send(orxonox::Host* host); 79 83 protected: 80 84 Packet(); 81 Packet(uint8_t *data, unsigned int clientID);85 Packet(uint8_t *data, unsigned int peerID); 82 86 // Packet(ENetPacket *packet, ENetPeer *peer); 83 87 inline bool isDataENetAllocated() const … … 85 89 86 90 uint32_t flags_; 87 unsigned int clientID_; 91 unsigned int peerID_; 92 uint32_t requiredGamestateID_; 88 93 Direction::Value packetDirection_; 89 94 /** Pointer to the data. Be careful when deleting it because it might -
code/branches/network5/src/libraries/network/packet/Welcome.cc
r5781 r7777 73 73 } 74 74 75 bool Welcome::process( ){75 bool Welcome::process(orxonox::Host* host){ 76 76 uint32_t clientID; 77 77 clientID = *(uint32_t *)(data_ + _CLIENTID ); 78 78 assert(*(uint32_t *)(data_ + _ENDIANTEST ) == 0xFEDC4321); 79 Host::setClientID(clientID);79 host->setClientID(clientID); 80 80 COUT(3) << "Welcome set clientId: " << clientID << endl; 81 81 Synchronisable::setClient(true); -
code/branches/network5/src/libraries/network/packet/Welcome.h
r6073 r7777 47 47 uint8_t *getData(); 48 48 inline unsigned int getSize() const; 49 bool process();49 virtual bool process(orxonox::Host* host); 50 50 51 51 private:
Note: See TracChangeset
for help on using the changeset viewer.