Changeset 1711 for code/branches/network/src/network/packet
- Timestamp:
- Sep 5, 2008, 11:32:42 PM (16 years ago)
- Location:
- code/branches/network/src/network/packet
- Files:
-
- 1 deleted
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
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 1 30 #include "Acknowledgement.h" 2 #include "Packet.h"3 31 #include "network/Host.h" 4 32 #include "network/GamestateHandler.h" … … 12 40 13 41 Acknowledgement::Acknowledgement( unsigned int id, int clientID ) 14 : Packet Content()42 : Packet() 15 43 { 16 44 flags_ = flags_ | PACKET_FLAGS_ACK; … … 22 50 23 51 Acknowledgement::Acknowledgement( unsigned char *data, int clientID ) 24 : Packet Content(data, clientID)52 : Packet(data, clientID) 25 53 { 26 clientID_=clientID;27 54 } 28 55 29 56 Acknowledgement::~Acknowledgement() 30 57 { 31 }32 33 unsigned char *Acknowledgement::getData(){34 return data_;35 58 } 36 59 … … 40 63 41 64 bool Acknowledgement::process(){ 42 return GamestateHandler::ackGamestate(data_[_ACKID], clientID_); 65 bool b = GamestateHandler::ackGamestate(data_[_ACKID], clientID_); 66 delete this; 67 return b; 43 68 } 44 69 -
code/branches/network/src/network/packet/Acknowledgement.h
r1705 r1711 29 29 #define NETWORKACKNOLEDGEMENT_H 30 30 31 #include "Packet Content.h"31 #include "Packet.h" 32 32 33 33 … … 37 37 @author 38 38 */ 39 class Acknowledgement : public Packet Content39 class Acknowledgement : public Packet 40 40 { 41 41 public: … … 44 44 ~Acknowledgement(); 45 45 46 unsigned char *getData();47 46 inline unsigned int getSize() const; 48 47 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 1 29 #include "Chat.h" 2 #include "Packet.h"30 #include <assert.h> 3 31 4 32 namespace network { … … 11 39 12 40 Chat::Chat( std::string& message, int clientID ) 13 : Packet Content()41 : Packet() 14 42 { 15 43 flags_ = flags_ | PACKET_FLAGS_CHAT; … … 23 51 24 52 Chat::Chat( unsigned char *data, int clientID ) 25 : Packet Content(data, clientID)53 : Packet(data, clientID) 26 54 { 27 55 messageLength_ = *(unsigned int *)&data[ _MESSAGELENGTH ]; … … 32 60 } 33 61 34 unsigned char *Chat::getData(){35 return data_;36 }37 38 62 unsigned int Chat::getSize() const{ 39 63 return _MESSAGE + messageLength_; … … 42 66 bool Chat::process(){ 43 67 //TODO: change this !!! 68 assert(0); 69 delete this; 44 70 return true; 45 71 } -
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 28 2 #ifndef NETWORKCHAT_H 29 3 #define NETWORKCHAT_H … … 31 5 #include <string> 32 6 33 #include "Packet Content.h"7 #include "Packet.h" 34 8 35 9 namespace network { … … 38 12 @author 39 13 */ 40 class Chat : public Packet Content14 class Chat : public Packet 41 15 { 42 16 public: … … 45 19 ~Chat(); 46 20 47 unsigned char *getData();48 21 inline unsigned int getSize() const; 49 22 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 1 31 #include "ClassID.h" 2 #include "Packet.h"3 32 #include "core/CoreIncludes.h" 4 33 #include <string> … … 15 44 16 45 ClassID::ClassID( unsigned int classID, std::string className ) 17 : Packet Content()46 : Packet() 18 47 { 19 48 flags_ = flags_ | PACKET_FLAGS_CLASSID; … … 29 58 30 59 ClassID::ClassID( unsigned char *data, int clientID ) 31 : Packet Content(data, clientID)60 : Packet(data, clientID) 32 61 { 33 62 memcpy( (void *)&classNameLength_, &data[ _CLASSNAMELENGTH ], sizeof(classNameLength_) ); … … 36 65 ClassID::~ClassID() 37 66 { 38 }39 40 unsigned char *ClassID::getData(){41 return data_;42 67 } 43 68 … … 51 76 return false; 52 77 id->setNetworkID( getClassID() ); 78 delete this; 53 79 return true; 54 80 } … … 58 84 } 59 85 60 // unsigned int ClassID::getClassNameLength(){61 // return *(unsigned int *)&data[ _CLASSNAMELENGTH ];62 // }63 64 86 } //namespace packet 65 87 }//namespace network -
code/branches/network/src/network/packet/ClassID.h
r1705 r1711 31 31 #include <string> 32 32 33 #include "Packet Content.h"33 #include "Packet.h" 34 34 35 35 namespace network { … … 39 39 @author 40 40 */ 41 class ClassID : public Packet Content41 class ClassID : public Packet 42 42 { 43 43 public: … … 46 46 ~ClassID(); 47 47 48 unsigned char *getData();49 48 inline unsigned int getSize() const; 50 49 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 1 47 #include "Gamestate.h" 2 48 #include "network/ClientInformation.h" … … 22 68 23 69 Gamestate::Gamestate(unsigned char *data, bool compressed, int clientID): 24 Packet Content(data, clientID)70 Packet(data, clientID) 25 71 { 26 72 compressed_ = compressed; 27 //GAMESTATE_HEADER = (GamestateHeader *)data;28 //if(!compressed)29 //bs_ = new Bytestream(data+sizeof(GamestateHeader), GAMESTATE_HEADER->compsize);30 73 } 31 74 … … 138 181 } 139 182 140 unsigned char *Gamestate::getData()141 {142 assert(data_!=0);143 return data_;144 }145 146 183 unsigned int Gamestate::getSize() const 147 184 { 185 assert(data_); 148 186 if(compressed_) 149 187 return HEADER->compsize+sizeof(GamestateHeader); -
code/branches/network/src/network/packet/Gamestate.h
r1710 r1711 27 27 */ 28 28 29 #include "PacketContent.h"30 29 #include "Packet.h" 31 30 #include "network/Synchronisable.h" … … 53 52 @author 54 53 */ 55 class Gamestate: public Packet Content{54 class Gamestate: public Packet{ 56 55 public: 57 56 Gamestate(); … … 68 67 bool decompressData(); 69 68 70 // PacketContent functions 71 virtual unsigned char *getData(); 69 // Packet functions 72 70 virtual unsigned int getSize() const; 73 71 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 1 29 2 30 #include <enet/enet.h> 31 #include <boost/bind.hpp> 3 32 4 33 #include "Packet.h" … … 10 39 #include "ClassID.h" 11 40 #include "Gamestate.h" 41 #include "Welcome.h" 12 42 #include "network/Host.h" 13 43 #include "core/CoreIncludes.h" … … 17 47 namespace packet{ 18 48 49 #define PACKET_FLAG_DEFAULT ENET_PACKET_FLAG_NO_ALLOCATE 19 50 #define _PACKETID 0 20 51 21 52 std::map<ENetPacket *, Packet *> Packet::packetMap_; 22 53 23 54 Packet::Packet(){ 55 flags_ = PACKET_FLAG_DEFAULT; 24 56 packetDirection_ = ENUM::Outgoing; 25 57 clientID_=0; 26 packetContent_=0;58 data_=0; 27 59 enetPacket_=0; 28 60 } 29 61 30 Packet::Packet(PacketContent *content){ 62 Packet::Packet(unsigned char *data, int clientID){ 63 flags_ = PACKET_FLAG_DEFAULT; 31 64 packetDirection_ = ENUM::Outgoing; 32 clientID_= 0;33 packetContent_=content;65 clientID_=clientID; 66 data_=data; 34 67 enetPacket_=0; 35 68 } … … 39 72 enetPacket_ = packet; 40 73 clientID_ = ClientInformation::findClient(&peer->address)->getID(); 41 packetContent_ = createPacketContent(packet);74 data_ = packet->data; 42 75 enet_packet_destroy(packet); 43 76 } 44 77 45 Packet::~Packet(){ 46 if(enetPacket_){ 47 enet_packet_destroy(enetPacket_); 48 } 78 Packet::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; 49 85 } 50 86 51 void Packet::setPacketContent(PacketContent *content){ 52 packetContent_ = content; 53 if(enetPacket_){ 87 Packet::~Packet(){ 88 if(enetPacket_) 54 89 enet_packet_destroy(enetPacket_); 55 enetPacket_=0;56 }90 if(data_) 91 delete[] data_; 57 92 } 58 93 … … 61 96 return false; 62 97 if(!enetPacket_){ 63 if(! packetContent_)98 if(!data_) 64 99 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; 66 103 } 67 104 network::Host::addPacket( enetPacket_, clientID_); … … 70 107 } 71 108 72 Packet Content *Packet::createPacketContent(ENetPacket *packet){109 Packet *Packet::createPacket(ENetPacket *packet, ENetPeer *peer){ 73 110 unsigned char *data = packet->data; 111 unsigned int clientID = ClientInformation::findClient(&peer->address)->getID(); 112 Packet *p; 74 113 switch( *(ENUM::Type *)&data[_PACKETID] ) 75 114 { 76 115 case ENUM::Acknowledgement: 77 p acketContent_ = new Acknowledgement( data, clientID_);116 p = new Acknowledgement( data, clientID ); 78 117 break; 79 118 case ENUM::Chat: 80 p acketContent_ = new Chat( data, clientID_);119 p = new Chat( data, clientID ); 81 120 break; 82 121 case ENUM::ClassID: 83 p acketContent_ = new ClassID( data, clientID_);122 p = new ClassID( data, clientID ); 84 123 break; 85 124 case ENUM::Gamestate: 86 125 // TODO: remove brackets 87 p acketContent_ = new Gamestate( data, true, clientID_);126 p = new Gamestate( data, true, clientID ); 88 127 break; 128 case ENUM::Welcome: 129 p = new Welcome( data, clientID ); 89 130 default: 90 131 assert(0); //TODO: repair this 91 132 break; 92 133 } 93 return packetContent_; 134 return p; 135 } 136 137 void Packet::deletePacket(ENetPacket *packet){ 138 assert(packetMap_[packet]); 139 delete packetMap_[packet]; 94 140 } 95 141 -
code/branches/network/src/network/packet/Packet.h
r1709 r1711 29 29 #define NETWORKPACKET_H 30 30 31 #include "PacketContent.h" 32 31 #include <map> 33 32 #include <enet/enet.h> 34 33 … … 57 56 class Packet{ 58 57 public: 59 Packet(); 60 Packet(PacketContent *content); 61 Packet(ENetPacket *packet, ENetPeer *peer); 58 Packet(const Packet &p); 62 59 virtual ~Packet(); 60 static Packet *createPacket(ENetPacket *packet, ENetPeer *peer); 61 static void deletePacket(ENetPacket *packet); 63 62 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; } 69 72 70 73 bool send(); 71 74 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_; 72 81 private: 73 PacketContent *createPacketContent(ENetPacket *packet); 74 75 int clientID_; 76 PacketContent *packetContent_; 82 static std::map<ENetPacket *, Packet *> packetMap_; 77 83 ENetPacket *enetPacket_; 78 84 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 1 32 #include "Welcome.h" 2 #include " Packet.h"33 #include "network/Host.h" 3 34 #include <assert.h> 4 35 … … 12 43 13 44 Welcome::Welcome( unsigned int clientID, unsigned int shipID ) 14 : Packet Content()45 : Packet() 15 46 { 16 47 flags_ = flags_ | PACKET_FLAGS_CLASSID; … … 24 55 25 56 Welcome::Welcome( unsigned char *data, int clientID ) 26 : Packet Content(data, clientID)57 : Packet(data, clientID) 27 58 { 28 59 } … … 44 75 clientID = *(unsigned int *)&data_[ _CLIENTID ]; 45 76 shipID = *(unsigned int *)&data_[ _SHIPID ]; 77 Host::setClientID(clientID); 78 Host::setShipID(shipID); 79 delete this; 46 80 return true; 47 81 } -
code/branches/network/src/network/packet/Welcome.h
r1709 r1711 29 29 #define NETWORKWELCOME_H 30 30 31 #include "Packet Content.h"31 #include "Packet.h" 32 32 33 33 namespace network { … … 37 37 @author 38 38 */ 39 class Welcome : public Packet Content39 class Welcome : public Packet 40 40 { 41 41 public:
Note: See TracChangeset
for help on using the changeset viewer.