Merge pull request #48 from pljones/feature/27-local-server-in-server-list
Use server internal address in server list
This commit is contained in:
commit
cf8642ad8b
10 changed files with 144 additions and 73 deletions
|
@ -110,6 +110,12 @@ LED bar: lbr
|
||||||
// download URL
|
// download URL
|
||||||
#define LLCON_DOWNLOAD_URL "http://sourceforge.net/projects/llcon/files"
|
#define LLCON_DOWNLOAD_URL "http://sourceforge.net/projects/llcon/files"
|
||||||
|
|
||||||
|
// determining server internal address uses well-known host and port
|
||||||
|
// (Google DNS, or something else reliable)
|
||||||
|
#define WELL_KNOWN_HOST "8.8.8.8" // Google
|
||||||
|
#define WELL_KNOWN_PORT 53 // DNS
|
||||||
|
#define IP_LOOKUP_TIMEOUT 500 // ms
|
||||||
|
|
||||||
// defined port number for client and server
|
// defined port number for client and server
|
||||||
#if ( SYSTEM_FRAME_SIZE_SAMPLES == 64 )
|
#if ( SYSTEM_FRAME_SIZE_SAMPLES == 64 )
|
||||||
# define LLCON_DEFAULT_PORT_NUMBER 22064 // different port number for 64 samples frame size version
|
# define LLCON_DEFAULT_PORT_NUMBER 22064 // different port number for 64 samples frame size version
|
||||||
|
@ -231,7 +237,7 @@ LED bar: lbr
|
||||||
#define MAX_LEN_CHAT_TEXT 1600
|
#define MAX_LEN_CHAT_TEXT 1600
|
||||||
#define MAX_LEN_CHAT_TEXT_PLUS_HTML 1800
|
#define MAX_LEN_CHAT_TEXT_PLUS_HTML 1800
|
||||||
#define MAX_LEN_SERVER_NAME 20
|
#define MAX_LEN_SERVER_NAME 20
|
||||||
#define MAX_LEN_SERVER_TOPIC 32
|
#define MAX_LEN_IP_ADDRESS 15
|
||||||
#define MAX_LEN_SERVER_CITY 20
|
#define MAX_LEN_SERVER_CITY 20
|
||||||
#define MAX_LEN_VERSION_TEXT 20
|
#define MAX_LEN_VERSION_TEXT 20
|
||||||
|
|
||||||
|
|
|
@ -203,26 +203,28 @@ CONNECTION LESS MESSAGES
|
||||||
... -----------------+----------------------------------+ ...
|
... -----------------+----------------------------------+ ...
|
||||||
... 2 bytes country | 1 byte maximum connected clients | ...
|
... 2 bytes country | 1 byte maximum connected clients | ...
|
||||||
... -----------------+----------------------------------+ ...
|
... -----------------+----------------------------------+ ...
|
||||||
... ---------------------+------------------+ ...
|
... ---------------------+ ...
|
||||||
... 1 byte is permanent | 2 bytes number n | ...
|
... 1 byte is permanent | ...
|
||||||
... ---------------------+------------------+ ...
|
... ---------------------+ ...
|
||||||
... ----------------------------------+ ...
|
... ------------------+----------------------------------+ ...
|
||||||
... n bytes UTF-8 string server name | ...
|
... 2 bytes number n | n bytes UTF-8 string server name | ...
|
||||||
... ----------------------------------+ ...
|
... ------------------+----------------------------------+ ...
|
||||||
... ------------------+----------------------------+ ...
|
... ------------------+---------------------------------------------+ ...
|
||||||
... 2 bytes number n | n bytes UTF-8 string topic | ...
|
... 2 bytes number n | n bytes UTF-8 string server interal address | ...
|
||||||
... ------------------+----------------------------+ ...
|
... ------------------+---------------------------------------------+ ...
|
||||||
... ------------------+---------------------------+
|
... ------------------+---------------------------+
|
||||||
... 2 bytes number n | n bytes UTF-8 string city |
|
... 2 bytes number n | n bytes UTF-8 string city |
|
||||||
... ------------------+---------------------------+
|
... ------------------+---------------------------+
|
||||||
|
|
||||||
|
- "country" is according to "Common Locale Data Repository" which is used in
|
||||||
|
the QLocale class
|
||||||
- "maximum connected clients" is the maximum number of clients which can
|
- "maximum connected clients" is the maximum number of clients which can
|
||||||
be connected to the server at the same time
|
be connected to the server at the same time
|
||||||
- "is permanent" is a flag which indicates if the server is permanent
|
- "is permanent" is a flag which indicates if the server is permanent
|
||||||
online or not. If this value is any value <> 0 indicates that the server
|
online or not. If this value is any value <> 0 indicates that the server
|
||||||
is permanent online.
|
is permanent online.
|
||||||
- "country" is according to "Common Locale Data Repository" which is used in
|
- "server interal address" represents the IPv4 address as a dotted quad to
|
||||||
the QLocale class
|
be used by clients with the same external IP address as the server.
|
||||||
|
|
||||||
|
|
||||||
- PROTMESSID_CLM_UNREGISTER_SERVER: Unregister a server
|
- PROTMESSID_CLM_UNREGISTER_SERVER: Unregister a server
|
||||||
|
@ -1401,14 +1403,15 @@ bool CProtocol::EvaluateCLServerFullMes()
|
||||||
}
|
}
|
||||||
|
|
||||||
void CProtocol::CreateCLRegisterServerMes ( const CHostAddress& InetAddr,
|
void CProtocol::CreateCLRegisterServerMes ( const CHostAddress& InetAddr,
|
||||||
|
const CHostAddress& LInetAddr,
|
||||||
const CServerCoreInfo& ServerInfo )
|
const CServerCoreInfo& ServerInfo )
|
||||||
{
|
{
|
||||||
int iPos = 0; // init position pointer
|
int iPos = 0; // init position pointer
|
||||||
|
|
||||||
// convert server info strings to utf-8
|
// convert server info strings to utf-8
|
||||||
const QByteArray strUTF8Name = ServerInfo.strName.toUtf8();
|
const QByteArray strUTF8LInetAddr = LInetAddr.InetAddr.toString().toUtf8();
|
||||||
const QByteArray strUTF8Topic = ServerInfo.strTopic.toUtf8();
|
const QByteArray strUTF8Name = ServerInfo.strName.toUtf8();
|
||||||
const QByteArray strUTF8City = ServerInfo.strCity.toUtf8();
|
const QByteArray strUTF8City = ServerInfo.strCity.toUtf8();
|
||||||
|
|
||||||
// size of current message body
|
// size of current message body
|
||||||
const int iEntrLen =
|
const int iEntrLen =
|
||||||
|
@ -1417,7 +1420,7 @@ void CProtocol::CreateCLRegisterServerMes ( const CHostAddress& InetAddr,
|
||||||
1 /* maximum number of connected clients */ +
|
1 /* maximum number of connected clients */ +
|
||||||
1 /* is permanent flag */ +
|
1 /* is permanent flag */ +
|
||||||
2 /* name utf-8 string size */ + strUTF8Name.size() +
|
2 /* name utf-8 string size */ + strUTF8Name.size() +
|
||||||
2 /* topic utf-8 string size */ + strUTF8Topic.size() +
|
2 /* server internal address utf-8 string size */ + strUTF8LInetAddr.size() +
|
||||||
2 /* city utf-8 string size */ + strUTF8City.size();
|
2 /* city utf-8 string size */ + strUTF8City.size();
|
||||||
|
|
||||||
// build data vector
|
// build data vector
|
||||||
|
@ -1442,8 +1445,8 @@ void CProtocol::CreateCLRegisterServerMes ( const CHostAddress& InetAddr,
|
||||||
// name
|
// name
|
||||||
PutStringUTF8OnStream ( vecData, iPos, strUTF8Name );
|
PutStringUTF8OnStream ( vecData, iPos, strUTF8Name );
|
||||||
|
|
||||||
// topic
|
// server internal address (formerly unused topic)
|
||||||
PutStringUTF8OnStream ( vecData, iPos, strUTF8Topic );
|
PutStringUTF8OnStream ( vecData, iPos, strUTF8LInetAddr );
|
||||||
|
|
||||||
// city
|
// city
|
||||||
PutStringUTF8OnStream ( vecData, iPos, strUTF8City );
|
PutStringUTF8OnStream ( vecData, iPos, strUTF8City );
|
||||||
|
@ -1458,6 +1461,8 @@ bool CProtocol::EvaluateCLRegisterServerMes ( const CHostAddress& InetAddr,
|
||||||
{
|
{
|
||||||
int iPos = 0; // init position pointer
|
int iPos = 0; // init position pointer
|
||||||
const int iDataLen = vecData.Size();
|
const int iDataLen = vecData.Size();
|
||||||
|
QString sLocHost; // temp string for server internal address
|
||||||
|
CHostAddress LInetAddr;
|
||||||
CServerCoreInfo RecServerInfo;
|
CServerCoreInfo RecServerInfo;
|
||||||
|
|
||||||
// check size (the first 6 bytes)
|
// check size (the first 6 bytes)
|
||||||
|
@ -1468,7 +1473,7 @@ bool CProtocol::EvaluateCLRegisterServerMes ( const CHostAddress& InetAddr,
|
||||||
|
|
||||||
// port number (2 bytes)
|
// port number (2 bytes)
|
||||||
RecServerInfo.iLocalPortNumber =
|
RecServerInfo.iLocalPortNumber =
|
||||||
static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
|
static_cast<quint16> ( GetValFromStream ( vecData, iPos, 2 ) );
|
||||||
|
|
||||||
// country (2 bytes)
|
// country (2 bytes)
|
||||||
RecServerInfo.eCountry =
|
RecServerInfo.eCountry =
|
||||||
|
@ -1491,11 +1496,21 @@ bool CProtocol::EvaluateCLRegisterServerMes ( const CHostAddress& InetAddr,
|
||||||
return true; // return error code
|
return true; // return error code
|
||||||
}
|
}
|
||||||
|
|
||||||
// server topic
|
// server internal address
|
||||||
if ( GetStringFromStream ( vecData,
|
if ( GetStringFromStream ( vecData,
|
||||||
iPos,
|
iPos,
|
||||||
MAX_LEN_SERVER_TOPIC,
|
MAX_LEN_IP_ADDRESS,
|
||||||
RecServerInfo.strTopic ) )
|
sLocHost ) )
|
||||||
|
{
|
||||||
|
return true; // return error code
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( sLocHost.isEmpty() )
|
||||||
|
{
|
||||||
|
// old server, empty "topic", register as external address
|
||||||
|
LInetAddr = InetAddr;
|
||||||
|
}
|
||||||
|
else if ( !LInetAddr.InetAddr.setAddress( sLocHost ) )
|
||||||
{
|
{
|
||||||
return true; // return error code
|
return true; // return error code
|
||||||
}
|
}
|
||||||
|
@ -1516,7 +1531,7 @@ bool CProtocol::EvaluateCLRegisterServerMes ( const CHostAddress& InetAddr,
|
||||||
}
|
}
|
||||||
|
|
||||||
// invoke message action
|
// invoke message action
|
||||||
emit CLRegisterServerReceived ( InetAddr, RecServerInfo );
|
emit CLRegisterServerReceived ( InetAddr, LInetAddr, RecServerInfo );
|
||||||
|
|
||||||
return false; // no error
|
return false; // no error
|
||||||
}
|
}
|
||||||
|
@ -1548,9 +1563,9 @@ void CProtocol::CreateCLServerListMes ( const CHostAddress& InetAddr,
|
||||||
for ( int i = 0; i < iNumServers; i++ )
|
for ( int i = 0; i < iNumServers; i++ )
|
||||||
{
|
{
|
||||||
// convert server list strings to utf-8
|
// convert server list strings to utf-8
|
||||||
const QByteArray strUTF8Name = vecServerInfo[i].strName.toUtf8();
|
const QByteArray strUTF8Name = vecServerInfo[i].strName.toUtf8();
|
||||||
const QByteArray strUTF8Topic = vecServerInfo[i].strTopic.toUtf8();
|
const QByteArray strUTF8LHostAddr = vecServerInfo[i].LHostAddr.InetAddr.toString().toUtf8();
|
||||||
const QByteArray strUTF8City = vecServerInfo[i].strCity.toUtf8();
|
const QByteArray strUTF8City = vecServerInfo[i].strCity.toUtf8();
|
||||||
|
|
||||||
// size of current list entry
|
// size of current list entry
|
||||||
const int iCurListEntrLen =
|
const int iCurListEntrLen =
|
||||||
|
@ -1560,7 +1575,7 @@ void CProtocol::CreateCLServerListMes ( const CHostAddress& InetAddr,
|
||||||
1 /* maximum number of connected clients */ +
|
1 /* maximum number of connected clients */ +
|
||||||
1 /* is permanent flag */ +
|
1 /* is permanent flag */ +
|
||||||
2 /* name utf-8 string size */ + strUTF8Name.size() +
|
2 /* name utf-8 string size */ + strUTF8Name.size() +
|
||||||
2 /* topic utf-8 string size */ + strUTF8Topic.size() +
|
2 /* server internal address utf-8 string size */ + strUTF8LHostAddr.size() +
|
||||||
2 /* city utf-8 string size */ + strUTF8City.size();
|
2 /* city utf-8 string size */ + strUTF8City.size();
|
||||||
|
|
||||||
// make space for new data
|
// make space for new data
|
||||||
|
@ -1590,7 +1605,7 @@ void CProtocol::CreateCLServerListMes ( const CHostAddress& InetAddr,
|
||||||
PutStringUTF8OnStream ( vecData, iPos, strUTF8Name );
|
PutStringUTF8OnStream ( vecData, iPos, strUTF8Name );
|
||||||
|
|
||||||
// topic
|
// topic
|
||||||
PutStringUTF8OnStream ( vecData, iPos, strUTF8Topic );
|
PutStringUTF8OnStream ( vecData, iPos, strUTF8LHostAddr );
|
||||||
|
|
||||||
// city
|
// city
|
||||||
PutStringUTF8OnStream ( vecData, iPos, strUTF8City );
|
PutStringUTF8OnStream ( vecData, iPos, strUTF8City );
|
||||||
|
@ -1618,11 +1633,11 @@ bool CProtocol::EvaluateCLServerListMes ( const CHostAddress& InetAddr,
|
||||||
|
|
||||||
// IP address (4 bytes)
|
// IP address (4 bytes)
|
||||||
const quint32 iIpAddr =
|
const quint32 iIpAddr =
|
||||||
static_cast<int> ( GetValFromStream ( vecData, iPos, 4 ) );
|
static_cast<quint32> ( GetValFromStream ( vecData, iPos, 4 ) );
|
||||||
|
|
||||||
// port number (2 bytes)
|
// port number (2 bytes)
|
||||||
const quint16 iPort =
|
const quint16 iPort =
|
||||||
static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
|
static_cast<quint16> ( GetValFromStream ( vecData, iPos, 2 ) );
|
||||||
|
|
||||||
// country (2 bytes)
|
// country (2 bytes)
|
||||||
const QLocale::Country eCountry =
|
const QLocale::Country eCountry =
|
||||||
|
@ -1646,12 +1661,23 @@ bool CProtocol::EvaluateCLServerListMes ( const CHostAddress& InetAddr,
|
||||||
return true; // return error code
|
return true; // return error code
|
||||||
}
|
}
|
||||||
|
|
||||||
// server topic
|
// server internal address
|
||||||
QString strTopic;
|
QString strLHostAddr;
|
||||||
if ( GetStringFromStream ( vecData,
|
if ( GetStringFromStream ( vecData,
|
||||||
iPos,
|
iPos,
|
||||||
MAX_LEN_SERVER_TOPIC,
|
MAX_LEN_IP_ADDRESS,
|
||||||
strTopic ) )
|
strLHostAddr ) )
|
||||||
|
{
|
||||||
|
return true; // return error code
|
||||||
|
}
|
||||||
|
|
||||||
|
CHostAddress LInetAddr;
|
||||||
|
if ( strLHostAddr.isEmpty() )
|
||||||
|
{
|
||||||
|
// old central server, empty "topic", default to server address
|
||||||
|
LInetAddr.InetAddr.setAddress( iIpAddr );
|
||||||
|
}
|
||||||
|
else if ( !LInetAddr.InetAddr.setAddress( strLHostAddr ) )
|
||||||
{
|
{
|
||||||
return true; // return error code
|
return true; // return error code
|
||||||
}
|
}
|
||||||
|
@ -1669,9 +1695,9 @@ bool CProtocol::EvaluateCLServerListMes ( const CHostAddress& InetAddr,
|
||||||
// add server information to vector
|
// add server information to vector
|
||||||
vecServerInfo.Add (
|
vecServerInfo.Add (
|
||||||
CServerInfo ( CHostAddress ( QHostAddress ( iIpAddr ), iPort ),
|
CServerInfo ( CHostAddress ( QHostAddress ( iIpAddr ), iPort ),
|
||||||
|
LInetAddr,
|
||||||
iPort,
|
iPort,
|
||||||
strName,
|
strName,
|
||||||
strTopic,
|
|
||||||
eCountry,
|
eCountry,
|
||||||
strCity,
|
strCity,
|
||||||
iMaxNumClients,
|
iMaxNumClients,
|
||||||
|
|
|
@ -112,6 +112,7 @@ public:
|
||||||
const int iNumClients );
|
const int iNumClients );
|
||||||
void CreateCLServerFullMes ( const CHostAddress& InetAddr );
|
void CreateCLServerFullMes ( const CHostAddress& InetAddr );
|
||||||
void CreateCLRegisterServerMes ( const CHostAddress& InetAddr,
|
void CreateCLRegisterServerMes ( const CHostAddress& InetAddr,
|
||||||
|
const CHostAddress& LInetAddr,
|
||||||
const CServerCoreInfo& ServerInfo );
|
const CServerCoreInfo& ServerInfo );
|
||||||
void CreateCLUnregisterServerMes ( const CHostAddress& InetAddr );
|
void CreateCLUnregisterServerMes ( const CHostAddress& InetAddr );
|
||||||
void CreateCLServerListMes ( const CHostAddress& InetAddr,
|
void CreateCLServerListMes ( const CHostAddress& InetAddr,
|
||||||
|
@ -287,6 +288,7 @@ signals:
|
||||||
int iMs,
|
int iMs,
|
||||||
int iNumClients );
|
int iNumClients );
|
||||||
void CLRegisterServerReceived ( CHostAddress InetAddr,
|
void CLRegisterServerReceived ( CHostAddress InetAddr,
|
||||||
|
CHostAddress LInetAddr,
|
||||||
CServerCoreInfo ServerInfo );
|
CServerCoreInfo ServerInfo );
|
||||||
void CLUnregisterServerReceived ( CHostAddress InetAddr );
|
void CLUnregisterServerReceived ( CHostAddress InetAddr );
|
||||||
void CLServerListReceived ( CHostAddress InetAddr,
|
void CLServerListReceived ( CHostAddress InetAddr,
|
||||||
|
|
|
@ -427,8 +427,8 @@ CServer::CServer ( const int iNewMaxNumChan,
|
||||||
this, SLOT ( OnCLPingWithNumClientsReceived ( CHostAddress, int, int ) ) );
|
this, SLOT ( OnCLPingWithNumClientsReceived ( CHostAddress, int, int ) ) );
|
||||||
|
|
||||||
QObject::connect ( &ConnLessProtocol,
|
QObject::connect ( &ConnLessProtocol,
|
||||||
SIGNAL ( CLRegisterServerReceived ( CHostAddress, CServerCoreInfo ) ),
|
SIGNAL ( CLRegisterServerReceived ( CHostAddress, CHostAddress, CServerCoreInfo ) ),
|
||||||
this, SLOT ( OnCLRegisterServerReceived ( CHostAddress, CServerCoreInfo ) ) );
|
this, SLOT ( OnCLRegisterServerReceived ( CHostAddress, CHostAddress, CServerCoreInfo ) ) );
|
||||||
|
|
||||||
QObject::connect ( &ConnLessProtocol,
|
QObject::connect ( &ConnLessProtocol,
|
||||||
SIGNAL ( CLUnregisterServerReceived ( CHostAddress ) ),
|
SIGNAL ( CLUnregisterServerReceived ( CHostAddress ) ),
|
||||||
|
|
|
@ -367,9 +367,10 @@ public slots:
|
||||||
{ ConnLessProtocol.CreateCLConnClientsListMes ( InetAddr, CreateChannelList() ); }
|
{ ConnLessProtocol.CreateCLConnClientsListMes ( InetAddr, CreateChannelList() ); }
|
||||||
|
|
||||||
void OnCLRegisterServerReceived ( CHostAddress InetAddr,
|
void OnCLRegisterServerReceived ( CHostAddress InetAddr,
|
||||||
|
CHostAddress LInetAddr,
|
||||||
CServerCoreInfo ServerInfo )
|
CServerCoreInfo ServerInfo )
|
||||||
{
|
{
|
||||||
ServerListManager.CentralServerRegisterServer ( InetAddr, ServerInfo );
|
ServerListManager.CentralServerRegisterServer ( InetAddr, LInetAddr, ServerInfo );
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnCLUnregisterServerReceived ( CHostAddress InetAddr )
|
void OnCLUnregisterServerReceived ( CHostAddress InetAddr )
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
|
|
||||||
#include "serverlist.h"
|
#include "serverlist.h"
|
||||||
|
|
||||||
|
|
||||||
/* Implementation *************************************************************/
|
/* Implementation *************************************************************/
|
||||||
CServerListManager::CServerListManager ( const quint16 iNPortNum,
|
CServerListManager::CServerListManager ( const quint16 iNPortNum,
|
||||||
const QString& sNCentServAddr,
|
const QString& sNCentServAddr,
|
||||||
|
@ -41,6 +40,9 @@ CServerListManager::CServerListManager ( const quint16 iNPortNum,
|
||||||
// set the central server address
|
// set the central server address
|
||||||
SetCentralServerAddress ( sNCentServAddr );
|
SetCentralServerAddress ( sNCentServAddr );
|
||||||
|
|
||||||
|
// set the server internal address
|
||||||
|
SlaveCurLocalHostAddress = CHostAddress( NetworkUtil::GetLocalAddress().InetAddr, iNPortNum );
|
||||||
|
|
||||||
// prepare the server info information
|
// prepare the server info information
|
||||||
QStringList slServInfoSeparateParams;
|
QStringList slServInfoSeparateParams;
|
||||||
int iServInfoNumSplitItems = 0;
|
int iServInfoNumSplitItems = 0;
|
||||||
|
@ -63,9 +65,9 @@ CServerListManager::CServerListManager ( const quint16 iNPortNum,
|
||||||
// itself for his server list. If we are the central server, we assume that
|
// itself for his server list. If we are the central server, we assume that
|
||||||
// we have a permanent server.
|
// we have a permanent server.
|
||||||
CServerListEntry ThisServerListEntry ( CHostAddress(),
|
CServerListEntry ThisServerListEntry ( CHostAddress(),
|
||||||
|
SlaveCurLocalHostAddress,
|
||||||
iPortNumber,
|
iPortNumber,
|
||||||
"",
|
"",
|
||||||
"",
|
|
||||||
QLocale::system().country(),
|
QLocale::system().country(),
|
||||||
"",
|
"",
|
||||||
iNumChannels,
|
iNumChannels,
|
||||||
|
@ -112,9 +114,9 @@ CServerListManager::CServerListManager ( const quint16 iNPortNum,
|
||||||
// create a new server list entry, we assume that servers which are
|
// create a new server list entry, we assume that servers which are
|
||||||
// registered via the command line are permanent servers
|
// registered via the command line are permanent servers
|
||||||
CServerListEntry NewServerListEntry ( CHostAddress(),
|
CServerListEntry NewServerListEntry ( CHostAddress(),
|
||||||
|
CHostAddress(),
|
||||||
0, // port number not used
|
0, // port number not used
|
||||||
"",
|
"",
|
||||||
"",
|
|
||||||
QLocale::AnyCountry,
|
QLocale::AnyCountry,
|
||||||
"",
|
"",
|
||||||
iNumChannels,
|
iNumChannels,
|
||||||
|
@ -125,6 +127,10 @@ CServerListManager::CServerListManager ( const quint16 iNPortNum,
|
||||||
slServInfoSeparateParams[iCurUsedServInfoSplitItems],
|
slServInfoSeparateParams[iCurUsedServInfoSplitItems],
|
||||||
NewServerListEntry.HostAddr );
|
NewServerListEntry.HostAddr );
|
||||||
|
|
||||||
|
// [server n server internal address]
|
||||||
|
// Not included in the static server info, so use external address
|
||||||
|
NewServerListEntry.LHostAddr = NewServerListEntry.HostAddr;
|
||||||
|
|
||||||
// [server n name]
|
// [server n name]
|
||||||
NewServerListEntry.strName =
|
NewServerListEntry.strName =
|
||||||
slServInfoSeparateParams[iCurUsedServInfoSplitItems + 1];
|
slServInfoSeparateParams[iCurUsedServInfoSplitItems + 1];
|
||||||
|
@ -307,6 +313,7 @@ void CServerListManager::OnTimerPollList()
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerListManager::CentralServerRegisterServer ( const CHostAddress& InetAddr,
|
void CServerListManager::CentralServerRegisterServer ( const CHostAddress& InetAddr,
|
||||||
|
const CHostAddress& LInetAddr,
|
||||||
const CServerCoreInfo& ServerInfo )
|
const CServerCoreInfo& ServerInfo )
|
||||||
{
|
{
|
||||||
QMutexLocker locker ( &Mutex );
|
QMutexLocker locker ( &Mutex );
|
||||||
|
@ -321,8 +328,8 @@ void CServerListManager::CentralServerRegisterServer ( const CHostAddress& In
|
||||||
// define invalid index used as a flag
|
// define invalid index used as a flag
|
||||||
const int ciInvalidIdx = -1;
|
const int ciInvalidIdx = -1;
|
||||||
|
|
||||||
// Check if server is already registered. Use address to identify
|
// Check if server is already registered.
|
||||||
// a server. The very first list entry must not be checked since
|
// The very first list entry must not be checked since
|
||||||
// this is per definition the central server (i.e., this server)
|
// this is per definition the central server (i.e., this server)
|
||||||
int iSelIdx = ciInvalidIdx; // initialize with an illegal value
|
int iSelIdx = ciInvalidIdx; // initialize with an illegal value
|
||||||
for ( int iIdx = 1; iIdx < iCurServerListSize; iIdx++ )
|
for ( int iIdx = 1; iIdx < iCurServerListSize; iIdx++ )
|
||||||
|
@ -341,7 +348,7 @@ void CServerListManager::CentralServerRegisterServer ( const CHostAddress& In
|
||||||
if ( iSelIdx == ciInvalidIdx )
|
if ( iSelIdx == ciInvalidIdx )
|
||||||
{
|
{
|
||||||
// create a new server list entry and init with received data
|
// create a new server list entry and init with received data
|
||||||
ServerList.append ( CServerListEntry ( InetAddr, ServerInfo ) );
|
ServerList.append ( CServerListEntry ( InetAddr, LInetAddr, ServerInfo ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -349,9 +356,8 @@ void CServerListManager::CentralServerRegisterServer ( const CHostAddress& In
|
||||||
if ( iSelIdx > iNumPredefinedServers )
|
if ( iSelIdx > iNumPredefinedServers )
|
||||||
{
|
{
|
||||||
// update all data and call update registration function
|
// update all data and call update registration function
|
||||||
ServerList[iSelIdx].iLocalPortNumber = ServerInfo.iLocalPortNumber;
|
ServerList[iSelIdx].LHostAddr = LInetAddr;
|
||||||
ServerList[iSelIdx].strName = ServerInfo.strName;
|
ServerList[iSelIdx].strName = ServerInfo.strName;
|
||||||
ServerList[iSelIdx].strTopic = ServerInfo.strTopic;
|
|
||||||
ServerList[iSelIdx].eCountry = ServerInfo.eCountry;
|
ServerList[iSelIdx].eCountry = ServerInfo.eCountry;
|
||||||
ServerList[iSelIdx].strCity = ServerInfo.strCity;
|
ServerList[iSelIdx].strCity = ServerInfo.strCity;
|
||||||
ServerList[iSelIdx].iMaxNumClients = ServerInfo.iMaxNumClients;
|
ServerList[iSelIdx].iMaxNumClients = ServerInfo.iMaxNumClients;
|
||||||
|
@ -415,20 +421,19 @@ void CServerListManager::CentralServerQueryServerList ( const CHostAddress& Inet
|
||||||
{
|
{
|
||||||
// check if the address of the client which is requesting the
|
// check if the address of the client which is requesting the
|
||||||
// list is the same address as one server in the list -> in this
|
// list is the same address as one server in the list -> in this
|
||||||
// case he has to connect to the local host address
|
// case he has to connect to the local host address and port
|
||||||
|
// to allow for NAT.
|
||||||
if ( vecServerInfo[iIdx].HostAddr.InetAddr == InetAddr.InetAddr )
|
if ( vecServerInfo[iIdx].HostAddr.InetAddr == InetAddr.InetAddr )
|
||||||
{
|
{
|
||||||
vecServerInfo[iIdx].HostAddr.InetAddr =
|
// for a predefined server:
|
||||||
QHostAddress ( QHostAddress::LocalHost );
|
// - LHostAddr and HostAddr are the same
|
||||||
|
// - no local port number is supplied
|
||||||
// take the local port number instead of the received port
|
// otherwise, use the supplied details
|
||||||
// number since some NAT (network address translation) might
|
|
||||||
// have changed the port, note that the predefined servers
|
|
||||||
// are treated differently, for these we assume that the
|
|
||||||
// received port number is the same as the actual port
|
|
||||||
// number
|
|
||||||
if ( iIdx > iNumPredefinedServers )
|
if ( iIdx > iNumPredefinedServers )
|
||||||
{
|
{
|
||||||
|
vecServerInfo[iIdx].HostAddr.InetAddr =
|
||||||
|
ServerList[iIdx].LHostAddr.InetAddr;
|
||||||
|
|
||||||
vecServerInfo[iIdx].HostAddr.iPort =
|
vecServerInfo[iIdx].HostAddr.iPort =
|
||||||
ServerList[iIdx].iLocalPortNumber;
|
ServerList[iIdx].iLocalPortNumber;
|
||||||
}
|
}
|
||||||
|
@ -491,6 +496,7 @@ void CServerListManager::SlaveServerRegisterServer ( const bool bIsRegister )
|
||||||
{
|
{
|
||||||
// register server
|
// register server
|
||||||
pConnLessProtocol->CreateCLRegisterServerMes ( SlaveCurCentServerHostAddress,
|
pConnLessProtocol->CreateCLRegisterServerMes ( SlaveCurCentServerHostAddress,
|
||||||
|
SlaveCurLocalHostAddress,
|
||||||
ServerList[0] );
|
ServerList[0] );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -75,37 +75,38 @@ class CServerListEntry : public CServerInfo
|
||||||
public:
|
public:
|
||||||
CServerListEntry() :
|
CServerListEntry() :
|
||||||
CServerInfo ( CHostAddress(),
|
CServerInfo ( CHostAddress(),
|
||||||
|
CHostAddress(),
|
||||||
0,
|
0,
|
||||||
"",
|
"",
|
||||||
"",
|
|
||||||
QLocale::AnyCountry,
|
QLocale::AnyCountry,
|
||||||
"",
|
"",
|
||||||
0,
|
0,
|
||||||
false ) { UpdateRegistration(); }
|
false ) { UpdateRegistration(); }
|
||||||
|
|
||||||
CServerListEntry ( const CHostAddress& NHAddr,
|
CServerListEntry ( const CHostAddress& NHAddr,
|
||||||
|
const CHostAddress& NLHAddr,
|
||||||
const quint16 NLocPort,
|
const quint16 NLocPort,
|
||||||
const QString& NsName,
|
const QString& NsName,
|
||||||
const QString& NsTopic,
|
|
||||||
const QLocale::Country& NeCountry,
|
const QLocale::Country& NeCountry,
|
||||||
const QString& NsCity,
|
const QString& NsCity,
|
||||||
const int NiMaxNumClients,
|
const int NiMaxNumClients,
|
||||||
const bool NbPermOnline)
|
const bool NbPermOnline)
|
||||||
: CServerInfo ( NHAddr,
|
: CServerInfo ( NHAddr,
|
||||||
|
NLHAddr,
|
||||||
NLocPort,
|
NLocPort,
|
||||||
NsName,
|
NsName,
|
||||||
NsTopic,
|
|
||||||
NeCountry,
|
NeCountry,
|
||||||
NsCity,
|
NsCity,
|
||||||
NiMaxNumClients,
|
NiMaxNumClients,
|
||||||
NbPermOnline ) { UpdateRegistration(); }
|
NbPermOnline ) { UpdateRegistration(); }
|
||||||
|
|
||||||
CServerListEntry ( const CHostAddress& NHAddr,
|
CServerListEntry ( const CHostAddress& NHAddr,
|
||||||
|
const CHostAddress& NLHAddr,
|
||||||
const CServerCoreInfo& NewCoreServerInfo )
|
const CServerCoreInfo& NewCoreServerInfo )
|
||||||
: CServerInfo ( NHAddr,
|
: CServerInfo ( NHAddr,
|
||||||
|
NLHAddr,
|
||||||
NewCoreServerInfo.iLocalPortNumber,
|
NewCoreServerInfo.iLocalPortNumber,
|
||||||
NewCoreServerInfo.strName,
|
NewCoreServerInfo.strName,
|
||||||
NewCoreServerInfo.strTopic,
|
|
||||||
NewCoreServerInfo.eCountry,
|
NewCoreServerInfo.eCountry,
|
||||||
NewCoreServerInfo.strCity,
|
NewCoreServerInfo.strCity,
|
||||||
NewCoreServerInfo.iMaxNumClients,
|
NewCoreServerInfo.iMaxNumClients,
|
||||||
|
@ -150,6 +151,7 @@ public:
|
||||||
bool GetIsCentralServer() const { return bIsCentralServer; }
|
bool GetIsCentralServer() const { return bIsCentralServer; }
|
||||||
|
|
||||||
void CentralServerRegisterServer ( const CHostAddress& InetAddr,
|
void CentralServerRegisterServer ( const CHostAddress& InetAddr,
|
||||||
|
const CHostAddress& LInetAddr,
|
||||||
const CServerCoreInfo& ServerInfo );
|
const CServerCoreInfo& ServerInfo );
|
||||||
|
|
||||||
void CentralServerUnregisterServer ( const CHostAddress& InetAddr );
|
void CentralServerUnregisterServer ( const CHostAddress& InetAddr );
|
||||||
|
@ -197,6 +199,7 @@ protected:
|
||||||
bool bCentServPingServerInList;
|
bool bCentServPingServerInList;
|
||||||
|
|
||||||
CHostAddress SlaveCurCentServerHostAddress;
|
CHostAddress SlaveCurCentServerHostAddress;
|
||||||
|
CHostAddress SlaveCurLocalHostAddress;
|
||||||
|
|
||||||
CProtocol* pConnLessProtocol;
|
CProtocol* pConnLessProtocol;
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,15 @@ protected:
|
||||||
return strReturn;
|
return strReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QHostAddress GenRandomIPv4Address() const
|
||||||
|
{
|
||||||
|
quint32 a = static_cast<quint32> ( 192 );
|
||||||
|
quint32 b = static_cast<quint32> ( 168 );
|
||||||
|
quint32 c = static_cast<quint32> ( GenRandomIntInRange ( 1, 253 ) );
|
||||||
|
quint32 d = static_cast<quint32> ( GenRandomIntInRange ( 1, 253 ) );
|
||||||
|
return QHostAddress( a << 24 | b << 16 | c << 8 | d );
|
||||||
|
}
|
||||||
|
|
||||||
QString sAddress;
|
QString sAddress;
|
||||||
quint16 iPort;
|
quint16 iPort;
|
||||||
QTimer Timer;
|
QTimer Timer;
|
||||||
|
@ -102,6 +111,7 @@ public slots:
|
||||||
CServerCoreInfo ServerInfo;
|
CServerCoreInfo ServerInfo;
|
||||||
CVector<CServerInfo> vecServerInfo ( 1 );
|
CVector<CServerInfo> vecServerInfo ( 1 );
|
||||||
CHostAddress CurHostAddress ( QHostAddress ( sAddress ), iPort );
|
CHostAddress CurHostAddress ( QHostAddress ( sAddress ), iPort );
|
||||||
|
CHostAddress CurLocalAddress ( GenRandomIPv4Address(), iPort );
|
||||||
CChannelCoreInfo ChannelCoreInfo;
|
CChannelCoreInfo ChannelCoreInfo;
|
||||||
ELicenceType eLicenceType;
|
ELicenceType eLicenceType;
|
||||||
|
|
||||||
|
@ -123,7 +133,7 @@ public slots:
|
||||||
|
|
||||||
case 4: // PROTMESSID_CONN_CLIENTS_LIST
|
case 4: // PROTMESSID_CONN_CLIENTS_LIST
|
||||||
vecChanInfo[0].iChanID = GenRandomIntInRange ( -2, 20 );
|
vecChanInfo[0].iChanID = GenRandomIntInRange ( -2, 20 );
|
||||||
vecChanInfo[0].iIpAddr = GenRandomIntInRange ( 0, 100000 );
|
vecChanInfo[0].iIpAddr = GenRandomIPv4Address().toIPv4Address();
|
||||||
vecChanInfo[0].strName = GenRandomString();
|
vecChanInfo[0].strName = GenRandomString();
|
||||||
|
|
||||||
Protocol.CreateConClientListMes ( vecChanInfo );
|
Protocol.CreateConClientListMes ( vecChanInfo );
|
||||||
|
@ -206,9 +216,9 @@ public slots:
|
||||||
ServerInfo.iMaxNumClients = GenRandomIntInRange ( -2, 10000 );
|
ServerInfo.iMaxNumClients = GenRandomIntInRange ( -2, 10000 );
|
||||||
ServerInfo.strCity = GenRandomString();
|
ServerInfo.strCity = GenRandomString();
|
||||||
ServerInfo.strName = GenRandomString();
|
ServerInfo.strName = GenRandomString();
|
||||||
ServerInfo.strTopic = GenRandomString();
|
|
||||||
|
|
||||||
Protocol.CreateCLRegisterServerMes ( CurHostAddress,
|
Protocol.CreateCLRegisterServerMes ( CurHostAddress,
|
||||||
|
CurLocalAddress,
|
||||||
ServerInfo );
|
ServerInfo );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -224,11 +234,11 @@ public slots:
|
||||||
static_cast<QLocale::Country> ( GenRandomIntInRange ( 0, 100 ) );
|
static_cast<QLocale::Country> ( GenRandomIntInRange ( 0, 100 ) );
|
||||||
|
|
||||||
vecServerInfo[0].HostAddr = CurHostAddress;
|
vecServerInfo[0].HostAddr = CurHostAddress;
|
||||||
|
vecServerInfo[0].LHostAddr = CurLocalAddress;
|
||||||
vecServerInfo[0].iLocalPortNumber = GenRandomIntInRange ( -2, 10000 );
|
vecServerInfo[0].iLocalPortNumber = GenRandomIntInRange ( -2, 10000 );
|
||||||
vecServerInfo[0].iMaxNumClients = GenRandomIntInRange ( -2, 10000 );
|
vecServerInfo[0].iMaxNumClients = GenRandomIntInRange ( -2, 10000 );
|
||||||
vecServerInfo[0].strCity = GenRandomString();
|
vecServerInfo[0].strCity = GenRandomString();
|
||||||
vecServerInfo[0].strName = GenRandomString();
|
vecServerInfo[0].strName = GenRandomString();
|
||||||
vecServerInfo[0].strTopic = GenRandomString();
|
|
||||||
|
|
||||||
Protocol.CreateCLServerListMes ( CurHostAddress,
|
Protocol.CreateCLServerListMes ( CurHostAddress,
|
||||||
vecServerInfo );
|
vecServerInfo );
|
||||||
|
|
14
src/util.cpp
14
src/util.cpp
|
@ -890,6 +890,20 @@ bool NetworkUtil::ParseNetworkAddress ( QString strAddress,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CHostAddress NetworkUtil::GetLocalAddress()
|
||||||
|
{
|
||||||
|
QTcpSocket socket;
|
||||||
|
socket.connectToHost( WELL_KNOWN_HOST, WELL_KNOWN_PORT );
|
||||||
|
if (socket.waitForConnected( IP_LOOKUP_TIMEOUT )) {
|
||||||
|
return CHostAddress( socket.localAddress(), 0 );
|
||||||
|
} else {
|
||||||
|
qWarning()
|
||||||
|
<< "could not determine local IPv4 address:"
|
||||||
|
<< socket.errorString()
|
||||||
|
<< "- using localhost";
|
||||||
|
return CHostAddress( QHostAddress::LocalHost, 0 );
|
||||||
|
}
|
||||||
|
}
|
||||||
// Instrument picture data base ------------------------------------------------
|
// Instrument picture data base ------------------------------------------------
|
||||||
CVector<CInstPictures::CInstPictProps>& CInstPictures::GetTable()
|
CVector<CInstPictures::CInstPictProps>& CInstPictures::GetTable()
|
||||||
{
|
{
|
||||||
|
|
23
src/util.h
23
src/util.h
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <QTcpSocket>
|
||||||
#include <QHostAddress>
|
#include <QHostAddress>
|
||||||
#include <QHostInfo>
|
#include <QHostInfo>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
@ -861,7 +862,6 @@ public:
|
||||||
CServerCoreInfo() :
|
CServerCoreInfo() :
|
||||||
iLocalPortNumber ( 0 ),
|
iLocalPortNumber ( 0 ),
|
||||||
strName ( "" ),
|
strName ( "" ),
|
||||||
strTopic ( "" ),
|
|
||||||
eCountry ( QLocale::AnyCountry ),
|
eCountry ( QLocale::AnyCountry ),
|
||||||
strCity ( "" ),
|
strCity ( "" ),
|
||||||
iMaxNumClients ( 0 ),
|
iMaxNumClients ( 0 ),
|
||||||
|
@ -870,14 +870,12 @@ public:
|
||||||
CServerCoreInfo (
|
CServerCoreInfo (
|
||||||
const quint16 NLocPort,
|
const quint16 NLocPort,
|
||||||
const QString& NsName,
|
const QString& NsName,
|
||||||
const QString& NsTopic,
|
|
||||||
const QLocale::Country& NeCountry,
|
const QLocale::Country& NeCountry,
|
||||||
const QString& NsCity,
|
const QString& NsCity,
|
||||||
const int NiMaxNumClients,
|
const int NiMaxNumClients,
|
||||||
const bool NbPermOnline) :
|
const bool NbPermOnline) :
|
||||||
iLocalPortNumber ( NLocPort ),
|
iLocalPortNumber ( NLocPort ),
|
||||||
strName ( NsName ),
|
strName ( NsName ),
|
||||||
strTopic ( NsTopic ),
|
|
||||||
eCountry ( NeCountry ),
|
eCountry ( NeCountry ),
|
||||||
strCity ( NsCity ),
|
strCity ( NsCity ),
|
||||||
iMaxNumClients ( NiMaxNumClients ),
|
iMaxNumClients ( NiMaxNumClients ),
|
||||||
|
@ -889,9 +887,6 @@ public:
|
||||||
// name of the server
|
// name of the server
|
||||||
QString strName;
|
QString strName;
|
||||||
|
|
||||||
// topic of the current jam session or server
|
|
||||||
QString strTopic;
|
|
||||||
|
|
||||||
// country in which the server is located
|
// country in which the server is located
|
||||||
QLocale::Country eCountry;
|
QLocale::Country eCountry;
|
||||||
|
|
||||||
|
@ -910,27 +905,33 @@ class CServerInfo : public CServerCoreInfo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CServerInfo() :
|
CServerInfo() :
|
||||||
HostAddr ( CHostAddress() ) {}
|
HostAddr ( CHostAddress() ),
|
||||||
|
LHostAddr ( CHostAddress() )
|
||||||
|
{}
|
||||||
|
|
||||||
CServerInfo (
|
CServerInfo (
|
||||||
const CHostAddress& NHAddr,
|
const CHostAddress& NHAddr,
|
||||||
|
const CHostAddress& NLAddr,
|
||||||
const quint16 NLocPort,
|
const quint16 NLocPort,
|
||||||
const QString& NsName,
|
const QString& NsName,
|
||||||
const QString& NsTopic,
|
|
||||||
const QLocale::Country& NeCountry,
|
const QLocale::Country& NeCountry,
|
||||||
const QString& NsCity,
|
const QString& NsCity,
|
||||||
const int NiMaxNumClients,
|
const int NiMaxNumClients,
|
||||||
const bool NbPermOnline) :
|
const bool NbPermOnline) :
|
||||||
CServerCoreInfo ( NLocPort,
|
CServerCoreInfo ( NLocPort,
|
||||||
NsName,
|
NsName,
|
||||||
NsTopic,
|
|
||||||
NeCountry,
|
NeCountry,
|
||||||
NsCity,
|
NsCity,
|
||||||
NiMaxNumClients,
|
NiMaxNumClients,
|
||||||
NbPermOnline ), HostAddr ( NHAddr ) {}
|
NbPermOnline ),
|
||||||
|
HostAddr ( NHAddr ),
|
||||||
|
LHostAddr ( NLAddr ) {}
|
||||||
|
|
||||||
// internet address of the server
|
// internet address of the server
|
||||||
CHostAddress HostAddr;
|
CHostAddress HostAddr;
|
||||||
|
|
||||||
|
// server internal address
|
||||||
|
CHostAddress LHostAddr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -977,6 +978,8 @@ class NetworkUtil
|
||||||
public:
|
public:
|
||||||
static bool ParseNetworkAddress ( QString strAddress,
|
static bool ParseNetworkAddress ( QString strAddress,
|
||||||
CHostAddress& HostAddress );
|
CHostAddress& HostAddress );
|
||||||
|
|
||||||
|
static CHostAddress GetLocalAddress();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue