[Orxonox-commit 3595] r8280 - code/branches/masterserver2/src/libraries/network

smerkli at orxonox.net smerkli at orxonox.net
Thu Apr 21 16:01:44 CEST 2011


Author: smerkli
Date: 2011-04-21 16:01:44 +0200 (Thu, 21 Apr 2011)
New Revision: 8280

Modified:
   code/branches/masterserver2/src/libraries/network/MasterServer.cc
   code/branches/masterserver2/src/libraries/network/MasterServer.h
   code/branches/masterserver2/src/libraries/network/MasterServerComm.cc
   code/branches/masterserver2/src/libraries/network/ServerList.cc
   code/branches/masterserver2/src/libraries/network/ServerList.h
Log:
ms-delserver command implemented to kick servers from the master server list

Modified: code/branches/masterserver2/src/libraries/network/MasterServer.cc
===================================================================
--- code/branches/masterserver2/src/libraries/network/MasterServer.cc	2011-04-21 12:17:39 UTC (rev 8279)
+++ code/branches/masterserver2/src/libraries/network/MasterServer.cc	2011-04-21 14:01:44 UTC (rev 8280)
@@ -37,7 +37,7 @@
   /*** MACROS ***/
   /* commands for the terminal interface */
   SetConsoleCommand( "ms-listservers", &MasterServer::listServers );
-  //SetConsoleCommand( "ms-delserver", &MasterServer::delServer );
+  SetConsoleCommand( "ms-delserver", &MasterServer::delServer );
   //SetConsoleCommand( "ms-serverinfo", &MasterServer::serverInfo );
 
   /* forward declaration so the linker doesn't complain */
@@ -68,7 +68,33 @@
       " servers connected." << std::endl;
   }
 
+  void 
+  MasterServer::delServer( std::string todeladdr )
+  {
+    /* tell the user we're now removing the entry from the server list */
+    COUT(0) << "MS: Deleting server \"" << todeladdr << "\"..." 
+      << std::endl;
 
+    /* see if we actually have that server on our list */
+    ServerListSearchResult shandle = 
+      MasterServer::getInstance()->mainlist.findServerByAddress(todeladdr);
+
+    if( !shandle.success )
+    { COUT(0) << "MS: Server not found, not removing." << std::endl;
+      return;
+    }
+
+    /* force-disconnect the server */  
+    enet_peer_disconnect( shandle.result.peer, NULL );
+
+    /* actually remove the entry from the server list by address */
+    MasterServer::getInstance()->mainlist.delServerByAddress( todeladdr);
+
+    /* tell the user about our success */
+    COUT(0) << "MS: Server deletion successful." << std::endl;
+  }
+
+
   /* helpers */
   static void 
   helper_output_debug( ENetEvent *event, char *addrconv )
@@ -364,9 +390,6 @@
       exit( EXIT_FAILURE );
     }
 
-    /***** INITIALIZE GAME SERVER AND PEER LISTS *****/
-    this->peers = new PeerList();
-
     /* set pointer to this instance */
     MasterServer::setInstance( this );
 

Modified: code/branches/masterserver2/src/libraries/network/MasterServer.h
===================================================================
--- code/branches/masterserver2/src/libraries/network/MasterServer.h	2011-04-21 12:17:39 UTC (rev 8279)
+++ code/branches/masterserver2/src/libraries/network/MasterServer.h	2011-04-21 14:01:44 UTC (rev 8280)
@@ -69,6 +69,7 @@
       
       /* functions for commands */
       static void listServers( void );
+      static void delServer( std::string todeladdr );
 
     private:
       /* methods */
@@ -84,7 +85,6 @@
       ENetAddress address;
       ENetHost *server;
       ServerList mainlist;
-      PeerList *peers;
 
       unsigned int port;
       bool quit;

Modified: code/branches/masterserver2/src/libraries/network/MasterServerComm.cc
===================================================================
--- code/branches/masterserver2/src/libraries/network/MasterServerComm.cc	2011-04-21 12:17:39 UTC (rev 8279)
+++ code/branches/masterserver2/src/libraries/network/MasterServerComm.cc	2011-04-21 14:01:44 UTC (rev 8280)
@@ -167,8 +167,10 @@
       { /* new connection, not supposed to happen. */
         case ENET_EVENT_TYPE_CONNECT: break;
 
-        /* disconnect */
-        case ENET_EVENT_TYPE_DISCONNECT: /* ?? */ break;
+        /* disconnection event - probably kick from masterserver or crash. */
+        case ENET_EVENT_TYPE_DISCONNECT: 
+          COUT(0) << "ERROR: Master server connection was dropped." << std::endl;
+          break;
 
         /* incoming data */
         case ENET_EVENT_TYPE_RECEIVE: 

Modified: code/branches/masterserver2/src/libraries/network/ServerList.cc
===================================================================
--- code/branches/masterserver2/src/libraries/network/ServerList.cc	2011-04-21 12:17:39 UTC (rev 8279)
+++ code/branches/masterserver2/src/libraries/network/ServerList.cc	2011-04-21 14:01:44 UTC (rev 8280)
@@ -81,7 +81,47 @@
     return false;
   }
 
+  /* SEARCHING */
+  ServerListSearchResult
+  ServerList::findServerByAddress( std::string address )
+  {
+    /* 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 the target, return it */
+        ServerListSearchResult res = { (*i), true };
+        return res;
+      }
+
+    /* no success */
+    ServerListSearchResult res = { (*i), false };
+    return res;
+  }
+
+  ServerListSearchResult
+  ServerList::findServerByName( std::string name )
+  {
+    /* get an iterator */
+    std::list<ServerListElem>::iterator i;
+
+    /* iterate, return when name found */
+    /* loop through list elements */
+    for( i = serverlist.begin(); i != serverlist.end(); ++i ) 
+      if( (*i).ServerInfo.getServerName() == name )
+      { 
+        ServerListSearchResult res = { (*i), true };
+        return res;
+      }
+
+    /* no luck, return a struct that tells the caller so */
+    ServerListSearchResult res = { (*i), false };
+    return res;
+  }
+
+  /* SORTING */
   /* sort by name */
   bool sub_compare_names( ServerListElem no1, 
     ServerListElem no2 )

Modified: code/branches/masterserver2/src/libraries/network/ServerList.h
===================================================================
--- code/branches/masterserver2/src/libraries/network/ServerList.h	2011-04-21 12:17:39 UTC (rev 8279)
+++ code/branches/masterserver2/src/libraries/network/ServerList.h	2011-04-21 14:01:44 UTC (rev 8280)
@@ -36,6 +36,7 @@
 /* methods necessary */
 namespace orxonox 
 { 
+  /* HELPER STRUCTURES */
   struct ServerListElem 
   {
     /* server information (name, IP, etc) */
@@ -45,6 +46,19 @@
     ENetPeer* peer;
   };
 
+  struct ServerListSearchResult
+  {
+    /* list element found */
+    ServerListElem result;
+
+    /* successful search */
+    bool success;
+  };
+
+
+
+
+
   /** This class is keeps a list of game servers
    * and some info about them.
    */
@@ -78,8 +92,31 @@
       bool delServerByAddress( std::string address );
 
 
-      /* SORTING (to be implemented) */
 
+
+      /* SEARCHING */
+      /* \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 
+       *  found
+       * \return The struct containing the list entry of the server
+       * 
+       * Find and return the list handle of a given name.
+       */
+      ServerListSearchResult
+      findServerByName( std::string name );
+
+
+      /* SORTING */
       /** sort by name  */
       void sortByName();
       




More information about the Orxonox-commit mailing list