Changeset 1245 for code/branches/network3/src/network/ConnectionManager.cc
- Timestamp:
- May 7, 2008, 4:39:42 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.