Changeset 1705 for code/branches/network/src/network/packet/Packet.cc
- Timestamp:
- Sep 4, 2008, 9:45:05 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/packet/Packet.cc
r1701 r1705 10 10 #include "ClassID.h" 11 11 #include "network/Host.h" 12 //#include "Gamestate.h"12 #include "core/CoreIncludes.h" 13 13 14 14 namespace network{ … … 39 39 clientID_ = ClientInformation::findClient(&peer->address)->getID(); 40 40 packetContent_ = createPacketContent(packet); 41 delete packet; 42 delete peer; 41 43 } 42 44 … … 49 51 } 50 52 53 void Packet::setPacketContent(PacketContent *content){ 54 packetContent_ = content; 55 if(enetPacket_){ 56 enet_packet_destroy(enetPacket_); 57 enetPacket_=0; 58 } 59 } 51 60 52 61 bool Packet::send(){ 53 if( !packetDirection_ == ENUM::Outgoing || !packetDirection_ == ENUM::Bidirectional )62 if(packetDirection_ != ENUM::Outgoing && packetDirection_ != ENUM::Bidirectional ) 54 63 return false; 55 64 if(!enetPacket_){ 56 65 if(!packetContent_) 57 66 return false; 67 COUT(3) << "creating packet with data: " << packetContent_->getData() << " size: " << packetContent_->getSize() << " and flags: " << packetContent_->getFlags() << std::endl; 58 68 enetPacket_ = enet_packet_create(packetContent_->getData(), packetContent_->getSize(), packetContent_->getFlags()); 59 69 } 60 70 network::Host::addPacket( enetPacket_, clientID_); 71 enetPacket_ = 0; // otherwise we have a double free because enet already handles the deallocation of the packet 61 72 return true; 62 73 } … … 73 84 break; 74 85 case ENUM::ClassID: 75 packetContent_ = new ClassID( data );86 packetContent_ = new ClassID( data, clientID_ ); 76 87 break; 77 88 case ENUM::Gamestate:
Note: See TracChangeset
for help on using the changeset viewer.