summaryrefslogtreecommitdiffstats
path: root/src/client/net/serverdiscovery.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/net/serverdiscovery.cpp')
-rw-r--r--src/client/net/serverdiscovery.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/client/net/serverdiscovery.cpp b/src/client/net/serverdiscovery.cpp
index 799fcbe..1b29398 100644
--- a/src/client/net/serverdiscovery.cpp
+++ b/src/client/net/serverdiscovery.cpp
@@ -21,7 +21,7 @@ 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 + qrand() % 32768);
if (_discoverySocket.bind(QHostAddress::AnyIPv4, port))
break;
if (tries == 0)
@@ -98,8 +98,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(qrand() & 0xff);
+ _salt2[i] = char(qrand() & 0xff);
}
_packet.reset();
_packet.setField(_HASH, genSha1(&_nameBytes, &salt1, &iplist));
@@ -154,7 +154,7 @@ void ServerDiscovery::onUdpReadyRead()
continue;
_packet.reset();
- if (_packet.readMessage(data, (quint32)size) != NM_READ_OK)
+ if (_packet.readMessage(data, quint32(size)) != NM_READ_OK)
continue;
// Valid packet, process it:
@@ -183,7 +183,11 @@ void ServerDiscovery::onUdpReadyRead()
<< addr.toString() + ":" + QString::fromUtf8(port) + "/" + _nameBytes;
// Tell that a server hs been found
- emit serverDetected(addr.toString(), (quint16)QString::fromUtf8(port).toInt(), _nameBytes, cert, (_mgrIP == addr));
+ bool ok = false;
+ const ushort iport = QString::fromUtf8(port).toUShort(&ok);
+ if (ok) {
+ emit serverDetected(addr.toString(), quint16(iport), _nameBytes, cert, (_mgrIP == addr));
+ }
// Stop the discovery
this->stop();