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
This commit is contained in:
woogerboy21 2016-10-26 02:07:42 -04:00 committed by Zach H
parent 1197c10a70
commit f17a0da434
6 changed files with 25 additions and 11 deletions

View file

@ -24,4 +24,5 @@ message ServerInfo_User {
optional uint64 accountage_secs = 11;
optional string email = 12;
optional string clientid = 13;
optional string privlevel = 14;
}

View file

@ -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());

View file

@ -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;

View file

@ -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`),

View file

@ -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;

View file

@ -9,7 +9,7 @@
#include "server.h"
#include "server_database_interface.h"
#define DATABASE_SCHEMA_VERSION 17
#define DATABASE_SCHEMA_VERSION 18
class Servatrice;