Skip to content

Commit ad58f5e

Browse files
committed
Fetch client list over TCP when necessary for a server
1 parent d939e5b commit ad58f5e

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

src/connectdlg.cpp

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,9 @@ void CConnectDlg::SetServerList ( const CHostAddress& InetAddr, const CVector<CS
531531
// store host address
532532
pNewListViewItem->setData ( LVC_NAME, Qt::UserRole, CurHostAddress.toString() );
533533

534+
enum EClientFetchMode eFetchMode = CFM_UDP_REQUEST; // start off in UDP mode
535+
pNewListViewItem->setData ( LVC_CLIENTS, Qt::UserRole, eFetchMode ); // initialise fetch mode
536+
534537
// per default expand the list item (if not "show all servers")
535538
if ( bShowAllMusicians )
536539
{
@@ -561,6 +564,26 @@ void CConnectDlg::SetTcpSupported ( const CHostAddress& InetAddr, int iID )
561564
break;
562565

563566
case PROTMESSID_CLM_CONN_CLIENTS_LIST:
567+
// find the server with the correct address
568+
{
569+
CMappedTreeWidgetItem* pCurListViewItem = FindListViewItem ( InetAddr );
570+
571+
if ( pCurListViewItem )
572+
{
573+
// find the current fetch mode for the client list for this server
574+
enum EClientFetchMode eFetchMode =
575+
static_cast<enum EClientFetchMode> ( pCurListViewItem->data ( LVC_CLIENTS, Qt::UserRole ).toInt() );
576+
577+
if ( eFetchMode == CFM_UDP_REQUEST )
578+
{
579+
// client list not yet received - switch to TCP mode
580+
eFetchMode = CFM_TCP;
581+
pCurListViewItem->setData ( LVC_CLIENTS, Qt::UserRole, eFetchMode ); // remember for future fetches
582+
583+
emit CreateCLServerListReqConnClientsListMes ( InetAddr, true ); // TCP
584+
}
585+
}
586+
}
564587
break;
565588

566589
default:
@@ -575,6 +598,16 @@ void CConnectDlg::SetConnClientsList ( const CHostAddress& InetAddr, const CVect
575598

576599
if ( pCurListViewItem )
577600
{
601+
// find the current fetch mode for the client list for this server
602+
enum EClientFetchMode eFetchMode = static_cast<enum EClientFetchMode> ( pCurListViewItem->data ( LVC_CLIENTS, Qt::UserRole ).toInt() );
603+
604+
if ( eFetchMode != CFM_TCP )
605+
{
606+
// not switched to TCP mode - set to UDP for successful fetch
607+
eFetchMode = CFM_UDP_RESULT;
608+
pCurListViewItem->setData ( LVC_CLIENTS, Qt::UserRole, eFetchMode );
609+
}
610+
578611
// first remove any existing children
579612
DeleteAllListViewItemChilds ( pCurListViewItem );
580613

@@ -1005,7 +1038,16 @@ void CConnectDlg::SetPingTimeAndNumClientsResult ( const CHostAddress& InetAddr,
10051038
// connected clients, if not then request the client names
10061039
if ( iNumClients != pCurListViewItem->childCount() )
10071040
{
1008-
emit CreateCLServerListReqConnClientsListMes ( InetAddr, false ); // UDP
1041+
// find the current fetch mode for the client list for this server
1042+
enum EClientFetchMode eFetchMode = static_cast<enum EClientFetchMode> ( pCurListViewItem->data ( LVC_CLIENTS, Qt::UserRole ).toInt() );
1043+
1044+
if ( eFetchMode != CFM_TCP )
1045+
{
1046+
// not switched to TCP mode - reset for next UDP fetch
1047+
eFetchMode = CFM_UDP_REQUEST;
1048+
pCurListViewItem->setData ( LVC_CLIENTS, Qt::UserRole, eFetchMode );
1049+
}
1050+
emit CreateCLServerListReqConnClientsListMes ( InetAddr, eFetchMode == CFM_TCP ); // UDP or TCP
10091051
}
10101052

10111053
// this is the first time a ping time was received, set item to visible

src/connectdlg.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ class CConnectDlg : public CBaseDlg, private Ui_CConnectDlgBase
9595
};
9696

9797
protected:
98+
// UDP/TCP mode for fetching client list - stored in data field for LVC_CLIENTS column
99+
enum EClientFetchMode
100+
{
101+
CFM_UDP_REQUEST, // set when sending request by UDP
102+
CFM_UDP_RESULT, // set when received a client list by UDP
103+
CFM_TCP, // set when "TCP Supported" message arrives but client list has not arrived -
104+
// re-request using TCP and remain in TCP mode
105+
};
106+
98107
virtual void showEvent ( QShowEvent* );
99108
virtual void hideEvent ( QHideEvent* );
100109

0 commit comments

Comments
 (0)