From f17a0da43438c57cf64c66f144b35c6a427d2e03 Mon Sep 17 00:00:00 2001 From: woogerboy21 Date: Wed, 26 Oct 2016 02:07:42 -0400 Subject: [PATCH] Added user privilege level (#2228) * Update log path example when running under windows Added example of log path syntax when running servatrice under windows. * Missed example bra cket * Added user privilege level Added a enum column in the users table named "privilevel" with the current values of "none", "vip", and "donator". Also allowed anyone with a higher privilege level than "none" to log in even if the server is set to limit the user total and the user limit is reached. This change add's the new user information into the users container that gets populated and passed between client and server. * Added user privilege level Added a enum column in the users table named "privilevel" with the current values of "none", "vip", and "donator". Also allowed anyone with a higher privilege level than "none" to log in even if the server is set to limit the user total and the user limit is reached. This change add's the new user information into the users container that gets populated and passed between client and server. * don't use corrected name when downloading card (#2164) * Fix dynamic user limit settings PR #2220 removed the ability to be able to change the max user limit count while the server is running requiring a restart to make the settings change. This PR reverts the behavior back to how it operated prior to the PR. * Call class functions for consistency Updated code to call functions for consistency. * don't use corrected name when downloading card (#2164) * Added user privilege level Added a enum column in the users table named "privilevel" with the current values of "none", "vip", and "donator". Also allowed anyone with a higher privilege level than "none" to log in even if the server is set to limit the user total and the user limit is reached. This change add's the new user information into the users container that gets populated and passed between client and server. * Corrected Typo Corrected typo in DB Migration Script * Git fuckup? * Added word column Added the word column to migration script for backwards compatibility --- common/pb/serverinfo_user.proto | 1 + common/server_protocolhandler.cpp | 19 +++++++++++-------- .../migrations/servatrice_0017_to_0018.sql | 5 +++++ servatrice/servatrice.sql | 3 ++- .../src/servatrice_database_interface.cpp | 6 +++++- .../src/servatrice_database_interface.h | 2 +- 6 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 servatrice/migrations/servatrice_0017_to_0018.sql diff --git a/common/pb/serverinfo_user.proto b/common/pb/serverinfo_user.proto index 71e5849e..cb1ea273 100644 --- a/common/pb/serverinfo_user.proto +++ b/common/pb/serverinfo_user.proto @@ -24,4 +24,5 @@ message ServerInfo_User { optional uint64 accountage_secs = 11; optional string email = 12; optional string clientid = 13; + optional string privlevel = 14; } diff --git a/common/server_protocolhandler.cpp b/common/server_protocolhandler.cpp index 29bf34fd..1efd1500 100644 --- a/common/server_protocolhandler.cpp +++ b/common/server_protocolhandler.cpp @@ -383,14 +383,7 @@ Response::ResponseCode Server_ProtocolHandler::cmdPing(const Command_Ping & /*cm Response::ResponseCode Server_ProtocolHandler::cmdLogin(const Command_Login &cmd, ResponseContainer &rc) { - // limit the number of users that can connect to the server based on configuration settings - if (server->getMaxUserLimitEnabled()) { - if (server->getUsersCount() >= server->getMaxUserLimit()) { - qDebug() << "Max Users Total Limit Reached, please increase the max_users_total setting."; - return Response::RespServerFull; - } - } - + QString userName = QString::fromStdString(cmd.user_name()).simplified(); QString clientId = QString::fromStdString(cmd.clientid()).simplified(); QString clientVersion = QString::fromStdString(cmd.clientver()).simplified(); @@ -447,6 +440,16 @@ Response::ResponseCode Server_ProtocolHandler::cmdLogin(const Command_Login &cmd default: authState = res; } + // limit the number of non-privileged users that can connect to the server based on configuration settings + if (QString::fromStdString(userInfo->privlevel()).toLower() == "none") { + if (server->getMaxUserLimitEnabled()) { + if (server->getUsersCount() > server->getMaxUserLimit()) { + qDebug() << "Max Users Total Limit Reached, please increase the max_users_total setting."; + return Response::RespServerFull; + } + } + } + userName = QString::fromStdString(userInfo->name()); Event_ServerMessage event; event.set_message(server->getLoginMessage().toStdString()); diff --git a/servatrice/migrations/servatrice_0017_to_0018.sql b/servatrice/migrations/servatrice_0017_to_0018.sql new file mode 100644 index 00000000..5b61f9bb --- /dev/null +++ b/servatrice/migrations/servatrice_0017_to_0018.sql @@ -0,0 +1,5 @@ +-- Servatrice db migration from version 17 to version 18 + +alter table cockatrice_users add column privlevel enum("NONE","VIP","DONATOR") NOT NULL; + +UPDATE cockatrice_schema_version SET version=18 WHERE version=17; diff --git a/servatrice/servatrice.sql b/servatrice/servatrice.sql index f354267d..b09e8de7 100644 --- a/servatrice/servatrice.sql +++ b/servatrice/servatrice.sql @@ -20,7 +20,7 @@ CREATE TABLE IF NOT EXISTS `cockatrice_schema_version` ( PRIMARY KEY (`version`) ) ENGINE=INNODB DEFAULT CHARSET=utf8; -INSERT INTO cockatrice_schema_version VALUES(17); +INSERT INTO cockatrice_schema_version VALUES(18); -- users and user data tables CREATE TABLE IF NOT EXISTS `cockatrice_users` ( @@ -37,6 +37,7 @@ CREATE TABLE IF NOT EXISTS `cockatrice_users` ( `active` tinyint(1) NOT NULL, `token` binary(16), `clientid` varchar(15) NOT NULL, + `privlevel` enum("NONE","VIP","DONATOR") NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`), KEY `token` (`token`), diff --git a/servatrice/src/servatrice_database_interface.cpp b/servatrice/src/servatrice_database_interface.cpp index d29fddad..da35796a 100644 --- a/servatrice/src/servatrice_database_interface.cpp +++ b/servatrice/src/servatrice_database_interface.cpp @@ -533,6 +533,10 @@ ServerInfo_User Servatrice_DatabaseInterface::evalUserQueryResult(const QSqlQuer const QString clientid = query->value(9).toString(); if (!clientid.isEmpty()) result.set_clientid(clientid.toStdString()); + + const QString privlevel = query->value(10).toString(); + if (!privlevel.isEmpty()) + result.set_privlevel(privlevel.toStdString()); } return result; } @@ -547,7 +551,7 @@ ServerInfo_User Servatrice_DatabaseInterface::getUserData(const QString &name, b if (!checkSql()) return result; - QSqlQuery *query = prepareQuery("select id, name, admin, country, gender, realname, avatar_bmp, registrationDate, email, clientid from {prefix}_users where name = :name and active = 1"); + QSqlQuery *query = prepareQuery("select id, name, admin, country, gender, realname, avatar_bmp, registrationDate, email, clientid, privlevel from {prefix}_users where name = :name and active = 1"); query->bindValue(":name", name); if (!execSqlQuery(query)) return result; diff --git a/servatrice/src/servatrice_database_interface.h b/servatrice/src/servatrice_database_interface.h index 3998812a..9bb23e59 100644 --- a/servatrice/src/servatrice_database_interface.h +++ b/servatrice/src/servatrice_database_interface.h @@ -9,7 +9,7 @@ #include "server.h" #include "server_database_interface.h" -#define DATABASE_SCHEMA_VERSION 17 +#define DATABASE_SCHEMA_VERSION 18 class Servatrice;