diff --git a/src/connectdlg.cpp b/src/connectdlg.cpp index dca0acbc..fb30d252 100755 --- a/src/connectdlg.cpp +++ b/src/connectdlg.cpp @@ -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& vecServerInfo ) +void CConnectDlg::SetServerList ( const CHostAddress& InetAddr, + const CVector& 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 ) ); } diff --git a/src/connectdlg.h b/src/connectdlg.h index f4090617..fb47c63c 100755 --- a/src/connectdlg.h +++ b/src/connectdlg.h @@ -28,6 +28,7 @@ #include #include #include +#include #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& vecServerInfo ); + void SetServerList ( const CHostAddress& InetAddr, + const CVector& 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(); diff --git a/src/llconclientdlg.cpp b/src/llconclientdlg.cpp index bbe100af..d32b61ca 100755 --- a/src/llconclientdlg.cpp +++ b/src/llconclientdlg.cpp @@ -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 ) ) ); diff --git a/src/llconclientdlg.h b/src/llconclientdlg.h index 147c5a0b..c7cceafd 100755 --- a/src/llconclientdlg.h +++ b/src/llconclientdlg.h @@ -145,7 +145,7 @@ public slots: void OnCLServerListReceived ( CHostAddress InetAddr, CVector vecServerInfo ) - { ConnectDlg.SetServerList ( vecServerInfo ); } + { ConnectDlg.SetServerList ( InetAddr, vecServerInfo ); } void OnLineEditServerAddrTextChanged ( const QString ); void OnLineEditServerAddrActivated ( int index ); diff --git a/src/llconserverdlg.h b/src/llconserverdlg.h index 9c70b497..97db957f 100755 --- a/src/llconserverdlg.h +++ b/src/llconserverdlg.h @@ -58,13 +58,13 @@ public: CLlconServerDlg ( CServer* pNServP, QWidget* parent = 0 ); protected: - QTimer Timer; - CServer* pServer; + QTimer Timer; + CServer* pServer; - CVector vecpListViewItems; - QMutex ListViewMutex; + CVector vecpListViewItems; + QMutex ListViewMutex; - QMenuBar* pMenu; + QMenuBar* pMenu; virtual void customEvent ( QEvent* Event ); void UpdateSliderNetBuf(); diff --git a/src/server.cpp b/src/server.cpp index 12ce8e21..8765f4dd 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -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 vecMessage ) @@ -946,6 +951,12 @@ bool CServer::PutData ( const CVector& vecbyRecBuf, ConnLessProtocol.CreateCLServerFullMes ( HostAdr ); } } + else + { + // this was a connection less protocol message, return accoring + // state + bChanOK = false; + } } diff --git a/src/serverlist.cpp b/src/serverlist.cpp index c3e77280..6f704e0b 100755 --- a/src/serverlist.cpp +++ b/src/serverlist.cpp @@ -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 ) diff --git a/src/socket.cpp b/src/socket.cpp index a1784235..d0f7cb45 100755 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -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 ); } diff --git a/src/socket.h b/src/socket.h index 42d89c93..b6af6f41 100755 --- a/src/socket.h +++ b/src/socket.h @@ -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 ); } diff --git a/src/util.h b/src/util.h index 05c12e60..993298fc 100755 --- a/src/util.h +++ b/src/util.h @@ -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; };