[Orxonox-commit 3068] r7763 - code/branches/presentation/src/libraries/network

smerkli at orxonox.net smerkli at orxonox.net
Wed Dec 15 14:51:39 CET 2010


Author: smerkli
Date: 2010-12-15 14:51:39 +0100 (Wed, 15 Dec 2010)
New Revision: 7763

Modified:
   code/branches/presentation/src/libraries/network/MasterServer.cc
   code/branches/presentation/src/libraries/network/MasterServerComm.cc
   code/branches/presentation/src/libraries/network/MasterServerComm.h
   code/branches/presentation/src/libraries/network/MasterServerProtocol.h
   code/branches/presentation/src/libraries/network/Server.cc
   code/branches/presentation/src/libraries/network/Server.h
   code/branches/presentation/src/libraries/network/WANDiscovery.cc
   code/branches/presentation/src/libraries/network/WANDiscovery.h
Log:
disconnect implemented, switching to only use the MSC object of wandiscovery.

Modified: code/branches/presentation/src/libraries/network/MasterServer.cc
===================================================================
--- code/branches/presentation/src/libraries/network/MasterServer.cc	2010-12-15 13:05:48 UTC (rev 7762)
+++ code/branches/presentation/src/libraries/network/MasterServer.cc	2010-12-15 13:51:39 UTC (rev 7763)
@@ -185,6 +185,20 @@
           packet::ServerInformation( event ).getServerIP() << "\n";
       }
 
+      else if( !strncmp( (char *)event->packet->data
+        + MSPROTO_GAME_SERVER_LEN+1,
+        MSPROTO_SERVERDC, MSPROTO_SERVERDC_LEN ) )
+      {
+        /* create string from peer data */
+        std::string name = std::string( addrconv );
+
+        /* remove the server from the list it belongs to */
+        this->mainlist.delServerByName( name );
+
+        /* tell the user */
+        COUT(2) << "Removed server " << name << " from list.\n";
+      }
+
       /* TODO add hook for disconnect here */
     }
     else if( !strncmp( (char *)event->packet->data, MSPROTO_CLIENT, 

Modified: code/branches/presentation/src/libraries/network/MasterServerComm.cc
===================================================================
--- code/branches/presentation/src/libraries/network/MasterServerComm.cc	2010-12-15 13:05:48 UTC (rev 7762)
+++ code/branches/presentation/src/libraries/network/MasterServerComm.cc	2010-12-15 13:51:39 UTC (rev 7763)
@@ -40,7 +40,7 @@
   int MasterServerComm::initialize()
   {
     /* initialize Enet */
-    if (enet_initialize () != 0)
+    if( enet_initialize () != 0 )
     { COUT(1) << "An error occurred while initializing ENet.\n";
       return 1;
     }
@@ -58,7 +58,8 @@
 
     /* see if it worked */
     if (this->client == NULL)
-    { COUT(1) << "An error occurred while trying to create an ENet client host.\n";
+    { COUT(1) << "An error occurred while trying to create an " 
+        << "ENet client host.\n";
       return 1;
     }
 
@@ -69,9 +70,6 @@
   {
     /* destroy the enet facilities */
     enet_host_destroy(this->client);
-
-    /* install atexit handler for enet */
-    enet_deinitialize();
   }
 
   int MasterServerComm::connect( const char *address, unsigned int port )
@@ -83,8 +81,9 @@
     /* Initiate the connection, allocating the two channels 0 and 1. */
     this->peer = enet_host_connect(this->client, &this->address, 2, 0);    
 
-    if (this->peer == NULL )
-    { COUT(2) << "ERROR: No available peers for initiating an ENet connection.\n";
+    if( this->peer == NULL )
+    { COUT(2) << "ERROR: No available peers for initiating an ENet"
+        << " connection.\n";
       return -1;
     }
 
@@ -95,7 +94,6 @@
     else
     {
       enet_peer_reset (this->peer);
-      fprintf( stdout, "Connection to %s failed.", address );
       COUT(2) << "ERROR: connection to " << address << " failed.\n";
       return -1;
     }
@@ -239,7 +237,7 @@
 
     /* One could just use enet_host_service() instead. */
     enet_host_flush( this->client );
-    if( packet ) free( packet );
+    enet_packet_destroy( packet );
 
     /* all done. */
     return 0;

Modified: code/branches/presentation/src/libraries/network/MasterServerComm.h
===================================================================
--- code/branches/presentation/src/libraries/network/MasterServerComm.h	2010-12-15 13:05:48 UTC (rev 7762)
+++ code/branches/presentation/src/libraries/network/MasterServerComm.h	2010-12-15 13:51:39 UTC (rev 7763)
@@ -65,7 +65,7 @@
        * 
        * Disconnect from master server.
        */
-      int disconnect();
+      int disconnect( void );
 
       /** \param data The data to be sent. 
        * \return 0 for success, other for error. 

Modified: code/branches/presentation/src/libraries/network/MasterServerProtocol.h
===================================================================
--- code/branches/presentation/src/libraries/network/MasterServerProtocol.h	2010-12-15 13:05:48 UTC (rev 7762)
+++ code/branches/presentation/src/libraries/network/MasterServerProtocol.h	2010-12-15 13:51:39 UTC (rev 7763)
@@ -68,6 +68,10 @@
 #define MSPROTO_PING_GAMESERVER "PING"
 #define MSPROTO_PING_GAMESERVER_LEN 4 
 
+/* server disconnect */
+#define MSPROTO_SERVERDC "DC"
+#define MSPROTO_SERVERDC_LEN 2
+
 /* ping reply */
 #define MSPROTO_ACK "ACK"
 #define MSPROTO_ACK_LEN 3 

Modified: code/branches/presentation/src/libraries/network/Server.cc
===================================================================
--- code/branches/presentation/src/libraries/network/Server.cc	2010-12-15 13:05:48 UTC (rev 7762)
+++ code/branches/presentation/src/libraries/network/Server.cc	2010-12-15 13:51:39 UTC (rev 7763)
@@ -103,21 +103,23 @@
   /** helper that connects to the master server */
   void Server::helper_ConnectToMasterserver()
   {
-    /* initialize it and see if it worked */
-    if( msc.initialize() )
-    { COUT(1) << "Error: could not initialize master server communications!\n";
-      return;
-    }
+    //[> initialize it and see if it worked <]
+    //if( msc.initialize() )
+    //{ COUT(1) << "Error: could not initialize master server communications!\n";
+      //return;
+    //}
 
-    /* connect and see if it worked */
-    if( msc.connect( WANDiscovery::getInstance().getMSAddress().c_str(), 
-      ORX_MSERVER_PORT ) )
-    { COUT(1) << "Error: could not connect to master server!\n";
-      return;
-    }
+    //[> connect and see if it worked <]
+    //if( msc.connect( WANDiscovery::getInstance().getMSAddress().c_str(), 
+      //ORX_MSERVER_PORT ) )
+    //{ COUT(1) << "Error: could not connect to master server!\n";
+      //return;
+    //}
 
     /* now send the master server some note we're here */
-    msc.sendRequest( MSPROTO_GAME_SERVER " " MSPROTO_REGISTER_SERVER );
+    //msc.sendRequest( MSPROTO_GAME_SERVER " " MSPROTO_REGISTER_SERVER );
+    WANDiscovery::getInstance().msc.sendRequest( MSPROTO_GAME_SERVER " " 
+      MSPROTO_REGISTER_SERVER );
   }
 
   /**
@@ -151,9 +153,13 @@
     COUT(4) << "closing server" << endl;
     this->disconnectClients();
     this->closeListener();
+
+    /* tell master server we're closing */
     COUT(2) << "disconnecting." << endl;
-    this->msc.disconnect();
+    WANDiscovery::getInstance().msc.sendRequest( MSPROTO_GAME_SERVER " " 
+      MSPROTO_SERVERDC );
     COUT(2) << "disconnecting done" << endl;
+
     LANDiscoverable::setActivity(false);
     return;
   }
@@ -195,7 +201,7 @@
     /* poll the master server for replies and see whether something 
      * has to be done or changed.
      */
-    this->msc.pollForReply( rephandler, 10 ); 
+    //WANDiscovery::getInstance().msc.pollForReply( rhandler, 10 );
   }
 
   /**

Modified: code/branches/presentation/src/libraries/network/Server.h
===================================================================
--- code/branches/presentation/src/libraries/network/Server.h	2010-12-15 13:05:48 UTC (rev 7762)
+++ code/branches/presentation/src/libraries/network/Server.h	2010-12-15 13:51:39 UTC (rev 7763)
@@ -89,7 +89,7 @@
     void syncClassid(unsigned int clientID);
 
     float timeSinceLastUpdate_;
-    MasterServerComm msc;
+    //MasterServerComm msc;
   };
 
 

Modified: code/branches/presentation/src/libraries/network/WANDiscovery.cc
===================================================================
--- code/branches/presentation/src/libraries/network/WANDiscovery.cc	2010-12-15 13:05:48 UTC (rev 7762)
+++ code/branches/presentation/src/libraries/network/WANDiscovery.cc	2010-12-15 13:51:39 UTC (rev 7763)
@@ -132,7 +132,7 @@
     while( i > 0 )
     {
       /* poll for reply and act according to what was received */
-      switch( this->msc.pollForReply( rhandler, 1000 ) )
+      switch( this->msc.pollForReply( rhandler, 500 ) )
       { case 0: /* no event occured, decrease timeout */
           --i; break;
         case 1: /* got a list element, continue */ 

Modified: code/branches/presentation/src/libraries/network/WANDiscovery.h
===================================================================
--- code/branches/presentation/src/libraries/network/WANDiscovery.h	2010-12-15 13:05:48 UTC (rev 7762)
+++ code/branches/presentation/src/libraries/network/WANDiscovery.h	2010-12-15 13:51:39 UTC (rev 7763)
@@ -94,14 +94,14 @@
 
       /** Function used for the configuration file parameter update */
       void setConfigValues();
+
+      /** Master server communications object */
+      MasterServerComm msc;
       
     private:
       /** Singleton pointer */
       static WANDiscovery* singletonPtr_s;
 
-      /** Master server communications object */
-      MasterServerComm msc;
-
       /** master server address */
       std::string msaddress;
 




More information about the Orxonox-commit mailing list