[Orxonox-commit 3033] r7729 - code/branches/masterserver/src/libraries/network

smerkli at orxonox.net smerkli at orxonox.net
Wed Dec 8 14:33:54 CET 2010


Author: smerkli
Date: 2010-12-08 14:33:54 +0100 (Wed, 08 Dec 2010)
New Revision: 7729

Added:
   code/branches/masterserver/src/libraries/network/MasterServer.cc
   code/branches/masterserver/src/libraries/network/MasterServer.h
   code/branches/masterserver/src/libraries/network/PeerList.cc
   code/branches/masterserver/src/libraries/network/PeerList.h
   code/branches/masterserver/src/libraries/network/ServerList.cc
   code/branches/masterserver/src/libraries/network/ServerList.h
Removed:
   code/branches/masterserver/src/libraries/network/masterserver/
Modified:
   code/branches/masterserver/src/libraries/network/CMakeLists.txt
   code/branches/masterserver/src/libraries/network/MasterServerProtocol.h
Log:
moved some files.

Modified: code/branches/masterserver/src/libraries/network/CMakeLists.txt
===================================================================
--- code/branches/masterserver/src/libraries/network/CMakeLists.txt	2010-12-08 12:52:14 UTC (rev 7728)
+++ code/branches/masterserver/src/libraries/network/CMakeLists.txt	2010-12-08 13:33:54 UTC (rev 7729)
@@ -67,6 +67,7 @@
 
 ADD_SUBDIRECTORY(packet)
 ADD_SUBDIRECTORY(synchronisable)
+ADD_SUBDIRECTORY(masterserver)
 
 ORXONOX_ADD_LIBRARY(network
   TOLUA_FILES

Copied: code/branches/masterserver/src/libraries/network/MasterServer.cc (from rev 7728, code/branches/masterserver/src/libraries/network/masterserver/MasterServer.cc)
===================================================================
--- code/branches/masterserver/src/libraries/network/MasterServer.cc	                        (rev 0)
+++ code/branches/masterserver/src/libraries/network/MasterServer.cc	2010-12-08 13:33:54 UTC (rev 7729)
@@ -0,0 +1,301 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Sandro 'smerkli' Merkli
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "MasterServer.h"
+#include "util/ScopedSingletonManager.h"
+#include "core/CoreIncludes.h"
+#include "core/CorePrereqs.h"
+
+namespace orxonox 
+{
+  /* helpers */
+  static void 
+  helper_output_debug( ENetEvent *event, char *addrconv )
+  {
+    COUT(4) << "A packet of length" 
+      << event->packet->dataLength
+      << " containing "
+      << (const char*)event->packet->data
+      << " was received from "
+      << addrconv 
+      << " on channel "
+      << event->channelID << "\n";
+  }
+
+  void
+  MasterServer::helper_sendlist( ENetEvent *event )
+  {
+    /* get an iterator */
+    std::list<packet::ServerInformation>::iterator i;
+
+    /* packet holder */
+    ENetPacket *reply;
+
+    /* loop through list elements */
+    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() 
+          + MSPROTO_SERVERLIST_ITEM_LEN + 2,1 );
+      if( !tosend ) 
+      { COUT(2) << "Masterserver.cc: Memory allocation failed.\n";
+        continue;
+      } 
+      sprintf( tosend, "%s %s", MSPROTO_SERVERLIST_ITEM, 
+          (*i).getServerIP().c_str() );
+
+      /* create packet from it */
+      reply = enet_packet_create( tosend,
+          strlen( tosend ) + 1, 
+          ENET_PACKET_FLAG_RELIABLE);
+
+      /* Send the reply to the peer over channel id 0. */
+      enet_peer_send( event->peer, 0, reply );
+
+      /* One could just use enet_host_service() instead. */
+      enet_host_flush( this->server );
+
+      /* free the tosend buffer */
+      free( tosend );
+    } 
+
+    /* send end-of-list packet */
+    reply = enet_packet_create( MSPROTO_SERVERLIST_END,
+        MSPROTO_SERVERLIST_END_LEN + 1,
+        ENET_PACKET_FLAG_RELIABLE );
+
+    enet_peer_send( event->peer, 0, reply );
+
+    /* One could just use enet_host_service() instead. */
+    enet_host_flush( this->server );
+  }
+
+
+
+
+  /***** EVENTS *****/
+  /* connect event */
+  int 
+  MasterServer::eventConnect( ENetEvent *event )
+  { /* check for bad parameters */
+    if( !event )
+    { COUT(2) << "MasterServer::eventConnect: No event given.\n" ;
+      return -1;
+    }
+
+    /* convert address to string. */
+    char *addrconv = (char *) calloc( 50, 1 );
+    enet_address_get_host_ip( &(event->peer->address), addrconv, 49 );
+
+    /* output debug info */
+    COUT(4) << "A new client connected from " 
+      << addrconv 
+      << " on port " 
+      << event->peer->address.port << "\n";
+
+    /* store string form of address here */
+    event->peer->data = addrconv; 
+
+    /* all fine. */
+    return 0;
+  }
+
+  /* disconnect event */
+  int 
+  MasterServer::eventDisconnect( ENetEvent *event )
+  { /* check for bad parameters */
+    if( !event )
+    { COUT(2) << "No event given.\n";
+      return -1;
+    }
+
+    /* output that the disconnect happened */
+    COUT(4) << (char*)event->peer->data << " disconnected.\n";
+
+    /* create string from peer data */
+    std::string name = std::string( (char*)event->peer->data );
+
+    /* remove the server from the list it belongs to */
+    this->mainlist.delServerByName( name );
+
+    /* Reset the peer's client information. */
+    if( event->peer->data ) free( event->peer->data );
+
+    /* done */
+    return 0;
+  }
+
+  /* data event */
+  int 
+  MasterServer::eventData( ENetEvent *event )
+  { /* validate packet */
+    if( !event || !(event->packet) || !(event->peer) )
+      //|| !(event->packet->data) || !strlen(event->packet->data) )
+    { COUT(2) << "No complete event given.\n";
+      return -1;
+    }
+     
+    /* generate address in readable form */
+    char *addrconv = (char *) calloc( 50, 1 );
+    enet_address_get_host_ip( &(event->peer->address), addrconv, 49 );
+
+    /* DEBUG */
+    /* output debug info about the data that has come, to be removed */
+    helper_output_debug( event, addrconv );
+
+    /* GAME SERVER OR CLIENT CONNECTION? */
+    if( !strncmp( (char *)event->packet->data, 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 ) )
+      { /* register new server */
+        mainlist.addServer( packet::ServerInformation( event ) );
+        
+        /* tell people we did so */
+        COUT(2) << "Added new server to list: " << 
+          packet::ServerInformation( event ).getServerIP() << "\n";
+      }
+    }
+    else if( !strncmp( (char *)event->packet->data, MSPROTO_CLIENT, 
+      MSPROTO_CLIENT_LEN) )
+    { /* client */
+      if( !strncmp( (char *)event->packet->data + MSPROTO_CLIENT_LEN+1,
+        MSPROTO_REQ_LIST, MSPROTO_REQ_LIST_LEN ) )
+        /* send server list */
+        helper_sendlist( event );
+    }
+    else
+    { /* 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;
+  }
+
+
+  /**** MAIN ROUTINE *****/
+  int 
+  MasterServer::run()
+  {
+    /***** ENTER MAIN LOOP *****/
+    ENetEvent *event = (ENetEvent *)calloc(sizeof(ENetEvent), sizeof(char));
+    if( event == NULL )
+    { 
+      COUT(1) << "Could not create ENetEvent structure, exiting.\n";
+      exit( EXIT_FAILURE );
+    }
+
+    /* tell people we're now initialized and blocking. */
+    COUT(0) << "MasterServer initialized, waiting for connections.\n";
+    
+    /* endless loop until we quit */
+    while( this->quit == false )
+    {
+      /* create an iterator for the loop */
+      while( enet_host_service( this->server, event, 1000 ) >= 0 )
+      { /* check what type of event it is and react accordingly */
+        switch (event->type)
+        { /* new connection */
+          case ENET_EVENT_TYPE_CONNECT: 
+            eventConnect( event ); break;
+
+            /* disconnect */
+          case ENET_EVENT_TYPE_DISCONNECT: 
+            eventDisconnect( event ); break;
+
+            /* incoming data */
+          case ENET_EVENT_TYPE_RECEIVE: eventData( event ); break;
+          default: break;
+        }
+      }
+    }
+
+    /* done */
+    return 0;
+  } 
+
+  /* constructor */
+  MasterServer::MasterServer()
+  {
+    /***** INITIALIZE NETWORKING *****/
+    if( enet_initialize () != 0)
+    { COUT(1) << "An error occurred while initializing ENet.\n";
+      exit( EXIT_FAILURE );
+    }
+
+    /* register deinitialization */
+    atexit( enet_deinitialize );
+
+    /* set the quit flag to false */
+    this->quit = false;
+
+    /* Bind the server to the default localhost and port ORX_MSERVER_PORT */
+    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 
+     * any input/output bandwidth */
+    this->server = enet_host_create( &this->address, ORX_MSERVER_MAXCONNS, 
+        ORX_MSERVER_MAXCHANS, 0, 0 );     
+
+    /* see if creation worked */
+    if( !this->server )
+    { COUT(1) << 
+        "An error occurred while trying to create an ENet server host.\n";
+      exit( EXIT_FAILURE );
+    }
+
+    /***** INITIALIZE GAME SERVER AND PEER LISTS *****/
+    //this->mainlist = new ServerList();
+    this->peers = new PeerList();
+  }
+
+  /* destructor */
+  MasterServer::~MasterServer()
+  {
+    /***** CLEANUP PROCESS *****/
+    /* terminate all networking connections */
+    enet_host_destroy( this->server );
+
+    /* free all used memory */
+    /* clear the list of connected game servers */
+    /* clear the list of connected game clients */
+
+  }
+
+/* end of namespace */
+}

Copied: code/branches/masterserver/src/libraries/network/MasterServer.h (from rev 7728, code/branches/masterserver/src/libraries/network/masterserver/MasterServer.h)
===================================================================
--- code/branches/masterserver/src/libraries/network/MasterServer.h	                        (rev 0)
+++ code/branches/masterserver/src/libraries/network/MasterServer.h	2010-12-08 13:33:54 UTC (rev 7729)
@@ -0,0 +1,81 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Sandro 'smerkli' Merkli
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _MasterServer_
+#define _MasterServer_
+
+/* orxonox includes */
+#include <enet/enet.h>
+#include <network/packet/Chat.h>
+#include <network/packet/ClassID.h>
+#include <network/packet/DeleteObjects.h>
+#include <network/packet/FunctionIDs.h>
+#include <network/packet/Gamestate.h>
+#include <network/packet/Welcome.h>
+#include <network/MasterServerProtocol.h>
+
+/* my includes */
+#include "ServerList.h"
+#include "PeerList.h"
+
+/* c compatibility */
+#include <cstdio>
+
+namespace orxonox 
+{
+  /* singleton */
+  class MasterServer
+  {
+    public:
+      MasterServer();
+      ~MasterServer();
+
+    private:
+      /* methods */
+      int eventConnect( ENetEvent *event );
+      int eventDisconnect( ENetEvent *event );
+      int eventData( ENetEvent *event );
+
+      /* helpers */
+      void helper_sendlist( ENetEvent *event );
+
+      /* members */
+      ENetAddress address;
+      ENetHost *server;
+      ServerList mainlist;
+      PeerList *peers;
+
+      unsigned int port;
+      bool quit;
+
+      /* main routine */
+      int run();
+  };
+}
+
+#endif /* _MasterServer_ */

Modified: code/branches/masterserver/src/libraries/network/MasterServerProtocol.h
===================================================================
--- code/branches/masterserver/src/libraries/network/MasterServerProtocol.h	2010-12-08 12:52:14 UTC (rev 7728)
+++ code/branches/masterserver/src/libraries/network/MasterServerProtocol.h	2010-12-08 13:33:54 UTC (rev 7729)
@@ -57,7 +57,7 @@
 
 
 
-#define ORX_MSERVER_PORT 1234
+#define ORX_MSERVER_PORT 55566
 
 
 #define ORX_MSERVER_MAXCONNS 32

Copied: code/branches/masterserver/src/libraries/network/PeerList.cc (from rev 7728, code/branches/masterserver/src/libraries/network/masterserver/PeerList.cc)
===================================================================
--- code/branches/masterserver/src/libraries/network/PeerList.cc	                        (rev 0)
+++ code/branches/masterserver/src/libraries/network/PeerList.cc	2010-12-08 13:33:54 UTC (rev 7729)
@@ -0,0 +1,96 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Sandro 'smerkli' Merkli
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "PeerList.h"
+#include <network/packet/ServerInformation.h>
+#include <cstdio>
+
+namespace orxonox
+{
+  PeerList::PeerList() { }
+  PeerList::~PeerList() { }
+
+  int 
+  PeerList::addPeer( ENetPeer *toadd )
+  { /* error correction */
+    if( toadd == NULL ) 
+    { fprintf( stderr, "PeerList::addPeer: empty peer given.\n" );
+      return -1;
+    }
+
+    /* if all went well, push to back of list */
+    this->peerlist.push_back( toadd );
+    return 0;
+  }
+
+  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;
+      else if( addr1.host.addr[i] > addr2.host.addr[i] )
+        return i;
+
+    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 ) 
+      if( !sub_compAddr((*i)->address, addr ) )
+      { /* found this name, remove and quit */
+        this->peerlist.remove( *i );
+        return true;
+      }
+
+    /* not found */
+    return false;
+  }
+
+  ENetPeer *
+  PeerList::findPeerByAddr( ENetAddress addr )
+  { /* get an iterator */
+    std::list<ENetPeer *>::iterator i;
+
+    /* loop through list elements */
+    for( i = peerlist.begin(); i != peerlist.end(); ++i ) 
+      if( !sub_compAddr((*i)->address, addr ) )
+        /* found this name, remove and quit */
+        return *i;
+
+    /* not found */
+    return NULL;
+  }
+
+}
+

Copied: code/branches/masterserver/src/libraries/network/PeerList.h (from rev 7728, code/branches/masterserver/src/libraries/network/masterserver/PeerList.h)
===================================================================
--- code/branches/masterserver/src/libraries/network/PeerList.h	                        (rev 0)
+++ code/branches/masterserver/src/libraries/network/PeerList.h	2010-12-08 13:33:54 UTC (rev 7729)
@@ -0,0 +1,83 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Sandro 'smerkli' Merkli
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _PeerList_
+#define _PeerList_
+
+#include <list>
+#include <string>
+#include <enet/enet.h>
+
+/* peer list */
+namespace orxonox 
+{
+  /** This class keeps a list of open connections 
+   * and some info about them.
+   */
+  class PeerList 
+  { public:
+      /** constructor */
+      PeerList();
+
+      /** destructor */
+      ~PeerList();
+
+      /** \param toadd The peer to add
+       * \return 0 for success, -1 for error.
+       * 
+       * 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 
+       */
+      bool remPeerByAddr( ENetAddress addr );
+
+      /** \param addr The address to find by
+       * 
+       * Find a connection by address */
+      ENetPeer *findPeerByAddr( ENetAddress addr );
+
+      /* 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.
+       */
+      /** the list of servers for internal storage */
+      std::list<ENetPeer *> peerlist;
+    private:
+      /* nothing so far. */
+  };
+}
+
+
+
+#endif /* _PeerList_ */

Copied: code/branches/masterserver/src/libraries/network/ServerList.cc (from rev 7728, code/branches/masterserver/src/libraries/network/masterserver/ServerList.cc)
===================================================================
--- code/branches/masterserver/src/libraries/network/ServerList.cc	                        (rev 0)
+++ code/branches/masterserver/src/libraries/network/ServerList.cc	2010-12-08 13:33:54 UTC (rev 7729)
@@ -0,0 +1,102 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Sandro 'smerkli' Merkli
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "ServerList.h"
+
+namespace orxonox
+{ 
+  ServerList::ServerList()
+  { /* create a new list */ }
+
+  ServerList::~ServerList()
+  { /* delete the list */
+    serverlist.clear();
+  }
+
+  int 
+  ServerList::addServer( packet::ServerInformation toadd )
+  { this->serverlist.push_back( toadd ); 
+    return 0;
+  }
+
+  bool 
+  ServerList::delServerByName( std::string name )
+  { 
+    /* get an iterator */
+    std::list<packet::ServerInformation>::iterator i;
+
+    /* loop through list elements */
+    for( i = serverlist.begin(); i != serverlist.end(); ++i ) 
+      if( (*i).getServerName() == name )
+      { /* found this name, remove and quit */
+        this->serverlist.erase( i );
+        return true;
+      }
+    return false;
+  }
+
+  bool ServerList::delServerByAddress( std::string address )
+  { 
+    /* get an iterator */
+    std::list<packet::ServerInformation>::iterator i;
+
+    /* loop through list elements */
+    for( i=serverlist.begin(); i != serverlist.end(); ++i ) 
+      if( (*i).getServerIP() == address )
+      { /* found this name, remove and quit */
+        this->serverlist.erase( i );
+        return true;
+      }
+    return false;
+  }
+
+
+  /* sort by name */
+  bool sub_compare_names( packet::ServerInformation no1, 
+    packet::ServerInformation no2 )
+  { return no1.getServerName() > no2.getServerName(); }
+
+  void ServerList::sortByName()
+  { 
+    this->serverlist.sort( sub_compare_names ); 
+  }
+  
+  /* sort by ping */
+  bool sub_compare_pings( packet::ServerInformation no1, 
+    packet::ServerInformation no2 )
+  { 
+    /* TODO */
+    return no1.getServerName() > no2.getServerName();
+  }
+
+  void ServerList::sortByPing()
+  {
+    this->serverlist.sort( sub_compare_pings ); 
+  }
+
+}

Copied: code/branches/masterserver/src/libraries/network/ServerList.h (from rev 7728, code/branches/masterserver/src/libraries/network/masterserver/ServerList.h)
===================================================================
--- code/branches/masterserver/src/libraries/network/ServerList.h	                        (rev 0)
+++ code/branches/masterserver/src/libraries/network/ServerList.h	2010-12-08 13:33:54 UTC (rev 7729)
@@ -0,0 +1,85 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Sandro 'smerkli' Merkli
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _ServerList_
+#define _ServerList_
+
+#include <list>
+#include <string>
+#include <network/packet/ServerInformation.h>
+
+/* methods necessary */
+namespace orxonox 
+{ 
+  /** This class is keeps a list of game servers
+   * and some info about them.
+   */
+  class ServerList 
+  { public:
+      /** constructor */
+      ServerList();
+
+      /** destructor */
+      ~ServerList();
+
+
+      /* BASIC MANIPULATION */
+      /** \param toadd the server to add.
+       * 
+       * Add server to the game server list
+       */
+      int addServer( packet::ServerInformation toadd );
+
+      /** \param name Name of the server to remove
+       * 
+       * 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 );
+
+
+      /* SORTING (to be implemented) */
+
+      /** sort by name  */
+      void sortByName();
+      
+      /** sort by ping */
+      void sortByPing();
+
+      /** the list of servers for internal storage */
+      std::list<packet::ServerInformation> serverlist;
+    private:
+  };
+}
+
+#endif /*_ServerList_*/




More information about the Orxonox-commit mailing list