[Orxonox-commit 5837] r10497 - in code/branches/presentationFS15: data/gui/scripts data/levels/includes src/libraries/network src/libraries/network/packet

maxima at orxonox.net maxima at orxonox.net
Wed May 27 10:45:56 CEST 2015


Author: maxima
Date: 2015-05-27 10:45:56 +0200 (Wed, 27 May 2015)
New Revision: 10497

Modified:
   code/branches/presentationFS15/data/gui/scripts/MultiplayerMenu.lua
   code/branches/presentationFS15/data/levels/includes/weaponSettingsHeartAttack.oxi
   code/branches/presentationFS15/src/libraries/network/GamestateManager.h
   code/branches/presentationFS15/src/libraries/network/LANDiscoverable.cc
   code/branches/presentationFS15/src/libraries/network/LANDiscoverable.h
   code/branches/presentationFS15/src/libraries/network/LANDiscovery.cc
   code/branches/presentationFS15/src/libraries/network/LANDiscovery.h
   code/branches/presentationFS15/src/libraries/network/MasterServer.cc
   code/branches/presentationFS15/src/libraries/network/MasterServer.h
   code/branches/presentationFS15/src/libraries/network/MasterServerProtocol.h
   code/branches/presentationFS15/src/libraries/network/PeerList.cc
   code/branches/presentationFS15/src/libraries/network/PeerList.h
   code/branches/presentationFS15/src/libraries/network/Server.cc
   code/branches/presentationFS15/src/libraries/network/Server.h
   code/branches/presentationFS15/src/libraries/network/ServerList.cc
   code/branches/presentationFS15/src/libraries/network/ServerList.h
   code/branches/presentationFS15/src/libraries/network/WANDiscoverable.cc
   code/branches/presentationFS15/src/libraries/network/WANDiscoverable.h
   code/branches/presentationFS15/src/libraries/network/WANDiscovery.cc
   code/branches/presentationFS15/src/libraries/network/WANDiscovery.h
   code/branches/presentationFS15/src/libraries/network/packet/ServerInformation.cc
   code/branches/presentationFS15/src/libraries/network/packet/ServerInformation.h
Log:
multiplayer branch merged to presentation

Modified: code/branches/presentationFS15/data/gui/scripts/MultiplayerMenu.lua
===================================================================
--- code/branches/presentationFS15/data/gui/scripts/MultiplayerMenu.lua	2015-05-27 08:21:55 UTC (rev 10496)
+++ code/branches/presentationFS15/data/gui/scripts/MultiplayerMenu.lua	2015-05-27 08:45:56 UTC (rev 10497)
@@ -69,7 +69,7 @@
     local destination = nil
     if choice then
         local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID()
-        destination = P.serverList[index][2]
+        destination = P.serverList[index][1]
     else
         return
     end
@@ -92,6 +92,8 @@
         local index = 0
         local servername = ""
         local serverip = ""
+        local serverrtt = ""
+        local playernumber = ""
         while true do
             servername = discovery:getServerListItemName(index)
             if servername == "" then
@@ -101,12 +103,15 @@
             if serverip == "" then
                 break
             end
-            table.insert(P.serverList, {servername, serverip})
+            --serverrtt = discovery:getServerListItemRTT(index)
+            playernumber = discovery:getServerListItemPlayerNumber(index)
+
+            table.insert(P.serverList, {serverip, servername, playernumber})
             index = index + 1
         end
         index = 1
         for k,v in pairs(P.serverList) do
-            local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] )
+            local item = CEGUI.createListboxTextItem("IP: " .. v[1] .. " Name: " .. v[2] .. " Players: " .. v[3])
             item:setID(index)
             index = index + 1
             item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
@@ -124,6 +129,8 @@
         local index = 0
         local servername = ""
         local serverip = ""
+        local serverrtt = ""
+        local playernumber = ""
         while true do
             servername = discovery:getServerListItemName(index)
             if servername == "" then
@@ -133,12 +140,15 @@
             if serverip == "" then
                 break
             end
-            table.insert(P.serverList, {servername, serverip})
+            --serverrtt = discovery:getServerListItemRTT(index)
+            playernumber = discovery:getServerListItemPlayerNumber(index)
+
+            table.insert(P.serverList, {serverip, servername, playernumber})
             index = index + 1
         end
         index = 1
         for k,v in pairs(P.serverList) do
-            local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] )
+            local item = CEGUI.createListboxTextItem("IP: " .. v[1] .. " Name: " .. v[2] .. " Players: " .. v[3])
             item:setID(index)
             index = index + 1
             item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
@@ -149,4 +159,3 @@
 end
 
 return P
-

Modified: code/branches/presentationFS15/data/levels/includes/weaponSettingsHeartAttack.oxi
===================================================================
--- code/branches/presentationFS15/data/levels/includes/weaponSettingsHeartAttack.oxi	2015-05-27 08:21:55 UTC (rev 10496)
+++ code/branches/presentationFS15/data/levels/includes/weaponSettingsHeartAttack.oxi	2015-05-27 08:45:56 UTC (rev 10497)
@@ -34,6 +34,7 @@
 	  	<LaserFire mode=1 munitionpershot=0 muzzleoffset="2.2,6,16" damage=30 shielddamage=20 />
 	  	<LaserFire mode=1 munitionpershot=0 muzzleoffset="-2.2,6,16" damage=30 shielddamage=20 />
           	<RocketFire mode=3 muzzleoffset="0,0,0" damage=30 healthdamage=50 shielddamage=20 />
+          <GravityBombFire mode=2 muzzleoffset="0,0,0" damage=30 shielddamage=20 />
 		
         </Weapon>
 	<Weapon>

Modified: code/branches/presentationFS15/src/libraries/network/GamestateManager.h
===================================================================
--- code/branches/presentationFS15/src/libraries/network/GamestateManager.h	2015-05-27 08:21:55 UTC (rev 10496)
+++ code/branches/presentationFS15/src/libraries/network/GamestateManager.h	2015-05-27 08:45:56 UTC (rev 10497)
@@ -1,4 +1,4 @@
-/*
+  /*
  *   ORXONOX - the hottest 3D action shooter ever to exist
  *                    > www.orxonox.net <
  *
@@ -77,9 +77,9 @@
       bool      isSynched;
       std::map< uint32_t, packet::Gamestate* > gamestates;
     };
-    
+
   public:
-    
+
     GamestateManager();
     ~GamestateManager();
 
@@ -87,7 +87,7 @@
     virtual bool      ackGamestate(unsigned int gamestateID, unsigned int peerID);
     virtual uint32_t  getLastReceivedGamestateID( unsigned int peerID );
     virtual uint32_t  getCurrentGamestateID(){ if( currentGamestate_) return currentGamestate_->getID(); else return GAMESTATEID_INITIAL; }
-    
+
     bool processGamestates();
     bool sendAck(unsigned int gamestateID, uint32_t peerID);
     bool update();

Modified: code/branches/presentationFS15/src/libraries/network/LANDiscoverable.cc
===================================================================
--- code/branches/presentationFS15/src/libraries/network/LANDiscoverable.cc	2015-05-27 08:21:55 UTC (rev 10496)
+++ code/branches/presentationFS15/src/libraries/network/LANDiscoverable.cc	2015-05-27 08:45:56 UTC (rev 10497)
@@ -34,7 +34,10 @@
 
 #include "util/Output.h"
 #include "packet/ServerInformation.h"
+#include "core/config/ConfigValueIncludes.h"
+#include "core/CoreIncludes.h"
 
+
 namespace orxonox
 {
   const char* LAN_DISCOVERY_MESSAGE = "Orxonox Client";
@@ -42,11 +45,23 @@
 
   LANDiscoverable::LANDiscoverable()
   {
+    /* register object in orxonox */
+    RegisterObject(LANDiscoverable);
+
+    this->setConfigValues();
+    //     this->setActivity(true);
     this->host_ = 0;
     this->bActive_ = false;
-//     this->setActivity(true);
   }
 
+  void LANDiscoverable::setConfigValues()
+  {
+    /* update ownName string from orxonox.ini config file, if it
+     * has changed.
+     */
+    SetConfigValueExternal(ownName, "Discovery", "ownName", "OrxServer");
+  }
+
   LANDiscoverable::~LANDiscoverable()
   {
     if( this->host_ )
@@ -60,7 +75,7 @@
   {
     if( bActive == this->bActive_ )        // no change
       return;
-    
+
     if( bActive )
     {
       ENetAddress bindAddress;
@@ -83,11 +98,11 @@
   void LANDiscoverable::update()
   {
     ENetEvent event;
-    
+
     if( this->bActive_==false )
       return;
     assert(this->host_);
-    
+
     while( enet_host_service( this->host_, &event, 0 ) > 0 )
     {
       switch(event.type)
@@ -103,7 +118,8 @@
           {
             orxout(internal_info, context::network) << "Received LAN discovery message from client " << event.peer->host->receivedAddress << endl;
             packet::ServerInformation info;
-            info.setServerName("Orxonox Server");
+            info.setServerName(this->ownName);
+            info.setClientNumber(this->clientNumber);
             info.send(event.peer);
 //             ENetPacket* packet = enet_packet_create( LAN_DISCOVERY_ACK, strlen(LAN_DISCOVERY_ACK)+1, ENET_PACKET_FLAG_RELIABLE );
 //             enet_peer_send(event.peer, 0, packet );

Modified: code/branches/presentationFS15/src/libraries/network/LANDiscoverable.h
===================================================================
--- code/branches/presentationFS15/src/libraries/network/LANDiscoverable.h	2015-05-27 08:21:55 UTC (rev 10496)
+++ code/branches/presentationFS15/src/libraries/network/LANDiscoverable.h	2015-05-27 08:45:56 UTC (rev 10497)
@@ -30,21 +30,28 @@
 #define _LANDISCOVERABLE_H__
 
 #include "NetworkPrereqs.h"
+#include "core/config/Configurable.h"
 
 namespace orxonox
 {
 
-  class LANDiscoverable
+  class LANDiscoverable: public Configurable
   {
     public:
       LANDiscoverable();
       virtual ~LANDiscoverable();
       void setActivity( bool bActive );
       void update();
+      void updateClientNumber(int clientNumber) {this->clientNumber = clientNumber;}
+;
+      /** Function used for the configuration file parameter update */
+      void setConfigValues();
 
     private:
       bool            bActive_;
       ENetHost*       host_;
+      std::string     ownName;
+      int             clientNumber;
   };
 
 }

Modified: code/branches/presentationFS15/src/libraries/network/LANDiscovery.cc
===================================================================
--- code/branches/presentationFS15/src/libraries/network/LANDiscovery.cc	2015-05-27 08:21:55 UTC (rev 10496)
+++ code/branches/presentationFS15/src/libraries/network/LANDiscovery.cc	2015-05-27 08:45:56 UTC (rev 10497)
@@ -88,7 +88,10 @@
         case ENET_EVENT_TYPE_RECEIVE:
           {
             packet::ServerInformation info(&event);
-            orxout(internal_info, context::network) << "Received LAN discovery server information; Name: " << info.getServerName() << ", Address: " << info.getServerIP() << ", RTT: " << info.getServerRTT() << endl;
+            std::string payload = info.getServerName();
+            info.setServerName(payload.substr(0,payload.length()-2));
+            info.setClientNumber( Ogre::StringConverter::parseInt(payload.substr(payload.length()-1)));
+            orxout(internal_info, context::network) << "Received LAN discovery server information; Name: " << info.getServerName() << ", Address: " << info.getServerIP() << ", Players: " << info.getClientNumber() << ", RTT: " << info.getServerRTT() << endl;
             std::vector<packet::ServerInformation>::iterator it;
             for( it=this->servers_.begin(); it!=this->servers_.end(); ++it )
             {
@@ -123,5 +126,23 @@
       return this->servers_[index].getServerIP();
   }
 
+  std::string LANDiscovery::getServerListItemRTT(unsigned int index)
+  {
+    if( index >= this->servers_.size() )
+      return BLANKSTRING;
+    else{
+      uint32_t serverrtt = this->servers_[index].getServerRTT();
+      return Ogre::StringConverter::toString(serverrtt);
+    }
+  }
 
+  std::string LANDiscovery::getServerListItemPlayerNumber(unsigned int index)
+  {
+    if( index >= this->servers_.size() )
+      return BLANKSTRING;
+    else{
+      int playerNumber = this->servers_[index].getClientNumber();
+      return Ogre::StringConverter::toString(playerNumber);
+    }
+  }
 } // namespace orxonox

Modified: code/branches/presentationFS15/src/libraries/network/LANDiscovery.h
===================================================================
--- code/branches/presentationFS15/src/libraries/network/LANDiscovery.h	2015-05-27 08:21:55 UTC (rev 10496)
+++ code/branches/presentationFS15/src/libraries/network/LANDiscovery.h	2015-05-27 08:45:56 UTC (rev 10497)
@@ -32,6 +32,7 @@
 #include "NetworkPrereqs.h"
 #include "packet/ServerInformation.h"
 #include "util/Singleton.h"
+#include <OgreStringConverter.h>
 
 #include <vector>
 
@@ -50,8 +51,10 @@
       void discover(); // tolua_export
       std::string getServerListItemName( unsigned int index ); // tolua_export
       std::string getServerListItemIP( unsigned int index ); // tolua_export
+      std::string getServerListItemRTT( unsigned int index ); // tolua_export
+      std::string getServerListItemPlayerNumber( unsigned int index ); // tolua_export
       static LANDiscovery& getInstance(){ return Singleton<LANDiscovery>::getInstance(); } // tolua_export
-      
+
     private:
       static LANDiscovery* singletonPtr_s;
       ENetHost* host_;

Modified: code/branches/presentationFS15/src/libraries/network/MasterServer.cc
===================================================================
--- code/branches/presentationFS15/src/libraries/network/MasterServer.cc	2015-05-27 08:21:55 UTC (rev 10496)
+++ code/branches/presentationFS15/src/libraries/network/MasterServer.cc	2015-05-27 08:45:56 UTC (rev 10497)
@@ -33,7 +33,7 @@
 #include "core/CorePrereqs.h"
 #include "util/Output.h"
 
-namespace orxonox 
+namespace orxonox
 {
   /*** MACROS ***/
   /* commands for the terminal interface */
@@ -44,11 +44,8 @@
   /* forward declaration so the linker doesn't complain */
   MasterServer *MasterServer::instance = NULL;
 
-
-
-
   /* command: list servers */
-  void 
+  void
   MasterServer::listServers( void )
   {
     /* get an iterator */
@@ -58,8 +55,8 @@
     orxout(user_info) << "List of connected servers" << std::endl;
 
     /* loop through list elements */
-    for( i = MasterServer::getInstance()->mainlist.serverlist.begin(); 
-      i != MasterServer::getInstance()->mainlist.serverlist.end(); ++i ) 
+    for( i = MasterServer::getInstance()->mainlist.serverlist.begin();
+      i != MasterServer::getInstance()->mainlist.serverlist.end(); ++i )
     {
       orxout(user_info) << "  " << (*i).ServerInfo.getServerIP() << std::endl;
     }
@@ -69,15 +66,15 @@
       " servers connected." << std::endl;
   }
 
-  void 
+  void
   MasterServer::delServer( std::string todeladdr )
   {
     /* tell the user we're now removing the entry from the server list */
-    orxout(user_info) << "MS: Deleting server \"" << todeladdr << "\"..." 
+    orxout(user_info) << "MS: Deleting server \"" << todeladdr << "\"..."
       << std::endl;
 
     /* see if we actually have that server on our list */
-    ServerListSearchResult shandle = 
+    ServerListSearchResult shandle =
       MasterServer::getInstance()->mainlist.findServerByAddress(todeladdr);
 
     if( !shandle.success )
@@ -85,7 +82,7 @@
       return;
     }
 
-    /* force-disconnect the server */  
+    /* force-disconnect the server */
     enet_peer_disconnect( shandle.result.peer, 0 );
 
     /* actually remove the entry from the server list by address */
@@ -97,16 +94,16 @@
 
 
   /* helpers */
-  static void 
+  static void
   helper_output_debug( ENetEvent *event, char *addrconv )
   {
     orxout(verbose, context::master_server)
-      << "A packet of length" 
+      << "A packet of length"
       << event->packet->dataLength
       << " containing "
       << (const char*)event->packet->data
       << " was received from "
-      << addrconv 
+      << addrconv
       << " on channel "
       << event->channelID << endl;
   }
@@ -121,23 +118,23 @@
     ENetPacket *reply;
 
     /* loop through list elements */
-    for( i = mainlist.serverlist.begin(); i 
-        != mainlist.serverlist.end(); ++i ) 
+    for( i = mainlist.serverlist.begin(); i
+        != mainlist.serverlist.end(); ++i )
     {
       /* send this particular server */
       /* build reply string */
-      char *tosend = (char *)calloc( (*i).ServerInfo.getServerIP().length() 
-          + MSPROTO_SERVERLIST_ITEM_LEN + 2,1 );
-      if( !tosend ) 
+      int packetlen = MSPROTO_SERVERLIST_ITEM_LEN + 1 + (*i).ServerInfo.getServerIP().length() + 1 + (*i).ServerInfo.getServerName().length() + 1 + sizeof((*i).ServerInfo.getClientNumber()) + 1;
+      char *tosend = (char *)calloc(packetlen ,1 );
+      if( !tosend )
       { orxout(internal_warning, context::master_server) << "Masterserver.cc: Memory allocation failed." << endl;
         continue;
-      } 
-      sprintf( tosend, "%s %s", MSPROTO_SERVERLIST_ITEM, 
-          (*i).ServerInfo.getServerIP().c_str() );
+      }
+      sprintf( tosend, "%s %s %s %u", MSPROTO_SERVERLIST_ITEM,
+          (*i).ServerInfo.getServerIP().c_str(), (*i).ServerInfo.getServerName().c_str(), (*i).ServerInfo.getClientNumber());
 
       /* create packet from it */
       reply = enet_packet_create( tosend,
-          strlen( tosend ) + 1, 
+          strlen( tosend ) + 1,
           ENET_PACKET_FLAG_RELIABLE);
 
       /* Send the reply to the peer over channel id 0. */
@@ -148,7 +145,7 @@
 
       /* free the tosend buffer */
       free( tosend );
-    } 
+    }
 
     /* create end-of-list packet */
     reply = enet_packet_create( MSPROTO_SERVERLIST_END,
@@ -162,40 +159,40 @@
     enet_host_flush( this->server );
   }
 
-  /* maybe the two methods below can be merged into one and 
-   * made to use ENet's RTT functionality to check for disconnected 
+  /* maybe the two methods below can be merged into one and
+   * made to use ENet's RTT functionality to check for disconnected
    * servers.
    */
-  void 
+  void
   MasterServer::helper_cleanupServers( void )
   {
     /* get an iterator */
     std::list<ServerListElem>::iterator i;
-     
+
     if( mainlist.serverlist.size() == 0 )
       return;
 
     /* loop through list elements */
-    for( i = mainlist.serverlist.begin(); i 
-        != mainlist.serverlist.end(); ++i ) 
+    for( i = mainlist.serverlist.begin(); i
+        != mainlist.serverlist.end(); ++i )
     { /* see if we have a disconnected peer */
-      if( (*i).peer && 
+      if( (*i).peer &&
          ((*i).peer->state == ENET_PEER_STATE_DISCONNECTED ||
           (*i).peer->state == ENET_PEER_STATE_ZOMBIE ))
-      { 
+      {
         /* Remove it from the list */
         orxout(internal_warning) << (char*)(*i).peer->data << " timed out.\n";
         mainlist.delServerByName( (*i).ServerInfo.getServerName() );
 
         /* stop iterating, we manipulated the list */
         /* TODO note: this only removes one dead server per loop
-         * iteration. not beautiful, but one iteration is ~100ms, 
+         * iteration. not beautiful, but one iteration is ~100ms,
          * so not really relevant for the moment.
          */
         break;
       }
     }
- 
+
   }
 
 
@@ -203,7 +200,7 @@
 
   /***** EVENTS *****/
   /* connect event */
-  int 
+  int
   MasterServer::eventConnect( ENetEvent *event )
   { /* check for bad parameters */
     if( !event )
@@ -216,20 +213,20 @@
     enet_address_get_host_ip( &(event->peer->address), addrconv, 49 );
 
     /* output debug info */
-    orxout(verbose, context::master_server) << "A new client connected from " 
-      << addrconv 
-      << " on port " 
+    orxout(verbose, context::master_server) << "A new client connected from "
+      << addrconv
+      << " on port "
       << event->peer->address.port << endl;
 
     /* store string form of address here */
-    event->peer->data = addrconv; 
+    event->peer->data = addrconv;
 
     /* all fine. */
     return 0;
   }
 
   /* disconnect event */
-  int 
+  int
   MasterServer::eventDisconnect( ENetEvent *event )
   { /* check for bad parameters */
     if( !event )
@@ -254,68 +251,87 @@
   }
 
   /* data event */
-  int 
+  int
   MasterServer::eventData( ENetEvent *event )
   { /* validate packet */
     if( !event || !(event->packet) || !(event->peer) )
     { orxout(internal_warning, context::master_server) << "No complete event given." << endl;
       return -1;
     }
-     
+
     /* generate address in readable form */
     char *addrconv = (char *) calloc( 50, 1 );
     enet_address_get_host_ip( &(event->peer->address), addrconv, 49 );
+    /* convert to string */
+    std::string ip = std::string( addrconv );
+    /* delete addrconv */
+    if( addrconv ) free( addrconv );
 
+    /* pointer to full packet data */
+    char * packetdata = (char *)event->packet->data;
+
     /* output debug info about the data that has come */
     helper_output_debug( event, addrconv );
 
     /* GAME SERVER OR CLIENT CONNECTION? */
-    if( !strncmp( (char *)event->packet->data, MSPROTO_GAME_SERVER, 
-      MSPROTO_GAME_SERVER_LEN ) )
+    if( !strncmp(packetdata, MSPROTO_GAME_SERVER, MSPROTO_GAME_SERVER_LEN ) )
     { /* Game server */
 
-      if( !strncmp( (char *)event->packet->data 
-        + MSPROTO_GAME_SERVER_LEN+1, 
-        MSPROTO_REGISTER_SERVER, MSPROTO_REGISTER_SERVER_LEN ) )
+      if( !strncmp( packetdata + MSPROTO_GAME_SERVER_LEN+1, MSPROTO_REGISTER_SERVER, MSPROTO_REGISTER_SERVER_LEN ) )
       { /* register new server */
-        mainlist.addServer( packet::ServerInformation( event ),
-          event->peer );
-        
+        mainlist.addServer( packet::ServerInformation( event ), event->peer );
+
         /* tell people we did so */
-        orxout(internal_info, context::master_server) << "Added new server to list: " << 
+        orxout(internal_info, context::master_server) << "Added new server to list: " <<
           packet::ServerInformation( event ).getServerIP() << endl;
       }
 
-      else if( !strncmp( (char *)event->packet->data
-        + MSPROTO_GAME_SERVER_LEN+1,
-        MSPROTO_SERVERDC, MSPROTO_SERVERDC_LEN ) )
-      {
+      else if( !strncmp( packetdata + MSPROTO_GAME_SERVER_LEN+1, MSPROTO_SERVERDC, MSPROTO_SERVERDC_LEN ) )
+      { /* disconnect server */
+
+        /* remove the server from the list it belongs to */
+        this->mainlist.delServerByAddress( ip );
+
+        /* tell the user */
+        orxout(internal_info, context::master_server) << "Removed server " << ip << " from list." << endl;
+      }
+      /* TODO add hook for disconnect here */
+
+      else if( !strncmp( packetdata + MSPROTO_GAME_SERVER_LEN+1, MSPROTO_SET_NAME, MSPROTO_SET_NAME_LEN ) )
+      { /* save server name */
         /* create string from peer data */
-        std::string name = std::string( addrconv );
+        std::string data (event->packet->data,event->packet->data + event->packet->dataLength );
+        std::string name = data.substr(MSPROTO_GAME_SERVER_LEN+1 + MSPROTO_SET_NAME_LEN + 1);
 
         /* remove the server from the list it belongs to */
-        this->mainlist.delServerByAddress( name );
+        this->mainlist.setNameByAddress( ip, name );
 
         /* tell the user */
-        orxout(internal_info, context::master_server) << "Removed server " << name << " from list." << endl;
+        orxout(internal_info, context::master_server) << "Updated server " << ip << " with new name " << name << endl;
       }
 
-      /* TODO add hook for disconnect here */
+      else if( !strncmp( packetdata + MSPROTO_GAME_SERVER_LEN+1, MSPROTO_SET_CLIENTS, MSPROTO_SET_CLIENTS_LEN ) )
+      { /* save client count from server */
+        /* create string from peer data */
+        std::string data (event->packet->data,event->packet->data + event->packet->dataLength );
+        std::string textform= data.substr(MSPROTO_GAME_SERVER_LEN + 1 + MSPROTO_SET_CLIENTS_LEN + 1);
+        int clientNumber = Ogre::StringConverter::parseInt(textform);
+
+        this->mainlist.setClientsByAddress( ip, clientNumber);
+
+        /* tell the user */
+        orxout(internal_info, context::master_server) << "Updated server " << ip << " with new client number " << clientNumber << endl;
+      }
     }
-    else if( !strncmp( (char *)event->packet->data, MSPROTO_CLIENT, 
-      MSPROTO_CLIENT_LEN) )
+    else if( !strncmp( packetdata, MSPROTO_CLIENT, MSPROTO_CLIENT_LEN) )
     { /* client */
-      if( !strncmp( (char *)event->packet->data + MSPROTO_CLIENT_LEN+1,
-        MSPROTO_REQ_LIST, MSPROTO_REQ_LIST_LEN ) )
+      if( !strncmp( packetdata + MSPROTO_CLIENT_LEN+1, MSPROTO_REQ_LIST, MSPROTO_REQ_LIST_LEN ) )
         /* send server list */
         helper_sendlist( event );
     }
     else
-    { /* bad message, don't do anything. */ } 
+    { /* bad message, don't do anything. */ }
 
-    /* delete addrconv */
-    if( addrconv ) free( addrconv );
-
     /* Clean up the packet now that we're done using it. */
     enet_packet_destroy( event->packet );
     return 0;
@@ -323,13 +339,13 @@
 
 
   /**** MAIN ROUTINE *****/
-  int 
+  int
   MasterServer::run()
   {
     /***** ENTER MAIN LOOP *****/
     ENetEvent *event = (ENetEvent *)calloc(sizeof(ENetEvent), sizeof(char));
     if( event == NULL )
-    { 
+    {
       orxout(user_error, context::master_server) << "Could not create ENetEvent structure, exiting." << endl;
       exit( EXIT_FAILURE );
     }
@@ -344,11 +360,11 @@
     /* check what type of event it is and react accordingly */
     switch (event->type)
     { /* new connection */
-      case ENET_EVENT_TYPE_CONNECT: 
+      case ENET_EVENT_TYPE_CONNECT:
         eventConnect( event ); break;
 
         /* disconnect */
-      case ENET_EVENT_TYPE_DISCONNECT: 
+      case ENET_EVENT_TYPE_DISCONNECT:
         eventDisconnect( event ); break;
 
         /* incoming data */
@@ -357,8 +373,9 @@
     }
 
     /* done */
+    free(event);
     return 0;
-  } 
+  }
 
   /* constructor */
   MasterServer::MasterServer()
@@ -379,15 +396,15 @@
     this->address.host = ENET_HOST_ANY;
     this->address.port = ORX_MSERVER_PORT;
 
-    /* create a host with the above settings (the last two 0 mean: accept 
+    /* create a host with the above settings (the last two 0 mean: accept
      * any input/output bandwidth */
-    this->server = enet_host_create( &this->address, ORX_MSERVER_MAXCONNS, 
+    this->server = enet_host_create( &this->address, ORX_MSERVER_MAXCONNS,
         ORX_MSERVER_MAXCHANS, 0, 0 );
     assert(this->server);
 
     /* see if creation worked */
     if( !this->server )
-    { orxout(user_error, context::master_server) << 
+    { orxout(user_error, context::master_server) <<
         "An error occurred while trying to create an ENet server host." << endl;
       exit( EXIT_FAILURE );
     }

Modified: code/branches/presentationFS15/src/libraries/network/MasterServer.h
===================================================================
--- code/branches/presentationFS15/src/libraries/network/MasterServer.h	2015-05-27 08:21:55 UTC (rev 10496)
+++ code/branches/presentationFS15/src/libraries/network/MasterServer.h	2015-05-27 08:45:56 UTC (rev 10497)
@@ -48,7 +48,10 @@
 /* c compatibility */
 #include <cstdio>
 
-namespace orxonox 
+#include <OgreStringConverter.h>
+
+
+namespace orxonox
 {
   /* singleton */
   class _NetworkExport MasterServer
@@ -62,11 +65,11 @@
 
       /* static pointer for commands */
       static MasterServer *instance;
-      static MasterServer *getInstance() 
+      static MasterServer *getInstance()
         { return instance; }
-      static void setInstance( MasterServer *setto ) 
+      static void setInstance( MasterServer *setto )
         { instance = setto;  }
-      
+
       /* functions for commands */
       static void listServers( void );
       static void delServer( std::string todeladdr );

Modified: code/branches/presentationFS15/src/libraries/network/MasterServerProtocol.h
===================================================================
--- code/branches/presentationFS15/src/libraries/network/MasterServerProtocol.h	2015-05-27 08:21:55 UTC (rev 10496)
+++ code/branches/presentationFS15/src/libraries/network/MasterServerProtocol.h	2015-05-27 08:45:56 UTC (rev 10497)
@@ -36,15 +36,13 @@
 /*** CLIENT COMMUNICATIONS ***/
 /* Client token (shows that the party sending data is a client */
 #define MSPROTO_CLIENT "CL"
-#define MSPROTO_CLIENT_LEN 2 
+#define MSPROTO_CLIENT_LEN 2
 
 /* Request: Serverlist (requiest made from client to master server */
 #define MSPROTO_REQ_LIST "REQ:LIST"
 #define MSPROTO_REQ_LIST_LEN 8
 
 
-
-
 /*** GAME SERVER COMMUNICATIONS ***/
 /* Game server token (shows that the party sending data is a game server) */
 #define MSPROTO_GAME_SERVER "GS"
@@ -66,7 +64,7 @@
 
 /* ping request from server */
 #define MSPROTO_PING_GAMESERVER "PING"
-#define MSPROTO_PING_GAMESERVER_LEN 4 
+#define MSPROTO_PING_GAMESERVER_LEN 4
 
 /* server disconnect */
 #define MSPROTO_SERVERDC "DC"
@@ -74,10 +72,18 @@
 
 /* ping reply */
 #define MSPROTO_ACK "ACK"
-#define MSPROTO_ACK_LEN 3 
+#define MSPROTO_ACK_LEN 3
 
+/* server name */
+#define MSPROTO_SET_NAME "NAM"
+#define MSPROTO_SET_NAME_LEN 3
 
+/* server number of clients */
+#define MSPROTO_SET_CLIENTS "CLI"
+#define MSPROTO_SET_CLIENTS_LEN 3
 
+#define SERVER_NAME_MAXLEN 7
+
 /* default master server port */
 #define ORX_MSERVER_PORT 55557
 

Modified: code/branches/presentationFS15/src/libraries/network/PeerList.cc
===================================================================
--- code/branches/presentationFS15/src/libraries/network/PeerList.cc	2015-05-27 08:21:55 UTC (rev 10496)
+++ code/branches/presentationFS15/src/libraries/network/PeerList.cc	2015-05-27 08:45:56 UTC (rev 10497)
@@ -37,10 +37,10 @@
   PeerList::PeerList() { }
   PeerList::~PeerList() { }
 
-  int 
+  int
   PeerList::addPeer( ENetPeer *toadd )
   { /* error correction */
-    if( toadd == NULL ) 
+    if( toadd == NULL )
     { orxout(internal_error, context::master_server) << "PeerList::addPeer: empty peer given." << endl;
       return -1;
     }
@@ -51,7 +51,7 @@
   }
 
   bool sub_compAddr( ENetAddress addr1, ENetAddress addr2 )
-  { 
+  {
     for( int i = 0; i < 16; ++i )
       if( addr1.host.addr[i] < addr2.host.addr[i] )
         return -i;
@@ -60,15 +60,15 @@
 
     return 0;
   }
-    
 
+
   bool
   PeerList::remPeerByAddr( ENetAddress addr )
   { /* get an iterator */
     std::list<ENetPeer *>::iterator i;
 
     /* loop through list elements */
-    for( i = peerlist.begin(); i != peerlist.end(); ++i ) 
+    for( i = peerlist.begin(); i != peerlist.end(); ++i )
       if( !sub_compAddr((*i)->address, addr ) )
       { /* found this name, remove and quit */
         this->peerlist.remove( *i );
@@ -85,7 +85,7 @@
     std::list<ENetPeer *>::iterator i;
 
     /* loop through list elements */
-    for( i = peerlist.begin(); i != peerlist.end(); ++i ) 
+    for( i = peerlist.begin(); i != peerlist.end(); ++i )
       if( !sub_compAddr((*i)->address, addr ) )
         /* found this name, remove and quit */
         return *i;
@@ -94,5 +94,9 @@
     return NULL;
   }
 
+  int
+  PeerList::count(){
+    return this->peerlist.size();
+  }
+
 }
-

Modified: code/branches/presentationFS15/src/libraries/network/PeerList.h
===================================================================
--- code/branches/presentationFS15/src/libraries/network/PeerList.h	2015-05-27 08:21:55 UTC (rev 10496)
+++ code/branches/presentationFS15/src/libraries/network/PeerList.h	2015-05-27 08:45:56 UTC (rev 10497)
@@ -34,12 +34,12 @@
 #include <enet/enet.h>
 
 /* peer list */
-namespace orxonox 
+namespace orxonox
 {
-  /** This class keeps a list of open connections 
+  /** This class keeps a list of open connections
    * and some info about them.
    */
-  class PeerList 
+  class PeerList
   { public:
       /** constructor */
       PeerList();
@@ -49,24 +49,30 @@
 
       /** \param toadd The peer to add
        * \return 0 for success, -1 for error.
-       * 
-       * Add new peer to list 
+       *
+       * Add new peer to list
        */
       int addPeer( ENetPeer *toadd );
 
       /** \param addr Address to look for
        * \return if the peer was found or not
-       * 
-       * Remove peer from list by address 
+       *
+       * Remove peer from list by address
        */
       bool remPeerByAddr( ENetAddress addr );
 
       /** \param addr The address to find by
-       * 
-       * Find a connection by address */
+       *
+       * Find a connection by address
+       */
       ENetPeer *findPeerByAddr( ENetAddress addr );
 
-      /* NOTE: making this list public so it can easily 
+      /**
+       * Count current peers
+       */
+       int count();
+
+      /* NOTE: making this list public so it can easily
        * be iterated. This makes sense since iterating it
        * will happen all the time, and using getter methods
        * for the next in list would slow things down unnecessarily.

Modified: code/branches/presentationFS15/src/libraries/network/Server.cc
===================================================================
--- code/branches/presentationFS15/src/libraries/network/Server.cc	2015-05-27 08:21:55 UTC (rev 10496)
+++ code/branches/presentationFS15/src/libraries/network/Server.cc	2015-05-27 08:45:56 UTC (rev 10497)
@@ -76,7 +76,13 @@
     this->setPort( port );
     this->timeSinceLastUpdate_=0;
   }
-
+/*
+  Server::Server(int port, const std::string name)
+  {
+    this->setPort( port );
+    this->timeSinceLastUpdate_=0;
+    this->serverName_=name;
+  }*/
   /**
   * Constructor
   * @param port Port to listen on
@@ -107,9 +113,11 @@
 
     /* make discoverable on LAN */
     LANDiscoverable::setActivity(true);
+    LANDiscoverable::updateClientNumber(0);
 
     /* make discoverable on WAN */
     WANDiscoverable::setActivity(true);
+    WANDiscoverable::updateClientNumber(0);
 
     /* done */
     return;
@@ -282,12 +290,16 @@
 
     // inform all the listeners
     this->clientIDs_.push_back(peerID);
+    WANDiscoverable::updateClientNumber(this->clientIDs_.size());
+    LANDiscoverable::updateClientNumber(this->clientIDs_.size());
+
     ClientConnectionListener::broadcastClientConnected(peerID);
     GamestateManager::addPeer(peerID);
 
 //     ++newid;
 
     orxout(internal_info, context::network) << "Server: added client id: " << peerID << endl;
+
     createClient(peerID);
 }
 
@@ -308,6 +320,9 @@
       break;
     }
   }
+  WANDiscoverable::updateClientNumber(this->clientIDs_.size());
+  LANDiscoverable::updateClientNumber(this->clientIDs_.size());
+
   ClientConnectionListener::broadcastClientDisconnected(peerID);
   GamestateManager::removePeer(peerID);
       //ServerConnection::disconnectClient( client );

Modified: code/branches/presentationFS15/src/libraries/network/Server.h
===================================================================
--- code/branches/presentationFS15/src/libraries/network/Server.h	2015-05-27 08:21:55 UTC (rev 10496)
+++ code/branches/presentationFS15/src/libraries/network/Server.h	2015-05-27 08:45:56 UTC (rev 10497)
@@ -66,6 +66,9 @@
     unsigned int getRTT(unsigned int clientID);
     virtual void printRTT();
     float getPacketLoss(unsigned int clientID);
+    int getClientCount() { return this->clientIDs_.size();}
+    std::string getServerName() { return this->serverName_;}
+
   protected:
     void updateGamestate();
   private:
@@ -88,6 +91,7 @@
     float timeSinceLastUpdate_;
     std::deque<packet::Packet*> packetQueue_;
     std::vector<uint32_t>       clientIDs_;
+    std::string                 serverName_;
   };
 
 

Modified: code/branches/presentationFS15/src/libraries/network/ServerList.cc
===================================================================
--- code/branches/presentationFS15/src/libraries/network/ServerList.cc	2015-05-27 08:21:55 UTC (rev 10496)
+++ code/branches/presentationFS15/src/libraries/network/ServerList.cc	2015-05-27 08:45:56 UTC (rev 10497)
@@ -29,7 +29,7 @@
 #include "ServerList.h"
 
 namespace orxonox
-{ 
+{
   ServerList::ServerList()
   { /* create a new list */ }
 
@@ -38,26 +38,26 @@
     serverlist.clear();
   }
 
-  int 
+  int
   ServerList::addServer( packet::ServerInformation toadd,
     ENetPeer *peer )
-  { 
+  {
     ServerListElem toAdd;
     toAdd.ServerInfo = toadd;
     toAdd.peer = peer;
 
-    this->serverlist.push_back( toAdd ); 
+    this->serverlist.push_back( toAdd );
     return 0;
   }
 
-  bool 
+  bool
   ServerList::delServerByName( std::string name )
-  { 
+  {
     /* get an iterator */
     std::list<ServerListElem>::iterator i;
 
     /* loop through list elements */
-    for( i = serverlist.begin(); i != serverlist.end(); ++i ) 
+    for( i = serverlist.begin(); i != serverlist.end(); ++i )
       if( (*i).ServerInfo.getServerName() == name )
       { /* found this name, remove and quit */
         this->serverlist.erase( i );
@@ -67,12 +67,12 @@
   }
 
   bool ServerList::delServerByAddress( std::string address )
-  { 
+  {
     /* get an iterator */
     std::list<ServerListElem>::iterator i;
 
     /* loop through list elements */
-    for( i = serverlist.begin(); i != serverlist.end(); ++i ) 
+    for( i = serverlist.begin(); i != serverlist.end(); ++i )
       if( (*i).ServerInfo.getServerIP() == address )
       { /* found this name, remove and quit */
         this->serverlist.erase( i );
@@ -89,7 +89,7 @@
     std::list<ServerListElem>::iterator i;
 
     /* loop through list elements */
-    for( i = serverlist.begin(); i != serverlist.end(); ++i ) 
+    for( i = serverlist.begin(); i != serverlist.end(); ++i )
       if( (*i).ServerInfo.getServerIP() == address )
       { /* found the target, return it */
         ServerListSearchResult res = { (*i), true };
@@ -109,9 +109,9 @@
 
     /* iterate, return when name found */
     /* loop through list elements */
-    for( i = serverlist.begin(); i != serverlist.end(); ++i ) 
+    for( i = serverlist.begin(); i != serverlist.end(); ++i )
       if( (*i).ServerInfo.getServerName() == name )
-      { 
+      {
         ServerListSearchResult res = { (*i), true };
         return res;
       }
@@ -123,25 +123,53 @@
 
   /* SORTING */
   /* sort by name */
-  bool sub_compare_names( ServerListElem no1, 
+  bool sub_compare_names( ServerListElem no1,
     ServerListElem no2 )
   { return no1.ServerInfo.getServerName() > no2.ServerInfo.getServerName(); }
 
   void ServerList::sortByName()
-  { 
-    this->serverlist.sort( sub_compare_names ); 
+  {
+    this->serverlist.sort( sub_compare_names );
   }
-  
+
   /* sort by ping */
-  bool sub_compare_pings( ServerListElem no1, 
+  bool sub_compare_pings( ServerListElem no1,
     ServerListElem no2 )
-  { 
-    return no1.ServerInfo.getServerName() > no2.ServerInfo.getServerName();
+  {
+    return no1.ServerInfo.getServerRTT() > no2.ServerInfo.getServerRTT();
   }
 
   void ServerList::sortByPing()
   {
-    this->serverlist.sort( sub_compare_pings ); 
+    this->serverlist.sort( sub_compare_pings );
   }
 
+  bool ServerList::setNameByAddress( std::string address, std::string name  ){
+    /* get an iterator */
+    std::list<ServerListElem>::iterator i;
+
+    /* loop through list elements */
+    for( i = serverlist.begin(); i != serverlist.end(); ++i )
+      if( (*i).ServerInfo.getServerIP() == address )
+      { /* found this adress, rename and quit */
+        (*i).ServerInfo.setServerName( name );
+        return true;
+      }
+    return false;
+  };
+
+  bool ServerList::setClientsByAddress( std::string address, int clientNumber ){
+    /* get an iterator */
+    std::list<ServerListElem>::iterator i;
+
+    /* loop through list elements */
+    for( i = serverlist.begin(); i != serverlist.end(); ++i )
+      if( (*i).ServerInfo.getServerIP() == address )
+      { /* found this adress, rename and quit */
+        (*i).ServerInfo.setClientNumber( clientNumber );
+        return true;
+      }
+    return false;
+  };
+
 }

Modified: code/branches/presentationFS15/src/libraries/network/ServerList.h
===================================================================
--- code/branches/presentationFS15/src/libraries/network/ServerList.h	2015-05-27 08:21:55 UTC (rev 10496)
+++ code/branches/presentationFS15/src/libraries/network/ServerList.h	2015-05-27 08:45:56 UTC (rev 10497)
@@ -34,10 +34,10 @@
 #include <network/packet/ServerInformation.h>
 
 /* methods necessary */
-namespace orxonox 
-{ 
+namespace orxonox
+{
   /* HELPER STRUCTURES */
-  struct ServerListElem 
+  struct ServerListElem
   {
     /* server information (name, IP, etc) */
     packet::ServerInformation ServerInfo;
@@ -62,7 +62,7 @@
   /** This class is keeps a list of game servers
    * and some info about them.
    */
-  class ServerList 
+  class ServerList
   { public:
       /** constructor */
       ServerList();
@@ -73,43 +73,44 @@
 
       /* BASIC MANIPULATION */
       /** \param toadd the server to add.
-       * 
+       *
        * Add server to the game server list
        */
       int addServer( packet::ServerInformation toadd,
         ENetPeer *peer );
 
       /** \param name Name of the server to remove
-       * 
-       * Remove server by name 
+       *
+       * Remove server by name
        */
       bool delServerByName( std::string name );
 
       /** \param address IP address of the server to remove
-       * 
+       *
        * Remove server by address
        */
       bool delServerByAddress( std::string address );
 
+      bool setNameByAddress( std::string address, std::string name  );
 
+      bool setClientsByAddress( std::string address, int clientNumber );
 
-
       /* SEARCHING */
-      /* \param address The address of the server that is to be 
+      /* \param address The address of the server that is to be
        *  found
        * \return A struct containing a result of the search and a boolean
        *  that is only true if the search was successful
-       * 
+       *
        * Find and return the list handle of a given address.
        */
       ServerListSearchResult
       findServerByAddress( std::string address );
 
 
-      /* \param name The name of the server that is to be 
+      /* \param name The name of the server that is to be
        *  found
        * \return The struct containing the list entry of the server
-       * 
+       *
        * Find and return the list handle of a given name.
        */
       ServerListSearchResult
@@ -119,7 +120,7 @@
       /* SORTING */
       /** sort by name  */
       void sortByName();
-      
+
       /** sort by ping */
       void sortByPing();
 

Modified: code/branches/presentationFS15/src/libraries/network/WANDiscoverable.cc
===================================================================
--- code/branches/presentationFS15/src/libraries/network/WANDiscoverable.cc	2015-05-27 08:21:55 UTC (rev 10496)
+++ code/branches/presentationFS15/src/libraries/network/WANDiscoverable.cc	2015-05-27 08:45:56 UTC (rev 10497)
@@ -43,35 +43,35 @@
   {
     /* debugging output */
     orxout(verbose, context::master_server) << "Creating WANDiscoverable." << endl;
-  
+
     /* register object in orxonox */
     RegisterObject(WANDiscoverable);
 
     /* check for the masterserver address option in orxonox.ini */
     this->setConfigValues();
-    
+
   }
 
   void WANDiscoverable::setConfigValues()
   {
-    /* update msaddress string from orxonox.ini config file, if it 
-     * has changed. 
+    /* update msaddress string from orxonox.ini config file, if it
+     * has changed.
      */
-    SetConfigValueExternal(msaddress, "WANDiscovery", "msaddress", "orxonox.net");
-//     SetConfigValue( msaddress, "orxonox.net");
-  } 
+    SetConfigValueExternal(msaddress, "Discovery", "msaddress", "orxonox.net");
+    SetConfigValueExternal(ownName, "Discovery", "ownName", "OrxServer");
+  }
 
   WANDiscoverable::~WANDiscoverable()
   {
     if( this->bActive_ )
       this->disconnect();
   }
-  
+
   void WANDiscoverable::setActivity(bool bActive)
   {
     if( bActive==this->bActive_ )
       return;
-    
+
     if( bActive )
     {
       if( this->connect() )
@@ -83,7 +83,7 @@
       this->bActive_ = false;
     }
   }
-  
+
   bool WANDiscoverable::connect()
   {
     /* initialize it and see if it worked */
@@ -92,22 +92,25 @@
       orxout(internal_error, context::master_server) << "Could not initialize master server communications!" << endl;
       return false;
     }
-    
+
     /* connect and see if it worked */
     if( msc.connect( this->msaddress.c_str(), ORX_MSERVER_PORT ) )
     {
-      orxout(internal_error, context::master_server) << "Could not connect to master server at " 
+      orxout(internal_error, context::master_server) << "Could not connect to master server at "
                  << this->msaddress << endl;
       return false;
     }
-                 
+
     /* debugging output */
     orxout(verbose, context::master_server) << "Initialization of WANDiscoverable complete." << endl;
-    
-    
+
     // Now register the server at the master server
     this->msc.sendRequest( MSPROTO_GAME_SERVER " " MSPROTO_REGISTER_SERVER );
-    
+
+    std::string request = MSPROTO_GAME_SERVER " " MSPROTO_SET_NAME " ";
+    request += this->ownName;
+    this->msc.sendRequest( request );
+
     return true;
   }
 
@@ -117,7 +120,16 @@
     msc.disconnect();
   }
 
+  void WANDiscoverable::updateClientNumber(int clientNumber)
+  {
+    orxout(verbose, context::master_server) << "Sending new number of clients: " << clientNumber << endl;
+    std::string request = MSPROTO_GAME_SERVER " " MSPROTO_SET_CLIENTS " ";
+    request += Ogre::StringConverter::toString(clientNumber);
 
+    this->msc.sendRequest( request );
+  }
 
-  
+
+
+
 } // namespace orxonox

Modified: code/branches/presentationFS15/src/libraries/network/WANDiscoverable.h
===================================================================
--- code/branches/presentationFS15/src/libraries/network/WANDiscoverable.h	2015-05-27 08:21:55 UTC (rev 10496)
+++ code/branches/presentationFS15/src/libraries/network/WANDiscoverable.h	2015-05-27 08:45:56 UTC (rev 10497)
@@ -31,6 +31,7 @@
 #include "NetworkPrereqs.h"
 #include "core/config/Configurable.h"
 #include "MasterServerComm.h"
+#include <OgreStringConverter.h>
 
 namespace orxonox
 {
@@ -45,30 +46,33 @@
       ~WANDiscoverable();
 
       /** \return Address of the master server
-       * 
-       * Get the master server address 
+       *
+       * Get the master server address
        */
       std::string getMSAddress()
       { return this->msaddress; }
 
       /** Function used for the configuration file parameter update */
       void setConfigValues();
-      
+
       /** Function used to set the activity/discoverability */
       void setActivity( bool bActive );
 
+      void updateClientNumber(int clientNumber);
+
       /** Master server communications object */
       MasterServerComm msc;
-      
+
     private:
       /** Function used to connect to the master server */
       bool connect();
-      
+
       /** Function used to disconnect from the master server */
       void disconnect();
-      
+
       /** master server address */
       std::string msaddress;
+      std::string ownName;
       bool        bActive_;
 
   };

Modified: code/branches/presentationFS15/src/libraries/network/WANDiscovery.cc
===================================================================
--- code/branches/presentationFS15/src/libraries/network/WANDiscovery.cc	2015-05-27 08:21:55 UTC (rev 10496)
+++ code/branches/presentationFS15/src/libraries/network/WANDiscovery.cc	2015-05-27 08:45:56 UTC (rev 10497)
@@ -40,7 +40,7 @@
   {
     /* debugging output */
     orxout(verbose, context::master_server) << "Creating WANDiscovery." << endl;
-  
+
     /* register object in orxonox */
     RegisterObject(WANDiscovery);
 
@@ -53,7 +53,7 @@
 
     /* connect and see if it worked */
     if( msc.connect( this->msaddress.c_str(), ORX_MSERVER_PORT ) )
-      orxout(internal_error, context::master_server) << "Could not connect to master server at " 
+      orxout(internal_error, context::master_server) << "Could not connect to master server at "
         << this->msaddress << endl;
 
     /* debugging output */
@@ -62,21 +62,21 @@
 
   void WANDiscovery::setConfigValues()
   {
-    /* update msaddress string from orxonox.ini config file, if it 
-     * has changed. 
+    /* update msaddress string from orxonox.ini config file, if it
+     * has changed.
      */
     SetConfigValue( msaddress, "master.orxonox.net");
-  } 
+  }
 
   WANDiscovery::~WANDiscovery()
-  { 
+  {
     /* clear server list */
-    this->servers_.clear();  
+    this->servers_.clear();
   }
 
   /* callback for the network reply poller */
   int WANDiscovery::rhandler( char *addr, ENetEvent *ev )
-  { 
+  {
     /* error recognition */
     if( !ev || !ev->packet || !ev->packet->data )
     { orxout(internal_warning, context::master_server) << "Bad arguments received in WANDiscovery's reply handler." << endl;
@@ -87,33 +87,37 @@
     /* if a list entry arrives add to list */
     if( !strncmp( (char*)ev->packet->data, MSPROTO_SERVERLIST_ITEM,
       MSPROTO_SERVERLIST_ITEM_LEN ) )
-    { 
+    {
       /* create server structure from that item */
       packet::ServerInformation toadd;
 
       /* fill in data, -1 for the index: index should be length -1 */
-      toadd.setServerName( std::string((char*)ev->packet->data + 
-        MSPROTO_SERVERLIST_ITEM_LEN+1) );
-      toadd.setServerIP( std::string((char*)ev->packet->data + 
-        MSPROTO_SERVERLIST_ITEM_LEN+1) );
+      std::string datastr = std::string((char*)ev->packet->data + MSPROTO_SERVERLIST_ITEM_LEN+1);
+      int separator = datastr.find(" ");
+      toadd.setServerIP(datastr.substr(0,separator));
+      int secondsep = datastr.find(" ", separator + 1);
+      toadd.setServerName(datastr.substr(separator + 1, secondsep - separator - 1));
+      toadd.setClientNumber(Ogre::StringConverter::parseInt(datastr.substr(secondsep+1)));
 
+      orxout(internal_info, context::network) << "Received WAN discovery server information; Name: " << toadd.getServerName() << ", Address: " << toadd.getServerIP() << ", Players: " << toadd.getClientNumber() << ", RTT: " << toadd.getServerRTT() << endl;
+
       /* add to list */
       this->servers_.push_back( toadd );
     }
     else if( !strncmp( (char*)ev->packet->data, MSPROTO_SERVERLIST_END,
       MSPROTO_SERVERLIST_END_LEN ) )
-    { 
+    {
       /* this is the only case where 2 should be returned,
        * as 1 is used to signal that we're done receiving
        * the list
        */
-      return 2; 
+      return 2;
     }
 
     /* done handling, return all ok code 0 */
     return 1;
   }
- 
+
   void WANDiscovery::discover()
   {
     /* clear list */
@@ -130,7 +134,7 @@
       switch( this->msc.pollForReply( this, 500 ) )
       { case 0: /* no event occured, decrease timeout */
           --i; break;
-        case 1: /* got a list element, continue */ 
+        case 1: /* got a list element, continue */
           break;
         case 2: /* done. */
           i = 0; break;
@@ -158,5 +162,24 @@
       return this->servers_[index].getServerIP();
   }
 
+  std::string WANDiscovery::getServerListItemRTT(unsigned int index)
+ 	{
+    if( index >= this->servers_.size() )
+      return BLANKSTRING;
+    else{
+      uint32_t serverrtt = this->servers_[index].getServerRTT();
+      return Ogre::StringConverter::toString(serverrtt);
+    }
 
+  }
+  std::string WANDiscovery::getServerListItemPlayerNumber(unsigned int index)
+  {
+    if( index >= this->servers_.size() )
+      return BLANKSTRING;
+    else{
+      int playerNumber = this->servers_[index].getClientNumber();
+      return Ogre::StringConverter::toString(playerNumber);
+    }
+  }
+
 } // namespace orxonox

Modified: code/branches/presentationFS15/src/libraries/network/WANDiscovery.h
===================================================================
--- code/branches/presentationFS15/src/libraries/network/WANDiscovery.h	2015-05-27 08:21:55 UTC (rev 10496)
+++ code/branches/presentationFS15/src/libraries/network/WANDiscovery.h	2015-05-27 08:45:56 UTC (rev 10497)
@@ -34,6 +34,7 @@
 #include "core/config/ConfigValueIncludes.h"
 #include "MasterServerComm.h"
 #include "MasterServerProtocol.h"
+#include <OgreStringConverter.h>
 
 #include <vector>
 
@@ -55,8 +56,8 @@
       ~WANDiscovery();
 
       /** \return Address of the master server
-       * 
-       * Get the master server address 
+       *
+       * Get the master server address
        */
       std::string getMSAddress()
       { return this->msaddress; }
@@ -64,22 +65,36 @@
       /** ask server for server list  */
       void discover(); // tolua_export
 
-      /** \param index Index to get the name of 
+      /** \param index Index to get the name of
        * \return The name of the server
-       * 
-       * Get the name of the server at index index. 
+       *
+       * Get the name of the server at index index.
        */
       std::string getServerListItemName( unsigned int index ); // tolua_export
 
-      /** \param index Index to get the IP of 
+      /** \param index Index to get the IP of
        * \return The IP of the server
-       * 
-       * Get the IP of the server at index index. 
+       *
+       * Get the IP of the server at index index.
        */
       std::string getServerListItemIP( unsigned int index ); // tolua_export
 
+      /** \param index Index to get the RTT of
+       * \return The RTT of the server
+       *
+       * Get the RTT of the server at index index.
+       */
+      std::string getServerListItemRTT( unsigned int index ); // tolua_export
+
+      /** \param index Index to get the RTT of
+       * \return The number of players on the server
+       *
+       * Get the number of players on the server
+       */
+      std::string getServerListItemPlayerNumber( unsigned int index ); // tolua_export
+
       /* todo: might make this private and use getter/setter methods
-       * at some later time. 
+       * at some later time.
        */
       /** game server list */
       std::vector<packet::ServerInformation> servers_;
@@ -91,7 +106,7 @@
       MasterServerComm msc;
 
       int rhandler( char *addr, ENetEvent *ev );
-      
+
     private:
       /** master server address */
       std::string msaddress;

Modified: code/branches/presentationFS15/src/libraries/network/packet/ServerInformation.cc
===================================================================
--- code/branches/presentationFS15/src/libraries/network/packet/ServerInformation.cc	2015-05-27 08:21:55 UTC (rev 10496)
+++ code/branches/presentationFS15/src/libraries/network/packet/ServerInformation.cc	2015-05-27 08:45:56 UTC (rev 10497)
@@ -38,12 +38,11 @@
 {
   namespace packet
   {
-    
+
     ServerInformation::ServerInformation()
     {
-      
     }
-    
+
     ServerInformation::ServerInformation(ENetEvent* event)
     {
       char serverIP[64];
@@ -68,22 +67,23 @@
 
     ServerInformation::~ServerInformation()
     {
-      
+
     }
 
     void ServerInformation::send(ENetPeer* peer)
     {
-      uint32_t size = returnSize((char*&)LAN_DISCOVERY_ACK) + returnSize(this->serverName_);
+      std::string payload = this->serverName_ + Ogre::StringConverter::toString(this->clientNumber_);
+      uint32_t size = returnSize((char*&)LAN_DISCOVERY_ACK) + returnSize(payload);
       uint8_t* temp = new uint8_t[size];
       uint8_t* temp2 = temp;
       saveAndIncrease((char*&)LAN_DISCOVERY_ACK, temp2);
-      saveAndIncrease(this->serverName_, temp2);
+      saveAndIncrease(payload, temp2);
       ENetPacket* packet = enet_packet_create( temp, size, 0 );
       enet_peer_send(peer, 0, packet);
-      
+
       delete[] temp;
     }
-  
+
   } // namespace packet
 
   std::ostream& operator<<(std::ostream& out, const ENetAddress& address)
@@ -94,4 +94,3 @@
       return out;
   }
 } // namespace orxonox
-

Modified: code/branches/presentationFS15/src/libraries/network/packet/ServerInformation.h
===================================================================
--- code/branches/presentationFS15/src/libraries/network/packet/ServerInformation.h	2015-05-27 08:21:55 UTC (rev 10496)
+++ code/branches/presentationFS15/src/libraries/network/packet/ServerInformation.h	2015-05-27 08:45:56 UTC (rev 10497)
@@ -29,7 +29,9 @@
 #include "../NetworkPrereqs.h"
 
 #include <string>
+#include <OgreStringConverter.h>
 
+
 #ifndef SERVERINFORMATION_H
 #define SERVERINFORMATION_H
 
@@ -44,16 +46,19 @@
         ServerInformation();
         ServerInformation(ENetEvent* event);
         ~ServerInformation();
-        
+
         void          send( ENetPeer* peer );
-        std::string   getServerIP() { return this->serverIP_; }
+        void          setServerName(std::string name) { this->serverName_ = name; }
         std::string   getServerName() { return this->serverName_; }
-        void          setServerName(std::string name) { this->serverName_ = name; }
         void          setServerIP( std::string IP ) { this->serverIP_ = IP; }
+        std::string   getServerIP() { return this->serverIP_; }
+        void          setClientNumber( int clientNumber ) { this->clientNumber_ = clientNumber; }
+        int           getClientNumber() { return this->clientNumber_; }
         uint32_t      getServerRTT() { return this->serverRTT_; }
-        
+
       private:
         std::string   serverName_;
+        int           clientNumber_;
         std::string   serverIP_;
         uint32_t      serverRTT_;
     };




More information about the Orxonox-commit mailing list