first working initial server list implementation
This commit is contained in:
parent
da9af48062
commit
a238cd9569
10 changed files with 62 additions and 28 deletions
|
@ -45,9 +45,6 @@ CConnectDlg::CConnectDlg ( QWidget* parent, Qt::WindowFlags f )
|
||||||
ListViewServers->setColumnWidth ( 3, 80 );
|
ListViewServers->setColumnWidth ( 3, 80 );
|
||||||
ListViewServers->clear();
|
ListViewServers->clear();
|
||||||
|
|
||||||
// TEST
|
|
||||||
pListViewItem = new QTreeWidgetItem ( ListViewServers );
|
|
||||||
|
|
||||||
|
|
||||||
// Connections -------------------------------------------------------------
|
// Connections -------------------------------------------------------------
|
||||||
// timers
|
// timers
|
||||||
|
@ -108,14 +105,36 @@ void CConnectDlg::OnTimerReRequestServList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConnectDlg::SetServerList ( const CVector<CServerInfo>& vecServerInfo )
|
void CConnectDlg::SetServerList ( const CHostAddress& InetAddr,
|
||||||
|
const CVector<CServerInfo>& vecServerInfo )
|
||||||
{
|
{
|
||||||
// set flag
|
// set flag
|
||||||
bServerListReceived = true;
|
bServerListReceived = true;
|
||||||
|
|
||||||
|
// first clear list
|
||||||
|
ListViewServers->clear();
|
||||||
|
|
||||||
// TODO
|
// add list item for each server in the server list
|
||||||
|
for ( int iIdx = 0; iIdx < vecServerInfo.Size(); iIdx++ )
|
||||||
|
{
|
||||||
|
QTreeWidgetItem* pNewListViewItem =
|
||||||
|
new QTreeWidgetItem ( ListViewServers );
|
||||||
|
|
||||||
|
// server name
|
||||||
|
pNewListViewItem->setText ( 0, vecServerInfo[iIdx].strName );
|
||||||
|
|
||||||
|
// server country
|
||||||
|
pNewListViewItem->setText ( 1,
|
||||||
|
QLocale::countryToString ( vecServerInfo[iIdx].eCountry ) );
|
||||||
|
|
||||||
|
// number of clients
|
||||||
|
pNewListViewItem->setText ( 2,
|
||||||
|
QString().setNum ( vecServerInfo[iIdx].iNumClients ) );
|
||||||
|
|
||||||
|
// store host address
|
||||||
|
pNewListViewItem->setData ( 0, Qt::UserRole,
|
||||||
|
vecServerInfo[iIdx].HostAddr.toString() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConnectDlg::OnTimerPing()
|
void CConnectDlg::OnTimerPing()
|
||||||
|
@ -129,10 +148,11 @@ void CConnectDlg::OnTimerPing()
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConnectDlg::SetPingTimeResult ( CHostAddress& InetAddr,
|
void CConnectDlg::SetPingTimeResult ( CHostAddress& InetAddr,
|
||||||
const int iPingTime )
|
const int iPingTime )
|
||||||
{
|
{
|
||||||
|
|
||||||
// TEST
|
// ListViewServers->
|
||||||
pListViewItem->setText ( 0, QString().setNum ( iPingTime ) );
|
//// TEST
|
||||||
|
//pListViewItem->setText ( 0, QString().setNum ( iPingTime ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include <qwhatsthis.h>
|
#include <qwhatsthis.h>
|
||||||
#include <qtimer.h>
|
#include <qtimer.h>
|
||||||
#include <qmutex.h>
|
#include <qmutex.h>
|
||||||
|
#include <qlocale.h>
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -55,7 +56,9 @@ class CConnectDlg : public QDialog, private Ui_CConnectDlgBase
|
||||||
public:
|
public:
|
||||||
CConnectDlg ( QWidget* parent = 0, Qt::WindowFlags f = 0 );
|
CConnectDlg ( QWidget* parent = 0, Qt::WindowFlags f = 0 );
|
||||||
|
|
||||||
void SetServerList ( const CVector<CServerInfo>& vecServerInfo );
|
void SetServerList ( const CHostAddress& InetAddr,
|
||||||
|
const CVector<CServerInfo>& vecServerInfo );
|
||||||
|
|
||||||
void SetPingTimeResult ( CHostAddress& InetAddr, const int iPingTime );
|
void SetPingTimeResult ( CHostAddress& InetAddr, const int iPingTime );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -67,10 +70,6 @@ protected:
|
||||||
CHostAddress CentralServerAddress;
|
CHostAddress CentralServerAddress;
|
||||||
bool bServerListReceived;
|
bool bServerListReceived;
|
||||||
|
|
||||||
// TEST
|
|
||||||
QTreeWidgetItem* pListViewItem;
|
|
||||||
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void OnTimerPing();
|
void OnTimerPing();
|
||||||
void OnTimerReRequestServList();
|
void OnTimerReRequestServList();
|
||||||
|
|
|
@ -443,7 +443,7 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP,
|
||||||
QObject::connect ( &ChatDlg, SIGNAL ( NewLocalInputText ( QString ) ),
|
QObject::connect ( &ChatDlg, SIGNAL ( NewLocalInputText ( QString ) ),
|
||||||
this, SLOT ( OnNewLocalInputText ( QString ) ) );
|
this, SLOT ( OnNewLocalInputText ( QString ) ) );
|
||||||
|
|
||||||
QObject::connect ( &ConnectDlg, SIGNAL ( NewLocalInputText ( CHostAddress ) ),
|
QObject::connect ( &ConnectDlg, SIGNAL ( ReqServerListQuery ( CHostAddress ) ),
|
||||||
this, SLOT ( OnReqServerListQuery ( CHostAddress ) ) );
|
this, SLOT ( OnReqServerListQuery ( CHostAddress ) ) );
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -145,7 +145,7 @@ public slots:
|
||||||
|
|
||||||
void OnCLServerListReceived ( CHostAddress InetAddr,
|
void OnCLServerListReceived ( CHostAddress InetAddr,
|
||||||
CVector<CServerInfo> vecServerInfo )
|
CVector<CServerInfo> vecServerInfo )
|
||||||
{ ConnectDlg.SetServerList ( vecServerInfo ); }
|
{ ConnectDlg.SetServerList ( InetAddr, vecServerInfo ); }
|
||||||
|
|
||||||
void OnLineEditServerAddrTextChanged ( const QString );
|
void OnLineEditServerAddrTextChanged ( const QString );
|
||||||
void OnLineEditServerAddrActivated ( int index );
|
void OnLineEditServerAddrActivated ( int index );
|
||||||
|
|
|
@ -58,13 +58,13 @@ public:
|
||||||
CLlconServerDlg ( CServer* pNServP, QWidget* parent = 0 );
|
CLlconServerDlg ( CServer* pNServP, QWidget* parent = 0 );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QTimer Timer;
|
QTimer Timer;
|
||||||
CServer* pServer;
|
CServer* pServer;
|
||||||
|
|
||||||
CVector<CServerListViewItem*> vecpListViewItems;
|
CVector<CServerListViewItem*> vecpListViewItems;
|
||||||
QMutex ListViewMutex;
|
QMutex ListViewMutex;
|
||||||
|
|
||||||
QMenuBar* pMenu;
|
QMenuBar* pMenu;
|
||||||
|
|
||||||
virtual void customEvent ( QEvent* Event );
|
virtual void customEvent ( QEvent* Event );
|
||||||
void UpdateSliderNetBuf();
|
void UpdateSliderNetBuf();
|
||||||
|
|
|
@ -381,6 +381,11 @@ CServer::CServer ( const QString& strLoggingFileName,
|
||||||
QObject::connect ( &vecChannels[9], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh9 ( int ) ) );
|
QObject::connect ( &vecChannels[9], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh9 ( int ) ) );
|
||||||
QObject::connect ( &vecChannels[10], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh10 ( int ) ) );
|
QObject::connect ( &vecChannels[10], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh10 ( int ) ) );
|
||||||
QObject::connect ( &vecChannels[11], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh11 ( int ) ) );
|
QObject::connect ( &vecChannels[11], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh11 ( int ) ) );
|
||||||
|
|
||||||
|
|
||||||
|
// set enable of the server list, must be done after the connections, we use
|
||||||
|
// the information about the enable status of the serverlist object itself
|
||||||
|
ServerListManager.SetEnabled ( ServerListManager.GetEnabled() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage )
|
void CServer::OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage )
|
||||||
|
@ -946,6 +951,12 @@ bool CServer::PutData ( const CVector<uint8_t>& vecbyRecBuf,
|
||||||
ConnLessProtocol.CreateCLServerFullMes ( HostAdr );
|
ConnLessProtocol.CreateCLServerFullMes ( HostAdr );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// this was a connection less protocol message, return accoring
|
||||||
|
// state
|
||||||
|
bChanOK = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -74,11 +74,6 @@ ServerList.append ( CServerListEntry (
|
||||||
|
|
||||||
QObject::connect ( &TimerRegistering, SIGNAL ( timeout() ),
|
QObject::connect ( &TimerRegistering, SIGNAL ( timeout() ),
|
||||||
this, SLOT ( OnTimerRegistering() ) );
|
this, SLOT ( OnTimerRegistering() ) );
|
||||||
|
|
||||||
|
|
||||||
// call set enable function after the connection of the timer since in this
|
|
||||||
// function the timer gets started
|
|
||||||
SetEnabled ( bEnabled );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerListManager::SetEnabled ( const bool bState )
|
void CServerListManager::SetEnabled ( const bool bState )
|
||||||
|
|
|
@ -36,11 +36,11 @@ void CSocket::Init ( const quint16 iPortNumber )
|
||||||
bool bSuccess;
|
bool bSuccess;
|
||||||
if ( bIsClient )
|
if ( bIsClient )
|
||||||
{
|
{
|
||||||
// Per definition use the port number plus one for the client to make
|
// Per definition use the port number plus ten for the client to make
|
||||||
// it possible to run server and client on the same computer. If the
|
// it possible to run server and client on the same computer. If the
|
||||||
// port is not available, try "NUM_SOCKET_PORTS_TO_TRY" times with
|
// port is not available, try "NUM_SOCKET_PORTS_TO_TRY" times with
|
||||||
// incremented port numbers
|
// incremented port numbers
|
||||||
quint16 iClientPortIncrement = 1; // start value: port nubmer plus one
|
quint16 iClientPortIncrement = 10; // start value: port nubmer plus ten
|
||||||
bSuccess = false; // initialization for while loop
|
bSuccess = false; // initialization for while loop
|
||||||
while ( !bSuccess &&
|
while ( !bSuccess &&
|
||||||
( iClientPortIncrement <= NUM_SOCKET_PORTS_TO_TRY ) )
|
( iClientPortIncrement <= NUM_SOCKET_PORTS_TO_TRY ) )
|
||||||
|
@ -54,6 +54,9 @@ void CSocket::Init ( const quint16 iPortNumber )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// for the server, only try the given port number and do not try out
|
||||||
|
// other port numbers to bind since it is imporatant that the server
|
||||||
|
// gets the desired port number
|
||||||
bSuccess = SocketDevice.bind (
|
bSuccess = SocketDevice.bind (
|
||||||
QHostAddress ( QHostAddress::Any ), iPortNumber );
|
QHostAddress ( QHostAddress::Any ), iPortNumber );
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ public:
|
||||||
: pChannel( pNewChannel ), pConnLessProtocol ( pNewCLProtocol ),
|
: pChannel( pNewChannel ), pConnLessProtocol ( pNewCLProtocol ),
|
||||||
bIsClient ( true ) { Init ( iPortNumber ); }
|
bIsClient ( true ) { Init ( iPortNumber ); }
|
||||||
|
|
||||||
CSocket ( CServer* pNServP,
|
CSocket ( CServer* pNServP,
|
||||||
const quint16 iPortNumber )
|
const quint16 iPortNumber )
|
||||||
: pServer ( pNServP ), bIsClient ( false ) { Init ( iPortNumber ); }
|
: pServer ( pNServP ), bIsClient ( false ) { Init ( iPortNumber ); }
|
||||||
|
|
||||||
|
|
|
@ -427,6 +427,12 @@ public:
|
||||||
return InetAddr.toString().section ( ".", 0, 2 ) + ".x";
|
return InetAddr.toString().section ( ".", 0, 2 ) + ".x";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString toString() const
|
||||||
|
{
|
||||||
|
// return in the format [IP number]:[port]
|
||||||
|
return InetAddr.toString() + ":" + QString().setNum ( iPort );
|
||||||
|
}
|
||||||
|
|
||||||
QHostAddress InetAddr;
|
QHostAddress InetAddr;
|
||||||
quint16 iPort;
|
quint16 iPort;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue