From 9f479b8f76238a03bce5d13aee14efd34e659c6e Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Sun, 30 Oct 2022 20:34:23 +0100 Subject: Clean up and modernize code - static "new-style" signal->slot connections - Fix a lot of things Clang-Tidy complained about - Move includes to .cpp files and use forward decls in .h - Don't use and , but specific includes instead --- src/client/net/serverdiscovery.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'src/client/net/serverdiscovery.cpp') diff --git a/src/client/net/serverdiscovery.cpp b/src/client/net/serverdiscovery.cpp index b2d7605..efae165 100644 --- a/src/client/net/serverdiscovery.cpp +++ b/src/client/net/serverdiscovery.cpp @@ -4,8 +4,7 @@ #include "../../shared/network.h" #include "../../shared/util.h" #include "serverdiscovery.h" -#include - +#include "../util/util.h" /** * Ctor @@ -21,33 +20,31 @@ ServerDiscovery::ServerDiscovery(QObject *parent) /* Try to get a UDP port for server discovery */ int tries = 10; while (tries-- != 0) { - quint16 port = quint16(16384 + qrand() % 32768); + quint16 port = quint16(16384 + slxrand() % 32768); if (_discoverySocket.bind(QHostAddress::AnyIPv4, port)) break; if (tries == 0) qFatal("Could not bind to any UDP port for server discovery."); } // Handle incoming messages - connect(&_discoverySocket, SIGNAL(readyRead()), this, SLOT(onUdpReadyRead())); + connect(&_discoverySocket, &QUdpSocket::readyRead, this, &ServerDiscovery::onUdpReadyRead); /* Setup the discovery timer */ _discoveryTimer.setInterval(_minDiscoveryInterval); _discoveryTimer.setSingleShot(true); // - connect(&_discoveryTimer, SIGNAL(timeout()), this, SLOT(doDiscovery())); + connect(&_discoveryTimer, &QTimer::timeout, this, &ServerDiscovery::doDiscovery); } /** * Dtor */ -ServerDiscovery::~ServerDiscovery() -{ -} +ServerDiscovery::~ServerDiscovery() = default; /** * @brief start */ -void ServerDiscovery::start(const QByteArray& sessionName, QString mgrIP) +void ServerDiscovery::start(const QByteArray& sessionName, const QString& mgrIP) { if (!mgrIP.isEmpty()) { _mgrIP.setAddress(mgrIP); @@ -98,8 +95,8 @@ void ServerDiscovery::doDiscovery() if (_salt2.size() < SALT_LEN) _salt2.resize(SALT_LEN); for (int i = 0; i < SALT_LEN; ++i) { - salt1[i] = char(qrand() & 0xff); - _salt2[i] = char(qrand() & 0xff); + salt1[i] = char(slxrand() & 0xff); + _salt2[i] = char(slxrand() & 0xff); } _packet.reset(); _packet.setField(_HASH, genSha1(&_nameBytes, &salt1, &iplist)); @@ -141,7 +138,7 @@ void ServerDiscovery::onUdpReadyRead() { char data[UDPBUFSIZ]; QHostAddress addr; - quint16 port; + quint16 peerPort; while (_discoverySocket.hasPendingDatagrams()) { // Discard any packets if discovery is stopped if (!this->isActive()) { @@ -149,7 +146,7 @@ void ServerDiscovery::onUdpReadyRead() continue; } - const qint64 size = _discoverySocket.readDatagram(data, UDPBUFSIZ, &addr, &port); + const qint64 size = _discoverySocket.readDatagram(data, UDPBUFSIZ, &addr, &peerPort); if (size <= 0) //|| clientApp->connection() != nullptr) // TODO CHECK continue; -- cgit v1.2.3-55-g7522