Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 19, 2010, 2:27:06 PM (14 years ago)
Author:
scheusso
Message:

some () structural changes
some functional changes (GamestateClient replaced through GamestateManager on client)
reliable packets get buffered until a recent gamestate arrived and got processed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network5/src/libraries/network/Server.cc

    r7773 r7777  
    162162    while(temp){
    163163      chat = new packet::Chat(message, playerID);
    164       chat->setClientID(temp->getID());
    165       if(!chat->send())
     164      chat->setPeerID(temp->getID());
     165      if(!chat->send( static_cast<Host*>(this) ))
    166166        COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
    167167      temp = temp->next();
     
    220220
    221221      // send function calls to clients
    222       FunctionCallManager::sendCalls();
     222      FunctionCallManager::sendCalls( static_cast<Host*>(this) );
    223223
    224224      //this steers our network frequency
     
    271271      return;
    272272    GamestateManager::update();
    273     COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;
     273//     COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;
    274274    //std::cout << "updated gamestate, sending it" << std::endl;
    275275    //if(clients->getGamestateID()!=GAMESTATEID_INITIAL)
    276     sendGameState();
     276    sendGameStates();
    277277    sendObjectDeletes();
    278     COUT(5) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl;
     278//     COUT(5) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl;
    279279    //std::cout << "sent gamestate" << std::endl;
    280280  }
    281281
    282   bool Server::processPacket( ENetPacket *packet, ENetPeer *peer ){
    283     packet::Packet *p = packet::Packet::createPacket(packet, peer);
    284     return p->process();
    285   }
    286 
    287   /**
    288   * sends the gamestate
    289   */
    290   bool Server::sendGameState()
    291   {
    292 //     COUT(5) << "Server: starting function sendGameState" << std::endl;
    293 //     ClientInformation *temp = ClientInformation::getBegin();
    294 //     bool added=false;
    295 //     while(temp != NULL){
    296 //       if( !(temp->getSynched()) ){
    297 //         COUT(5) << "Server: not sending gamestate" << std::endl;
    298 //         temp=temp->next();
    299 //         if(!temp)
    300 //           break;
    301 //         continue;
    302 //       }
    303 //       COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl;
    304 //       COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
    305 //       int cid = temp->getID(); //get client id
    306 //       packet::Gamestate *gs = GamestateManager::popGameState(cid);
    307 //       if(gs==NULL){
    308 //         COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl;
    309 //         temp = temp->next();
    310 //         continue;
    311 //       }
    312 //       //std::cout << "adding gamestate" << std::endl;
    313 //       gs->setClientID(cid);
    314 //       if ( !gs->send() ){
    315 //         COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl;
    316 //         temp->addFailure();
    317 //       }else
    318 //         temp->resetFailures();
    319 //       added=true;
    320 //       temp=temp->next();
    321 //       // gs gets automatically deleted by enet callback
    322 //     }
    323     GamestateManager::sendGamestates();
     282  /**
     283  * sends the current gamestate to all peers
     284  */
     285  bool Server::sendGameStates()
     286  {
     287    std::vector<packet::Gamestate*> gamestates = GamestateManager::getGamestates();
     288    std::vector<packet::Gamestate*>::iterator it;
     289    for( it = gamestates.begin(); it != gamestates.end(); ++it )
     290    {
     291      (*it)->send(static_cast<Host*>(this));
     292    }
    324293    return true;
    325294  }
     295
    326296
    327297  bool Server::sendObjectDeletes()
     
    348318      packet::DeleteObjects *cd = new packet::DeleteObjects(*del);
    349319      assert(cd);
    350       cd->setClientID(cid);
    351       if ( !cd->send() )
    352         COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl;
     320      cd->setPeerID(cid);
     321      if ( !cd->send( static_cast<Host*>(this) ) )
     322        COUT(3) << "Server: packet with client id (cid): " << cid << " not sended" << std::endl;
    353323      temp=temp->next();
    354324      // gs gets automatically deleted by enet callback
     
    374344    // inform all the listeners
    375345    ClientConnectionListener::broadcastClientConnected(newid);
     346    GamestateManager::addPeer(newid);
    376347
    377348    ++newid;
     
    394365    }
    395366  }
     367 
     368  void Server::processPacket(packet::Packet* packet)
     369  {
     370    if( packet->isReliable() )
     371    {
     372      if( this->getLastProcessedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() )
     373        packet->process(static_cast<Host*>(this));
     374      else
     375        this->packetQueue_.push_back(packet);
     376    }
     377    else
     378      packet->process(static_cast<Host*>(this));
     379  }
     380
    396381
    397382  bool Server::createClient(int clientID)
     
    403388      return false;
    404389    }
    405     COUT(5) << "Con.Man: creating client id: " << temp->getID() << std::endl;
     390    COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl;
    406391
    407392    // synchronise class ids
     
    410395    // now synchronise functionIDs
    411396    packet::FunctionIDs *fIDs = new packet::FunctionIDs();
    412     fIDs->setClientID(clientID);
    413     bool b = fIDs->send();
     397    fIDs->setPeerID(clientID);
     398    bool b = fIDs->send( static_cast<Host*>(this) );
    414399    assert(b);
    415400
    416401    temp->setSynched(true);
     402    GamestateManager::setSynched(clientID);
     403   
    417404    COUT(4) << "sending welcome" << std::endl;
    418405    packet::Welcome *w = new packet::Welcome(temp->getID(), temp->getShipID());
    419     w->setClientID(temp->getID());
    420     b = w->send();
     406    w->setPeerID(temp->getID());
     407    b = w->send( static_cast<Host*>(this) );
    421408    assert(b);
    422409    packet::Gamestate *g = new packet::Gamestate();
    423     g->setClientID(temp->getID());
    424     b = g->collectData(0,0x1);
     410    g->setPeerID(temp->getID());
     411    b = g->collectData(0,packet::GAMESTATE_MODE_SERVER);
     412    assert(b);
    425413    if(!b)
    426414      return false; //no data for the client
    427415//     b = g->compressData();
    428416//     assert(b);
    429     b = g->send();
     417    b = g->send( static_cast<Host*>(this) );
    430418    assert(b);
    431419    return true;
     
    435423  {
    436424    ServerConnection::disconnectClient( client );
    437     GamestateManager::removeClient(client);
     425    GamestateManager::removePeer(client->getID());
    438426    // inform all the listeners
    439427    // ClientConnectionListener::broadcastClientDisconnected(client->getID()); // this is done in ClientInformation now
     
    457445    {
    458446      chat = new packet::Chat(message, clientID);
    459       chat->setClientID(temp->getID());
    460       if(!chat->send())
     447      chat->setPeerID(temp->getID());
     448      if(!chat->send( static_cast<Host*>(this) ))
    461449        COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
    462450      temp = temp->next();
     
    473461    int failures=0;
    474462    packet::ClassID *classid = new packet::ClassID();
    475     classid->setClientID(clientID);
    476     while(!classid->send() && failures < 10){
     463    classid->setPeerID(clientID);
     464    while(!classid->send( static_cast<Host*>(this) ) && failures < 10){
    477465      failures++;
    478466    }
Note: See TracChangeset for help on using the changeset viewer.