added trusted sources to servatrice

This commit is contained in:
wcollins 2014-11-18 15:09:21 -05:00
parent b351abcce4
commit da98d24d8c
3 changed files with 161 additions and 142 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=""
; 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"
@ -34,7 +35,10 @@
#include "main.h"
#include "decklist.h"
#include "pb/event_server_message.pb.h"
#include "pb/event_server_shutdown.pb.h"
#include "pb/event_server_shutdo; 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=""wn.pb.h"
#include "pb/event_connection_closed.pb.h"
Servatrice_GameServer::Servatrice_GameServer(Servatrice *_server, int _numberPools, const QSqlDatabase &_sqlDatabase, QObject *parent)
@ -379,10 +383,16 @@ QList<ServerProperties> Servatrice::getServerList() const
int Servatrice::getUsersWithAddress(const QHostAddress &address) const
{
int result = 0;
QReadLocker locker(&clientsLock);
for (int i = 0; i < clients.size(); ++i)
if (static_cast<ServerSocketInterface *>(clients[i])->getPeerAddress() == address)
++result;
QString trustedSources = settingsCache->value("server/trusted_sources","127.0.0.1,::1").toString();
if (trustedSources.contains(address.toString(),Qt::CaseInsensitive)) {
//allow all clients from trusted sources regardsless of number of connections
} else {
QReadLocker locker(&clientsLock);
for (int i = 0; i < clients.size(); ++i)
if (static_cast<ServerSocketInterface *>(clients[i])->getPeerAddress() == address)
++result;
}
return result;
}

View file

@ -22,6 +22,7 @@
#include <QHostAddress>
#include <QDebug>
#include <QDateTime>
#include "settingscache.h"
#include "serversocketinterface.h"
#include "servatrice.h"
#include "servatrice_database_interface.h"
@ -707,7 +708,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)");