diff --git a/src/packets.cpp b/src/packets.cpp index 39709b1..2595576 100644 --- a/src/packets.cpp +++ b/src/packets.cpp @@ -301,6 +301,19 @@ void AOClient::pktWebSocketIp(AreaData* area, int argc, QStringList argv, AOPack #endif remote_ip = QHostAddress(argv[0]); calculateIpid(); + + int multiclient_count = 0; + for (AOClient* joined_client : server->clients) { + if (remote_ip.isEqual(joined_client->remote_ip)) + multiclient_count++; + } + + if (multiclient_count > 5) { + socket->close(); + return; + } + + qDebug() << "MULTICLIENT COUNT WS: " << multiclient_count; } } diff --git a/src/server.cpp b/src/server.cpp index e0c5825..9ecdb31 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -114,14 +114,31 @@ void Server::clientConnected() break; } AOClient* client = new AOClient(this, socket, this, user_id); - if (db_manager->isIPBanned(socket->peerAddress())) { + + int multiclient_count = 1; + bool is_at_multiclient_limit = false; + bool is_banned = db_manager->isIPBanned(socket->peerAddress()); + for (AOClient* joined_client : clients) { + if (client->remote_ip.isEqual(joined_client->remote_ip)) + multiclient_count++; + } + + qDebug() << "MULTICLIENT COUNT: " << multiclient_count; + + if (multiclient_count > 5 && !client->remote_ip.isLoopback()) // TODO: make this configurable + is_at_multiclient_limit = true; + + if (is_banned) { AOPacket ban_reason("BD", {db_manager->getBanReason(socket->peerAddress())}); socket->write(ban_reason.toUtf8()); + } + if (is_banned || is_at_multiclient_limit) { socket->flush(); client->deleteLater(); socket->close(); return; } + clients.append(client); connect(socket, &QTcpSocket::disconnected, client, &AOClient::clientDisconnected);