Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Implemented custom servernames

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.