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)

Location:
code/branches/network/src/network
Files:
1 deleted
19 edited

Legend:

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

    r1710 r1711  
    123123  }
    124124 
    125   bool Client::sendChat(packet::Chat *chat){
     125  /*bool Client::sendChat(packet::Chat *chat){
    126126    chat->process();
    127127    packet::Packet *p = new packet::Packet(chat);
    128128    return p->send();
    129   }
     129  }*/
    130130 
    131131
     
    139139    if(!isConnected)
    140140      return false;
    141     packet::Packet p(new packet::Chat(message, clientID_));
    142     return p.send();
    143       //return client_connection.sendPackets();
     141    packet::Chat chat(message, 0);
     142    return chat.send();
    144143    // send packets
    145144  }
     
    155154      if(gs){
    156155        COUT(4) << "client tick: sending gs " << gs << std::endl;
    157         packet::Packet packet(gs);
    158         if( !packet.send() )
     156        if( !gs->send() )
    159157          COUT(3) << "Problem adding partial gamestate to queue" << std::endl;
    160         // now delete it to save memory
    161         delete gs;
     158        // gs gets automatically deleted by enet callback
    162159      }
    163160    }
     
    167164      event = client_connection.getEvent();
    168165      COUT(5) << "tick packet size " << event->packet->dataLength << std::endl;
    169       packet::Packet packet(event->packet, event->peer);
    170       assert(packet.getPacketContent()->process());
     166      packet::Packet *packet = packet::Packet::createPacket(event->packet, event->peer);
     167      assert(packet->process());
    171168    }
    172169    int gameStateID = gamestate.processGamestates();
     
    174171      if(gameStateFailure_){
    175172        packet::Acknowledgement ack(GAMESTATEID_INITIAL, 0);
    176         packet::Packet packet(&ack);
    177         if(!packet.send())
     173        if(!ack.send())
    178174          COUT(3) << "could not (negatively) ack gamestate" << std::endl;
    179175        else
     
    188184      gameStateFailure_=false;
    189185      packet::Acknowledgement ack(gameStateID, 0);
    190       packet::Packet packet(&ack);
    191       if(!packet.send())
     186      if(!ack.send())
    192187        COUT(3) << "could not ack gamestate" << std::endl;
    193188    }// otherwise we had no gamestate to load
  • code/branches/network/src/network/Client.h

    r1705 r1711  
    7474    bool queuePacket(ENetPacket *packet, int clientID);
    7575    bool processChat(packet::Chat *message, unsigned int clientID);
    76     bool sendChat(packet::Chat *chat);
     76    //bool sendChat(packet::Chat *chat);
    7777   
    7878//    static void Chat( std::string message );
  • code/branches/network/src/network/ConnectionManager.cc

    r1710 r1711  
    338338    std::string classname;
    339339    orxonox::Identifier *id;
    340     packet::Packet packet;
    341     packet.setClientID(clientID);
    342     packet::ClassID *classid;
    343340    std::map<std::string, orxonox::Identifier*>::const_iterator it = orxonox::Factory::getFactoryBegin();
    344341    while(it != orxonox::Factory::getFactoryEnd()){
     
    352349      COUT(4) << "Con.Man:syncClassid:\tnetwork_id: " << network_id << ", classname: " << classname << std::endl;
    353350
    354       classid = new packet::ClassID(network_id, classname);
    355       packet.setPacketContent(classid);
    356       while(!packet.send() && failures < 10){
     351      packet::ClassID classid( network_id, classname );
     352      classid.setClientID(clientID);
     353      while(!classid.send() && failures < 10){
    357354        failures++;
    358355      }
    359       delete classid;
    360356      ++it;
    361357    }
  • code/branches/network/src/network/Host.cc

    r1705 r1711  
    2828
    2929
    30 bool Host::chat(std::string& message){
    31   if(!instance_)
    32     return false;
    33   packet::Chat *c = new packet::Chat(message, getPlayerID());
    34   return instance_->sendChat(c);
    35 }
     30// bool Host::chat(std::string& message){
     31//   if(!instance_)
     32//     return false;
     33//   packet::Chat *c = new packet::Chat(message, getPlayerID());
     34//   return instance_->sendChat(c);
     35// }
    3636
    37 bool Host::receiveChat(network::packet::Chat *message, unsigned int clientID){
    38   if(instance_)
    39     return instance_->processChat(message, clientID);
    40   else
    41     return false;
    42 }
     37// bool Host::receiveChat(network::packet::Chat *message, unsigned int clientID){
     38//   if(instance_)
     39//     return instance_->processChat(message, clientID);
     40//   else
     41//     return false;
     42// }
    4343
    4444int Host::getPlayerID(){
  • code/branches/network/src/network/Host.h

    r1705 r1711  
    4242  private:
    4343    //TODO add theese functions or adequate
    44     virtual bool processChat(packet::Chat *message, unsigned int clientID)=0;
    45     virtual bool sendChat(packet::Chat *chat)=0;
     44    //virtual bool processChat(packet::Chat *message, unsigned int clientID)=0;
     45    //virtual bool sendChat(packet::Chat *chat)=0;
    4646    virtual bool queuePacket(ENetPacket *packet, int clientID)=0;
    4747    virtual unsigned int shipID()=0;
     
    5858    static bool running(){return instance_!=0;}
    5959    static bool addPacket(ENetPacket *packet, int clientID=0);
    60     static bool chat(std::string& message);
    61     static bool receiveChat(packet::Chat *message, unsigned int clientID);
     60    //static bool chat(std::string& message);
     61//     static bool receiveChat(packet::Chat *message, unsigned int clientID);
    6262    static int getPlayerID();
    6363    static unsigned int getShipID();
    64    
    65     // packet process functions
     64    static void setClientID(unsigned int id){ instance_->clientID_ = id; }
     65    static void setShipID(unsigned int id){ instance_->shipID_ = id; }
     66  private:
     67    unsigned int clientID_;
     68    unsigned int shipID_;
    6669};
    6770
  • code/branches/network/src/network/NetworkPrereqs.h

    r1705 r1711  
    8181    class Gamestate;
    8282    class Packet;
    83     class PacketContent;
    8483    class Acknowledgement;
    8584    class ClassID;
    8685    class Welcome;
     86    class Chat;
    8787  }
    8888}
  • 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;
  • code/branches/network/src/network/packet/Acknowledgement.cc

    r1705 r1711  
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Oliver Scheuss, (C) 2008
     24 *   Co-authors:
     25 *      ...
     26 *
     27 */
     28
     29
    130#include "Acknowledgement.h"
    2 #include "Packet.h"
    331#include "network/Host.h"
    432#include "network/GamestateHandler.h"
     
    1240 
    1341Acknowledgement::Acknowledgement( unsigned int id, int clientID )
    14  : PacketContent()
     42 : Packet()
    1543{
    1644  flags_ = flags_ | PACKET_FLAGS_ACK;
     
    2250
    2351Acknowledgement::Acknowledgement( unsigned char *data, int clientID )
    24   : PacketContent(data, clientID)
     52  : Packet(data, clientID)
    2553{
    26   clientID_=clientID;
    2754}
    2855
    2956Acknowledgement::~Acknowledgement()
    3057{
    31 }
    32 
    33 unsigned char *Acknowledgement::getData(){
    34   return data_;
    3558}
    3659
     
    4063
    4164bool Acknowledgement::process(){
    42   return GamestateHandler::ackGamestate(data_[_ACKID], clientID_);
     65  bool b = GamestateHandler::ackGamestate(data_[_ACKID], clientID_);
     66  delete this;
     67  return b;
    4368}
    4469
  • code/branches/network/src/network/packet/Acknowledgement.h

    r1705 r1711  
    2929#define NETWORKACKNOLEDGEMENT_H
    3030
    31 #include "PacketContent.h"
     31#include "Packet.h"
    3232
    3333
     
    3737        @author
    3838*/
    39 class Acknowledgement : public PacketContent
     39class Acknowledgement : public Packet
    4040{
    4141public:
     
    4444  ~Acknowledgement();
    4545 
    46   unsigned char *getData();
    4746  inline unsigned int getSize() const;
    4847  bool process();
  • code/branches/network/src/network/packet/Chat.cc

    r1705 r1711  
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Oliver Scheuss <scheusso [at] ee.ethz.ch>, (C) 2008
     24 *   Co-authors:
     25 *      ...
     26 *
     27 */
     28
    129#include "Chat.h"
    2 #include "Packet.h"
     30#include <assert.h>
    331
    432namespace network {
     
    1139
    1240Chat::Chat( std::string& message, int clientID )
    13  : PacketContent()
     41 : Packet()
    1442{
    1543  flags_ = flags_ | PACKET_FLAGS_CHAT;
     
    2351
    2452Chat::Chat( unsigned char *data, int clientID )
    25   : PacketContent(data, clientID)
     53  : Packet(data, clientID)
    2654{
    2755  messageLength_ = *(unsigned int *)&data[ _MESSAGELENGTH ];
     
    3260}
    3361
    34 unsigned char *Chat::getData(){
    35   return data_;
    36 }
    37 
    3862unsigned int Chat::getSize() const{
    3963  return _MESSAGE + messageLength_;
     
    4266bool Chat::process(){
    4367  //TODO: change this !!!
     68  assert(0);
     69  delete this;
    4470  return true;
    4571}
  • code/branches/network/src/network/packet/Chat.h

    r1701 r1711  
    1 /*
    2  *   ORXONOX - the hottest 3D action shooter ever to exist
    3  *                    > www.orxonox.net <
    4  *
    5  *
    6  *   License notice:
    7  *
    8  *   This program is free software; you can redistribute it and/or
    9  *   modify it under the terms of the GNU General Public License
    10  *   as published by the Free Software Foundation; either version 2
    11  *   of the License, or (at your option) any later version.
    12  *
    13  *   This program is distributed in the hope that it will be useful,
    14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  *   GNU General Public License for more details.
    17  *
    18  *   You should have received a copy of the GNU General Public License
    19  *   along with this program; if not, write to the Free Software
    20  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    21  *
    22  *   Author:
    23  *      Oliver Scheuss <scheusso [at] ee.ethz.ch>, (C) 2008
    24  *   Co-authors:
    25  *      ...
    26  *
    27  */
     1
    282#ifndef NETWORKCHAT_H
    293#define NETWORKCHAT_H
     
    315#include <string>
    326
    33 #include "PacketContent.h"
     7#include "Packet.h"
    348
    359namespace network {
     
    3812        @author
    3913*/
    40 class Chat : public PacketContent
     14class Chat : public Packet
    4115{
    4216public:
     
    4519  ~Chat();
    4620 
    47   unsigned char *getData();
    4821  inline unsigned int getSize() const;
    4922  bool process();
  • code/branches/network/src/network/packet/ClassID.cc

    r1708 r1711  
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Oliver Scheuss, (C) 2008
     24 *   Co-authors:
     25 *      ...
     26 *
     27 */
     28
     29
     30
    131#include "ClassID.h"
    2 #include "Packet.h"
    332#include "core/CoreIncludes.h"
    433#include <string>
     
    1544 
    1645  ClassID::ClassID( unsigned int classID, std::string className )
    17  : PacketContent()
     46 : Packet()
    1847{
    1948  flags_ = flags_ | PACKET_FLAGS_CLASSID;
     
    2958
    3059ClassID::ClassID( unsigned char *data, int clientID )
    31   : PacketContent(data, clientID)
     60  : Packet(data, clientID)
    3261{
    3362  memcpy( (void *)&classNameLength_, &data[ _CLASSNAMELENGTH ], sizeof(classNameLength_) );
     
    3665ClassID::~ClassID()
    3766{
    38 }
    39 
    40 unsigned char *ClassID::getData(){
    41   return data_;
    4267}
    4368
     
    5176    return false;
    5277  id->setNetworkID( getClassID() );
     78  delete this;
    5379  return true;
    5480}
     
    5884}
    5985
    60 // unsigned int ClassID::getClassNameLength(){
    61 //   return *(unsigned int *)&data[ _CLASSNAMELENGTH ];
    62 // }
    63 
    6486} //namespace packet
    6587}//namespace network
  • code/branches/network/src/network/packet/ClassID.h

    r1705 r1711  
    3131#include <string>
    3232
    33 #include "PacketContent.h"
     33#include "Packet.h"
    3434
    3535namespace network {
     
    3939        @author
    4040*/
    41 class ClassID : public PacketContent
     41class ClassID : public Packet
    4242{
    4343public:
     
    4646  ~ClassID();
    4747 
    48   unsigned char *getData();
    4948  inline unsigned int getSize() const;
    5049  bool process();
  • code/branches/network/src/network/packet/Gamestate.cc

    r1710 r1711  
     1
     2
     3
     4
     5
     6
     7
     8
     9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19/*
     20 *   ORXONOX - the hottest 3D action shooter ever to exist
     21 *                    > www.orxonox.net <
     22 *
     23 *
     24 *   License notice:
     25 *
     26 *   This program is free software; you can redistribute it and/or
     27 *   modify it under the terms of the GNU General Public License
     28 *   as published by the Free Software Foundation; either version 2
     29 *   of the License, or (at your option) any later version.
     30 *
     31 *   This program is distributed in the hope that it will be useful,
     32 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     33 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     34 *   GNU General Public License for more details.
     35 *
     36 *   You should have received a copy of the GNU General Public License
     37 *   along with this program; if not, write to the Free Software
     38 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     39 *
     40 *   Author:
     41 *      Oliver Scheuss, (C) 2008
     42 *   Co-authors:
     43 *      ...
     44 *
     45 */
     46
    147#include "Gamestate.h"
    248#include "network/ClientInformation.h"
     
    2268
    2369Gamestate::Gamestate(unsigned char *data, bool compressed, int clientID):
    24     PacketContent(data, clientID)
     70    Packet(data, clientID)
    2571{
    2672  compressed_ = compressed;
    27   //GAMESTATE_HEADER = (GamestateHeader *)data;
    28   //if(!compressed)
    29     //bs_ = new Bytestream(data+sizeof(GamestateHeader), GAMESTATE_HEADER->compsize);
    3073}
    3174
     
    138181}
    139182
    140 unsigned char *Gamestate::getData()
    141 {
    142   assert(data_!=0);
    143   return data_;
    144 }
    145 
    146183unsigned int Gamestate::getSize() const
    147184{
     185  assert(data_);
    148186  if(compressed_)
    149187    return HEADER->compsize+sizeof(GamestateHeader);
  • code/branches/network/src/network/packet/Gamestate.h

    r1710 r1711  
    2727 */
    2828
    29 #include "PacketContent.h"
    3029#include "Packet.h"
    3130#include "network/Synchronisable.h"
     
    5352        @author
    5453*/
    55 class Gamestate: public PacketContent{
     54class Gamestate: public Packet{
    5655  public:
    5756    Gamestate();
     
    6867    bool decompressData();
    6968   
    70     // PacketContent functions
    71     virtual unsigned char *getData();
     69    // Packet functions
    7270    virtual unsigned int getSize() const;
    7371    virtual bool process();
  • code/branches/network/src/network/packet/Packet.cc

    r1710 r1711  
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Oliver Scheuss, (C) 2008
     24 *   Co-authors:
     25 *      ...
     26 *
     27 */
     28
    129
    230#include <enet/enet.h>
     31#include <boost/bind.hpp>
    332
    433#include "Packet.h"
     
    1039#include "ClassID.h"
    1140#include "Gamestate.h"
     41#include "Welcome.h"
    1242#include "network/Host.h"
    1343#include "core/CoreIncludes.h"
     
    1747namespace packet{
    1848 
     49#define PACKET_FLAG_DEFAULT ENET_PACKET_FLAG_NO_ALLOCATE
    1950#define _PACKETID           0
    2051 
    21 
     52std::map<ENetPacket *, Packet *> Packet::packetMap_;
    2253 
    2354Packet::Packet(){
     55  flags_ = PACKET_FLAG_DEFAULT;
    2456  packetDirection_ = ENUM::Outgoing;
    2557  clientID_=0;
    26   packetContent_=0;
     58  data_=0;
    2759  enetPacket_=0;
    2860}
    2961
    30 Packet::Packet(PacketContent *content){
     62Packet::Packet(unsigned char *data, int clientID){
     63  flags_ = PACKET_FLAG_DEFAULT;
    3164  packetDirection_ = ENUM::Outgoing;
    32   clientID_=0;
    33   packetContent_=content;
     65  clientID_=clientID;
     66  data_=data;
    3467  enetPacket_=0;
    3568}
     
    3972  enetPacket_ = packet;
    4073  clientID_ = ClientInformation::findClient(&peer->address)->getID();
    41   packetContent_ = createPacketContent(packet);
     74  data_ = packet->data;
    4275  enet_packet_destroy(packet);
    4376}
    4477
    45 Packet::~Packet(){
    46   if(enetPacket_){
    47     enet_packet_destroy(enetPacket_);
    48   }
     78Packet::Packet(const Packet &p){
     79  flags_=p.flags_;
     80  if(p.data_){
     81    data_ = new unsigned char[p.getSize()];
     82    memcpy(data_, p.data_, p.getSize());
     83  }else
     84    data_=0;
    4985}
    5086
    51 void Packet::setPacketContent(PacketContent *content){
    52   packetContent_ = content;
    53   if(enetPacket_){
     87Packet::~Packet(){
     88  if(enetPacket_)
    5489    enet_packet_destroy(enetPacket_);
    55     enetPacket_=0;
    56   }
     90  if(data_)
     91    delete[] data_;
    5792}
    5893
     
    6196    return false;
    6297  if(!enetPacket_){
    63     if(!packetContent_)
     98    if(!data_)
    6499      return false;
    65     enetPacket_ = enet_packet_create(packetContent_->getData(), packetContent_->getSize(), packetContent_->getFlags());
     100    enetPacket_ = enet_packet_create(getData(), getSize(), getFlags());
     101    enetPacket_->freeCallback = &Packet::deletePacket;
     102    packetMap_[enetPacket_] = this;
    66103  }
    67104  network::Host::addPacket( enetPacket_, clientID_);
     
    70107}
    71108
    72 PacketContent *Packet::createPacketContent(ENetPacket *packet){
     109Packet *Packet::createPacket(ENetPacket *packet, ENetPeer *peer){
    73110  unsigned char *data = packet->data;
     111  unsigned int clientID = ClientInformation::findClient(&peer->address)->getID();
     112  Packet *p;
    74113  switch( *(ENUM::Type *)&data[_PACKETID] )
    75114  {
    76115    case ENUM::Acknowledgement:
    77       packetContent_ = new Acknowledgement( data, clientID_ );
     116      p = new Acknowledgement( data, clientID );
    78117      break;
    79118    case ENUM::Chat:
    80       packetContent_ = new Chat( data, clientID_ );
     119      p = new Chat( data, clientID );
    81120      break;
    82121    case ENUM::ClassID:
    83       packetContent_ = new ClassID( data, clientID_ );
     122      p = new ClassID( data, clientID );
    84123      break;
    85124    case ENUM::Gamestate:
    86125      // TODO: remove brackets
    87       packetContent_ = new Gamestate( data, true, clientID_ );
     126      p = new Gamestate( data, true, clientID );
    88127      break;
     128    case ENUM::Welcome:
     129      p = new Welcome( data, clientID );
    89130    default:
    90131      assert(0); //TODO: repair this
    91132      break;
    92133  }
    93   return packetContent_;
     134  return p;
     135}
     136
     137void Packet::deletePacket(ENetPacket *packet){
     138  assert(packetMap_[packet]);
     139  delete packetMap_[packet];
    94140}
    95141
  • code/branches/network/src/network/packet/Packet.h

    r1709 r1711  
    2929#define NETWORKPACKET_H
    3030
    31 #include "PacketContent.h"
    32 
     31#include <map>
    3332#include <enet/enet.h>
    3433
     
    5756class Packet{
    5857  public:
    59     Packet();
    60     Packet(PacketContent *content);
    61     Packet(ENetPacket *packet, ENetPeer *peer);
     58    Packet(const Packet &p);
    6259    virtual ~Packet();
     60    static Packet *createPacket(ENetPacket *packet, ENetPeer *peer);
     61    static void deletePacket(ENetPacket *packet);
    6362   
    64     int getClientID(){ return clientID_; }
    65     PacketContent *getPacketContent(){ return packetContent_; }
    66    
    67     void setClientID( int id ){ clientID_ = id; }
    68     void setPacketContent(PacketContent *content);
     63    virtual unsigned char *getData(){ return data_; };
     64    virtual unsigned int getSize() const =0;
     65    virtual bool process()=0;
     66    enet_uint32 getFlags()
     67      { return flags_; }
     68    int getClientID()
     69      { return clientID_; }
     70    void setClientID( int id )
     71      { clientID_ = id; }
    6972   
    7073    bool send();
    7174  protected:
     75    Packet();
     76    Packet(unsigned char *data, int clientID);
     77    Packet(ENetPacket *packet, ENetPeer *peer);
     78    enet_uint32 flags_;
     79    int clientID_;
     80    unsigned char *data_;
    7281  private:
    73     PacketContent *createPacketContent(ENetPacket *packet);
    74    
    75     int clientID_;
    76     PacketContent *packetContent_;
     82    static std::map<ENetPacket *, Packet *> packetMap_;
    7783    ENetPacket *enetPacket_;
    7884    ENUM::Direction packetDirection_;
  • code/branches/network/src/network/packet/Welcome.cc

    r1709 r1711  
     1
     2
     3/*
     4 *   ORXONOX - the hottest 3D action shooter ever to exist
     5 *                    > www.orxonox.net <
     6 *
     7 *
     8 *   License notice:
     9 *
     10 *   This program is free software; you can redistribute it and/or
     11 *   modify it under the terms of the GNU General Public License
     12 *   as published by the Free Software Foundation; either version 2
     13 *   of the License, or (at your option) any later version.
     14 *
     15 *   This program is distributed in the hope that it will be useful,
     16 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     17 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     18 *   GNU General Public License for more details.
     19 *
     20 *   You should have received a copy of the GNU General Public License
     21 *   along with this program; if not, write to the Free Software
     22 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     23 *
     24 *   Author:
     25 *      Oliver Scheuss, (C) 2008
     26 *   Co-authors:
     27 *      ...
     28 *
     29 */
     30
     31
    132#include "Welcome.h"
    2 #include "Packet.h"
     33#include "network/Host.h"
    334#include <assert.h>
    435
     
    1243 
    1344  Welcome::Welcome( unsigned int clientID, unsigned int shipID )
    14  : PacketContent()
     45 : Packet()
    1546{
    1647  flags_ = flags_ | PACKET_FLAGS_CLASSID;
     
    2455
    2556Welcome::Welcome( unsigned char *data, int clientID )
    26   : PacketContent(data, clientID)
     57  : Packet(data, clientID)
    2758{
    2859}
     
    4475  clientID = *(unsigned int *)&data_[ _CLIENTID ];
    4576  shipID = *(unsigned int *)&data_[ _SHIPID ];
     77  Host::setClientID(clientID);
     78  Host::setShipID(shipID);
     79  delete this;
    4680  return true;
    4781}
  • code/branches/network/src/network/packet/Welcome.h

    r1709 r1711  
    2929#define NETWORKWELCOME_H
    3030
    31 #include "PacketContent.h"
     31#include "Packet.h"
    3232
    3333namespace network {
     
    3737        @author
    3838*/
    39 class Welcome : public PacketContent
     39class Welcome : public Packet
    4040{
    4141public:
Note: See TracChangeset for help on using the changeset viewer.