Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 7, 2008, 4:39:42 PM (17 years ago)
Author:
scheusso
Message:

different enhancements in input/network handling and synchronisation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network3/src/network/ConnectionManager.cc

    r1234 r1245  
    165165    enet_initialize();
    166166    atexit(enet_deinitialize);
    167     ENetEvent event;
     167    ENetEvent *event = new ENetEvent;
    168168    server = enet_host_create(&bindAddress, NETWORK_MAX_CONNECTIONS, 0, 0);
    169169    if(server==NULL){
     
    174174
    175175    while(!quit){
    176       if(enet_host_service(server, &event, NETWORK_WAIT_TIMEOUT)<0){
     176      if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){
    177177        // we should never reach this point
    178178        quit=true;
    179179        // add some error handling here ========================
    180180      }
    181       switch(event.type){
     181      switch(event->type){
    182182        // log handling ================
    183183        case ENET_EVENT_TYPE_CONNECT:
    184           addClient(&event);
     184          addClient(event);
    185185          //this is a workaround to ensure thread safety
    186186          /*if(!addFakeConnectRequest(&event))
     
    191191          //std::cout << "received data" << std::endl;
    192192          COUT(5) << "Con.Man: receive event has occured" << std::endl;
    193           processData(&event);
     193          processData(event);
    194194          break;
    195195        case ENET_EVENT_TYPE_DISCONNECT:
    196           // add some error/log handling here
    197           clientDisconnect(event.peer);
     196          clientDisconnect(event->peer);
    198197          break;
    199198        case ENET_EVENT_TYPE_NONE:
    200199          break;
    201200      }
     201//       usleep(1000);
     202      //yield(); //TODO: find apropriate
    202203    }
    203204    disconnectClients();
     
    246247  bool ConnectionManager::clientDisconnect(ENetPeer *peer) {
    247248    COUT(4) << "removing client from list" << std::endl;
    248     return head_->removeClient(peer);
     249    return removeClient(head_->findClient(&(peer->address))->getID());
    249250  }
    250251/**
     
    311312    sendWelcome(temp->getID(), temp->getShipID(), true);
    312313    return true;
     314  }
     315 
     316  bool ConnectionManager::removeClient(int clientID){
     317    orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>::start();
     318    while(it){
     319      if(it->objectID!=head_->findClient(clientID)->getShipID()){
     320        ++it;
     321        continue;
     322      }
     323      orxonox::Iterator<orxonox::SpaceShip> temp=it;
     324      ++it;
     325      delete  *temp;
     326      return head_->removeClient(clientID);
     327    }
     328    return false;
    313329  }
    314330 
     
    335351   
    336352    client->setShipID(no->objectID);
    337     no->getFocus();
    338353    return true;
    339354  }
     
    342357    addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID);
    343358    sendPackets();
     359    return true;
    344360  }
    345361 
Note: See TracChangeset for help on using the changeset viewer.