Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 4, 2008, 9:45:05 PM (16 years ago)
Author:
scheusso
Message:

further changes

File:
1 edited

Legend:

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

    r1699 r1705  
    4545
    4646#include "ConnectionManager.h"
    47 #include "PacketTypes.h"
    48 #include "GameStateManager.h"
     47#include "GamestateManager.h"
    4948#include "ClientInformation.h"
    5049#include "util/Sleep.h"
     
    5352#include "packet/Chat.h"
    5453#include "packet/Packet.h"
     54#include "packet/Welcome.h"
    5555
    5656namespace network
     
    6565  Server::Server() {
    6666    timeSinceLastUpdate_=0;
    67     packet_gen = PacketGenerator();
    6867    connection = new ConnectionManager();
    69     gamestates = new GameStateManager();
     68    gamestates_ = new GamestateManager();
    7069  }
    7170 
    7271  Server::Server(int port){
    7372    timeSinceLastUpdate_=0;
    74     packet_gen = PacketGenerator();
    7573    connection = new ConnectionManager(port);
    76     gamestates = new GameStateManager();
     74    gamestates_ = new GamestateManager();
    7775  }
    7876
     
    8482  Server::Server(int port, std::string bindAddress) {
    8583    timeSinceLastUpdate_=0;
    86     packet_gen = PacketGenerator();
    8784    connection = new ConnectionManager(port, bindAddress);
    88     gamestates = new GameStateManager();
     85    gamestates_ = new GamestateManager();
    8986  }
    9087
     
    9693  Server::Server(int port, const char *bindAddress) {
    9794    timeSinceLastUpdate_=0;
    98     packet_gen = PacketGenerator();
    9995    connection = new ConnectionManager(port, bindAddress);
    100     gamestates = new GameStateManager();
     96    gamestates_ = new GamestateManager();
    10197  }
    10298
     
    173169      timeSinceLastUpdate_=(float)((int)(timeSinceLastUpdate_*NETWORK_FREQUENCY))/timeSinceLastUpdate_;
    174170//      timeSinceLastUpdate_-=1./NETWORK_FREQUENCY;
    175       gamestates->processGameStates();
     171      gamestates_->processGamestates();
    176172      updateGamestate();
    177173    }
     
    191187  void Server::processQueue() {
    192188    ENetEvent *event;
    193     int clientID=-1;
    194189    while(!connection->queueEmpty()){
    195190      //std::cout << "Client " << clientID << " sent: " << std::endl;
     
    209204        break;
    210205      case ENET_EVENT_TYPE_RECEIVE:
    211         if(ClientInformation::findClient(&event->peer->address)){
    212           clientID = ClientInformation::findClient(&event->peer->address)->getID();
    213           if( !elaborate(event->packet, clientID) )
    214             COUT(3) << "Server: could not elaborate" << std::endl;
    215         }
     206        if(!processPacket(event->packet, event->peer))
     207          COUT(3) << "processing incoming packet failed" << std::endl;
    216208        break;
    217209      default:
     
    227219  */
    228220  void Server::updateGamestate() {
    229     gamestates->update();
     221    gamestates_->update();
    230222    COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;
    231223    //std::cout << "updated gamestate, sending it" << std::endl;
     
    236228  }
    237229
     230  bool Server::processPacket( ENetPacket *packet, ENetPeer *peer ){
     231    packet::Packet p = packet::Packet(packet, peer);
     232    return p.getPacketContent()->process();
     233  }
     234 
    238235  /**
    239236  * sends the gamestate
     
    257254      int cid = temp->getID(); //get client id
    258255      COUT(5) << "Server: got acked (gamestate) ID from clientlist: " << gid << std::endl;
    259       GameStateCompressed *gs = gamestates->popGameState(cid);
     256      packet::Gamestate *gs = gamestates_->popGameState(cid);
    260257      if(gs==NULL){
    261258        COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl;
     
    263260      }
    264261      //std::cout << "adding gamestate" << std::endl;
    265       ENetPacket *packet = packet_gen.gstate(gs);
    266       if(!packet)
    267         continue;
    268       if ( !(connection->addPacket(packet, cid)) ){
     262      packet::Packet packet(gs);
     263      packet.setClientID(cid);
     264      if ( !packet.send() ){
    269265        COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl;
    270266        temp->addFailure();
     
    277273      temp=temp->next();
    278274      // now delete gamestate
    279       delete[] gs->data;
    280275      delete gs;
    281276    }
     
    286281    //COUT(5) << "Server: had no gamestates to send" << std::endl;
    287282    return true;
    288   }
    289 
    290   void Server::processAck( ack *data, int clientID) {
    291     COUT(4) << "Server: processing ack from client: " << clientID << "; ack-id: " << data->a << std::endl;
    292     gamestates->ackGameState(clientID, data->a);
    293     delete data;
    294   }
    295  
    296   bool Server::processConnectRequest( connectRequest *con, int clientID ){
    297     //(COUT(3) << "processing connectRequest " << std::endl;
    298     //connection->addPacket(packet_gen.gstate(gamestates->popGameState(clientID)) , clientID);
    299     //createClient(clientID);
    300     delete con;
    301     return true;
    302   }
    303  
    304   bool Server::ackGamestateID(int gamestateID, int clientID){
    305     gamestates->ackGameState(clientID, gamestateID);
    306     return true;
    307   }
    308  
    309   void Server::processGamestate( GameStateCompressed *data, int clientID){
    310     COUT(4) << "processing partial gamestate from client " << clientID << std::endl;
    311     gamestates->addGameState(data, clientID);
    312         /*COUT(3) << "Could not push gamestate\t\t\t\t=====" << std::endl;
    313     else
    314       if(clients->findClient(clientID))
    315         clients->findClient(clientID)->resetFailures();*/
    316283  }
    317284 
     
    359326    temp->setSynched(true);
    360327    COUT(3) << "sending welcome" << std::endl;
    361     connection->sendWelcome(temp->getID(), temp->getShipID(), true);
     328    packet::Packet packet(new packet::Welcome(temp->getID(), temp->getShipID()));
     329    assert(packet.send());
    362330    return true;
    363331  }
     
    421389  void Server::disconnectClient( ClientInformation *client){
    422390    connection->disconnectClient(client);
    423     gamestates->removeClient(client);
     391    gamestates_->removeClient(client);
    424392  }
    425393 
Note: See TracChangeset for help on using the changeset viewer.