first working initial server list implementation

This commit is contained in:
Volker Fischer 2011-04-14 06:46:21 +00:00
parent da9af48062
commit a238cd9569
10 changed files with 62 additions and 28 deletions

View File

@ -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()
@ -129,10 +148,11 @@ void CConnectDlg::OnTimerPing()
}
void CConnectDlg::SetPingTimeResult ( CHostAddress& InetAddr,
const int iPingTime )
const int iPingTime )
{
// TEST
pListViewItem->setText ( 0, QString().setNum ( iPingTime ) );
// ListViewServers->
//// TEST
//pListViewItem->setText ( 0, QString().setNum ( iPingTime ) );
}

View File

@ -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();

View File

@ -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 ) ) );

View File

@ -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 );

View File

@ -58,13 +58,13 @@ public:
CLlconServerDlg ( CServer* pNServP, QWidget* parent = 0 );
protected:
QTimer Timer;
CServer* pServer;
QTimer Timer;
CServer* pServer;
CVector<CServerListViewItem*> vecpListViewItems;
QMutex ListViewMutex;
CVector<CServerListViewItem*> vecpListViewItems;
QMutex ListViewMutex;
QMenuBar* pMenu;
QMenuBar* pMenu;
virtual void customEvent ( QEvent* Event );
void UpdateSliderNetBuf();

View File

@ -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;
}
}

View File

@ -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 )

View File

@ -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 );
}

View File

@ -59,7 +59,7 @@ public:
: pChannel( pNewChannel ), pConnLessProtocol ( pNewCLProtocol ),
bIsClient ( true ) { Init ( iPortNumber ); }
CSocket ( CServer* pNServP,
CSocket ( CServer* pNServP,
const quint16 iPortNumber )
: pServer ( pNServP ), bIsClient ( false ) { Init ( iPortNumber ); }

View File

@ -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;
};