Changeset 1705
- Timestamp:
- Sep 4, 2008, 9:45:05 PM (16 years ago)
- Location:
- code/branches/network/src/network
- Files:
-
- 4 added
- 6 deleted
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/CMakeLists.txt
r1699 r1705 4 4 ClientInformation.cc 5 5 ConnectionManager.cc 6 GameStateManager.cc 7 GameStateClient.cc 6 GamestateManager.cc 7 GamestateClient.cc 8 GamestateHandler.cc 8 9 PacketBuffer.cc 9 PacketDecoder.cc10 PacketGenerator.cc11 10 Server.cc 12 11 Synchronisable.cc … … 17 16 packet/Acknowledgement.cc 18 17 packet/Gamestate.cc 18 packet/Welcome.cc 19 19 Host.cc 20 20 ) -
code/branches/network/src/network/Client.cc
r1699 r1705 45 45 #include "core/ConsoleCommand.h" 46 46 #include "packet/Packet.h" 47 #include "packet/Acknowledgement.h" 47 48 48 49 namespace network … … 127 128 return p->send(); 128 129 } 130 129 131 130 132 /** … … 137 139 if(!isConnected) 138 140 return false; 139 return client_connection.addPacket(pck_gen.chatMessage( message.c_str() )); 141 packet::Packet p(new packet::Chat(message, clientID_)); 142 return p.send(); 140 143 //return client_connection.sendPackets(); 141 144 // send packets 142 return false;143 145 } 144 146 … … 150 152 if(client_connection.isConnected() && isSynched_){ 151 153 COUT(4) << "popping partial gamestate: " << std::endl; 152 GameStateCompressed *gs = gamestate.popPartialGameState();154 packet::Gamestate *gs = gamestate.getGamestate(); 153 155 if(gs){ 154 156 COUT(4) << "client tick: sending gs " << gs << std::endl; 155 ENetPacket *packet = pck_gen.gstate(gs);156 if( packet == NULL || !client_connection.addPacket(packet))157 packet::Packet p(gs); 158 if( !p.send() ) 157 159 COUT(3) << "Problem adding partial gamestate to queue" << std::endl; 158 160 // now delete it to save memory 159 delete[] gs->data;160 161 delete gs; 161 162 } … … 166 167 event = client_connection.getEvent(); 167 168 COUT(5) << "tick packet size " << event->packet->dataLength << std::endl; 168 elaborate(event->packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server) 169 packet::Packet packet(event->packet, event->peer); 170 assert(packet.getPacketContent()->process()); 169 171 } 170 int gameStateID = gamestate.processGame State();172 int gameStateID = gamestate.processGamestates(); 171 173 if(gameStateID==GAMESTATEID_INITIAL) 172 174 if(gameStateFailure_){ 173 if(!client_connection.addPacket(pck_gen.acknowledgement(GAMESTATEID_INITIAL))) 175 packet::Packet packet(new packet::Acknowledgement(GAMESTATEID_INITIAL, 0)); 176 if(!packet.send()) 174 177 COUT(3) << "could not (negatively) ack gamestate" << std::endl; 175 178 else … … 183 186 isSynched_=true; 184 187 gameStateFailure_=false; 185 if(!client_connection.addPacket(pck_gen.acknowledgement(gameStateID))) 188 packet::Packet packet(new packet::Acknowledgement(gameStateID, 0)); 189 if(!packet.send()) 186 190 COUT(3) << "could not ack gamestate" << std::endl; 187 191 }// otherwise we had no gamestate to load 188 192 gamestate.cleanup(); 189 /*if(!client_connection.sendPackets())190 COUT(3) << "Problem sending packets to server" << std::endl;*/191 193 return; 192 194 } 193 195 194 void Client::processGamestate( GameStateCompressed *data, int clientID){195 COUT(5) << "received gamestate id: " << data->id << std::endl;196 gamestate.addGameState(data);197 }198 199 void Client::processClassid(classid *clid){200 orxonox::Identifier *id;201 id=ID(std::string(clid->message));202 if(id!=NULL)203 id->setNetworkID(clid->clid);204 COUT(4) << "Client: received and set network id: " << clid->clid << "; classname: " << clid->message << std::endl;205 COUT(4) << "id(classid)->getName " << ID((unsigned int)clid->clid)->getName() << std::endl;206 delete clid;207 return;208 }209 210 bool Client::ackGamestateID(int gamestateID, int clientID){211 return true;212 //TODO: maybe change this (not needed at the moment)213 }214 215 // void Client::processChat( chat *data, int clientId){216 // COUT(1) << data->message << std::endl;217 // delete[] data->message;218 // delete data;219 // }220 221 bool Client::processWelcome( welcome *w ){222 COUT(4) << "processing welcome message" << std::endl;223 clientID_ = w->clientID;224 shipID_ = w->shipID;225 delete w;226 return true;227 }228 229 196 } -
code/branches/network/src/network/Client.h
r1699 r1705 49 49 #include "packet/Chat.h" 50 50 #include "ClientConnection.h" 51 #include "PacketManager.h" 52 #include "GameStateClient.h" 51 #include "GamestateClient.h" 53 52 //#include "NetworkFrameListener.h" 54 53 … … 64 63 * 65 64 */ 66 class _NetworkExport Client : PacketDecoder,public Host{65 class _NetworkExport Client : public Host{ 67 66 public: 68 67 Client(); … … 81 80 unsigned int shipID(){return shipID_;} 82 81 int playerID(){return clientID_;} 83 82 static void setShipID( unsigned int shipID){ dynamic_cast<Client *>(instance_)->shipID_=shipID; } 83 static void setClientID( unsigned int clientID){ dynamic_cast<Client *>(instance_)->clientID_=clientID; } 84 84 85 void tick(float time); 85 86 … … 87 88 88 89 ClientConnection client_connection; 89 PacketGenerator pck_gen; 90 GameStateClient gamestate; 90 GamestateClient gamestate; 91 91 bool isConnected; 92 92 bool isSynched_; … … 95 95 96 96 // implement data processing functions of PacketDecoder 97 void processGamestate( GameStateCompressed *data, int clientID);98 void processClassid(classid *clid);99 bool ackGamestateID(int gamestateID, int clientID);100 97 // void processChat( chat *data, int clientId ); 101 bool processWelcome( welcome *w );102 98 int clientID_; // this is the id the server gave to us 103 99 int shipID_; -
code/branches/network/src/network/ClientInformation.cc
r1666 r1705 123 123 } 124 124 125 bool ClientInformation::setGame StateID(int id){125 bool ClientInformation::setGamestateID(int id){ 126 126 if(!this) 127 127 return false; -
code/branches/network/src/network/ClientInformation.h
r1699 r1705 70 70 void setID(int clientID); 71 71 bool setPeer(ENetPeer *peer); 72 bool setGame StateID(int id);72 bool setGamestateID(int id); 73 73 bool setPartialGamestateID(int id); 74 74 inline void setShipID(unsigned int id){ShipID_=id;} -
code/branches/network/src/network/ConnectionManager.cc
r1699 r1705 51 51 #include "ConnectionManager.h" 52 52 #include "Synchronisable.h" 53 #include "packet/ClassID.h" 53 54 54 55 namespace std … … 75 76 bindAddress.port = NETWORK_PORT; 76 77 } 77 boost::recursive_mutex ConnectionManager::enet_mutex _;78 boost::recursive_mutex ConnectionManager::enet_mutex; 78 79 79 80 // ConnectionManager::ConnectionManager(ClientInformation *head) : receiverThread_(0) { … … 172 173 173 174 bool ConnectionManager::addPacket(ENetPacket *packet, ENetPeer *peer) { 174 boost::recursive_mutex::scoped_lock lock(instance_->enet_mutex _);175 boost::recursive_mutex::scoped_lock lock(instance_->enet_mutex); 175 176 if(enet_peer_send(peer, NETWORK_DEFAULT_CHANNEL, packet)!=0) 176 177 return false; … … 190 191 if(!instance_) 191 192 return false; 192 boost::recursive_mutex::scoped_lock lock(instance_->enet_mutex _);193 boost::recursive_mutex::scoped_lock lock(instance_->enet_mutex); 193 194 for(ClientInformation *i=ClientInformation::getBegin()->next(); i!=0; i=i->next()){ 194 195 COUT(3) << "adding broadcast packet for client: " << i->getID() << std::endl; … … 203 204 if(server==NULL || !instance_) 204 205 return false; 205 boost::recursive_mutex::scoped_lock lock(enet_mutex _);206 boost::recursive_mutex::scoped_lock lock(enet_mutex); 206 207 enet_host_flush(server); 207 208 lock.unlock(); … … 214 215 atexit(enet_deinitialize); 215 216 { //scope of the mutex 216 boost::recursive_mutex::scoped_lock lock(enet_mutex _);217 boost::recursive_mutex::scoped_lock lock(enet_mutex); 217 218 enet_initialize(); 218 219 server = enet_host_create(&bindAddress, NETWORK_MAX_CONNECTIONS, 0, 0); … … 228 229 while(!quit){ 229 230 { //mutex scope 230 boost::recursive_mutex::scoped_lock lock(enet_mutex _);231 boost::recursive_mutex::scoped_lock lock(enet_mutex); 231 232 if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){ 232 233 // we should never reach this point … … 270 271 // if we're finishied, destroy server 271 272 { 272 boost::recursive_mutex::scoped_lock lock(enet_mutex _);273 boost::recursive_mutex::scoped_lock lock(enet_mutex); 273 274 enet_host_destroy(server); 274 275 lock.unlock(); … … 284 285 while(temp!=0){ 285 286 { 286 boost::recursive_mutex::scoped_lock lock(enet_mutex _);287 boost::recursive_mutex::scoped_lock lock(enet_mutex); 287 288 enet_peer_disconnect(temp->getPeer(), 0); 288 289 lock.unlock(); … … 292 293 //bugfix: might be the reason why server crashes when clients disconnects 293 294 temp = ClientInformation::getBegin()->next(); 294 boost::recursive_mutex::scoped_lock lock(enet_mutex _);295 boost::recursive_mutex::scoped_lock lock(enet_mutex); 295 296 while( temp!=0 && enet_host_service(server, &event, NETWORK_WAIT_TIMEOUT) >= 0){ 296 297 switch (event.type) … … 337 338 std::string classname; 338 339 orxonox::Identifier *id; 340 packet::Packet packet; 341 packet.setClientID(clientID); 342 packet::ClassID *classid; 339 343 std::map<std::string, orxonox::Identifier*>::const_iterator it = orxonox::Factory::getFactoryBegin(); 340 344 while(it != orxonox::Factory::getFactoryEnd()){ … … 348 352 COUT(4) << "Con.Man:syncClassid:\tnetwork_id: " << network_id << ", classname: " << classname << std::endl; 349 353 350 while(!addPacket(packet_gen.clid( (int)network_id, classname ), clientID) && failures < 10){ 354 classid = new packet::ClassID(network_id, classname); 355 packet.setPacketContent(classid); 356 while(!packet.send() && failures < 10){ 351 357 failures++; 352 358 } 359 delete classid; 353 360 ++it; 354 361 } 362 packet.setPacketContent(0); 355 363 //sendPackets(); 356 364 COUT(4) << "syncClassid:\tall synchClassID packets have been sent" << std::endl; … … 370 378 } 371 379 372 bool ConnectionManager::sendWelcome(int clientID, int shipID, bool allowed){373 if(addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID)){374 //sendPackets();375 return true;376 }else377 return false;378 }379 380 380 381 void ConnectionManager::disconnectClient(ClientInformation *client){ 381 382 { 382 boost::recursive_mutex::scoped_lock lock(enet_mutex _);383 boost::recursive_mutex::scoped_lock lock(enet_mutex); 383 384 enet_peer_disconnect(client->getPeer(), 0); 384 385 lock.unlock(); … … 387 388 } 388 389 389 bool ConnectionManager::addFakeConnectRequest(ENetEvent *ev){390 ENetEvent event;391 event.peer=ev->peer;392 event.packet = packet_gen.generateConnectRequest();393 return buffer.push(&event);394 }395 396 397 390 398 391 } -
code/branches/network/src/network/ConnectionManager.h
r1666 r1705 51 51 52 52 #include "PacketBuffer.h" 53 #include "PacketManager.h"54 53 #include "packet/Packet.h" 55 54 … … 73 72 74 73 class ConnectionManager{ 75 public: 74 public: 75 static boost::recursive_mutex enet_mutex; 76 76 ConnectionManager(); 77 77 //ConnectionManager(ClientInformation *head); … … 95 95 void disconnectClient(ClientInformation *client); 96 96 void syncClassid(int clientID); 97 bool sendWelcome(int clientID, int shipID, bool allowed);98 97 99 98 private: … … 109 108 //bool createShip(ClientInformation *client); 110 109 bool removeShip(ClientInformation *client); 111 bool addFakeConnectRequest(ENetEvent *ev);112 110 PacketBuffer buffer; 113 PacketGenerator packet_gen;114 111 115 112 ENetHost *server; … … 119 116 120 117 boost::thread *receiverThread_; 121 static boost::recursive_mutex enet_mutex_;122 118 static ConnectionManager *instance_; 123 119 -
code/branches/network/src/network/Host.cc
r1699 r1705 54 54 } 55 55 56 bool Host::ackGamestate(int gamestateID, int clientID){57 return instance_->ackGamestateID(gamestateID, clientID);58 }59 60 56 }//namespace network -
code/branches/network/src/network/Host.h
r1699 r1705 31 31 #include <string> 32 32 33 #include "NetworkPrereqs.h" 33 34 #include "packet/Chat.h" 34 35 … … 44 45 virtual bool sendChat(packet::Chat *chat)=0; 45 46 virtual bool queuePacket(ENetPacket *packet, int clientID)=0; 46 virtual bool ackGamestateID(int gamestateID, int clientID)=0;47 47 virtual unsigned int shipID()=0; 48 48 virtual int playerID()=0; 49 49 50 static Host *instance_;51 50 52 51 … … 54 53 Host(); 55 54 ~Host(); 55 static Host *instance_; 56 56 57 57 public: … … 62 62 static int getPlayerID(); 63 63 static unsigned int getShipID(); 64 static bool ackGamestate(int gamestateID, int clientID); 64 65 // packet process functions 65 66 }; 66 67 -
code/branches/network/src/network/NetworkPrereqs.h
r1505 r1705 66 66 class ClientInformation; 67 67 class ConnectionManager; 68 class GameStateClient; 69 class GameStateManager; 68 class GamestateClient; 69 class GamestateManager; 70 class GamestateHandler; 70 71 class PacketBuffer; 71 class PacketDecoder;72 class PacketGenerator;73 72 class Server; 74 73 class ServerFrameListener; 75 74 class Synchronisable; 76 struct ack;77 struct chat;78 struct classid;79 struct welcome;80 struct connectRequest;81 75 struct ClientList; 82 struct GameState;83 struct GameStateCompressed;84 struct keyboard;85 struct mouse;86 76 struct PacketEnvelope; 87 77 struct QueueItem; 88 78 struct syncData; 89 79 struct synchronisableVariable; 80 namespace packet{ 81 class Gamestate; 82 class Packet; 83 class PacketContent; 84 class Acknowledgement; 85 class ClassID; 86 class Welcome; 87 } 90 88 } 91 89 -
code/branches/network/src/network/Server.cc
r1699 r1705 45 45 46 46 #include "ConnectionManager.h" 47 #include "PacketTypes.h" 48 #include "GameStateManager.h" 47 #include "GamestateManager.h" 49 48 #include "ClientInformation.h" 50 49 #include "util/Sleep.h" … … 53 52 #include "packet/Chat.h" 54 53 #include "packet/Packet.h" 54 #include "packet/Welcome.h" 55 55 56 56 namespace network … … 65 65 Server::Server() { 66 66 timeSinceLastUpdate_=0; 67 packet_gen = PacketGenerator();68 67 connection = new ConnectionManager(); 69 gamestates = new GameStateManager();68 gamestates_ = new GamestateManager(); 70 69 } 71 70 72 71 Server::Server(int port){ 73 72 timeSinceLastUpdate_=0; 74 packet_gen = PacketGenerator();75 73 connection = new ConnectionManager(port); 76 gamestates = new GameStateManager();74 gamestates_ = new GamestateManager(); 77 75 } 78 76 … … 84 82 Server::Server(int port, std::string bindAddress) { 85 83 timeSinceLastUpdate_=0; 86 packet_gen = PacketGenerator();87 84 connection = new ConnectionManager(port, bindAddress); 88 gamestates = new GameStateManager();85 gamestates_ = new GamestateManager(); 89 86 } 90 87 … … 96 93 Server::Server(int port, const char *bindAddress) { 97 94 timeSinceLastUpdate_=0; 98 packet_gen = PacketGenerator();99 95 connection = new ConnectionManager(port, bindAddress); 100 gamestates = new GameStateManager();96 gamestates_ = new GamestateManager(); 101 97 } 102 98 … … 173 169 timeSinceLastUpdate_=(float)((int)(timeSinceLastUpdate_*NETWORK_FREQUENCY))/timeSinceLastUpdate_; 174 170 // timeSinceLastUpdate_-=1./NETWORK_FREQUENCY; 175 gamestates ->processGameStates();171 gamestates_->processGamestates(); 176 172 updateGamestate(); 177 173 } … … 191 187 void Server::processQueue() { 192 188 ENetEvent *event; 193 int clientID=-1;194 189 while(!connection->queueEmpty()){ 195 190 //std::cout << "Client " << clientID << " sent: " << std::endl; … … 209 204 break; 210 205 case ENET_EVENT_TYPE_RECEIVE: 211 if(ClientInformation::findClient(&event->peer->address)){ 212 clientID = ClientInformation::findClient(&event->peer->address)->getID(); 213 if( !elaborate(event->packet, clientID) ) 214 COUT(3) << "Server: could not elaborate" << std::endl; 215 } 206 if(!processPacket(event->packet, event->peer)) 207 COUT(3) << "processing incoming packet failed" << std::endl; 216 208 break; 217 209 default: … … 227 219 */ 228 220 void Server::updateGamestate() { 229 gamestates ->update();221 gamestates_->update(); 230 222 COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl; 231 223 //std::cout << "updated gamestate, sending it" << std::endl; … … 236 228 } 237 229 230 bool Server::processPacket( ENetPacket *packet, ENetPeer *peer ){ 231 packet::Packet p = packet::Packet(packet, peer); 232 return p.getPacketContent()->process(); 233 } 234 238 235 /** 239 236 * sends the gamestate … … 257 254 int cid = temp->getID(); //get client id 258 255 COUT(5) << "Server: got acked (gamestate) ID from clientlist: " << gid << std::endl; 259 GameStateCompressed *gs = gamestates->popGameState(cid);256 packet::Gamestate *gs = gamestates_->popGameState(cid); 260 257 if(gs==NULL){ 261 258 COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl; … … 263 260 } 264 261 //std::cout << "adding gamestate" << std::endl; 265 ENetPacket *packet = packet_gen.gstate(gs); 266 if(!packet) 267 continue; 268 if ( !(connection->addPacket(packet, cid)) ){ 262 packet::Packet packet(gs); 263 packet.setClientID(cid); 264 if ( !packet.send() ){ 269 265 COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl; 270 266 temp->addFailure(); … … 277 273 temp=temp->next(); 278 274 // now delete gamestate 279 delete[] gs->data;280 275 delete gs; 281 276 } … … 286 281 //COUT(5) << "Server: had no gamestates to send" << std::endl; 287 282 return true; 288 }289 290 void Server::processAck( ack *data, int clientID) {291 COUT(4) << "Server: processing ack from client: " << clientID << "; ack-id: " << data->a << std::endl;292 gamestates->ackGameState(clientID, data->a);293 delete data;294 }295 296 bool Server::processConnectRequest( connectRequest *con, int clientID ){297 //(COUT(3) << "processing connectRequest " << std::endl;298 //connection->addPacket(packet_gen.gstate(gamestates->popGameState(clientID)) , clientID);299 //createClient(clientID);300 delete con;301 return true;302 }303 304 bool Server::ackGamestateID(int gamestateID, int clientID){305 gamestates->ackGameState(clientID, gamestateID);306 return true;307 }308 309 void Server::processGamestate( GameStateCompressed *data, int clientID){310 COUT(4) << "processing partial gamestate from client " << clientID << std::endl;311 gamestates->addGameState(data, clientID);312 /*COUT(3) << "Could not push gamestate\t\t\t\t=====" << std::endl;313 else314 if(clients->findClient(clientID))315 clients->findClient(clientID)->resetFailures();*/316 283 } 317 284 … … 359 326 temp->setSynched(true); 360 327 COUT(3) << "sending welcome" << std::endl; 361 connection->sendWelcome(temp->getID(), temp->getShipID(), true); 328 packet::Packet packet(new packet::Welcome(temp->getID(), temp->getShipID())); 329 assert(packet.send()); 362 330 return true; 363 331 } … … 421 389 void Server::disconnectClient( ClientInformation *client){ 422 390 connection->disconnectClient(client); 423 gamestates ->removeClient(client);391 gamestates_->removeClient(client); 424 392 } 425 393 -
code/branches/network/src/network/Server.h
r1699 r1705 47 47 48 48 #include "Host.h" 49 #include "PacketManager.h" 50 51 49 #include "GamestateManager.h" 52 50 53 51 namespace network … … 59 57 * It implements all functions necessary for a Server 60 58 */ 61 class _NetworkExport Server : public PacketDecoder, publicHost{59 class _NetworkExport Server : public Host{ 62 60 public: 63 61 Server(); … … 85 83 void disconnectClient(int clientID); 86 84 void disconnectClient( ClientInformation *client); 85 bool processPacket( ENetPacket *packet, ENetPeer *peer ); 87 86 bool sendGameState(); 88 void processAck( ack *data, int clientID);89 bool processConnectRequest( connectRequest *con, int clientID );90 void processGamestate( GameStateCompressed *data, int clientID);91 87 92 bool ackGamestateID(int gamestateID, int clientID);93 88 94 89 //void processChat( chat *data, int clientId); 95 90 ConnectionManager *connection; 96 GameStateManager *gamestates; 97 PacketGenerator packet_gen; 91 GamestateManager *gamestates_; 98 92 99 93 -
code/branches/network/src/network/packet/Acknowledgement.cc
r1701 r1705 2 2 #include "Packet.h" 3 3 #include "network/Host.h" 4 #include "network/GamestateHandler.h" 4 5 5 6 namespace network { … … 21 22 22 23 Acknowledgement::Acknowledgement( unsigned char *data, int clientID ) 23 : PacketContent(data )24 : PacketContent(data, clientID) 24 25 { 25 26 clientID_=clientID; … … 39 40 40 41 bool Acknowledgement::process(){ 41 return Host::ackGamestate(data_[_ACKID], clientID_);42 return GamestateHandler::ackGamestate(data_[_ACKID], clientID_); 42 43 } 43 44 -
code/branches/network/src/network/packet/Acknowledgement.h
r1701 r1705 50 50 unsigned int getAckID(); 51 51 private: 52 int clientID_;53 52 }; 54 53 -
code/branches/network/src/network/packet/Chat.cc
r1701 r1705 23 23 24 24 Chat::Chat( unsigned char *data, int clientID ) 25 : PacketContent(data )25 : PacketContent(data, clientID) 26 26 { 27 27 messageLength_ = *(unsigned int *)&data[ _MESSAGELENGTH ]; 28 clientID_ = clientID;29 28 } 30 29 -
code/branches/network/src/network/packet/ClassID.cc
r1701 r1705 3 3 #include "core/CoreIncludes.h" 4 4 #include <string> 5 5 #include <assert.h> 6 6 7 7 namespace network { … … 19 19 flags_ = flags_ | PACKET_FLAGS_CLASSID; 20 20 classNameLength_=className.length()+1; 21 assert(getSize()); 21 22 data_=new unsigned char[ getSize() ]; 22 23 if(!data_) … … 28 29 } 29 30 30 ClassID::ClassID( unsigned char *data )31 : PacketContent(data )31 ClassID::ClassID( unsigned char *data, int clientID ) 32 : PacketContent(data, clientID) 32 33 { 33 34 memcpy( (void *)&classNameLength_, &data[ sizeof(ENUM::Type) + sizeof(int) ], sizeof(classNameLength_) ); -
code/branches/network/src/network/packet/ClassID.h
r1701 r1705 43 43 public: 44 44 ClassID( unsigned int classID, std::string className ); 45 ClassID( unsigned char* data );45 ClassID( unsigned char* data, int clientID ); 46 46 ~ClassID(); 47 47 -
code/branches/network/src/network/packet/Gamestate.cc
r1701 r1705 1 1 #include "Gamestate.h" 2 2 #include "network/ClientInformation.h" 3 3 #include "network/GamestateHandler.h" 4 4 5 5 #include <zlib.h> … … 21 21 } 22 22 23 Gamestate::Gamestate(unsigned char *data, bool compressed ):24 PacketContent(data )23 Gamestate::Gamestate(unsigned char *data, bool compressed, int clientID): 24 PacketContent(data, clientID) 25 25 { 26 26 compressed_ = compressed; … … 133 133 } 134 134 135 int Gamestate::getID(){ 136 return HEADER->id; 137 } 138 135 139 unsigned char *Gamestate::getData() 136 140 { … … 146 150 { 147 151 return HEADER->normsize+sizeof(GamestateHeader); 148 //assert(bs_);149 //return bs_->getSize();150 152 } 151 153 } … … 153 155 bool Gamestate::process() 154 156 { 155 //FIXME: TODO: implement this function 156 return true; 157 return GamestateHandler::addGamestate(this, getClientID()); 157 158 } 158 159 … … 182 183 *GAMESTATE_HEADER(ndata) = *HEADER; 183 184 //delete old data 184 // delete bs_;185 185 delete[] data_; 186 186 //save new data … … 250 250 } 251 251 252 Gamestate *g = new Gamestate(ndata, false );252 Gamestate *g = new Gamestate(ndata, false, 0); 253 253 return g; 254 254 } … … 282 282 } 283 283 284 Gamestate *g = new Gamestate(ndata, false );284 Gamestate *g = new Gamestate(ndata, false, 0); 285 285 return g; 286 286 } -
code/branches/network/src/network/packet/Gamestate.h
r1701 r1705 54 54 public: 55 55 Gamestate(); 56 Gamestate(unsigned char *data, bool compressed );56 Gamestate(unsigned char *data, bool compressed, int clientID); 57 57 58 58 ~Gamestate(); … … 60 60 bool collectData(int id, int mode=0x0); 61 61 bool spreadData(int mode=0x0); 62 int getID(); 63 Gamestate *diff(Gamestate *base); 64 Gamestate *undiff(Gamestate *base); 65 bool compressData(); 66 bool decompressData(); 62 67 63 68 // PacketContent functions … … 68 73 69 74 private: 70 bool compressData();71 bool decompressData();72 Gamestate *diff(Gamestate *base);73 Gamestate *undiff(Gamestate *base);74 75 unsigned int calcGamestateSize(int mode=0x0); 75 //unsigned char *getGs(){ return bs_->getData(); }76 76 void removeObject(orxonox::Iterator<Synchronisable> &it); 77 77 -
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: -
code/branches/network/src/network/packet/Packet.h
r1701 r1705 47 47 Gamestate, 48 48 ClassID, 49 Chat 49 Chat, 50 Welcome 50 51 }; 51 52 } … … 65 66 66 67 void setClientID( int id ){ clientID_ = id; } 67 void setPacketContent(PacketContent *content) { packetContent_=content; }68 void setPacketContent(PacketContent *content); 68 69 69 70 bool send(); -
code/branches/network/src/network/packet/PacketContent.h
r1701 r1705 47 47 virtual unsigned char *getData()=0; 48 48 virtual unsigned int getSize() const =0; 49 int getClientID(){return clientID_;} 49 50 virtual bool process()=0; 50 51 enet_uint32 getFlags(){ return flags_; } … … 53 54 { flags_ = PACKET_FLAG_DEFAULT; 54 55 data_=0; } 55 PacketContent( unsigned char *data )56 { flags_ = PACKET_FLAG_DEFAULT; data_=data; }56 PacketContent( unsigned char *data, int clientID ) 57 { flags_ = PACKET_FLAG_DEFAULT; data_=data; clientID_=clientID; } 57 58 PacketContent(const PacketContent& p){ 58 59 flags_=p.flags_; … … 66 67 enet_uint32 flags_; 67 68 unsigned char *data_; 69 int clientID_; 68 70 private: 69 71 };
Note: See TracChangeset
for help on using the changeset viewer.