mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
minor cleanups
This commit is contained in:
parent
0ef00dd437
commit
7e13352a95
29 changed files with 102 additions and 134 deletions
|
|
@ -28,6 +28,10 @@ Server::Server(QObject *parent)
|
|||
: QTcpServer(parent), nextGameId(0)
|
||||
{
|
||||
settings = new QSettings("servatrice.ini", QSettings::IniFormat, this);
|
||||
|
||||
QString dbType = settings->value("database/type").toString();
|
||||
if (dbType == "mysql")
|
||||
openDatabase();
|
||||
}
|
||||
|
||||
Server::~Server()
|
||||
|
|
@ -81,21 +85,27 @@ void Server::incomingConnection(int socketId)
|
|||
|
||||
AuthenticationResult Server::checkUserPassword(const QString &user, const QString &password)
|
||||
{
|
||||
if (!QSqlDatabase::database().exec("select 1").isActive())
|
||||
openDatabase();
|
||||
|
||||
QSqlQuery query;
|
||||
query.prepare("select password from players where name = :name");
|
||||
query.bindValue(":name", user);
|
||||
if (!query.exec()) {
|
||||
qCritical(QString("Database error: %1").arg(query.lastError().text()).toLatin1());
|
||||
return PasswordWrong;
|
||||
}
|
||||
if (query.next()) {
|
||||
if (query.value(0).toString() == password)
|
||||
return PasswordRight;
|
||||
else
|
||||
const QString method = settings->value("authentication/method").toString();
|
||||
if (method == "none")
|
||||
return UnknownUser;
|
||||
else if (method == "sql") {
|
||||
if (!QSqlDatabase::database().exec("select 1").isActive())
|
||||
openDatabase();
|
||||
|
||||
QSqlQuery query;
|
||||
query.prepare("select password from players where name = :name");
|
||||
query.bindValue(":name", user);
|
||||
if (!query.exec()) {
|
||||
qCritical(QString("Database error: %1").arg(query.lastError().text()).toLatin1());
|
||||
return PasswordWrong;
|
||||
}
|
||||
if (query.next()) {
|
||||
if (query.value(0).toString() == password)
|
||||
return PasswordRight;
|
||||
else
|
||||
return PasswordWrong;
|
||||
} else
|
||||
return UnknownUser;
|
||||
} else
|
||||
return UnknownUser;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue