From f45099e47b9630b1d762d30521a6b234ff801fa4 Mon Sep 17 00:00:00 2001 From: scatterflower Date: Sat, 13 Mar 2021 05:10:36 -0600 Subject: [PATCH 1/7] implement tsu-like time parsing --- include/aoclient.h | 7 +++- src/commands.cpp | 89 ++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 88 insertions(+), 8 deletions(-) diff --git a/include/aoclient.h b/include/aoclient.h index 4ff94c7..0cbf476 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -240,11 +240,15 @@ class AOClient : public QObject { void cmdToggleGlobal(int argc, QStringList argv); void cmdPM(int argc, QStringList argv); + // DELETE THIS LATER MARISA + void cmdTestDateTime(int argc, QStringList argv); + // Command helper functions QString getAreaTimer(int area_idx, QTimer* timer); QStringList buildAreaList(int area_idx); int genRand(int min, int max); void diceThrower(int argc, QStringList argv, RollType Type); + long long parseTime(QString input); // Command function global variables bool change_auth_started = false; @@ -309,7 +313,8 @@ class AOClient : public QObject { {"motd", {ACLFlags.value("NONE"), 0, &AOClient::cmdMOTD}}, {"announce", {ACLFlags.value("ANNOUNCE"), 1, &AOClient::cmdAnnounce}}, {"m", {ACLFlags.value("MODCHAT"), 1, &AOClient::cmdM}}, - {"gm", {ACLFlags.value("MODCHAT"), 1, &AOClient::cmdGM}} + {"gm", {ACLFlags.value("MODCHAT"), 1, &AOClient::cmdGM}}, + {"test", {ACLFlags.value("NONE"), 1, &AOClient::cmdTestDateTime}} }; QString partial_packet; diff --git a/src/commands.cpp b/src/commands.cpp index 04243a9..c0f2d18 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -89,19 +89,44 @@ void AOClient::cmdGetArea(int argc, QStringList argv) void AOClient::cmdBan(int argc, QStringList argv) { + QString args_str = argv[1]; + if (argc > 2) { + for (int i = 2; i < argc; i++) + args_str += " " + argv[i]; + } + + QRegularExpression quoteMatcher("['\"](.+?)[\"']"); + QRegularExpressionMatchIterator matches = quoteMatcher.globalMatch(args_str); + QList unquoted_args; + while (matches.hasNext()) { + QRegularExpressionMatch match = matches.next(); + unquoted_args.append(match.captured(1)); + } + + QString reason; + QString duration = "perma"; + + if (unquoted_args.length() < 1) { + sendServerMessage("Invalid syntax. Usage:\n/ban \"\" \"\""); + return; + } + + reason = unquoted_args.at(0); + if (unquoted_args.length() > 1) + duration = unquoted_args.at(1); + + + qDebug() << "Reason: " << reason; + qDebug() << "Duration: " << duration; + return; + QString target_ipid = argv[0]; QHostAddress ip; QString hdid; unsigned long time = QDateTime::currentDateTime().toTime_t(); - QString reason = argv[1]; + //QString reason = argv[1]; bool ban_logged = false; - if (argc > 2) { - for (int i = 2; i < argv.length(); i++) { - reason += " " + argv[i]; - } - } - for (AOClient* client : server->clients) { if (client->getIpid() == target_ipid) { if (!ban_logged) { @@ -1019,3 +1044,53 @@ QString AOClient::getAreaTimer(int area_idx, QTimer* timer) } } +void AOClient::cmdTestDateTime(int argc, QStringList argv) +{ + qDebug() << parseTime(argv[0]); +} + +long long AOClient::parseTime(QString input) +{ + QRegularExpression regex("(?:(?:(?.*?)y)*(?:(?.*?)w)*(?:(?.*?)d)*(?:(?
.*?)h)*(?:(?.*?)m)*(?:(?.*?)s)*)"); + QRegularExpressionMatch match = regex.match(input); + QString str_year, str_week, str_hour, str_day, str_minute, str_second; + int year, week, day, hour, minute, second; + + str_year = match.captured("year"); + str_week = match.captured("week"); + str_day = match.captured("day"); + str_hour = match.captured("hr"); + str_minute = match.captured("min"); + str_second = match.captured("sec"); + + qDebug() << str_year << "years," << str_week << "weeks," << str_day << "days," << str_hour << "hours," << str_minute << "minutes," << str_second << "seconds"; + + bool is_well_formed = false; + QString concat_str(str_year + str_week + str_day + str_hour + str_minute + str_second); + concat_str.toInt(&is_well_formed); + + if (!is_well_formed) { + qDebug() << "retard alert!"; + return -1; + } + + year = str_year.toInt(); + week = str_week.toInt(); + day = str_day.toInt(); + hour = str_hour.toInt(); + minute = str_minute.toInt(); + second = str_second.toInt(); + + long long total = 0; + total += 31622400 * year; + total += 604800 * week; + total += 86400 * day; + total += 3600 * hour; + total += 60 * minute; + total += second; + + if (total < 0) + return -1; + + return total; +} From 6a38e50c4f5a73ad14deaf14222078dd456fad5c Mon Sep 17 00:00:00 2001 From: scatterflower Date: Sat, 13 Mar 2021 13:25:09 -0600 Subject: [PATCH 2/7] add ban durations (only works for hdid atm) --- include/db_manager.h | 5 +++- src/commands.cpp | 19 ++++++++----- src/db_manager.cpp | 63 +++++++++++++++++++++++++++++++++++++++----- 3 files changed, 72 insertions(+), 15 deletions(-) diff --git a/include/db_manager.h b/include/db_manager.h index 150d751..d18b87a 100644 --- a/include/db_manager.h +++ b/include/db_manager.h @@ -19,6 +19,7 @@ #define BAN_MANAGER_H #include +#include #include #include #include @@ -37,8 +38,10 @@ public: QString getBanReason(QHostAddress ip); QString getBanReason(QString hdid); + long long getBanDuration(QString hdid); + long long getBanDuration(QHostAddress hdid); - void addBan(QString ipid, QHostAddress ip, QString hdid, unsigned long time, QString reason); + void addBan(QString ipid, QHostAddress ip, QString hdid, unsigned long time, QString reason, long long duration); bool createUser(QString username, QString salt, QString password, unsigned long long acl); unsigned long long getACL(QString moderator_name); diff --git a/src/commands.cpp b/src/commands.cpp index c0f2d18..071ad85 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -115,16 +115,21 @@ void AOClient::cmdBan(int argc, QStringList argv) if (unquoted_args.length() > 1) duration = unquoted_args.at(1); + long long duration_seconds = 0; + if (duration == "perma") + duration_seconds = -2; + else + duration_seconds = parseTime(duration); - qDebug() << "Reason: " << reason; - qDebug() << "Duration: " << duration; - return; + if (duration_seconds == -1) { + sendServerMessage("Invalid time format. Format example: 1h30m"); + return; + } QString target_ipid = argv[0]; QHostAddress ip; QString hdid; - unsigned long time = QDateTime::currentDateTime().toTime_t(); - //QString reason = argv[1]; + unsigned long time = QDateTime::currentDateTime().toSecsSinceEpoch(); bool ban_logged = false; for (AOClient* client : server->clients) { @@ -132,8 +137,8 @@ void AOClient::cmdBan(int argc, QStringList argv) if (!ban_logged) { ip = client->remote_ip; hdid = client->hwid; - server->db_manager->addBan(target_ipid, ip, hdid, time, reason); - sendServerMessage("Banned user with ipid " + target_ipid + " for reason: " + reason); + server->db_manager->addBan(target_ipid, ip, hdid, time, reason, duration_seconds); + sendServerMessage("Banned user with ipid " + target_ipid + " for " + duration + ". Reason: " + reason); ban_logged = true; } client->sendPacket("KB", {reason}); diff --git a/src/db_manager.cpp b/src/db_manager.cpp index f23f20e..0ea610d 100644 --- a/src/db_manager.cpp +++ b/src/db_manager.cpp @@ -24,26 +24,46 @@ DBManager::DBManager() : db.setDatabaseName("config/akashi.db"); if (!db.open()) qCritical() << "Database Error:" << db.lastError(); - QSqlQuery create_ban_table("CREATE TABLE IF NOT EXISTS bans ('ID' INTEGER, 'IPID' TEXT, 'HDID' TEXT, 'IP' TEXT, 'TIME' INTEGER, 'REASON' TEXT, PRIMARY KEY('ID' AUTOINCREMENT))"); + QSqlQuery create_ban_table("CREATE TABLE IF NOT EXISTS bans ('ID' INTEGER, 'IPID' TEXT, 'HDID' TEXT, 'IP' TEXT, 'TIME' INTEGER, 'REASON' TEXT, 'DURATION' INTEGER, PRIMARY KEY('ID' AUTOINCREMENT))"); QSqlQuery create_user_table("CREATE TABLE IF NOT EXISTS users ('ID' INTEGER, 'USERNAME' TEXT, 'SALT' TEXT, 'PASSWORD' TEXT, 'ACL' TEXT, PRIMARY KEY('ID' AUTOINCREMENT))"); } bool DBManager::isIPBanned(QHostAddress ip) { QSqlQuery query; - query.prepare("SELECT ID FROM BANS WHERE IP = ?"); + query.prepare("SELECT DURATION FROM BANS WHERE IP = ? ORDER BY TIME DESC"); query.addBindValue(ip.toString()); query.exec(); - return query.first(); + if (query.first()) { + long long duration = getBanDuration(ip); + long long ban_time = query.value(0).toLongLong(); + if (duration == -2) + return true; + long long current_time = QDateTime::currentDateTime().toSecsSinceEpoch(); + if (ban_time + duration > current_time) + return true; + else return false; + } + else return false; } bool DBManager::isHDIDBanned(QString hdid) { QSqlQuery query; - query.prepare("SELECT ID FROM BANS WHERE HDID = ?"); + query.prepare("SELECT TIME FROM BANS WHERE HDID = ? ORDER BY TIME DESC"); query.addBindValue(hdid); query.exec(); - return query.first(); + if (query.first()) { + long long duration = getBanDuration(hdid); + long long ban_time = query.value(0).toLongLong(); + if (duration == -2) + return true; + long long current_time = QDateTime::currentDateTime().toSecsSinceEpoch(); + if (ban_time + duration > current_time) + return true; + else return false; + } + else return false; } QString DBManager::getBanReason(QHostAddress ip) @@ -74,15 +94,44 @@ QString DBManager::getBanReason(QString hdid) } } -void DBManager::addBan(QString ipid, QHostAddress ip, QString hdid, unsigned long time, QString reason) +long long DBManager::getBanDuration(QString hdid) { QSqlQuery query; - query.prepare("INSERT INTO BANS(IPID, HDID, IP, TIME, REASON) VALUES(?, ?, ?, ?, ?)"); + query.prepare("SELECT DURATION FROM BANS WHERE HDID = ?"); + query.addBindValue(hdid); + query.exec(); + if (query.first()) { + return query.value(0).toLongLong(); + } + else { + return -1; + } +} + +long long DBManager::getBanDuration(QHostAddress ip) +{ + QSqlQuery query; + query.prepare("SELECT DURATION FROM BANS WHERE IP = ?"); + query.addBindValue(ip.toString()); + query.exec(); + if (query.first()) { + return query.value(0).toLongLong(); + } + else { + return -1; + } +} + +void DBManager::addBan(QString ipid, QHostAddress ip, QString hdid, unsigned long time, QString reason, long long duration) +{ + QSqlQuery query; + query.prepare("INSERT INTO BANS(IPID, HDID, IP, TIME, REASON, DURATION) VALUES(?, ?, ?, ?, ?, ?)"); query.addBindValue(ipid); query.addBindValue(hdid); query.addBindValue(ip.toString()); query.addBindValue(QString::number(time)); query.addBindValue(reason); + query.addBindValue(duration); if (!query.exec()) qDebug() << "SQL Error:" << query.lastError().text(); } From fa72e87e34fcfa0012bffc0c9279b6a90658a2d4 Mon Sep 17 00:00:00 2001 From: scatterflower Date: Sat, 13 Mar 2021 13:33:47 -0600 Subject: [PATCH 3/7] fix ip bans and generally make it work correctly --- src/db_manager.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/db_manager.cpp b/src/db_manager.cpp index 0ea610d..cdd68c1 100644 --- a/src/db_manager.cpp +++ b/src/db_manager.cpp @@ -31,12 +31,13 @@ DBManager::DBManager() : bool DBManager::isIPBanned(QHostAddress ip) { QSqlQuery query; - query.prepare("SELECT DURATION FROM BANS WHERE IP = ? ORDER BY TIME DESC"); + query.prepare("SELECT TIME FROM BANS WHERE IP = ? ORDER BY TIME DESC"); query.addBindValue(ip.toString()); query.exec(); if (query.first()) { long long duration = getBanDuration(ip); long long ban_time = query.value(0).toLongLong(); + qDebug() << ban_time << "duration:" << duration; if (duration == -2) return true; long long current_time = QDateTime::currentDateTime().toSecsSinceEpoch(); @@ -69,7 +70,7 @@ bool DBManager::isHDIDBanned(QString hdid) QString DBManager::getBanReason(QHostAddress ip) { QSqlQuery query; - query.prepare("SELECT REASON FROM BANS WHERE IP = ?"); + query.prepare("SELECT REASON FROM BANS WHERE IP = ? ORDER BY TIME DESC"); query.addBindValue(ip.toString()); query.exec(); if (query.first()) { @@ -83,7 +84,7 @@ QString DBManager::getBanReason(QHostAddress ip) QString DBManager::getBanReason(QString hdid) { QSqlQuery query; - query.prepare("SELECT REASON FROM BANS WHERE HDID = ?"); + query.prepare("SELECT REASON FROM BANS WHERE HDID = ? ORDER BY TIME DESC"); query.addBindValue(hdid); query.exec(); if (query.first()) { @@ -97,7 +98,7 @@ QString DBManager::getBanReason(QString hdid) long long DBManager::getBanDuration(QString hdid) { QSqlQuery query; - query.prepare("SELECT DURATION FROM BANS WHERE HDID = ?"); + query.prepare("SELECT DURATION FROM BANS WHERE HDID = ? ORDER BY TIME DESC"); query.addBindValue(hdid); query.exec(); if (query.first()) { @@ -111,7 +112,7 @@ long long DBManager::getBanDuration(QString hdid) long long DBManager::getBanDuration(QHostAddress ip) { QSqlQuery query; - query.prepare("SELECT DURATION FROM BANS WHERE IP = ?"); + query.prepare("SELECT DURATION FROM BANS WHERE IP = ? ORDER BY TIME DESC"); query.addBindValue(ip.toString()); query.exec(); if (query.first()) { From 5368601b6750df0ecb2c0c7fd35e5a5d424a719d Mon Sep 17 00:00:00 2001 From: scatterflower Date: Sat, 13 Mar 2021 13:40:37 -0600 Subject: [PATCH 4/7] remove desu --- include/aoclient.h | 6 +----- src/commands.cpp | 8 -------- src/db_manager.cpp | 1 - 3 files changed, 1 insertion(+), 14 deletions(-) diff --git a/include/aoclient.h b/include/aoclient.h index 0cbf476..061b193 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -240,9 +240,6 @@ class AOClient : public QObject { void cmdToggleGlobal(int argc, QStringList argv); void cmdPM(int argc, QStringList argv); - // DELETE THIS LATER MARISA - void cmdTestDateTime(int argc, QStringList argv); - // Command helper functions QString getAreaTimer(int area_idx, QTimer* timer); QStringList buildAreaList(int area_idx); @@ -313,8 +310,7 @@ class AOClient : public QObject { {"motd", {ACLFlags.value("NONE"), 0, &AOClient::cmdMOTD}}, {"announce", {ACLFlags.value("ANNOUNCE"), 1, &AOClient::cmdAnnounce}}, {"m", {ACLFlags.value("MODCHAT"), 1, &AOClient::cmdM}}, - {"gm", {ACLFlags.value("MODCHAT"), 1, &AOClient::cmdGM}}, - {"test", {ACLFlags.value("NONE"), 1, &AOClient::cmdTestDateTime}} + {"gm", {ACLFlags.value("MODCHAT"), 1, &AOClient::cmdGM}} }; QString partial_packet; diff --git a/src/commands.cpp b/src/commands.cpp index 071ad85..e290fe5 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -1049,11 +1049,6 @@ QString AOClient::getAreaTimer(int area_idx, QTimer* timer) } } -void AOClient::cmdTestDateTime(int argc, QStringList argv) -{ - qDebug() << parseTime(argv[0]); -} - long long AOClient::parseTime(QString input) { QRegularExpression regex("(?:(?:(?.*?)y)*(?:(?.*?)w)*(?:(?.*?)d)*(?:(?
.*?)h)*(?:(?.*?)m)*(?:(?.*?)s)*)"); @@ -1068,14 +1063,11 @@ long long AOClient::parseTime(QString input) str_minute = match.captured("min"); str_second = match.captured("sec"); - qDebug() << str_year << "years," << str_week << "weeks," << str_day << "days," << str_hour << "hours," << str_minute << "minutes," << str_second << "seconds"; - bool is_well_formed = false; QString concat_str(str_year + str_week + str_day + str_hour + str_minute + str_second); concat_str.toInt(&is_well_formed); if (!is_well_formed) { - qDebug() << "retard alert!"; return -1; } diff --git a/src/db_manager.cpp b/src/db_manager.cpp index cdd68c1..6a0c0b7 100644 --- a/src/db_manager.cpp +++ b/src/db_manager.cpp @@ -37,7 +37,6 @@ bool DBManager::isIPBanned(QHostAddress ip) if (query.first()) { long long duration = getBanDuration(ip); long long ban_time = query.value(0).toLongLong(); - qDebug() << ban_time << "duration:" << duration; if (duration == -2) return true; long long current_time = QDateTime::currentDateTime().toSecsSinceEpoch(); From 6f1d17f923e1ae544e403e1b26f51861379c14c6 Mon Sep 17 00:00:00 2001 From: scatterflower <2956568+scatterflower@users.noreply.github.com> Date: Sat, 13 Mar 2021 13:57:58 -0600 Subject: [PATCH 5/7] Update README.md --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3681abc..862d627 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,8 @@ Requires Qt >= 5.10, and Qt websockets make ``` -Copyright © scatterflower 2021 \ No newline at end of file +Copyright © scatterflower 2020-2021 + +Copyright © Salanto 2021 + +Copyright © in1tiate 2021 From c6733396533f8681f44972b1e41babafdaae6539 Mon Sep 17 00:00:00 2001 From: scatterflower Date: Sun, 14 Mar 2021 08:21:58 -0500 Subject: [PATCH 6/7] Add mute and unmute --- include/aoclient.h | 8 +++++++- src/commands.cpp | 32 ++++++++++++++++++++++++++++++++ src/packets.cpp | 5 +++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/include/aoclient.h b/include/aoclient.h index 061b193..2da1478 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -59,6 +59,7 @@ class AOClient : public QObject { QString ooc_name = ""; QString showname = ""; bool global_enabled = true; + bool is_muted = false; struct ClientVersion { QString string; int release = -1; @@ -79,6 +80,7 @@ class AOClient : public QObject { {"MOTD", 1ULL << 7}, {"ANNOUNCE", 1ULL << 8}, {"MODCHAT", 1ULL << 9}, + {"MUTE", 1ULL << 10}, {"SUPER", ~0ULL} }; @@ -221,6 +223,8 @@ class AOClient : public QObject { void cmdAnnounce(int argc, QStringList argv); void cmdM(int argc, QStringList argv); void cmdGM(int argc, QStringList argv); + void cmdMute(int argc, QStringList argv); + void cmdUnmute(int argc, QStringList argv); // Casing/RP void cmdPlay(int argc, QStringList argv); void cmdNeed(int argc, QStringList argv); @@ -310,7 +314,9 @@ class AOClient : public QObject { {"motd", {ACLFlags.value("NONE"), 0, &AOClient::cmdMOTD}}, {"announce", {ACLFlags.value("ANNOUNCE"), 1, &AOClient::cmdAnnounce}}, {"m", {ACLFlags.value("MODCHAT"), 1, &AOClient::cmdM}}, - {"gm", {ACLFlags.value("MODCHAT"), 1, &AOClient::cmdGM}} + {"gm", {ACLFlags.value("MODCHAT"), 1, &AOClient::cmdGM}}, + {"mute", {ACLFlags.value("MUTE"), 1, &AOClient::cmdMute}}, + {"unmute", {ACLFlags.value("MUTE"), 1, &AOClient::cmdUnmute}} }; QString partial_packet; diff --git a/src/commands.cpp b/src/commands.cpp index e290fe5..0a6df94 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -933,6 +933,38 @@ void AOClient::cmdGM(int argc, QStringList argv) } } +void AOClient::cmdMute(int argc, QStringList argv) +{ + bool conv_ok = false; + int uid = argv[0].toInt(&conv_ok); + if (!conv_ok) { + sendServerMessage("Invalid user ID."); + return; + } + + if (server->getClientByID(uid)->is_muted) + sendServerMessage("That player is already muted!"); + else + sendServerMessage("Muted player."); + server->getClientByID(uid)->is_muted = true; +} + +void AOClient::cmdUnmute(int argc, QStringList argv) +{ + bool conv_ok = false; + int uid = argv[0].toInt(&conv_ok); + if (!conv_ok) { + sendServerMessage("Invalid user ID."); + return; + } + + if (!server->getClientByID(uid)->is_muted) + sendServerMessage("That player is already unmuted!"); + else + sendServerMessage("Unmuted player."); + server->getClientByID(uid)->is_muted = false; +} + QStringList AOClient::buildAreaList(int area_idx) { QStringList entries; diff --git a/src/packets.cpp b/src/packets.cpp index 9cc9989..6dcd25f 100644 --- a/src/packets.cpp +++ b/src/packets.cpp @@ -154,6 +154,11 @@ void AOClient::pktSelectChar(AreaData* area, int argc, QStringList argv, AOPacke void AOClient::pktIcChat(AreaData* area, int argc, QStringList argv, AOPacket packet) { + if (is_muted) { + sendServerMessage("You cannot speak while muted."); + return; + } + AOPacket validated_packet = validateIcPacket(packet); if (validated_packet.header == "INVALID") return; From ae0d308ec786b51bf6ae88a4beff3e794bfaa261 Mon Sep 17 00:00:00 2001 From: scatterflower Date: Sun, 14 Mar 2021 12:01:27 -0500 Subject: [PATCH 7/7] 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(); } }