implement multiclient limit

This commit is contained in:
scatterflower 2021-04-19 01:54:22 -05:00
parent 0454ac114c
commit e8a99eb35a
2 changed files with 31 additions and 1 deletions

View File

@ -301,6 +301,19 @@ void AOClient::pktWebSocketIp(AreaData* area, int argc, QStringList argv, AOPack
#endif #endif
remote_ip = QHostAddress(argv[0]); remote_ip = QHostAddress(argv[0]);
calculateIpid(); 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;
} }
} }

View File

@ -114,14 +114,31 @@ void Server::clientConnected()
break; break;
} }
AOClient* client = new AOClient(this, socket, this, user_id); 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())}); AOPacket ban_reason("BD", {db_manager->getBanReason(socket->peerAddress())});
socket->write(ban_reason.toUtf8()); socket->write(ban_reason.toUtf8());
}
if (is_banned || is_at_multiclient_limit) {
socket->flush(); socket->flush();
client->deleteLater(); client->deleteLater();
socket->close(); socket->close();
return; return;
} }
clients.append(client); clients.append(client);
connect(socket, &QTcpSocket::disconnected, client, connect(socket, &QTcpSocket::disconnected, client,
&AOClient::clientDisconnected); &AOClient::clientDisconnected);