Changeset 1711
- Timestamp:
- Sep 5, 2008, 11:32:42 PM (16 years ago)
- Location:
- code/branches/network/src/network
- Files:
-
- 1 deleted
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/Client.cc
r1710 r1711 123 123 } 124 124 125 bool Client::sendChat(packet::Chat *chat){125 /*bool Client::sendChat(packet::Chat *chat){ 126 126 chat->process(); 127 127 packet::Packet *p = new packet::Packet(chat); 128 128 return p->send(); 129 } 129 }*/ 130 130 131 131 … … 139 139 if(!isConnected) 140 140 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(); 144 143 // send packets 145 144 } … … 155 154 if(gs){ 156 155 COUT(4) << "client tick: sending gs " << gs << std::endl; 157 packet::Packet packet(gs); 158 if( !packet.send() ) 156 if( !gs->send() ) 159 157 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 162 159 } 163 160 } … … 167 164 event = client_connection.getEvent(); 168 165 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()); 171 168 } 172 169 int gameStateID = gamestate.processGamestates(); … … 174 171 if(gameStateFailure_){ 175 172 packet::Acknowledgement ack(GAMESTATEID_INITIAL, 0); 176 packet::Packet packet(&ack); 177 if(!packet.send()) 173 if(!ack.send()) 178 174 COUT(3) << "could not (negatively) ack gamestate" << std::endl; 179 175 else … … 188 184 gameStateFailure_=false; 189 185 packet::Acknowledgement ack(gameStateID, 0); 190 packet::Packet packet(&ack); 191 if(!packet.send()) 186 if(!ack.send()) 192 187 COUT(3) << "could not ack gamestate" << std::endl; 193 188 }// otherwise we had no gamestate to load -
code/branches/network/src/network/Client.h
r1705 r1711 74 74 bool queuePacket(ENetPacket *packet, int clientID); 75 75 bool processChat(packet::Chat *message, unsigned int clientID); 76 bool sendChat(packet::Chat *chat);76 //bool sendChat(packet::Chat *chat); 77 77 78 78 // static void Chat( std::string message ); -
code/branches/network/src/network/ConnectionManager.cc
r1710 r1711 338 338 std::string classname; 339 339 orxonox::Identifier *id; 340 packet::Packet packet;341 packet.setClientID(clientID);342 packet::ClassID *classid;343 340 std::map<std::string, orxonox::Identifier*>::const_iterator it = orxonox::Factory::getFactoryBegin(); 344 341 while(it != orxonox::Factory::getFactoryEnd()){ … … 352 349 COUT(4) << "Con.Man:syncClassid:\tnetwork_id: " << network_id << ", classname: " << classname << std::endl; 353 350 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){ 357 354 failures++; 358 355 } 359 delete classid;360 356 ++it; 361 357 } -
code/branches/network/src/network/Host.cc
r1705 r1711 28 28 29 29 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 // } 36 36 37 bool Host::receiveChat(network::packet::Chat *message, unsigned int clientID){38 if(instance_)39 return instance_->processChat(message, clientID);40 else41 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 // } 43 43 44 44 int Host::getPlayerID(){ -
code/branches/network/src/network/Host.h
r1705 r1711 42 42 private: 43 43 //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; 46 46 virtual bool queuePacket(ENetPacket *packet, int clientID)=0; 47 47 virtual unsigned int shipID()=0; … … 58 58 static bool running(){return instance_!=0;} 59 59 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); 62 62 static int getPlayerID(); 63 63 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_; 66 69 }; 67 70 -
code/branches/network/src/network/NetworkPrereqs.h
r1705 r1711 81 81 class Gamestate; 82 82 class Packet; 83 class PacketContent;84 83 class Acknowledgement; 85 84 class ClassID; 86 85 class Welcome; 86 class Chat; 87 87 } 88 88 } -
code/branches/network/src/network/Server.cc
r1710 r1711 115 115 bool Server::processChat(packet::Chat *message, unsigned int clientID){ 116 116 ClientInformation *temp = ClientInformation::getBegin(); 117 packet::Packet *pkt;118 117 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()) 122 120 COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl; 123 delete pkt;121 temp = temp->next(); 124 122 } 125 123 return message->process(); … … 134 132 //TODO: change this (no informations about who wrote a message) 135 133 ClientInformation *temp = ClientInformation::getBegin(); 136 packet::Packet *pkt;137 134 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()) 141 137 COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl; 142 138 } … … 230 226 231 227 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(); 234 230 } 235 231 … … 261 257 } 262 258 //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() ){ 266 261 COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl; 267 262 temp->addFailure(); … … 270 265 added=true; 271 266 temp=temp->next(); 272 delete gs;267 // gs gets automatically deleted by enet callback 273 268 } 274 269 /*if(added) { … … 324 319 COUT(3) << "sending welcome" << std::endl; 325 320 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()); 328 323 delete w; 329 324 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 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.