src/network/index_server.h

Go to the documentation of this file.
00001 /******************************************************************************
00002  *  Wormux is a convivial mass murder game.
00003  *  Copyright (C) 2001-2004 Lawrence Azzoug.
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00018  ******************************************************************************
00019  * Notify an index server of an opened wormux server
00020  * Obtain information about running games from an index server
00021  *****************************************************************************/
00022  
00023 #ifndef INDEX_SERVER_H
00024 #define INDEX_SERVER_H
00025 //-----------------------------------------------------------------------------
00026 #include <SDL_net.h>
00027 #include <map>
00028 #include <list>
00029 #include <string>
00030 #include <utility>
00031 
00032 typedef std::pair<std::string, std::string> address_pair;
00033 
00034 class IndexServer
00035 {
00036   // Connection to the server
00037   TCPsocket socket;
00038   IPaddress ip;
00039 
00040   // Stores the hostname / port of all online servers
00041   std::map<std::string, int> server_lst;
00042   // First server we tried to connect to
00043   std::map<std::string, int>::iterator first_server;
00044   // The current server we are trying to connect to
00045   std::map<std::string, int>::iterator current_server;
00046 
00047   // If we are a server, tell if we are visible on internet
00048   bool hidden_server;
00049 
00050   bool connected;
00051 
00052   // Transfer functions
00053   void Send(const int &nbr);
00054   void Send(const std::string &str);
00055   int ReceiveInt();
00056   std::string ReceiveStr();
00057 
00058   // Download the list of online servers on www.wormux.org
00059   bool GetServerList();
00060 
00061   // Gives the address of a server in the list
00062   bool GetServerAddress(std::string & address, int & port);
00063   // Connect to a server
00064   bool ConnectTo(const std::string & address, const int & port);
00065 
00066   // Perform a handshake with the server
00067   bool HandShake();
00068 public:
00069   IndexServer();
00070   ~IndexServer();
00071 
00072   // Connect to a server
00073   bool Connect();
00074 
00075   // We want to host a game hidden on internet
00076   void SetHiddenServer() { hidden_server = true; };
00077 
00078   // Notify the top server we are hosting a game
00079   void SendServerStatus();
00080   void Disconnect();
00081   // returns a list with string pairs: first element = hostname/ip, second element = port
00082   std::list<address_pair> GetHostList();
00083 };
00084 
00085 extern IndexServer index_server;
00086 
00087 #endif

Generated on Mon Jan 1 13:10:59 2007 for Wormux by  doxygen 1.4.7