Changeset 7823 for code/branches/network6/src/libraries/network/Server.cc
- Timestamp:
- Dec 28, 2010, 4:46:42 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network6/src/libraries/network/Server.cc
r7801 r7823 57 57 #include "packet/Welcome.h" 58 58 #include "ChatListener.h" 59 #include "ClientInformation.h"59 // #include "ClientInformation.h" 60 60 #include "FunctionCallManager.h" 61 61 #include "GamestateManager.h" … … 152 152 bool Server::processChat(const std::string& message, unsigned int playerID) 153 153 { 154 ClientInformation *temp = ClientInformation::getBegin();154 // ClientInformation *temp = ClientInformation::getBegin(); 155 155 packet::Chat *chat; 156 while(temp){157 158 chat->setPeerID(temp->getID());159 if(!chat->send( static_cast<Host*>(this) ))160 COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;161 temp = temp->next();162 }156 // while(temp){ 157 chat = new packet::Chat(message, playerID); 158 chat->setPeerID(NETWORK_PEER_ID_BROADCAST); 159 chat->send( static_cast<Host*>(this) ); 160 // COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl; 161 // temp = temp->next(); 162 // } 163 163 // COUT(1) << "Player " << playerID << ": " << message << std::endl; 164 164 return true; … … 207 207 //helper_HandleMasterServerRequests(); 208 208 209 if ( ClientInformation::hasClients() )209 if ( GamestateManager::hasPeers() ) 210 210 { 211 211 // process incoming gamestates … … 237 237 unsigned int Server::getRTT(unsigned int clientID) 238 238 { 239 assert(ClientInformation::findClient(clientID)); 240 return ClientInformation::findClient(clientID)->getRTT(); 239 // assert(ClientInformation::findClient(clientID)); 240 // return ClientInformation::findClient(clientID)->getRTT(); 241 // TODO: reimplement 242 return 0; 241 243 } 242 244 243 245 void Server::printRTT() 244 246 { 245 for( ClientInformation* temp=ClientInformation::getBegin(); temp!=0; temp=temp->next() )246 COUT(0) << "Round trip time to client with ID: " << temp->getID() << " is " << temp->getRTT() << " ms" << endl;247 // for( ClientInformation* temp=ClientInformation::getBegin(); temp!=0; temp=temp->next() ) 248 // COUT(0) << "Round trip time to client with ID: " << temp->getID() << " is " << temp->getRTT() << " ms" << endl; 247 249 } 248 250 … … 252 254 double Server::getPacketLoss(unsigned int clientID) 253 255 { 254 assert(ClientInformation::findClient(clientID)); 255 return ClientInformation::findClient(clientID)->getPacketLoss(); 256 // assert(ClientInformation::findClient(clientID)); 257 // return ClientInformation::findClient(clientID)->getPacketLoss(); 258 return 0.; 256 259 } 257 260 … … 261 264 void Server::updateGamestate() 262 265 { 263 if( ClientInformation::getBegin()==NULL)266 if( this->clientIDs_.size()==0 ) 264 267 //no client connected 265 268 return; … … 291 294 bool Server::sendObjectDeletes() 292 295 { 293 ClientInformation *temp = ClientInformation::getBegin();294 if( temp == NULL )296 // ClientInformation *temp = ClientInformation::getBegin(); 297 // if( temp == NULL ) 295 298 //no client connected 299 if( this->clientIDs_.size()==0 ) 296 300 return true; 297 301 packet::DeleteObjects *del = new packet::DeleteObjects(); … … 302 306 } 303 307 // COUT(3) << "sending DeleteObjects" << std::endl; 304 while(temp != NULL){305 if( !(temp->getSynched()) )306 {307 COUT(5) << "Server: not sending gamestate" << std::endl;308 temp=temp->next();309 continue;310 }311 int cid = temp->getID(); //get client id312 packet::DeleteObjects *cd = new packet::DeleteObjects(*del);313 assert(cd);314 cd->setPeerID(cid);315 if ( !cd->send( static_cast<Host*>(this) ) )316 COUT(3) << "Server: packet with client id (cid): " << cid << " not sended" << std::endl;317 temp=temp->next();308 // while(temp != NULL){ 309 // if( !(temp->getSynched()) ) 310 // { 311 // COUT(5) << "Server: not sending gamestate" << std::endl; 312 // temp=temp->next(); 313 // continue; 314 // } 315 // int cid = temp->getID(); //get client id 316 // packet::DeleteObjects *cd = new packet::DeleteObjects(*del); 317 // assert(cd); 318 del->setPeerID(NETWORK_PEER_ID_BROADCAST); 319 if ( !del->send( static_cast<Host*>(this) ) ) 320 COUT(3) << "Server: could not broadcast deleteObjects packet" << std::endl; 321 // temp=temp->next(); 318 322 // gs gets automatically deleted by enet callback 319 }320 delete del;323 // } 324 // delete del; 321 325 return true; 322 326 } 323 327 324 328 325 void Server::addPeer( ENetEvent *event)326 { 327 static unsigned int newid=1;328 329 COUT(2) << "Server: adding client" << std::endl;330 ClientInformation *temp = ClientInformation::insertBack(new ClientInformation);331 if(!temp)332 {333 COUT(2) << "Server: could not add client" << std::endl;334 }335 temp->setID(newid);336 temp->setPeer(event->peer);329 void Server::addPeer(uint32_t peerID) 330 { 331 // static unsigned int newid=1; 332 // 333 // COUT(2) << "Server: adding client" << std::endl; 334 // ClientInformation *temp = ClientInformation::insertBack(new ClientInformation); 335 // if(!temp) 336 // { 337 // COUT(2) << "Server: could not add client" << std::endl; 338 // } 339 // temp->setID(newid); 340 // temp->setPeer(event->peer); 337 341 338 342 // inform all the listeners 339 ClientConnectionListener::broadcastClientConnected(newid); 340 GamestateManager::addPeer(newid); 341 342 ++newid; 343 344 COUT(3) << "Server: added client id: " << temp->getID() << std::endl; 345 createClient(temp->getID()); 343 this->clientIDs_.push_back(peerID); 344 ClientConnectionListener::broadcastClientConnected(peerID); 345 GamestateManager::addPeer(peerID); 346 347 // ++newid; 348 349 COUT(3) << "Server: added client id: " << peerID << std::endl; 350 createClient(peerID); 346 351 } 347 352 348 void Server::removePeer( ENetEvent *event)353 void Server::removePeer(uint32_t peerID) 349 354 { 350 355 COUT(4) << "removing client from list" << std::endl; 351 ClientInformation *client = ClientInformation::findClient(&event->peer->address); 352 if(!client) 353 return; 354 else 355 { 356 GamestateManager::removePeer(client->getID()); 356 // ClientInformation *client = ClientInformation::findClient(&event->peer->address); 357 // if(!client) 358 // return; 359 // else 360 // { 361 std::vector<uint32_t>::iterator it; 362 for( it=this->clientIDs_.begin(); it!=this->clientIDs_.end(); ++it ) 363 { 364 if( *it == peerID ) 365 { 366 this->clientIDs_.erase(it); 367 break; 368 } 369 } 370 ClientConnectionListener::broadcastClientDisconnected(peerID); 371 GamestateManager::removePeer(peerID); 357 372 //ServerConnection::disconnectClient( client ); 358 373 //ClientConnectionListener::broadcastClientDisconnected( client->getID() ); //this is done in ClientInformation now 359 delete client;360 }374 // delete client; 375 // } 361 376 } 362 377 … … 377 392 bool Server::createClient(int clientID) 378 393 { 379 ClientInformation *temp = ClientInformation::findClient(clientID);380 if(!temp)381 {382 COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl;383 return false;384 }385 COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl;394 // ClientInformation *temp = ClientInformation::findClient(clientID); 395 // if(!temp) 396 // { 397 // COUT(2) << "Server. could not create client with id: " << clientID << std::endl; 398 // return false; 399 // } 400 // COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl; 386 401 387 402 // synchronise class ids 388 syncClassid( temp->getID());403 syncClassid(clientID); 389 404 390 405 // now synchronise functionIDs … … 394 409 assert(b); 395 410 396 temp->setSynched(true);411 // temp->setSynched(true); 397 412 GamestateManager::setSynched(clientID); 398 413 399 414 COUT(4) << "sending welcome" << std::endl; 400 packet::Welcome *w = new packet::Welcome( temp->getID(), temp->getShipID());401 w->setPeerID( temp->getID());415 packet::Welcome *w = new packet::Welcome(clientID, OBJECTID_UNKNOWN); 416 w->setPeerID(clientID); 402 417 b = w->send( static_cast<Host*>(this) ); 403 418 assert(b); 404 419 packet::Gamestate *g = new packet::Gamestate(); 405 g->setPeerID( temp->getID());420 g->setPeerID(clientID); 406 421 b = g->collectData(0,packet::GAMESTATE_MODE_SERVER); 407 422 assert(b); … … 415 430 } 416 431 417 void Server::disconnectClient( ClientInformation *client)418 { 419 ServerConnection::disconnectClient( client );420 GamestateManager::removePeer( client->getID());432 void Server::disconnectClient( uint32_t clientID ) 433 { 434 ServerConnection::disconnectClient( clientID ); 435 GamestateManager::removePeer( clientID ); 421 436 // inform all the listeners 422 437 // ClientConnectionListener::broadcastClientDisconnected(client->getID()); // this is done in ClientInformation now … … 430 445 bool Server::broadcast(const std::string& message) 431 446 { 432 return this->sendChat(message, CLIENTID_UNKNOWN);447 return this->sendChat(message, NETWORK_PEER_ID_BROADCAST); 433 448 } 434 449 435 450 bool Server::sendChat(const std::string& message, unsigned int clientID) 436 451 { 437 ClientInformation *temp = ClientInformation::getBegin();452 // ClientInformation *temp = ClientInformation::getBegin(); 438 453 packet::Chat *chat; 439 while(temp)454 // while(temp) 440 455 { 441 456 chat = new packet::Chat(message, clientID); 442 chat->setPeerID( temp->getID());443 if(!chat->send( static_cast<Host*>(this) ))444 COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;445 temp = temp->next();457 chat->setPeerID(NETWORK_PEER_ID_BROADCAST); 458 chat->send( static_cast<Host*>(this) ); 459 // COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl; 460 // temp = temp->next(); 446 461 } 447 462 // COUT(1) << "Player " << Host::getPlayerID() << ": " << message << std::endl;
Note: See TracChangeset
for help on using the changeset viewer.