Changeset 1245 for code/branches/network3/src/network
- Timestamp:
- May 7, 2008, 4:39:42 PM (17 years ago)
- Location:
- code/branches/network3/src/network
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network3/src/network/Client.cc
r1233 r1245 84 84 // set server address to localhost 85 85 isConnected=false; 86 test_once=false; 86 87 } 87 88 … … 93 94 Client::Client(std::string address, int port) : client_connection(port, address){ 94 95 isConnected=false; 96 test_once=false; 95 97 } 96 98 … … 102 104 Client::Client(const char *address, int port) : client_connection(port, address){ 103 105 isConnected=false; 106 test_once=false; 104 107 } 105 108 … … 226 229 */ 227 230 void Client::tick(float time){ 231 if(client_connection.isConnected()){ 232 COUT(4) << "popping partial gamestate: " << std::endl; 233 GameStateCompressed *gs = gamestate.popPartialGameState(); 234 if(gs){ 235 COUT(4) << "client tick: sending gs " << gs << std::endl; 236 if(client_connection.addPacket(pck_gen.gstate(gs))) 237 if(!client_connection.sendPackets()) 238 COUT(3) << "Problem sending partial gamestate" << std::endl; 239 // now delete it to save memory 240 delete [] gs->data; 241 delete gs; 242 } 243 } 228 244 ENetPacket *packet; 229 245 // stop if the packet queue is empty … … 231 247 packet = client_connection.getPacket(); 232 248 COUT(5) << "tick packet size " << packet->dataLength << std::endl; 233 elaborate(packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server) 249 if(!test_once){ 250 elaborate(packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server) 251 } 234 252 } 235 253 return; 236 254 } 237 255 238 void Client::processGamestate( GameStateCompressed *data){ 239 int id = data->id; 240 COUT(5) << "received gamestate id: " << data->id << std::endl; 241 if(gamestate.pushGameState(data)){ 242 client_connection.addPacket(pck_gen.acknowledgement(id)); 243 if(!client_connection.sendPackets()) 244 COUT(2) << "Could not send acknowledgment" << std::endl; 256 void Client::processGamestate( GameStateCompressed *data, int clientID){ 257 if(!test_once){ 258 int id = data->id; 259 COUT(5) << "received gamestate id: " << data->id << std::endl; 260 if(gamestate.pushGameState(data)){ 261 client_connection.addPacket(pck_gen.acknowledgement(id)); 262 if(!client_connection.sendPackets()) 263 COUT(2) << "Could not send acknowledgment" << std::endl; 264 } 265 // test_once=true; 245 266 } 246 267 } … … 263 284 clientID_ = w->clientID; 264 285 shipID_ = w->shipID; 265 286 return true; 266 287 } 267 288 -
code/branches/network3/src/network/Client.h
r1232 r1245 103 103 104 104 // implement data processing functions of PacketDecoder 105 void processGamestate( GameStateCompressed *data );105 void processGamestate( GameStateCompressed *data, int clientID); 106 106 void processClassid(classid *clid); 107 107 void processChat( chat *data); … … 109 109 int clientID_; // this is the id the server gave to us 110 110 int shipID_; 111 bool test_once; 111 112 }; 112 113 -
code/branches/network3/src/network/ClientConnection.h
r1168 r1245 76 76 bool sendPackets(ENetEvent *event); 77 77 bool waitEstablished(int milisec); 78 bool isConnected(){return established;} 78 79 private: 79 80 bool processData(ENetEvent *event); -
code/branches/network3/src/network/ConnectionManager.cc
r1234 r1245 165 165 enet_initialize(); 166 166 atexit(enet_deinitialize); 167 ENetEvent event;167 ENetEvent *event = new ENetEvent; 168 168 server = enet_host_create(&bindAddress, NETWORK_MAX_CONNECTIONS, 0, 0); 169 169 if(server==NULL){ … … 174 174 175 175 while(!quit){ 176 if(enet_host_service(server, &event, NETWORK_WAIT_TIMEOUT)<0){176 if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){ 177 177 // we should never reach this point 178 178 quit=true; 179 179 // add some error handling here ======================== 180 180 } 181 switch(event .type){181 switch(event->type){ 182 182 // log handling ================ 183 183 case ENET_EVENT_TYPE_CONNECT: 184 addClient( &event);184 addClient(event); 185 185 //this is a workaround to ensure thread safety 186 186 /*if(!addFakeConnectRequest(&event)) … … 191 191 //std::cout << "received data" << std::endl; 192 192 COUT(5) << "Con.Man: receive event has occured" << std::endl; 193 processData( &event);193 processData(event); 194 194 break; 195 195 case ENET_EVENT_TYPE_DISCONNECT: 196 // add some error/log handling here 197 clientDisconnect(event.peer); 196 clientDisconnect(event->peer); 198 197 break; 199 198 case ENET_EVENT_TYPE_NONE: 200 199 break; 201 200 } 201 // usleep(1000); 202 //yield(); //TODO: find apropriate 202 203 } 203 204 disconnectClients(); … … 246 247 bool ConnectionManager::clientDisconnect(ENetPeer *peer) { 247 248 COUT(4) << "removing client from list" << std::endl; 248 return head_->removeClient(peer);249 return removeClient(head_->findClient(&(peer->address))->getID()); 249 250 } 250 251 /** … … 311 312 sendWelcome(temp->getID(), temp->getShipID(), true); 312 313 return true; 314 } 315 316 bool ConnectionManager::removeClient(int clientID){ 317 orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>::start(); 318 while(it){ 319 if(it->objectID!=head_->findClient(clientID)->getShipID()){ 320 ++it; 321 continue; 322 } 323 orxonox::Iterator<orxonox::SpaceShip> temp=it; 324 ++it; 325 delete *temp; 326 return head_->removeClient(clientID); 327 } 328 return false; 313 329 } 314 330 … … 335 351 336 352 client->setShipID(no->objectID); 337 no->getFocus();338 353 return true; 339 354 } … … 342 357 addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID); 343 358 sendPackets(); 359 return true; 344 360 } 345 361 -
code/branches/network3/src/network/ConnectionManager.h
r1232 r1245 89 89 private: 90 90 bool clientDisconnect(ENetPeer *peer); 91 bool removeClient(int clientID); 91 92 bool processData(ENetEvent *event); 92 93 bool addClient(ENetEvent *event); -
code/branches/network3/src/network/GameStateClient.cc
r1232 r1245 166 166 167 167 GameState *GameStateClient::getPartialSnapshot(){ 168 169 GameState *reference; 170 // std::map<int, GameState*>::iterator it = --gameStateMap.end(); 171 // reference=(--gameStateMap.end())->second; 172 168 173 //std::cout << "begin getSnapshot" << std::endl; 169 174 //the size of the gamestate … … 178 183 179 184 GameState *retval=new GameState; //return value 180 retval->id=reference->id; 185 // retval->id=reference->id; 186 if(gameStateMap.size()!=0) 187 retval->id=(--gameStateMap.end())->second->id; 181 188 retval->diffed=false; 182 189 retval->complete=false; … … 190 197 size+=it->getSize(); // size of the actual data of the synchronisable 191 198 size+=3*sizeof(int); // size of datasize, classID and objectID 199 COUT(4) << "getpartialsnapshot: size: " << size << std::endl; 192 200 } 193 201 //retval->data = (unsigned char*)malloc(size); -
code/branches/network3/src/network/GameStateClient.h
r1232 r1245 70 70 void printGameStateMap(); 71 71 72 GameState *reference;73 72 int last_diff_; 74 73 std::map<int, GameState *> gameStateMap; -
code/branches/network3/src/network/GameStateManager.cc
r1233 r1245 106 106 if(gID != GAMESTATEID_INITIAL){ 107 107 // TODO something with the gamestatemap is wrong 108 GameState *client = gameStateMap.find(gID)->second; 108 GameState *client=NULL; 109 std::map<int, GameState*>::iterator it = gameStateMap.find(gID); 110 if(it!=gameStateMap.end()) 111 client = it->second; 109 112 GameState *server = reference; 110 113 //head_->findClient(clientID)->setGamestateID(id); … … 203 206 204 207 bool GameStateManager::loadPartialSnapshot(GameState *state, int clientID){ 208 if(!state) 209 return false; 205 210 unsigned char *data=state->data; 206 211 COUT(4) << "loadSnapshot: loading gs: " << state->id << std::endl; … … 219 224 sync.data = data; 220 225 data+=sync.length; 221 226 COUT(4) << "objectID: " << sync.objectID << " classID: " << sync.classID << std::endl; 222 227 while(it && it->objectID!=sync.objectID) 223 228 ++it; … … 226 231 if(!it){ 227 232 // the object does not exist yet 233 COUT(4) << "loadsnapshot: creating new object " << std::endl; 228 234 //COUT(4) << "loadSnapshot:\tclassid: " << sync.classID << ", name: " << ID((unsigned int) sync.classID)->getName() << std::endl; 229 235 orxonox::Identifier* id = ID((unsigned int)sync.classID); … … 244 250 }else{ 245 251 // we have our object 252 COUT(4) << "loadpartialsnapshot: we found the appropriate object" << std::endl; 246 253 if(checkAccess(clientID, sync.objectID)){ 247 254 if(! it->updateData(sync)) … … 396 403 //std::cout << "length " << length << std::endl; 397 404 switch ( retval ) { 398 case Z_OK: COUT( 4) << "successfully decompressed" << std::endl; break;405 case Z_OK: COUT(5) << "successfully decompressed" << std::endl; break; 399 406 case Z_MEM_ERROR: COUT(1) << "not enough memory available" << std::endl; return NULL; 400 407 case Z_BUF_ERROR: COUT(2) << "not enough memory available in the buffer" << std::endl; return NULL; … … 444 451 bool GameStateManager::checkAccess(int clientID, int objectID){ 445 452 // currently we only check, wheter the object is the clients spaceship 446 return head_->findClient(objectID)->getShipID()==objectID; 453 // return head_->findClient(objectID)->getShipID()==objectID; 454 return true; // TODO: change this 447 455 } 448 456 -
code/branches/network3/src/network/PacketDecoder.cc
r1233 r1245 78 78 return true; 79 79 case GAMESTATE: 80 gstate( packet );80 gstate( packet, clientId ); 81 81 return true; 82 82 case CLASSID: … … 155 155 } 156 156 157 void PacketDecoder::gstate( ENetPacket* packet )157 void PacketDecoder::gstate( ENetPacket* packet, int clientID ) 158 158 { 159 159 GameStateCompressed* currentState = NULL; … … 190 190 //clean memory 191 191 enet_packet_destroy( packet ); 192 processGamestate(currentState );192 processGamestate(currentState, clientID); 193 193 } 194 194 … … 234 234 } 235 235 236 void PacketDecoder::processGamestate( GameStateCompressed *state )236 void PacketDecoder::processGamestate( GameStateCompressed *state, int clientID ) 237 237 { 238 238 COUT(5) << "PacketDecoder: processing Gamestate" << std::endl; -
code/branches/network3/src/network/PacketManager.h
r1232 r1245 91 91 void mousem( ENetPacket* packet, int clientId = CLIENTID_CLIENT ); 92 92 void keystrike( ENetPacket* packet, int clientId = CLIENTID_CLIENT ); 93 void chatMessage( ENetPacket* packet, int clientId = CLIENTID_CLIENT );94 void gstate( ENetPacket* packet );93 void chatMessage( ENetPacket* packet, int clientId = CLIENTID_CLIENT ); 94 void gstate( ENetPacket* packet, int clientID = CLIENTID_CLIENT ); 95 95 void clid( ENetPacket *packet); 96 96 bool decodeWelcome( ENetPacket* packet, int clientID = CLIENTID_CLIENT ); … … 99 99 //process data 100 100 //two functions are note yet implemented! 101 virtual void processGamestate(GameStateCompressed *state );101 virtual void processGamestate(GameStateCompressed *state, int clientID); 102 102 virtual void processAck( ack *data, int clientID); 103 103 virtual void processClassid( classid *cid); -
code/branches/network3/src/network/Server.cc
r1232 r1245 143 143 updateGamestate(); 144 144 145 usleep(200000); // TODO remove145 // usleep(500000); // TODO remove 146 146 return; 147 147 } … … 228 228 //connection->addPacket(packet_gen.gstate(gamestates->popGameState(clientID)) , clientID); 229 229 connection->createClient(clientID); 230 return true; 231 } 232 233 void Server::processGamestate( GameStateCompressed *data, int clientID){ 234 COUT(4) << "processing partial gamestate from client " << clientID << std::endl; 235 if(!gamestates->pushGameState(data, clientID)) 236 COUT(3) << "Could not push gamestate\t\t\t\t=====" << std::endl; 237 // delete[] data->data; 238 // delete data; 230 239 } 231 240 -
code/branches/network3/src/network/Server.h
r1232 r1245 74 74 void processAck( ack *data, int clientID); 75 75 bool processConnectRequest( connectRequest *con, int clientID ); 76 void processGamestate( GameStateCompressed *data, int clientID); 76 77 ConnectionManager *connection; 77 78 GameStateManager *gamestates; -
code/branches/network3/src/network/Synchronisable.cc
r1232 r1245 50 50 51 51 52 int Synchronisable::state_= 1; // detemines wheter we are server (default) or client52 int Synchronisable::state_=0x1; // detemines wheter we are server (default) or client 53 53 54 54 /** … … 165 165 for(i=syncList->begin(); n<datasize && i!=syncList->end(); ++i){ 166 166 //(std::memcpy(retVal.data+n, (const void*)(&(i->size)), sizeof(int)); 167 if( ((*i)->mode & state_) == 0 ) 167 if( ((*i)->mode & state_) == 0 ){ 168 COUT(4) << "not getting data: " << std::endl; 168 169 continue; // this variable should only be received 170 } 169 171 switch((*i)->type){ 170 172 case DATA: … … 199 201 COUT(5) << "Synchronisable: objectID " << vars.objectID << ", classID " << vars.classID << " size: " << vars.length << " synchronising data" << std::endl; 200 202 for(i=syncList->begin(); i!=syncList->end(); i++){ 201 if( ((*i)->mode ^ state_) == 0 ) 202 continue; // this variable should only be sent 203 if( ((*i)->mode ^ state_) == 0 ){ 204 COUT(5) << "synchronisable: not updating variable " << std::endl; 205 continue; // this variable should only be updated 206 } 203 207 COUT(5) << "Synchronisable: element size: " << (*i)->size << " type: " << (*i)->type << std::endl; 204 208 switch((*i)->type){
Note: See TracChangeset
for help on using the changeset viewer.