diff options
Diffstat (limited to 'src/client/net')
-rw-r--r-- | src/client/net/serverconnection.cpp | 6 | ||||
-rw-r--r-- | src/client/net/serverdiscovery.cpp | 14 |
2 files changed, 12 insertions, 8 deletions
diff --git a/src/client/net/serverconnection.cpp b/src/client/net/serverconnection.cpp index 6350418..ca19c76 100644 --- a/src/client/net/serverconnection.cpp +++ b/src/client/net/serverconnection.cpp @@ -33,7 +33,7 @@ ServerConnection::ServerConnection(const QString& host, const quint16 port, cons SLOT(sslErrors(const QList<QSslError> &)) ); connect(_socket, &QSslSocket::peerVerifyError, [=](const QSslError &error) { qDebug() << "PVE:" << error.errorString(); }); - qDebug("Connecting to %s on port %d", host.toUtf8().data(), (int)port); + qDebug("Connecting to %s on port %d", host.toUtf8().data(), int(port)); _socket->ignoreSslErrors(); _socket->connectToHostEncrypted(host, port); _timerId = startTimer(4000); @@ -112,7 +112,7 @@ void ServerConnection::handleMsg() emit stateChange(ConnectWindow::AwaitingChallengeResponse); _myChallenge.resize(CHALLENGE_LEN); for (int i = 0; i < CHALLENGE_LEN; ++i) { - _myChallenge[i] = (char)(qrand() & 0xff); + _myChallenge[i] = char(qrand() & 0xff); } QByteArray serverChallenge(_fromServer.getFieldBytes(_CHALLENGE)); _toServer.reset(); @@ -407,7 +407,7 @@ void ServerConnection::sock_closed() void ServerConnection::sock_error(QAbstractSocket::SocketError errcode) { - qDebug("Connection error: %d", (int)errcode); + qDebug("Connection error: %d", int(errcode)); this->disconnectFromServer(); } 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(); |