Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 28, 2010, 4:46:42 PM (14 years ago)
Author:
scheusso
Message:

again some structural changes in network to increase modularity/encapsulation
precondition for fixing client-disconnect bug

File:
1 edited

Legend:

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

    r7801 r7823  
    4747#include "Welcome.h"
    4848#include "network/Host.h"
    49 #include "network/ClientInformation.h"
     49// #include "network/ClientInformation.h"
    5050
    5151namespace orxonox{
     
    8585
    8686
    87 Packet::Packet(const Packet &p){
     87Packet::Packet(const Packet &p)
     88{
    8889  enetPacket_=p.enetPacket_;
    8990  flags_=p.flags_;
     
    104105    That also means destroying the ENetPacket if one exists. There
    105106*/
    106 Packet::~Packet(){
     107Packet::~Packet()
     108{
    107109  // Deallocate data_ memory if necessary.
    108   if (this->bDataENetAllocated_){
     110  if (this->bDataENetAllocated_)
     111  {
    109112    // In this case ENet allocated data_ and will destroy it.
    110113  }
    111   else if (this->data_) {
     114  else if (this->data_)
     115  {
    112116    // This destructor was probably called as a consequence of ENet executing our callback.
    113117    // It simply serves us to be able to deallocate the packet content (data_) ourselves since
     
    119123  // Note: For the case ENet used the callback to destroy the packet, we have already set
    120124  // enetPacket_ to NULL to avoid destroying it again.
    121   if (this->enetPacket_){
     125  if (this->enetPacket_)
     126  {
    122127    // enetPacket_->data gets destroyed too by ENet if it was allocated by it.
    123128    enet_packet_destroy(enetPacket_);
     
    125130}
    126131
    127 bool Packet::send(orxonox::Host* host){
    128   if(packetDirection_ != Direction::Outgoing && packetDirection_ != Direction::Bidirectional ){
     132bool Packet::send(orxonox::Host* host)
     133{
     134  if(packetDirection_ != Direction::Outgoing && packetDirection_ != Direction::Bidirectional )
     135  {
    129136    assert(0);
    130137    return false;
    131138  }
    132   if(!enetPacket_){
     139  if(!enetPacket_)
     140  {
    133141    if(!data_){
    134142      assert(0);
     
    175183}
    176184
    177 Packet *Packet::createPacket(ENetPacket *packet, ENetPeer *peer){
     185Packet *Packet::createPacket(ENetPacket* packet, uint32_t peerID)
     186{
    178187  uint8_t *data = packet->data;
    179   assert(ClientInformation::findClient(&peer->address)->getID() != static_cast<unsigned int>(-2) || !Host::isServer());
    180   unsigned int peerID = ClientInformation::findClient(&peer->address)->getID();
     188//   assert(ClientInformation::findClient(&peer->address)->getID() != static_cast<unsigned int>(-2) || !Host::isServer());
     189//   unsigned int peerID = ClientInformation::findClient(&peer->address)->getID();
    181190  // HACK
    182   if( peerID==static_cast<unsigned int>(-2))
    183     peerID = NETWORK_PEER_ID_SERVER;
     191//   if( peerID==static_cast<unsigned int>(-2))
     192//     peerID = NETWORK_PEER_ID_SERVER;
    184193  Packet *p = 0;
    185194//   COUT(6) << "packet type: " << *(Type::Value *)&data[_PACKETID] << std::endl;
     
    235244    data we allocated ourselves.
    236245*/
    237 void Packet::deletePacket(ENetPacket *enetPacket){
     246void Packet::deletePacket(ENetPacket *enetPacket)
     247{
    238248  // Get our Packet from a global map with all Packets created in the send() method of Packet.
    239249  Packet::packetMapMutex_.lock();
Note: See TracChangeset for help on using the changeset viewer.