Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 15, 2008, 10:08:41 PM (16 years ago)
Author:
scheusso
Message:

a huge fix in packetbuffer

File:
1 edited

Legend:

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

    r1282 r1299  
    101101    ENetPacket *packet=getPacket(address);
    102102    ClientInformation *temp =head_->findClient(&address);
     103    if(!temp)
     104      return NULL;
    103105    clientID=temp->getID();
    104106    return packet;
     
    124126
    125127  bool ConnectionManager::addPacket(ENetPacket *packet, ENetPeer *peer) {
    126     if(enet_peer_send(peer, (enet_uint8)head_->findClient(&(peer->address))->getID() , packet)!=0)
     128    ClientInformation *temp = head_->findClient(&(peer->address));
     129    if(!temp)
     130      return false;
     131    if(enet_peer_send(peer, (enet_uint8)temp->getID() , packet)!=0)
    127132      return false;
    128133    return true;
     
    130135
    131136  bool ConnectionManager::addPacket(ENetPacket *packet, int clientID) {
    132     if(enet_peer_send(head_->findClient(clientID)->getPeer(), (enet_uint8)clientID, packet)!=0)
     137    ClientInformation *temp = head_->findClient(clientID);
     138    if(!temp)
     139      return false;
     140    if(enet_peer_send(temp->getPeer(), (enet_uint8)clientID, packet)!=0)
    133141      return false;
    134142    return true;
     
    195203          if(head_->findClient(&event->peer->address))
    196204            processData(event);
     205          else
     206            COUT(3) << "received a packet from a client we don't know" << std::endl;
    197207          break;
    198208        case ENET_EVENT_TYPE_DISCONNECT:
     
    233243      case ENET_EVENT_TYPE_DISCONNECT:
    234244        COUT(4) << "disconnecting all clients" << std::endl;
    235         delete head_->findClient(&(event.peer->address));
     245        if(head_->findClient(&(event.peer->address)))
     246          delete head_->findClient(&(event.peer->address));
    236247        //maybe needs bugfix: might also be a reason for the server to crash
    237248        temp = temp->next();
     
    259270  bool ConnectionManager::addClient(ENetEvent *event) {
    260271    ClientInformation *temp = head_->insertBack(new ClientInformation);
     272    if(!temp){
     273      COUT(2) << "Conn.Man. could not add client" << std::endl;
     274      return false;
     275    }
    261276    if(temp->prev()->head) { //not good if you use anything else than insertBack
    262277      temp->prev()->setID(0); //bugfix: not necessary but usefull
     
    266281      temp->setID(temp->prev()->getID()+1);
    267282    temp->setPeer(event->peer);
    268     COUT(4) << "Con.Man: added client id: " << temp->getID() << std::endl;
     283    COUT(3) << "Con.Man: added client id: " << temp->getID() << std::endl;
    269284    return true;
    270285  }
     
    283298
    284299  void ConnectionManager::syncClassid(int clientID) {
    285     unsigned int network_id=0;
     300    unsigned int network_id=0, failures=0;
    286301    std::string classname;
    287302    orxonox::Identifier *id;
     
    295310      COUT(4) << "Con.Man:syncClassid:\tnetwork_id: " << network_id << ", classname: " << classname << std::endl;
    296311
    297       addPacket(packet_gen.clid( (int)network_id, classname ), clientID);
    298 
     312      while(!addPacket(packet_gen.clid( (int)network_id, classname ), clientID) && failures < 10){
     313        failures++;
     314      }
    299315      ++it;
    300316    }
     
    305321  bool ConnectionManager::createClient(int clientID){
    306322    ClientInformation *temp = head_->findClient(clientID);
     323    if(!temp){
     324      COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl;
     325      return false;
     326    }
    307327    COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl;
    308328    syncClassid(temp->getID());
    309329    COUT(4) << "creating spaceship for clientid: " << temp->getID() << std::endl;
    310330    // TODO: this is only a hack, untill we have a possibility to define default player-join actions
    311     createShip(temp);
    312     COUT(4) << "created spaceship" << std::endl;
     331    if(!createShip(temp))
     332      COUT(2) << "Con.Man. could not create ship for clientid: " << clientID << std::endl;
     333    else
     334      COUT(3) << "created spaceship" << std::endl;
    313335    temp->setSynched(true);
    314     COUT(4) << "sending welcome" << std::endl;
     336    COUT(3) << "sending welcome" << std::endl;
    315337    sendWelcome(temp->getID(), temp->getShipID(), true);
    316338    return true;
     
    319341  bool ConnectionManager::removeClient(int clientID){
    320342    orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>::start();
     343    ClientInformation *client = head_->findClient(clientID);
     344    if(!client)
     345      return false;
    321346    while(it){
    322       if(it->objectID!=head_->findClient(clientID)->getShipID()){
     347      if(it->objectID!=client->getShipID()){
    323348        ++it;
    324349        continue;
     
    333358 
    334359  bool ConnectionManager::createShip(ClientInformation *client){
     360    if(!client)
     361      return false;
    335362    orxonox::Identifier* id = ID("SpaceShip");
    336363    if(!id){
     
    369396 
    370397  bool ConnectionManager::sendWelcome(int clientID, int shipID, bool allowed){
    371     addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID);
    372     sendPackets();
    373     return true;
     398    if(addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID)){
     399      sendPackets();
     400      return true;
     401    }else
     402      return false;
    374403  }
    375404 
Note: See TracChangeset for help on using the changeset viewer.