Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 5, 2008, 11:32:42 PM (16 years ago)
Author:
scheusso
Message:

we use enetcallback for destroying packets now (unfortunately there are still some problems)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/network/Server.cc

    r1710 r1711  
    115115  bool Server::processChat(packet::Chat *message, unsigned int clientID){
    116116    ClientInformation *temp = ClientInformation::getBegin();
    117     packet::Packet *pkt;
    118117    while(temp){
    119       pkt = new packet::Packet(message);
    120       pkt->setClientID(temp->getID());
    121       if(!pkt->send())
     118      message->setClientID(temp->getID());
     119      if(!message->send())
    122120        COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
    123       delete pkt;
     121      temp = temp->next();
    124122    }
    125123    return message->process();
     
    134132    //TODO: change this (no informations about who wrote a message)
    135133    ClientInformation *temp = ClientInformation::getBegin();
    136     packet::Packet *pkt;
    137134    while(temp){
    138       pkt = new packet::Packet(chat);
    139       pkt->setClientID(temp->getID());
    140       if(!pkt->send())
     135      chat->setClientID(temp->getID());
     136      if(!chat->send())
    141137        COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
    142138    }
     
    230226
    231227  bool Server::processPacket( ENetPacket *packet, ENetPeer *peer ){
    232     packet::Packet p = packet::Packet(packet, peer);
    233     return p.getPacketContent()->process();
     228    packet::Packet *p = packet::Packet::createPacket(packet, peer);
     229    return p->process();
    234230  }
    235231 
     
    261257      }
    262258      //std::cout << "adding gamestate" << std::endl;
    263       packet::Packet packet(gs);
    264       packet.setClientID(cid);
    265       if ( !packet.send() ){
     259      gs->setClientID(cid);
     260      if ( !gs->send() ){
    266261        COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl;
    267262        temp->addFailure();
     
    270265      added=true;
    271266      temp=temp->next();
    272       delete gs;
     267      // gs gets automatically deleted by enet callback
    273268    }
    274269    /*if(added) {
     
    324319    COUT(3) << "sending welcome" << std::endl;
    325320    packet::Welcome *w = new packet::Welcome(temp->getID(), temp->getShipID());
    326     packet::Packet packet(w);
    327     assert(packet.send());
     321    w->setClientID(temp->getID());
     322    assert(w->send());
    328323    delete w;
    329324    return true;
Note: See TracChangeset for help on using the changeset viewer.