Changeset 1499
- Timestamp:
- Jun 1, 2008, 1:44:44 PM (16 years ago)
- Location:
- code/branches/network/src/network
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/Client.cc
r1494 r1499 153 153 if(!isConnected) 154 154 return false; 155 if(client_connection.addPacket(pck_gen.chatMessage( message.c_str() )))156 return client_connection.sendPackets();155 return client_connection.addPacket(pck_gen.chatMessage( message.c_str() )); 156 //return client_connection.sendPackets(); 157 157 // send packets 158 158 return false; 159 }160 161 162 /**163 * Sends out all the packets queued by addXXX164 */165 bool Client::sendPackets(){166 if(!isConnected)167 return false;168 // send packets169 client_connection.sendPackets();170 return true;171 159 } 172 160 … … 215 203 }// otherwise we had no gamestate to load 216 204 gamestate.cleanup(); 217 if(!client_connection.sendPackets())218 COUT(3) << "Problem sending packets to server" << std::endl; 205 /*if(!client_connection.sendPackets()) 206 COUT(3) << "Problem sending packets to server" << std::endl;*/ 219 207 return; 220 208 } -
code/branches/network/src/network/Client.h
r1494 r1499 77 77 bool sendChat( std::string message ); 78 78 79 bool sendPackets();80 81 79 int getShipID(){return shipID_;} 82 80 int getClientID(){return clientID_;} -
code/branches/network/src/network/ClientConnection.cc
r1494 r1499 163 163 return; 164 164 } 165 event = new ENetEvent; 165 166 //main loop 166 167 while(!quit){ 167 event = new ENetEvent;168 168 //std::cout << "connection loop" << std::endl; 169 169 { … … 185 185 if ( !processData(event) ) COUT(2) << "Current packet was not pushed to packetBuffer -> ev ongoing SegFault" << std::endl; 186 186 COUT(5) << "Cl.Con: processed Data in receiver-thread while loop" << std::endl; 187 event = new ENetEvent; 187 188 break; 188 189 case ENET_EVENT_TYPE_DISCONNECT: … … 192 193 break; 193 194 case ENET_EVENT_TYPE_NONE: 194 continue; 195 //receiverThread_->yield(); 196 usleep(1000); 197 break; 195 198 } 196 receiverThread_->yield();197 199 } 198 200 // now disconnect -
code/branches/network/src/network/ClientConnection.h
r1494 r1499 54 54 #define NETWORK_PORT 55556 55 55 #define NETWORK_CLIENT_MAX_CONNECTIONS 5 56 #define NETWORK_CLIENT_TIMEOUT 1 056 #define NETWORK_CLIENT_TIMEOUT 1 57 57 #define NETWORK_CLIENT_CHANNELS 2 58 58 -
code/branches/network/src/network/ConnectionManager.cc
r1497 r1499 169 169 } 170 170 171 // we actually dont need that function, because host_service does that for us 171 172 bool ConnectionManager::sendPackets() { 172 173 if(server==NULL) … … 194 195 } 195 196 197 event = new ENetEvent; 196 198 while(!quit){ 197 event = new ENetEvent;198 199 { //mutex scope 199 200 boost::recursive_mutex::scoped_lock lock(enet_mutex_); … … 221 222 //if(head_->findClient(&event->peer->address)) 222 223 processData(event); 224 event = new ENetEvent; 223 225 // else 224 226 // COUT(3) << "received a packet from a client we don't know" << std::endl; … … 228 230 //break; 229 231 case ENET_EVENT_TYPE_NONE: 230 delete event;231 receiverThread_->yield();232 //receiverThread_->yield(); 233 usleep(1000); 232 234 break; 233 235 } … … 287 289 } 288 290 289 /** 290 This function adds a client that connects to the clientlist of the server 291 NOTE: if you change this, don't forget to change the test function 292 addClientTest in diffTest.cc since addClient is not good for testing because of syncClassid 293 */ 294 /*bool ConnectionManager::addClient(ENetEvent *event) { 295 ClientInformation *temp = head_->insertBack(new ClientInformation); 296 if(!temp){ 297 COUT(2) << "Conn.Man. could not add client" << std::endl; 298 return false; 299 } 300 if(temp->prev()->getHead()) { //not good if you use anything else than insertBack 301 temp->prev()->setID(0); //bugfix: not necessary but usefull 302 temp->setID(1); 303 } 304 else 305 temp->setID(temp->prev()->getID()+1); 306 temp->setPeer(event->peer); 307 COUT(3) << "Con.Man: added client id: " << temp->getID() << std::endl; 308 return true; 309 }*/ 291 310 292 311 293 int ConnectionManager::getClientID(ENetPeer peer) { … … 341 323 ++it; 342 324 } 343 sendPackets();325 //sendPackets(); 344 326 COUT(4) << "syncClassid:\tall synchClassID packets have been sent" << std::endl; 345 327 } 346 328 347 /*bool ConnectionManager::createClient(int clientID){ 348 ClientInformation *temp = head_->findClient(clientID); 349 if(!temp){ 350 COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl; 351 return false; 352 } 353 COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl; 354 syncClassid(temp->getID()); 355 COUT(4) << "creating spaceship for clientid: " << temp->getID() << std::endl; 356 // TODO: this is only a hack, until we have a possibility to define default player-join actions 357 if(!createShip(temp)) 358 COUT(2) << "Con.Man. could not create ship for clientid: " << clientID << std::endl; 359 else 360 COUT(3) << "created spaceship" << std::endl; 361 temp->setSynched(true); 362 COUT(3) << "sending welcome" << std::endl; 363 sendWelcome(temp->getID(), temp->getShipID(), true); 364 return true; 365 }*/ 366 367 /*bool ConnectionManager::removeClient(int clientID){ 368 boost::recursive_mutex::scoped_lock lock(head_->mutex_); 369 orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>::start(); 370 ClientInformation *client = head_->findClient(clientID); 371 if(!client) 372 return false; 373 while(it){ 374 if(it->objectID!=client->getShipID()){ 375 ++it; 376 continue; 377 } 378 orxonox::Iterator<orxonox::SpaceShip> temp=it; 379 ++it; 380 delete *temp; 381 return head_->removeClient(clientID); 382 } 383 return false; 384 }*/ 385 386 /* bool ConnectionManager::createShip(ClientInformation *client){ 387 if(!client) 388 return false; 389 orxonox::Identifier* id = ID("SpaceShip"); 390 if(!id){ 391 COUT(4) << "We could not create the SpaceShip for client: " << client->getID() << std::endl; 392 return false; 393 } 394 orxonox::SpaceShip *no = dynamic_cast<orxonox::SpaceShip *>(id->fabricate()); 395 no->setPosition(orxonox::Vector3(0,0,80)); 396 no->setScale(10); 397 //no->setYawPitchRoll(orxonox::Degree(-90),orxonox::Degree(-90),orxonox::Degree(0)); 398 no->setMesh("assff.mesh"); 399 no->setMaxSpeed(500); 400 no->setMaxSideAndBackSpeed(50); 401 no->setMaxRotation(1.0); 402 no->setTransAcc(200); 403 no->setRotAcc(3.0); 404 no->setTransDamp(75); 405 no->setRotDamp(1.0); 406 no->setCamera("cam_"+client->getID()); 407 no->classID = id->getNetworkID(); 408 no->create(); 409 410 client->setShipID(no->objectID); 411 return true; 412 }*/ 329 413 330 414 331 bool ConnectionManager::removeShip(ClientInformation *client){ … … 425 342 bool ConnectionManager::sendWelcome(int clientID, int shipID, bool allowed){ 426 343 if(addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID)){ 427 sendPackets();344 //sendPackets(); 428 345 return true; 429 346 }else … … 448 365 449 366 450 // int ConnectionManager::getNumberOfClients() { 451 // 452 // return clientsShip.size(); 453 // } 454 455 /*void ConnectionManager::addClientsObjectID( int clientID, int objectID ) { 456 COUT(4) << "ship of client: " << clientID << ": " << objectID << " mapped" << std::endl; 457 clientsShip.insert( std::make_pair( clientID, objectID ) ); 367 458 368 } 459 460 int ConnectionManager::getClientsShipID( int clientID ) {461 return clientsShip[clientID];462 }463 464 int ConnectionManager::getObjectsClientID( int objectID ) {465 std::map<int, int>::iterator iter;466 for( iter = clientsShip.begin(); iter != clientsShip.end(); iter++ ) {467 if( iter->second == objectID ) return iter->first;468 }469 return -99;470 }471 472 void ConnectionManager::deleteClientIDReg( int clientID ) {473 clientsShip.erase( clientID );474 }475 476 void ConnectionManager::deleteObjectIDReg( int objectID ) {477 std::map<int, int>::iterator iter = clientsShip.begin();478 for( iter = clientsShip.begin(); iter != clientsShip.end(); iter++ ) {479 if( iter->second == objectID ) break;480 }481 clientsShip.erase( iter->first );482 }*/483 } -
code/branches/network/src/network/ConnectionManager.h
r1494 r1499 62 62 #define NETWORK_PORT 55556 63 63 #define NETWORK_MAX_CONNECTIONS 50 64 #define NETWORK_WAIT_TIMEOUT 1 064 #define NETWORK_WAIT_TIMEOUT 1 65 65 66 66 struct ClientList{ -
code/branches/network/src/network/Server.cc
r1494 r1499 130 130 ENetPacket *packet = packet_gen.chatMessage(msg.c_str()); 131 131 //std::cout <<"adding packets" << std::endl; 132 if(connection->addPacketAll(packet)) 133 //std::cout <<"added packets" << std::endl; 134 return connection->sendPackets(); 135 else 136 return false; 132 return connection->addPacketAll(packet); 137 133 } 138 134 … … 145 141 ENetPacket *packet = packet_gen.chatMessage(msg); 146 142 COUT(4) <<"Server: adding Packets" << std::endl; 147 connection->addPacketAll(packet); 148 //std::cout <<"added packets" << std::endl; 149 if (connection->sendPackets()){ 150 COUT(4) << "Server: Sucessfully" << std::endl; 151 return true; 152 } 153 return false; 143 return connection->addPacketAll(packet); 154 144 } 155 145 … … 184 174 if(!event) 185 175 continue; 176 assert(event->type != ENET_EVENT_TYPE_NONE); 186 177 switch( event->type ) { 187 178 case ENET_EVENT_TYPE_CONNECT: … … 265 256 delete gs; 266 257 } 267 if(added) {258 /*if(added) { 268 259 //std::cout << "send gamestates from server.cc in sendGameState" << std::endl; 269 260 return connection->sendPackets(); 270 } 271 COUT(5) << "Server: had no gamestates to send" << std::endl;272 return false;261 }*/ 262 //COUT(5) << "Server: had no gamestates to send" << std::endl; 263 return true; 273 264 } 274 265
Note: See TracChangeset
for help on using the changeset viewer.