From 0261862b1b647bb5c22c2e8f91dae3a9eeb028bf Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Sat, 4 Oct 2014 10:33:55 +0200 Subject: [PATCH 1/6] Fix configuration loading --- servatrice/src/main.cpp | 2 +- servatrice/src/settingscache.cpp | 6 ++++++ servatrice/src/settingscache.h | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/servatrice/src/main.cpp b/servatrice/src/main.cpp index 49b06b27..6c29e8be 100644 --- a/servatrice/src/main.cpp +++ b/servatrice/src/main.cpp @@ -166,7 +166,7 @@ int main(int argc, char *argv[]) configPath = SettingsCache::guessConfigurationPath(configPath); qWarning() << "Using configuration file: " << configPath; - settingsCache = new SettingsCache(); + settingsCache = new SettingsCache(configPath); loggerThread = new QThread; loggerThread->setObjectName("logger"); diff --git a/servatrice/src/settingscache.cpp b/servatrice/src/settingscache.cpp index 10984dd6..b2b74d74 100644 --- a/servatrice/src/settingscache.cpp +++ b/servatrice/src/settingscache.cpp @@ -7,6 +7,12 @@ #include #endif +SettingsCache::SettingsCache(const QString & fileName, QSettings::Format format, QObject * parent) +:QSettings(fileName, format, parent) +{ + +} + QString SettingsCache::guessConfigurationPath(QString & specificPath) { const QString fileName="servatrice.ini"; diff --git a/servatrice/src/settingscache.h b/servatrice/src/settingscache.h index 945ab71f..7284d273 100644 --- a/servatrice/src/settingscache.h +++ b/servatrice/src/settingscache.h @@ -9,7 +9,7 @@ class SettingsCache : public QSettings { private: QSettings *settings; public: - SettingsCache(const QString & fileName="servatrice.ini", QSettings::Format format=QSettings::IniFormat, QObject * parent = 0) { }; + SettingsCache(const QString & fileName="servatrice.ini", QSettings::Format format=QSettings::IniFormat, QObject * parent = 0); static QString guessConfigurationPath(QString & specificPath); }; From 0d9eec4b6466eff095fc1d303ea632b6f654e871 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Sat, 4 Oct 2014 17:50:01 +0200 Subject: [PATCH 2/6] Servatrice: added authentication type "password" --- servatrice/src/servatrice.cpp | 4 +++- servatrice/src/servatrice.h | 2 +- servatrice/src/servatrice_database_interface.cpp | 8 ++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/servatrice/src/servatrice.cpp b/servatrice/src/servatrice.cpp index c4590f5b..c7abc432 100644 --- a/servatrice/src/servatrice.cpp +++ b/servatrice/src/servatrice.cpp @@ -141,9 +141,11 @@ bool Servatrice::initServer() const QString authenticationMethodStr = settingsCache->value("authentication/method").toString(); if (authenticationMethodStr == "sql") { authenticationMethod = AuthenticationSql; + } else if(authenticationMethodStr == "password") { + authenticationMethod = AuthenticationPassword; } else { if (regServerOnly) { - qDebug() << "Registration only server enabled but no DB Connection : Error."; + qDebug() << "Registration only server enabled but no authentication method defined: Error."; return false; } authenticationMethod = AuthenticationNone; diff --git a/servatrice/src/servatrice.h b/servatrice/src/servatrice.h index 86c36a5c..86da6dc5 100644 --- a/servatrice/src/servatrice.h +++ b/servatrice/src/servatrice.h @@ -88,7 +88,7 @@ class Servatrice : public Server { Q_OBJECT public: - enum AuthenticationMethod { AuthenticationNone, AuthenticationSql }; + enum AuthenticationMethod { AuthenticationNone, AuthenticationSql, AuthenticationPassword }; private slots: void statusUpdate(); void shutdownTimeout(); diff --git a/servatrice/src/servatrice_database_interface.cpp b/servatrice/src/servatrice_database_interface.cpp index 58856f4f..fa9e8b6a 100644 --- a/servatrice/src/servatrice_database_interface.cpp +++ b/servatrice/src/servatrice_database_interface.cpp @@ -2,6 +2,7 @@ #include "servatrice_database_interface.h" #include "passwordhasher.h" #include "serversocketinterface.h" +#include "settingscache.h" #include "decklist.h" #include "pb/game_replay.pb.h" #include @@ -92,6 +93,13 @@ AuthenticationResult Servatrice_DatabaseInterface::checkUserPassword(Server_Prot { switch (server->getAuthenticationMethod()) { case Servatrice::AuthenticationNone: return UnknownUser; + case Servatrice::AuthenticationPassword: { + QString configPassword = settingsCache->value("authentication/password").toString(); + if(configPassword == password) + return PasswordRight; + + return NotLoggedIn; + } case Servatrice::AuthenticationSql: { if (!checkSql()) return UnknownUser; From 29cf353913ec857af79c57e057ff33a713b11573 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Sat, 4 Oct 2014 17:51:27 +0200 Subject: [PATCH 3/6] Give servatrice example configuration some love added "password" settings commented all settings --- servatrice/servatrice.ini.example | 114 ++++++++++++++++++++++++++++-- 1 file changed, 110 insertions(+), 4 deletions(-) diff --git a/servatrice/servatrice.ini.example b/servatrice/servatrice.ini.example index 14926463..d426db09 100644 --- a/servatrice/servatrice.ini.example +++ b/servatrice/servatrice.ini.example @@ -1,50 +1,156 @@ +; Servatrice configuration file +; +; This is the main configuration file for Servatrice; while using a configuration is not mandatory, +; you may want to customize some aspects of your servatrice instance, lie its name, port or the way +; users can authenticate to the server. + + [server] -port=4747 -statusupdate=15000 -logfile=server.log + +; This is the name that servatrice exposes to the users; the default value is pretty boring name="My Cockatrice server" + +; Multiple servatrice servers can run on the same host using the same database; each server instance +; must have a different id; the default id is 1 id=1 + +; The TCP port number servatrice will listen on for clients; default is 4747 +port=4747 + +; Servatrice can scale up to serve big number of users using more than one parallel thread of execution; +; If your server is hosting a lot of players and they frequently report of being unable to login or +; long delays (lag), you may want to try increasing this value; default is 1. number_pools=1 + +; When database is eneabled, servatrice writes the server status in the "update" database table; this +; setting defines every how many milliseconds servatrice will update its status; default is 15000 (15 secs) +statusupdate=15000 + +; Do you want servatrice to write important events and errors to a logfile? Default is 1 (yes). writelog=1 + +; Choose a name for the log file, if enabled; the default file name is server.log +logfile=server.log + +; You may want to silence some useless, commonly recurring messages in the logfile. This setting can contain +; a comma-separed list of words; if any message that is about to be logged contains at least one of these words, +; it won't be logged. Default is empty; example: "kittens,ponies,faires" logfilters="" + [servernetwork] + +; Servatrice servers can connect themselves and build a network. This settins enable the ability of servatrice +; of waiting for other server's connections and connect to other servers. Other servers can be defined in the +; "servers" table of the database. Default is 0 (disabled) active=0 + +; The TCP port number servatrice will listen on for other servers; default is 14747 port=14747 + +; Server-to-server communication needs a valid certificate in PEM format. Enter its filename in this setting ssl_cert=ssl_cert.pem + +; Filename of the private key for the server-to-server certificate ssl_key=ssl_key.pem + [authentication] + +; Servatrice can authenticate users connecting. It currently supports 3 different authentication methods: +; * none: no authentication, accept every user; +; * password: require users to specify a common password to log in; +; * sql: authenticate users against the "users" table of the database; +; Please note that only the "sql" method permits to have registered users and store their data on the server. method=none + +; if the chosen authentication methos is password, here you can define the password your users will use to log in +password=123456 + +; Accept only registered users? default is 0 (accept unregistered users) +; FIXME: unused / not working regonly=0 + [database] + +; Database type. Valid values are: +; * none: no database; +; * mysql: mysql or compatible database; type=none + +; Prefix used in he database for table names; default is cockatrice prefix=cockatrice + +; Database connection parameter: server hostname or IP hostname=localhost + +; Database connection parameter: database name database=servatrice + +; Database connection parameter: database user user=servatrice + +; Database connection parameter: database user's password password=foobar [rooms] + +; A servtrice server can expose to the users different "rooms" to chat and create games. Rooms can be defined +; with two different methods: +; config: rooms are defined in this configuration (see the following example) +; sql: rooms are defined in the "rooms" table of the database method=config + +; Example configuration for a server with rooms configured in the configuration file. Number of rooms defined roomlist\size=1 + +; Room name for the room number 1 roomlist\1\name="General room" + +; Room description for the room number 1 roomlist\1\description="Play anything here." + +; Wether to make users autojoin this room when connected to the server roomlist\1\autojoin=true + +; Message displayed to each user when he joins room number 1 roomlist\1\joinmessage="This message is only here to show that rooms can have a join message." + +; Number of game types allowed (defined) in the room number 1 roomlist\1\game_types\size=3 + +; Name of the three game types for the room number 1 roomlist\1\game_types\1\name="GameType1" roomlist\1\game_types\2\name="GameType2" roomlist\1\game_types\3\name="GameType3" + [game] -max_game_inactivity_time=120 + +; Maximum time in seconds a player can stay inactive, with his client hot even responding to pings, before is +; considered disconnected; default is 15 max_player_inactivity_time=15 +; Maximum time in seconds all players in a game can stay inactive before the game is automatically closed; +; default is 120 +max_game_inactivity_time=120 + + [security] + +; Maximum number of users that can connect from the same IP address; useful to avoid bots, default is 4 max_users_per_address=4 + +; 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 + +; Maximum size in characters of all messages in an interval before new messages gets dropped; default is 1000 max_message_size_per_interval=1000 + +; Maximum number of messages in an interval before new messages gets dropped; default is 10 max_message_count_per_interval=10 + +; Maximum number of games a single user can create; default is 5 max_games_per_user=5 From 91dafdb3e827c6997d7743f9edb866ff74214383 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Sat, 4 Oct 2014 18:21:07 +0200 Subject: [PATCH 4/6] Move server network settings to the bottom and add a disclaimer --- servatrice/servatrice.ini.example | 38 +++++++++++++++++-------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/servatrice/servatrice.ini.example b/servatrice/servatrice.ini.example index d426db09..14e01d25 100644 --- a/servatrice/servatrice.ini.example +++ b/servatrice/servatrice.ini.example @@ -38,23 +38,6 @@ logfile=server.log logfilters="" -[servernetwork] - -; Servatrice servers can connect themselves and build a network. This settins enable the ability of servatrice -; of waiting for other server's connections and connect to other servers. Other servers can be defined in the -; "servers" table of the database. Default is 0 (disabled) -active=0 - -; The TCP port number servatrice will listen on for other servers; default is 14747 -port=14747 - -; Server-to-server communication needs a valid certificate in PEM format. Enter its filename in this setting -ssl_cert=ssl_cert.pem - -; Filename of the private key for the server-to-server certificate -ssl_key=ssl_key.pem - - [authentication] ; Servatrice can authenticate users connecting. It currently supports 3 different authentication methods: @@ -154,3 +137,24 @@ max_message_count_per_interval=10 ; Maximum number of games a single user can create; default is 5 max_games_per_user=5 + + +; EXPERIMENTAL - NOT WORKING YET +; The following settings are relative to the server network functionality, that is not yet complete. +; Avoid enabling it unless you are willing to test it and help its development. + +[servernetwork] + +; Servatrice servers can connect themselves and build a network. This settins enable the ability of servatrice +; of waiting for other server's connections and connect to other servers. Other servers can be defined in the +; "servers" table of the database. Default is 0 (disabled) +active=0 + +; The TCP port number servatrice will listen on for other servers; default is 14747 +port=14747 + +; Server-to-server communication needs a valid certificate in PEM format. Enter its filename in this setting +ssl_cert=ssl_cert.pem + +; Filename of the private key for the server-to-server certificate +ssl_key=ssl_key.pem From 01bd26d2289dcb6d7f2b8045e086a06563379e4b Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Mon, 6 Oct 2014 21:44:20 +0200 Subject: [PATCH 5/6] Misc typos fixing --- servatrice/servatrice.ini.example | 14 +++++++------- servatrice/src/servatrice_database_interface.cpp | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/servatrice/servatrice.ini.example b/servatrice/servatrice.ini.example index 14e01d25..05a5ba3a 100644 --- a/servatrice/servatrice.ini.example +++ b/servatrice/servatrice.ini.example @@ -1,7 +1,7 @@ ; Servatrice configuration file ; ; This is the main configuration file for Servatrice; while using a configuration is not mandatory, -; you may want to customize some aspects of your servatrice instance, lie its name, port or the way +; you may want to customize some aspects of your servatrice instance, like its name, port or the way ; users can authenticate to the server. @@ -22,18 +22,19 @@ port=4747 ; long delays (lag), you may want to try increasing this value; default is 1. number_pools=1 -; When database is eneabled, servatrice writes the server status in the "update" database table; this +; When database is enabled, servatrice writes the server status in the "update" database table; this ; setting defines every how many milliseconds servatrice will update its status; default is 15000 (15 secs) statusupdate=15000 ; Do you want servatrice to write important events and errors to a logfile? Default is 1 (yes). writelog=1 -; Choose a name for the log file, if enabled; the default file name is server.log +; Choose a name for the log file, if enabled; you can specify an absolute path or a path relative to +; the servatrice executable; the default file name is server.log (in the same path as servatrice) logfile=server.log -; You may want to silence some useless, commonly recurring messages in the logfile. This setting can contain -; a comma-separed list of words; if any message that is about to be logged contains at least one of these words, +; You may want to silence some commonly recurring messages in the logfile. This setting can contain a +; comma-separed list of words; if any message that is about to be logged contains at least one of these words, ; it won't be logged. Default is empty; example: "kittens,ponies,faires" logfilters="" @@ -47,11 +48,10 @@ logfilters="" ; Please note that only the "sql" method permits to have registered users and store their data on the server. method=none -; if the chosen authentication methos is password, here you can define the password your users will use to log in +; if the chosen authentication method is password, here you can define the password your users will use to log in password=123456 ; Accept only registered users? default is 0 (accept unregistered users) -; FIXME: unused / not working regonly=0 diff --git a/servatrice/src/servatrice_database_interface.cpp b/servatrice/src/servatrice_database_interface.cpp index fa9e8b6a..2a97664b 100644 --- a/servatrice/src/servatrice_database_interface.cpp +++ b/servatrice/src/servatrice_database_interface.cpp @@ -95,7 +95,7 @@ AuthenticationResult Servatrice_DatabaseInterface::checkUserPassword(Server_Prot case Servatrice::AuthenticationNone: return UnknownUser; case Servatrice::AuthenticationPassword: { QString configPassword = settingsCache->value("authentication/password").toString(); - if(configPassword == password) + if (configPassword == password) return PasswordRight; return NotLoggedIn; From 0d35488c21e0c6ddee509202663003222b0f6840 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Mon, 6 Oct 2014 21:49:38 +0200 Subject: [PATCH 6/6] Added schema for _rooms table --- servatrice/servatrice.sql | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/servatrice/servatrice.sql b/servatrice/servatrice.sql index 6e83f1f2..a38335d8 100644 --- a/servatrice/servatrice.sql +++ b/servatrice/servatrice.sql @@ -208,3 +208,12 @@ CREATE TABLE `cockatrice_replays_access` ( KEY `id_game` (`id_game`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; +CREATE TABLE IF NOT EXISTS `cockatrice_rooms` ( +`id` int(7) unsigned NOT NULL auto_increment, +`name` varchar(50) NOT NULL, +`descr` varchar(255) NOT NULL, +`autojoin` tinyint(1) default 0, +`join_message` varchar(255) NOT NULL, +PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; +