Changeset 1299 for code/branches/merge/src/network/ConnectionManager.cc
- Timestamp:
- May 15, 2008, 10:08:41 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/merge/src/network/ConnectionManager.cc
r1282 r1299 101 101 ENetPacket *packet=getPacket(address); 102 102 ClientInformation *temp =head_->findClient(&address); 103 if(!temp) 104 return NULL; 103 105 clientID=temp->getID(); 104 106 return packet; … … 124 126 125 127 bool ConnectionManager::addPacket(ENetPacket *packet, ENetPeer *peer) { 126 if(enet_peer_send(peer, (enet_uint8)head_->findClient(&(peer->address))->getID() , packet)!=0) 128 ClientInformation *temp = head_->findClient(&(peer->address)); 129 if(!temp) 130 return false; 131 if(enet_peer_send(peer, (enet_uint8)temp->getID() , packet)!=0) 127 132 return false; 128 133 return true; … … 130 135 131 136 bool ConnectionManager::addPacket(ENetPacket *packet, int clientID) { 132 if(enet_peer_send(head_->findClient(clientID)->getPeer(), (enet_uint8)clientID, packet)!=0) 137 ClientInformation *temp = head_->findClient(clientID); 138 if(!temp) 139 return false; 140 if(enet_peer_send(temp->getPeer(), (enet_uint8)clientID, packet)!=0) 133 141 return false; 134 142 return true; … … 195 203 if(head_->findClient(&event->peer->address)) 196 204 processData(event); 205 else 206 COUT(3) << "received a packet from a client we don't know" << std::endl; 197 207 break; 198 208 case ENET_EVENT_TYPE_DISCONNECT: … … 233 243 case ENET_EVENT_TYPE_DISCONNECT: 234 244 COUT(4) << "disconnecting all clients" << std::endl; 235 delete head_->findClient(&(event.peer->address)); 245 if(head_->findClient(&(event.peer->address))) 246 delete head_->findClient(&(event.peer->address)); 236 247 //maybe needs bugfix: might also be a reason for the server to crash 237 248 temp = temp->next(); … … 259 270 bool ConnectionManager::addClient(ENetEvent *event) { 260 271 ClientInformation *temp = head_->insertBack(new ClientInformation); 272 if(!temp){ 273 COUT(2) << "Conn.Man. could not add client" << std::endl; 274 return false; 275 } 261 276 if(temp->prev()->head) { //not good if you use anything else than insertBack 262 277 temp->prev()->setID(0); //bugfix: not necessary but usefull … … 266 281 temp->setID(temp->prev()->getID()+1); 267 282 temp->setPeer(event->peer); 268 COUT( 4) << "Con.Man: added client id: " << temp->getID() << std::endl;283 COUT(3) << "Con.Man: added client id: " << temp->getID() << std::endl; 269 284 return true; 270 285 } … … 283 298 284 299 void ConnectionManager::syncClassid(int clientID) { 285 unsigned int network_id=0 ;300 unsigned int network_id=0, failures=0; 286 301 std::string classname; 287 302 orxonox::Identifier *id; … … 295 310 COUT(4) << "Con.Man:syncClassid:\tnetwork_id: " << network_id << ", classname: " << classname << std::endl; 296 311 297 addPacket(packet_gen.clid( (int)network_id, classname ), clientID); 298 312 while(!addPacket(packet_gen.clid( (int)network_id, classname ), clientID) && failures < 10){ 313 failures++; 314 } 299 315 ++it; 300 316 } … … 305 321 bool ConnectionManager::createClient(int clientID){ 306 322 ClientInformation *temp = head_->findClient(clientID); 323 if(!temp){ 324 COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl; 325 return false; 326 } 307 327 COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl; 308 328 syncClassid(temp->getID()); 309 329 COUT(4) << "creating spaceship for clientid: " << temp->getID() << std::endl; 310 330 // TODO: this is only a hack, untill we have a possibility to define default player-join actions 311 createShip(temp); 312 COUT(4) << "created spaceship" << std::endl; 331 if(!createShip(temp)) 332 COUT(2) << "Con.Man. could not create ship for clientid: " << clientID << std::endl; 333 else 334 COUT(3) << "created spaceship" << std::endl; 313 335 temp->setSynched(true); 314 COUT( 4) << "sending welcome" << std::endl;336 COUT(3) << "sending welcome" << std::endl; 315 337 sendWelcome(temp->getID(), temp->getShipID(), true); 316 338 return true; … … 319 341 bool ConnectionManager::removeClient(int clientID){ 320 342 orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>::start(); 343 ClientInformation *client = head_->findClient(clientID); 344 if(!client) 345 return false; 321 346 while(it){ 322 if(it->objectID!= head_->findClient(clientID)->getShipID()){347 if(it->objectID!=client->getShipID()){ 323 348 ++it; 324 349 continue; … … 333 358 334 359 bool ConnectionManager::createShip(ClientInformation *client){ 360 if(!client) 361 return false; 335 362 orxonox::Identifier* id = ID("SpaceShip"); 336 363 if(!id){ … … 369 396 370 397 bool ConnectionManager::sendWelcome(int clientID, int shipID, bool allowed){ 371 addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID); 372 sendPackets(); 373 return true; 398 if(addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID)){ 399 sendPackets(); 400 return true; 401 }else 402 return false; 374 403 } 375 404
Note: See TracChangeset
for help on using the changeset viewer.