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->clear();
|
||||
|
||||
// TEST
|
||||
pListViewItem = new QTreeWidgetItem ( ListViewServers );
|
||||
|
||||
|
||||
// Connections -------------------------------------------------------------
|
||||
// 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
|
||||
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()
|
||||
|
@ -132,7 +151,8 @@ void CConnectDlg::SetPingTimeResult ( CHostAddress& InetAddr,
|
|||
const int iPingTime )
|
||||
{
|
||||
|
||||
// TEST
|
||||
pListViewItem->setText ( 0, QString().setNum ( iPingTime ) );
|
||||
// ListViewServers->
|
||||
//// TEST
|
||||
//pListViewItem->setText ( 0, QString().setNum ( iPingTime ) );
|
||||
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <qwhatsthis.h>
|
||||
#include <qtimer.h>
|
||||
#include <qmutex.h>
|
||||
#include <qlocale.h>
|
||||
#include "global.h"
|
||||
#include "client.h"
|
||||
#ifdef _WIN32
|
||||
|
@ -55,7 +56,9 @@ class CConnectDlg : public QDialog, private Ui_CConnectDlgBase
|
|||
public:
|
||||
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 );
|
||||
|
||||
protected:
|
||||
|
@ -67,10 +70,6 @@ protected:
|
|||
CHostAddress CentralServerAddress;
|
||||
bool bServerListReceived;
|
||||
|
||||
// TEST
|
||||
QTreeWidgetItem* pListViewItem;
|
||||
|
||||
|
||||
public slots:
|
||||
void OnTimerPing();
|
||||
void OnTimerReRequestServList();
|
||||
|
|
|
@ -443,7 +443,7 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP,
|
|||
QObject::connect ( &ChatDlg, SIGNAL ( NewLocalInputText ( QString ) ),
|
||||
this, SLOT ( OnNewLocalInputText ( QString ) ) );
|
||||
|
||||
QObject::connect ( &ConnectDlg, SIGNAL ( NewLocalInputText ( CHostAddress ) ),
|
||||
QObject::connect ( &ConnectDlg, SIGNAL ( ReqServerListQuery ( CHostAddress ) ),
|
||||
this, SLOT ( OnReqServerListQuery ( CHostAddress ) ) );
|
||||
|
||||
|
||||
|
|
|
@ -145,7 +145,7 @@ public slots:
|
|||
|
||||
void OnCLServerListReceived ( CHostAddress InetAddr,
|
||||
CVector<CServerInfo> vecServerInfo )
|
||||
{ ConnectDlg.SetServerList ( vecServerInfo ); }
|
||||
{ ConnectDlg.SetServerList ( InetAddr, vecServerInfo ); }
|
||||
|
||||
void OnLineEditServerAddrTextChanged ( const QString );
|
||||
void OnLineEditServerAddrActivated ( int index );
|
||||
|
|
|
@ -381,6 +381,11 @@ CServer::CServer ( const QString& strLoggingFileName,
|
|||
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[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 )
|
||||
|
@ -946,6 +951,12 @@ bool CServer::PutData ( const CVector<uint8_t>& vecbyRecBuf,
|
|||
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() ),
|
||||
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 )
|
||||
|
|
|
@ -36,11 +36,11 @@ void CSocket::Init ( const quint16 iPortNumber )
|
|||
bool bSuccess;
|
||||
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
|
||||
// port is not available, try "NUM_SOCKET_PORTS_TO_TRY" times with
|
||||
// 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
|
||||
while ( !bSuccess &&
|
||||
( iClientPortIncrement <= NUM_SOCKET_PORTS_TO_TRY ) )
|
||||
|
@ -54,6 +54,9 @@ void CSocket::Init ( const quint16 iPortNumber )
|
|||
}
|
||||
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 (
|
||||
QHostAddress ( QHostAddress::Any ), iPortNumber );
|
||||
}
|
||||
|
|
|
@ -427,6 +427,12 @@ public:
|
|||
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;
|
||||
quint16 iPort;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue