[Orxonox-commit 4161] r8832 - in code/branches/output: data/gui/scripts src/libraries/network

landauf at orxonox.net landauf at orxonox.net
Tue Aug 9 00:37:21 CEST 2011


Author: landauf
Date: 2011-08-09 00:37:21 +0200 (Tue, 09 Aug 2011)
New Revision: 8832

Modified:
   code/branches/output/data/gui/scripts/MultiplayerMenu.lua
   code/branches/output/src/libraries/network/MasterServerComm.cc
   code/branches/output/src/libraries/network/MasterServerComm.h
   code/branches/output/src/libraries/network/NetworkPrereqs.h
   code/branches/output/src/libraries/network/Server.cc
   code/branches/output/src/libraries/network/Server.h
   code/branches/output/src/libraries/network/WANDiscovery.cc
   code/branches/output/src/libraries/network/WANDiscovery.h
Log:
Quick and dirty fix to un-singletonize WANDiscovery. It is now created on demand by the multiplayer menu. This delays the master server connection until we really need it (and avoids the annoying connection-failed error/warning during startup if the master server can't be reached).
Also removed some unneeded/commented functions related to WANDiscovery from Server.
Presumably won't collide with the changes in the masterserver2 branch, but needs some review.

Modified: code/branches/output/data/gui/scripts/MultiplayerMenu.lua
===================================================================
--- code/branches/output/data/gui/scripts/MultiplayerMenu.lua	2011-08-08 20:19:09 UTC (rev 8831)
+++ code/branches/output/data/gui/scripts/MultiplayerMenu.lua	2011-08-08 22:37:21 UTC (rev 8832)
@@ -116,7 +116,7 @@
     elseif P.joinMode == 2 then
         local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
         CEGUI.toListbox(listbox):resetList()
-        local discovery = orxonox.WANDiscovery:getInstance()
+        local discovery = orxonox.WANDiscovery()
         cout(0, "discovering.\n" )
         discovery:discover()
         cout(0, "discovered.\n" )

Modified: code/branches/output/src/libraries/network/MasterServerComm.cc
===================================================================
--- code/branches/output/src/libraries/network/MasterServerComm.cc	2011-08-08 20:19:09 UTC (rev 8831)
+++ code/branches/output/src/libraries/network/MasterServerComm.cc	2011-08-08 22:37:21 UTC (rev 8832)
@@ -28,6 +28,7 @@
 
 #include "MasterServerComm.h"
 #include "util/Output.h"
+#include "WANDiscovery.h"
 
 namespace orxonox
 {
@@ -148,8 +149,7 @@
    * - the event
    * so we can also make callbacks from objects
    */
-  int MasterServerComm::pollForReply( int (*callback)( char*, ENetEvent* ),
-    int delayms )
+  int MasterServerComm::pollForReply( WANDiscovery* listener, int delayms )
   { 
     /* see whether anything happened */
     /* WORK MARK REMOVE THIS OUTPUT */
@@ -192,8 +192,8 @@
           /* END DEBUG */
 
           /* call the supplied callback, if any. */
-          if( (*callback) != NULL )
-            retval = (*callback)( addrconv, &(this->event) );
+          if( listener != NULL )
+            retval = listener->rhandler( addrconv, &(this->event) );
 
           /* clean up */
           enet_packet_destroy( event.packet );

Modified: code/branches/output/src/libraries/network/MasterServerComm.h
===================================================================
--- code/branches/output/src/libraries/network/MasterServerComm.h	2011-08-08 20:19:09 UTC (rev 8831)
+++ code/branches/output/src/libraries/network/MasterServerComm.h	2011-08-08 22:37:21 UTC (rev 8832)
@@ -92,7 +92,7 @@
        * \return 0 for success, other for error
        * 
        * Poll the master server for new data and act accordingly */
-      int pollForReply( int (*callback)( char*, ENetEvent* ), int delayms );
+      int pollForReply( WANDiscovery* listener, int delayms );
 
     private:
       /** client handle */

Modified: code/branches/output/src/libraries/network/NetworkPrereqs.h
===================================================================
--- code/branches/output/src/libraries/network/NetworkPrereqs.h	2011-08-08 20:19:09 UTC (rev 8831)
+++ code/branches/output/src/libraries/network/NetworkPrereqs.h	2011-08-08 22:37:21 UTC (rev 8832)
@@ -128,6 +128,8 @@
   class GamestateHandler;
   class GamestateManager;
   class Host;
+  class MasterServer;
+  class MasterServerComm;
   class NetworkChatListener;
   class NetworkFunctionBase;
   struct NetworkFunctionPointer;
@@ -135,9 +137,12 @@
   template <class T>
   class NetworkMemberFunction;
   class NetworkMemberFunctionBase;
+  class PeerList;
   class Server;
   class ServerConnection;
   class TrafficControl;
+  class WANDiscoverable;
+  class WANDiscovery;
 
   // packet
   namespace packet

Modified: code/branches/output/src/libraries/network/Server.cc
===================================================================
--- code/branches/output/src/libraries/network/Server.cc	2011-08-08 20:19:09 UTC (rev 8831)
+++ code/branches/output/src/libraries/network/Server.cc	2011-08-08 22:37:21 UTC (rev 8832)
@@ -58,7 +58,6 @@
 // #include "ClientInformation.h"
 #include "FunctionCallManager.h"
 #include "GamestateManager.h"
-#include "WANDiscovery.h"
 
 namespace orxonox
 {
@@ -98,14 +97,6 @@
   {
   }
 
-
-  /** helper that connects to the master server */
-  void Server::helper_ConnectToMasterserver()
-  {
-//     WANDiscovery::getInstance().msc.sendRequest( MSPROTO_GAME_SERVER " "
-//       MSPROTO_REGISTER_SERVER );
-  }
-
   /**
   * This function opens the server by creating the listener thread
   */
@@ -120,10 +111,6 @@
 
     /* make discoverable on WAN */
     WANDiscoverable::setActivity(true);
-    /* TODO this needs to be optional, we need a switch from the UI to
-     * enable/disable this
-     */
-//     helper_ConnectToMasterserver();
 
     /* done */
     return;
@@ -148,30 +135,6 @@
     return;
   }
 
-  /* handle incoming data */
-  int rephandler( char *addr, ENetEvent *ev )
-  {
-    /* reply to pings */
-    if( !strncmp( (char *)ev->packet->data, MSPROTO_PING_GAMESERVER,
-      MSPROTO_PING_GAMESERVER_LEN ) )
-      //this->msc.sendRequest( MSPROTO_ACK );
-      /* NOTE implement this after pollForReply
-       * reimplementation
-       */
-      return 0;
-
-    /* done handling, return all ok code 0 */
-    return 0;
-  }
-
-  void Server::helper_HandleMasterServerRequests()
-  {
-    /* poll the master server for replies and see whether something
-     * has to be done or changed.
-     */
-    //WANDiscovery::getInstance().msc.pollForReply( rhandler, 10 );
-  }
-
   /**
   * Run this function once every tick
   * calls processQueue and updateGamestate
@@ -185,10 +148,6 @@
     // receive and process incoming discovery packets
     LANDiscoverable::update();
 
-    // receive and process requests from master server
-    /* todo */
-    //helper_HandleMasterServerRequests();
-
     if ( GamestateManager::hasPeers() )
     {
       // process incoming gamestates

Modified: code/branches/output/src/libraries/network/Server.h
===================================================================
--- code/branches/output/src/libraries/network/Server.h	2011-08-08 20:19:09 UTC (rev 8831)
+++ code/branches/output/src/libraries/network/Server.h	2011-08-08 22:37:21 UTC (rev 8832)
@@ -41,8 +41,6 @@
 #include "ServerConnection.h"
 #include "LANDiscoverable.h"
 #include "WANDiscoverable.h"
-// #include "MasterServerComm.h"
-// #include "MasterServerProtocol.h"
 
 
 namespace orxonox
@@ -60,11 +58,6 @@
     Server(int port, const std::string& bindAddress);
     ~Server();
 
-    /* helpers */
-    void helper_ConnectToMasterserver();
-    void helper_HandleMasterServerRequests();
-    int replyhandler( char *addr, ENetEvent *ev );
-
     void open();
     void close();
     void queuePacket(ENetPacket *packet, int clientID, uint8_t channelID);

Modified: code/branches/output/src/libraries/network/WANDiscovery.cc
===================================================================
--- code/branches/output/src/libraries/network/WANDiscovery.cc	2011-08-08 20:19:09 UTC (rev 8831)
+++ code/branches/output/src/libraries/network/WANDiscovery.cc	2011-08-08 22:37:21 UTC (rev 8832)
@@ -31,15 +31,11 @@
 #include <enet/enet.h>
 #include <cstring>
 
-#include "util/ScopedSingletonManager.h"
 #include "core/CoreIncludes.h"
 
 
 namespace orxonox
 {
-  ManageScopedSingleton(WANDiscovery, ScopeID::Graphics, true);
-
-
   WANDiscovery::WANDiscovery()
   {
     /* debugging output */
@@ -79,7 +75,7 @@
   }
 
   /* callback for the network reply poller */
-  int rhandler( char *addr, ENetEvent *ev )
+  int WANDiscovery::rhandler( char *addr, ENetEvent *ev )
   { 
     /* error recognition */
     if( !ev || !ev->packet || !ev->packet->data )
@@ -102,7 +98,7 @@
         MSPROTO_SERVERLIST_ITEM_LEN+1) );
 
       /* add to list */
-      WANDiscovery::getInstance().servers_.push_back( toadd );
+      this->servers_.push_back( toadd );
     }
     else if( !strncmp( (char*)ev->packet->data, MSPROTO_SERVERLIST_END,
       MSPROTO_SERVERLIST_END_LEN ) )
@@ -131,7 +127,7 @@
     while( i > 0 )
     {
       /* poll for reply and act according to what was received */
-      switch( this->msc.pollForReply( rhandler, 500 ) )
+      switch( this->msc.pollForReply( this, 500 ) )
       { case 0: /* no event occured, decrease timeout */
           --i; break;
         case 1: /* got a list element, continue */ 

Modified: code/branches/output/src/libraries/network/WANDiscovery.h
===================================================================
--- code/branches/output/src/libraries/network/WANDiscovery.h	2011-08-08 20:19:09 UTC (rev 8831)
+++ code/branches/output/src/libraries/network/WANDiscovery.h	2011-08-08 22:37:21 UTC (rev 8832)
@@ -31,7 +31,6 @@
 #include "NetworkPrereqs.h"
 #include "packet/ServerInformation.h"
 #include "core/ConfigFileManager.h"
-#include "util/Singleton.h"
 #include "core/OrxonoxClass.h"
 #include "core/ConfigValueIncludes.h"
 #include "core/CoreIncludes.h"
@@ -48,12 +47,11 @@
 
   class _NetworkExport WANDiscovery
 // tolua_end
-    : public Singleton<WANDiscovery>, public OrxonoxClass
+    : public OrxonoxClass
   { // tolua_export
-    friend class Singleton<WANDiscovery>;
     public:
       /** constructor */
-      WANDiscovery();
+      WANDiscovery(); // tolua_export
 
       /** destructor */
       ~WANDiscovery();
@@ -82,12 +80,6 @@
        */
       std::string getServerListItemIP( unsigned int index ); // tolua_export
 
-      /** \return an instance of WANDiscovery
-       * 
-       * Create and return an instance of WANDiscovery.
-       */
-      static WANDiscovery& getInstance() { return Singleton<WANDiscovery>::getInstance(); } // tolua_export
-    
       /* todo: might make this private and use getter/setter methods
        * at some later time. 
        */
@@ -99,11 +91,10 @@
 
       /** Master server communications object */
       MasterServerComm msc;
+
+      int rhandler( char *addr, ENetEvent *ev );
       
     private:
-      /** Singleton pointer */
-      static WANDiscovery* singletonPtr_s;
-
       /** master server address */
       std::string msaddress;
 




More information about the Orxonox-commit mailing list