diff --git a/core/include/server.h b/core/include/server.h index 9de8c4b..1e0acd0 100644 --- a/core/include/server.h +++ b/core/include/server.h @@ -223,6 +223,11 @@ class Server : public QObject { */ QTimer next_message_timer; + /** + * @brief Attempts to parse a IPv6 mapped IPv4 to an IPv4. + */ + QHostAddress parseToIPv4(QHostAddress f_remote_ip); + /** * @brief If false, IC messages will be rejected. */ diff --git a/core/src/packets.cpp b/core/src/packets.cpp index cdad7c5..b668ff5 100644 --- a/core/src/packets.cpp +++ b/core/src/packets.cpp @@ -399,7 +399,12 @@ void AOClient::pktWebSocketIp(AreaData* area, int argc, QStringList argv, AOPack #endif m_remote_ip = QHostAddress(argv[0]); - if (server->isIPBanned(m_remote_ip)){ + QHostAddress l_remote_ip = m_remote_ip; + if (l_remote_ip.protocol() == QAbstractSocket::IPv6Protocol) { + l_remote_ip = server->parseToIPv4(l_remote_ip); + } + + if (server->isIPBanned(l_remote_ip)){ QString l_reason = "Your IP has been banned by a moderator."; AOPacket l_ban_reason("BD", {l_reason}); m_socket->write(l_ban_reason.toUtf8()); diff --git a/core/src/server.cpp b/core/src/server.cpp index 8f47b1f..27af9ec 100644 --- a/core/src/server.cpp +++ b/core/src/server.cpp @@ -148,7 +148,12 @@ void Server::clientConnected() return; } - if (isIPBanned(client->m_remote_ip)){ + QHostAddress l_remote_ip = client->m_remote_ip; + if (l_remote_ip.protocol() == QAbstractSocket::IPv6Protocol) { + l_remote_ip = parseToIPv4(l_remote_ip); + } + + if (isIPBanned(l_remote_ip)){ QString l_reason = "Your IP has been banned by a moderator."; AOPacket l_ban_reason("BD", {l_reason}); socket->write(l_ban_reason.toUtf8()); @@ -212,6 +217,17 @@ QStringList Server::getCursedCharsTaken(AOClient* client, QStringList chars_take return chars_taken_cursed; } +QHostAddress Server::parseToIPv4(QHostAddress f_remote_ip) +{ + bool l_ok; + QHostAddress l_remote_ip = f_remote_ip; + QHostAddress l_temp_remote_ip = QHostAddress(f_remote_ip.toIPv4Address(&l_ok)); + if (l_ok) { + l_remote_ip = l_temp_remote_ip; + } + return l_remote_ip; +} + void Server::broadcast(AOPacket packet, int area_index) { for (AOClient* client : qAsConst(m_clients)) {