Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 4, 2015, 12:13:42 PM (9 years ago)
Author:
landauf
Message:

merged branch multiplayerFS15

Location:
code/branches/presentationFS15merge
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentationFS15merge

  • code/branches/presentationFS15merge/src/libraries/network/WANDiscovery.cc

    r8858 r10612  
    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      int secondsep = datastr.find(" ", separator + 1);
     99      toadd.setServerName(datastr.substr(separator + 1, secondsep - separator - 1));
     100      toadd.setClientNumber(Ogre::StringConverter::parseInt(datastr.substr(secondsep+1)));
     101
     102      orxout(internal_info, context::network) << "Received WAN discovery server information; Name: " << toadd.getServerName() << ", Address: " << toadd.getServerIP() << ", Players: " << toadd.getClientNumber() << ", RTT: " << toadd.getServerRTT() << endl;
    99103
    100104      /* add to list */
     
    103107    else if( !strncmp( (char*)ev->packet->data, MSPROTO_SERVERLIST_END,
    104108      MSPROTO_SERVERLIST_END_LEN ) )
    105     { 
     109    {
    106110      /* this is the only case where 2 should be returned,
    107111       * as 1 is used to signal that we're done receiving
    108112       * the list
    109113       */
    110       return 2; 
     114      return 2;
    111115    }
    112116
     
    114118    return 1;
    115119  }
    116  
     120
    117121  void WANDiscovery::discover()
    118122  {
     
    131135      { case 0: /* no event occured, decrease timeout */
    132136          --i; break;
    133         case 1: /* got a list element, continue */ 
     137        case 1: /* got a list element, continue */
    134138          break;
    135139        case 2: /* done. */
     
    159163  }
    160164
     165  std::string WANDiscovery::getServerListItemRTT(unsigned int index)
     166        {
     167    if( index >= this->servers_.size() )
     168      return BLANKSTRING;
     169    else{
     170      uint32_t serverrtt = this->servers_[index].getServerRTT();
     171      return Ogre::StringConverter::toString(serverrtt);
     172    }
     173
     174  }
     175  std::string WANDiscovery::getServerListItemPlayerNumber(unsigned int index)
     176  {
     177    if( index >= this->servers_.size() )
     178      return BLANKSTRING;
     179    else{
     180      int playerNumber = this->servers_[index].getClientNumber();
     181      return Ogre::StringConverter::toString(playerNumber);
     182    }
     183  }
    161184
    162185} // namespace orxonox
Note: See TracChangeset for help on using the changeset viewer.