Changeset 10919 for code/branches/cpp11_v2/src/libraries/network
- Timestamp:
- Dec 5, 2015, 10:47:51 PM (9 years ago)
- Location:
- code/branches/cpp11_v2/src/libraries/network
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/cpp11_v2/src/libraries/network/Client.cc
r10624 r10919 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/branches/cpp11_v2/src/libraries/network/ClientConnectionListener.cc
r10624 r10919 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/branches/cpp11_v2/src/libraries/network/Connection.cc
r10768 r10919 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; -
code/branches/cpp11_v2/src/libraries/network/FunctionCallManager.cc
r10918 r10919 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(); -
code/branches/cpp11_v2/src/libraries/network/GamestateManager.cc
r10769 r10919 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 … … 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;185 int peerID = mapEntry.first; //get client id 186 187 unsigned int lastAckedGamestateID = mapEntry.second.lastAckedGamestateID; 192 188 193 189 packet::Gamestate* baseGamestate=nullptr; … … 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)); -
code/branches/cpp11_v2/src/libraries/network/Host.cc
r10916 r10919 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 -
code/branches/cpp11_v2/src/libraries/network/MasterServer.cc
r10765 r10919 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 */ -
code/branches/cpp11_v2/src/libraries/network/PeerList.cc
r10765 r10919 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 */ -
code/branches/cpp11_v2/src/libraries/network/Server.cc
r10768 r10919 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; … … 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/branches/cpp11_v2/src/libraries/network/packet/ClassID.cc
r10769 r10919 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; 57 for(const auto& mapEntry : IdentifierManager::getInstance().getIdentifierByStringMap()){ 58 id = mapEntry.second; 60 59 if(id == nullptr || !id->hasFactory()) 61 60 continue; -
code/branches/cpp11_v2/src/libraries/network/packet/Gamestate.cc
r10918 r10919 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 } … … 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/branches/cpp11_v2/src/libraries/network/packet/ServerInformation.h
r10857 r10919 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: -
code/branches/cpp11_v2/src/libraries/network/synchronisable/Synchronisable.cc
r10916 r10919 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;
Note: See TracChangeset
for help on using the changeset viewer.