Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7763


Ignore:
Timestamp:
Dec 15, 2010, 2:51:39 PM (13 years ago)
Author:
smerkli
Message:

disconnect implemented, switching to only use the MSC object of wandiscovery.

Location:
code/branches/presentation/src/libraries/network
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation/src/libraries/network/MasterServer.cc

    r7756 r7763  
    186186      }
    187187
     188      else if( !strncmp( (char *)event->packet->data
     189        + MSPROTO_GAME_SERVER_LEN+1,
     190        MSPROTO_SERVERDC, MSPROTO_SERVERDC_LEN ) )
     191      {
     192        /* create string from peer data */
     193        std::string name = std::string( addrconv );
     194
     195        /* remove the server from the list it belongs to */
     196        this->mainlist.delServerByName( name );
     197
     198        /* tell the user */
     199        COUT(2) << "Removed server " << name << " from list.\n";
     200      }
     201
    188202      /* TODO add hook for disconnect here */
    189203    }
  • code/branches/presentation/src/libraries/network/MasterServerComm.cc

    r7761 r7763  
    4141  {
    4242    /* initialize Enet */
    43     if (enet_initialize () != 0)
     43    if( enet_initialize () != 0 )
    4444    { COUT(1) << "An error occurred while initializing ENet.\n";
    4545      return 1;
     
    5959    /* see if it worked */
    6060    if (this->client == NULL)
    61     { COUT(1) << "An error occurred while trying to create an ENet client host.\n";
     61    { COUT(1) << "An error occurred while trying to create an "
     62        << "ENet client host.\n";
    6263      return 1;
    6364    }
     
    7071    /* destroy the enet facilities */
    7172    enet_host_destroy(this->client);
    72 
    73     /* install atexit handler for enet */
    74     enet_deinitialize();
    7573  }
    7674
     
    8482    this->peer = enet_host_connect(this->client, &this->address, 2, 0);   
    8583
    86     if (this->peer == NULL )
    87     { COUT(2) << "ERROR: No available peers for initiating an ENet connection.\n";
     84    if( this->peer == NULL )
     85    { COUT(2) << "ERROR: No available peers for initiating an ENet"
     86        << " connection.\n";
    8887      return -1;
    8988    }
     
    9695    {
    9796      enet_peer_reset (this->peer);
    98       fprintf( stdout, "Connection to %s failed.", address );
    9997      COUT(2) << "ERROR: connection to " << address << " failed.\n";
    10098      return -1;
     
    240238    /* One could just use enet_host_service() instead. */
    241239    enet_host_flush( this->client );
    242     if( packet ) free( packet );
     240    enet_packet_destroy( packet );
    243241
    244242    /* all done. */
  • code/branches/presentation/src/libraries/network/MasterServerComm.h

    r7761 r7763  
    6666       * Disconnect from master server.
    6767       */
    68       int disconnect();
     68      int disconnect( void );
    6969
    7070      /** \param data The data to be sent.
  • code/branches/presentation/src/libraries/network/MasterServerProtocol.h

    r7756 r7763  
    6969#define MSPROTO_PING_GAMESERVER_LEN 4
    7070
     71/* server disconnect */
     72#define MSPROTO_SERVERDC "DC"
     73#define MSPROTO_SERVERDC_LEN 2
     74
    7175/* ping reply */
    7276#define MSPROTO_ACK "ACK"
  • code/branches/presentation/src/libraries/network/Server.cc

    r7762 r7763  
    104104  void Server::helper_ConnectToMasterserver()
    105105  {
    106     /* initialize it and see if it worked */
    107     if( msc.initialize() )
    108     { COUT(1) << "Error: could not initialize master server communications!\n";
    109       return;
    110     }
    111 
    112     /* connect and see if it worked */
    113     if( msc.connect( WANDiscovery::getInstance().getMSAddress().c_str(),
    114       ORX_MSERVER_PORT ) )
    115     { COUT(1) << "Error: could not connect to master server!\n";
    116       return;
    117     }
     106    //[> initialize it and see if it worked <]
     107    //if( msc.initialize() )
     108    //{ COUT(1) << "Error: could not initialize master server communications!\n";
     109      //return;
     110    //}
     111
     112    //[> connect and see if it worked <]
     113    //if( msc.connect( WANDiscovery::getInstance().getMSAddress().c_str(),
     114      //ORX_MSERVER_PORT ) )
     115    //{ COUT(1) << "Error: could not connect to master server!\n";
     116      //return;
     117    //}
    118118
    119119    /* now send the master server some note we're here */
    120     msc.sendRequest( MSPROTO_GAME_SERVER " " MSPROTO_REGISTER_SERVER );
     120    //msc.sendRequest( MSPROTO_GAME_SERVER " " MSPROTO_REGISTER_SERVER );
     121    WANDiscovery::getInstance().msc.sendRequest( MSPROTO_GAME_SERVER " "
     122      MSPROTO_REGISTER_SERVER );
    121123  }
    122124
     
    152154    this->disconnectClients();
    153155    this->closeListener();
     156
     157    /* tell master server we're closing */
    154158    COUT(2) << "disconnecting." << endl;
    155     this->msc.disconnect();
     159    WANDiscovery::getInstance().msc.sendRequest( MSPROTO_GAME_SERVER " "
     160      MSPROTO_SERVERDC );
    156161    COUT(2) << "disconnecting done" << endl;
     162
    157163    LANDiscoverable::setActivity(false);
    158164    return;
     
    196202     * has to be done or changed.
    197203     */
    198     this->msc.pollForReply( rephandler, 10 );
     204    //WANDiscovery::getInstance().msc.pollForReply( rhandler, 10 );
    199205  }
    200206
  • code/branches/presentation/src/libraries/network/Server.h

    r7739 r7763  
    9090
    9191    float timeSinceLastUpdate_;
    92     MasterServerComm msc;
     92    //MasterServerComm msc;
    9393  };
    9494
  • code/branches/presentation/src/libraries/network/WANDiscovery.cc

    r7756 r7763  
    133133    {
    134134      /* poll for reply and act according to what was received */
    135       switch( this->msc.pollForReply( rhandler, 1000 ) )
     135      switch( this->msc.pollForReply( rhandler, 500 ) )
    136136      { case 0: /* no event occured, decrease timeout */
    137137          --i; break;
  • code/branches/presentation/src/libraries/network/WANDiscovery.h

    r7750 r7763  
    9595      /** Function used for the configuration file parameter update */
    9696      void setConfigValues();
     97
     98      /** Master server communications object */
     99      MasterServerComm msc;
    97100     
    98101    private:
    99102      /** Singleton pointer */
    100103      static WANDiscovery* singletonPtr_s;
    101 
    102       /** Master server communications object */
    103       MasterServerComm msc;
    104104
    105105      /** master server address */
Note: See TracChangeset for help on using the changeset viewer.