From ae0d308ec786b51bf6ae88a4beff3e794bfaa261 Mon Sep 17 00:00:00 2001 From: scatterflower Date: Sun, 14 Mar 2021 12:01:27 -0500 Subject: [PATCH] apparently ipids are different --- include/aoclient.h | 5 ++--- src/aoclient.cpp | 16 ++++++---------- src/packets.cpp | 9 +++++---- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/include/aoclient.h b/include/aoclient.h index 2da1478..1d663fe 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -42,10 +42,9 @@ class AOClient : public QObject { AOClient(Server* p_server, QTcpSocket* p_socket, QObject* parent = nullptr, int user_id = 0); ~AOClient(); - QString getHwid(); - QString getIpid(); Server* getServer(); - void setHwid(QString p_hwid); + QString getIpid(); + void calculateIpid(); int id; diff --git a/src/aoclient.cpp b/src/aoclient.cpp index 2d8f26c..10521af 100644 --- a/src/aoclient.cpp +++ b/src/aoclient.cpp @@ -28,6 +28,7 @@ AOClient::AOClient(Server* p_server, QTcpSocket* p_socket, QObject* parent, int current_area = 0; current_char = ""; remote_ip = p_socket->peerAddress(); + calculateIpid(); is_partial = false; last_wtce_time = 0; last_message = ""; @@ -274,22 +275,17 @@ void AOClient::sendPacket(QString header) sendPacket(AOPacket(header, {})); } -QString AOClient::getHwid() { return hwid; } - -void AOClient::setHwid(QString p_hwid) +void AOClient::calculateIpid() { - // TODO: add support for longer hwids? + // TODO: add support for longer ipids? // This reduces the (fairly high) chance of // birthday paradox issues arising. However, // typing more than 8 characters might be a // bit cumbersome. - hwid = p_hwid; - QCryptographicHash hash( - QCryptographicHash::Md5); // Don't need security, just - // hashing for uniqueness - QString concat_ip_id = remote_ip.toString() + p_hwid; - hash.addData(concat_ip_id.toUtf8()); + QCryptographicHash hash(QCryptographicHash::Md5); // Don't need security, just hashing for uniqueness + + hash.addData(remote_ip.toString().toUtf8()); ipid = hash.result().toHex().right(8); // Use the last 8 characters (4 bytes) } diff --git a/src/packets.cpp b/src/packets.cpp index 6dcd25f..9cfc22a 100644 --- a/src/packets.cpp +++ b/src/packets.cpp @@ -26,9 +26,9 @@ void AOClient::pktDefault(AreaData* area, int argc, QStringList argv, AOPacket p void AOClient::pktHardwareId(AreaData* area, int argc, QStringList argv, AOPacket packet) { - setHwid(argv[0]); - if(server->db_manager->isHDIDBanned(getHwid())) { - sendPacket("BD", {server->db_manager->getBanReason(getHwid())}); + hwid = argv[0]; + if(server->db_manager->isHDIDBanned(hwid)) { + sendPacket("BD", {server->db_manager->getBanReason(hwid)}); socket->close(); return; } @@ -88,7 +88,7 @@ void AOClient::pktRequestMusic(AreaData* area, int argc, QStringList argv, AOPac void AOClient::pktLoadingDone(AreaData* area, int argc, QStringList argv, AOPacket packet) { - if (getHwid() == "") { + if (hwid == "") { // No early connecting! socket->close(); return; @@ -271,6 +271,7 @@ void AOClient::pktWebSocketIp(AreaData* area, int argc, QStringList argv, AOPack qDebug() << "ws ip set to" << argv[0]; #endif remote_ip = QHostAddress(argv[0]); + calculateIpid(); } }