Initial release of client ID generation.

This commit is contained in:
woogerboy21 2015-08-05 10:15:49 -04:00
parent 44d757f691
commit 52db13a1ca
14 changed files with 246 additions and 186 deletions

View file

@ -20,7 +20,7 @@ CREATE TABLE IF NOT EXISTS `cockatrice_schema_version` (
PRIMARY KEY (`version`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO cockatrice_schema_version VALUES(1);
INSERT INTO cockatrice_schema_version VALUES(3);
CREATE TABLE IF NOT EXISTS `cockatrice_decklist_files` (
`id` int(7) unsigned zerofill NOT NULL auto_increment,
@ -83,6 +83,7 @@ CREATE TABLE IF NOT EXISTS `cockatrice_users` (
`registrationDate` datetime NOT NULL,
`active` tinyint(1) NOT NULL,
`token` binary(16) NOT NULL,
`clientid` varchar(15) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`),
KEY `token` (`token`),

View file

@ -811,20 +811,33 @@ bool Servatrice_DatabaseInterface::changeUserPassword(const QString &user, const
int Servatrice_DatabaseInterface::getActiveUserCount()
{
int userCount = 0;
int userCount = 0;
if (!checkSql())
return userCount;
if (!checkSql())
return userCount;
QSqlQuery *query = prepareQuery("select count(*) from {prefix}_sessions where id_server = :serverid AND end_time is NULL");
query->bindValue(":serverid", server->getServerId());
if (!execSqlQuery(query)){
return userCount;
}
QSqlQuery *query = prepareQuery("select count(*) from {prefix}_sessions where id_server = :serverid AND end_time is NULL");
query->bindValue(":serverid", server->getServerId());
if (!execSqlQuery(query)){
return userCount;
}
if (query->next()){
userCount = query->value(0).toInt();
}
if (query->next()){
userCount = query->value(0).toInt();
}
return userCount;
}
return userCount;
}
void Servatrice_DatabaseInterface::updateUsersClientID(const QString &userName, const QString &userClientID)
{
if (!checkSql())
return;
QSqlQuery *query = prepareQuery("update {prefix}_users set clientid = :clientid where name = :username");
query->bindValue(":clientid", userClientID);
query->bindValue(":username", userName);
execSqlQuery(query);
}

View file

@ -9,7 +9,7 @@
#include "server.h"
#include "server_database_interface.h"
#define DATABASE_SCHEMA_VERSION 2
#define DATABASE_SCHEMA_VERSION 3
class Servatrice;
@ -72,7 +72,7 @@ public:
bool registerUser(const QString &userName, const QString &realName, ServerInfo_User_Gender const &gender,
const QString &password, const QString &emailAddress, const QString &country, QString &token, bool active = false);
bool activateUser(const QString &userName, const QString &token);
void updateUsersClientID(const QString &userName, const QString &userClientID);
void logMessage(const int senderId, const QString &senderName, const QString &senderIp, const QString &logMessage,
LogMessage_TargetType targetType, const int targetId, const QString &targetName);
bool changeUserPassword(const QString &user, const QString &oldPassword, const QString &newPassword);