mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
deprecate the gender property from the protocol entirely (#4496)
* deprecate the gender property from the protocol entirely * use obsolete instead of deprecated * add the database migration * update internal database version as well
This commit is contained in:
parent
86881bbbc3
commit
07e6aadbbe
24 changed files with 25 additions and 170 deletions
5
servatrice/migrations/servatrice_0027_to_0028.sql
Normal file
5
servatrice/migrations/servatrice_0027_to_0028.sql
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
-- Servatrice db migration from version 27 to version 28
|
||||
|
||||
ALTER TABLE cockatrice_users DROP COLUMN gender;
|
||||
|
||||
UPDATE cockatrice_schema_version SET version=28 WHERE version=27;
|
||||
|
|
@ -20,7 +20,7 @@ CREATE TABLE IF NOT EXISTS `cockatrice_schema_version` (
|
|||
PRIMARY KEY (`version`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
INSERT INTO cockatrice_schema_version VALUES(27);
|
||||
INSERT INTO cockatrice_schema_version VALUES(28);
|
||||
|
||||
-- users and user data tables
|
||||
CREATE TABLE IF NOT EXISTS `cockatrice_users` (
|
||||
|
|
@ -28,7 +28,6 @@ CREATE TABLE IF NOT EXISTS `cockatrice_users` (
|
|||
`admin` tinyint(1) NOT NULL,
|
||||
`name` varchar(35) NOT NULL,
|
||||
`realname` varchar(255) NOT NULL,
|
||||
`gender` char(1) NOT NULL,
|
||||
`password_sha512` char(120) NOT NULL,
|
||||
`email` varchar(255) NOT NULL,
|
||||
`country` char(2) NOT NULL,
|
||||
|
|
|
|||
|
|
@ -197,7 +197,6 @@ bool Servatrice_DatabaseInterface::usernameIsValid(const QString &user, QString
|
|||
|
||||
bool Servatrice_DatabaseInterface::registerUser(const QString &userName,
|
||||
const QString &realName,
|
||||
ServerInfo_User_Gender const &gender,
|
||||
const QString &password,
|
||||
const QString &emailAddress,
|
||||
const QString &country,
|
||||
|
|
@ -211,14 +210,13 @@ bool Servatrice_DatabaseInterface::registerUser(const QString &userName,
|
|||
|
||||
QSqlQuery *query =
|
||||
prepareQuery("insert into {prefix}_users "
|
||||
"(name, realname, gender, password_sha512, email, country, registrationDate, active, token, "
|
||||
"(name, realname, password_sha512, email, country, registrationDate, active, token, "
|
||||
"admin, avatar_bmp, clientid, privlevel, privlevelStartDate, privlevelEndDate) "
|
||||
"values "
|
||||
"(:userName, :realName, :gender, :password_sha512, :email, :country, UTC_TIMESTAMP(), :active, "
|
||||
"(:userName, :realName, :password_sha512, :email, :country, UTC_TIMESTAMP(), :active, "
|
||||
":token, 0, '', '', 'NONE', UTC_TIMESTAMP(), UTC_TIMESTAMP())");
|
||||
query->bindValue(":userName", userName);
|
||||
query->bindValue(":realName", realName);
|
||||
query->bindValue(":gender", getGenderChar(gender));
|
||||
query->bindValue(":password_sha512", passwordSha512);
|
||||
query->bindValue(":email", emailAddress);
|
||||
query->bindValue(":country", country);
|
||||
|
|
@ -268,20 +266,6 @@ bool Servatrice_DatabaseInterface::activateUser(const QString &userName, const Q
|
|||
return false;
|
||||
}
|
||||
|
||||
QChar Servatrice_DatabaseInterface::getGenderChar(ServerInfo_User_Gender const &gender)
|
||||
{
|
||||
switch (gender) {
|
||||
case ServerInfo_User_Gender_GenderUnknown:
|
||||
return QChar('u');
|
||||
case ServerInfo_User_Gender_Male:
|
||||
return QChar('m');
|
||||
case ServerInfo_User_Gender_Female:
|
||||
return QChar('f');
|
||||
default:
|
||||
return QChar('u');
|
||||
}
|
||||
}
|
||||
|
||||
AuthenticationResult Servatrice_DatabaseInterface::checkUserPassword(Server_ProtocolHandler *handler,
|
||||
const QString &user,
|
||||
const QString &password,
|
||||
|
|
@ -602,31 +586,25 @@ ServerInfo_User Servatrice_DatabaseInterface::evalUserQueryResult(const QSqlQuer
|
|||
result.set_privlevel(privlevel.toStdString());
|
||||
|
||||
if (complete) {
|
||||
const QString genderStr = query->value(5).toString();
|
||||
if (genderStr == "m")
|
||||
result.set_gender(ServerInfo_User::Male);
|
||||
else if (genderStr == "f")
|
||||
result.set_gender(ServerInfo_User::Female);
|
||||
|
||||
const QString realName = query->value(6).toString();
|
||||
const QString realName = query->value(5).toString();
|
||||
if (!realName.isEmpty())
|
||||
result.set_real_name(realName.toStdString());
|
||||
|
||||
const QByteArray avatarBmp = query->value(7).toByteArray();
|
||||
const QByteArray avatarBmp = query->value(6).toByteArray();
|
||||
if (avatarBmp.size())
|
||||
result.set_avatar_bmp(avatarBmp.data(), avatarBmp.size());
|
||||
|
||||
const QDateTime regDate = query->value(8).toDateTime();
|
||||
const QDateTime regDate = query->value(7).toDateTime();
|
||||
if (!regDate.toString(Qt::ISODate).isEmpty()) {
|
||||
qint64 accountAgeInSeconds = regDate.secsTo(QDateTime::currentDateTime());
|
||||
result.set_accountage_secs(accountAgeInSeconds);
|
||||
}
|
||||
|
||||
const QString email = query->value(9).toString();
|
||||
const QString email = query->value(8).toString();
|
||||
if (!email.isEmpty())
|
||||
result.set_email(email.toStdString());
|
||||
|
||||
const QString clientid = query->value(10).toString();
|
||||
const QString clientid = query->value(9).toString();
|
||||
if (!clientid.isEmpty())
|
||||
result.set_clientid(clientid.toStdString());
|
||||
}
|
||||
|
|
@ -644,7 +622,7 @@ ServerInfo_User Servatrice_DatabaseInterface::getUserData(const QString &name, b
|
|||
return result;
|
||||
|
||||
QSqlQuery *query =
|
||||
prepareQuery("select id, name, admin, country, privlevel, gender, realname, avatar_bmp, registrationDate, "
|
||||
prepareQuery("select id, name, admin, country, privlevel, realname, avatar_bmp, registrationDate, "
|
||||
"email, clientid from {prefix}_users where name = :name and active = 1");
|
||||
query->bindValue(":name", name);
|
||||
if (!execSqlQuery(query))
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
#include <QObject>
|
||||
#include <QSqlDatabase>
|
||||
|
||||
#define DATABASE_SCHEMA_VERSION 27
|
||||
#define DATABASE_SCHEMA_VERSION 28
|
||||
|
||||
class Servatrice;
|
||||
|
||||
|
|
@ -97,7 +97,6 @@ public:
|
|||
int checkNumberOfUserAccounts(const QString &email);
|
||||
bool registerUser(const QString &userName,
|
||||
const QString &realName,
|
||||
ServerInfo_User_Gender const &gender,
|
||||
const QString &password,
|
||||
const QString &emailAddress,
|
||||
const QString &country,
|
||||
|
|
@ -114,7 +113,6 @@ public:
|
|||
const QString &targetName);
|
||||
bool
|
||||
changeUserPassword(const QString &user, const QString &oldPassword, const QString &newPassword, const bool &force);
|
||||
QChar getGenderChar(ServerInfo_User_Gender const &gender);
|
||||
QList<ServerInfo_Ban> getUserBanHistory(const QString userName);
|
||||
bool
|
||||
addWarning(const QString userName, const QString adminName, const QString warningReason, const QString clientID);
|
||||
|
|
|
|||
|
|
@ -1164,7 +1164,6 @@ Response::ResponseCode AbstractServerSocketInterface::cmdRegisterAccount(const C
|
|||
}
|
||||
|
||||
QString realName = QString::fromStdString(cmd.real_name());
|
||||
ServerInfo_User_Gender gender = cmd.gender();
|
||||
QString country = QString::fromStdString(cmd.country());
|
||||
QString password = QString::fromStdString(cmd.password());
|
||||
|
||||
|
|
@ -1178,8 +1177,8 @@ Response::ResponseCode AbstractServerSocketInterface::cmdRegisterAccount(const C
|
|||
}
|
||||
|
||||
bool requireEmailActivation = settingsCache->value("registration/requireemailactivation", true).toBool();
|
||||
bool regSucceeded = sqlInterface->registerUser(userName, realName, gender, password, emailAddress, country,
|
||||
!requireEmailActivation);
|
||||
bool regSucceeded =
|
||||
sqlInterface->registerUser(userName, realName, password, emailAddress, country, !requireEmailActivation);
|
||||
|
||||
if (regSucceeded) {
|
||||
qDebug() << "Accepted register command for user: " << userName;
|
||||
|
|
@ -1260,16 +1259,14 @@ Response::ResponseCode AbstractServerSocketInterface::cmdAccountEdit(const Comma
|
|||
|
||||
QString realName = QString::fromStdString(cmd.real_name());
|
||||
QString emailAddress = QString::fromStdString(cmd.email());
|
||||
ServerInfo_User_Gender gender = cmd.gender();
|
||||
QString country = QString::fromStdString(cmd.country());
|
||||
|
||||
QString userName = QString::fromStdString(userInfo->name());
|
||||
|
||||
QSqlQuery *query = sqlInterface->prepareQuery("update {prefix}_users set realname=:realName, email=:email, "
|
||||
"gender=:gender, country=:country where name=:userName");
|
||||
"country=:country where name=:userName");
|
||||
query->bindValue(":realName", realName);
|
||||
query->bindValue(":email", emailAddress);
|
||||
query->bindValue(":gender", sqlInterface->getGenderChar(gender));
|
||||
query->bindValue(":country", country);
|
||||
query->bindValue(":userName", userName);
|
||||
if (!sqlInterface->execSqlQuery(query))
|
||||
|
|
@ -1277,7 +1274,6 @@ Response::ResponseCode AbstractServerSocketInterface::cmdAccountEdit(const Comma
|
|||
|
||||
userInfo->set_real_name(cmd.real_name());
|
||||
userInfo->set_email(cmd.email());
|
||||
userInfo->set_gender(cmd.gender());
|
||||
userInfo->set_country(cmd.country());
|
||||
|
||||
return Response::RespOk;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue