Changeset 3198 for code/trunk/src/network
- Timestamp:
- Jun 20, 2009, 4:27:38 PM (16 years ago)
- Location:
- code/trunk/src/network
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/network/Client.cc
r3084 r3198 169 169 bool b = packet->process(); 170 170 assert(b); 171 delete event; 171 172 } 172 173 if(gamestate.processGamestates()) -
code/trunk/src/network/ClientConnection.cc
r3084 r3198 169 169 // assert(0); 170 170 printf("ClientConnection: ENet returned with an error!\n"); 171 quit_=true;172 break;171 // quit_=true; 172 continue; 173 173 // add some error handling here ======================== 174 174 } … … 197 197 } 198 198 } 199 delete event; 199 200 // now disconnect 200 201 201 202 if(!disconnectConnection()) 203 { 204 printf("could not disconnect properly\n"); 202 205 // if disconnecting failed destroy conn. 203 206 boost::recursive_mutex::scoped_lock lock(enet_mutex_g); 204 207 enet_peer_reset(server); 208 } 209 else 210 printf("properly disconnected\n"); 205 211 return; 206 212 } … … 221 227 break; 222 228 case ENET_EVENT_TYPE_DISCONNECT: 229 printf("received disconnect confirmation from server"); 223 230 return true; 224 231 } -
code/trunk/src/network/ClientInformation.h
r2773 r3198 91 91 bool getSynched(); 92 92 93 94 93 private: 95 94 static ClientInformation *head_; -
code/trunk/src/network/ConnectionManager.cc
r3093 r3198 132 132 quit_=true; 133 133 receiverThread_->join(); 134 delete receiverThread_; 134 135 return true; 135 136 } … … 206 207 // we should never reach this point 207 208 printf("ConnectionManager: ENet returned with an error\n"); 208 quit_=true;209 printf("waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhh\n");209 // quit_=true; 210 // printf("waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhh\n"); 210 211 continue; 211 212 // add some error handling here ======================== … … 218 219 // printf("===================================================================="); 219 220 case ENET_EVENT_TYPE_DISCONNECT: 221 // printf("===================================================================="); 220 222 case ENET_EVENT_TYPE_RECEIVE: 221 222 223 processData(event); 224 event = new ENetEvent; 223 225 break; 224 226 case ENET_EVENT_TYPE_NONE: 225 227 //receiverThread_->yield(); 226 msleep(1 0);228 msleep(1); 227 229 break; 228 230 } -
code/trunk/src/network/ConnectionManager.h
r3093 r3198 55 55 const int NETWORK_PORT = 55556; 56 56 const int NETWORK_MAX_CONNECTIONS = 50; 57 const int NETWORK_WAIT_TIMEOUT = 1 0;57 const int NETWORK_WAIT_TIMEOUT = 1; 58 58 const int NETWORK_DEFAULT_CHANNEL = 0; 59 59 -
code/trunk/src/network/GamestateManager.cc
r3102 r3198 63 63 GamestateManager::~GamestateManager() 64 64 { 65 if( this->reference ) 66 delete this->reference; 67 for( std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateQueue.begin(); it != gamestateQueue.end(); it++ ) 68 delete (*it).second; 65 69 delete trafficControl_; 66 70 } … … 133 137 // COUT(3) << "diffing" << std::endl; 134 138 // packet::Gamestate* gs1 = gs; 135 gs = gs->diff(client); 139 packet::Gamestate *diffed = gs->diff(client); 140 //packet::Gamestate *gs2 = diffed->undiff(gs); 141 // assert(*gs == *gs2); 142 gs = diffed; 136 143 // packet::Gamestate* gs2 = gs->undiff(client); 137 144 // gs = new packet::Gamestate(*gs); -
code/trunk/src/network/Server.cc
r3196 r3198 128 128 */ 129 129 void Server::close() { 130 ClientInformation *temp = ClientInformation::getBegin(); 131 ClientInformation *temp2; 132 // disconnect all connected clients 133 while( temp ) 134 { 135 temp2 = temp; 136 temp = temp->next(); 137 disconnectClient( temp2 ); 138 } 130 139 connection->quitListener(); 131 140 return; … … 198 207 switch( event->type ) { 199 208 case ENET_EVENT_TYPE_CONNECT: 200 COUT( 3) << "processing event_Type_connect" << std::endl;209 COUT(4) << "processing event_Type_connect" << std::endl; 201 210 addClient(event); 202 211 break; … … 304 313 // gs gets automatically deleted by enet callback 305 314 } 315 delete del; 306 316 return true; 307 317 } … … 381 391 if(!client) 382 392 return false; 393 else 394 disconnectClient( client ); 395 return true; 396 } 397 398 void Server::disconnectClient(int clientID){ 399 ClientInformation *client = ClientInformation::findClient(clientID); 400 if(client) 401 disconnectClient(client); 402 } 403 404 void Server::disconnectClient( ClientInformation *client){ 405 connection->disconnectClient(client); 383 406 gamestates_->removeClient(client); 384 385 407 // inform all the listeners 386 408 ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin(); 387 409 while(listener){ 388 410 listener->clientDisconnected(client->getID()); 389 listener++; 390 } 391 392 return ClientInformation::removeClient(event->peer); 393 } 394 395 void Server::disconnectClient(int clientID){ 396 ClientInformation *client = ClientInformation::findClient(clientID); 397 if(client) 398 disconnectClient(client); 399 } 400 void Server::disconnectClient( ClientInformation *client){ 401 connection->disconnectClient(client); 402 gamestates_->removeClient(client); 411 ++listener; 412 } 413 delete client; //remove client from list 403 414 } 404 415 -
code/trunk/src/network/TrafficControl.cc
r3084 r3198 137 137 void TrafficControl::ack(unsigned int clientID, unsigned int gamestateID) 138 138 { 139 if ( !this->bActive_ ) 140 return; 139 141 std::list<obj>::iterator itvec; // iterator to iterate through the acked objects 140 142 … … 189 191 void TrafficControl::updateClientListTemp(std::list<obj>& list) 190 192 { 191 clientListTemp_[currentClientID][currentGamestateID] = std::list<obj>(list);193 clientListTemp_[currentClientID][currentGamestateID] = list; 192 194 } 193 195 … … 227 229 { 228 230 229 //now the sorting 230 231 //compare listToProcess vs clientListPerm 232 //if listToProcess contains new Objects, add them to clientListPerm 233 std::list<obj>::iterator itvec; 231 if( bActive_ ) 232 { 233 //now the sorting 234 235 //compare listToProcess vs clientListPerm 236 //if listToProcess contains new Objects, add them to clientListPerm 237 std::list<obj>::iterator itvec; 234 238 235 std::map<unsigned int, objInfo >& objectListPerm = clientListPerm_[clientID];239 std::map<unsigned int, objInfo >& objectListPerm = clientListPerm_[clientID]; 236 240 237 238 239 240 {241 for( itvec=list.begin(); itvec != list.end(); itvec++) 242 { 243 if ( objectListPerm.find( (*itvec).objID) != objectListPerm.end() ) 244 { 241 245 // we already have the object in our map 242 246 //obj bleibt in liste und permanente prio wird berechnet 243 objectListPerm[(*itvec).objID].objDiffGS = currentGamestateID - objectListPerm[(*itvec).objID].objCurGS;244 continue;//check next objId245 }246 else247 {247 objectListPerm[(*itvec).objID].objDiffGS = currentGamestateID - objectListPerm[(*itvec).objID].objCurGS; 248 continue;//check next objId 249 } 250 else 251 { 248 252 // insert the object into clientListPerm 249 insertinClientListPerm(clientID,*itvec); 250 continue;//check next objId 251 } 252 } 253 //end compare listToProcess vs clientListPerm 254 255 if( bActive_ ) 256 { 253 insertinClientListPerm(clientID,*itvec); 254 continue;//check next objId 255 } 256 } 257 //end compare listToProcess vs clientListPerm 258 257 259 //sort copied list according to priorities 258 260 // use boost bind here because we need to pass a memberfunction to stl sort … … 275 277 // sort(list.begin(), list.end(), boost::bind(&TrafficControl::dataSort, this, _1, _2) ); 276 278 list.sort( boost::bind(&TrafficControl::dataSort, this, _1, _2) ); 279 280 //diese Funktion updateClientList muss noch gemacht werden 281 updateClientListTemp(list); 282 //end of sorting 277 283 } 278 //diese Funktion updateClientList muss noch gemacht werden279 updateClientListTemp(list);280 //end of sorting281 284 } 282 285 -
code/trunk/src/network/packet/Acknowledgement.cc
r2710 r3198 64 64 65 65 bool Acknowledgement::process(){ 66 COUT(6) << "processing ACK with ID: " << getAckID() << endl;66 COUT(5) << "processing ACK with ID: " << getAckID() << endl; 67 67 bool b = GamestateHandler::ackGamestate(getAckID(), clientID_); 68 68 delete this; -
code/trunk/src/network/packet/Gamestate.cc
r3196 r3198 79 79 Gamestate::~Gamestate() 80 80 { 81 if( header_ ) 82 delete header_; 81 83 } 82 84 … … 98 100 99 101 // create the header object 102 assert( header_ == 0 ); 100 103 header_ = new GamestateHeader(data_); 101 104 … … 137 140 header_->setDataSize( currentsize ); 138 141 header_->setID( id ); 142 header_->setBaseID( GAMESTATEID_INITIAL ); 139 143 header_->setDiffed( false ); 140 144 header_->setComplete( true ); … … 207 211 } 208 212 #endif 209 210 213 return true; 211 214 } … … 320 323 } 321 324 322 Gamestate *Gamestate::diff(Gamestate *base)325 /*Gamestate *Gamestate::diff(Gamestate *base) 323 326 { 324 327 assert(data_); … … 355 358 g->packetDirection_ = packetDirection_; 356 359 return g; 357 } 360 }*/ 361 362 Gamestate *Gamestate::diff(Gamestate *base) 363 { 364 assert(this && base); assert(data_ && base->data_); 365 assert(!header_->isCompressed() && !base->header_->isCompressed()); 366 assert(!header_->isDiffed()); 367 368 uint8_t *basep = GAMESTATE_START(base->data_); 369 uint8_t *gs = GAMESTATE_START(this->data_); 370 uint32_t dest_length = header_->getDataSize(); 371 372 if(dest_length==0) 373 return NULL; 374 375 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()]; 376 uint8_t *dest = GAMESTATE_START(ndata); 377 378 rawDiff( dest, gs, basep, header_->getDataSize(), base->header_->getDataSize() ); 379 #ifndef NDEBUG 380 uint8_t *dest2 = new uint8_t[dest_length]; 381 rawDiff( dest2, dest, basep, header_->getDataSize(), base->header_->getDataSize() ); 382 assert( memcmp( dest2, gs, dest_length) == 0 ); 383 #endif 384 385 Gamestate *g = new Gamestate(ndata, getClientID()); 386 assert(g->header_); 387 *(g->header_) = *header_; 388 g->header_->setDiffed( true ); 389 g->header_->setBaseID( base->getID() ); 390 g->flags_=flags_; 391 g->packetDirection_ = packetDirection_; 392 assert(g->isDiffed()); 393 assert(!g->isCompressed()); 394 return g; 395 } 396 397 Gamestate *Gamestate::undiff(Gamestate *base) 398 { 399 assert(this && base); assert(data_ && base->data_); 400 assert(!header_->isCompressed() && !base->header_->isCompressed()); 401 assert(header_->isDiffed()); 402 403 uint8_t *basep = GAMESTATE_START(base->data_); 404 uint8_t *gs = GAMESTATE_START(this->data_); 405 uint32_t dest_length = header_->getDataSize(); 406 407 if(dest_length==0) 408 return NULL; 409 410 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()]; 411 uint8_t *dest = ndata + GamestateHeader::getSize(); 412 413 rawDiff( dest, gs, basep, header_->getDataSize(), base->header_->getDataSize() ); 414 415 Gamestate *g = new Gamestate(ndata, getClientID()); 416 assert(g->header_); 417 *(g->header_) = *header_; 418 g->header_->setDiffed( false ); 419 g->flags_=flags_; 420 g->packetDirection_ = packetDirection_; 421 assert(!g->isDiffed()); 422 assert(!g->isCompressed()); 423 return g; 424 } 425 358 426 359 427 // Gamestate *Gamestate::diff(Gamestate *base) … … 409 477 // } 410 478 479 480 void Gamestate::rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength) 481 { 482 uint64_t* gd = (uint64_t*)data; 483 uint64_t* bd = (uint64_t*)basedata; 484 uint64_t* nd = (uint64_t*)newdata; 485 486 unsigned int i; 487 for( i=0; i<datalength/8; i++ ) 488 { 489 if( i<baselength/8 ) 490 *(nd+i) = *(gd+i) ^ *(bd+i); // xor the data 491 else 492 *(nd+i) = *(gd+i); // just copy over the data 493 } 494 unsigned int j; 495 // now process the rest (when datalength isn't a multiple of 4) 496 for( j = 8*(datalength/8); j<datalength; j++ ) 497 { 498 if( j<baselength ) 499 *(newdata+j) = *(data+j) ^ *(basedata+j); // xor 500 else 501 *(newdata+j) = *(data+j); // just copy 502 } 503 assert(j==datalength); 504 } 505 411 506 Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){ 412 507 assert(data_); … … 478 573 479 574 480 Gamestate *Gamestate::undiff(Gamestate *base)575 /*Gamestate *Gamestate::undiff(Gamestate *base) 481 576 { 482 577 assert(this && base);assert(data_); … … 514 609 assert(!g->isCompressed()); 515 610 return g; 516 } 517 611 }*/ 518 612 519 613 uint32_t Gamestate::calcGamestateSize(int32_t id, uint8_t mode) -
code/trunk/src/network/packet/Gamestate.h
r3084 r3198 124 124 // Packet functions 125 125 private: 126 void rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength); 126 127 virtual uint32_t getSize() const; 127 128 virtual inline bool process(); -
code/trunk/src/network/synchronisable/Synchronisable.cc
r3088 r3198 98 98 // delete callback function objects 99 99 if(!Identifier::isCreatingHierarchy()){ 100 // remove object from the static objectMap 101 if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer())) 102 deletedObjects_.push(objectID); 103 // delete all Synchronisable Variables from syncList ( which are also in stringList ) 100 104 for(std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin(); it!=syncList.end(); it++) 101 105 delete (*it); 102 if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer()))103 deletedObjects_.push(objectID);106 syncList.clear(); 107 stringList.clear(); 104 108 } 105 109 std::map<uint32_t, Synchronisable*>::iterator it; … … 174 178 COUT(4) << "fabricate objectID: " << no->objectID << " classID: " << no->classID << std::endl; 175 179 // update data and create object/entity... 180 assert( Synchronisable::objectMap_.find(header.getObjectID()) == Synchronisable::objectMap_.end() ); 181 Synchronisable::objectMap_[header.getObjectID()] = no; 176 182 bool b = no->updateData(mem, mode, true); 177 183 assert(b); … … 213 219 return it1->second; 214 220 215 ObjectList<Synchronisable>::iterator it; 216 for(it = ObjectList<Synchronisable>::begin(); it; ++it){ 217 if( it->getObjectID()==objectID ){ 218 objectMap_[objectID] = *it; 219 return *it; 220 } 221 } 221 // ObjectList<Synchronisable>::iterator it; 222 // for(it = ObjectList<Synchronisable>::begin(); it; ++it){ 223 // if( it->getObjectID()==objectID ){ 224 // objectMap_[objectID] = *it; 225 // return *it; 226 // } 227 // } 228 // if the objects not in the map it should'nt exist at all anymore 222 229 return NULL; 223 230 }
Note: See TracChangeset
for help on using the changeset viewer.