summaryrefslogtreecommitdiffstats
path: root/src/server/net/discoverylistener.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/net/discoverylistener.cpp')
-rw-r--r--src/server/net/discoverylistener.cpp23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/server/net/discoverylistener.cpp b/src/server/net/discoverylistener.cpp
index b0f0df4..d644259 100644
--- a/src/server/net/discoverylistener.cpp
+++ b/src/server/net/discoverylistener.cpp
@@ -29,23 +29,20 @@
/**
* @brief DiscoveryListener::DiscoveryListener
*/
-DiscoveryListener::DiscoveryListener() :
- _socket(this), _counterResetPos(0)
+DiscoveryListener::DiscoveryListener(QObject *parent)
+ : _socket(this)
{
- if (!_socket.bind(QHostAddress::AnyIPv4, SERVICE_DISCOVERY_PORT))
+ if (!_socket.bind(QHostAddress::AnyIPv4, SERVICE_DISCOVERY_PORT)) {
qFatal("Could not bind to service discovery port %d", int(SERVICE_DISCOVERY_PORT));
- connect(&_socket, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
- for (int i = 0; i < SD_PACKET_TABLE_SIZE; ++i)
- _packetCounter[i] = 0;
+ }
+ connect(&_socket, &QUdpSocket::readyRead, this, &DiscoveryListener::onReadyRead);
startTimer((SPAM_MODERATE_AT_ONCE * SPAM_MODERATE_INTERVAL) / SD_PACKET_TABLE_SIZE + 1);
}
/**
* @brief DiscoveryListener::~DiscoveryListener
*/
-DiscoveryListener::~DiscoveryListener()
-{
-}
+DiscoveryListener::~DiscoveryListener() = default;
/**
* @brief hash
@@ -57,8 +54,8 @@ static quint16 hash(const QHostAddress& host)
static quint16 seed1 = 0, seed2 = 0;
while (seed1 == 0) { // Make sure the algorithm uses different seeds each time the program is
// run to prevent hash collision attacks
- seed1 = quint16(qrand() & 0xffff);
- seed2 = quint16(qrand() & 0xffff);
+ seed1 = quint16(slxrand() & 0xffff);
+ seed2 = quint16(slxrand() & 0xffff);
}
quint8 data[16], len;
if (host.protocol() == QAbstractSocket::IPv4Protocol) {
@@ -79,8 +76,8 @@ static quint16 hash(const QHostAddress& host)
} else {
// Durr?
len = 2;
- data[0] = quint8(qrand());
- data[1] = quint8(qrand());
+ data[0] = quint8(slxrand());
+ data[1] = quint8(slxrand());
}
quint16 result = 0;
quint16 mod = seed1;