Changeset 1499 for code/branches/network/src/network/ConnectionManager.cc
- Timestamp:
- Jun 1, 2008, 1:44:44 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/ConnectionManager.cc
r1497 r1499 169 169 } 170 170 171 // we actually dont need that function, because host_service does that for us 171 172 bool ConnectionManager::sendPackets() { 172 173 if(server==NULL) … … 194 195 } 195 196 197 event = new ENetEvent; 196 198 while(!quit){ 197 event = new ENetEvent;198 199 { //mutex scope 199 200 boost::recursive_mutex::scoped_lock lock(enet_mutex_); … … 221 222 //if(head_->findClient(&event->peer->address)) 222 223 processData(event); 224 event = new ENetEvent; 223 225 // else 224 226 // COUT(3) << "received a packet from a client we don't know" << std::endl; … … 228 230 //break; 229 231 case ENET_EVENT_TYPE_NONE: 230 delete event;231 receiverThread_->yield();232 //receiverThread_->yield(); 233 usleep(1000); 232 234 break; 233 235 } … … 287 289 } 288 290 289 /** 290 This function adds a client that connects to the clientlist of the server 291 NOTE: if you change this, don't forget to change the test function 292 addClientTest in diffTest.cc since addClient is not good for testing because of syncClassid 293 */ 294 /*bool ConnectionManager::addClient(ENetEvent *event) { 295 ClientInformation *temp = head_->insertBack(new ClientInformation); 296 if(!temp){ 297 COUT(2) << "Conn.Man. could not add client" << std::endl; 298 return false; 299 } 300 if(temp->prev()->getHead()) { //not good if you use anything else than insertBack 301 temp->prev()->setID(0); //bugfix: not necessary but usefull 302 temp->setID(1); 303 } 304 else 305 temp->setID(temp->prev()->getID()+1); 306 temp->setPeer(event->peer); 307 COUT(3) << "Con.Man: added client id: " << temp->getID() << std::endl; 308 return true; 309 }*/ 291 310 292 311 293 int ConnectionManager::getClientID(ENetPeer peer) { … … 341 323 ++it; 342 324 } 343 sendPackets();325 //sendPackets(); 344 326 COUT(4) << "syncClassid:\tall synchClassID packets have been sent" << std::endl; 345 327 } 346 328 347 /*bool ConnectionManager::createClient(int clientID){ 348 ClientInformation *temp = head_->findClient(clientID); 349 if(!temp){ 350 COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl; 351 return false; 352 } 353 COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl; 354 syncClassid(temp->getID()); 355 COUT(4) << "creating spaceship for clientid: " << temp->getID() << std::endl; 356 // TODO: this is only a hack, until we have a possibility to define default player-join actions 357 if(!createShip(temp)) 358 COUT(2) << "Con.Man. could not create ship for clientid: " << clientID << std::endl; 359 else 360 COUT(3) << "created spaceship" << std::endl; 361 temp->setSynched(true); 362 COUT(3) << "sending welcome" << std::endl; 363 sendWelcome(temp->getID(), temp->getShipID(), true); 364 return true; 365 }*/ 366 367 /*bool ConnectionManager::removeClient(int clientID){ 368 boost::recursive_mutex::scoped_lock lock(head_->mutex_); 369 orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>::start(); 370 ClientInformation *client = head_->findClient(clientID); 371 if(!client) 372 return false; 373 while(it){ 374 if(it->objectID!=client->getShipID()){ 375 ++it; 376 continue; 377 } 378 orxonox::Iterator<orxonox::SpaceShip> temp=it; 379 ++it; 380 delete *temp; 381 return head_->removeClient(clientID); 382 } 383 return false; 384 }*/ 385 386 /* bool ConnectionManager::createShip(ClientInformation *client){ 387 if(!client) 388 return false; 389 orxonox::Identifier* id = ID("SpaceShip"); 390 if(!id){ 391 COUT(4) << "We could not create the SpaceShip for client: " << client->getID() << std::endl; 392 return false; 393 } 394 orxonox::SpaceShip *no = dynamic_cast<orxonox::SpaceShip *>(id->fabricate()); 395 no->setPosition(orxonox::Vector3(0,0,80)); 396 no->setScale(10); 397 //no->setYawPitchRoll(orxonox::Degree(-90),orxonox::Degree(-90),orxonox::Degree(0)); 398 no->setMesh("assff.mesh"); 399 no->setMaxSpeed(500); 400 no->setMaxSideAndBackSpeed(50); 401 no->setMaxRotation(1.0); 402 no->setTransAcc(200); 403 no->setRotAcc(3.0); 404 no->setTransDamp(75); 405 no->setRotDamp(1.0); 406 no->setCamera("cam_"+client->getID()); 407 no->classID = id->getNetworkID(); 408 no->create(); 409 410 client->setShipID(no->objectID); 411 return true; 412 }*/ 329 413 330 414 331 bool ConnectionManager::removeShip(ClientInformation *client){ … … 425 342 bool ConnectionManager::sendWelcome(int clientID, int shipID, bool allowed){ 426 343 if(addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID)){ 427 sendPackets();344 //sendPackets(); 428 345 return true; 429 346 }else … … 448 365 449 366 450 // int ConnectionManager::getNumberOfClients() { 451 // 452 // return clientsShip.size(); 453 // } 454 455 /*void ConnectionManager::addClientsObjectID( int clientID, int objectID ) { 456 COUT(4) << "ship of client: " << clientID << ": " << objectID << " mapped" << std::endl; 457 clientsShip.insert( std::make_pair( clientID, objectID ) ); 367 458 368 } 459 460 int ConnectionManager::getClientsShipID( int clientID ) {461 return clientsShip[clientID];462 }463 464 int ConnectionManager::getObjectsClientID( int objectID ) {465 std::map<int, int>::iterator iter;466 for( iter = clientsShip.begin(); iter != clientsShip.end(); iter++ ) {467 if( iter->second == objectID ) return iter->first;468 }469 return -99;470 }471 472 void ConnectionManager::deleteClientIDReg( int clientID ) {473 clientsShip.erase( clientID );474 }475 476 void ConnectionManager::deleteObjectIDReg( int objectID ) {477 std::map<int, int>::iterator iter = clientsShip.begin();478 for( iter = clientsShip.begin(); iter != clientsShip.end(); iter++ ) {479 if( iter->second == objectID ) break;480 }481 clientsShip.erase( iter->first );482 }*/483 }
Note: See TracChangeset
for help on using the changeset viewer.