Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 7, 2015, 2:22:43 PM (10 years ago)
Author:
frovelli
Message:

Implemented custom servernames

Location:
code/branches/multiplayerFS15/src/libraries/network
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • code/branches/multiplayerFS15/src/libraries/network/GamestateManager.h

    r8402 r10427  
    1 /*
     1  /*
    22 *   ORXONOX - the hottest 3D action shooter ever to exist
    33 *                    > www.orxonox.net <
     
    7878      std::map< uint32_t, packet::Gamestate* > gamestates;
    7979    };
    80    
     80
    8181  public:
    82    
     82
    8383    GamestateManager();
    8484    ~GamestateManager();
     
    8888    virtual uint32_t  getLastReceivedGamestateID( unsigned int peerID );
    8989    virtual uint32_t  getCurrentGamestateID(){ if( currentGamestate_) return currentGamestate_->getID(); else return GAMESTATEID_INITIAL; }
    90    
     90
    9191    bool processGamestates();
    9292    bool sendAck(unsigned int gamestateID, uint32_t peerID);
  • code/branches/multiplayerFS15/src/libraries/network/LANDiscoverable.cc

    r8858 r10427  
    3535#include "util/Output.h"
    3636#include "packet/ServerInformation.h"
     37#include "core/config/ConfigValueIncludes.h"
     38#include "core/CoreIncludes.h"
     39
    3740
    3841namespace orxonox
     
    4346  LANDiscoverable::LANDiscoverable()
    4447  {
     48    /* register object in orxonox */
     49    RegisterObject(LANDiscoverable);
     50
     51    this->setConfigValues();
     52    //     this->setActivity(true);
    4553    this->host_ = 0;
    4654    this->bActive_ = false;
    47 //     this->setActivity(true);
     55  }
     56
     57  void LANDiscoverable::setConfigValues()
     58  {
     59    /* update msaddress string from orxonox.ini config file, if it
     60     * has changed.
     61     */
     62    SetConfigValueExternal(ownName, "WANDiscovery", "ownName", "tme213");
    4863  }
    4964
     
    6176    if( bActive == this->bActive_ )        // no change
    6277      return;
    63    
     78
    6479    if( bActive )
    6580    {
     
    8499  {
    85100    ENetEvent event;
    86    
     101
    87102    if( this->bActive_==false )
    88103      return;
    89104    assert(this->host_);
    90    
     105
    91106    while( enet_host_service( this->host_, &event, 0 ) > 0 )
    92107    {
     
    104119            orxout(internal_info, context::network) << "Received LAN discovery message from client " << event.peer->host->receivedAddress << endl;
    105120            packet::ServerInformation info;
    106             info.setServerName("Orxonox Server");
     121            info.setServerName(this->ownName);
    107122            info.send(event.peer);
    108123//             ENetPacket* packet = enet_packet_create( LAN_DISCOVERY_ACK, strlen(LAN_DISCOVERY_ACK)+1, ENET_PACKET_FLAG_RELIABLE );
  • code/branches/multiplayerFS15/src/libraries/network/LANDiscoverable.h

    r8351 r10427  
    3131
    3232#include "NetworkPrereqs.h"
     33#include "core/config/Configurable.h"
    3334
    3435namespace orxonox
    3536{
    3637
    37   class LANDiscoverable
     38  class LANDiscoverable: public Configurable
    3839  {
    3940    public:
     
    4243      void setActivity( bool bActive );
    4344      void update();
     45      /** Function used for the configuration file parameter update */
     46      void setConfigValues();
    4447
    4548    private:
    4649      bool            bActive_;
    4750      ENetHost*       host_;
     51      std::string     ownName;
    4852  };
    4953
  • code/branches/multiplayerFS15/src/libraries/network/MasterServer.cc

    r8952 r10427  
    3434#include "util/Output.h"
    3535
    36 namespace orxonox 
     36namespace orxonox
    3737{
    3838  /*** MACROS ***/
     
    4949
    5050  /* command: list servers */
    51   void 
     51  void
    5252  MasterServer::listServers( void )
    5353  {
     
    5959
    6060    /* loop through list elements */
    61     for( i = MasterServer::getInstance()->mainlist.serverlist.begin(); 
    62       i != MasterServer::getInstance()->mainlist.serverlist.end(); ++i ) 
     61    for( i = MasterServer::getInstance()->mainlist.serverlist.begin();
     62      i != MasterServer::getInstance()->mainlist.serverlist.end(); ++i )
    6363    {
    6464      orxout(user_info) << "  " << (*i).ServerInfo.getServerIP() << std::endl;
     
    7070  }
    7171
    72   void 
     72  void
    7373  MasterServer::delServer( std::string todeladdr )
    7474  {
    7575    /* tell the user we're now removing the entry from the server list */
    76     orxout(user_info) << "MS: Deleting server \"" << todeladdr << "\"..." 
     76    orxout(user_info) << "MS: Deleting server \"" << todeladdr << "\"..."
    7777      << std::endl;
    7878
    7979    /* see if we actually have that server on our list */
    80     ServerListSearchResult shandle = 
     80    ServerListSearchResult shandle =
    8181      MasterServer::getInstance()->mainlist.findServerByAddress(todeladdr);
    8282
     
    8686    }
    8787
    88     /* force-disconnect the server */ 
     88    /* force-disconnect the server */
    8989    enet_peer_disconnect( shandle.result.peer, 0 );
    9090
     
    9898
    9999  /* helpers */
    100   static void 
     100  static void
    101101  helper_output_debug( ENetEvent *event, char *addrconv )
    102102  {
    103103    orxout(verbose, context::master_server)
    104       << "A packet of length" 
     104      << "A packet of length"
    105105      << event->packet->dataLength
    106106      << " containing "
    107107      << (const char*)event->packet->data
    108108      << " was received from "
    109       << addrconv 
     109      << addrconv
    110110      << " on channel "
    111111      << event->channelID << endl;
     
    122122
    123123    /* loop through list elements */
    124     for( i = mainlist.serverlist.begin(); i 
    125         != mainlist.serverlist.end(); ++i ) 
     124    for( i = mainlist.serverlist.begin(); i
     125        != mainlist.serverlist.end(); ++i )
    126126    {
    127127      /* send this particular server */
    128128      /* build reply string */
    129       char *tosend = (char *)calloc( (*i).ServerInfo.getServerIP().length()
    130           + MSPROTO_SERVERLIST_ITEM_LEN + 2,1 );
    131       if( !tosend ) 
     129      int packetlen = MSPROTO_SERVERLIST_ITEM_LEN + 1 + (*i).ServerInfo.getServerIP().length() + 1 + (*i).ServerInfo.getServerName().length() + 1;
     130      char *tosend = (char *)calloc(packetlen ,1 );
     131      if( !tosend )
    132132      { orxout(internal_warning, context::master_server) << "Masterserver.cc: Memory allocation failed." << endl;
    133133        continue;
    134       } 
    135       sprintf( tosend, "%s %s", MSPROTO_SERVERLIST_ITEM,
    136           (*i).ServerInfo.getServerIP().c_str() );
     134      }
     135      sprintf( tosend, "%s %s %s", MSPROTO_SERVERLIST_ITEM,
     136          (*i).ServerInfo.getServerIP().c_str(), (*i).ServerInfo.getServerName().c_str());
    137137
    138138      /* create packet from it */
    139139      reply = enet_packet_create( tosend,
    140           strlen( tosend ) + 1, 
     140          strlen( tosend ) + 1,
    141141          ENET_PACKET_FLAG_RELIABLE);
    142142
     
    149149      /* free the tosend buffer */
    150150      free( tosend );
    151     } 
     151    }
    152152
    153153    /* create end-of-list packet */
     
    163163  }
    164164
    165   /* maybe the two methods below can be merged into one and 
    166    * made to use ENet's RTT functionality to check for disconnected 
     165  /* maybe the two methods below can be merged into one and
     166   * made to use ENet's RTT functionality to check for disconnected
    167167   * servers.
    168168   */
    169   void 
     169  void
    170170  MasterServer::helper_cleanupServers( void )
    171171  {
    172172    /* get an iterator */
    173173    std::list<ServerListElem>::iterator i;
    174      
     174
    175175    if( mainlist.serverlist.size() == 0 )
    176176      return;
    177177
    178178    /* loop through list elements */
    179     for( i = mainlist.serverlist.begin(); i 
    180         != mainlist.serverlist.end(); ++i ) 
     179    for( i = mainlist.serverlist.begin(); i
     180        != mainlist.serverlist.end(); ++i )
    181181    { /* see if we have a disconnected peer */
    182       if( (*i).peer && 
     182      if( (*i).peer &&
    183183         ((*i).peer->state == ENET_PEER_STATE_DISCONNECTED ||
    184184          (*i).peer->state == ENET_PEER_STATE_ZOMBIE ))
    185       { 
     185      {
    186186        /* Remove it from the list */
    187187        orxout(internal_warning) << (char*)(*i).peer->data << " timed out.\n";
     
    190190        /* stop iterating, we manipulated the list */
    191191        /* TODO note: this only removes one dead server per loop
    192          * iteration. not beautiful, but one iteration is ~100ms, 
     192         * iteration. not beautiful, but one iteration is ~100ms,
    193193         * so not really relevant for the moment.
    194194         */
     
    196196      }
    197197    }
    198  
     198
    199199  }
    200200
     
    204204  /***** EVENTS *****/
    205205  /* connect event */
    206   int 
     206  int
    207207  MasterServer::eventConnect( ENetEvent *event )
    208208  { /* check for bad parameters */
     
    217217
    218218    /* output debug info */
    219     orxout(verbose, context::master_server) << "A new client connected from " 
    220       << addrconv 
    221       << " on port " 
     219    orxout(verbose, context::master_server) << "A new client connected from "
     220      << addrconv
     221      << " on port "
    222222      << event->peer->address.port << endl;
    223223
    224224    /* store string form of address here */
    225     event->peer->data = addrconv; 
     225    event->peer->data = addrconv;
    226226
    227227    /* all fine. */
     
    230230
    231231  /* disconnect event */
    232   int 
     232  int
    233233  MasterServer::eventDisconnect( ENetEvent *event )
    234234  { /* check for bad parameters */
     
    255255
    256256  /* data event */
    257   int 
     257  int
    258258  MasterServer::eventData( ENetEvent *event )
    259259  { /* validate packet */
     
    262262      return -1;
    263263    }
    264      
     264
    265265    /* generate address in readable form */
    266266    char *addrconv = (char *) calloc( 50, 1 );
     
    271271
    272272    /* GAME SERVER OR CLIENT CONNECTION? */
    273     if( !strncmp( (char *)event->packet->data, MSPROTO_GAME_SERVER, 
     273    if( !strncmp( (char *)event->packet->data, MSPROTO_GAME_SERVER,
    274274      MSPROTO_GAME_SERVER_LEN ) )
    275275    { /* Game server */
    276276
    277       if( !strncmp( (char *)event->packet->data 
    278         + MSPROTO_GAME_SERVER_LEN+1, 
     277      if( !strncmp( (char *)event->packet->data
     278        + MSPROTO_GAME_SERVER_LEN+1,
    279279        MSPROTO_REGISTER_SERVER, MSPROTO_REGISTER_SERVER_LEN ) )
    280280      { /* register new server */
    281281        mainlist.addServer( packet::ServerInformation( event ),
    282282          event->peer );
    283        
     283
    284284        /* tell people we did so */
    285         orxout(internal_info, context::master_server) << "Added new server to list: " << 
     285        orxout(internal_info, context::master_server) << "Added new server to list: " <<
    286286          packet::ServerInformation( event ).getServerIP() << endl;
    287287      }
     
    292292      {
    293293        /* create string from peer data */
    294         std::string name = std::string( addrconv );
     294        std::string ip = std::string( addrconv );
    295295
    296296        /* remove the server from the list it belongs to */
    297         this->mainlist.delServerByAddress( name );
     297        this->mainlist.delServerByAddress( ip );
    298298
    299299        /* tell the user */
    300         orxout(internal_info, context::master_server) << "Removed server " << name << " from list." << endl;
     300        orxout(internal_info, context::master_server) << "Removed server " << ip << " from list." << endl;
    301301      }
    302302
     303      else if( !strncmp( (char *)event->packet->data
     304        + MSPROTO_GAME_SERVER_LEN+1,
     305        MSPROTO_SET_NAME, MSPROTO_SET_NAME_LEN ) )
     306      {
     307        /* create string from peer data */
     308        std::string ip = std::string( addrconv );
     309        std::string data (event->packet->data,event->packet->data + event->packet->dataLength );
     310        std::string name = data.substr(MSPROTO_GAME_SERVER_LEN+1 + MSPROTO_SET_NAME_LEN + 1);
     311
     312        /* remove the server from the list it belongs to */
     313        this->mainlist.setNameByAddress( ip, name );
     314
     315        /* tell the user */
     316        orxout(internal_info, context::master_server) << "Updated server " << ip << " with new name " << name << endl;
     317      }
     318
    303319      /* TODO add hook for disconnect here */
    304320    }
    305     else if( !strncmp( (char *)event->packet->data, MSPROTO_CLIENT, 
     321    else if( !strncmp( (char *)event->packet->data, MSPROTO_CLIENT,
    306322      MSPROTO_CLIENT_LEN) )
    307323    { /* client */
     
    312328    }
    313329    else
    314     { /* bad message, don't do anything. */ } 
     330    { /* bad message, don't do anything. */ }
    315331
    316332    /* delete addrconv */
     
    324340
    325341  /**** MAIN ROUTINE *****/
    326   int 
     342  int
    327343  MasterServer::run()
    328344  {
     
    330346    ENetEvent *event = (ENetEvent *)calloc(sizeof(ENetEvent), sizeof(char));
    331347    if( event == NULL )
    332     { 
     348    {
    333349      orxout(user_error, context::master_server) << "Could not create ENetEvent structure, exiting." << endl;
    334350      exit( EXIT_FAILURE );
     
    345361    switch (event->type)
    346362    { /* new connection */
    347       case ENET_EVENT_TYPE_CONNECT: 
     363      case ENET_EVENT_TYPE_CONNECT:
    348364        eventConnect( event ); break;
    349365
    350366        /* disconnect */
    351       case ENET_EVENT_TYPE_DISCONNECT: 
     367      case ENET_EVENT_TYPE_DISCONNECT:
    352368        eventDisconnect( event ); break;
    353369
     
    358374
    359375    /* done */
     376    free(event);
    360377    return 0;
    361   } 
     378  }
    362379
    363380  /* constructor */
     
    380397    this->address.port = ORX_MSERVER_PORT;
    381398
    382     /* create a host with the above settings (the last two 0 mean: accept 
     399    /* create a host with the above settings (the last two 0 mean: accept
    383400     * any input/output bandwidth */
    384     this->server = enet_host_create( &this->address, ORX_MSERVER_MAXCONNS, 
     401    this->server = enet_host_create( &this->address, ORX_MSERVER_MAXCONNS,
    385402        ORX_MSERVER_MAXCHANS, 0, 0 );
    386403    assert(this->server);
     
    388405    /* see if creation worked */
    389406    if( !this->server )
    390     { orxout(user_error, context::master_server) << 
     407    { orxout(user_error, context::master_server) <<
    391408        "An error occurred while trying to create an ENet server host." << endl;
    392409      exit( EXIT_FAILURE );
  • code/branches/multiplayerFS15/src/libraries/network/MasterServerProtocol.h

    r8351 r10427  
    3737/* Client token (shows that the party sending data is a client */
    3838#define MSPROTO_CLIENT "CL"
    39 #define MSPROTO_CLIENT_LEN 2 
     39#define MSPROTO_CLIENT_LEN 2
    4040
    4141/* Request: Serverlist (requiest made from client to master server */
     
    6767/* ping request from server */
    6868#define MSPROTO_PING_GAMESERVER "PING"
    69 #define MSPROTO_PING_GAMESERVER_LEN 4 
     69#define MSPROTO_PING_GAMESERVER_LEN 4
    7070
    7171/* server disconnect */
     
    7575/* ping reply */
    7676#define MSPROTO_ACK "ACK"
    77 #define MSPROTO_ACK_LEN 3 
     77#define MSPROTO_ACK_LEN 3
    7878
     79#define MSPROTO_SET_NAME "NAM"
     80#define MSPROTO_SET_NAME_LEN 3
    7981
     82#define MSPROTO_SET_CLIENTS "CLI"
     83#define MSPROTO_SET_CLIENTS_LEN 3
     84
     85#define SERVER_NAME_MAXLEN 7
    8086
    8187/* default master server port */
  • code/branches/multiplayerFS15/src/libraries/network/PeerList.cc

    r8858 r10427  
    3838  PeerList::~PeerList() { }
    3939
    40   int 
     40  int
    4141  PeerList::addPeer( ENetPeer *toadd )
    4242  { /* error correction */
    43     if( toadd == NULL ) 
     43    if( toadd == NULL )
    4444    { orxout(internal_error, context::master_server) << "PeerList::addPeer: empty peer given." << endl;
    4545      return -1;
     
    5252
    5353  bool sub_compAddr( ENetAddress addr1, ENetAddress addr2 )
    54   { 
     54  {
    5555    for( int i = 0; i < 16; ++i )
    5656      if( addr1.host.addr[i] < addr2.host.addr[i] )
     
    6161    return 0;
    6262  }
    63    
     63
    6464
    6565  bool
     
    6969
    7070    /* loop through list elements */
    71     for( i = peerlist.begin(); i != peerlist.end(); ++i ) 
     71    for( i = peerlist.begin(); i != peerlist.end(); ++i )
    7272      if( !sub_compAddr((*i)->address, addr ) )
    7373      { /* found this name, remove and quit */
     
    8686
    8787    /* loop through list elements */
    88     for( i = peerlist.begin(); i != peerlist.end(); ++i ) 
     88    for( i = peerlist.begin(); i != peerlist.end(); ++i )
    8989      if( !sub_compAddr((*i)->address, addr ) )
    9090        /* found this name, remove and quit */
     
    9595  }
    9696
     97  int
     98  PeerList::count(){
     99    return this->peerlist.size();
     100  }
     101
    97102}
    98 
  • code/branches/multiplayerFS15/src/libraries/network/PeerList.h

    r8351 r10427  
    3535
    3636/* peer list */
    37 namespace orxonox 
     37namespace orxonox
    3838{
    39   /** This class keeps a list of open connections 
     39  /** This class keeps a list of open connections
    4040   * and some info about them.
    4141   */
    42   class PeerList 
     42  class PeerList
    4343  { public:
    4444      /** constructor */
     
    5050      /** \param toadd The peer to add
    5151       * \return 0 for success, -1 for error.
    52        * 
    53        * Add new peer to list 
     52       *
     53       * Add new peer to list
    5454       */
    5555      int addPeer( ENetPeer *toadd );
     
    5757      /** \param addr Address to look for
    5858       * \return if the peer was found or not
    59        * 
    60        * Remove peer from list by address 
     59       *
     60       * Remove peer from list by address
    6161       */
    6262      bool remPeerByAddr( ENetAddress addr );
    6363
    6464      /** \param addr The address to find by
    65        *
    66        * Find a connection by address */
     65       *
     66       * Find a connection by address
     67       */
    6768      ENetPeer *findPeerByAddr( ENetAddress addr );
    6869
    69       /* NOTE: making this list public so it can easily
     70      /**
     71       * Count current peers
     72       */
     73       int count();
     74
     75      /* NOTE: making this list public so it can easily
    7076       * be iterated. This makes sense since iterating it
    7177       * will happen all the time, and using getter methods
  • code/branches/multiplayerFS15/src/libraries/network/Server.cc

    r9667 r10427  
    7777    this->timeSinceLastUpdate_=0;
    7878  }
    79 
     79/*
     80  Server::Server(int port, const std::string name)
     81  {
     82    this->setPort( port );
     83    this->timeSinceLastUpdate_=0;
     84    this->serverName_=name;
     85  }*/
    8086  /**
    8187  * Constructor
  • code/branches/multiplayerFS15/src/libraries/network/Server.h

    r8858 r10427  
    6767    virtual void printRTT();
    6868    float getPacketLoss(unsigned int clientID);
     69    int getClientCount() { return this->clientIDs_.size();}
     70    std::string getServerName() { return this->serverName_;}
     71
    6972  protected:
    7073    void updateGamestate();
     
    8992    std::deque<packet::Packet*> packetQueue_;
    9093    std::vector<uint32_t>       clientIDs_;
     94    std::string                 serverName_;
    9195  };
    9296
  • code/branches/multiplayerFS15/src/libraries/network/ServerList.cc

    r10334 r10427  
    145145  }
    146146
     147  bool ServerList::setNameByAddress( std::string address, std::string name  ){
     148    /* get an iterator */
     149    std::list<ServerListElem>::iterator i;
     150
     151    /* loop through list elements */
     152    for( i = serverlist.begin(); i != serverlist.end(); ++i )
     153      if( (*i).ServerInfo.getServerIP() == address )
     154      { /* found this adress, rename and quit */
     155        (*i).ServerInfo.setServerName( name );
     156        return true;
     157      }
     158    return false;
     159  };
     160
    147161}
  • code/branches/multiplayerFS15/src/libraries/network/ServerList.h

    r8937 r10427  
    3535
    3636/* methods necessary */
    37 namespace orxonox 
    38 { 
     37namespace orxonox
     38{
    3939  /* HELPER STRUCTURES */
    40   struct ServerListElem 
     40  struct ServerListElem
    4141  {
    4242    /* server information (name, IP, etc) */
     
    6363   * and some info about them.
    6464   */
    65   class ServerList 
     65  class ServerList
    6666  { public:
    6767      /** constructor */
     
    7474      /* BASIC MANIPULATION */
    7575      /** \param toadd the server to add.
    76        * 
     76       *
    7777       * Add server to the game server list
    7878       */
     
    8181
    8282      /** \param name Name of the server to remove
    83        * 
    84        * Remove server by name 
     83       *
     84       * Remove server by name
    8585       */
    8686      bool delServerByName( std::string name );
    8787
    8888      /** \param address IP address of the server to remove
    89        * 
     89       *
    9090       * Remove server by address
    9191       */
    9292      bool delServerByAddress( std::string address );
    9393
    94 
    95 
     94      bool setNameByAddress( std::string address, std::string name  );
    9695
    9796      /* SEARCHING */
    98       /* \param address The address of the server that is to be 
     97      /* \param address The address of the server that is to be
    9998       *  found
    10099       * \return A struct containing a result of the search and a boolean
    101100       *  that is only true if the search was successful
    102        * 
     101       *
    103102       * Find and return the list handle of a given address.
    104103       */
     
    107106
    108107
    109       /* \param name The name of the server that is to be 
     108      /* \param name The name of the server that is to be
    110109       *  found
    111110       * \return The struct containing the list entry of the server
    112        * 
     111       *
    113112       * Find and return the list handle of a given name.
    114113       */
     
    120119      /** sort by name  */
    121120      void sortByName();
    122      
     121
    123122      /** sort by ping */
    124123      void sortByPing();
  • code/branches/multiplayerFS15/src/libraries/network/WANDiscoverable.cc

    r9667 r10427  
    4444    /* debugging output */
    4545    orxout(verbose, context::master_server) << "Creating WANDiscoverable." << endl;
    46  
     46
    4747    /* register object in orxonox */
    4848    RegisterObject(WANDiscoverable);
     
    5050    /* check for the masterserver address option in orxonox.ini */
    5151    this->setConfigValues();
    52    
     52
    5353  }
    5454
    5555  void WANDiscoverable::setConfigValues()
    5656  {
    57     /* update msaddress string from orxonox.ini config file, if it 
    58      * has changed. 
     57    /* update msaddress string from orxonox.ini config file, if it
     58     * has changed.
    5959     */
    6060    SetConfigValueExternal(msaddress, "WANDiscovery", "msaddress", "orxonox.net");
     61    SetConfigValueExternal(ownName, "WANDiscovery", "ownName", "tme213");
    6162//     SetConfigValue( msaddress, "orxonox.net");
    62   } 
     63  }
    6364
    6465  WANDiscoverable::~WANDiscoverable()
     
    6768      this->disconnect();
    6869  }
    69  
     70
    7071  void WANDiscoverable::setActivity(bool bActive)
    7172  {
    7273    if( bActive==this->bActive_ )
    7374      return;
    74    
     75
    7576    if( bActive )
    7677    {
     
    8485    }
    8586  }
    86  
     87
    8788  bool WANDiscoverable::connect()
    8889  {
     
    9394      return false;
    9495    }
    95    
     96
    9697    /* connect and see if it worked */
    9798    if( msc.connect( this->msaddress.c_str(), ORX_MSERVER_PORT ) )
    9899    {
    99       orxout(internal_error, context::master_server) << "Could not connect to master server at " 
     100      orxout(internal_error, context::master_server) << "Could not connect to master server at "
    100101                 << this->msaddress << endl;
    101102      return false;
    102103    }
    103                  
     104
    104105    /* debugging output */
    105106    orxout(verbose, context::master_server) << "Initialization of WANDiscoverable complete." << endl;
    106    
    107    
     107
     108    std::string request = MSPROTO_GAME_SERVER " " MSPROTO_SET_NAME " ";
     109    request += this->ownName;
     110
    108111    // Now register the server at the master server
    109112    this->msc.sendRequest( MSPROTO_GAME_SERVER " " MSPROTO_REGISTER_SERVER );
    110    
     113    this->msc.sendRequest( request );
     114
     115
    111116    return true;
    112117  }
     
    120125
    121126
    122  
     127
    123128} // namespace orxonox
  • code/branches/multiplayerFS15/src/libraries/network/WANDiscoverable.h

    r9667 r10427  
    4646
    4747      /** \return Address of the master server
    48        * 
    49        * Get the master server address 
     48       *
     49       * Get the master server address
    5050       */
    5151      std::string getMSAddress()
     
    5454      /** Function used for the configuration file parameter update */
    5555      void setConfigValues();
    56      
     56
    5757      /** Function used to set the activity/discoverability */
    5858      void setActivity( bool bActive );
     
    6060      /** Master server communications object */
    6161      MasterServerComm msc;
    62      
     62
    6363    private:
    6464      /** Function used to connect to the master server */
    6565      bool connect();
    66      
     66
    6767      /** Function used to disconnect from the master server */
    6868      void disconnect();
    69      
     69
    7070      /** master server address */
    7171      std::string msaddress;
     72      std::string ownName;
    7273      bool        bActive_;
    7374
  • code/branches/multiplayerFS15/src/libraries/network/WANDiscovery.cc

    r8858 r10427  
    4141    /* debugging output */
    4242    orxout(verbose, context::master_server) << "Creating WANDiscovery." << endl;
    43  
     43
    4444    /* register object in orxonox */
    4545    RegisterObject(WANDiscovery);
     
    5454    /* connect and see if it worked */
    5555    if( msc.connect( this->msaddress.c_str(), ORX_MSERVER_PORT ) )
    56       orxout(internal_error, context::master_server) << "Could not connect to master server at " 
     56      orxout(internal_error, context::master_server) << "Could not connect to master server at "
    5757        << this->msaddress << endl;
    5858
     
    6363  void WANDiscovery::setConfigValues()
    6464  {
    65     /* update msaddress string from orxonox.ini config file, if it 
    66      * has changed. 
     65    /* update msaddress string from orxonox.ini config file, if it
     66     * has changed.
    6767     */
    6868    SetConfigValue( msaddress, "master.orxonox.net");
    69   } 
     69  }
    7070
    7171  WANDiscovery::~WANDiscovery()
    72   { 
     72  {
    7373    /* clear server list */
    74     this->servers_.clear(); 
     74    this->servers_.clear();
    7575  }
    7676
    7777  /* callback for the network reply poller */
    7878  int WANDiscovery::rhandler( char *addr, ENetEvent *ev )
    79   { 
     79  {
    8080    /* error recognition */
    8181    if( !ev || !ev->packet || !ev->packet->data )
     
    8888    if( !strncmp( (char*)ev->packet->data, MSPROTO_SERVERLIST_ITEM,
    8989      MSPROTO_SERVERLIST_ITEM_LEN ) )
    90     { 
     90    {
    9191      /* create server structure from that item */
    9292      packet::ServerInformation toadd;
    9393
    9494      /* fill in data, -1 for the index: index should be length -1 */
    95       toadd.setServerName( std::string((char*)ev->packet->data +
    96         MSPROTO_SERVERLIST_ITEM_LEN+1) );
    97       toadd.setServerIP( std::string((char*)ev->packet->data +
    98         MSPROTO_SERVERLIST_ITEM_LEN+1) );
     95      std::string datastr = std::string((char*)ev->packet->data + MSPROTO_SERVERLIST_ITEM_LEN+1);
     96      int separator = datastr.find(" ");
     97      toadd.setServerIP(datastr.substr(0,separator));
     98      toadd.setServerName(datastr.substr(separator+1));
    9999
    100100      /* add to list */
     
    103103    else if( !strncmp( (char*)ev->packet->data, MSPROTO_SERVERLIST_END,
    104104      MSPROTO_SERVERLIST_END_LEN ) )
    105     { 
     105    {
    106106      /* this is the only case where 2 should be returned,
    107107       * as 1 is used to signal that we're done receiving
    108108       * the list
    109109       */
    110       return 2; 
     110      return 2;
    111111    }
    112112
     
    114114    return 1;
    115115  }
    116  
     116
    117117  void WANDiscovery::discover()
    118118  {
     
    131131      { case 0: /* no event occured, decrease timeout */
    132132          --i; break;
    133         case 1: /* got a list element, continue */ 
     133        case 1: /* got a list element, continue */
    134134          break;
    135135        case 2: /* done. */
     
    159159  }
    160160
     161  std::string WANDiscovery::getServerListItemRTT(unsigned int index)
     162        {
     163    if( index >= this->servers_.size() )
     164      return BLANKSTRING;
     165    else{
     166      uint32_t serverrtt = this->servers_[index].getServerRTT();
     167      return Ogre::StringConverter::toString(serverrtt);
     168    }
     169
     170  }
    161171
    162172} // namespace orxonox
  • code/branches/multiplayerFS15/src/libraries/network/WANDiscovery.h

    r9667 r10427  
    3535#include "MasterServerComm.h"
    3636#include "MasterServerProtocol.h"
     37#include <OgreStringConverter.h>
    3738
    3839#include <vector>
     
    5657
    5758      /** \return Address of the master server
    58        * 
    59        * Get the master server address 
     59       *
     60       * Get the master server address
    6061       */
    6162      std::string getMSAddress()
     
    6566      void discover(); // tolua_export
    6667
    67       /** \param index Index to get the name of 
     68      /** \param index Index to get the name of
    6869       * \return The name of the server
    69        * 
    70        * Get the name of the server at index index. 
     70       *
     71       * Get the name of the server at index index.
    7172       */
    7273      std::string getServerListItemName( unsigned int index ); // tolua_export
    7374
    74       /** \param index Index to get the IP of 
     75      /** \param index Index to get the IP of
    7576       * \return The IP of the server
    76        * 
    77        * Get the IP of the server at index index. 
     77       *
     78       * Get the IP of the server at index index.
    7879       */
    7980      std::string getServerListItemIP( unsigned int index ); // tolua_export
    8081
     82      /** \param index Index to get the RTT of
     83       * \return The RTT of the server
     84       *
     85       * Get the RTT of the server at index index.
     86       */
     87      std::string getServerListItemRTT( unsigned int index ); // tolua_export
     88
    8189      /* todo: might make this private and use getter/setter methods
    82        * at some later time. 
     90       * at some later time.
    8391       */
    8492      /** game server list */
     
    92100
    93101      int rhandler( char *addr, ENetEvent *ev );
    94      
     102
    95103    private:
    96104      /** master server address */
  • code/branches/multiplayerFS15/src/libraries/network/packet/ServerInformation.h

    r10334 r10427  
    4747
    4848        void          send( ENetPeer* peer );
     49        void          setServerName(std::string name) { this->serverName_ = name; }
     50        std::string   getServerName() { return this->serverName_; }
     51        void          setServerIP( std::string IP ) { this->serverIP_ = IP; }
    4952        std::string   getServerIP() { return this->serverIP_; }
    50         std::string   getServerName() { return this->serverName_; }
    51         void          setServerName(std::string name) { this->serverName_ = name; }
    52         void          setServerIP( std::string IP ) { this->serverIP_ = IP; }
    5353        uint32_t      getServerRTT() { return this->serverRTT_; }
    5454
Note: See TracChangeset for help on using the changeset viewer.