Changeset 1574 for code/branches/core3/src/network
- Timestamp:
- Jun 9, 2008, 4:35:38 AM (16 years ago)
- Location:
- code/branches/core3/src/network
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core3/src/network/ConnectionManager.cc
r1534 r1574 64 64 { 65 65 //boost::thread_group network_threads; 66 66 67 67 ConnectionManager::ConnectionManager():receiverThread_(0){} 68 68 boost::recursive_mutex ConnectionManager::enet_mutex_; 69 69 70 70 ConnectionManager::ConnectionManager(ClientInformation *head) : receiverThread_(0) { 71 71 quit=false; … … 74 74 head_ = head; 75 75 } 76 76 77 77 ConnectionManager::ConnectionManager(ClientInformation *head, int port){ 78 78 quit=false; … … 115 115 return packet; 116 116 }*/ 117 117 118 118 ENetEvent *ConnectionManager::getEvent(){ 119 119 if(!buffer.isEmpty()) … … 251 251 } 252 252 } 253 253 254 254 //### added some bugfixes here, but we cannot test them because 255 255 //### the server crashes everytime because of some gamestates … … 333 333 } 334 334 335 336 335 336 337 337 bool ConnectionManager::removeShip(ClientInformation *client){ 338 338 int id=client->getShipID(); 339 339 orxonox::Iterator<orxonox::SpaceShip> it; 340 for(it = orxonox::ObjectList<orxonox::SpaceShip>:: start(); it; ++it){340 for(it = orxonox::ObjectList<orxonox::SpaceShip>::begin(); it; ++it){ 341 341 if(it->objectID!=id) 342 342 continue; … … 345 345 return true; 346 346 } 347 347 348 348 bool ConnectionManager::sendWelcome(int clientID, int shipID, bool allowed){ 349 349 if(addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID)){ … … 353 353 return false; 354 354 } 355 355 356 356 void ConnectionManager::disconnectClient(ClientInformation *client){ 357 357 { … … 362 362 removeShip(client); 363 363 } 364 364 365 365 bool ConnectionManager::addFakeConnectRequest(ENetEvent *ev){ 366 366 ENetEvent event; … … 369 369 return buffer.push(&event); 370 370 } 371 372 371 372 373 373 374 374 } -
code/branches/core3/src/network/GameStateClient.cc
r1534 r1574 151 151 COUT(4) << "loadSnapshot: loading gs: " << state->id << std::endl; 152 152 // get the start of the Synchronisable list 153 orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>:: start();153 orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::begin(); 154 154 syncData sync; 155 155 // loop as long as we have some data ;) … … 236 236 int offset=0, size=0; 237 237 // get total size of gamestate 238 for(it = orxonox::ObjectList<Synchronisable>:: start(); it; ++it){238 for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it){ 239 239 if(!it->getBacksync()) 240 240 continue; … … 253 253 memsize=size; 254 254 // go through all Synchronisables 255 for(it = orxonox::ObjectList<Synchronisable>:: start(); it; ++it){255 for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it){ 256 256 if(!it->getBacksync()) 257 257 continue; -
code/branches/core3/src/network/GameStateManager.cc
r1534 r1574 70 70 return; 71 71 } 72 72 73 73 void GameStateManager::addGameState(GameStateCompressed *gs, int clientID){ 74 74 if(!gs) … … 83 83 return; 84 84 } 85 85 86 86 void GameStateManager::processGameStates(){ 87 87 std::map<int, GameStateCompressed*>::iterator it; … … 93 93 gameStateQueue.clear(); 94 94 } 95 96 95 96 97 97 /** 98 98 * this function is used to keep the memory usage low 99 99 * it tries to delete all the unused gamestates 100 * 101 * 100 * 101 * 102 102 */ 103 103 void GameStateManager::cleanup(){ … … 155 155 } 156 156 } 157 157 158 158 bool GameStateManager::pushGameState( GameStateCompressed *gs, int clientID ){ 159 159 GameState *ugs = decompress(gs); … … 190 190 int offset=0, size=0; 191 191 // get total size of gamestate 192 for(it = orxonox::ObjectList<Synchronisable>:: start(); it; ++it){192 for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it){ 193 193 size+=it->getSize(); // size of the actual data of the synchronisable 194 194 size+=3*sizeof(int); // size of datasize, classID and objectID … … 204 204 memsize=size; 205 205 // go through all Synchronisables 206 for(it = orxonox::ObjectList<Synchronisable>:: start(); it; ++it){206 for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it){ 207 207 //get size of the synchronisable 208 208 tempsize=it->getSize(); … … 246 246 COUT(4) << "loadSnapshot: loading gs: " << state->id << std::endl; 247 247 // get the start of the Synchronisable list 248 orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>:: start();248 orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::begin(); 249 249 syncData sync; 250 250 /*ClientInformation *client = head_->findClient(clientID); … … 308 308 return true; 309 309 } 310 311 310 311 312 312 //##### ADDED FOR TESTING PURPOSE ##### 313 313 GameStateCompressed* GameStateManager::testCompress( GameState* g ) { … … 405 405 switch ( retval ) { 406 406 case Z_OK: COUT(5) << "G.St.Man: compress: successfully compressed" << std::endl; break; 407 case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl; 407 case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl; 408 408 return NULL; 409 409 case Z_BUF_ERROR: COUT(2) << "G.St.Man: compress: not enough memory available in the buffer in gamestate.compress" << std::endl; … … 426 426 return compressedGamestate; 427 427 } 428 428 429 429 GameState *GameStateManager::decompress(GameStateCompressed *a) { 430 430 //COUT(4) << "GameStateClient: uncompressing gamestate. id: " << a->id << ", baseid: " << a->base_id << ", normsize: " << a->normsize << ", compsize: " << a->compsize << std::endl; … … 464 464 return gamestate; 465 465 } 466 466 467 467 468 468 void GameStateManager::ackGameState(int clientID, int gamestateID) { … … 471 471 return; 472 472 int curid = temp->getGamestateID(); 473 473 474 474 if(gamestateID == GAMESTATEID_INITIAL){ 475 475 temp->setGameStateID(GAMESTATEID_INITIAL); … … 481 481 } 482 482 if(curid > gamestateID) 483 // the network packets got messed up 483 // the network packets got messed up 484 484 return; 485 485 COUT(4) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl; … … 512 512 return true; 513 513 } 514 514 515 515 bool GameStateManager::checkAccess(int clientID, int objectID){ 516 516 // currently we only check, wheter the object is the clients spaceship … … 518 518 return true; // TODO: change this 519 519 } 520 520 521 521 void GameStateManager::removeClient(ClientInformation* client){ 522 522 if(!client) -
code/branches/core3/src/network/Server.cc
r1556 r1574 57 57 #define MAX_FAILURES 20; 58 58 #define NETWORK_FREQUENCY 30 59 59 60 60 Server *Server::instance_=0; 61 61 62 62 Server *Server::createSingleton(){ 63 63 if(!instance_) … … 80 80 return instance_; 81 81 } 82 82 83 83 Server *Server::getSingleton(){ 84 84 return instance_; 85 85 } 86 87 86 87 88 88 /** 89 89 * Constructor for default values (bindaddress is set to ENET_HOST_ANY … … 97 97 gamestates = new GameStateManager(clients); 98 98 } 99 99 100 100 Server::Server(int port){ 101 101 timeSinceLastUpdate_=0; … … 217 217 if(clients->findClient(&event->peer->address)){ 218 218 clientID = clients->findClient(&event->peer->address)->getID(); 219 if( !elaborate(event->packet, clientID) ) 219 if( !elaborate(event->packet, clientID) ) 220 220 COUT(3) << "Server: could not elaborate" << std::endl; 221 221 } … … 276 276 continue; 277 277 if ( !(connection->addPacket(packet, cid)) ){ 278 COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl; 278 COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl; 279 279 temp->addFailure(); 280 280 /*if(temp->getFailures() > 0 ) … … 302 302 delete data; 303 303 } 304 304 305 305 bool Server::processConnectRequest( connectRequest *con, int clientID ){ 306 306 //(COUT(3) << "processing connectRequest " << std::endl; … … 310 310 return true; 311 311 } 312 312 313 313 void Server::processGamestate( GameStateCompressed *data, int clientID){ 314 314 COUT(4) << "processing partial gamestate from client " << clientID << std::endl; … … 319 319 clients->findClient(clientID)->resetFailures();*/ 320 320 } 321 321 322 322 void Server::processChat( chat *data, int clientId){ 323 323 char *message = new char [strlen(data->message)+10+1]; … … 329 329 delete data; 330 330 } 331 331 332 332 bool Server::addClient(ENetEvent *event){ 333 333 ClientInformation *temp = clients->insertBack(new ClientInformation); … … 346 346 return createClient(temp->getID()); 347 347 } 348 348 349 349 bool Server::createClient(int clientID){ 350 350 ClientInformation *temp = clients->findClient(clientID); … … 366 366 return true; 367 367 } 368 368 369 369 bool Server::createShip(ClientInformation *client){ 370 370 if(!client) … … 390 390 no->classID = id->getNetworkID(); 391 391 no->create(); 392 392 393 393 client->setShipID(no->objectID); 394 394 return true; 395 395 } 396 396 397 397 bool Server::disconnectClient(ENetEvent *event){ 398 398 COUT(4) << "removing client from list" << std::endl; 399 399 //return removeClient(head_->findClient(&(peer->address))->getID()); 400 400 401 401 //boost::recursive_mutex::scoped_lock lock(head_->mutex_); 402 orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>:: start();402 orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>::begin(); 403 403 ClientInformation *client = clients->findClient(&event->peer->address); 404 404 if(!client) … … 426 426 gamestates->removeClient(client); 427 427 } 428 428 429 429 }
Note: See TracChangeset
for help on using the changeset viewer.