Changeset 11071 for code/trunk/src/libraries/network
- Timestamp:
- Jan 17, 2016, 10:29:21 PM (9 years ago)
- Location:
- code/trunk
- Files:
-
- 55 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/network/Client.cc
r10624 r11071 161 161 { 162 162 std::vector<packet::Gamestate*> gamestates = GamestateManager::getGamestates(); 163 std::vector<packet::Gamestate*>::iterator it; 164 for( it = gamestates.begin(); it != gamestates.end(); ++it ) 163 for( packet::Gamestate* gamestate : gamestates ) 165 164 { 166 (*it)->send( static_cast<Host*>(this) );165 gamestate->send( static_cast<Host*>(this) ); 167 166 } 168 167 } -
code/trunk/src/libraries/network/Client.h
r8858 r11071 76 76 static Client* getInstance(){ return singletonPtr_s; } // tolua_export 77 77 78 bool establishConnection();78 virtual bool establishConnection() override; 79 79 void setDestination( const std::string& serverAddress, unsigned int port ); // tolua_export 80 bool closeConnection();81 v oid queuePacket(ENetPacket* packet, int clientID, uint8_t channelID);82 virtual bool sendPacket( packet::Packet* packet ) { return packet->send( static_cast<Host*>(this) ); }83 virtual void doSendChat(const std::string& message, unsigned int sourceID, unsigned int targetID) ;84 virtual void doReceiveChat(const std::string& message, unsigned int sourceID, unsigned int targetID) ;85 virtual void printRTT() ;80 virtual bool closeConnection() override; 81 virtual void queuePacket(ENetPacket* packet, int clientID, uint8_t channelID) override; 82 virtual bool sendPacket( packet::Packet* packet ) override{ return packet->send( static_cast<Host*>(this) ); } 83 virtual void doSendChat(const std::string& message, unsigned int sourceID, unsigned int targetID) override; 84 virtual void doReceiveChat(const std::string& message, unsigned int sourceID, unsigned int targetID) override; 85 virtual void printRTT() override; 86 86 87 87 void update(const Clock& time); 88 88 protected: 89 virtual void connectionClosed() ;89 virtual void connectionClosed() override; 90 90 private: 91 91 Client(const Client& copy); // not used 92 virtual bool isServer_() {return false;}93 v oid processPacket(packet::Packet* packet);92 virtual bool isServer_() override{return false;} 93 virtual void processPacket(packet::Packet* packet) override; 94 94 95 95 static Client* singletonPtr_s; -
code/trunk/src/libraries/network/ClientConnection.cc
r8858 r11071 44 44 Connection(NETWORK_PEER_ID_SERVER), 45 45 established_(false), 46 server_( NULL)46 server_(nullptr) 47 47 { 48 48 this->serverAddress_ = new ENetAddress(); … … 72 72 73 73 // create host 74 this->host_ = enet_host_create( NULL, NETWORK_CLIENT_MAX_CONNECTIONS, NETWORK_CHANNEL_COUNT, 0, 0);74 this->host_ = enet_host_create(nullptr, NETWORK_CLIENT_MAX_CONNECTIONS, NETWORK_CHANNEL_COUNT, 0, 0); 75 75 76 if ( this->host_ == NULL)76 if ( this->host_ == nullptr ) 77 77 { 78 orxout(internal_error, context::network) << "ClientConnection: host_ == NULL" << endl;78 orxout(internal_error, context::network) << "ClientConnection: host_ == nullptr" << endl; 79 79 // error handling 80 80 return false; … … 93 93 94 94 this->server_ = enet_host_connect(this->host_, serverAddress_, NETWORK_CHANNEL_COUNT, 0); 95 if ( this->server_== NULL)95 if ( this->server_==nullptr ) 96 96 { 97 orxout(internal_error, context::network) << "ClientConnection: server_ == NULL" << endl;97 orxout(internal_error, context::network) << "ClientConnection: server_ == nullptr" << endl; 98 98 // error handling 99 99 return false; -
code/trunk/src/libraries/network/ClientConnection.h
r8327 r11071 57 57 uint32_t getRTT(); 58 58 private: 59 virtual void addPeer(uint32_t peerID) ;60 virtual void removePeer(uint32_t peerID) ;59 virtual void addPeer(uint32_t peerID) override; 60 virtual void removePeer(uint32_t peerID) override; 61 61 62 62 bool disconnectConnection(); -
code/trunk/src/libraries/network/ClientConnectionListener.cc
r10624 r11071 44 44 void ClientConnectionListener::broadcastClientConnected(unsigned int clientID) 45 45 { 46 for ( ObjectList<ClientConnectionListener>::iterator it = ObjectList<ClientConnectionListener>::begin(); it != ObjectList<ClientConnectionListener>::end(); ++it)47 it->clientConnected(clientID);46 for (ClientConnectionListener* listener : ObjectList<ClientConnectionListener>()) 47 listener->clientConnected(clientID); 48 48 } 49 49 50 50 void ClientConnectionListener::broadcastClientDisconnected(unsigned int clientID) 51 51 { 52 for ( ObjectList<ClientConnectionListener>::iterator it = ObjectList<ClientConnectionListener>::begin(); it != ObjectList<ClientConnectionListener>::end(); ++it)53 it->clientDisconnected(clientID);52 for (ClientConnectionListener* listener : ObjectList<ClientConnectionListener>()) 53 listener->clientDisconnected(clientID); 54 54 } 55 55 -
code/trunk/src/libraries/network/Connection.cc
r8858 r11071 46 46 47 47 Connection::Connection(uint32_t firstPeerID): 48 host_( 0), bCommunicationThreadRunning_(false), nextPeerID_(firstPeerID)48 host_(nullptr), bCommunicationThreadRunning_(false), nextPeerID_(firstPeerID) 49 49 { 50 50 enet_initialize(); … … 81 81 { 82 82 // this->overallMutex_->lock(); 83 outgoingEvent outEvent = { peerID, outgoingEventType::disconnectPeer, 0, 0 };83 outgoingEvent outEvent = { peerID, OutgoingEventType::disconnectPeer, nullptr, 0 }; 84 84 85 85 this->outgoingEventsMutex_->lock(); … … 91 91 void Connection::disconnectPeers() 92 92 { 93 outgoingEvent outEvent = { 0, outgoingEventType::disconnectPeers, 0, 0 };93 outgoingEvent outEvent = { 0, OutgoingEventType::disconnectPeers, nullptr, 0 }; 94 94 95 95 this->outgoingEventsMutex_->lock(); … … 101 101 { 102 102 // this->overallMutex_->lock(); 103 outgoingEvent outEvent = { peerID, outgoingEventType::sendPacket, packet, channelID };103 outgoingEvent outEvent = { peerID, OutgoingEventType::sendPacket, packet, channelID }; 104 104 105 105 this->outgoingEventsMutex_->lock(); … … 112 112 { 113 113 // this->overallMutex_->lock(); 114 outgoingEvent outEvent = { 0, outgoingEventType::broadcastPacket, packet, channelID };114 outgoingEvent outEvent = { 0, OutgoingEventType::broadcastPacket, packet, channelID }; 115 115 116 116 this->outgoingEventsMutex_->lock(); … … 197 197 switch( event.type ) 198 198 { 199 case outgoingEventType::sendPacket:199 case OutgoingEventType::sendPacket: 200 200 // check whether the peer is still/already in the peer list 201 201 if( this->peerMap_.find(event.peerID) != this->peerMap_.end() ) … … 211 211 } 212 212 break; 213 case outgoingEventType::disconnectPeer:213 case OutgoingEventType::disconnectPeer: 214 214 if( this->peerMap_.find(event.peerID) != this->peerMap_.end() ) 215 215 { … … 223 223 } 224 224 break; 225 case outgoingEventType::disconnectPeers:225 case OutgoingEventType::disconnectPeers: 226 226 disconnectPeersInternal(); 227 227 break; 228 case outgoingEventType::broadcastPacket:228 case OutgoingEventType::broadcastPacket: 229 229 enet_host_broadcast( this->host_, event.channelID, event.packet ); 230 230 break; … … 237 237 void Connection::disconnectPeersInternal() 238 238 { 239 std::map<uint32_t, ENetPeer*>::iterator it; 240 for( it=this->peerMap_.begin(); it!=this->peerMap_.end(); ++it ) 241 { 242 enet_peer_disconnect(it->second, 0); 239 for( const auto& mapEntry : this->peerMap_ ) 240 { 241 enet_peer_disconnect(mapEntry.second, 0); 243 242 } 244 243 uint32_t iterations = NETWORK_DISCONNECT_TIMEOUT/NETWORK_WAIT_TIMEOUT; … … 272 271 switch( inEvent.type ) 273 272 { 274 case incomingEventType::peerConnect:273 case IncomingEventType::peerConnect: 275 274 addPeer(inEvent.peerID); 276 275 break; 277 case incomingEventType::peerDisconnect:276 case IncomingEventType::peerDisconnect: 278 277 removePeer(inEvent.peerID); 279 278 break; 280 case incomingEventType::receivePacket:279 case IncomingEventType::receivePacket: 281 280 processPacket(inEvent.packet); 282 281 break; … … 323 322 324 323 // create new peerEvent and return it 325 incomingEvent inEvent = { peerID, incomingEventType::peerConnect, 0};324 incomingEvent inEvent = { peerID, IncomingEventType::peerConnect, nullptr }; 326 325 return inEvent; 327 326 } … … 338 337 339 338 // create new peerEvent and return it 340 incomingEvent inEvent = { peerID, incomingEventType::peerDisconnect, 0};339 incomingEvent inEvent = { peerID, IncomingEventType::peerDisconnect, nullptr }; 341 340 return inEvent; 342 341 } … … 352 351 353 352 // create new peerEvent and return it 354 incomingEvent inEvent = { peerID, incomingEventType::receivePacket, p };353 incomingEvent inEvent = { peerID, IncomingEventType::receivePacket, p }; 355 354 return inEvent; 356 355 } -
code/trunk/src/libraries/network/Connection.h
r8327 r11071 46 46 #include <map> 47 47 #include <enet/enet.h> 48 #include <boost/concept_check.hpp>49 48 50 49 namespace boost … … 61 60 const unsigned int NETWORK_MAX_QUEUE_PROCESS_TIME = 5; 62 61 63 namespace incomingEventType62 enum class IncomingEventType 64 63 { 65 enum Value 66 { 67 receivePacket = 1, // incoming packet 68 peerConnect = 2, // incoming connect request 69 peerDisconnect = 3 // incoming disconnect request 70 }; 71 72 } 64 receivePacket = 1, // incoming packet 65 peerConnect = 2, // incoming connect request 66 peerDisconnect = 3 // incoming disconnect request 67 }; 73 68 74 namespace outgoingEventType69 enum class OutgoingEventType 75 70 { 76 enum Value 77 { 78 sendPacket = 1, // outgoing packet 79 broadcastPacket = 2, // outgoing broadcast packet 80 disconnectPeer = 3, // outgoing disconnect request 81 disconnectPeers = 4 // outgoing disconnect request 82 }; 83 84 } 71 sendPacket = 1, // outgoing packet 72 broadcastPacket = 2, // outgoing broadcast packet 73 disconnectPeer = 3, // outgoing disconnect request 74 disconnectPeers = 4 // outgoing disconnect request 75 }; 85 76 86 77 struct _NetworkExport incomingEvent 87 78 { 88 uint32_t 89 incomingEventType::Valuetype;90 packet::Packet* 79 uint32_t peerID; 80 IncomingEventType type; 81 packet::Packet* packet; 91 82 }; 92 83 93 84 struct _NetworkExport outgoingEvent 94 85 { 95 uint32_t 96 outgoingEventType::Valuetype;97 ENetPacket* 98 ENetChannelID 86 uint32_t peerID; 87 OutgoingEventType type; 88 ENetPacket* packet; 89 ENetChannelID channelID; 99 90 }; 100 91 -
code/trunk/src/libraries/network/FunctionCall.cc
r10624 r11071 48 48 bool FunctionCall::execute(){ 49 49 NetworkFunctionBase* fct = NetworkFunctionManager::getInstance().getFunctionByNetworkId( this->functionID_ ); 50 assert( fct != NULL);50 assert( fct != nullptr ); 51 51 assert( this->nrOfArguments_==this->arguments_.size() ); 52 52 switch(this->nrOfArguments_) … … 119 119 for( unsigned int i=0; i<this->nrOfArguments_; ++i ) 120 120 { 121 this->arguments_. push_back(MultiType());121 this->arguments_.emplace_back(); 122 122 this->arguments_.back().importData(mem); 123 123 } … … 131 131 *(uint32_t*)(mem+2*sizeof(uint32_t)) = this->objectID_; 132 132 mem += 3*sizeof(uint32_t); 133 for( std::vector<MultiType>::iterator it = this->arguments_.begin(); it!=this->arguments_.end(); ++it)133 for(const MultiType& argument : this->arguments_) 134 134 { 135 it->exportData( mem );135 argument.exportData( mem ); 136 136 } 137 137 } -
code/trunk/src/libraries/network/FunctionCallManager.cc
r10624 r11071 37 37 38 38 std::map<uint32_t, packet::FunctionCalls*> FunctionCallManager::sPeerMap_; 39 std::vector<std::pair<FunctionCall, std::pair<uint32_t, uint32_t> >> FunctionCallManager::sIncomingFunctionCallBuffer_;39 std::vector<std::pair<FunctionCall, std::pair<uint32_t, uint32_t>>> FunctionCallManager::sIncomingFunctionCallBuffer_; 40 40 41 41 … … 54 54 void FunctionCallManager::sendCalls(orxonox::Host* host) 55 55 { 56 std::map<uint32_t, packet::FunctionCalls*>::iterator it; 57 for (it = FunctionCallManager::sPeerMap_.begin(); it != FunctionCallManager::sPeerMap_.end(); ++it ) 56 for (const auto& mapEntry : FunctionCallManager::sPeerMap_ ) 58 57 { 59 58 assert(!FunctionCallManager::sPeerMap_.empty()); 60 it->second->send(host);59 mapEntry.second->send(host); 61 60 } 62 61 FunctionCallManager::sPeerMap_.clear(); … … 65 64 void FunctionCallManager::bufferIncomingFunctionCall(const orxonox::FunctionCall& fctCall, uint32_t minGamestateID, uint32_t peerID) 66 65 { 67 FunctionCallManager::sIncomingFunctionCallBuffer_. push_back( std::make_pair(fctCall, std::make_pair(minGamestateID, peerID)));66 FunctionCallManager::sIncomingFunctionCallBuffer_.emplace_back(fctCall, std::make_pair(minGamestateID, peerID)); 68 67 } 69 68 70 69 void FunctionCallManager::processBufferedFunctionCalls() 71 70 { 72 std::vector<std::pair<FunctionCall, std::pair<uint32_t, uint32_t> >>::iterator it = FunctionCallManager::sIncomingFunctionCallBuffer_.begin();71 std::vector<std::pair<FunctionCall, std::pair<uint32_t, uint32_t>>>::iterator it = FunctionCallManager::sIncomingFunctionCallBuffer_.begin(); 73 72 while( it!=FunctionCallManager::sIncomingFunctionCallBuffer_.end() ) 74 73 { -
code/trunk/src/libraries/network/FunctionCallManager.h
r10624 r11071 54 54 55 55 static std::map<uint32_t, packet::FunctionCalls*> sPeerMap_; 56 static std::vector<std::pair<FunctionCall,std::pair<uint32_t, uint32_t> >> sIncomingFunctionCallBuffer_;56 static std::vector<std::pair<FunctionCall,std::pair<uint32_t, uint32_t>>> sIncomingFunctionCallBuffer_; 57 57 protected: 58 58 FunctionCallManager(); -
code/trunk/src/libraries/network/GamestateHandler.cc
r7801 r11071 32 32 namespace orxonox { 33 33 34 // GamestateHandler *GamestateHandler::instance_= 0;34 // GamestateHandler *GamestateHandler::instance_=nullptr; 35 35 36 36 GamestateHandler::GamestateHandler() -
code/trunk/src/libraries/network/GamestateManager.cc
r8858 r11071 60 60 { 61 61 GamestateManager::GamestateManager() : 62 currentGamestate_( 0), id_(0)62 currentGamestate_(nullptr), id_(0) 63 63 { 64 64 // trafficControl_ = new TrafficControl(); … … 70 70 { 71 71 if( this->currentGamestate_ ) 72 delete this->currentGamestate_;std::map<unsigned int, packet::Gamestate*>::iterator it; 73 for( it = gamestateQueue.begin(); it != gamestateQueue.end(); ++it ) 74 delete it->second; 75 std::map<uint32_t, peerInfo>::iterator peerIt; 76 std::map<uint32_t, packet::Gamestate*>::iterator gamestateIt; 77 for( peerIt = peerMap_.begin(); peerIt != peerMap_.end(); ++peerIt ) 78 { 79 for( gamestateIt = peerIt->second.gamestates.begin(); gamestateIt != peerIt->second.gamestates.end(); ++gamestateIt ) 80 delete gamestateIt->second; 72 delete this->currentGamestate_; 73 for( const auto& mapEntry : gamestateQueue ) 74 delete mapEntry.second; 75 for( const auto& mapEntryPeer : peerMap_ ) 76 { 77 for( const auto& mapEntryGamestate : mapEntryPeer.second.gamestates ) 78 delete mapEntryGamestate.second; 81 79 } 82 80 // this->trafficControl_->destroy(); … … 107 105 if( this->gamestateQueue.empty() ) 108 106 return true; 109 std::map<unsigned int, packet::Gamestate*>::iterator it;110 107 // now push only the most recent gamestates we received (ignore obsolete ones) 111 for( it = gamestateQueue.begin(); it!=gamestateQueue.end(); it++)112 { 113 OrxVerify(processGamestate( it->second), "ERROR: could not process Gamestate");114 sendAck( it->second->getID(), it->second->getPeerID() );115 delete it->second;108 for(const auto& mapEntry : gamestateQueue) 109 { 110 OrxVerify(processGamestate(mapEntry.second), "ERROR: could not process Gamestate"); 111 sendAck( mapEntry.second->getID(), mapEntry.second->getPeerID() ); 112 delete mapEntry.second; 116 113 } 117 114 // now clear the queue … … 140 137 141 138 bool GamestateManager::getSnapshot(){ 142 if ( currentGamestate_ != 0)139 if ( currentGamestate_ != nullptr ) 143 140 delete currentGamestate_; 144 141 uint8_t gsMode; … … 165 162 { //we have no data to send 166 163 delete currentGamestate_; 167 currentGamestate_= 0;164 currentGamestate_=nullptr; 168 165 return false; 169 166 } … … 177 174 std::vector<packet::Gamestate*> peerGamestates; 178 175 179 std::map<uint32_t, peerInfo>::iterator peerIt; 180 for( peerIt=peerMap_.begin(); peerIt!=peerMap_.end(); ++peerIt ) 181 { 182 if( !peerIt->second.isSynched ) 176 for( const auto& mapEntry : peerMap_ ) 177 { 178 if( !mapEntry.second.isSynched ) 183 179 { 184 180 orxout(verbose_more, context::network) << "Server: not sending gamestate" << endl; 185 181 continue; 186 182 } 187 orxout(verbose_more, context::network) << "client id: " << peerIt->first << endl;183 orxout(verbose_more, context::network) << "client id: " << mapEntry.first << endl; 188 184 orxout(verbose_more, context::network) << "Server: doing gamestate gamestate preparation" << endl; 189 int peerID = peerIt->first; //get client id190 191 unsigned int lastAckedGamestateID = peerIt->second.lastAckedGamestateID;192 193 packet::Gamestate* baseGamestate= 0;185 int peerID = mapEntry.first; //get client id 186 187 unsigned int lastAckedGamestateID = mapEntry.second.lastAckedGamestateID; 188 189 packet::Gamestate* baseGamestate=nullptr; 194 190 if(lastAckedGamestateID != GAMESTATEID_INITIAL) 195 191 { … … 200 196 } 201 197 202 peerGamestates.push_back( 0); // insert an empty gamestate* to be changed198 peerGamestates.push_back(nullptr); // insert an empty gamestate* to be changed 203 199 finishGamestate( peerID, peerGamestates.back(), baseGamestate, currentGamestate_ ); 204 if( peerGamestates.back()== 0)200 if( peerGamestates.back()==nullptr ) 205 201 // nothing to send to remove pointer from vector 206 202 peerGamestates.pop_back(); … … 243 239 { 244 240 delete diffed1; 245 destgamestate = 0;241 destgamestate = nullptr; 246 242 return; 247 243 } … … 340 336 { 341 337 assert(peerMap_.find(peerID)!=peerMap_.end()); 342 std::map<uint32_t, packet::Gamestate*>::iterator peerIt; 343 for( peerIt = peerMap_[peerID].gamestates.begin(); peerIt!=peerMap_[peerID].gamestates.end(); ++peerIt ) 344 { 345 delete peerIt->second; 338 for( const auto& mapEntry : peerMap_[peerID].gamestates ) 339 { 340 delete mapEntry.second; 346 341 } 347 342 peerMap_.erase(peerMap_.find(peerID)); … … 351 346 // void GamestateManager::removeClient(ClientInformation* client){ 352 347 // assert(client); 353 // std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> 348 // std::map<unsigned int, std::map<unsigned int, packet::Gamestate*>>::iterator clientMap = gamestateMap_.find(client->getID()); 354 349 // // first delete all remained gamestates 355 350 // std::map<unsigned int, packet::Gamestate*>::iterator it; -
code/trunk/src/libraries/network/GamestateManager.h
r10622 r11071 47 47 #include "core/CorePrereqs.h" 48 48 #include "packet/Gamestate.h" 49 #include <boost/concept_check.hpp>50 49 51 50 namespace orxonox … … 84 83 ~GamestateManager(); 85 84 86 virtual bool addGamestate(packet::Gamestate *gs, unsigned int peerID) ;87 virtual bool ackGamestate(unsigned int gamestateID, unsigned int peerID) ;88 virtual uint32_t getLastReceivedGamestateID( unsigned int peerID ) ;89 virtual uint32_t getCurrentGamestateID() { if( currentGamestate_) return currentGamestate_->getID(); else return GAMESTATEID_INITIAL; }85 virtual bool addGamestate(packet::Gamestate *gs, unsigned int peerID) override; 86 virtual bool ackGamestate(unsigned int gamestateID, unsigned int peerID) override; 87 virtual uint32_t getLastReceivedGamestateID( unsigned int peerID ) override; 88 virtual uint32_t getCurrentGamestateID() override{ if( currentGamestate_) return currentGamestate_->getID(); else return GAMESTATEID_INITIAL; } 90 89 91 90 bool processGamestates(); … … 108 107 bool processGamestate(packet::Gamestate *gs); 109 108 110 // std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> 109 // std::map<unsigned int, std::map<unsigned int, packet::Gamestate*>> gamestateMap_; 111 110 std::map<unsigned int, packet::Gamestate*> gamestateQueue; 112 111 // std::map<unsigned int, uint32_t> lastProcessedGamestateID_; -
code/trunk/src/libraries/network/Host.cc
r10624 r11071 44 44 SetConsoleCommand(__CC_printRTT_group, __CC_printRTT_name, &Host::printRTT); 45 45 46 // Host* Host::instance_= 0;46 // Host* Host::instance_=nullptr; 47 47 uint32_t Host::clientID_s=0; 48 48 // uint32_t Host::shipID_s=-1; … … 54 54 Host::Host() 55 55 { 56 // assert(instance_== 0);56 // assert(instance_==nullptr); 57 57 instances_s.push_back(this); 58 58 ModifyConsoleCommand(__CC_printRTT_group, __CC_printRTT_name).setObject(this); … … 62 62 63 63 /** 64 * @brief Destructor: resets the instance pointer to 064 * @brief Destructor: resets the instance pointer to nullptr 65 65 */ 66 66 Host::~Host() … … 68 68 assert( std::find( instances_s.begin(), instances_s.end(), this )!=instances_s.end() ); 69 69 instances_s.erase(std::find( instances_s.begin(), instances_s.end(), this )); 70 ModifyConsoleCommand(__CC_printRTT_group, __CC_printRTT_name).setObject( 0);70 ModifyConsoleCommand(__CC_printRTT_group, __CC_printRTT_name).setObject(nullptr); 71 71 } 72 72 … … 80 80 void Host::addPacket(ENetPacket *packet, int clientID, uint8_t channelID) 81 81 { 82 for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it)82 for(Host* host : instances_s) 83 83 { 84 if( (*it)->isActive() )84 if( host->isActive() ) 85 85 { 86 (*it)->queuePacket(packet, clientID, channelID);86 host->queuePacket(packet, clientID, channelID); 87 87 } 88 88 } … … 97 97 void Host::sendChat(const std::string& message, unsigned int sourceID, unsigned int targetID) 98 98 { 99 for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it)100 if( (*it)->isActive() )101 (*it)->doSendChat(message, sourceID, targetID);99 for(Host* host : instances_s) 100 if( host->isActive() ) 101 host->doSendChat(message, sourceID, targetID); 102 102 } 103 103 … … 107 107 void Host::doReceiveChat(const std::string& message, unsigned int sourceID, unsigned int targetID) 108 108 { 109 for ( ObjectList<NetworkChatListener>::iterator it = ObjectList<NetworkChatListener>::begin(); it != ObjectList<NetworkChatListener>::end(); ++it)110 it->incomingChat(message, sourceID);109 for (NetworkChatListener* listener : ObjectList<NetworkChatListener>()) 110 listener->incomingChat(message, sourceID); 111 111 } 112 112 … … 114 114 bool Host::isServer() 115 115 { 116 for ( std::vector<Host*>::iterator it=instances_s.begin(); it!=instances_s.end(); ++it)116 for (Host* host : instances_s) 117 117 { 118 if( (*it)->isActive() )118 if( host->isActive() ) 119 119 { 120 if( (*it)->isServer_() )120 if( host->isServer_() ) 121 121 return true; 122 122 } … … 135 135 ++it; 136 136 } 137 return 0;137 return nullptr; 138 138 } 139 139 -
code/trunk/src/libraries/network/LANDiscoverable.cc
r11009 r11071 46 46 RegisterClassNoArgs(LANDiscoverable); 47 47 48 LANDiscoverable::LANDiscoverable() : bActive_(false), host_( 0)48 LANDiscoverable::LANDiscoverable() : bActive_(false), host_(nullptr) 49 49 { 50 50 /* register object in orxonox */ … … 82 82 bindAddress.host = ENET_HOST_ANY; 83 83 bindAddress.port = LAN_DISCOVERY_PORT; 84 assert( this->host_ == 0);84 assert( this->host_ == nullptr ); 85 85 this->host_ = enet_host_create( &bindAddress, 10, 0, 0, 0 ); 86 if ( this->host_ == NULL)87 orxout(internal_error, context::network) << "LANDiscoverable: host_ == NULL" << endl;86 if ( this->host_ == nullptr ) 87 orxout(internal_error, context::network) << "LANDiscoverable: host_ == nullptr" << endl; 88 88 } 89 89 else 90 90 { 91 91 enet_host_destroy( this->host_ ); 92 this->host_ = 0;92 this->host_ = nullptr; 93 93 } 94 94 this->bActive_ = bActive; -
code/trunk/src/libraries/network/LANDiscovery.cc
r10624 r11071 42 42 LANDiscovery::LANDiscovery() 43 43 { 44 this->host_ = enet_host_create( NULL, 10, 0, 0, 0 );45 if ( this->host_ == NULL)46 orxout(internal_error, context::network) << "LANDiscovery: host_ == NULL" << endl;44 this->host_ = enet_host_create(nullptr, 10, 0, 0, 0 ); 45 if ( this->host_ == nullptr ) 46 orxout(internal_error, context::network) << "LANDiscovery: host_ == nullptr" << endl; 47 47 } 48 48 49 49 LANDiscovery::~LANDiscovery() 50 50 { 51 if (this->host_ != NULL)51 if (this->host_ != nullptr) 52 52 enet_host_destroy(this->host_); 53 53 } … … 65 65 address.host = ENET_HOST_BROADCAST; 66 66 peer = enet_host_connect(this->host_, &address, 0, 0); 67 if (peer == NULL)67 if (peer == nullptr) 68 68 orxout(internal_error, context::network) << "Could not send LAN discovery to IPv4 Broadcast." << endl; 69 69 … … 71 71 enet_address_set_host(&address, "ff02::1"); // TODO: use a multicast group 72 72 peer = enet_host_connect(this->host_, &address, 0, 0); 73 if (peer == NULL)73 if (peer == nullptr) 74 74 orxout(internal_error, context::network) << "Could not send LAN discovery to IPv6 Multicast." << endl; 75 75 -
code/trunk/src/libraries/network/MasterServer.cc
r10624 r11071 43 43 44 44 /* forward declaration so the linker doesn't complain */ 45 MasterServer *MasterServer::instance = NULL;45 MasterServer *MasterServer::instance = nullptr; 46 46 47 47 /* command: list servers */ … … 49 49 MasterServer::listServers( void ) 50 50 { 51 /* get an iterator */52 std::list<ServerListElem>::iterator i;53 54 51 /* print list header */ 55 52 orxout(user_info) << "List of connected servers" << std::endl; 56 53 57 54 /* loop through list elements */ 58 for( i = MasterServer::getInstance()->mainlist.serverlist.begin(); 59 i != MasterServer::getInstance()->mainlist.serverlist.end(); ++i ) 55 for( const ServerListElem& elem : MasterServer::getInstance()->mainlist.serverlist ) 60 56 { 61 orxout(user_info) << " " << (*i).ServerInfo.getServerIP() << std::endl;57 orxout(user_info) << " " << elem.ServerInfo.getServerIP() << std::endl; 62 58 } 63 59 … … 112 108 MasterServer::helper_sendlist( ENetEvent *event ) 113 109 { 114 /* get an iterator */115 std::list<ServerListElem>::iterator i;116 117 110 /* packet holder */ 118 111 ENetPacket *reply; 119 112 120 113 /* loop through list elements */ 121 for( i = mainlist.serverlist.begin(); i 122 != mainlist.serverlist.end(); ++i ) 114 for( const ServerListElem& elem : mainlist.serverlist ) 123 115 { 124 116 /* send this particular server */ 125 117 /* build reply string */ 126 int packetlen = MSPROTO_SERVERLIST_ITEM_LEN + 1 + (*i).ServerInfo.getServerIP().length() + 1 + (*i).ServerInfo.getServerName().length() + 1 + sizeof((*i).ServerInfo.getClientNumber()) + 1;118 int packetlen = MSPROTO_SERVERLIST_ITEM_LEN + 1 + elem.ServerInfo.getServerIP().length() + 1 + elem.ServerInfo.getServerName().length() + 1 + sizeof(elem.ServerInfo.getClientNumber()) + 1; 127 119 char *tosend = (char *)calloc(packetlen ,1 ); 128 120 if( !tosend ) … … 131 123 } 132 124 sprintf( tosend, "%s %s %s %u", MSPROTO_SERVERLIST_ITEM, 133 (*i).ServerInfo.getServerIP().c_str(), (*i).ServerInfo.getServerName().c_str(), (*i).ServerInfo.getClientNumber());125 elem.ServerInfo.getServerIP().c_str(), elem.ServerInfo.getServerName().c_str(), elem.ServerInfo.getClientNumber()); 134 126 135 127 /* create packet from it */ … … 167 159 MasterServer::helper_cleanupServers( void ) 168 160 { 169 /* get an iterator */170 std::list<ServerListElem>::iterator i;171 172 161 if( mainlist.serverlist.size() == 0 ) 173 162 return; 174 163 175 164 /* loop through list elements */ 176 for( i = mainlist.serverlist.begin(); i 177 != mainlist.serverlist.end(); ++i ) 165 for( const ServerListElem& elem : mainlist.serverlist ) 178 166 { /* see if we have a disconnected peer */ 179 if( (*i).peer &&180 ( (*i).peer->state == ENET_PEER_STATE_DISCONNECTED ||181 (*i).peer->state == ENET_PEER_STATE_ZOMBIE ))167 if( elem.peer && 168 (elem.peer->state == ENET_PEER_STATE_DISCONNECTED || 169 elem.peer->state == ENET_PEER_STATE_ZOMBIE )) 182 170 { 183 171 /* Remove it from the list */ 184 orxout(internal_warning) << (char*) (*i).peer->data << " timed out.\n";185 mainlist.delServerByName( (*i).ServerInfo.getServerName() );172 orxout(internal_warning) << (char*)elem.peer->data << " timed out.\n"; 173 mainlist.delServerByName( elem.ServerInfo.getServerName() ); 186 174 187 175 /* stop iterating, we manipulated the list */ … … 345 333 /***** ENTER MAIN LOOP *****/ 346 334 ENetEvent *event = (ENetEvent *)calloc(sizeof(ENetEvent), sizeof(char)); 347 if( event == NULL)335 if( event == nullptr ) 348 336 { 349 337 orxout(user_error, context::master_server) << "Could not create ENetEvent structure, exiting." << endl; -
code/trunk/src/libraries/network/MasterServerComm.cc
r8858 r11071 54 54 55 55 /* initiate the client */ 56 this->client = enet_host_create( NULL/* create a client host */,56 this->client = enet_host_create( nullptr /* create a client host */, 57 57 1, 58 58 2, /* allow up 2 channels to be used, 0 and 1 */ … … 61 61 62 62 /* see if it worked */ 63 if (this->client == NULL)63 if (this->client == nullptr) 64 64 { orxout(internal_error, context::master_server) << "An error occurred while trying to create an " 65 65 << "ENet client host." << endl; … … 85 85 this->peer = enet_host_connect(this->client, &this->address, 2, 0); 86 86 87 if( this->peer == NULL)87 if( this->peer == nullptr ) 88 88 { orxout(internal_error, context::master_server) << "No available peers for initiating an ENet" 89 89 << " connection." << endl; … … 157 157 158 158 /* address buffer */ 159 char *addrconv = NULL;159 char *addrconv = nullptr; 160 160 int retval = 0; 161 161 … … 193 193 194 194 /* call the supplied callback, if any. */ 195 if( listener != NULL)195 if( listener != nullptr ) 196 196 retval = listener->rhandler( addrconv, &(this->event) ); 197 197 -
code/trunk/src/libraries/network/NetworkFunction.h
r10624 r11071 45 45 46 46 #if defined(ORXONOX_COMPILER_GCC) && defined(ORXONOX_ARCH_32) 47 static const unsigned int MAX_FUNCTION_POINTER_SIZE = 8;47 static constexpr unsigned int MAX_FUNCTION_POINTER_SIZE = 8; 48 48 #else 49 static const unsigned int MAX_FUNCTION_POINTER_SIZE = 16;49 static constexpr unsigned int MAX_FUNCTION_POINTER_SIZE = 16; 50 50 #endif //ORXONOX_COMPILER_GCC 51 static const unsigned int MAX_FUNCTION_POINTER_INTS = (MAX_FUNCTION_POINTER_SIZE-1)/4+1;51 static constexpr unsigned int MAX_FUNCTION_POINTER_INTS = (MAX_FUNCTION_POINTER_SIZE-1)/4+1; 52 52 53 53 struct _NetworkExport NetworkFunctionPointer { … … 114 114 115 115 // ignore the objectID because its a static function 116 virtual bool call(uint32_t objectID) { (*this->functor_)(); return true; }117 virtual bool call(uint32_t objectID, const MultiType& mt1) { (*this->functor_)(mt1); return true; }118 virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2) { (*this->functor_)(mt1, mt2); return true; }119 virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3) { (*this->functor_)(mt1, mt2, mt3); return true; }120 virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4) { (*this->functor_)(mt1, mt2, mt3, mt4); return true; }121 virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5) { (*this->functor_)(mt1, mt2, mt3, mt4, mt5); return true; }116 virtual bool call(uint32_t objectID) override{ (*this->functor_)(); return true; } 117 virtual bool call(uint32_t objectID, const MultiType& mt1) override{ (*this->functor_)(mt1); return true; } 118 virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2) override{ (*this->functor_)(mt1, mt2); return true; } 119 virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3) override{ (*this->functor_)(mt1, mt2, mt3); return true; } 120 virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4) override{ (*this->functor_)(mt1, mt2, mt3, mt4); return true; } 121 virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5) override{ (*this->functor_)(mt1, mt2, mt3, mt4, mt5); return true; } 122 122 123 123 private: … … 142 142 { } 143 143 144 inline bool call(uint32_t objectID)145 { 146 if ( Synchronisable::getSynchronisable(objectID)!= 0)144 virtual inline bool call(uint32_t objectID) override 145 { 146 if ( Synchronisable::getSynchronisable(objectID)!=nullptr ) 147 147 { 148 148 (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID))); … … 152 152 return false; 153 153 } 154 inline bool call(uint32_t objectID, const MultiType& mt1)155 { 156 if ( Synchronisable::getSynchronisable(objectID)!= 0)154 virtual inline bool call(uint32_t objectID, const MultiType& mt1) override 155 { 156 if ( Synchronisable::getSynchronisable(objectID)!=nullptr ) 157 157 { 158 158 (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1); … … 162 162 return false; 163 163 } 164 inline bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2)165 { 166 if ( Synchronisable::getSynchronisable(objectID)!= 0)164 virtual inline bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2) override 165 { 166 if ( Synchronisable::getSynchronisable(objectID)!=nullptr ) 167 167 { 168 168 (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1, mt2); … … 172 172 return false; 173 173 } 174 inline bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)175 { 176 if ( Synchronisable::getSynchronisable(objectID)!= 0)174 virtual inline bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3) override 175 { 176 if ( Synchronisable::getSynchronisable(objectID)!=nullptr ) 177 177 { 178 178 (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1, mt2, mt3); … … 182 182 return false; 183 183 } 184 inline bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)185 { 186 if ( Synchronisable::getSynchronisable(objectID)!= 0)184 virtual inline bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4) override 185 { 186 if ( Synchronisable::getSynchronisable(objectID)!=nullptr ) 187 187 { 188 188 (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1, mt2, mt3, mt4); … … 192 192 return false; 193 193 } 194 inline bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)195 { 196 if ( Synchronisable::getSynchronisable(objectID)!= 0)194 virtual inline bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5) override 195 { 196 if ( Synchronisable::getSynchronisable(objectID)!=nullptr ) 197 197 { 198 198 (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1, mt2, mt3, mt4, mt5); -
code/trunk/src/libraries/network/NetworkFunctionIncludes.h
r11052 r11071 33 33 34 34 #include <boost/preprocessor/cat.hpp> 35 #include <boost/static_assert.hpp>36 35 37 36 #include "NetworkFunction.h" … … 57 56 ~StaticallyInitializedNetworkFunction() { delete function_; } 58 57 59 virtual void load() ;60 virtual void unload() ;58 virtual void load() override; 59 virtual void unload() override; 61 60 62 61 inline NetworkFunctionBase& getFunction() … … 72 71 inline NetworkFunctionBase* registerStaticNetworkFunctionFct(PT ptr, const std::string& name) 73 72 { 74 BOOST_STATIC_ASSERT(sizeof(PT) <= sizeof(NetworkFunctionPointer)); // if this fails your compiler uses bigger pointers for static functions than defined above73 static_assert(sizeof(PT) <= sizeof(NetworkFunctionPointer), "check pointer size"); // if this fails your compiler uses bigger pointers for static functions than defined above 75 74 NetworkFunctionPointer destptr; 76 75 copyPtr(ptr, destptr); … … 81 80 inline NetworkFunctionBase* registerMemberNetworkFunctionFct(PT ptr, const std::string& name) 82 81 { 83 BOOST_STATIC_ASSERT(sizeof(PT) <= sizeof(NetworkFunctionPointer)); // if this fails your compiler uses bigger pointers for a specific kind of member functions than defined above82 static_assert(sizeof(PT) <= sizeof(NetworkFunctionPointer), "check pointer size"); // if this fails your compiler uses bigger pointers for a specific kind of member functions than defined above 84 83 NetworkFunctionPointer destptr; 85 84 copyPtr(ptr, destptr); -
code/trunk/src/libraries/network/NetworkFunctionManager.cc
r11052 r11071 32 32 namespace orxonox 33 33 { 34 NetworkFunctionManager* NetworkFunctionManager::singletonPtr_s = 0;34 NetworkFunctionManager* NetworkFunctionManager::singletonPtr_s = nullptr; 35 35 36 36 void NetworkFunctionManager::registerFunction(NetworkFunctionBase* function) … … 71 71 return it->second; 72 72 else 73 return NULL;73 return nullptr; 74 74 } 75 75 -
code/trunk/src/libraries/network/NetworkPrereqs.h
r10624 r11071 67 67 namespace orxonox 68 68 { 69 static const unsigned int GAMESTATEID_INITIAL = static_cast<unsigned int>(-1);69 static constexpr unsigned int GAMESTATEID_INITIAL = static_cast<unsigned int>(-1); 70 70 extern const char* LAN_DISCOVERY_MESSAGE; 71 71 extern const char* LAN_DISCOVERY_ACK; 72 static const unsigned int LAN_DISCOVERY_PORT = 55558;73 static const unsigned int NETWORK_PEER_ID_SERVER = 0;74 static const unsigned int NETWORK_PEER_ID_BROADCAST = static_cast<unsigned int>(-1);75 static const unsigned int NETWORK_PEER_ID_UNKNOWN = static_cast<unsigned int>(-2);76 static const unsigned int NETWORK_CHANNEL_DEFAULT = 0;77 static const unsigned int NETWORK_CHANNEL_UNRELIABLE = 1;78 static const unsigned int NETWORK_CHANNEL_COUNT = 2;72 static constexpr unsigned int LAN_DISCOVERY_PORT = 55558; 73 static constexpr unsigned int NETWORK_PEER_ID_SERVER = 0; 74 static constexpr unsigned int NETWORK_PEER_ID_BROADCAST = static_cast<unsigned int>(-1); 75 static constexpr unsigned int NETWORK_PEER_ID_UNKNOWN = static_cast<unsigned int>(-2); 76 static constexpr unsigned int NETWORK_CHANNEL_DEFAULT = 0; 77 static constexpr unsigned int NETWORK_CHANNEL_UNRELIABLE = 1; 78 static constexpr unsigned int NETWORK_CHANNEL_COUNT = 2; 79 79 } 80 80 … … 89 89 namespace PacketFlag 90 90 { 91 enum Value 92 { 93 Reliable = 1, 94 Unsequenced = 2, 95 NoAllocate = 4 96 }; 91 static constexpr uint32_t Reliable = 1; 92 static constexpr uint32_t Unsequenced = 2; 93 static constexpr uint32_t NoAllocate = 4; 97 94 } 98 95 } … … 101 98 { 102 99 typedef int Type; 103 static const Type NETWORK_FUNCTION = 6;100 static constexpr Type NETWORK_FUNCTION = 6; 104 101 } 105 102 } -
code/trunk/src/libraries/network/NetworkStaticInitializationHandler.h
r10624 r11071 39 39 { 40 40 public: 41 virtual void setupHandler() ;42 virtual void shutdownHandler() ;41 virtual void setupHandler() override; 42 virtual void shutdownHandler() override; 43 43 44 virtual void loadModule(ModuleInstance* module) ;45 virtual void unloadModule(ModuleInstance* module) ;44 virtual void loadModule(ModuleInstance* module) override; 45 virtual void unloadModule(ModuleInstance* module) override; 46 46 }; 47 47 } -
code/trunk/src/libraries/network/PeerList.cc
r10622 r11071 41 41 PeerList::addPeer( ENetPeer *toadd ) 42 42 { /* error correction */ 43 if( toadd == NULL)43 if( toadd == nullptr ) 44 44 { orxout(internal_error, context::master_server) << "PeerList::addPeer: empty peer given." << endl; 45 45 return -1; … … 65 65 bool 66 66 PeerList::remPeerByAddr( ENetAddress addr ) 67 { /* get an iterator */ 68 std::list<ENetPeer *>::iterator i; 69 67 { 70 68 /* loop through list elements */ 71 for( i = peerlist.begin(); i != peerlist.end(); ++i)72 if( !sub_compAddr( (*i)->address, addr ) )69 for( ENetPeer* peer : peerlist ) 70 if( !sub_compAddr(peer->address, addr ) ) 73 71 { /* found this name, remove and quit */ 74 this->peerlist.remove( *i);72 this->peerlist.remove( peer ); 75 73 return true; 76 74 } … … 82 80 ENetPeer * 83 81 PeerList::findPeerByAddr( ENetAddress addr ) 84 { /* get an iterator */ 85 std::list<ENetPeer *>::iterator i; 86 82 { 87 83 /* loop through list elements */ 88 for( i = peerlist.begin(); i != peerlist.end(); ++i)89 if( !sub_compAddr( (*i)->address, addr ) )84 for( ENetPeer* peer : peerlist ) 85 if( !sub_compAddr(peer->address, addr ) ) 90 86 /* found this name, remove and quit */ 91 return *i;87 return peer; 92 88 93 89 /* not found */ 94 return NULL;90 return nullptr; 95 91 } 96 92 -
code/trunk/src/libraries/network/Server.cc
r10622 r11071 194 194 void Server::printRTT() 195 195 { 196 // for( ClientInformation* temp=ClientInformation::getBegin(); temp!= 0; temp=temp->next() )196 // for( ClientInformation* temp=ClientInformation::getBegin(); temp!=nullptr; temp=temp->next() ) 197 197 // orxout(message) << "Round trip time to client with ID: " << temp->getID() << " is " << temp->getRTT() << " ms" << endl; 198 198 } … … 232 232 { 233 233 std::vector<packet::Gamestate*> gamestates = GamestateManager::getGamestates(); 234 std::vector<packet::Gamestate*>::iterator it; 235 for( it = gamestates.begin(); it != gamestates.end(); ++it ) 234 for( packet::Gamestate* gamestate : gamestates ) 236 235 { 237 (*it)->send(static_cast<Host*>(this));236 gamestate->send(static_cast<Host*>(this)); 238 237 } 239 238 return true; … … 244 243 { 245 244 // ClientInformation *temp = ClientInformation::getBegin(); 246 // if( temp == NULL)245 // if( temp == nullptr ) 247 246 //no client connected 248 247 if( this->clientIDs_.size()==0 ) … … 255 254 } 256 255 // orxout(verbose, context::network) << "sending DeleteObjects" << endl; 257 // while(temp != NULL){256 // while(temp != nullptr){ 258 257 // if( !(temp->getSynched()) ) 259 258 // { … … 434 433 return true; 435 434 436 std::vector<uint32_t>::iterator it; 437 for( it=this->clientIDs_.begin(); it!=this->clientIDs_.end(); ++it ) 438 if( *it == targetID ) 435 for( uint32_t id : this->clientIDs_ ) 436 if( id == targetID ) 439 437 return true; 440 438 -
code/trunk/src/libraries/network/Server.h
r10622 r11071 61 61 void open(); 62 62 void close(); 63 v oid queuePacket(ENetPacket *packet, int clientID, uint8_t channelID);64 virtual bool sendPacket( packet::Packet* packet ) { return packet->send( static_cast<Host*>(this) ); }63 virtual void queuePacket(ENetPacket *packet, int clientID, uint8_t channelID) override; 64 virtual bool sendPacket( packet::Packet* packet ) override{ return packet->send( static_cast<Host*>(this) ); } 65 65 void update(const Clock& time); 66 66 unsigned int getRTT(unsigned int clientID); 67 virtual void printRTT() ;67 virtual void printRTT() override; 68 68 float getPacketLoss(unsigned int clientID); 69 69 int getClientCount() { return this->clientIDs_.size();} … … 73 73 void updateGamestate(); 74 74 private: 75 virtual bool isServer_() {return true;}75 virtual bool isServer_() override{return true;} 76 76 unsigned int playerID(){return 0;} 77 77 78 v oid addPeer(uint32_t peerID);79 v oid removePeer(uint32_t peerID);80 v oid processPacket(packet::Packet* packet);78 virtual void addPeer(uint32_t peerID) override; 79 virtual void removePeer(uint32_t peerID) override; 80 virtual void processPacket(packet::Packet* packet) override; 81 81 82 82 bool createClient(int clientID); … … 85 85 bool sendObjectDeletes(); 86 86 bool isValidTarget(unsigned int targetID); 87 virtual void doSendChat(const std::string& message, unsigned int sourceID, unsigned int targetID) ;88 virtual void doReceiveChat(const std::string& message, unsigned int sourceID, unsigned int targetID) ;87 virtual void doSendChat(const std::string& message, unsigned int sourceID, unsigned int targetID) override; 88 virtual void doReceiveChat(const std::string& message, unsigned int sourceID, unsigned int targetID) override; 89 89 void syncClassid(unsigned int clientID); 90 90 -
code/trunk/src/libraries/network/ServerConnection.cc
r8858 r11071 73 73 this->host_ = enet_host_create(this->bindAddress_, NETWORK_MAX_CONNECTIONS, NETWORK_CHANNEL_COUNT, 0, 0); 74 74 75 if ( this->host_ == NULL)75 if ( this->host_ == nullptr ) 76 76 { 77 orxout(internal_error, context::network) << "ServerConnection: host_ == NULL" << endl;77 orxout(internal_error, context::network) << "ServerConnection: host_ == nullptr" << endl; 78 78 return false; 79 79 } -
code/trunk/src/libraries/network/TrafficControl.cc
r9667 r11071 30 30 31 31 #include <cassert> 32 #include < boost/bind.hpp>32 #include <functional> 33 33 34 34 #include "core/CoreIncludes.h" … … 38 38 namespace orxonox { 39 39 40 static const unsigned int SCHED_PRIORITY_OFFSET = static_cast<unsigned int>(-1); 40 static constexpr unsigned int SCHED_PRIORITY_OFFSET = static_cast<unsigned int>(-1); 41 namespace arg = std::placeholders; 41 42 42 43 objInfo::objInfo(uint32_t ID, uint32_t creatorID, int32_t curGsID, int32_t diffGsID, uint32_t size, unsigned int prioperm, unsigned int priosched) … … 64 65 *Initializing protected members 65 66 */ 66 TrafficControl *TrafficControl::instance_= 0;67 TrafficControl *TrafficControl::instance_=nullptr; 67 68 68 69 /** … … 72 73 { 73 74 RegisterObject(TrafficControl); 74 assert(instance_== 0);75 assert(instance_==nullptr); 75 76 instance_=this; 76 77 this->setConfigValues(); … … 78 79 79 80 /** 80 * @brief Destructor: resets the instance pointer to 081 * @brief Destructor: resets the instance pointer to nullptr 81 82 */ 82 83 TrafficControl::~TrafficControl() 83 84 { 84 instance_= 0;85 instance_=nullptr; 85 86 } 86 87 … … 148 149 // shortcut for maps 149 150 std::map<unsigned int, objInfo >& objectListPerm = clientListPerm_[clientID]; 150 std::map<unsigned int, std::list<obj> 151 std::map<unsigned int, std::list<obj>>& objectListTemp = clientListTemp_[clientID]; 151 152 152 153 for(itvec = objectListTemp[gamestateID].begin(); itvec != objectListTemp[gamestateID].end(); itvec++) … … 180 181 void TrafficControl::insertinClientListPerm(unsigned int clientID, obj objinf) 181 182 { 182 std::map<unsigned int,std::map<unsigned int, objInfo> 183 std::map<unsigned int,std::map<unsigned int, objInfo>>::iterator itperm;//iterator clientListPerm over clientIDs 183 184 unsigned int gsid=GAMESTATEID_INITIAL, gsdiff=currentGamestateID, prioperm=Synchronisable::getSynchronisable(objinf.objID)->getPriority(), priomom=0; 184 185 clientListPerm_[clientID][objinf.objID] = objInfo(objinf.objID, objinf.objCreatorID,gsid,gsdiff, objinf.objSize,prioperm,priomom); … … 258 259 259 260 //sort copied list according to priorities 260 // use boostbind here because we need to pass a memberfunction to stl sort261 // sort( list.begin(), list.end(), boost::bind(&TrafficControl::prioritySort, this, clientID, _1,_2) );262 list.sort( boost::bind(&TrafficControl::prioritySort, this, clientID, _1,_2) );263 264 // list.sort( boost::bind(&TrafficControl::prioritySort, this, clientID, _1,_2) );261 // use std::bind here because we need to pass a memberfunction to stl sort 262 // sort( list.begin(), list.end(), std::bind(&TrafficControl::prioritySort, this, clientID, arg::_1, arg::_2) ); 263 list.sort( std::bind(&TrafficControl::prioritySort, this, clientID, arg::_1, arg::_2) ); 264 265 // list.sort(std::bind(&TrafficControl::prioritySort, this, clientID, arg::_1, arg::_2) ); 265 266 266 267 //now we check, that the creator of an object always exists on a client … … 275 276 cut(list, targetSize); 276 277 //now sort again after objDataOffset 277 // sort(list.begin(), list.end(), boost::bind(&TrafficControl::dataSort, this, _1,_2) );278 list.sort( boost::bind(&TrafficControl::dataSort, this, _1,_2) );278 // sort(list.begin(), list.end(), std::bind(&TrafficControl::dataSort, this, arg::_1, arg::_2) ); 279 list.sort( std::bind(&TrafficControl::dataSort, this, arg::_1, arg::_2) ); 279 280 280 281 //diese Funktion updateClientList muss noch gemacht werden -
code/trunk/src/libraries/network/TrafficControl.h
r6746 r11071 82 82 *permanent client list: contains client ids, object ids and objectInfos (in this order) 83 83 */ 84 std::map<unsigned int, std::map<unsigned int, objInfo > 84 std::map<unsigned int, std::map<unsigned int, objInfo >> clientListPerm_; 85 85 //has to be created with constructor and then needs to be updated by evaluateList(). 86 86 … … 88 88 *temporary client list: contains client ids, gamestate ids and object ids (in this order) 89 89 */ 90 std::map<unsigned int, std::map<unsigned int, std::list<obj> >> clientListTemp_;90 std::map<unsigned int, std::map<unsigned int, std::list<obj>>> clientListTemp_; 91 91 92 92 /**updateReferenceList … … 109 109 110 110 //ClientConnectionListener functions 111 virtual void clientConnected(unsigned int clientID) {};112 virtual void clientDisconnected(unsigned int clientID) ;111 virtual void clientConnected(unsigned int clientID) override{}; 112 virtual void clientDisconnected(unsigned int clientID) override; 113 113 114 114 -
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: -
code/trunk/src/libraries/network/synchronisable/NetworkCallback.h
r6417 r11071 53 53 NetworkCallback(T* object, void (T::*function) (void)) : object_(object), function_(function) {} 54 54 virtual ~NetworkCallback() {} 55 virtual void call() 55 virtual void call() override 56 56 { (this->object_->*function_)(); } 57 57 … … 68 68 NetworkCallbackNotify() {} 69 69 virtual ~NetworkCallbackNotify() {} 70 virtual void call() 70 virtual void call() override 71 71 { (this->object_->*function_)( this->oldValue_ ); } 72 72 void setOldValue(const U& value){ this->oldValue_ = value; } -
code/trunk/src/libraries/network/synchronisable/Serialise.h
r10624 r11071 90 90 { 91 91 // *const_cast<typename Loki::TypeTraits<T*>::UnqualifiedType*>(&variable) = dynamic_cast<T*>(variable->getSynchronisable( *(uint32_t*)(mem) )); 92 *const_cast<typename Loki::TypeTraits<StrongPtr<T> 92 *const_cast<typename Loki::TypeTraits<StrongPtr<T>>::UnqualifiedType*>(&variable) = orxonox_cast<T*>(T::getSynchronisable(*(uint32_t*)(mem))); 93 93 mem += returnSize( variable ); 94 94 } … … 125 125 { 126 126 // *const_cast<typename Loki::TypeTraits<T*>::UnqualifiedType*>(&variable) = dynamic_cast<T*>(variable->getSynchronisable( *(uint32_t*)(mem) )); 127 *const_cast<typename Loki::TypeTraits<WeakPtr<T> 127 *const_cast<typename Loki::TypeTraits<WeakPtr<T>>::UnqualifiedType*>(&variable) = orxonox_cast<T*>(T::getSynchronisable(*(uint32_t*)(mem))); 128 128 mem += returnSize( variable ); 129 129 } -
code/trunk/src/libraries/network/synchronisable/Synchronisable.cc
r10624 r11071 88 88 } 89 89 // delete all Synchronisable Variables from syncList_ ( which are also in stringList_ ) 90 for( std::vector<SynchronisableVariableBase*>::iterator it = syncList_.begin(); it!=syncList_.end(); it++)91 delete (*it);90 for(SynchronisableVariableBase* variable : syncList_) 91 delete variable; 92 92 syncList_.clear(); 93 93 stringList_.clear(); … … 105 105 uint32_t Synchronisable::findContextID(Context* context) 106 106 { 107 if (context == NULL)107 if (context == nullptr) 108 108 return OBJECTID_UNKNOWN; 109 109 110 110 Synchronisable* synchronisableContext = orxonox_cast<Synchronisable*>(context); 111 if (synchronisableContext != NULL)111 if (synchronisableContext != nullptr) 112 112 return synchronisableContext->getObjectID(); 113 113 else … … 140 140 { 141 141 mem += header.getDataSize() + header.getSize(); 142 return 0;142 return nullptr; 143 143 } 144 144 // assert( !header.isDiffed() ); … … 156 156 } 157 157 assert(id); 158 Context* context = 0;158 Context* context = nullptr; 159 159 if (header.getContextID() != OBJECTID_UNKNOWN) 160 160 { … … 164 164 mem += header.getDataSize()+SynchronisableHeader::getSize(); //.TODO: this suckz.... remove size from header 165 165 assert(0); // TODO: uncomment this if we have a clean objecthierarchy (with destruction of children of objects) ^^ 166 return 0;166 return nullptr; 167 167 } 168 168 else … … 172 172 context = Context::getRootContext(); 173 173 174 assert(getSynchronisable(header.getObjectID())== 0); //make sure no object with this id exists174 assert(getSynchronisable(header.getObjectID())==nullptr); //make sure no object with this id exists 175 175 BaseObject *bo = orxonox_cast<BaseObject*>(id->fabricate(context)); 176 176 assert(bo); … … 226 226 return it1->second; 227 227 // if the objects not in the map it should'nt exist at all anymore 228 return NULL;228 return nullptr; 229 229 } 230 230 … … 266 266 assert(this->classID_==this->getIdentifier()->getNetworkID()); 267 267 assert(this->objectID_!=OBJECTID_UNKNOWN); 268 std::vector<SynchronisableVariableBase*>::iterator i;269 268 270 269 // start copy header … … 276 275 // orxout(verbose, context::network) << "objectid: " << this->objectID_ << ":"; 277 276 // copy to location 278 for( i=syncList_.begin(); i!=syncList_.end(); ++i)279 { 280 uint32_t varsize = (*i)->getData( mem, mode );277 for(SynchronisableVariableBase* variable : syncList_) 278 { 279 uint32_t varsize = variable->getData( mem, mode ); 281 280 // orxout(verbose, context::network) << " " << varsize; 282 281 tempsize += varsize; … … 348 347 assert( this->getContextID() == syncHeader2.getContextID() ); 349 348 mem += SynchronisableHeader::getSize(); 350 std::vector<SynchronisableVariableBase *>::iterator i; 351 for(i=syncList_.begin(); i!=syncList_.end(); ++i) 349 for(SynchronisableVariableBase* variable : syncList_) 352 350 { 353 351 assert( mem <= data+syncHeader2.getDataSize()+SynchronisableHeader::getSize() ); // always make sure we don't exceed the datasize in our stream 354 (*i)->putData( mem, mode, forceCallback );352 variable->putData( mem, mode, forceCallback ); 355 353 } 356 354 assert(mem == data+syncHeaderLight.getDataSize()+SynchronisableHeader::getSize() ); … … 388 386 assert( mode==state_ ); 389 387 tsize += this->dataSize_; 390 std::vector<SynchronisableVariableBase*>::iterator i; 391 for(i=stringList_.begin(); i!=stringList_.end(); ++i) 392 { 393 tsize += (*i)->getSize( mode ); 388 for(SynchronisableVariableBase* variable : stringList_) 389 { 390 tsize += variable->getSize( mode ); 394 391 } 395 392 return tsize; -
code/trunk/src/libraries/network/synchronisable/Synchronisable.h
r9667 r11071 38 38 #include <queue> 39 39 #include <set> 40 #include <type_traits> 40 41 41 42 #include "util/mbool.h" … … 171 172 protected: 172 173 Synchronisable(Context* context); 173 template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb= 0, bool bidirectional=false);174 template <class T> void registerVariable(std::set<T>& variable, uint8_t mode=0x1, NetworkCallbackBase *cb= 0, bool bidirectional=false);174 template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=nullptr, bool bidirectional=false); 175 template <class T> void registerVariable(std::set<T>& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=nullptr, bool bidirectional=false); 175 176 template <class T> void unregisterVariable(T& var); 176 177 … … 203 204 }; 204 205 205 template <class T> void Synchronisable::registerVariable(T& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional) 206 { 206 namespace detail 207 { 208 template <class T, bool = std::is_enum<T>::value> 209 struct UnderlyingType; 210 template <class T> 211 struct UnderlyingType<T, true> { typedef typename std::underlying_type<T>::type type; }; 212 template <class T> 213 struct UnderlyingType<T, false> { typedef T type; }; 214 } 215 216 template <class T> 217 void Synchronisable::registerVariable(T& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional) 218 { 219 typedef typename detail::UnderlyingType<T>::type UnderlyingType; 207 220 if (bidirectional) 208 221 { 209 syncList_.push_back(new SynchronisableVariableBidirectional< T>(variable, mode, cb));222 syncList_.push_back(new SynchronisableVariableBidirectional<UnderlyingType>(reinterpret_cast<UnderlyingType&>(variable), mode, cb)); 210 223 this->dataSize_ += syncList_.back()->getSize(state_); 211 224 } 212 225 else 213 226 { 214 syncList_.push_back(new SynchronisableVariable< T>(variable, mode, cb));227 syncList_.push_back(new SynchronisableVariable<UnderlyingType>(reinterpret_cast<UnderlyingType&>(variable), mode, cb)); 215 228 if ( this->state_ == mode ) 216 229 this->dataSize_ += syncList_.back()->getSize(state_); … … 218 231 } 219 232 220 template <class T> void Synchronisable::unregisterVariable(T& variable) 233 template <class T> 234 void Synchronisable::unregisterVariable(T& variable) 221 235 { 222 236 std::vector<SynchronisableVariableBase*>::iterator it = syncList_.begin(); … … 238 252 } 239 253 240 template <class T> void Synchronisable::registerVariable( std::set<T>& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional) 241 { 254 template <class T> 255 void Synchronisable::registerVariable( std::set<T>& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional) 256 { 257 typedef typename detail::UnderlyingType<T>::type UnderlyingType; 242 258 SynchronisableVariableBase* sv; 243 259 if (bidirectional) 244 sv = new SynchronisableVariableBidirectional<std::set< T> >(variable, mode, cb);260 sv = new SynchronisableVariableBidirectional<std::set<UnderlyingType>>(reinterpret_cast<std::set<UnderlyingType>&>(variable), mode, cb); 245 261 else 246 sv = new SynchronisableVariable<std::set< T> >(variable, mode, cb);262 sv = new SynchronisableVariable<std::set<UnderlyingType>>(reinterpret_cast<std::set<UnderlyingType>&>(variable), mode, cb); 247 263 syncList_.push_back(sv); 248 264 stringList_.push_back(sv); … … 250 266 251 267 template <> _NetworkExport void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional); 252 // template <class T> _NetworkExport void Synchronisable::registerVariable<std::set<T> 268 // template <class T> _NetworkExport void Synchronisable::registerVariable<std::set<T>>( std::set<T>& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional); 253 269 template <> _NetworkExport void Synchronisable::unregisterVariable( std::string& variable ); 254 270 -
code/trunk/src/libraries/network/synchronisable/SynchronisableVariable.h
r10624 r11071 71 71 { 72 72 public: 73 SynchronisableVariable(T& variable, uint8_t syncDirection=VariableDirection::ToClient, NetworkCallbackBase *cb= 0);73 SynchronisableVariable(T& variable, uint8_t syncDirection=VariableDirection::ToClient, NetworkCallbackBase *cb=nullptr); 74 74 virtual ~SynchronisableVariable(); 75 75 76 virtual inline uint8_t getMode() { return mode_; }77 virtual inline uint32_t getData(uint8_t*& mem, uint8_t mode) ;78 virtual inline void putData(uint8_t*& mem, uint8_t mode, bool forceCallback = false) ;79 virtual inline uint32_t getSize(uint8_t mode) ;80 virtual inline void* getReference() { return static_cast<void*>(const_cast<typename Loki::TypeTraits<T>::UnqualifiedType*>(&this->variable_)); }76 virtual inline uint8_t getMode() override{ return mode_; } 77 virtual inline uint32_t getData(uint8_t*& mem, uint8_t mode) override; 78 virtual inline void putData(uint8_t*& mem, uint8_t mode, bool forceCallback = false) override; 79 virtual inline uint32_t getSize(uint8_t mode) override; 80 virtual inline void* getReference() override{ return static_cast<void*>(const_cast<typename Loki::TypeTraits<T>::UnqualifiedType*>(&this->variable_)); } 81 81 protected: 82 82 T& variable_; … … 89 89 { 90 90 public: 91 SynchronisableVariableBidirectional(T& variable, uint8_t master=Bidirectionality::ServerMaster, NetworkCallbackBase *cb= 0);91 SynchronisableVariableBidirectional(T& variable, uint8_t master=Bidirectionality::ServerMaster, NetworkCallbackBase *cb=nullptr); 92 92 virtual ~SynchronisableVariableBidirectional(); 93 93
Note: See TracChangeset
for help on using the changeset viewer.