Changeset 11842 for code/branches/Masterserver_FS18/src
- Timestamp:
- Mar 29, 2018, 4:04:35 PM (7 years ago)
- Location:
- code/branches/Masterserver_FS18/src/libraries/network
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/Masterserver_FS18/src/libraries/network/Client.h
r11071 r11842 90 90 private: 91 91 Client(const Client& copy); // not used 92 virtual bool isServer_() override {return false;}92 virtual bool isServer_() override { return false; } 93 93 virtual void processPacket(packet::Packet* packet) override; 94 94 -
code/branches/Masterserver_FS18/src/libraries/network/ClientConnection.h
r11071 r11842 36 36 { 37 37 38 class _NetworkExport ClientConnection: public Connection {38 class _NetworkExport ClientConnection: public Connection { 39 39 public: 40 40 ClientConnection(); -
code/branches/Masterserver_FS18/src/libraries/network/ClientConnectionListener.cc
r11071 r11842 31 31 #include "core/CoreIncludes.h" 32 32 #include "core/GameMode.h" 33 // #include "ClientInformation.h"34 33 35 34 namespace orxonox … … 37 36 RegisterAbstractClass(ClientConnectionListener).inheritsFrom<Listable>(); 38 37 38 /** 39 * Constructor 40 * Register the object 41 */ 39 42 ClientConnectionListener::ClientConnectionListener() 40 43 { … … 42 45 } 43 46 47 /** 48 * Call clientConnected() on all ClientConnectionListeners. 49 * @param clientID The ID of the newly connected client 50 */ 44 51 void ClientConnectionListener::broadcastClientConnected(unsigned int clientID) 45 52 { … … 48 55 } 49 56 57 /** 58 * Call clientDisconnected() on all ClientConnectionListeners. 59 * @param clientID The ID of the newly disconnected client 60 */ 50 61 void ClientConnectionListener::broadcastClientDisconnected(unsigned int clientID) 51 62 { … … 53 64 listener->clientDisconnected(clientID); 54 65 } 55 56 // void ClientConnectionListener::getConnectedClients()57 // {58 // ClientInformation* client = ClientInformation::getBegin();59 // while (client)60 // {61 // this->clientConnected(client->getID());62 // client = client->next();63 // }64 // }65 66 } 66 67 -
code/branches/Masterserver_FS18/src/libraries/network/ClientConnectionListener.h
r9667 r11842 35 35 namespace orxonox 36 36 { 37 /** 38 * An abstract base class. Derived classes must implement clientConnected() and clientDisconnected(). 39 */ 37 40 class _NetworkExport ClientConnectionListener : virtual public Listable 38 41 { … … 46 49 virtual void clientConnected(unsigned int clientID) = 0; 47 50 virtual void clientDisconnected(unsigned int clientID) = 0; 48 49 protected:50 // void getConnectedClients();51 51 }; 52 52 } -
code/branches/Masterserver_FS18/src/libraries/network/FunctionCallManager.cc
r11784 r11842 42 42 void FunctionCallManager::addCall(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5) 43 43 { 44 if(sPeerMap_.find(peerID)==sPeerMap_.end()) 44 // If the peerID doesn't exist yet in the map... 45 if(sPeerMap_.find(peerID) == sPeerMap_.end()) 45 46 { 47 // ... add a new FunctionCalls packet for the peer 46 48 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls; 47 49 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID); 48 50 } 51 52 // Add a new function call to the peer 49 53 FunctionCallManager::sPeerMap_[peerID]->addCall(functionID, objectID, mt1, mt2, mt3, mt4, mt5); 50 54 } 51 55 52 // Send calls 53 56 /** 57 * Send all function calls in sPeerMap_ to a given host, then clear sPeerMap_ 58 * @param host The host to send the function calls to 59 */ 54 60 void FunctionCallManager::sendCalls(orxonox::Host* host) 55 61 { 56 62 for (const auto& mapEntry : FunctionCallManager::sPeerMap_ ) 57 63 { 64 // TODO: This seems rather pointless, as it wouldn't be called anyways if the map was empty. 58 65 assert(!FunctionCallManager::sPeerMap_.empty()); 59 66 mapEntry.second->send(host); 60 67 } 68 // TODO: Why is the map cleared here? 61 69 FunctionCallManager::sPeerMap_.clear(); 62 70 } 63 71 72 /** 73 * Place an incoming function call in the queue for processing. 74 */ 64 75 void FunctionCallManager::bufferIncomingFunctionCall(const orxonox::FunctionCall& fctCall, uint32_t minGamestateID, uint32_t peerID) 65 76 { … … 67 78 } 68 79 80 /** 81 * Process queue of incoming function calls. 82 */ 69 83 void FunctionCallManager::processBufferedFunctionCalls() 70 84 { 71 85 std::vector<std::pair<FunctionCall, std::pair<uint32_t, uint32_t>>>::iterator it = FunctionCallManager::sIncomingFunctionCallBuffer_.begin(); 72 while( it !=FunctionCallManager::sIncomingFunctionCallBuffer_.end() )86 while( it != FunctionCallManager::sIncomingFunctionCallBuffer_.end() ) 73 87 { 74 88 OrxAssert( Host::getActiveInstance(), "No Host class existing" ); -
code/branches/Masterserver_FS18/src/libraries/network/FunctionCallManager.h
r11071 r11842 53 53 static void processBufferedFunctionCalls(); 54 54 55 // Maps peer IDs to function calls 55 56 static std::map<uint32_t, packet::FunctionCalls*> sPeerMap_; 57 58 // TODO: What's up with the pair within the pair? 59 // Vector of pairs 60 // The pair consists of the FunctionCall and another pair, which... 56 61 static std::vector<std::pair<FunctionCall,std::pair<uint32_t, uint32_t>>> sIncomingFunctionCallBuffer_; 62 57 63 protected: 58 64 FunctionCallManager(); -
code/branches/Masterserver_FS18/src/libraries/network/GamestateHandler.cc
r11071 r11842 32 32 namespace orxonox { 33 33 34 // GamestateHandler *GamestateHandler::instance_=nullptr;35 36 34 GamestateHandler::GamestateHandler() 37 35 { -
code/branches/Masterserver_FS18/src/libraries/network/GamestateHandler.h
r8327 r11842 37 37 38 38 /** 39 @author Oliver Scheuss 39 * An interface for any class that wants to handle gamestates. 40 * @author Oliver Scheuss 40 41 */ 41 42 class _NetworkExport GamestateHandler … … 51 52 virtual bool addGamestate(packet::Gamestate* gs, unsigned int clientID) = 0; 52 53 virtual bool ackGamestate(unsigned int gamestateID, unsigned int clientID) = 0; 53 virtual uint32_t getLastReceivedGamestateID( unsigned int clientID ) =0;54 virtual uint32_t getCurrentGamestateID() =0;54 virtual uint32_t getLastReceivedGamestateID( unsigned int clientID ) = 0; 55 virtual uint32_t getCurrentGamestateID() = 0; 55 56 }; 56 57 -
code/branches/Masterserver_FS18/src/libraries/network/GamestateManager.h
r11829 r11842 58 58 * - writing gamestates to universe 59 59 * - diffing gamestates 60 * 61 * Inherited by Host 62 * 60 63 * EN/DECODATION: 61 64 * a: last Gamestate a client has received … … 86 89 virtual bool ackGamestate(unsigned int gamestateID, unsigned int peerID) override; 87 90 virtual uint32_t getLastReceivedGamestateID( unsigned int peerID ) override; 88 virtual uint32_t getCurrentGamestateID() override { if(currentGamestate ) return currentGamestate_->getID(); else return GAMESTATEID_INITIAL; }91 virtual uint32_t getCurrentGamestateID() override { if(currentGamestate_) return currentGamestate_->getID(); else return GAMESTATEID_INITIAL; } 89 92 90 93 bool processGamestates(); -
code/branches/Masterserver_FS18/src/libraries/network/MasterServer.cc
r11083 r11842 357 357 358 358 /* incoming data */ 359 case ENET_EVENT_TYPE_RECEIVE: eventData( event ); break; 359 case ENET_EVENT_TYPE_RECEIVE: 360 eventData( event ); break; 361 360 362 default: break; 361 363 } -
code/branches/Masterserver_FS18/src/libraries/network/packet/Acknowledgement.cc
r11071 r11842 37 37 38 38 #define PACKET_FLAGS_ACK 0 39 // Offset to start of packet ID 39 40 #define _PACKETID 0 41 // Offset to start of ACK ID 40 42 #define _ACKID _PACKETID + sizeof(packet::Type) 41 43 44 /** 45 * Constructor 46 * Acknowledgement.data_ is 40 bits in size: 47 * [0, 7]: Packet Type 48 * [8, 39]: Acknowledgement ID 49 */ 42 50 Acknowledgement::Acknowledgement( unsigned int id, unsigned int peerID ) 43 51 : Packet() 44 52 { 45 flags_ = flags_ |PACKET_FLAGS_ACK;46 data_=new uint8_t[getSize() ];47 *(Type *)( data_ + _PACKETID) = Type::Acknowledgement;48 *(uint32_t *)( data_ + _ACKID) = id;49 peerID_=peerID;53 this->flags_ |= PACKET_FLAGS_ACK; 54 this->data_ = new uint8_t[ this->getSize() ]; 55 *(Type *)(this->data_ + _PACKETID) = Type::Acknowledgement; 56 *(uint32_t *)(this->data_ + _ACKID) = id; 57 this->peerID_ = peerID; 50 58 } 51 59 … … 59 67 } 60 68 61 unsigned int Acknowledgement::getSize() const {69 unsigned int Acknowledgement::getSize() const { 62 70 return _ACKID + sizeof(uint32_t); 63 71 } 64 72 65 bool Acknowledgement::process(orxonox::Host* host) {73 bool Acknowledgement::process(orxonox::Host* host) { 66 74 orxout(verbose_more, context::packets) << "processing ACK with ID: " << getAckID() << endl; 67 75 bool b = host->ackGamestate(getAckID(), peerID_); … … 70 78 } 71 79 72 unsigned int Acknowledgement::getAckID() {80 unsigned int Acknowledgement::getAckID() { 73 81 return *(uint32_t *)(data_ + _ACKID); 74 82 } -
code/branches/Masterserver_FS18/src/libraries/network/packet/Acknowledgement.h
r11071 r11842 34 34 35 35 namespace orxonox { 36 36 37 const unsigned int ACKID_NACK = 0; 38 37 39 namespace packet { 38 /** 39 @author 40 */ 40 41 41 class _NetworkExport Acknowledgement : public Packet 42 42 { -
code/branches/Masterserver_FS18/src/libraries/network/packet/Chat.cc
r11071 r11842 38 38 #define PACKET_FLAGS_CHAT PacketFlag::Reliable 39 39 40 /* Some lengths */40 /* Some lengths / offsets */ 41 41 #define _PACKETID 0 42 42 #define _SOURCEID _PACKETID + sizeof(Type) … … 49 49 { 50 50 /* Add chat flag to packet flags */ 51 flags_ = flags_ |PACKET_FLAGS_CHAT;51 this->flags_ |= PACKET_FLAGS_CHAT; 52 52 53 53 /* set message length to length of input string + 1 */ 54 messageLength_ = message.length()+1;54 this->messageLength_ = message.length() + 1; 55 55 56 56 /* allocate memory for the data */ 57 data_=new unsigned char[ getSize() ];57 this->data_ = new unsigned char[ getSize() ]; 58 58 59 59 *(Type *)(data_ + _PACKETID ) = Type::Chat; 60 60 *(unsigned int *)(data_ + _SOURCEID ) = sourceID; 61 61 *(unsigned int *)(data_ + _TARGETID ) = targetID; 62 *(unsigned int *)(data_ + _MESSAGELENGTH ) = messageLength_;62 *(unsigned int *)(data_ + _MESSAGELENGTH ) = this->messageLength_; 63 63 64 64 /* cast the hell out of the message string, and copy it into the 65 65 * data buffer. 66 66 */ 67 memcpy( data_+_MESSAGE, static_cast<void*>(const_cast<char*>(message.c_str())),messageLength_ );67 memcpy( this->data_ + _MESSAGE, static_cast<void*>(const_cast<char*>(message.c_str())), this->messageLength_ ); 68 68 } 69 69 … … 71 71 : Packet(data, clientID) 72 72 { 73 messageLength_ = *(uint32_t *)(data + _MESSAGELENGTH );73 this->messageLength_ = *(uint32_t *)(data + _MESSAGELENGTH ); 74 74 } 75 75 … … 79 79 80 80 unsigned int Chat::getSize() const{ 81 return _MESSAGE + messageLength_;81 return _MESSAGE + this->messageLength_; 82 82 } 83 83 84 84 bool Chat::process(orxonox::Host* host){ 85 host->doReceiveChat(std::string((const char*)data_+_MESSAGE), *(uint32_t *)(data_+_SOURCEID), *(uint32_t *)(data_+_TARGETID)); 85 host->doReceiveChat(std::string((const char*)this->data_ + _MESSAGE), 86 *(uint32_t *)(this->data_+_SOURCEID), 87 *(uint32_t *)(this->data_+_TARGETID)); 86 88 delete this; 87 89 return true; 88 90 } 89 91 90 unsigned char *Chat::getMessage() {91 return data_ + _MESSAGE;92 unsigned char *Chat::getMessage() { 93 return this->data_ + _MESSAGE; 92 94 } 93 95 -
code/branches/Masterserver_FS18/src/libraries/network/packet/Chat.h
r11071 r11842 55 55 56 56 /* Get the length of the message (not the full size of the packet) */ 57 unsigned int getMessageLength() { returnmessageLength_; };57 unsigned int getMessageLength() { return this->messageLength_; }; 58 58 59 59 /* return message content */ -
code/branches/Masterserver_FS18/src/libraries/network/packet/ClassID.cc
r11071 r11842 46 46 47 47 48 ClassID::ClassID( ) : Packet(){48 ClassID::ClassID() : Packet() { 49 49 Identifier *id; 50 unsigned int nrOfClasses =0;51 unsigned int packetSize =2*sizeof(uint32_t); //space for the packetID and for the nrofclasses50 unsigned int nrOfClasses = 0; 51 unsigned int packetSize = 2 * sizeof(uint32_t); //space for the packetID and for the nrofclasses 52 52 uint32_t network_id; 53 flags_ = flags_ |PACKET_FLAGS_CLASSID;53 this->flags_ |= PACKET_FLAGS_CLASSID; 54 54 std::queue<std::pair<uint32_t, std::string>> tempQueue; 55 55 56 // calculate total needed size (for all strings and integers)57 for(const auto& mapEntry : IdentifierManager::getInstance().getIdentifierByStringMap()) {56 // calculate total needed size (for all strings and integers) 57 for(const auto& mapEntry : IdentifierManager::getInstance().getIdentifierByStringMap()) { 58 58 id = mapEntry.second; 59 59 if(id == nullptr || !id->hasFactory()) … … 64 64 tempQueue.push( std::pair<unsigned int, std::string>(network_id, classname) ); 65 65 ++nrOfClasses; 66 packetSize += (classname.size() +1)+sizeof(network_id)+sizeof(uint32_t);66 packetSize += (classname.size() + 1) + sizeof(network_id) + sizeof(uint32_t); 67 67 } 68 68 69 this->data_ =new uint8_t[ packetSize ];69 this->data_ = new uint8_t[ packetSize ]; 70 70 //set the appropriate packet id 71 71 assert(this->data_); 72 72 *(Type *)(this->data_ + _PACKETID ) = Type::ClassID; 73 73 74 uint8_t *temp =data_+sizeof(uint32_t);74 uint8_t *temp = this->data_ + sizeof(uint32_t); 75 75 // save the number of all classes 76 *(uint32_t*) temp = nrOfClasses;76 *(uint32_t*) temp = nrOfClasses; 77 77 temp += sizeof(uint32_t); 78 78 79 79 // now save all classids and classnames 80 80 std::pair<uint32_t, std::string> tempPair; 81 uint32_t tempsize = 2 *sizeof(uint32_t); // packetid and nrOfClasses81 uint32_t tempsize = 2 * sizeof(uint32_t); // packetid and nrOfClasses 82 82 while( !tempQueue.empty() ){ 83 83 tempPair = tempQueue.front(); 84 84 tempQueue.pop(); 85 *(uint32_t*) temp = tempPair.first;86 *(uint32_t*) (temp+sizeof(uint32_t)) = tempPair.second.size()+1;87 memcpy(temp +2*sizeof(uint32_t), tempPair.second.c_str(), tempPair.second.size()+1);88 temp +=2*sizeof(uint32_t)+tempPair.second.size()+1;89 tempsize +=2*sizeof(uint32_t)+tempPair.second.size()+1;85 *(uint32_t*) temp = tempPair.first; 86 *(uint32_t*) (temp+sizeof(uint32_t)) = tempPair.second.size() + 1; 87 memcpy(temp + 2 * sizeof(uint32_t), tempPair.second.c_str(), tempPair.second.size() + 1); 88 temp += 2 * sizeof(uint32_t) + tempPair.second.size() + 1; 89 tempsize += 2 * sizeof(uint32_t) + tempPair.second.size() + 1; 90 90 } 91 assert(tempsize ==packetSize);91 assert(tempsize == packetSize); 92 92 93 93 orxout(verbose_more, context::packets) << "classid packetSize is " << packetSize << endl; … … 104 104 } 105 105 106 uint32_t ClassID::getSize() const {107 uint8_t *temp = data_+sizeof(uint32_t); // packet identification106 uint32_t ClassID::getSize() const { 107 uint8_t *temp = this->data_ + sizeof(uint32_t); // packet identification 108 108 uint32_t totalsize = sizeof(uint32_t); // packet identification 109 uint32_t nrOfClasses = *(uint32_t*) temp;109 uint32_t nrOfClasses = *(uint32_t*) temp; 110 110 temp += sizeof(uint32_t); 111 111 totalsize += sizeof(uint32_t); // storage size for nr of all classes 112 112 113 for(unsigned int i=0; i <nrOfClasses; i++){114 totalsize += 2 *sizeof(uint32_t) + *(uint32_t*)(temp + sizeof(uint32_t));115 temp += 2 *sizeof(uint32_t) + *(uint32_t*)(temp + sizeof(uint32_t));113 for(unsigned int i=0; i < nrOfClasses; i++) { 114 totalsize += 2 * sizeof(uint32_t) + *(uint32_t*) (temp + sizeof(uint32_t)); 115 temp += 2 * sizeof(uint32_t) + *(uint32_t*)(temp + sizeof(uint32_t)); 116 116 } 117 117 return totalsize; 118 118 } 119 119 120 121 bool ClassID::process(orxonox::Host* host){ 120 // TODO: This parses the packet and calls ClassByString() 121 // However, the resulting Identifier is discarded... 122 bool ClassID::process(orxonox::Host* host) { 122 123 int nrOfClasses; 123 uint8_t *temp = data_+sizeof(uint32_t); //skip the packetid124 uint8_t *temp = this->data_ + sizeof(uint32_t); //skip the packetid 124 125 uint32_t networkID; 125 126 uint32_t stringsize; 126 127 unsigned char *classname; 127 128 128 129 129 //clear the map of network ids … … 134 134 Identifier *id; 135 135 // read the total number of classes 136 nrOfClasses = *(uint32_t*) temp;136 nrOfClasses = *(uint32_t*) temp; 137 137 temp += sizeof(uint32_t); 138 138 139 for( int i =0; i<nrOfClasses; i++){140 networkID = *(uint32_t*) temp;141 stringsize = *(uint32_t*) (temp+sizeof(uint32_t));142 classname = temp +2*sizeof(uint32_t);143 id =ClassByString( std::string((const char*)classname) );139 for( int i = 0; i < nrOfClasses; i++) { 140 networkID = *(uint32_t*) temp; 141 stringsize = *(uint32_t*) (temp + sizeof(uint32_t)); 142 classname = temp + 2 * sizeof(uint32_t); 143 id = ClassByString( std::string((const char*) classname) ); 144 144 orxout(internal_info, context::packets) << "processing classid: " << networkID << " name: " << classname << " id: " << id << endl; 145 if(id ==nullptr){145 if(id == nullptr) { 146 146 orxout(user_error, context::packets) << "Received a bad classname" << endl; 147 147 abort(); 148 148 } 149 149 id->setNetworkID( networkID ); 150 temp += 2 *sizeof(uint32_t) + stringsize;150 temp += 2 * sizeof(uint32_t) + stringsize; 151 151 } 152 152 delete this; -
code/branches/Masterserver_FS18/src/libraries/network/packet/DeleteObjects.cc
r11071 r11842 45 45 : Packet() 46 46 { 47 flags_ = flags_ |PACKET_FLAG_DELETE;47 this->flags_ |= PACKET_FLAG_DELETE; 48 48 } 49 49 … … 60 60 { 61 61 unsigned int number = Synchronisable::getNumberOfDeletedObject(); 62 if(number ==0)62 if(number == 0) 63 63 return false; 64 64 orxout(verbose, context::packets) << "sending DeleteObjects: "; … … 83 83 { 84 84 assert(data_); 85 return _OBJECTIDS + *(uint32_t*) (data_+_QUANTITY)*sizeof(uint32_t);85 return _OBJECTIDS + *(uint32_t*) (this->data_ + _QUANTITY) * sizeof(uint32_t); 86 86 } 87 87 88 88 bool DeleteObjects::process(orxonox::Host* host) 89 89 { 90 for(unsigned int i =0; i<*(unsigned int *)(data_+_QUANTITY); i++)90 for(unsigned int i = 0; i < *(unsigned int *) (this->data_+_QUANTITY); i++) 91 91 { 92 92 orxout(verbose, context::packets) << "deleting object with id: " << *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) << endl; 93 Synchronisable::deleteObject( *(uint32_t*)( data_+_OBJECTIDS+i*sizeof(uint32_t)) );93 Synchronisable::deleteObject( *(uint32_t*)(this->data_ + _OBJECTIDS + i * sizeof(uint32_t)) ); 94 94 } 95 95 delete this; -
code/branches/Masterserver_FS18/src/libraries/network/packet/FunctionCalls.cc
r11071 r11842 63 63 assert(isDataENetAllocated()); 64 64 65 uint8_t* temp = data_ +sizeof(uint32_t); //skip packetid66 uint32_t nrOfCalls = *(uint32_t*) temp;65 uint8_t* temp = data_ + sizeof(uint32_t); //skip packetid 66 uint32_t nrOfCalls = *(uint32_t*) temp; 67 67 temp += sizeof(uint32_t); 68 this->minGamestateID_ = *(uint32_t*) temp;68 this->minGamestateID_ = *(uint32_t*) temp; 69 69 temp += sizeof(uint32_t); 70 for( unsigned int i = 0; i <nrOfCalls; i++ )70 for( unsigned int i = 0; i < nrOfCalls; i++ ) 71 71 { 72 72 FunctionCall fctCall; … … 95 95 this->minGamestateID_ = host->getCurrentGamestateID(); 96 96 assert(this->functionCalls_.size()); 97 data_=new uint8_t[ currentSize_ ];98 *(Type *)( data_ + _PACKETID ) = Type::FunctionCalls; // Set the Packet ID99 *(uint32_t*)( data_+sizeof(uint32_t)) = this->functionCalls_.size(); // set nrOfCalls100 *(uint32_t*)( data_+2*sizeof(uint32_t)) = this->minGamestateID_; // set minGamestateID_101 uint8_t* temp = data_+3*sizeof(uint32_t);97 this->data_ = new uint8_t[ currentSize_ ]; 98 *(Type *)(this->data_ + _PACKETID ) = Type::FunctionCalls; // Set the Packet ID 99 *(uint32_t*)(this->data_ + sizeof(uint32_t)) = this->functionCalls_.size(); // set nrOfCalls 100 *(uint32_t*)(this->data_ + 2 * sizeof(uint32_t)) = this->minGamestateID_; // set minGamestateID_ 101 uint8_t* temp = this->data_ + 3 * sizeof(uint32_t); 102 102 103 103 while( this->functionCalls_.size() ) … … 107 107 } 108 108 109 assert( temp ==data_+currentSize_ );109 assert( temp == this->data_ + currentSize_ ); 110 110 111 111 Packet::send(host); -
code/branches/Masterserver_FS18/src/libraries/network/packet/Packet.cc
r11071 r11842 129 129 } 130 130 131 /** 132 * Send the Packet. 133 * @param host The host which sends the packet 134 */ 131 135 bool Packet::send(orxonox::Host* host) 132 136 { 137 // Deny sending incoming packets 133 138 if(packetDirection_ != Direction::Outgoing && packetDirection_ != Direction::Bidirectional ) 134 139 { … … 136 141 return false; 137 142 } 143 138 144 if(!enetPacket_) 139 145 { 140 if(!data_){ 146 // Deny sending empty packets 147 if(!data_) { 141 148 assert(0); 142 149 return false; … … 152 159 // without having a reference in the packetMap_ 153 160 Packet::packetMapMutex_.lock(); 154 packetMap_[reinterpret_cast<size_t>(enetPacket_)] = this;161 Packet::packetMap_[reinterpret_cast<size_t>(enetPacket_)] = this; 155 162 Packet::packetMapMutex_.unlock(); 156 163 } … … 173 180 } 174 181 #endif 175 // ENetPacket *temp = enetPacket_; 176 // enetPacket_ = nullptr; // otherwise we have a double free because enet already handles the deallocation of the packet 182 183 // Send via reliable or standard channel respectively 177 184 if( this->flags_ & PacketFlag::Reliable ) 178 185 host->addPacket( enetPacket_, peerID_, NETWORK_CHANNEL_DEFAULT); 179 186 else 180 187 host->addPacket( enetPacket_, peerID_, NETWORK_CHANNEL_UNRELIABLE); 188 181 189 return true; 182 190 } 183 191 192 /** 193 * Given an ENetPacket, create an Orxonox packet 194 * @param packet The ENetPacket 195 * @param peerID The sender 196 */ 184 197 Packet *Packet::createPacket(ENetPacket* packet, uint32_t peerID) 185 198 { 186 199 uint8_t *data = packet->data; 187 // assert(ClientInformation::findClient(&peer->address)->getID() != static_cast<unsigned int>(-2) || !Host::isServer());188 // unsigned int peerID = ClientInformation::findClient(&peer->address)->getID();189 // HACK190 // if( peerID==static_cast<unsigned int>(-2))191 // peerID = NETWORK_PEER_ID_SERVER;192 200 Packet *p = nullptr; 193 // orxout(verbose_ultra, context::packets) << "packet type: " << *(Type *)&data[_PACKETID] << endl;194 201 switch( *(Type *)(data + _PACKETID) ) 195 202 { 196 203 case Type::Acknowledgement: 197 // orxout(verbose_more, context::packets) << "ack" << endl; 198 p = new Acknowledgement( data, peerID ); 204 p = new Acknowledgement( data, peerID ); 199 205 break; 200 206 case Type::Chat: 201 // orxout(verbose_more, context::packets) << "chat" << endl;202 207 p = new Chat( data, peerID ); 203 208 break; 204 209 case Type::ClassID: 205 // orxout(verbose_more, context::packets) << "classid" << endl;206 210 p = new ClassID( data, peerID ); 207 211 break; 208 212 case Type::Gamestate: 209 // orxout(verbose_more, context::packets) << "gamestate" << endl;210 213 p = new Gamestate( data, peerID ); 211 214 break; 212 215 case Type::Welcome: 213 // orxout(verbose_more, context::packets) << "welcome" << endl;214 216 p = new Welcome( data, peerID ); 215 217 break; 216 218 case Type::DeleteObjects: 217 // orxout(verbose_more, context::packets) << "deleteobjects" << endl;218 219 p = new DeleteObjects( data, peerID ); 219 220 break; 220 221 case Type::FunctionCalls: 221 // orxout(verbose_more, context::packets) << "functionCalls" << endl;222 222 p = new FunctionCalls( data, peerID ); 223 223 break; 224 224 case Type::FunctionIDs: 225 // orxout(verbose_more, context::packets) << "functionIDs" << endl;226 225 p = new FunctionIDs( data, peerID ); 227 226 break; … … 247 246 // Get our Packet from a global map with all Packets created in the send() method of Packet. 248 247 Packet::packetMapMutex_.lock(); 249 std::map<size_t, Packet*>::iterator it = packetMap_.find(reinterpret_cast<size_t>(enetPacket)); 248 249 std::map<size_t, Packet*>::iterator it = Packet::packetMap_.find(reinterpret_cast<size_t>(enetPacket)); 250 250 assert(it != packetMap_.end()); 251 251 252 // Make sure we don't delete it again in the destructor 252 253 it->second->enetPacket_ = nullptr; 253 254 delete it->second; 254 255 packetMap_.erase(it); 256 255 257 Packet::packetMapMutex_.unlock(); 256 // orxout(verbose_ultra, context::packets) << "PacketMap size: " << packetMap_.size() << endl;257 258 } 258 259 -
code/branches/Masterserver_FS18/src/libraries/network/packet/Packet.h
r11071 r11842 68 68 69 69 virtual unsigned char* getData(){ return data_; }; 70 virtual unsigned int getSize() const =0; 71 virtual bool process(orxonox::Host* host)=0; 70 virtual unsigned int getSize() const = 0; 71 72 // Invoke some sort of action associated with the packet 73 virtual bool process(orxonox::Host* host) = 0; 74 72 75 inline uint32_t getFlags() 73 76 { return flags_; } … … 82 85 83 86 virtual bool send(orxonox::Host* host); 87 84 88 protected: 85 89 Packet(); 86 90 Packet(uint8_t *data, unsigned int peerID); 87 // Packet(ENetPacket *packet, ENetPeer *peer);88 91 inline bool isDataENetAllocated() const 89 92 { return bDataENetAllocated_; } … … 100 103 data_ might no correlate with enetPacket_->data. */ 101 104 bool bDataENetAllocated_; 105 102 106 private: 107 // All Packets are contained in this map 103 108 static std::map<size_t, Packet *> packetMap_; 104 109 static boost::mutex packetMapMutex_; -
code/branches/Masterserver_FS18/src/libraries/network/packet/ServerInformation.cc
r11083 r11842 50 50 // Save Server Round Trip Time 51 51 this->serverRTT_ = event->peer->roundTripTime; 52 52 53 // Save Server Address, leave some space for scope ID 53 54 enet_address_get_host_ip(&event->peer->address, serverIP, 64); 55 54 56 this->serverIP_ = std::string(serverIP); 55 57 // Save ACK … … 57 59 char* ack = nullptr; 58 60 loadAndIncrease((char*&)ack, temp); 59 60 /* Fabian, what is this used for? it crashes the masterserver, hence commenting it */61 // written by Oli: this is just to make sure that loadAndIncrease really writes the whole ACK string into char* ack62 // assert(strcmp(ack, (const char*)LAN_DISCOVERY_ACK)==0);63 64 61 // Save Server Name 65 62 loadAndIncrease(this->serverName_, temp); … … 74 71 void ServerInformation::send(ENetPeer* peer) 75 72 { 76 std::string payload = this->serverName_ + Ogre::StringConverter::toString(this->clientNumber_);73 std::string payload = this->serverName_ + std::to_string(this->clientNumber_); 77 74 uint32_t size = returnSize(LAN_DISCOVERY_ACK) + returnSize(payload); 78 75 uint8_t* temp = new uint8_t[size];
Note: See TracChangeset
for help on using the changeset viewer.