Merge pull request #441 from woogerboy21/servatrice_trustedsources

Servatrice trustedsources
This commit is contained in:
woogerboy21 2014-12-01 10:46:55 -05:00
commit 8b0d67ea5c
3 changed files with 631 additions and 613 deletions

View file

@ -125,6 +125,11 @@ max_game_inactivity_time=120
; Maximum number of users that can connect from the same IP address; useful to avoid bots, default is 4
max_users_per_address=4
; You may want to allow an unlimited number of users from a trusted source. This setting can contain a
; comma-separed list of IP addresses which will allow an unlimited number of connections from each of the
; IP addresses listed (ignoring the max_users_per_address). Default is "127.0.0.1,::1"; example: "192.73.233.244,81.4.100.74"
trusted_sources="127.0.0.1,::1"
; Servatrice can avoid users from flooding rooms with large number messages in an interval of time.
; This setting defines the length in seconds of the considered interval; default is 10
message_counting_interval=10

View file

@ -22,6 +22,7 @@
#include <QTimer>
#include <QDateTime>
#include <QDebug>
#include <QString>
#include <iostream>
#include "servatrice.h"
#include "servatrice_database_interface.h"
@ -383,6 +384,7 @@ int Servatrice::getUsersWithAddress(const QHostAddress &address) const
for (int i = 0; i < clients.size(); ++i)
if (static_cast<ServerSocketInterface *>(clients[i])->getPeerAddress() == address)
++result;
return result;
}

View file

@ -22,6 +22,8 @@
#include <QHostAddress>
#include <QDebug>
#include <QDateTime>
#include <QString>
#include "settingscache.h"
#include "serversocketinterface.h"
#include "servatrice.h"
#include "servatrice_database_interface.h"
@ -117,6 +119,12 @@ bool ServerSocketInterface::initSession()
delete identSe;
int maxUsers = servatrice->getMaxUsersPerAddress();
//allow unlimited number of connections from the trusted sources
QString trustedSources = settingsCache->value("server/trusted_sources","127.0.0.1,::1").toString();
if (trustedSources.contains(socket->peerAddress().toString(),Qt::CaseInsensitive))
return true;
if ((maxUsers > 0) && (servatrice->getUsersWithAddress(socket->peerAddress()) >= maxUsers)) {
Event_ConnectionClosed event;
event.set_reason(Event_ConnectionClosed::TOO_MANY_CONNECTIONS);
@ -707,7 +715,10 @@ Response::ResponseCode ServerSocketInterface::cmdBanFromServer(const Command_Ban
QString userName = QString::fromStdString(cmd.user_name());
QString address = QString::fromStdString(cmd.address());
QString trustedSources = settingsCache->value("server/trusted_sources","127.0.0.1,::1").toString();
int minutes = cmd.minutes();
if (trustedSources.contains(address,Qt::CaseInsensitive))
address = "";
QSqlQuery query(sqlInterface->getDatabase());
query.prepare("insert into " + servatrice->getDbPrefix() + "_bans (user_name, ip_address, id_admin, time_from, minutes, reason, visible_reason) values(:user_name, :ip_address, :id_admin, NOW(), :minutes, :reason, :visible_reason)");