[Orxonox-commit 2958] r7657 - in code/branches/masterserver/src: libraries/network modules/masterserver orxonox

smerkli at orxonox.net smerkli at orxonox.net
Wed Nov 24 14:07:54 CET 2010


Author: smerkli
Date: 2010-11-24 14:07:53 +0100 (Wed, 24 Nov 2010)
New Revision: 7657

Modified:
   code/branches/masterserver/src/libraries/network/MasterServerProtocol.h
   code/branches/masterserver/src/libraries/network/WANDiscovery.cc
   code/branches/masterserver/src/libraries/network/WANDiscovery.h
   code/branches/masterserver/src/modules/masterserver/MasterServer.cc
   code/branches/masterserver/src/modules/masterserver/MasterServer.h
   code/branches/masterserver/src/modules/masterserver/ServerList.cc
   code/branches/masterserver/src/modules/masterserver/ServerList.h
   code/branches/masterserver/src/orxonox/Main.cc
Log:
it has compiled.

Modified: code/branches/masterserver/src/libraries/network/MasterServerProtocol.h
===================================================================
--- code/branches/masterserver/src/libraries/network/MasterServerProtocol.h	2010-11-18 21:40:06 UTC (rev 7656)
+++ code/branches/masterserver/src/libraries/network/MasterServerProtocol.h	2010-11-24 13:07:53 UTC (rev 7657)
@@ -36,6 +36,7 @@
 #define MSPROTO_CLIENT_LEN 2 
 
 #define MSPROTO_REQ_LIST "REQ:LIST"
+#define MSPROTO_REQ_LIST_LEN 8
 
 
 

Modified: code/branches/masterserver/src/libraries/network/WANDiscovery.cc
===================================================================
--- code/branches/masterserver/src/libraries/network/WANDiscovery.cc	2010-11-18 21:40:06 UTC (rev 7656)
+++ code/branches/masterserver/src/libraries/network/WANDiscovery.cc	2010-11-24 13:07:53 UTC (rev 7657)
@@ -61,10 +61,14 @@
   }
 
   /* callback for the network reply poller */
-  /* WORK MARK WORK WORK */
-  /* NOTE implement protocol-specific part here. */
-  int WANDiscovery::rhandler( char *addr, ENetEvent *ev )
+  int rhandler( char *addr, ENetEvent *ev )
   { 
+    /* error recognition */
+    if( !ev || !ev->packet || !ev->packet->data )
+    { COUT(2) << "Bad arguments received in WANDiscovery's reply handler.\n";
+      return 0;
+    }
+
     /* handle incoming data */
     /* if a list entry arrives add to list */
     if( !strncmp( (char*)ev->packet->data, MSPROTO_SERVERLIST_ITEM,
@@ -80,7 +84,7 @@
         MSPROTO_SERVERLIST_ITEM_LEN) );
 
       /* add to list */
-      this->servers_.push_back( toadd );
+      WANDiscovery::getInstance().servers_.push_back( toadd );
     }
     else if( !strncmp( (char*)ev->packet->data, MSPROTO_SERVERLIST_END,
       MSPROTO_SERVERLIST_END_LEN ) )
@@ -96,10 +100,10 @@
     this->servers_.clear();
 
     /* send request to server */
-    msc.sendRequest( MSPROTO_CLIENT " " MSPROTO_REQ_LIST );
+    this->msc.sendRequest( MSPROTO_CLIENT " " MSPROTO_REQ_LIST );
 
     /* deal with replies */
-    while( !msc.pollForReply( WANDiscovery::rhandler ) ) 
+    while( !(this->msc).pollForReply( rhandler ) )
       /* nothing */;
 
     /* done receiving. */

Modified: code/branches/masterserver/src/libraries/network/WANDiscovery.h
===================================================================
--- code/branches/masterserver/src/libraries/network/WANDiscovery.h	2010-11-18 21:40:06 UTC (rev 7656)
+++ code/branches/masterserver/src/libraries/network/WANDiscovery.h	2010-11-24 13:07:53 UTC (rev 7657)
@@ -77,7 +77,8 @@
        */
       static WANDiscovery& getInstance() { return Singleton<WANDiscovery>::getInstance(); } // tolua_export
     
-      int rhandler( char *addr, ENetEvent *ev );
+      /** game server list */
+      std::vector<packet::ServerInformation> servers_;
       
     private:
       /** Singleton pointer */
@@ -86,9 +87,6 @@
       /** Master server communications object */
       MasterServerComm msc;
 
-      /** game server list */
-      std::vector<packet::ServerInformation> servers_;
-
   }; // tolua_export
 
 } // tolua_export

Modified: code/branches/masterserver/src/modules/masterserver/MasterServer.cc
===================================================================
--- code/branches/masterserver/src/modules/masterserver/MasterServer.cc	2010-11-18 21:40:06 UTC (rev 7656)
+++ code/branches/masterserver/src/modules/masterserver/MasterServer.cc	2010-11-24 13:07:53 UTC (rev 7657)
@@ -79,7 +79,7 @@
     std::string name = std::string( (char*)event->peer->data );
 
     /* remove the server from the list it belongs to */
-    this->mainlist->delServerByName( name );
+    this->mainlist.delServerByName( name );
 
     /* Reset the peer's client information. */
     if( event->peer->data ) free( event->peer->data );
@@ -140,7 +140,7 @@
         + MSPROTO_GAME_SERVER_LEN+1, 
         MSPROTO_REGISTER_SERVER, MSPROTO_REGISTER_SERVER_LEN ) )
       { /* register new server */
-        mainlist->addServer( packet::ServerInformation( event ) );
+        mainlist.addServer( packet::ServerInformation( event ) );
       }
     }
     else if( !strncmp( (char *)event->packet->data, MSPROTO_CLIENT, 
@@ -148,20 +148,20 @@
     { /* client */
       
       if( !strncmp( (char *)event->packet->data + MSPROTO_CLIENT_LEN+1,
-        MSPROTO_REQ_LIST ) )
+        MSPROTO_REQ_LIST, MSPROTO_REQ_LIST_LEN ) )
       { /* send server list */
         
         /* get an iterator */
-        std::list<packet::ServerInformation *>::iterator i;
+        std::list<packet::ServerInformation>::iterator i;
 
         /* loop through list elements */
-        for( i = serverlist.begin(); i != serverlist.end(); ++i ) 
+        for( i = mainlist.serverlist.begin(); i != mainlist.serverlist.end(); ++i ) 
         {
           /* WORK MARK */
           /* send this particular server */
           /* build reply string */
-          char *tosend = (char *)calloc( (*i)->getServerIP().length() + 1,1 );
-          snprintf( "%s %s", MSPROTO_SERVERLIST_ITEM, (*i)->getServerIP() );
+          char *tosend = (char *)calloc( (*i).getServerIP().length() + MSPROTO_SERVERLIST_ITEM_LEN + 2,1 );
+          sprintf( "%s %s", MSPROTO_SERVERLIST_ITEM, (*i).getServerIP().c_str() );
 
           /* create packet from it */
           ENetPacket * reply = enet_packet_create( tosend,
@@ -257,12 +257,12 @@
     }
 
     /***** INITIALIZE GAME SERVER AND PEER LISTS *****/
-    this->mainlist = new ServerList();
+    //this->mainlist = new ServerList();
     this->peers = new PeerList();
-    if( this->mainlist == NULL || this->peers == NULL )
-    { COUT(1) << "Error creating server or peer list.\n";
-      exit( EXIT_FAILURE );
-    }
+    //if( this->mainlist == NULL || this->peers == NULL )
+    //{ COUT(1) << "Error creating server or peer list.\n";
+      //exit( EXIT_FAILURE );
+    //}
 
     /* run the main method */
     run();

Modified: code/branches/masterserver/src/modules/masterserver/MasterServer.h
===================================================================
--- code/branches/masterserver/src/modules/masterserver/MasterServer.h	2010-11-18 21:40:06 UTC (rev 7656)
+++ code/branches/masterserver/src/modules/masterserver/MasterServer.h	2010-11-24 13:07:53 UTC (rev 7657)
@@ -72,7 +72,7 @@
       /* members */
       ENetAddress address;
       ENetHost *server;
-      ServerList *mainlist;
+      ServerList mainlist;
       PeerList *peers;
 
       /* main routine */

Modified: code/branches/masterserver/src/modules/masterserver/ServerList.cc
===================================================================
--- code/branches/masterserver/src/modules/masterserver/ServerList.cc	2010-11-18 21:40:06 UTC (rev 7656)
+++ code/branches/masterserver/src/modules/masterserver/ServerList.cc	2010-11-24 13:07:53 UTC (rev 7657)
@@ -39,7 +39,7 @@
   }
 
   int 
-  ServerList::addServer( packet::ServerInformation *toadd )
+  ServerList::addServer( packet::ServerInformation toadd )
   { this->serverlist.push_back( toadd ); 
     return 0;
   }
@@ -48,13 +48,13 @@
   ServerList::delServerByName( std::string name )
   { 
     /* get an iterator */
-    std::list<packet::ServerInformation *>::iterator i;
+    std::list<packet::ServerInformation>::iterator i;
 
     /* loop through list elements */
     for( i = serverlist.begin(); i != serverlist.end(); ++i ) 
-      if( (*i)->getServerName() == name )
+      if( (*i).getServerName() == name )
       { /* found this name, remove and quit */
-        this->serverlist.remove( *i );
+        this->serverlist.erase( i );
         return true;
       }
     return false;
@@ -63,13 +63,13 @@
   bool ServerList::delServerByAddress( std::string address )
   { 
     /* get an iterator */
-    std::list<packet::ServerInformation *>::iterator i;
+    std::list<packet::ServerInformation>::iterator i;
 
     /* loop through list elements */
     for( i=serverlist.begin(); i != serverlist.end(); ++i ) 
-      if( (*i)->getServerIP() == address )
+      if( (*i).getServerIP() == address )
       { /* found this name, remove and quit */
-        this->serverlist.remove( *i );
+        this->serverlist.erase( i );
         return true;
       }
     return false;
@@ -77,9 +77,9 @@
 
 
   /* sort by name */
-  bool sub_compare_names( packet::ServerInformation *no1, 
-    packet::ServerInformation *no2 )
-  { return no1->getServerName() > no2->getServerName(); }
+  bool sub_compare_names( packet::ServerInformation no1, 
+    packet::ServerInformation no2 )
+  { return no1.getServerName() > no2.getServerName(); }
 
   void ServerList::sortByName()
   { 
@@ -87,11 +87,11 @@
   }
   
   /* sort by ping */
-  bool sub_compare_pings( packet::ServerInformation *no1, 
-    packet::ServerInformation *no2 )
+  bool sub_compare_pings( packet::ServerInformation no1, 
+    packet::ServerInformation no2 )
   { 
     /* TODO */
-    return no1->getServerName() > no2->getServerName();
+    return no1.getServerName() > no2.getServerName();
   }
 
   void ServerList::sortByPing()

Modified: code/branches/masterserver/src/modules/masterserver/ServerList.h
===================================================================
--- code/branches/masterserver/src/modules/masterserver/ServerList.h	2010-11-18 21:40:06 UTC (rev 7656)
+++ code/branches/masterserver/src/modules/masterserver/ServerList.h	2010-11-24 13:07:53 UTC (rev 7657)
@@ -53,7 +53,7 @@
        * 
        * Add server to the game server list
        */
-      int addServer( packet::ServerInformation *toadd );
+      int addServer( packet::ServerInformation toadd );
 
       /** \param name Name of the server to remove
        * 
@@ -77,7 +77,7 @@
       void sortByPing();
 
       /** the list of servers for internal storage */
-      std::list<packet::ServerInformation *> serverlist;
+      std::list<packet::ServerInformation> serverlist;
     private:
   };
 }

Modified: code/branches/masterserver/src/orxonox/Main.cc
===================================================================
--- code/branches/masterserver/src/orxonox/Main.cc	2010-11-18 21:40:06 UTC (rev 7656)
+++ code/branches/masterserver/src/orxonox/Main.cc	2010-11-24 13:07:53 UTC (rev 7657)
@@ -89,6 +89,8 @@
                 Game::getInstance().requestStates("server, level");
             else if (CommandLineParser::getValue("dedicatedClient").getBool())
                 Game::getInstance().requestStates("client, level");
+            //else if (CommandLineParser::getValue("masterserver").getBool())
+                //Game::getInstance().requestStates("client, level");
             else
             {
                 if (!CommandLineParser::getValue("console").getBool())




More information about the Orxonox-commit mailing list