Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 4, 2008, 9:45:05 PM (16 years ago)
Author:
scheusso
Message:

further changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/network/packet/Packet.cc

    r1701 r1705  
    1010#include "ClassID.h"
    1111#include "network/Host.h"
    12 //#include "Gamestate.h"
     12#include "core/CoreIncludes.h"
    1313
    1414namespace network{
     
    3939  clientID_ = ClientInformation::findClient(&peer->address)->getID();
    4040  packetContent_ = createPacketContent(packet);
     41  delete packet;
     42  delete peer;
    4143}
    4244
     
    4951}
    5052
     53void Packet::setPacketContent(PacketContent *content){
     54  packetContent_ = content;
     55  if(enetPacket_){
     56    enet_packet_destroy(enetPacket_);
     57    enetPacket_=0;
     58  }
     59}
    5160
    5261bool Packet::send(){
    53   if(!packetDirection_ == ENUM::Outgoing || !packetDirection_ == ENUM::Bidirectional )
     62  if(packetDirection_ != ENUM::Outgoing && packetDirection_ != ENUM::Bidirectional )
    5463    return false;
    5564  if(!enetPacket_){
    5665    if(!packetContent_)
    5766      return false;
     67    COUT(3) << "creating packet with data: " << packetContent_->getData() << " size: " << packetContent_->getSize() << " and flags: " << packetContent_->getFlags() << std::endl;
    5868    enetPacket_ = enet_packet_create(packetContent_->getData(), packetContent_->getSize(), packetContent_->getFlags());
    5969  }
    6070  network::Host::addPacket( enetPacket_, clientID_);
     71  enetPacket_ = 0; // otherwise we have a double free because enet already handles the deallocation of the packet
    6172  return true;
    6273}
     
    7384      break;
    7485    case ENUM::ClassID:
    75       packetContent_ = new ClassID( data );
     86      packetContent_ = new ClassID( data, clientID_ );
    7687      break;
    7788    case ENUM::Gamestate:
Note: See TracChangeset for help on using the changeset viewer.