Changeset 8327
- Timestamp:
- Apr 25, 2011, 8:22:36 PM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 4 deleted
- 38 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/network6 (added) merged: 7823-7825,7875,7878,7881-7882,7898,7900,7931,8315
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/core/Thread.cc
r7284 r8327 26 26 * 27 27 */ 28 29 #if defined(ORXONOX_PLATFORM_WINDOWS) 30 #include "ThreadWin.cc" 31 #elif defined(ORXONOX_PLATFORM_UNIX) 32 28 33 29 34 #include "Thread.h" … … 91 96 while( !stopThread ) 92 97 { 93 //this->executorMutex_->lock();98 this->executorMutex_->lock(); 94 99 ExecutorPtr executor = this->executor_; 95 //this->executorMutex_->unlock();100 this->executorMutex_->unlock(); 96 101 if( executor ) 97 102 { … … 108 113 this->workerThread_->yield(); 109 114 } 110 //this->stopThreadMutex_->lock();115 this->stopThreadMutex_->lock(); 111 116 stopThread = this->stopThread_; 112 //this->stopThreadMutex_->unlock();117 this->stopThreadMutex_->unlock(); 113 118 } 114 119 } … … 127 132 } 128 133 } 134 135 #endif -
code/trunk/src/libraries/network/CMakeLists.txt
r7801 r8327 22 22 Client.cc 23 23 ClientConnection.cc 24 ClientInformation.cc25 24 ClientConnectionListener.cc 26 25 Connection.cc … … 50 49 ClientConnection.h 51 50 ClientConnectionListener.h 52 ClientInformation.h53 51 Connection.h 54 52 FunctionCall.h -
code/trunk/src/libraries/network/Client.cc
r7801 r8327 155 155 COUT(4) << "popping partial gamestate: " << std::endl; 156 156 // packet::Gamestate *gs = GamestateClient::getGamestate(); 157 GamestateManager::update(); 158 std::vector<packet::Gamestate*> gamestates = GamestateManager::getGamestates(); 159 std::vector<packet::Gamestate*>::iterator it; 160 for( it = gamestates.begin(); it != gamestates.end(); ++it ) 157 if( GamestateManager::update() ) 161 158 { 162 (*it)->send( static_cast<Host*>(this) ); 159 std::vector<packet::Gamestate*> gamestates = GamestateManager::getGamestates(); 160 std::vector<packet::Gamestate*>::iterator it; 161 for( it = gamestates.begin(); it != gamestates.end(); ++it ) 162 { 163 (*it)->send( static_cast<Host*>(this) ); 164 } 163 165 } 164 166 //assert(gs); <--- there might be the case that no data has to be sent, so its commented out now … … 207 209 if( packet->isReliable() ) 208 210 { 209 if( this->getLast ProcessedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() )211 if( this->getLastReceivedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() ) 210 212 packet->process(static_cast<Host*>(this)); 211 213 else -
code/trunk/src/libraries/network/ClientConnection.cc
r7801 r8327 42 42 43 43 ClientConnection::ClientConnection(): 44 Connection(NETWORK_PEER_ID_SERVER), 44 45 established_(false), 45 46 server_(NULL) … … 103 104 if( enet_host_service(this->host_, &event, NETWORK_CLIENT_WAIT_TIME)>=0 && event.type == ENET_EVENT_TYPE_CONNECT ) 104 105 { 106 // manually add server to list of peers 107 /*incomingEvent inEvent = */Connection::preprocessConnectEvent(event); 108 // addPeer(inEvent.peerID); 109 // start communication thread 105 110 this->established_=true; 106 111 Connection::startCommunicationThread(); … … 118 123 return true; 119 124 this->established_ = false; 125 126 // stop communication thread and disconnect server 120 127 Connection::stopCommunicationThread(); 121 128 enet_peer_disconnect(this->server_, 0); … … 148 155 assert( this->server_ ); 149 156 assert( packet ); 150 return Connection::addPacket( packet, this->server_, channelID ); 157 // return Connection::addPacket( packet, NETWORK_PEER_ID_SERVER, channelID ); 158 // HACK: actually there should be a way to do this using addPacket and the correct peerID 159 return Connection::broadcastPacket(packet, channelID); 151 160 } 152 161 153 void ClientConnection::addPeer( ENetEvent* event)162 void ClientConnection::addPeer(uint32_t peerID) 154 163 { 155 164 assert(0); 156 165 } 157 void ClientConnection::removePeer( ENetEvent* event)166 void ClientConnection::removePeer(uint32_t peerID) 158 167 { 159 168 this->established_=false; -
code/trunk/src/libraries/network/ClientConnection.h
r7801 r8327 57 57 uint32_t getRTT(); 58 58 private: 59 virtual void addPeer( ENetEvent* event);60 virtual void removePeer( ENetEvent* event);59 virtual void addPeer(uint32_t peerID); 60 virtual void removePeer(uint32_t peerID); 61 61 62 62 bool disconnectConnection(); -
code/trunk/src/libraries/network/ClientConnectionListener.cc
r6417 r8327 31 31 #include "core/CoreIncludes.h" 32 32 #include "core/GameMode.h" 33 #include "ClientInformation.h"33 // #include "ClientInformation.h" 34 34 35 35 namespace orxonox … … 52 52 } 53 53 54 void ClientConnectionListener::getConnectedClients()55 {56 ClientInformation* client = ClientInformation::getBegin();57 while (client)58 {59 this->clientConnected(client->getID());60 client = client->next();61 }62 }54 // void ClientConnectionListener::getConnectedClients() 55 // { 56 // ClientInformation* client = ClientInformation::getBegin(); 57 // while (client) 58 // { 59 // this->clientConnected(client->getID()); 60 // client = client->next(); 61 // } 62 // } 63 63 } 64 64 -
code/trunk/src/libraries/network/ClientConnectionListener.h
r6417 r8327 48 48 49 49 protected: 50 void getConnectedClients();50 // void getConnectedClients(); 51 51 }; 52 52 } -
code/trunk/src/libraries/network/Connection.cc
r7801 r8327 38 38 39 39 #include "packet/Packet.h" 40 #include <util/Sleep.h> 40 41 41 42 namespace orxonox 42 43 { 43 const boost::posix_time::millisec NETWORK_COMMUNICATION_THREAD_WAIT_TIME(20); 44 45 Connection::Connection(): 46 host_(0), bCommunicationThreadRunning_(false) 44 const boost::posix_time::millisec NETWORK_COMMUNICATION_THREAD_WAIT_TIME(200); 45 const unsigned int NETWORK_DISCONNECT_TIMEOUT = 500; 46 47 Connection::Connection(uint32_t firstPeerID): 48 host_(0), bCommunicationThreadRunning_(false), nextPeerID_(firstPeerID) 47 49 { 48 50 enet_initialize(); … … 50 52 this->incomingEventsMutex_ = new boost::mutex; 51 53 this->outgoingEventsMutex_ = new boost::mutex; 54 // this->overallMutex_ = new boost::mutex; 52 55 } 53 56 … … 75 78 } 76 79 77 78 // int Connection::service(ENetEvent* event) { 79 // return enet_host_service( this->host_, event, NETWORK_WAIT_TIMEOUT ); 80 // } 81 82 void Connection::disconnectPeer(ENetPeer *peer) 83 { 84 assert(peer); 85 outgoingEvent outEvent = { peer, outgoingEventType::disconnectPeer, (ENetPacket*)10, 15 }; 80 void Connection::disconnectPeer(uint32_t peerID) 81 { 82 // this->overallMutex_->lock(); 83 outgoingEvent outEvent = { peerID, outgoingEventType::disconnectPeer, 0, 0 }; 86 84 87 85 this->outgoingEventsMutex_->lock(); 88 86 this->outgoingEvents_.push_back(outEvent); 89 87 this->outgoingEventsMutex_->unlock(); 90 } 91 92 void Connection::addPacket(ENetPacket *packet, ENetPeer *peer, uint8_t channelID)93 {94 assert(peer);95 outgoingEvent outEvent = { peer, outgoingEventType::sendPacket, packet, channelID};88 // this->overallMutex_->unlock(); 89 } 90 91 void Connection::disconnectPeers() 92 { 93 outgoingEvent outEvent = { 0, outgoingEventType::disconnectPeers, 0, 0 }; 96 94 97 95 this->outgoingEventsMutex_->lock(); … … 99 97 this->outgoingEventsMutex_->unlock(); 100 98 } 99 100 void Connection::addPacket(ENetPacket* packet, uint32_t peerID, uint8_t channelID) 101 { 102 // this->overallMutex_->lock(); 103 outgoingEvent outEvent = { peerID, outgoingEventType::sendPacket, packet, channelID }; 104 105 this->outgoingEventsMutex_->lock(); 106 this->outgoingEvents_.push_back(outEvent); 107 this->outgoingEventsMutex_->unlock(); 108 // this->overallMutex_->unlock(); 109 } 101 110 102 111 void Connection::broadcastPacket(ENetPacket* packet, uint8_t channelID) 103 112 { 104 outgoingEvent outEvent = { (ENetPeer*)15, outgoingEventType::broadcastPacket, packet, channelID }; 113 // this->overallMutex_->lock(); 114 outgoingEvent outEvent = { 0, outgoingEventType::broadcastPacket, packet, channelID }; 105 115 106 116 this->outgoingEventsMutex_->lock(); 107 117 this->outgoingEvents_.push_back(outEvent); 108 118 this->outgoingEventsMutex_->unlock(); 119 // this->overallMutex_->unlock(); 109 120 } 110 121 … … 114 125 ENetEvent event; 115 126 127 // this->overallMutex_->lock(); 116 128 while( bCommunicationThreadRunning_ ) 117 129 { … … 119 131 while( enet_host_check_events( this->host_, &event ) > 0 ) 120 132 { 121 // COUT(0) << "incoming event" << endl;122 // received an event123 this->incomingEventsMutex_->lock();124 this->incomingEvents_.push_back(event);125 this->incomingEventsMutex_->unlock();126 } 133 processIncomingEvent(event); 134 } 135 136 // this->overallMutex_->unlock(); 137 msleep(1); 138 // this->overallMutex_->lock(); 127 139 128 140 // Send all waiting outgoing packets … … 138 150 this->outgoingEventsMutex_->unlock(); 139 151 140 switch( outEvent.type ) 141 { 142 case outgoingEventType::sendPacket: 143 enet_peer_send( outEvent.peer, outEvent.channelID, outEvent.packet ); 144 break; 145 case outgoingEventType::disconnectPeer: 146 enet_peer_disconnect(outEvent.peer, 0); 147 break; 148 case outgoingEventType::broadcastPacket: 149 enet_host_broadcast( this->host_, outEvent.channelID, outEvent.packet ); 150 break; 151 default: 152 assert(0); 153 } 152 processOutgoingEvent(outEvent); 153 154 154 this->outgoingEventsMutex_->lock(); 155 155 outgoingEventsCount = this->outgoingEvents_.size(); … … 160 160 if( enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 ) 161 161 { 162 // COUT(0) << "incoming event after wait" << endl; 163 //received an event 164 this->incomingEventsMutex_->lock(); 165 this->incomingEvents_.push_back(event); 166 this->incomingEventsMutex_->unlock(); 162 processIncomingEvent(event); 163 } 164 } 165 // this->overallMutex_->unlock(); 166 } 167 168 void Connection::processIncomingEvent(ENetEvent& event) 169 { 170 incomingEvent inEvent; 171 // preprocess event 172 switch( event.type ) 173 { 174 case ENET_EVENT_TYPE_CONNECT: 175 inEvent = preprocessConnectEvent(event); 176 break; 177 case ENET_EVENT_TYPE_RECEIVE: 178 inEvent = preprocessReceiveEvent(event); 179 break; 180 case ENET_EVENT_TYPE_DISCONNECT: 181 inEvent = preprocessDisconnectEvent(event); 182 break; 183 case ENET_EVENT_TYPE_NONE: 184 default: 185 return; 186 } 187 188 // pushing event to queue 189 this->incomingEventsMutex_->lock(); 190 this->incomingEvents_.push_back(inEvent); 191 this->incomingEventsMutex_->unlock(); 192 } 193 194 void Connection::processOutgoingEvent(outgoingEvent& event) 195 { 196 ENetPeer* peer; 197 switch( event.type ) 198 { 199 case outgoingEventType::sendPacket: 200 // check whether the peer is still/already in the peer list 201 if( this->peerMap_.find(event.peerID) != this->peerMap_.end() ) 202 { 203 peer = this->peerMap_[event.peerID]; 204 enet_peer_send( peer, event.channelID, event.packet ); 205 } 206 else 207 { 208 // peer probably already disconnected so just discard packet 209 assert(event.peerID<this->nextPeerID_); 210 enet_packet_destroy(event.packet); 211 } 212 break; 213 case outgoingEventType::disconnectPeer: 214 if( this->peerMap_.find(event.peerID) != this->peerMap_.end() ) 215 { 216 peer = this->peerMap_[event.peerID]; 217 enet_peer_disconnect(peer, 0); 218 } 219 else 220 { 221 // peer probably already disconnected so just discard disconnect event 222 assert(event.peerID<this->nextPeerID_); 223 } 224 break; 225 case outgoingEventType::disconnectPeers: 226 disconnectPeersInternal(); 227 break; 228 case outgoingEventType::broadcastPacket: 229 enet_host_broadcast( this->host_, event.channelID, event.packet ); 230 break; 231 default: 232 assert(0); 233 } 234 } 235 236 237 void Connection::disconnectPeersInternal() 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); 243 } 244 uint32_t iterations = NETWORK_DISCONNECT_TIMEOUT/NETWORK_WAIT_TIMEOUT; 245 uint32_t i = 0; 246 while( this->peerMap_.size() && i++ < iterations ) 247 { 248 ENetEvent event; 249 if( enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 ) 250 { 251 processIncomingEvent(event); 167 252 } 168 253 } … … 171 256 void Connection::processQueue() 172 257 { 173 ENetEvent event;258 incomingEvent inEvent; 174 259 175 260 this->incomingEventsMutex_->lock(); … … 178 263 while( incomingEventsCount > 0 ) 179 264 { 180 packet::Packet* p;265 // pop event from queue 181 266 this->incomingEventsMutex_->lock(); 182 event = this->incomingEvents_.front();267 inEvent = this->incomingEvents_.front(); 183 268 this->incomingEvents_.pop_front(); 184 269 this->incomingEventsMutex_->unlock(); 185 270 186 switch(event.type)187 {188 // log handling ================189 case ENET_EVENT_TYPE_CONNECT:190 addPeer( &event);271 // process event 272 switch( inEvent.type ) 273 { 274 case incomingEventType::peerConnect: 275 addPeer(inEvent.peerID); 191 276 break; 192 case ENET_EVENT_TYPE_DISCONNECT:193 removePeer( &event);277 case incomingEventType::peerDisconnect: 278 removePeer(inEvent.peerID); 194 279 break; 195 case ENET_EVENT_TYPE_RECEIVE: 196 // COUT(0) << "ENET_EVENT_TYPE_RECEIVE" << endl; 197 p = createPacket( &event ); 198 processPacket(p); 280 case incomingEventType::receivePacket: 281 processPacket(inEvent.packet); 199 282 break; 200 case ENET_EVENT_TYPE_NONE:283 default: 201 284 break; 202 285 } 203 286 287 // check whether there are still events in the queue 204 288 this->incomingEventsMutex_->lock(); 205 289 incomingEventsCount = this->incomingEvents_.size(); … … 207 291 } 208 292 } 209 210 packet::Packet* Connection::createPacket(ENetEvent* event) 211 { 212 packet::Packet *p = packet::Packet::createPacket(event->packet, event->peer); 213 return p; 214 // return p->process(); 215 } 293 294 void Connection::waitOutgoingQueue() 295 { 296 uint32_t outgoingEventsCount; 297 this->outgoingEventsMutex_->lock(); 298 outgoingEventsCount = this->outgoingEvents_.size(); 299 this->outgoingEventsMutex_->unlock(); 300 while( outgoingEventsCount ) 301 { 302 msleep(1); 303 this->outgoingEventsMutex_->lock(); 304 outgoingEventsCount = this->outgoingEvents_.size(); 305 this->outgoingEventsMutex_->unlock(); 306 } 307 } 308 309 310 incomingEvent Connection::preprocessConnectEvent(ENetEvent& event) 311 { 312 // make sure this peer doesn't exist 313 assert( this->peerMap_.find(this->nextPeerID_) == this->peerMap_.end() ); 314 assert( this->peerIDMap_.find(event.peer) == this->peerIDMap_.end() ); 315 316 // give peer a new id and increase peerID for next peer 317 uint32_t peerID = this->nextPeerID_; 318 ++this->nextPeerID_; 319 320 // add peer/peerID into peerMap_ and peerIDMap_ 321 this->peerMap_[peerID] = event.peer; 322 this->peerIDMap_[event.peer] = peerID; 323 324 // create new peerEvent and return it 325 incomingEvent inEvent = { peerID, incomingEventType::peerConnect, 0 }; 326 return inEvent; 327 } 328 329 incomingEvent Connection::preprocessDisconnectEvent(ENetEvent& event) 330 { 331 // assert that the peer exists and get peerID 332 assert( this->peerIDMap_.find(event.peer) != this->peerIDMap_.end() ); 333 uint32_t peerID = this->peerIDMap_[event.peer]; 334 335 // remove peer/peerID from maps 336 this->peerIDMap_.erase(this->peerIDMap_.find(event.peer)); 337 this->peerMap_.erase(this->peerMap_.find(peerID)); 338 339 // create new peerEvent and return it 340 incomingEvent inEvent = { peerID, incomingEventType::peerDisconnect, 0 }; 341 return inEvent; 342 } 343 344 incomingEvent Connection::preprocessReceiveEvent(ENetEvent& event) 345 { 346 // assert that the peer exists and get peerID 347 assert( this->peerIDMap_.find(event.peer) != this->peerIDMap_.end() ); 348 uint32_t peerID = this->peerIDMap_[event.peer]; 349 350 // create new Packet from ENetPacket 351 packet::Packet* p = packet::Packet::createPacket(event.packet, peerID); 352 353 // create new peerEvent and return it 354 incomingEvent inEvent = { peerID, incomingEventType::receivePacket, p }; 355 return inEvent; 356 } 357 216 358 217 359 void Connection::enableCompression() -
code/trunk/src/libraries/network/Connection.h
r7801 r8327 44 44 45 45 #include <deque> 46 #include <map> 46 47 #include <enet/enet.h> 48 #include <boost/concept_check.hpp> 47 49 48 50 namespace boost … … 59 61 const unsigned int NETWORK_MAX_QUEUE_PROCESS_TIME = 5; 60 62 63 namespace incomingEventType 64 { 65 enum Value 66 { 67 receivePacket = 1, // incoming packet 68 peerConnect = 2, // incoming connect request 69 peerDisconnect = 3 // incoming disconnect request 70 }; 71 72 } 73 61 74 namespace outgoingEventType 62 75 { 63 76 enum Value 64 77 { 65 sendPacket = 1, 66 disconnectPeer = 2, 67 broadcastPacket = 3 78 sendPacket = 1, // outgoing packet 79 broadcastPacket = 2, // outgoing broadcast packet 80 disconnectPeer = 3, // outgoing disconnect request 81 disconnectPeers = 4 // outgoing disconnect request 68 82 }; 69 83 70 84 } 71 85 86 struct _NetworkExport incomingEvent 87 { 88 uint32_t peerID; 89 incomingEventType::Value type; 90 packet::Packet* packet; 91 }; 92 72 93 struct _NetworkExport outgoingEvent 73 94 { 74 ENetPeer* peer;95 uint32_t peerID; 75 96 outgoingEventType::Value type; 76 97 ENetPacket* packet; … … 83 104 virtual ~Connection(); 84 105 85 void addPacket(ENetPacket *packet, ENetPeer *peer, uint8_t channelID);86 void broadcastPacket(ENetPacket* packet, uint8_t channelID);87 // ENetHost* getHost(){ return this->host_; }88 89 106 protected: 90 Connection(); 91 // static Connection* getInstance(){ return Connection::instance_; } 92 93 // int service(ENetEvent* event); 107 Connection(uint32_t firstPeerID = NETWORK_PEER_ID_SERVER+1); 108 94 109 void startCommunicationThread(); 95 110 void stopCommunicationThread(); 96 void communicationThread(); 97 virtual void disconnectPeer(ENetPeer *peer); 111 112 void addPacket(ENetPacket *packet, uint32_t peerID, uint8_t channelID); 113 void broadcastPacket(ENetPacket* packet, uint8_t channelID); 114 void disconnectPeer(uint32_t peerID); 115 void disconnectPeers(); 98 116 99 117 void enableCompression(); 100 118 101 119 void processQueue(); 102 virtual void addPeer(ENetEvent* event)=0; 103 virtual void removePeer(ENetEvent* event)=0; 120 void waitOutgoingQueue(); // wait for the outgoing queue to become empty (everything processed by communication thread) 121 virtual void addPeer(uint32_t peerID)=0; 122 virtual void removePeer(uint32_t peerID)=0; 104 123 virtual void processPacket( packet::Packet* packet)=0; 105 virtual packet::Packet* createPacket(ENetEvent* event); 124 125 incomingEvent preprocessConnectEvent(ENetEvent& event); 126 incomingEvent preprocessDisconnectEvent(ENetEvent& event); 127 incomingEvent preprocessReceiveEvent(ENetEvent& event); 128 129 void processIncomingEvent(ENetEvent& event); 130 void processOutgoingEvent(outgoingEvent& event); 131 132 void disconnectPeersInternal(); 106 133 107 ENetHost* host_;134 ENetHost* host_; 108 135 private: 109 boost::thread* communicationThread_; 110 bool bCommunicationThreadRunning_; 111 ENetAddress* bindAddress_; 112 std::deque<ENetEvent> incomingEvents_; 113 std::deque<outgoingEvent> outgoingEvents_; 114 boost::mutex* incomingEventsMutex_; 115 boost::mutex* outgoingEventsMutex_; 116 117 // static Connection *instance_; 136 void communicationThread(); 137 138 boost::thread* communicationThread_; 139 bool bCommunicationThreadRunning_; 140 ENetAddress* bindAddress_; 141 std::deque<incomingEvent> incomingEvents_; 142 std::deque<outgoingEvent> outgoingEvents_; 143 boost::mutex* incomingEventsMutex_; 144 boost::mutex* outgoingEventsMutex_; 145 boost::mutex* overallMutex_; 146 std::map<uint32_t, ENetPeer*> peerMap_; 147 std::map<ENetPeer*, uint32_t> peerIDMap_; 148 uint32_t nextPeerID_; 118 149 119 150 }; -
code/trunk/src/libraries/network/GamestateHandler.h
r7801 r8327 51 51 virtual bool addGamestate(packet::Gamestate* gs, unsigned int clientID) = 0; 52 52 virtual bool ackGamestate(unsigned int gamestateID, unsigned int clientID) = 0; 53 virtual uint32_t getLast ProcessedGamestateID( unsigned int clientID )=0;53 virtual uint32_t getLastReceivedGamestateID( unsigned int clientID )=0; 54 54 virtual uint32_t getCurrentGamestateID()=0; 55 55 }; -
code/trunk/src/libraries/network/GamestateManager.cc
r7801 r8327 57 57 58 58 namespace orxonox 59 { 59 { 60 60 GamestateManager::GamestateManager() : 61 61 currentGamestate_(0), id_(0) … … 122 122 bool GamestateManager::sendAck(unsigned int gamestateID, uint32_t peerID) 123 123 { 124 assert( gamestateID != ACKID_NACK ); 124 125 packet::Acknowledgement *ack = new packet::Acknowledgement(gamestateID, peerID); 125 126 if( !this->sendPacket(ack)) … … 139 140 if ( currentGamestate_ != 0 ) 140 141 delete currentGamestate_; 141 currentGamestate_ = new packet::Gamestate();142 142 uint8_t gsMode; 143 143 if( GameMode::isMaster() ) … … 149 149 newID = ++id_; 150 150 else 151 newID = peerMap_[NETWORK_PEER_ID_SERVER].lastProcessedGamestateID; 151 { 152 assert(peerMap_.size()!=0); 153 newID = peerMap_[NETWORK_PEER_ID_SERVER].lastReceivedGamestateID; 154 if( newID == GAMESTATEID_INITIAL ) 155 { 156 return false; 157 } 158 } 152 159 153 if(!currentGamestate_->collectData(newID, gsMode)){ //we have no data to send 160 currentGamestate_ = new packet::Gamestate(); 161 162 if(!currentGamestate_->collectData(newID, gsMode)) 163 { //we have no data to send 154 164 delete currentGamestate_; 155 165 currentGamestate_=0; 166 return false; 156 167 } 157 168 return true; … … 172 183 continue; 173 184 } 174 COUT( 4) << "client id: " << peerIt->first << std::endl;185 COUT(5) << "client id: " << peerIt->first << std::endl; 175 186 COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl; 176 187 int peerID = peerIt->first; //get client id … … 187 198 } 188 199 189 peerGamestates.push_back(0); // insert an empty gamestate* to change200 peerGamestates.push_back(0); // insert an empty gamestate* to be changed 190 201 finishGamestate( peerID, peerGamestates.back(), baseGamestate, currentGamestate_ ); 191 202 if( peerGamestates.back()==0 ) … … 244 255 // assert(b); 245 256 clock.capture(); 246 COUT( 4) << "diff and compress time: " << clock.getDeltaTime() << endl;257 COUT(5) << "diff and compress time: " << clock.getDeltaTime() << endl; 247 258 // COUT(5) << "sending gamestate with id " << gs->getID(); 248 259 // if(gamestate->isDiffed()) … … 263 274 unsigned int curid = it->second.lastAckedGamestateID; 264 275 265 if(gamestateID == ACKID_NACK){ 266 it->second.lastAckedGamestateID = GAMESTATEID_INITIAL; 267 // temp->setGamestateID(GAMESTATEID_INITIAL); 268 // now delete all saved gamestates for this client 269 std::map<uint32_t, packet::Gamestate*>::iterator it2; 270 for(it2 = it->second.gamestates.begin(); it2!=it->second.gamestates.end(); ++it2 ){ 271 delete it2->second; 272 } 273 it->second.gamestates.clear(); 274 return true; 275 } 276 277 assert(curid==GAMESTATEID_INITIAL || curid<=gamestateID); 278 COUT(5) << "acking gamestate " << gamestateID << " for peerID: " << peerID << " curid: " << curid << std::endl; 276 assert(gamestateID != ACKID_NACK); 277 // if(gamestateID == ACKID_NACK){ 278 // it->second.lastAckedGamestateID = GAMESTATEID_INITIAL; 279 // // temp->setGamestateID(GAMESTATEID_INITIAL); 280 // // now delete all saved gamestates for this client 281 // std::map<uint32_t, packet::Gamestate*>::iterator it2; 282 // for(it2 = it->second.gamestates.begin(); it2!=it->second.gamestates.end(); ++it2 ){ 283 // delete it2->second; 284 // } 285 // it->second.gamestates.clear(); 286 // return true; 287 // } 288 289 // assert(curid==GAMESTATEID_INITIAL || curid<=gamestateID); // this line is commented out because acknowledgements are unreliable and may arrive in distorted order 290 if( gamestateID <= curid ) 291 return true; 292 COUT(4) << "acking gamestate " << gamestateID << " for peerID: " << peerID << " curid: " << curid << std::endl; 279 293 std::map<uint32_t, packet::Gamestate*>::iterator it2; 280 294 for( it2=it->second.gamestates.begin(); it2!=it->second.gamestates.end(); ) … … 300 314 } 301 315 302 uint32_t GamestateManager::getLast ProcessedGamestateID(unsigned int peerID)316 uint32_t GamestateManager::getLastReceivedGamestateID(unsigned int peerID) 303 317 { 304 318 assert( this->peerMap_.find(peerID)!=this->peerMap_.end() ); 305 319 if( this->peerMap_.find(peerID) != this->peerMap_.end() ) 306 return this->peerMap_[peerID].last ProcessedGamestateID;320 return this->peerMap_[peerID].lastReceivedGamestateID; 307 321 else 308 322 return GAMESTATEID_INITIAL; … … 314 328 assert(peerMap_.find(peerID)==peerMap_.end()); 315 329 peerMap_[peerID].peerID = peerID; 316 peerMap_[peerID].last ProcessedGamestateID = GAMESTATEID_INITIAL;330 peerMap_[peerID].lastReceivedGamestateID = GAMESTATEID_INITIAL; 317 331 peerMap_[peerID].lastAckedGamestateID = GAMESTATEID_INITIAL; 318 332 if( GameMode::isMaster() ) … … 360 374 if( gs->spreadData(gsMode) ) 361 375 { 362 this->peerMap_[gs->getPeerID()].last ProcessedGamestateID = gs->getID();376 this->peerMap_[gs->getPeerID()].lastReceivedGamestateID = gs->getID(); 363 377 return true; 364 378 } -
code/trunk/src/libraries/network/GamestateManager.h
r7801 r8327 73 73 { 74 74 uint32_t peerID; 75 uint32_t last ProcessedGamestateID;76 uint32_t lastAckedGamestateID; 75 uint32_t lastReceivedGamestateID; //!< id of the last gamestate which was received (and processed) from the peer 76 uint32_t lastAckedGamestateID; //!< id of the last gamestate on which we received an ack from the peer 77 77 bool isSynched; 78 78 std::map< uint32_t, packet::Gamestate* > gamestates; … … 86 86 virtual bool addGamestate(packet::Gamestate *gs, unsigned int peerID); 87 87 virtual bool ackGamestate(unsigned int gamestateID, unsigned int peerID); 88 virtual uint32_t getLast ProcessedGamestateID( unsigned int peerID );88 virtual uint32_t getLastReceivedGamestateID( unsigned int peerID ); 89 89 virtual uint32_t getCurrentGamestateID(){ return currentGamestate_->getID(); } 90 90 … … 101 101 { assert(peerMap_.find(peerID)!=peerMap_.end()); peerMap_[peerID].isSynched = true; } 102 102 void removePeer( uint32_t peerID ); 103 bool hasPeers(){ return this->peerMap_.size()!=0; } 103 104 // void removeClient(ClientInformation *client); 104 105 protected: -
code/trunk/src/libraries/network/Host.cc
r8108 r8327 117 117 { 118 118 for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it) 119 it->incomingChat(message, CLIENTID_UNKNOWN);119 it->incomingChat(message, NETWORK_PEER_ID_BROADCAST); 120 120 return true; 121 121 } -
code/trunk/src/libraries/network/NetworkPrereqs.h
r7801 r8327 65 65 { 66 66 static const unsigned int GAMESTATEID_INITIAL = static_cast<unsigned int>(-1); 67 static const unsigned int CLIENTID_UNKNOWN = static_cast<unsigned int>(-2);68 67 extern const char* LAN_DISCOVERY_MESSAGE; 69 68 extern const char* LAN_DISCOVERY_ACK; 70 69 static const unsigned int LAN_DISCOVERY_PORT = 55558; 71 70 static const unsigned int NETWORK_PEER_ID_SERVER = 0; 71 static const unsigned int NETWORK_PEER_ID_BROADCAST = static_cast<unsigned int>(-1); 72 static const unsigned int NETWORK_PEER_ID_UNKNOWN = static_cast<unsigned int>(-2); 72 73 static const unsigned int NETWORK_CHANNEL_DEFAULT = 0; 73 74 static const unsigned int NETWORK_CHANNEL_UNRELIABLE = 1; -
code/trunk/src/libraries/network/Server.cc
r7801 r8327 57 57 #include "packet/Welcome.h" 58 58 #include "ChatListener.h" 59 #include "ClientInformation.h"59 // #include "ClientInformation.h" 60 60 #include "FunctionCallManager.h" 61 61 #include "GamestateManager.h" … … 152 152 bool Server::processChat(const std::string& message, unsigned int playerID) 153 153 { 154 ClientInformation *temp = ClientInformation::getBegin();154 // ClientInformation *temp = ClientInformation::getBegin(); 155 155 packet::Chat *chat; 156 while(temp){157 158 chat->setPeerID(temp->getID());159 if(!chat->send( static_cast<Host*>(this) ))160 COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;161 temp = temp->next();162 }156 // while(temp){ 157 chat = new packet::Chat(message, playerID); 158 chat->setPeerID(NETWORK_PEER_ID_BROADCAST); 159 chat->send( static_cast<Host*>(this) ); 160 // COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl; 161 // temp = temp->next(); 162 // } 163 163 // COUT(1) << "Player " << playerID << ": " << message << std::endl; 164 164 return true; … … 207 207 //helper_HandleMasterServerRequests(); 208 208 209 if ( ClientInformation::hasClients() )209 if ( GamestateManager::hasPeers() ) 210 210 { 211 211 // process incoming gamestates … … 237 237 unsigned int Server::getRTT(unsigned int clientID) 238 238 { 239 assert(ClientInformation::findClient(clientID)); 240 return ClientInformation::findClient(clientID)->getRTT(); 239 // assert(ClientInformation::findClient(clientID)); 240 // return ClientInformation::findClient(clientID)->getRTT(); 241 // TODO: reimplement 242 return 0; 241 243 } 242 244 243 245 void Server::printRTT() 244 246 { 245 for( ClientInformation* temp=ClientInformation::getBegin(); temp!=0; temp=temp->next() )246 COUT(0) << "Round trip time to client with ID: " << temp->getID() << " is " << temp->getRTT() << " ms" << endl;247 // for( ClientInformation* temp=ClientInformation::getBegin(); temp!=0; temp=temp->next() ) 248 // COUT(0) << "Round trip time to client with ID: " << temp->getID() << " is " << temp->getRTT() << " ms" << endl; 247 249 } 248 250 … … 252 254 double Server::getPacketLoss(unsigned int clientID) 253 255 { 254 assert(ClientInformation::findClient(clientID)); 255 return ClientInformation::findClient(clientID)->getPacketLoss(); 256 // assert(ClientInformation::findClient(clientID)); 257 // return ClientInformation::findClient(clientID)->getPacketLoss(); 258 return 0.; 256 259 } 257 260 … … 261 264 void Server::updateGamestate() 262 265 { 263 if( ClientInformation::getBegin()==NULL)266 if( this->clientIDs_.size()==0 ) 264 267 //no client connected 265 268 return; … … 291 294 bool Server::sendObjectDeletes() 292 295 { 293 ClientInformation *temp = ClientInformation::getBegin();294 if( temp == NULL )296 // ClientInformation *temp = ClientInformation::getBegin(); 297 // if( temp == NULL ) 295 298 //no client connected 299 if( this->clientIDs_.size()==0 ) 296 300 return true; 297 301 packet::DeleteObjects *del = new packet::DeleteObjects(); … … 302 306 } 303 307 // COUT(3) << "sending DeleteObjects" << std::endl; 304 while(temp != NULL){305 if( !(temp->getSynched()) )306 {307 COUT(5) << "Server: not sending gamestate" << std::endl;308 temp=temp->next();309 continue;310 }311 int cid = temp->getID(); //get client id312 packet::DeleteObjects *cd = new packet::DeleteObjects(*del);313 assert(cd);314 cd->setPeerID(cid);315 if ( !cd->send( static_cast<Host*>(this) ) )316 COUT(3) << "Server: packet with client id (cid): " << cid << " not sended" << std::endl;317 temp=temp->next();308 // while(temp != NULL){ 309 // if( !(temp->getSynched()) ) 310 // { 311 // COUT(5) << "Server: not sending gamestate" << std::endl; 312 // temp=temp->next(); 313 // continue; 314 // } 315 // int cid = temp->getID(); //get client id 316 // packet::DeleteObjects *cd = new packet::DeleteObjects(*del); 317 // assert(cd); 318 del->setPeerID(NETWORK_PEER_ID_BROADCAST); 319 if ( !del->send( static_cast<Host*>(this) ) ) 320 COUT(3) << "Server: could not broadcast deleteObjects packet" << std::endl; 321 // temp=temp->next(); 318 322 // gs gets automatically deleted by enet callback 319 }320 delete del;323 // } 324 // delete del; 321 325 return true; 322 326 } 323 327 324 328 325 void Server::addPeer( ENetEvent *event)326 { 327 static unsigned int newid=1;328 329 COUT(2) << "Server: adding client" << std::endl;330 ClientInformation *temp = ClientInformation::insertBack(new ClientInformation);331 if(!temp)332 {333 COUT(2) << "Server: could not add client" << std::endl;334 }335 temp->setID(newid);336 temp->setPeer(event->peer);329 void Server::addPeer(uint32_t peerID) 330 { 331 // static unsigned int newid=1; 332 // 333 // COUT(2) << "Server: adding client" << std::endl; 334 // ClientInformation *temp = ClientInformation::insertBack(new ClientInformation); 335 // if(!temp) 336 // { 337 // COUT(2) << "Server: could not add client" << std::endl; 338 // } 339 // temp->setID(newid); 340 // temp->setPeer(event->peer); 337 341 338 342 // inform all the listeners 339 ClientConnectionListener::broadcastClientConnected(newid); 340 GamestateManager::addPeer(newid); 341 342 ++newid; 343 344 COUT(3) << "Server: added client id: " << temp->getID() << std::endl; 345 createClient(temp->getID()); 343 this->clientIDs_.push_back(peerID); 344 ClientConnectionListener::broadcastClientConnected(peerID); 345 GamestateManager::addPeer(peerID); 346 347 // ++newid; 348 349 COUT(3) << "Server: added client id: " << peerID << std::endl; 350 createClient(peerID); 346 351 } 347 352 348 void Server::removePeer( ENetEvent *event)353 void Server::removePeer(uint32_t peerID) 349 354 { 350 355 COUT(4) << "removing client from list" << std::endl; 351 ClientInformation *client = ClientInformation::findClient(&event->peer->address); 352 if(!client) 353 return; 354 else 355 { 356 GamestateManager::removePeer(client->getID()); 356 // ClientInformation *client = ClientInformation::findClient(&event->peer->address); 357 // if(!client) 358 // return; 359 // else 360 // { 361 std::vector<uint32_t>::iterator it; 362 for( it=this->clientIDs_.begin(); it!=this->clientIDs_.end(); ++it ) 363 { 364 if( *it == peerID ) 365 { 366 this->clientIDs_.erase(it); 367 break; 368 } 369 } 370 ClientConnectionListener::broadcastClientDisconnected(peerID); 371 GamestateManager::removePeer(peerID); 357 372 //ServerConnection::disconnectClient( client ); 358 373 //ClientConnectionListener::broadcastClientDisconnected( client->getID() ); //this is done in ClientInformation now 359 delete client;360 }374 // delete client; 375 // } 361 376 } 362 377 … … 365 380 if( packet->isReliable() ) 366 381 { 367 if( this->getLast ProcessedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() )382 if( this->getLastReceivedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() ) 368 383 packet->process(static_cast<Host*>(this)); 369 384 else … … 377 392 bool Server::createClient(int clientID) 378 393 { 379 ClientInformation *temp = ClientInformation::findClient(clientID);380 if(!temp)381 {382 COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl;383 return false;384 }385 COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl;394 // ClientInformation *temp = ClientInformation::findClient(clientID); 395 // if(!temp) 396 // { 397 // COUT(2) << "Server. could not create client with id: " << clientID << std::endl; 398 // return false; 399 // } 400 // COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl; 386 401 387 402 // synchronise class ids 388 syncClassid( temp->getID());403 syncClassid(clientID); 389 404 390 405 // now synchronise functionIDs … … 394 409 assert(b); 395 410 396 temp->setSynched(true);411 // temp->setSynched(true); 397 412 GamestateManager::setSynched(clientID); 398 413 399 414 COUT(4) << "sending welcome" << std::endl; 400 packet::Welcome *w = new packet::Welcome( temp->getID(), temp->getShipID());401 w->setPeerID( temp->getID());415 packet::Welcome *w = new packet::Welcome(clientID, OBJECTID_UNKNOWN); 416 w->setPeerID(clientID); 402 417 b = w->send( static_cast<Host*>(this) ); 403 418 assert(b); 404 packet::Gamestate *g = new packet::Gamestate(); 405 g->setPeerID(temp->getID()); 406 b = g->collectData(0,packet::GAMESTATE_MODE_SERVER); 407 assert(b); 408 if(!b) 409 return false; //no data for the client 410 // b = g->compressData(); 419 // packet::Gamestate *g = new packet::Gamestate(); 420 // g->setPeerID(clientID); 421 // b = g->collectData(0,packet::GAMESTATE_MODE_SERVER); 411 422 // assert(b); 412 b = g->send( static_cast<Host*>(this) ); 413 assert(b); 423 // if(!b) 424 // return false; //no data for the client 425 // // b = g->compressData(); 426 // // assert(b); 427 // b = g->send( static_cast<Host*>(this) ); 428 // assert(b); 414 429 return true; 415 430 } 416 431 417 void Server::disconnectClient( ClientInformation *client)418 { 419 ServerConnection::disconnectClient( client );420 GamestateManager::removePeer( client->getID());432 void Server::disconnectClient( uint32_t clientID ) 433 { 434 ServerConnection::disconnectClient( clientID ); 435 GamestateManager::removePeer( clientID ); 421 436 // inform all the listeners 422 437 // ClientConnectionListener::broadcastClientDisconnected(client->getID()); // this is done in ClientInformation now … … 430 445 bool Server::broadcast(const std::string& message) 431 446 { 432 return this->sendChat(message, CLIENTID_UNKNOWN);447 return this->sendChat(message, NETWORK_PEER_ID_BROADCAST); 433 448 } 434 449 435 450 bool Server::sendChat(const std::string& message, unsigned int clientID) 436 451 { 437 ClientInformation *temp = ClientInformation::getBegin();452 // ClientInformation *temp = ClientInformation::getBegin(); 438 453 packet::Chat *chat; 439 while(temp)454 // while(temp) 440 455 { 441 456 chat = new packet::Chat(message, clientID); 442 chat->setPeerID( temp->getID());443 if(!chat->send( static_cast<Host*>(this) ))444 COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;445 temp = temp->next();457 chat->setPeerID(NETWORK_PEER_ID_BROADCAST); 458 chat->send( static_cast<Host*>(this) ); 459 // COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl; 460 // temp = temp->next(); 446 461 } 447 462 // COUT(1) << "Player " << Host::getPlayerID() << ": " << message << std::endl; -
code/trunk/src/libraries/network/Server.h
r7801 r8327 33 33 34 34 #include <deque> 35 #include <vector> 35 36 36 37 #include "util/UtilPrereqs.h" … … 80 81 unsigned int playerID(){return 0;} 81 82 82 void addPeer( ENetEvent *event);83 void removePeer( ENetEvent *event);83 void addPeer(uint32_t peerID); 84 void removePeer(uint32_t peerID); 84 85 void processPacket(packet::Packet* packet); 85 86 86 87 bool createClient(int clientID); 87 void disconnectClient( ClientInformation *client);88 void disconnectClient( uint32_t clientID ); 88 89 bool sendGameStates(); 89 90 bool sendObjectDeletes(); … … 95 96 float timeSinceLastUpdate_; 96 97 std::deque<packet::Packet*> packetQueue_; 98 std::vector<uint32_t> clientIDs_; 97 99 }; 98 100 -
code/trunk/src/libraries/network/ServerConnection.cc
r7801 r8327 35 35 36 36 #include "util/Debug.h" 37 #include "ClientInformation.h" 37 #include <util/Sleep.h> 38 // #include "ClientInformation.h" 38 39 39 40 namespace orxonox … … 44 45 { 45 46 this->bindAddress_ = new ENetAddress(); 46 memset(this->bindAddress_, 0, sizeof(ENetAddress));47 // memset(this->bindAddress_, 0, sizeof(ENetAddress)); 47 48 this->bindAddress_->host = ENET_HOST_ANY; 48 49 this->bindAddress_->port = NETWORK_PORT; 50 this->bindAddress_->scopeID = 0; 49 51 } 50 52 … … 104 106 void ServerConnection::addPacket(ENetPacket *packet, unsigned int clientID, uint8_t channelID) 105 107 { 106 if ( clientID == CLIENTID_UNKNOWN)108 if ( clientID == NETWORK_PEER_ID_BROADCAST ) 107 109 { 108 110 broadcastPacket(packet, channelID); … … 110 112 else 111 113 { 112 ClientInformation *temp = ClientInformation::findClient(clientID);113 if(!temp){114 COUT(3) << "C.Man: addPacket findClient failed" << std::endl;115 }116 Connection::addPacket(packet, temp->getPeer(), channelID);114 // ClientInformation *temp = ClientInformation::findClient(clientID); 115 // if(!temp){ 116 // COUT(3) << "C.Man: addPacket findClient failed" << std::endl; 117 // } 118 Connection::addPacket(packet, clientID, channelID); 117 119 } 118 120 } 119 121 120 void ServerConnection::disconnectClient(ClientInformation *client)121 {122 Connection::disconnectPeer( client->getPeer() );123 }122 // void ServerConnection::disconnectClient(ClientInformation *client) 123 // { 124 // Connection::disconnectPeer( client->getPeer() ); 125 // } 124 126 125 127 void ServerConnection::disconnectClient(int clientID) 126 128 { 127 ClientInformation *client = ClientInformation::findClient(clientID);128 if(client)129 ServerConnection::disconnectClient(client);129 // ClientInformation *client = ClientInformation::findClient(clientID); 130 // if(client) 131 ServerConnection::disconnectClient(clientID); 130 132 } 131 133 132 134 void ServerConnection::disconnectClients() 133 135 { 134 ClientInformation *temp = ClientInformation::getBegin(); 135 while(temp!=0) 136 { 137 ServerConnection::disconnectClient( temp ); 138 temp = temp->next(); 139 } 136 Connection::disconnectPeers(); 137 Connection::waitOutgoingQueue(); 140 138 return; 141 139 } 142 140 143 141 144 int ServerConnection::getClientID(ENetPeer* peer)145 {146 return getClientID(&(peer->address));147 }142 // int ServerConnection::getClientID(ENetPeer* peer) 143 // { 144 // return getClientID(&(peer->address)); 145 // } 148 146 149 int ServerConnection::getClientID(ENetAddress* address)150 {151 return ClientInformation::findClient(address)->getID();152 }153 154 ENetPeer *ServerConnection::getClientPeer(int clientID)155 {156 return ClientInformation::findClient(clientID)->getPeer();157 }147 // int ServerConnection::getClientID(ENetAddress* address) 148 // { 149 // return ClientInformation::findClient(address)->getID(); 150 // } 151 // 152 // ENetPeer *ServerConnection::getClientPeer(int clientID) 153 // { 154 // return ClientInformation::findClient(clientID)->getPeer(); 155 // } 158 156 159 157 -
code/trunk/src/libraries/network/ServerConnection.h
r7801 r8327 57 57 bool closeListener(); 58 58 void addPacket(ENetPacket *packet, unsigned int ID, uint8_t channelID); 59 virtual void disconnectClient(ClientInformation *client);59 // virtual void disconnectClient(ClientInformation *client); 60 60 void disconnectClient(int clientID); 61 61 protected: … … 64 64 65 65 private: 66 int getClientID(ENetPeer* peer);67 int getClientID(ENetAddress* address);68 ENetPeer* getClientPeer(int clientID);66 // int getClientID(ENetPeer* peer); 67 // int getClientID(ENetAddress* address); 68 // ENetPeer* getClientPeer(int clientID); 69 69 70 70 ENetAddress* bindAddress_; -
code/trunk/src/libraries/network/WANDiscovery.cc
r7801 r8327 71 71 * has changed. 72 72 */ 73 SetConfigValue( msaddress, " orxonox.net");73 SetConfigValue( msaddress, "master.orxonox.net"); 74 74 } 75 75 -
code/trunk/src/libraries/network/packet/Gamestate.cc
r7844 r8327 107 107 uint32_t size = calcGamestateSize(id, mode); 108 108 109 COUT( 4) << "G.ST.Man: producing gamestate with id: " << id << std::endl;109 COUT(5) << "G.ST.Man: producing gamestate with id: " << id << std::endl; 110 110 if(size==0) 111 111 return false; … … 158 158 //start write gamestate header 159 159 header_.setDataSize( currentsize ); 160 header_.setCompSize( 0 ); 160 161 header_.setID( id ); 161 162 header_.setBaseID( GAMESTATEID_INITIAL ); -
code/trunk/src/libraries/network/packet/Packet.cc
r7801 r8327 47 47 #include "Welcome.h" 48 48 #include "network/Host.h" 49 #include "network/ClientInformation.h"49 // #include "network/ClientInformation.h" 50 50 51 51 namespace orxonox{ … … 85 85 86 86 87 Packet::Packet(const Packet &p){ 87 Packet::Packet(const Packet &p) 88 { 88 89 enetPacket_=p.enetPacket_; 89 90 flags_=p.flags_; … … 104 105 That also means destroying the ENetPacket if one exists. There 105 106 */ 106 Packet::~Packet(){ 107 Packet::~Packet() 108 { 107 109 // Deallocate data_ memory if necessary. 108 if (this->bDataENetAllocated_){ 110 if (this->bDataENetAllocated_) 111 { 109 112 // In this case ENet allocated data_ and will destroy it. 110 113 } 111 else if (this->data_) { 114 else if (this->data_) 115 { 112 116 // This destructor was probably called as a consequence of ENet executing our callback. 113 117 // It simply serves us to be able to deallocate the packet content (data_) ourselves since … … 119 123 // Note: For the case ENet used the callback to destroy the packet, we have already set 120 124 // enetPacket_ to NULL to avoid destroying it again. 121 if (this->enetPacket_){ 125 if (this->enetPacket_) 126 { 122 127 // enetPacket_->data gets destroyed too by ENet if it was allocated by it. 123 128 enet_packet_destroy(enetPacket_); … … 125 130 } 126 131 127 bool Packet::send(orxonox::Host* host){ 128 if(packetDirection_ != Direction::Outgoing && packetDirection_ != Direction::Bidirectional ){ 132 bool Packet::send(orxonox::Host* host) 133 { 134 if(packetDirection_ != Direction::Outgoing && packetDirection_ != Direction::Bidirectional ) 135 { 129 136 assert(0); 130 137 return false; 131 138 } 132 if(!enetPacket_){ 139 if(!enetPacket_) 140 { 133 141 if(!data_){ 134 142 assert(0); … … 175 183 } 176 184 177 Packet *Packet::createPacket(ENetPacket *packet, ENetPeer *peer){ 185 Packet *Packet::createPacket(ENetPacket* packet, uint32_t peerID) 186 { 178 187 uint8_t *data = packet->data; 179 assert(ClientInformation::findClient(&peer->address)->getID() != static_cast<unsigned int>(-2) || !Host::isServer());180 unsigned int peerID = ClientInformation::findClient(&peer->address)->getID();188 // assert(ClientInformation::findClient(&peer->address)->getID() != static_cast<unsigned int>(-2) || !Host::isServer()); 189 // unsigned int peerID = ClientInformation::findClient(&peer->address)->getID(); 181 190 // HACK 182 if( peerID==static_cast<unsigned int>(-2))183 peerID = NETWORK_PEER_ID_SERVER;191 // if( peerID==static_cast<unsigned int>(-2)) 192 // peerID = NETWORK_PEER_ID_SERVER; 184 193 Packet *p = 0; 185 194 // COUT(6) << "packet type: " << *(Type::Value *)&data[_PACKETID] << std::endl; … … 235 244 data we allocated ourselves. 236 245 */ 237 void Packet::deletePacket(ENetPacket *enetPacket){ 246 void Packet::deletePacket(ENetPacket *enetPacket) 247 { 238 248 // Get our Packet from a global map with all Packets created in the send() method of Packet. 239 249 Packet::packetMapMutex_.lock(); -
code/trunk/src/libraries/network/packet/Packet.h
r7801 r8327 32 32 #include <map> 33 33 34 namespace orxonox { 34 namespace orxonox 35 { 35 36 36 namespace packet{ 37 namespace packet 38 { 37 39 38 namespace Direction{ 39 enum Value{ 40 namespace Direction 41 { 42 enum Value 43 { 40 44 Incoming, 41 45 Outgoing, … … 43 47 }; 44 48 } 45 namespace Type{ 46 enum Value{ 49 namespace Type 50 { 51 enum Value 52 { 47 53 Acknowledgement, 48 54 Chat, … … 59 65 @author Oliver Scheuss <scheusso [at] ee.ethz.ch> 60 66 */ 61 class _NetworkExport Packet{ 67 class _NetworkExport Packet 68 { 62 69 public: 63 70 Packet(const Packet &p); 64 71 virtual ~Packet(); 65 static Packet *createPacket(ENetPacket *packet, ENetPeer *peer);66 static void deletePacket(ENetPacket *packet);72 static Packet* createPacket(ENetPacket* packet, uint32_t peerID); 73 static void deletePacket(ENetPacket* packet); 67 74 68 virtual unsigned char *getData(){ return data_; };75 virtual unsigned char* getData(){ return data_; }; 69 76 virtual unsigned int getSize() const =0; 70 77 virtual bool process(orxonox::Host* host)=0; -
code/trunk/src/libraries/network/synchronisable/Synchronisable.cc
r7801 r8327 295 295 * @param mem pointer to the bytestream 296 296 * @param mode same as in getData 297 * @param forceCallback FIXME - add doc!297 * @param forceCallback this makes updateData call each callback 298 298 * @return true/false 299 299 */ … … 372 372 * This function determines, wheter the object should be saved to the bytestream (according to its syncmode/direction) 373 373 * @param id gamestate id 374 * @param mode FIXME - add doc!374 * @param mode Synchronisation mode (toclient, toserver or bidirectional) 375 375 * @return true/false 376 376 */ 377 377 bool Synchronisable::doSync(int32_t id, uint8_t mode) 378 378 { 379 if(mode==0x0) 380 mode=state_; 379 // if(mode==0x0) 380 // mode=state_; 381 assert(mode!=0x0); 381 382 return ( (this->objectMode_ & mode)!=0 && (!syncList_.empty() ) ); 382 383 } -
code/trunk/src/modules/overlays/hud/ChatOverlay.cc
r7284 r8327 71 71 std::string text; 72 72 73 if (senderID != CLIENTID_UNKNOWN)73 if (senderID != NETWORK_PEER_ID_UNKNOWN) 74 74 { 75 75 std::string name = "unknown"; -
code/trunk/src/orxonox/ChatHistory.cc
r7284 r8327 82 82 #ifndef CHATTEST 83 83 /* get sender ID and prepend it to the message */ 84 if (senderID != CLIENTID_UNKNOWN)84 if (senderID != NETWORK_PEER_ID_UNKNOWN) 85 85 { 86 86 /* if we can't find anything, use "unknown" as default */ -
code/trunk/src/orxonox/ChatInputHandler.cc
r8079 r8327 220 220 221 221 /* setup player name info */ 222 if (senderID != CLIENTID_UNKNOWN)222 if (senderID != NETWORK_PEER_ID_UNKNOWN) 223 223 { 224 224 PlayerInfo* player = PlayerManager::getInstance().getClient(senderID); -
code/trunk/src/orxonox/PlayerManager.cc
r7474 r8327 45 45 RegisterRootObject(PlayerManager); 46 46 47 this->getConnectedClients();47 // this->getConnectedClients(); 48 48 } 49 49 -
code/trunk/src/orxonox/gamestates/GSRoot.cc
r8079 r8327 183 183 { 184 184 if (!GameMode::isStandalone()) 185 callStaticNetworkFunction(&TimeFactorListener::setTimeFactor, CLIENTID_UNKNOWN, factor_new);185 callStaticNetworkFunction(&TimeFactorListener::setTimeFactor, NETWORK_PEER_ID_BROADCAST, factor_new); 186 186 } 187 187 -
code/trunk/src/orxonox/gametypes/Dynamicmatch.cc
r7284 r8327 452 452 if (!it->first)//in order to catch nullpointer 453 453 continue; 454 if (it->first->getClientID() == CLIENTID_UNKNOWN)454 if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN) 455 455 continue; 456 456 this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",it->first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f)); … … 467 467 if (!it->first)//in order to catch nullpointer 468 468 continue; 469 if (it->first->getClientID() == CLIENTID_UNKNOWN)469 if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN) 470 470 continue; 471 471 else if (it->second==chaser) … … 501 501 if (!it->first)//in order to catch nullpointer 502 502 continue; 503 if (it->first->getClientID() == CLIENTID_UNKNOWN)503 if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN) 504 504 continue; 505 505 this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",it->first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f)); … … 516 516 if (!it->first) 517 517 continue; 518 if (it->first->getClientID() == CLIENTID_UNKNOWN)518 if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN) 519 519 continue; 520 520 else if (it->second==chaser) … … 551 551 if (!it->first)//in order to catch nullpointer 552 552 continue; 553 if (it->first->getClientID() == CLIENTID_UNKNOWN)553 if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN) 554 554 continue; 555 555 this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",it->first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f)); … … 566 566 if (!it->first) 567 567 continue; 568 if (it->first->getClientID() == CLIENTID_UNKNOWN)568 if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN) 569 569 continue; 570 570 else if (it->second==chaser) … … 632 632 for (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it) 633 633 { 634 if (it->first->getClientID() == CLIENTID_UNKNOWN)634 if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN) 635 635 continue; 636 636 this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",it->first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f)); -
code/trunk/src/orxonox/gametypes/Gametype.cc
r8079 r8327 263 263 it->second.frags_++; 264 264 265 if (killer->getPlayer()->getClientID() != CLIENTID_UNKNOWN)265 if (killer->getPlayer()->getClientID() != NETWORK_PEER_ID_UNKNOWN) 266 266 this->gtinfo_->sendKillMessage("You killed " + victim->getPlayer()->getName(), killer->getPlayer()->getClientID()); 267 if (victim->getPlayer()->getClientID() != CLIENTID_UNKNOWN)267 if (victim->getPlayer()->getClientID() != NETWORK_PEER_ID_UNKNOWN) 268 268 this->gtinfo_->sendDeathMessage("You were killed by " + killer->getPlayer()->getName(), victim->getPlayer()->getClientID()); 269 269 } -
code/trunk/src/orxonox/gametypes/LastManStanding.cc
r8234 r8327 86 86 if (it != this->players_.end()) 87 87 { 88 if (it->first->getClientID()== CLIENTID_UNKNOWN)88 if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN) 89 89 return true; 90 90 const std::string& message = ""; // resets Camper-Warning-message … … 131 131 for (std::map<PlayerInfo*, int>::iterator it = this->playerLives_.begin(); it != this->playerLives_.end(); ++it) 132 132 { 133 if (it->first->getClientID() == CLIENTID_UNKNOWN)133 if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN) 134 134 continue; 135 135 … … 194 194 if (it != this->players_.end()) 195 195 { 196 if (it->first->getClientID()== CLIENTID_UNKNOWN)196 if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN) 197 197 return; 198 198 const std::string& message = ""; // resets Camper-Warning-message … … 249 249 this->inGame_[it->first]=true; 250 250 251 if (it->first->getClientID()== CLIENTID_UNKNOWN)251 if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN) 252 252 continue; 253 253 int output=1+(int)playerDelayTime_[it->first]; … … 261 261 { 262 262 this->punishPlayer(it->first); 263 if (it->first->getClientID()== CLIENTID_UNKNOWN)263 if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN) 264 264 return; 265 265 const std::string& message = ""; // resets Camper-Warning-message … … 269 269 else if (it->second<timeRemaining/5)//Warning message 270 270 { 271 if (it->first->getClientID()== CLIENTID_UNKNOWN)271 if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN) 272 272 continue; 273 273 const std::string& message = "Camper Warning! Don't forget to shoot."; -
code/trunk/src/orxonox/gametypes/LastTeamStanding.cc
r8234 r8327 30 30 31 31 #include "core/CoreIncludes.h" 32 #include "network/NetworkPrereqs.h" 32 33 #include "network/Host.h" 33 34 #include "infos/PlayerInfo.h" … … 135 136 if (it != this->players_.end()) 136 137 { 137 if (it->first->getClientID()== CLIENTID_UNKNOWN)138 if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN) 138 139 return true; 139 140 const std::string& message = ""; // resets Camper-Warning-message … … 169 170 if (it != this->players_.end()) 170 171 { 171 if (it->first->getClientID()== CLIENTID_UNKNOWN)172 if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN) 172 173 return; 173 174 const std::string& message = ""; // resets Camper-Warning-message … … 196 197 this->inGame_[it->first] = true; 197 198 198 if (it->first->getClientID()== CLIENTID_UNKNOWN)199 if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN) 199 200 continue; 200 201 int output = 1 + (int)playerDelayTime_[it->first]; … … 208 209 { 209 210 this->punishPlayer(it->first); 210 if (it->first->getClientID() == CLIENTID_UNKNOWN)211 if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN) 211 212 return; 212 213 const std::string& message = ""; // resets Camper-Warning-message … … 216 217 else if (it->second < timeRemaining/5)//Warning message 217 218 { 218 if (it->first->getClientID()== CLIENTID_UNKNOWN)219 if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN) 219 220 continue; 220 221 const std::string& message = "Camper Warning! Don't forget to shoot."; … … 232 233 for (std::map<PlayerInfo*, int>::iterator it = this->playerLives_.begin(); it != this->playerLives_.end(); ++it) 233 234 { 234 if (it->first->getClientID() == CLIENTID_UNKNOWN)235 if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN) 235 236 continue; 236 237 … … 247 248 for (std::map<PlayerInfo*, int>::iterator it3 = this->teamnumbers_.begin(); it3 != this->teamnumbers_.end(); ++it3) 248 249 { 249 if (it3->first->getClientID() == CLIENTID_UNKNOWN)250 if (it3->first->getClientID() == NETWORK_PEER_ID_UNKNOWN) 250 251 continue; 251 252 if (it3->second == party) -
code/trunk/src/orxonox/gametypes/TeamBaseMatch.cc
r7284 r8327 190 190 for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it) 191 191 { 192 if (it->first->getClientID() == CLIENTID_UNKNOWN)192 if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN) 193 193 continue; 194 194 -
code/trunk/src/orxonox/gametypes/UnderAttack.cc
r6417 r8327 76 76 for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it) 77 77 { 78 if (it->first->getClientID() == CLIENTID_UNKNOWN)78 if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN) 79 79 continue; 80 80 … … 158 158 for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it) 159 159 { 160 if (it->first->getClientID() == CLIENTID_UNKNOWN)160 if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN) 161 161 continue; 162 162 -
code/trunk/src/orxonox/infos/GametypeInfo.cc
r7163 r8327 74 74 if (GameMode::isMaster()) 75 75 { 76 callMemberNetworkFunction(GametypeInfo, dispatchAnnounceMessage, this->getObjectID(), CLIENTID_UNKNOWN, message);76 callMemberNetworkFunction(GametypeInfo, dispatchAnnounceMessage, this->getObjectID(), NETWORK_PEER_ID_BROADCAST, message); 77 77 this->dispatchAnnounceMessage(message); 78 78 } -
code/trunk/src/orxonox/infos/HumanPlayer.cc
r6417 r8327 32 32 #include "core/ConfigValueIncludes.h" 33 33 #include "core/GameMode.h" 34 #include "network/ClientInformation.h"34 // #include "network/ClientInformation.h" 35 35 #include "network/Host.h" 36 36 #include "controllers/HumanController.h" … … 144 144 float HumanPlayer::getPing() const 145 145 { 146 return static_cast<float>(ClientInformation::findClient(this->getClientID())->getRTT()); 146 // return static_cast<float>(ClientInformation::findClient(this->getClientID())->getRTT()); 147 return 0.; //TODO: reimplement this 147 148 } 148 149 149 150 float HumanPlayer::getPacketLossRatio() const 150 151 { 151 return static_cast<float>(ClientInformation::findClient(this->getClientID())->getPacketLoss()); 152 // return static_cast<float>(ClientInformation::findClient(this->getClientID())->getPacketLoss()); 153 return 0.; //TODO: reimplement this 152 154 } 153 155 -
code/trunk/src/orxonox/infos/PlayerInfo.cc
r7163 r8327 32 32 33 33 #include "core/CoreIncludes.h" 34 #include "network/ClientInformation.h"34 // #include "network/ClientInformation.h" 35 35 #include "gametypes/Gametype.h" 36 36 #include "worldentities/ControllableEntity.h" … … 43 43 RegisterObject(PlayerInfo); 44 44 45 this->clientID_ = CLIENTID_UNKNOWN;45 this->clientID_ = NETWORK_PEER_ID_UNKNOWN; 46 46 this->bHumanPlayer_ = false; 47 47 this->bLocalPlayer_ = false;
Note: See TracChangeset
for help on using the changeset viewer.