Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 28, 2010, 8:29:32 PM (14 years ago)
Author:
scheusso
Message:

some new features:
-Orxonox servers announce themselves now inside a LAN (and can provide some information (e.g. server name, etc.) to the client )
-Orxonox clients discover the servers inside the LAN and list them in the menu

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation3/src/libraries/network/Client.cc

    r6417 r7161  
    5050#include "FunctionCallManager.h"
    5151#include "core/CoreIncludes.h"
     52#include "core/CommandLineParser.h"
    5253#include "core/Game.h"
     54#include "core/ScopedSingletonManager.h"
    5355
    5456namespace orxonox
    5557{
    5658
     59  ManageScopedSingleton( Client, ScopeID::Root, true );
    5760
    5861  /**
     
    6164  */
    6265  Client::Client():
     66      gamestate(0),
    6367      isSynched_(false),
    6468      gameStateFailure_(false),
    6569      timeSinceLastUpdate_(0)
    6670  {
    67   }
    68 
    69   /**
    70   * Constructor for the Client class
    71   * @param address the server address
    72   * @param port port of the application on the server
    73   */
    74   Client::Client(const std::string& address, int port):
    75       isSynched_(false),
    76       gameStateFailure_(false),
    77       timeSinceLastUpdate_(0)
    78   {
    79       setPort( port );
    80       setServerAddress( address );
    81   }
    82 
    83   Client::~Client(){
     71    this->setDestination( CommandLineParser::getValue("dest").getString(), CommandLineParser::getValue("port") );
     72  }
     73
     74  Client::~Client()
     75  {
    8476    if ( ClientConnection::isConnected() )
    8577      closeConnection();
     
    9082  * @return true/false
    9183  */
    92   bool Client::establishConnection(){
     84  bool Client::establishConnection()
     85  {
    9386    Synchronisable::setClient(true);
    94     return ClientConnection::establishConnection();
     87    this->gamestate = new GamestateClient();
     88    if( ClientConnection::establishConnection() )
     89    {
     90      Host::setActive(true);
     91      return true;
     92    }
     93    else
     94      return false;
    9595  }
    9696
     
    9999  * @return true/false
    100100  */
    101   bool Client::closeConnection(){
     101  bool Client::closeConnection()
     102  {
     103    assert(this->gamestate);
     104    delete this->gamestate;
     105    this->gamestate = 0;
     106    Host::setActive(false);
    102107    return ClientConnection::closeConnection();
    103108  }
    104 
    105   bool Client::queuePacket(ENetPacket *packet, int clientID){
     109 
     110  void Client::setDestination(const std::string& serverAddress, unsigned int port)
     111  {
     112    ClientConnection::setServerAddress(serverAddress);
     113    ClientConnection::setPort(port);
     114  }
     115
     116  bool Client::queuePacket(ENetPacket *packet, int clientID)
     117  {
    106118    bool b = ClientConnection::addPacket(packet);
    107119    assert(b);
     
    109121  }
    110122
    111   bool Client::processChat(const std::string& message, unsigned int playerID){
     123  bool Client::processChat(const std::string& message, unsigned int playerID)
     124  {
    112125//    COUT(1) << "Player " << playerID << ": " << message << std::endl;
    113126    return true;
    114127  }
    115128
    116   void Client::printRTT(){
     129  void Client::printRTT()
     130  {
    117131    COUT(0) << "Round trip time to server is " << ClientConnection::getRTT() << " ms" << endl;
    118132  }
     
    123137   * @return result(true/false)
    124138   */
    125   bool Client::chat(const std::string& message){
     139  bool Client::chat(const std::string& message)
     140  {
    126141    packet::Chat *m = new packet::Chat(message, Host::getPlayerID());
    127142    return m->send();
     
    133148   * @param time
    134149   */
    135   void Client::update(const Clock& time){
     150  void Client::update(const Clock& time)
     151  {
    136152    //this steers our network frequency
    137153    timeSinceLastUpdate_+=time.getDeltaTime();
     
    143159      {
    144160        COUT(4) << "popping partial gamestate: " << std::endl;
    145         packet::Gamestate *gs = gamestate.getGamestate();
     161        packet::Gamestate *gs = gamestate->getGamestate();
    146162        //assert(gs); <--- there might be the case that no data has to be sent, so its commented out now
    147163        if(gs){
     
    157173
    158174    Connection::processQueue();
    159     if(gamestate.processGamestates())
     175    if(gamestate->processGamestates())
    160176    {
    161177      if(!isSynched_)
    162178        isSynched_=true;
    163179    }
    164     gamestate.cleanup();
     180    gamestate->cleanup();
    165181    Connection::sendPackets();
    166182
     
    184200  }
    185201
     202
     203
    186204}
Note: See TracChangeset for help on using the changeset viewer.