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;