2011-04-25 12:51:57 +02:00
|
|
|
/******************************************************************************\
|
2014-01-05 17:52:38 +01:00
|
|
|
* Copyright (c) 2004-2014
|
2011-04-25 12:51:57 +02:00
|
|
|
*
|
|
|
|
* Author(s):
|
|
|
|
* Volker Fischer
|
|
|
|
*
|
|
|
|
|
|
|
|
Currently, if you want to run a private server, you have to open the firewall of
|
|
|
|
your computer at the correct ports and introduce a port forwarding at your
|
|
|
|
router to get it work. Using a central server simplifies the process. The user
|
2013-03-24 11:49:25 +01:00
|
|
|
who wants to run a server just registers his server a the central server
|
2011-04-25 12:51:57 +02:00
|
|
|
and a mechanism implemented in the protocol opens the firewall similar to STUN.
|
|
|
|
|
|
|
|
REQUIREMENTS:
|
|
|
|
|
2013-03-24 11:49:25 +01:00
|
|
|
The client sets the URL of the central server and can get a list of all
|
|
|
|
currently activated and registered private servers. If the user clicks on
|
2011-04-25 12:51:57 +02:00
|
|
|
the server of his choice, he gets connected to this server.
|
|
|
|
|
|
|
|
The server list must be available in both cases: if the client is connected to
|
|
|
|
the central server or not.
|
|
|
|
|
|
|
|
The server list contains the name of the server, an optional topic, an optional
|
|
|
|
location, the number of connected users and a ping time which is updated as
|
|
|
|
long as the server list is visible (similar to the ping measurement in the
|
|
|
|
general settings dialog). Additional information may be also present in the list
|
|
|
|
like reliability of the server, etc.
|
|
|
|
|
|
|
|
CONNECTION PROCESS:
|
|
|
|
|
|
|
|
The private server contacts the central server and registers through some
|
|
|
|
protocol mechanism.
|
|
|
|
|
|
|
|
If a client requests the server list from the central server, the central server
|
|
|
|
sends the IP address of the client to each registered private servers so that
|
|
|
|
they can immediately send a "firewall opening" UDP packet to this IP address.
|
|
|
|
If the client now sends ping messages to each of the private servers in the
|
|
|
|
list, the firewalls and routers are prepared for receiving UDP packets from this
|
|
|
|
IP address and will tunnel it through. Note: this mechanism will not work in a
|
|
|
|
private network.
|
|
|
|
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* 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.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
\******************************************************************************/
|
|
|
|
|
|
|
|
#if !defined ( SERVERLIST_HOIJH8OUWEF_WFEIOBU_3_43445KJIUHF1912__INCLUDED_ )
|
|
|
|
#define SERVERLIST_HOIJH8OUWEF_WFEIOBU_3_43445KJIUHF1912__INCLUDED_
|
|
|
|
|
2013-01-02 21:41:04 +01:00
|
|
|
#include <QObject>
|
|
|
|
#include <QLocale>
|
|
|
|
#include <QList>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QMutex>
|
2011-04-25 12:51:57 +02:00
|
|
|
#include "global.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "protocol.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* Classes ********************************************************************/
|
|
|
|
class CServerListEntry : public CServerInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CServerListEntry() :
|
|
|
|
CServerInfo ( CHostAddress(),
|
2011-05-04 20:18:31 +02:00
|
|
|
0,
|
2011-04-25 12:51:57 +02:00
|
|
|
"",
|
|
|
|
"",
|
|
|
|
QLocale::AnyCountry,
|
|
|
|
"",
|
|
|
|
0,
|
|
|
|
false ) { UpdateRegistration(); }
|
|
|
|
|
|
|
|
CServerListEntry ( const CHostAddress& NHAddr,
|
2011-05-04 20:18:31 +02:00
|
|
|
const quint16 NLocPort,
|
2011-04-25 12:51:57 +02:00
|
|
|
const QString& NsName,
|
|
|
|
const QString& NsTopic,
|
|
|
|
const QLocale::Country& NeCountry,
|
|
|
|
const QString& NsCity,
|
|
|
|
const int NiMaxNumClients,
|
|
|
|
const bool NbPermOnline)
|
|
|
|
: CServerInfo ( NHAddr,
|
2011-05-04 20:18:31 +02:00
|
|
|
NLocPort,
|
2011-04-25 12:51:57 +02:00
|
|
|
NsName,
|
|
|
|
NsTopic,
|
|
|
|
NeCountry,
|
|
|
|
NsCity,
|
|
|
|
NiMaxNumClients,
|
|
|
|
NbPermOnline ) { UpdateRegistration(); }
|
|
|
|
|
|
|
|
CServerListEntry ( const CHostAddress& NHAddr,
|
|
|
|
const CServerCoreInfo& NewCoreServerInfo )
|
|
|
|
: CServerInfo ( NHAddr,
|
2011-05-04 20:18:31 +02:00
|
|
|
NewCoreServerInfo.iLocalPortNumber,
|
2011-04-25 12:51:57 +02:00
|
|
|
NewCoreServerInfo.strName,
|
|
|
|
NewCoreServerInfo.strTopic,
|
|
|
|
NewCoreServerInfo.eCountry,
|
|
|
|
NewCoreServerInfo.strCity,
|
|
|
|
NewCoreServerInfo.iMaxNumClients,
|
|
|
|
NewCoreServerInfo.bPermanentOnline )
|
|
|
|
{ UpdateRegistration(); }
|
|
|
|
|
|
|
|
void UpdateRegistration() { RegisterTime.start(); }
|
|
|
|
|
|
|
|
public:
|
|
|
|
// time on which the entry was registered
|
|
|
|
QTime RegisterTime;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CServerListManager : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2011-05-04 20:18:31 +02:00
|
|
|
CServerListManager ( const quint16 iNPortNum,
|
|
|
|
const QString& sNCentServAddr,
|
2011-04-25 15:25:33 +02:00
|
|
|
const QString& strServerInfo,
|
2011-05-13 20:23:00 +02:00
|
|
|
const int iNumChannels,
|
2012-07-14 18:18:09 +02:00
|
|
|
const bool bNCentServPingServerInList,
|
2011-04-25 12:51:57 +02:00
|
|
|
CProtocol* pNConLProt );
|
|
|
|
|
2011-04-30 15:01:26 +02:00
|
|
|
// the update has to be called if any change to the server list
|
|
|
|
// properties was done
|
|
|
|
void Update();
|
|
|
|
|
|
|
|
void SetEnabled ( const bool bState ) { bEnabled = bState; }
|
2011-04-25 12:51:57 +02:00
|
|
|
bool GetEnabled() const { return bEnabled; }
|
2011-04-25 18:16:31 +02:00
|
|
|
|
2011-04-30 15:01:26 +02:00
|
|
|
void SetCentralServerAddress ( const QString sNCentServAddr );
|
|
|
|
QString GetCentralServerAddress() { return strCentralServerAddress; }
|
|
|
|
|
2011-04-30 21:51:49 +02:00
|
|
|
void SetUseDefaultCentralServerAddress ( const bool bNUDCSeAddr )
|
|
|
|
{ bUseDefaultCentralServerAddress = bNUDCSeAddr; }
|
|
|
|
|
|
|
|
bool GetUseDefaultCentralServerAddress()
|
|
|
|
{ return bUseDefaultCentralServerAddress; }
|
|
|
|
|
2011-04-25 12:51:57 +02:00
|
|
|
bool GetIsCentralServer() const { return bIsCentralServer; }
|
|
|
|
|
2011-05-04 09:00:43 +02:00
|
|
|
void CentralServerRegisterServer ( const CHostAddress& InetAddr,
|
|
|
|
const CServerCoreInfo& ServerInfo );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2011-05-04 09:00:43 +02:00
|
|
|
void CentralServerUnregisterServer ( const CHostAddress& InetAddr );
|
2011-05-03 22:37:06 +02:00
|
|
|
|
2011-05-04 09:00:43 +02:00
|
|
|
void CentralServerQueryServerList ( const CHostAddress& InetAddr );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2011-05-04 09:15:50 +02:00
|
|
|
void SlaveServerUnregister() { SlaveServerRegisterServer ( false ); }
|
2011-04-25 18:16:31 +02:00
|
|
|
|
|
|
|
// set server infos -> per definition the server info of this server is
|
|
|
|
// stored in the first entry of the list, we assume here that the first
|
|
|
|
// entry is correctly created in the constructor of the class
|
|
|
|
void SetServerName ( const QString& strNewName )
|
|
|
|
{ ServerList[0].strName = strNewName; }
|
|
|
|
|
|
|
|
QString GetServerName() { return ServerList[0].strName; }
|
|
|
|
|
|
|
|
void SetServerCity ( const QString& strNewCity )
|
|
|
|
{ ServerList[0].strCity = strNewCity; }
|
|
|
|
|
|
|
|
QString GetServerCity() { return ServerList[0].strCity; }
|
|
|
|
|
|
|
|
void SetServerCountry ( const QLocale::Country eNewCountry )
|
|
|
|
{ ServerList[0].eCountry = eNewCountry; }
|
|
|
|
|
|
|
|
QLocale::Country GetServerCountry() { return ServerList[0].eCountry; }
|
|
|
|
|
2011-04-25 12:51:57 +02:00
|
|
|
protected:
|
2011-05-04 09:15:50 +02:00
|
|
|
void SlaveServerRegisterServer ( const bool bIsRegister );
|
|
|
|
|
2011-04-25 12:51:57 +02:00
|
|
|
QTimer TimerPollList;
|
|
|
|
QTimer TimerRegistering;
|
2012-06-05 08:25:19 +02:00
|
|
|
QTimer TimerPingServerInList;
|
2012-07-09 14:53:40 +02:00
|
|
|
QTimer TimerPingCentralServer;
|
2012-06-05 08:25:19 +02:00
|
|
|
|
2011-04-25 12:51:57 +02:00
|
|
|
QMutex Mutex;
|
2011-05-04 20:18:31 +02:00
|
|
|
|
2011-04-25 12:51:57 +02:00
|
|
|
QList<CServerListEntry> ServerList;
|
2011-05-04 20:18:31 +02:00
|
|
|
|
|
|
|
quint16 iPortNumber;
|
2011-04-25 12:51:57 +02:00
|
|
|
QString strCentralServerAddress;
|
2011-05-03 22:37:06 +02:00
|
|
|
int iNumPredefinedServers;
|
2011-04-25 12:51:57 +02:00
|
|
|
bool bEnabled;
|
|
|
|
bool bIsCentralServer;
|
2011-04-30 21:51:49 +02:00
|
|
|
bool bUseDefaultCentralServerAddress;
|
2012-07-14 18:18:09 +02:00
|
|
|
bool bCentServPingServerInList;
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2012-07-09 14:53:40 +02:00
|
|
|
CHostAddress SlaveCurCentServerHostAddress;
|
|
|
|
|
2011-04-25 12:51:57 +02:00
|
|
|
CProtocol* pConnLessProtocol;
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void OnTimerPollList();
|
2012-06-05 08:25:19 +02:00
|
|
|
void OnTimerPingServerInList();
|
2012-07-09 14:53:40 +02:00
|
|
|
void OnTimerPingCentralServer();
|
2011-05-04 09:15:50 +02:00
|
|
|
void OnTimerRegistering() { SlaveServerRegisterServer ( true ); }
|
2011-04-25 12:51:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* !defined ( SERVERLIST_HOIJH8OUWEF_WFEIOBU_3_43445KJIUHF1912__INCLUDED_ ) */
|