Add mapped IPv4 address parser.

This commit is contained in:
Salanto 2021-10-17 15:47:18 +02:00
parent 6c15aa2164
commit d92ba88cb7
3 changed files with 28 additions and 2 deletions

View File

@ -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.
*/

View File

@ -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());

View File

@ -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)) {