Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ CClient::CClient ( const quint16 iPortNumber,
QObject::connect ( &ConnLessProtocol, &CProtocol::CLServerListReceived,
this, &CClient::CLServerListReceived );

QObject::connect ( &ConnLessProtocol, &CProtocol::CLRedServerListReceived,
this, &CClient::CLRedServerListReceived );

QObject::connect ( &ConnLessProtocol, &CProtocol::CLConnClientsListMesReceived,
this, &CClient::CLConnClientsListMesReceived );

Expand Down
3 changes: 3 additions & 0 deletions src/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,9 @@ protected slots:
void CLServerListReceived ( CHostAddress InetAddr,
CVector<CServerInfo> vecServerInfo );

void CLRedServerListReceived ( CHostAddress InetAddr,
CVector<CServerInfo> vecServerInfo );

void CLConnClientsListMesReceived ( CHostAddress InetAddr,
CVector<CChannelInfo> vecChanInfo );

Expand Down
3 changes: 3 additions & 0 deletions src/clientdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,9 @@ CClientDlg::CClientDlg ( CClient* pNCliP,
QObject::connect ( pClient, &CClient::CLServerListReceived,
this, &CClientDlg::OnCLServerListReceived );

QObject::connect ( pClient, &CClient::CLRedServerListReceived,
this, &CClientDlg::OnCLRedServerListReceived );

QObject::connect ( pClient, &CClient::CLConnClientsListMesReceived,
this, &CClientDlg::OnCLConnClientsListMesReceived );

Expand Down
4 changes: 4 additions & 0 deletions src/clientdlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ public slots:
CVector<CServerInfo> vecServerInfo )
{ ConnectDlg.SetServerList ( InetAddr, vecServerInfo ); }

void OnCLRedServerListReceived ( CHostAddress InetAddr,
CVector<CServerInfo> vecServerInfo )
{ ConnectDlg.SetServerList ( InetAddr, vecServerInfo, true ); }

void OnCLConnClientsListMesReceived ( CHostAddress InetAddr,
CVector<CChannelInfo> vecChanInfo )
{ ConnectDlg.SetConnClientsList ( InetAddr, vecChanInfo ); }
Expand Down
68 changes: 46 additions & 22 deletions src/connectdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@ CConnectDlg::CConnectDlg ( CClient* pNCliP,
const bool bNewShowCompleteRegList,
QWidget* parent,
Qt::WindowFlags f )
: QDialog ( parent, f ),
pClient ( pNCliP ),
strCentralServerAddress ( "" ),
strSelectedAddress ( "" ),
strSelectedServerName ( "" ),
bShowCompleteRegList ( bNewShowCompleteRegList ),
bServerListReceived ( false ),
bServerListItemWasChosen ( false ),
bListFilterWasActive ( false ),
bShowAllMusicians ( true )
: QDialog ( parent, f ),
pClient ( pNCliP ),
strCentralServerAddress ( "" ),
strSelectedAddress ( "" ),
strSelectedServerName ( "" ),
bShowCompleteRegList ( bNewShowCompleteRegList ),
bServerListReceived ( false ),
bReducedServerListReceived ( false ),
bServerListItemWasChosen ( false ),
bListFilterWasActive ( false ),
bShowAllMusicians ( true )
{
setupUi ( this );

Expand Down Expand Up @@ -216,9 +217,10 @@ void CConnectDlg::showEvent ( QShowEvent* )
void CConnectDlg::RequestServerList()
{
// reset flags
bServerListReceived = false;
bServerListItemWasChosen = false;
bListFilterWasActive = false;
bServerListReceived = false;
bReducedServerListReceived = false;
bServerListItemWasChosen = false;
bListFilterWasActive = false;

// clear current address and name
strSelectedAddress = "";
Expand Down Expand Up @@ -267,11 +269,30 @@ void CConnectDlg::OnTimerReRequestServList()
}

void CConnectDlg::SetServerList ( const CHostAddress& InetAddr,
const CVector<CServerInfo>& vecServerInfo )
const CVector<CServerInfo>& vecServerInfo,
const bool bIsReducedServerList )
{
// set flag and disable timer for resend server list request
bServerListReceived = true;
TimerReRequestServList.stop();
// special treatment if a reduced server list was received
if ( bIsReducedServerList )
{
// make sure we only apply the reduced version list once
if ( bReducedServerListReceived )
{
// do nothing
return;
}
else
{
bReducedServerListReceived = true;
}
}
else
{
// set flag and disable timer for resend server list request if full list
// was received (i.e. not the reduced list)
bServerListReceived = true;
TimerReRequestServList.stop();
}

// first clear list
lvwServers->clear();
Expand Down Expand Up @@ -745,15 +766,18 @@ void CConnectDlg::SetPingTimeAndNumClientsResult ( const CHostAddress& InetAddr,
}

// update number of clients text
if ( iNumClients >= pCurListViewItem->text ( 5 ).toInt() )
if ( pCurListViewItem->text ( 5 ).toInt() == 0 )
{
pCurListViewItem->
setText ( 2, QString().setNum ( iNumClients ) + " (full)" );
// special case: reduced server list
pCurListViewItem->setText ( 2, QString().setNum ( iNumClients ) );
}
else if ( iNumClients >= pCurListViewItem->text ( 5 ).toInt() )
{
pCurListViewItem->setText ( 2, QString().setNum ( iNumClients ) + " (full)" );
}
else
{
pCurListViewItem->
setText ( 2, QString().setNum ( iNumClients ) + "/" + pCurListViewItem->text ( 5 ) );
pCurListViewItem->setText ( 2, QString().setNum ( iNumClients ) + "/" + pCurListViewItem->text ( 5 ) );
}

// check if the number of child list items matches the number of
Expand Down
4 changes: 3 additions & 1 deletion src/connectdlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class CConnectDlg : public QDialog, private Ui_CConnectDlgBase
bool GetShowAllMusicians() { return bShowAllMusicians; }

void SetServerList ( const CHostAddress& InetAddr,
const CVector<CServerInfo>& vecServerInfo );
const CVector<CServerInfo>& vecServerInfo,
const bool bIsReducedServerList = false );

void SetConnClientsList ( const CHostAddress& InetAddr,
const CVector<CChannelInfo>& vecChanInfo );
Expand Down Expand Up @@ -101,6 +102,7 @@ class CConnectDlg : public QDialog, private Ui_CConnectDlgBase
QString strSelectedServerName;
bool bShowCompleteRegList;
bool bServerListReceived;
bool bReducedServerListReceived;
bool bServerListItemWasChosen;
bool bListFilterWasActive;
bool bShowAllMusicians;
Expand Down
131 changes: 123 additions & 8 deletions src/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,18 @@ CONNECTION LESS MESSAGES
of the PROTMESSID_CLM_REGISTER_SERVER message is used


- PROTMESSID_CLM_RED_SERVER_LIST: Reduced server list message (to have less UDP fragmentation)

for each registered server append following data:

+--------------------+------------------------------+ ...
| 4 bytes IP address | 2 bytes server internal port | ...
+--------------------+------------------------------+ ...
... -----------------+----------------------------------+
... 1 byte number n | n bytes UTF-8 string server name |
... -----------------+----------------------------------+


- PROTMESSID_CLM_REQ_SERVER_LIST: Request server list

note: does not have any data -> n = 0
Expand Down Expand Up @@ -883,6 +895,10 @@ if ( rand() < ( RAND_MAX / 2 ) ) return false;
EvaluateCLServerListMes ( InetAddr, vecbyMesBodyData );
break;

case PROTMESSID_CLM_RED_SERVER_LIST:
EvaluateCLRedServerListMes ( InetAddr, vecbyMesBodyData );
break;

case PROTMESSID_CLM_REQ_SERVER_LIST:
EvaluateCLReqServerListMes ( InetAddr );
break;
Expand Down Expand Up @@ -2323,6 +2339,103 @@ bool CProtocol::EvaluateCLServerListMes ( const CHostAddress& InetAddr,
return false; // no error
}

void CProtocol::CreateCLRedServerListMes ( const CHostAddress& InetAddr,
const CVector<CServerInfo> vecServerInfo )
{
const int iNumServers = vecServerInfo.Size();

// build data vector
CVector<uint8_t> vecData ( 0 );
int iPos = 0; // init position pointer

for ( int i = 0; i < iNumServers; i++ )
{
// convert server list strings to utf-8
const QByteArray strUTF8Name = vecServerInfo[i].strName.toUtf8();

// size of current list entry
const int iCurListEntrLen =
4 /* IP address */ +
2 /* port number */ +
1 /* name utf-8 string size */ + strUTF8Name.size();

// make space for new data
vecData.Enlarge ( iCurListEntrLen );

// IP address (4 bytes)
// note the Server List manager has put the internal details in HostAddr where required
PutValOnStream ( vecData, iPos, static_cast<uint32_t> (
vecServerInfo[i].HostAddr.InetAddr.toIPv4Address() ), 4 );

// port number (2 bytes)
// note the Server List manager has put the internal details in HostAddr where required
PutValOnStream ( vecData, iPos,
static_cast<uint32_t> ( vecServerInfo[i].HostAddr.iPort ), 2 );

// name (note that the string length indicator is 1 in this special case)
PutStringUTF8OnStream ( vecData, iPos, strUTF8Name, 1 );
}

CreateAndImmSendConLessMessage ( PROTMESSID_CLM_RED_SERVER_LIST,
vecData,
InetAddr );
}

bool CProtocol::EvaluateCLRedServerListMes ( const CHostAddress& InetAddr,
const CVector<uint8_t>& vecData )
{
int iPos = 0; // init position pointer
const int iDataLen = vecData.Size();
CVector<CServerInfo> vecServerInfo ( 0 );

while ( iPos < iDataLen )
{
// check size (the next 6 bytes)
if ( ( iDataLen - iPos ) < 6 )
{
return true; // return error code
}

// IP address (4 bytes)
const quint32 iIpAddr = static_cast<quint32> ( GetValFromStream ( vecData, iPos, 4 ) );

// port number (2 bytes)
const quint16 iPort = static_cast<quint16> ( GetValFromStream ( vecData, iPos, 2 ) );

// server name (note that the string length indicator is 1 in this special case)
QString strName;
if ( GetStringFromStream ( vecData,
iPos,
MAX_LEN_SERVER_NAME,
strName,
1 ) )
{
return true; // return error code
}

// add server information to vector
vecServerInfo.Add (
CServerInfo ( CHostAddress ( QHostAddress ( iIpAddr ), iPort ),
CHostAddress ( QHostAddress ( iIpAddr ), iPort ),
strName,
QLocale::AnyCountry, // set to any country since the information is not transmitted
"", // empty city name since the information is not transmitted
0, // per definition: if max. num. client is zero, we ignore the value in the server list
false ) ); // assume not permanent since the information is not transmitted
}

// check size: all data is read, the position must now be at the end
if ( iPos != iDataLen )
{
return true; // return error code
}

// invoke message action
emit CLRedServerListReceived ( InetAddr, vecServerInfo );

return false; // no error
}

void CProtocol::CreateCLReqServerListMes ( const CHostAddress& InetAddr )
{
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_REQ_SERVER_LIST,
Expand Down Expand Up @@ -2883,21 +2996,22 @@ uint32_t CProtocol::GetValFromStream ( const CVector<uint8_t>& vecIn,
bool CProtocol::GetStringFromStream ( const CVector<uint8_t>& vecIn,
int& iPos,
const int iMaxStringLen,
QString& strOut )
QString& strOut,
const int iNumberOfBytsLen )
{
/*
note: iPos is automatically incremented in this function
*/
const int iInLen = vecIn.Size();

// check if at least two bytes are available
if ( ( iInLen - iPos ) < 2 )
// check if at least iNumberOfBytsLen bytes are available
if ( ( iInLen - iPos ) < iNumberOfBytsLen )
{
return true; // return error code
}

// number of bytes for utf-8 string (2 bytes)
const int iStrUTF8Len = static_cast<int> ( GetValFromStream ( vecIn, iPos, 2 ) );
// number of bytes for utf-8 string (1 or 2 bytes)
const int iStrUTF8Len = static_cast<int> ( GetValFromStream ( vecIn, iPos, iNumberOfBytsLen ) );

// (note that iPos was incremented by 2 in the above code!)
if ( ( iInLen - iPos ) < iStrUTF8Len )
Expand Down Expand Up @@ -3034,13 +3148,14 @@ void CProtocol::PutValOnStream ( CVector<uint8_t>& vecIn,

void CProtocol::PutStringUTF8OnStream ( CVector<uint8_t>& vecIn,
int& iPos,
const QByteArray& sStringUTF8 )
const QByteArray& sStringUTF8,
const int iNumberOfBytsLen )
{
// get the utf-8 string size
const int iStrUTF8Len = sStringUTF8.size();

// number of bytes for utf-8 string (2 bytes)
PutValOnStream ( vecIn, iPos, static_cast<uint32_t> ( iStrUTF8Len ), 2 );
// number of bytes for utf-8 string (iNumberOfBytsLen bytes)
PutValOnStream ( vecIn, iPos, static_cast<uint32_t> ( iStrUTF8Len ), iNumberOfBytsLen );

// actual utf-8 string (n bytes)
for ( int j = 0; j < iStrUTF8Len; j++ )
Expand Down
13 changes: 11 additions & 2 deletions src/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
#define PROTMESSID_CLM_CHANNEL_LEVEL_LIST 1015 // channel level list
#define PROTMESSID_CLM_REGISTER_SERVER_RESP 1016 // status of server registration request
#define PROTMESSID_CLM_REGISTER_SERVER_EX 1017 // register server with extended information
#define PROTMESSID_CLM_RED_SERVER_LIST 1018 // reduced server list

// special IDs
#define PROTMESSID_SPECIAL_SPLIT_MESSAGE 2001 // a container for split messages
Expand Down Expand Up @@ -145,6 +146,8 @@ class CProtocol : public QObject
void CreateCLUnregisterServerMes ( const CHostAddress& InetAddr );
void CreateCLServerListMes ( const CHostAddress& InetAddr,
const CVector<CServerInfo> vecServerInfo );
void CreateCLRedServerListMes ( const CHostAddress& InetAddr,
const CVector<CServerInfo> vecServerInfo );
void CreateCLReqServerListMes ( const CHostAddress& InetAddr );
void CreateCLSendEmptyMesMes ( const CHostAddress& InetAddr,
const CHostAddress& TargetInetAddr );
Expand Down Expand Up @@ -238,7 +241,8 @@ class CProtocol : public QObject

void PutStringUTF8OnStream ( CVector<uint8_t>& vecIn,
int& iPos,
const QByteArray& sStringUTF8 );
const QByteArray& sStringUTF8,
const int iNumberOfBytsLen = 2 ); // default is 2 bytes lenght indicator

static uint32_t GetValFromStream ( const CVector<uint8_t>& vecIn,
int& iPos,
Expand All @@ -247,7 +251,8 @@ class CProtocol : public QObject
bool GetStringFromStream ( const CVector<uint8_t>& vecIn,
int& iPos,
const int iMaxStringLen,
QString& strOut );
QString& strOut,
const int iNumberOfBytsLen = 2 ); // default is 2 bytes lenght indicator

void SendMessage();

Expand Down Expand Up @@ -290,6 +295,8 @@ class CProtocol : public QObject
bool EvaluateCLUnregisterServerMes ( const CHostAddress& InetAddr );
bool EvaluateCLServerListMes ( const CHostAddress& InetAddr,
const CVector<uint8_t>& vecData );
bool EvaluateCLRedServerListMes ( const CHostAddress& InetAddr,
const CVector<uint8_t>& vecData );
bool EvaluateCLReqServerListMes ( const CHostAddress& InetAddr );
bool EvaluateCLSendEmptyMesMes ( const CVector<uint8_t>& vecData );
bool EvaluateCLDisconnectionMes ( const CHostAddress& InetAddr );
Expand Down Expand Up @@ -367,6 +374,8 @@ public slots:
void CLUnregisterServerReceived ( CHostAddress InetAddr );
void CLServerListReceived ( CHostAddress InetAddr,
CVector<CServerInfo> vecServerInfo );
void CLRedServerListReceived ( CHostAddress InetAddr,
CVector<CServerInfo> vecServerInfo );
void CLReqServerList ( CHostAddress InetAddr );
void CLSendEmptyMes ( CHostAddress TargetInetAddr );
void CLDisconnection ( CHostAddress InetAddr );
Expand Down
Loading