mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 09:04:53 -07:00
generalized user information
This commit is contained in:
parent
adaa1d5323
commit
f9446f9822
61 changed files with 3710 additions and 175 deletions
|
|
@ -48,7 +48,6 @@ void testRNG()
|
|||
numbers[max - minMax] = rng->makeNumbersVector(n * (max - min + 1), min, max);
|
||||
chisq[max - minMax] = rng->testRandom(numbers[max - minMax]);
|
||||
}
|
||||
qDebug() << numbers;
|
||||
for (int i = 0; i <= maxMax - min; ++i) {
|
||||
std::cerr << (min + i);
|
||||
for (int j = 0; j < numbers.size(); ++j) {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
***************************************************************************/
|
||||
#include <QtSql>
|
||||
#include <QSettings>
|
||||
#include <QDebug>
|
||||
#include "servatrice.h"
|
||||
#include "server_chatchannel.h"
|
||||
#include "serversocketinterface.h"
|
||||
|
|
@ -88,7 +89,7 @@ bool Servatrice::openDatabase()
|
|||
if (!query.next())
|
||||
return false;
|
||||
nextGameId = query.value(0).toInt() + 1;
|
||||
qDebug(QString("set nextGameId to %1").arg(nextGameId).toLatin1());
|
||||
qDebug() << "set nextGameId to " << nextGameId;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
@ -103,7 +104,7 @@ bool Servatrice::execSqlQuery(QSqlQuery &query)
|
|||
{
|
||||
if (query.exec())
|
||||
return true;
|
||||
qCritical(QString("Database error: %1").arg(query.lastError().text()).toLatin1());
|
||||
qCritical() << "Database error:" << query.lastError().text();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -139,4 +140,35 @@ AuthenticationResult Servatrice::checkUserPassword(const QString &user, const QS
|
|||
return UnknownUser;
|
||||
}
|
||||
|
||||
const QString Servatrice::versionString = "Servatrice 0.20100915";
|
||||
ServerInfo_User *Servatrice::getUserData(const QString &name)
|
||||
{
|
||||
const QString method = settings->value("authentication/method").toString();
|
||||
if (method == "sql") {
|
||||
checkSql();
|
||||
|
||||
QSqlQuery query;
|
||||
query.prepare("select admin, country from users where name = :name");
|
||||
query.bindValue(":name", name);
|
||||
if (!execSqlQuery(query))
|
||||
return new ServerInfo_User(name);
|
||||
|
||||
if (query.next()) {
|
||||
bool is_admin = query.value(0).toInt();
|
||||
QString country = query.value(1).toString();
|
||||
|
||||
int userLevel = ServerInfo_User::IsUser;
|
||||
if (is_admin)
|
||||
userLevel |= ServerInfo_User::IsAdmin;
|
||||
|
||||
return new ServerInfo_User(
|
||||
name,
|
||||
userLevel,
|
||||
country
|
||||
);
|
||||
} else
|
||||
return new ServerInfo_User(name);
|
||||
} else
|
||||
return new ServerInfo_User(name);
|
||||
}
|
||||
|
||||
const QString Servatrice::versionString = "Servatrice 0.20100918";
|
||||
|
|
|
|||
|
|
@ -40,11 +40,13 @@ public:
|
|||
bool openDatabase();
|
||||
void checkSql();
|
||||
bool execSqlQuery(QSqlQuery &query);
|
||||
AuthenticationResult checkUserPassword(const QString &user, const QString &password);
|
||||
QString getLoginMessage() const { return loginMessage; }
|
||||
bool getGameShouldPing() const { return true; }
|
||||
int getMaxGameInactivityTime() const { return maxGameInactivityTime; }
|
||||
int getMaxPlayerInactivityTime() const { return maxPlayerInactivityTime; }
|
||||
protected:
|
||||
AuthenticationResult checkUserPassword(const QString &user, const QString &password);
|
||||
ServerInfo_User *getUserData(const QString &name);
|
||||
private:
|
||||
QTimer *pingClock;
|
||||
QTcpServer *tcpServer;
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ int ServerSocketInterface::getDeckPathId(int basePathId, QStringList path)
|
|||
query.prepare("select id from decklist_folders where id_parent = :id_parent and name = :name and user = :user");
|
||||
query.bindValue(":id_parent", basePathId);
|
||||
query.bindValue(":name", path.takeFirst());
|
||||
query.bindValue(":user", playerName);
|
||||
query.bindValue(":user", userInfo->getName());
|
||||
if (!servatrice->execSqlQuery(query))
|
||||
return -1;
|
||||
if (!query.next())
|
||||
|
|
@ -131,7 +131,7 @@ bool ServerSocketInterface::deckListHelper(DeckList_Directory *folder)
|
|||
QSqlQuery query;
|
||||
query.prepare("select id, name from decklist_folders where id_parent = :id_parent and user = :user");
|
||||
query.bindValue(":id_parent", folder->getId());
|
||||
query.bindValue(":user", playerName);
|
||||
query.bindValue(":user", userInfo->getName());
|
||||
if (!servatrice->execSqlQuery(query))
|
||||
return false;
|
||||
|
||||
|
|
@ -144,7 +144,7 @@ bool ServerSocketInterface::deckListHelper(DeckList_Directory *folder)
|
|||
|
||||
query.prepare("select id, name, upload_time from decklist_files where id_folder = :id_folder and user = :user");
|
||||
query.bindValue(":id_folder", folder->getId());
|
||||
query.bindValue(":user", playerName);
|
||||
query.bindValue(":user", userInfo->getName());
|
||||
if (!servatrice->execSqlQuery(query))
|
||||
return false;
|
||||
|
||||
|
|
@ -190,7 +190,7 @@ ResponseCode ServerSocketInterface::cmdDeckNewDir(Command_DeckNewDir *cmd, Comma
|
|||
QSqlQuery query;
|
||||
query.prepare("insert into decklist_folders (id_parent, user, name) values(:id_parent, :user, :name)");
|
||||
query.bindValue(":id_parent", folderId);
|
||||
query.bindValue(":user", playerName);
|
||||
query.bindValue(":user", userInfo->getName());
|
||||
query.bindValue(":name", cmd->getDirName());
|
||||
if (!servatrice->execSqlQuery(query))
|
||||
return RespContextError;
|
||||
|
|
@ -243,7 +243,7 @@ ResponseCode ServerSocketInterface::cmdDeckDel(Command_DeckDel *cmd, CommandCont
|
|||
|
||||
query.prepare("select id from decklist_files where id = :id and user = :user");
|
||||
query.bindValue(":id", cmd->getDeckId());
|
||||
query.bindValue(":user", playerName);
|
||||
query.bindValue(":user", userInfo->getName());
|
||||
servatrice->execSqlQuery(query);
|
||||
if (!query.next())
|
||||
return RespNameNotFound;
|
||||
|
|
@ -281,7 +281,7 @@ ResponseCode ServerSocketInterface::cmdDeckUpload(Command_DeckUpload *cmd, Comma
|
|||
QSqlQuery query;
|
||||
query.prepare("insert into decklist_files (id_folder, user, name, upload_time, content) values(:id_folder, :user, :name, NOW(), :content)");
|
||||
query.bindValue(":id_folder", folderId);
|
||||
query.bindValue(":user", playerName);
|
||||
query.bindValue(":user", userInfo->getName());
|
||||
query.bindValue(":name", deckName);
|
||||
query.bindValue(":content", deckContents);
|
||||
servatrice->execSqlQuery(query);
|
||||
|
|
@ -298,7 +298,7 @@ DeckList *ServerSocketInterface::getDeckFromDatabase(int deckId)
|
|||
|
||||
query.prepare("select content from decklist_files where id = :id and user = :user");
|
||||
query.bindValue(":id", deckId);
|
||||
query.bindValue(":user", playerName);
|
||||
query.bindValue(":user", userInfo->getName());
|
||||
servatrice->execSqlQuery(query);
|
||||
if (!query.next())
|
||||
throw RespNameNotFound;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue