on request show the names of the connected clients in the server list

This commit is contained in:
Volker Fischer 2015-12-09 15:50:30 +00:00
parent 5d693d8ea4
commit 33c6e77c68
11 changed files with 321 additions and 181 deletions

View file

@ -3,7 +3,7 @@
3.3.12
TODO:
TODO: (close Ticket on Sourceforge if finished!)
- on request show the names of the connected clients in the server list

View file

@ -204,6 +204,10 @@ QObject::connect ( &Channel, SIGNAL ( OpusSupported() ),
SIGNAL ( CLServerListReceived ( CHostAddress, CVector<CServerInfo> ) ),
SIGNAL ( CLServerListReceived ( CHostAddress, CVector<CServerInfo> ) ) );
QObject::connect ( &ConnLessProtocol,
SIGNAL ( CLConnClientsListMesReceived ( CHostAddress, CVector<CChannelInfo> ) ),
SIGNAL ( CLConnClientsListMesReceived ( CHostAddress, CVector<CChannelInfo> ) ) );
QObject::connect ( &ConnLessProtocol,
SIGNAL ( CLPingReceived ( CHostAddress, int ) ),
this, SLOT ( OnCLPingReceived ( CHostAddress, int ) ) );

View file

@ -267,9 +267,10 @@ public:
}
void CreateCLServerListReqVerAndOSMes ( const CHostAddress& InetAddr )
{
ConnLessProtocol.CreateCLReqVersionAndOSMes ( InetAddr );
}
{ ConnLessProtocol.CreateCLReqVersionAndOSMes ( InetAddr ); }
void CreateCLServerListReqConnClientsListMes ( const CHostAddress& InetAddr )
{ ConnLessProtocol.CreateCLReqConnClientsListMes ( InetAddr ); }
void CreateCLReqServerListMes ( const CHostAddress& InetAddr )
{ ConnLessProtocol.CreateCLReqServerListMes ( InetAddr ); }
@ -428,6 +429,9 @@ signals:
void CLServerListReceived ( CHostAddress InetAddr,
CVector<CServerInfo> vecServerInfo );
void CLConnClientsListMesReceived ( CHostAddress InetAddr,
CVector<CChannelInfo> vecChanInfo );
void CLPingTimeWithNumClientsReceived ( CHostAddress InetAddr,
int iPingTime,
int iNumClients );

View file

@ -474,6 +474,10 @@ CClientDlg::CClientDlg ( CClient* pNCliP,
SIGNAL ( CLServerListReceived ( CHostAddress, CVector<CServerInfo> ) ),
this, SLOT ( OnCLServerListReceived ( CHostAddress, CVector<CServerInfo> ) ) );
QObject::connect ( pClient,
SIGNAL ( CLConnClientsListMesReceived ( CHostAddress, CVector<CChannelInfo> ) ),
this, SLOT ( OnCLConnClientsListMesReceived ( CHostAddress, CVector<CChannelInfo> ) ) );
QObject::connect ( pClient,
SIGNAL ( CLPingTimeWithNumClientsReceived ( CHostAddress, int, int ) ),
this, SLOT ( OnCLPingTimeWithNumClientsReceived ( CHostAddress, int, int ) ) );
@ -520,6 +524,9 @@ CClientDlg::CClientDlg ( CClient* pNCliP,
QObject::connect ( &ConnectDlg, SIGNAL ( CreateCLServerListReqVerAndOSMes ( CHostAddress ) ),
this, SLOT ( OnCreateCLServerListReqVerAndOSMes ( CHostAddress ) ) );
QObject::connect ( &ConnectDlg, SIGNAL ( CreateCLServerListReqConnClientsListMes ( CHostAddress ) ),
this, SLOT ( OnCreateCLServerListReqConnClientsListMes ( CHostAddress ) ) );
QObject::connect ( &ConnectDlg, SIGNAL ( accepted() ),
this, SLOT ( OnConnectDlgAccepted() ) );

View file

@ -176,10 +176,17 @@ public slots:
void OnCreateCLServerListReqVerAndOSMes ( CHostAddress InetAddr )
{ pClient->CreateCLServerListReqVerAndOSMes ( InetAddr ); }
void OnCreateCLServerListReqConnClientsListMes ( CHostAddress InetAddr )
{ pClient->CreateCLServerListReqConnClientsListMes ( InetAddr ); }
void OnCLServerListReceived ( CHostAddress InetAddr,
CVector<CServerInfo> vecServerInfo )
{ ConnectDlg.SetServerList ( InetAddr, vecServerInfo ); }
void OnCLConnClientsListMesReceived ( CHostAddress InetAddr,
CVector<CChannelInfo> vecChanInfo )
{ ConnectDlg.SetConnClientsList ( InetAddr, vecChanInfo ); }
void OnConnectDlgAccepted();
void OnDisconnected();

View file

@ -93,6 +93,17 @@ CConnectDlg::CConnectDlg ( const bool bNewShowCompleteRegList,
lvwServers->setColumnCount ( 5 );
lvwServers->hideColumn ( 4 );
// setup the server list context menu
lvwServers->setContextMenuPolicy ( Qt::CustomContextMenu );
// per default the root shall not be decorated (to save space)
lvwServers->setRootIsDecorated ( false );
pServerListContextMenu = new QMenu ( this );
pServerListContextMenu->addAction ( tr ( "&Query Names" ), this,
SLOT ( OnServerListContextMenuNames() ) );
// make sure the connect button has the focus
butConnect->setFocus();
@ -116,6 +127,10 @@ CConnectDlg::CConnectDlg ( const bool bNewShowCompleteRegList,
SIGNAL ( activated ( QModelIndex ) ),
this, SLOT ( OnConnectClicked() ) );
QObject::connect ( lvwServers,
SIGNAL ( customContextMenuRequested ( const QPoint& ) ),
this, SLOT ( OnCustomContextMenuRequested ( const QPoint& ) ) );
// combo boxes
QObject::connect ( cbxServerAddr, SIGNAL ( editTextChanged ( const QString& ) ),
this, SLOT ( OnServerAddrEditTextChanged ( const QString& ) ) );
@ -305,6 +320,43 @@ strLocation += ", " + vecServerInfo[iIdx].HostAddr.InetAddr.toString() +
TimerPing.start ( PING_UPDATE_TIME_SERVER_LIST_MS );
}
void CConnectDlg::SetConnClientsList ( const CHostAddress& InetAddr,
const CVector<CChannelInfo>& vecChanInfo )
{
// find the server with the correct address
QTreeWidgetItem* pCurListViewItem = FindListViewItem ( InetAddr );
if ( pCurListViewItem )
{
// first remove any existing childs
DeleteAllListViewItemChilds ( pCurListViewItem );
// get number of connected clients
const int iNumConnectedClients = vecChanInfo.Size();
for ( int i = 0; i < iNumConnectedClients; i++ )
{
// create new list view item
QTreeWidgetItem* pNewChildListViewItem =
new QTreeWidgetItem ( pCurListViewItem );
// child items shall use only one column
pNewChildListViewItem->setFirstColumnSpanned ( true );
// set the clients name
pNewChildListViewItem->setText ( 0, vecChanInfo[i].strName );
// add the new child to the corresponding server item
pCurListViewItem->addChild ( pNewChildListViewItem );
// at least one server has childs now, show decoration to be able
// to show the childs and also expand to see the new childs
lvwServers->setRootIsDecorated ( true );
lvwServers->expandItem ( pCurListViewItem );
}
}
}
void CConnectDlg::OnServerListItemSelectionChanged()
{
// get current selected item (we are only interested in the first selcted
@ -317,7 +369,8 @@ void CConnectDlg::OnServerListItemSelectionChanged()
// make sure no signals are send when we change the text
cbxServerAddr->blockSignals ( true );
{
cbxServerAddr->setEditText ( CurSelListItemList[0]->text ( 0 ) );
cbxServerAddr->setEditText (
GetParentListViewItem ( CurSelListItemList[0] )->text ( 0 ) );
}
cbxServerAddr->blockSignals ( false );
}
@ -334,6 +387,24 @@ void CConnectDlg::OnServerListItemDoubleClicked ( QTreeWidgetItem* Item,
}
}
void CConnectDlg::OnCustomContextMenuRequested ( const QPoint& Position )
{
// get the item to which the context menu is assigned to based on the given
// mouse position
QTreeWidgetItem* Item = lvwServers->itemAt ( Position );
// first check if the item is valid
if ( Item != 0 )
{
// only show the context menu if there is at least von conntected client
if ( Item->text ( 2 ).toInt() > 0 )
{
// use the given position for the position of the context menu
pServerListContextMenu->exec ( lvwServers->mapToGlobal ( Position ) );
}
}
}
void CConnectDlg::OnServerAddrEditTextChanged ( const QString& )
{
// in the server address combo box, a text was changed, remove selection
@ -350,12 +421,16 @@ void CConnectDlg::OnConnectClicked()
if ( CurSelListItemList.count() > 0 )
{
// get the parent list view item
QTreeWidgetItem* pCurSelTopListItem =
GetParentListViewItem ( CurSelListItemList[0] );
// get host address from selected list view item as a string
strSelectedAddress =
CurSelListItemList[0]->data ( 0, Qt::UserRole ).toString();
pCurSelTopListItem->data ( 0, Qt::UserRole ).toString();
// store selected server name
strSelectedServerName = CurSelListItemList[0]->text ( 0 );
strSelectedServerName = pCurSelTopListItem->text ( 0 );
// set flag that a server list item was chosen to connect
bServerListItemWasChosen = true;
@ -369,6 +444,28 @@ void CConnectDlg::OnConnectClicked()
done ( QDialog::Accepted );
}
void CConnectDlg::OnServerListContextMenuNames()
{
// get the current selected item(s)
QList<QTreeWidgetItem*> CurSelListItemList = lvwServers->selectedItems();
if ( CurSelListItemList.count() > 0 )
{
CHostAddress CurServerAddress;
// try to parse host address string which is stored as user data
// in the server list item GUI control element
if ( NetworkUtil().ParseNetworkAddress (
CurSelListItemList[0]->
data ( 0, Qt::UserRole ).toString(),
CurServerAddress ) )
{
// if address is valid, send connected clients list request
emit CreateCLServerListReqConnClientsListMes ( CurServerAddress );
}
}
}
void CConnectDlg::OnTimerPing()
{
// send ping messages to the servers in the list
@ -401,6 +498,96 @@ void CConnectDlg::SetPingTimeAndNumClientsResult ( CHostAddress&
const int iNumClients )
{
// apply the received ping time to the correct server list entry
QTreeWidgetItem* pCurListViewItem = FindListViewItem ( InetAddr );
if ( pCurListViewItem )
{
// update the color of the ping time font
switch ( ePingTimeLEDColor )
{
case CMultiColorLED::RL_GREEN:
pCurListViewItem->setTextColor ( 1, Qt::darkGreen );
break;
case CMultiColorLED::RL_YELLOW:
pCurListViewItem->setTextColor ( 1, Qt::darkYellow );
break;
default: // including "CMultiColorLED::RL_RED"
pCurListViewItem->setTextColor ( 1, Qt::red );
break;
}
// update ping text, take special care if ping time exceeds a
// certain value
if ( iPingTime > 500 )
{
pCurListViewItem->setText ( 1, ">500 ms" );
}
else
{
pCurListViewItem->
setText ( 1, QString().setNum ( iPingTime ) + " ms" );
}
// update number of clients text
pCurListViewItem->
setText ( 2, QString().setNum ( iNumClients ) );
// a ping time was received, set item to visible (note that we have
// to check if the item is hidden, otherwise we get a lot of CPU
// usage by calling "setHidden(false)" even if the item was already
// visible)
if ( pCurListViewItem->isHidden() )
{
pCurListViewItem->setHidden ( false );
}
// update minimum ping time column (invisible, used for sorting) if
// the new value is smaller than the old value
if ( pCurListViewItem->text ( 4 ).toInt() > iPingTime )
{
// we pad to a total of 8 characters with zeros to make sure the
// sorting is done correctly
pCurListViewItem->setText ( 4, QString ( "%1" ).arg (
iPingTime, 8, 10, QLatin1Char ( '0' ) ) );
// Update the sorting (lowest number on top).
// Note that the sorting must be the last action for the current
// item since the topLevelItem ( iIdx ) is then no longer valid.
lvwServers->sortByColumn ( 4, Qt::AscendingOrder );
}
// check if the current number of clients is the same as the number
// of child items, if not, we remove all child items
if ( iNumClients != pCurListViewItem->childCount() )
{
// delete all childs
DeleteAllListViewItemChilds ( pCurListViewItem );
}
}
// if no server item has childs, do not show decoration
bool bAnyListItemHasChilds = false;
const int iServerListLen = lvwServers->topLevelItemCount();
for ( int iIdx = 0; iIdx < iServerListLen; iIdx++ )
{
// check if the current list item has childs
if ( lvwServers->topLevelItem ( iIdx )->childCount() > 0 )
{
bAnyListItemHasChilds = true;
}
}
if ( !bAnyListItemHasChilds )
{
lvwServers->setRootIsDecorated ( false );
}
}
QTreeWidgetItem* CConnectDlg::FindListViewItem ( const CHostAddress& InetAddr )
{
const int iServerListLen = lvwServers->topLevelItemCount();
for ( int iIdx = 0; iIdx < iServerListLen; iIdx++ )
@ -411,67 +598,44 @@ void CConnectDlg::SetPingTimeAndNumClientsResult ( CHostAddress&
data ( 0, Qt::UserRole ).toString().
compare ( InetAddr.toString() ) )
{
// update the color of the ping time font
switch ( ePingTimeLEDColor )
{
case CMultiColorLED::RL_GREEN:
lvwServers->
topLevelItem ( iIdx )->setTextColor ( 1, Qt::darkGreen );
break;
case CMultiColorLED::RL_YELLOW:
lvwServers->
topLevelItem ( iIdx )->setTextColor ( 1, Qt::darkYellow );
break;
default: // including "CMultiColorLED::RL_RED"
lvwServers->
topLevelItem ( iIdx )->setTextColor ( 1, Qt::red );
break;
}
// update ping text, take special care if ping time exceeds a
// certain value
if ( iPingTime > 500 )
{
lvwServers->topLevelItem ( iIdx )->setText ( 1, ">500 ms" );
}
else
{
lvwServers->topLevelItem ( iIdx )->
setText ( 1, QString().setNum ( iPingTime ) + " ms" );
}
// update number of clients text
lvwServers->topLevelItem ( iIdx )->
setText ( 2, QString().setNum ( iNumClients ) );
// a ping time was received, set item to visible (note that we have
// to check if the item is hidden, otherwise we get a lot of CPU
// usage by calling "setHidden(false)" even if the item was already
// visible)
if ( lvwServers->topLevelItem ( iIdx )->isHidden() )
{
lvwServers->topLevelItem ( iIdx )->setHidden ( false );
}
// update minimum ping time column (invisible, used for sorting) if
// the new value is smaller than the old value
if ( lvwServers->topLevelItem ( iIdx )->text ( 4 ).toInt() > iPingTime )
{
// we pad to a total of 8 characters with zeros to make sure the
// sorting is done correctly
lvwServers->topLevelItem ( iIdx )->
setText ( 4, QString ( "%1" ).arg (
iPingTime, 8, 10, QLatin1Char ( '0' ) ) );
// Update the sorting (lowest number on top).
// Note that the sorting must be the last action for the current
// item since the topLevelItem ( iIdx ) is then no longer valid.
lvwServers->sortByColumn ( 4, Qt::AscendingOrder );
}
return lvwServers->topLevelItem ( iIdx );
}
}
return NULL;
}
QTreeWidgetItem* CConnectDlg::GetParentListViewItem ( QTreeWidgetItem* pItem )
{
// check if the current item is already the top item, i.e. the parent
// query fails and returns null
if ( pItem->parent() )
{
// we only have maximum one level, i.e. if we call the parent function
// we are at the top item
return pItem->parent();
}
else
{
// this item is already the top item
return pItem;
}
}
void CConnectDlg::DeleteAllListViewItemChilds ( QTreeWidgetItem* pItem )
{
// loop over all childs
while ( pItem->childCount() > 0 )
{
// get the first child in the list
QTreeWidgetItem* pCurChildItem = pItem->child ( 0 );
// remove it from the item (note that the object is not deleted)
pItem->removeChild ( pCurChildItem );
// delete the object to avoid a memory leak
delete pCurChildItem;
}
}
#ifdef ENABLE_CLIENT_VERSION_AND_OS_DEBUGGING
@ -480,28 +644,21 @@ void CConnectDlg::SetVersionAndOSType ( CHostAddress InetAddr,
QString strVersion )
{
// apply the received version and OS type to the correct server list entry
const int iServerListLen = lvwServers->topLevelItemCount();
QTreeWidgetItem* pCurListViewItem = FindListViewItem ( InetAddr );
for ( int iIdx = 0; iIdx < iServerListLen; iIdx++ )
if ( pCurListViewItem )
{
// compare the received address with the user data string of the
// host address by a string compare
if ( !lvwServers->topLevelItem ( iIdx )->
data ( 0, Qt::UserRole ).toString().
compare ( InetAddr.toString() ) )
{
// TEST since this is just a debug info, we just reuse the ping column (note
// the we have to replace the ping message emit with the version and OS request
// so that this works, see above code)
lvwServers->topLevelItem ( iIdx )->
pCurListViewItem->
setText ( 1, strVersion + "/" + COSUtil::GetOperatingSystemString ( eOSType ) );
// a version and OS type was received, set item to visible
if ( lvwServers->topLevelItem ( iIdx )->isHidden() )
if ( pCurListViewItem->isHidden() )
{
lvwServers->topLevelItem ( iIdx )->setHidden ( false );
pCurListViewItem->setHidden ( false );
}
}
}
}
#endif

View file

@ -29,6 +29,7 @@
#include <QTimer>
#include <QMutex>
#include <QLocale>
#include <QMenu>
#include "global.h"
#include "client.h"
#include "multicolorled.h"
@ -57,6 +58,9 @@ public:
void SetServerList ( const CHostAddress& InetAddr,
const CVector<CServerInfo>& vecServerInfo );
void SetConnClientsList ( const CHostAddress& InetAddr,
const CVector<CChannelInfo>& vecChanInfo );
void SetPingTimeAndNumClientsResult ( CHostAddress& InetAddr,
const int iPingTime,
const CMultiColorLED::ELightColor ePingTimeLEDColor,
@ -76,6 +80,11 @@ protected:
virtual void showEvent ( QShowEvent* );
virtual void hideEvent ( QHideEvent* );
QTreeWidgetItem* FindListViewItem ( const CHostAddress& InetAddr );
QTreeWidgetItem* GetParentListViewItem ( QTreeWidgetItem* pItem );
void DeleteAllListViewItemChilds ( QTreeWidgetItem* pItem );
QMenu* pServerListContextMenu;
QTimer TimerPing;
QTimer TimerReRequestServList;
QString strCentralServerAddress;
@ -90,6 +99,8 @@ protected:
public slots:
void OnServerListItemSelectionChanged();
void OnServerListItemDoubleClicked ( QTreeWidgetItem* Item, int );
void OnCustomContextMenuRequested ( const QPoint& Position );
void OnServerListContextMenuNames();
void OnServerAddrEditTextChanged ( const QString& );
void OnConnectClicked();
void OnTimerPing();
@ -99,4 +110,5 @@ signals:
void ReqServerListQuery ( CHostAddress InetAddr );
void CreateCLServerListPingMes ( CHostAddress InetAddr );
void CreateCLServerListReqVerAndOSMes ( CHostAddress InetAddr );
void CreateCLServerListReqConnClientsListMes ( CHostAddress InetAddr );
};

View file

@ -1,7 +1,8 @@
<ui version="4.0" >
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CConnectDlgBase</class>
<widget class="QDialog" name="CConnectDlgBase" >
<property name="geometry" >
<widget class="QDialog" name="CConnectDlgBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
@ -9,70 +10,65 @@
<height>294</height>
</rect>
</property>
<property name="windowTitle" >
<property name="windowTitle">
<string>Connection Setup</string>
</property>
<property name="windowIcon" >
<iconset resource="resources.qrc" >:/png/main/res/mainicon.png</iconset>
<property name="windowIcon">
<iconset resource="resources.qrc">
<normaloff>:/png/main/res/mainicon.png</normaloff>:/png/main/res/mainicon.png</iconset>
</property>
<property name="styleSheet" >
<property name="styleSheet">
<string/>
</property>
<property name="sizeGripEnabled" >
<property name="sizeGripEnabled">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" >
<layout class="QVBoxLayout">
<item>
<widget class="QTreeWidget" name="lvwServers" >
<property name="editTriggers" >
<widget class="QTreeWidget" name="lvwServers">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="tabKeyNavigation" >
<property name="tabKeyNavigation">
<bool>true</bool>
</property>
<property name="rootIsDecorated" >
<bool>false</bool>
</property>
<property name="itemsExpandable" >
<bool>false</bool>
</property>
<column>
<property name="text" >
<property name="text">
<string>Server Name</string>
</property>
</column>
<column>
<property name="text" >
<property name="text">
<string>Ping Time</string>
</property>
</column>
<column>
<property name="text" >
<property name="text">
<string>Musicians</string>
</property>
</column>
<column>
<property name="text" >
<property name="text">
<string>Location</string>
</property>
</column>
</widget>
</item>
<item>
<layout class="QHBoxLayout" >
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="lblServerAddr" >
<property name="text" >
<widget class="QLabel" name="lblServerAddr">
<property name="text">
<string>Server Name/Address</string>
</property>
<property name="alignment" >
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cbxServerAddr" >
<property name="editable" >
<widget class="QComboBox" name="cbxServerAddr">
<property name="editable">
<bool>true</bool>
</property>
</widget>
@ -80,13 +76,13 @@
</layout>
</item>
<item>
<layout class="QHBoxLayout" >
<layout class="QHBoxLayout">
<item>
<spacer>
<property name="orientation" >
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0">
<size>
<width>351</width>
<height>25</height>
@ -95,18 +91,18 @@
</spacer>
</item>
<item>
<widget class="QPushButton" name="butCancel" >
<property name="text" >
<widget class="QPushButton" name="butCancel">
<property name="text">
<string>C&amp;ancel</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="butConnect" >
<property name="text" >
<widget class="QPushButton" name="butConnect">
<property name="text">
<string>&amp;Connect</string>
</property>
<property name="default" >
<property name="default">
<bool>true</bool>
</property>
</widget>
@ -116,7 +112,7 @@
</layout>
</widget>
<resources>
<include location="resources.qrc" />
<include location="resources.qrc"/>
</resources>
<connections/>
</ui>

View file

@ -286,19 +286,14 @@ CONNECTION LESS MESSAGES
for each connected client append the PROTMESSID_CONN_CLIENTS_LIST:
+--------------------+------------------------------+ ...
| 4 bytes request ID | PROTMESSID_CONN_CLIENTS_LIST | ...
+--------------------+------------------------------+ ...
+------------------------------+ ...
| PROTMESSID_CONN_CLIENTS_LIST | ...
+------------------------------+ ...
+------------------------------+------------------------------+ ...
| PROTMESSID_CONN_CLIENTS_LIST | PROTMESSID_CONN_CLIENTS_LIST | ...
+------------------------------+------------------------------+ ...
- PROTMESSID_CLM_REQ_CONN_CLIENTS_LIST: Request the connected clients list
+--------------------+
| 4 bytes request ID |
+--------------------+
note: does not have any data -> n = 0
******************************************************************************
@ -673,7 +668,7 @@ if ( rand() < ( RAND_MAX / 2 ) ) return false;
break;
case PROTMESSID_CLM_REQ_CONN_CLIENTS_LIST:
bRet = EvaluateCLReqConnClientsListMes ( InetAddr, vecbyMesBodyData );
bRet = EvaluateCLReqConnClientsListMes ( InetAddr );
break;
}
}
@ -1968,18 +1963,14 @@ bool CProtocol::EvaluateCLReqVersionAndOSMes ( const CHostAddress& InetAddr )
}
void CProtocol::CreateCLConnClientsListMes ( const CHostAddress& InetAddr,
const int iRequestID,
const CVector<CChannelInfo>& vecChanInfo )
{
const int iNumClients = vecChanInfo.Size();
// build data vector
CVector<uint8_t> vecData ( 4 ); // 4 bytes of data for request ID
CVector<uint8_t> vecData ( 0 );
int iPos = 0; // init position pointer
// request ID (4 bytes)
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iRequestID ), 4 );
for ( int i = 0; i < iNumClients; i++ )
{
// convert strings to utf-8
@ -2036,16 +2027,6 @@ bool CProtocol::EvaluateCLConnClientsListMes ( const CHostAddress& InetAddr,
const int iDataLen = vecData.Size();
CVector<CChannelInfo> vecChanInfo ( 0 );
// check size (the first 4 bytes)
if ( iDataLen < 4 )
{
return true; // return error code
}
// request ID (4 bytes)
const int iRequestID =
static_cast<int> ( GetValFromStream ( vecData, iPos, 4 ) );
while ( iPos < iDataLen )
{
// check size (the next 12 bytes)
@ -2111,44 +2092,22 @@ bool CProtocol::EvaluateCLConnClientsListMes ( const CHostAddress& InetAddr,
}
// invoke message action
emit CLConnClientsListMesReceived ( InetAddr, iRequestID, vecChanInfo );
emit CLConnClientsListMesReceived ( InetAddr, vecChanInfo );
return false; // no error
}
void CProtocol::CreateCLReqConnClientsListMes ( const CHostAddress& InetAddr,
const int iRequestID )
void CProtocol::CreateCLReqConnClientsListMes ( const CHostAddress& InetAddr )
{
int iPos = 0; // init position pointer
// build data vector (4 bytes long)
CVector<uint8_t> vecData ( 4 );
// request ID (4 bytes)
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iRequestID ), 4 );
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_REQ_CONN_CLIENTS_LIST,
vecData,
CVector<uint8_t> ( 0 ),
InetAddr );
}
bool CProtocol::EvaluateCLReqConnClientsListMes ( const CHostAddress& InetAddr,
const CVector<uint8_t>& vecData )
bool CProtocol::EvaluateCLReqConnClientsListMes ( const CHostAddress& InetAddr )
{
int iPos = 0; // init position pointer
// check size
if ( vecData.Size() != 4 )
{
return true; // return error code
}
// request ID (4 bytes)
const int iRequestID =
static_cast<int> ( GetValFromStream ( vecData, iPos, 4 ) );
// invoke message action
emit CLReqConnClientsList ( InetAddr, iRequestID );
emit CLReqConnClientsList ( InetAddr );
return false; // no error
}

View file

@ -124,10 +124,8 @@ public:
void CreateCLVersionAndOSMes ( const CHostAddress& InetAddr );
void CreateCLReqVersionAndOSMes ( const CHostAddress& InetAddr );
void CreateCLConnClientsListMes ( const CHostAddress& InetAddr,
const int iRequestID,
const CVector<CChannelInfo>& vecChanInfo );
void CreateCLReqConnClientsListMes ( const CHostAddress& InetAddr,
const int iRequestID );
void CreateCLReqConnClientsListMes ( const CHostAddress& InetAddr );
static bool ParseMessageFrame ( const CVector<uint8_t>& vecbyData,
const int iNumBytesIn,
@ -237,16 +235,15 @@ protected:
bool EvaluateCLUnregisterServerMes ( const CHostAddress& InetAddr );
bool EvaluateCLServerListMes ( const CHostAddress& InetAddr,
const CVector<uint8_t>& vecData );
bool EvaluateCLReqServerListMes ( const CHostAddress& InetAddr );
bool EvaluateCLReqServerListMes ( const CHostAddress& InetAddr );
bool EvaluateCLSendEmptyMesMes ( const CVector<uint8_t>& vecData );
bool EvaluateCLDisconnectionMes ( const CHostAddress& InetAddr );
bool EvaluateCLDisconnectionMes ( const CHostAddress& InetAddr );
bool EvaluateCLVersionAndOSMes ( const CHostAddress& InetAddr,
const CVector<uint8_t>& vecData );
bool EvaluateCLReqVersionAndOSMes ( const CHostAddress& InetAddr );
bool EvaluateCLReqVersionAndOSMes ( const CHostAddress& InetAddr );
bool EvaluateCLConnClientsListMes ( const CHostAddress& InetAddr,
const CVector<uint8_t>& vecData );
bool EvaluateCLReqConnClientsListMes ( const CHostAddress& InetAddr,
const CVector<uint8_t>& vecData );
bool EvaluateCLReqConnClientsListMes ( const CHostAddress& InetAddr );
int iOldRecID;
int iOldRecCnt;
@ -303,10 +300,8 @@ signals:
QString strVersion );
void CLReqVersionAndOS ( CHostAddress InetAddr );
void CLConnClientsListMesReceived ( CHostAddress InetAddr,
int iRequestID,
CVector<CChannelInfo> vecChanInfo );
void CLReqConnClientsList ( CHostAddress InetAddr,
int iRequestID );
void CLReqConnClientsList ( CHostAddress InetAddr );
};
#endif /* !defined ( PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_ ) */

View file

@ -332,9 +332,8 @@ public slots:
void OnCLReqVersionAndOS ( CHostAddress InetAddr )
{ ConnLessProtocol.CreateCLVersionAndOSMes ( InetAddr ); }
void OnCLReqConnClientsList ( CHostAddress InetAddr,
int iRequestID )
{ ConnLessProtocol.CreateCLConnClientsListMes ( InetAddr, iRequestID, CreateChannelList() ); }
void OnCLReqConnClientsList ( CHostAddress InetAddr )
{ ConnLessProtocol.CreateCLConnClientsListMes ( InetAddr, CreateChannelList() ); }
void OnCLRegisterServerReceived ( CHostAddress InetAddr,
CServerCoreInfo ServerInfo )