mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-24 23:53:54 -07:00
Prevent server crash if DB is down and game is attempted to be created (#5600)
This commit is contained in:
parent
80bd783d54
commit
cb060f43b5
2 changed files with 17 additions and 13 deletions
|
|
@ -790,9 +790,6 @@ Server_ProtocolHandler::cmdCreateGame(const Command_CreateGame &cmd, Server_Room
|
||||||
{
|
{
|
||||||
if (authState == NotLoggedIn)
|
if (authState == NotLoggedIn)
|
||||||
return Response::RespLoginNeeded;
|
return Response::RespLoginNeeded;
|
||||||
const int gameId = databaseInterface->getNextGameId();
|
|
||||||
if (gameId == -1)
|
|
||||||
return Response::RespInternalError;
|
|
||||||
if (cmd.password().length() > MAX_NAME_LENGTH)
|
if (cmd.password().length() > MAX_NAME_LENGTH)
|
||||||
return Response::RespContextError;
|
return Response::RespContextError;
|
||||||
|
|
||||||
|
|
@ -821,6 +818,11 @@ Server_ProtocolHandler::cmdCreateGame(const Command_CreateGame &cmd, Server_Room
|
||||||
QString description = nameFromStdString(cmd.description());
|
QString description = nameFromStdString(cmd.description());
|
||||||
int startingLifeTotal = cmd.has_starting_life_total() ? cmd.starting_life_total() : 20;
|
int startingLifeTotal = cmd.has_starting_life_total() ? cmd.starting_life_total() : 20;
|
||||||
|
|
||||||
|
const int gameId = databaseInterface->getNextGameId();
|
||||||
|
if (gameId == -1) {
|
||||||
|
return Response::RespInternalError;
|
||||||
|
}
|
||||||
|
|
||||||
// When server doesn't permit registered users to exist, do not honor only-reg setting
|
// When server doesn't permit registered users to exist, do not honor only-reg setting
|
||||||
bool onlyRegisteredUsers = cmd.only_registered() && (server->permitUnregisteredUsers());
|
bool onlyRegisteredUsers = cmd.only_registered() && (server->permitUnregisteredUsers());
|
||||||
Server_Game *game = new Server_Game(
|
Server_Game *game = new Server_Game(
|
||||||
|
|
|
||||||
|
|
@ -709,7 +709,9 @@ bool Servatrice_DatabaseInterface::userSessionExists(const QString &userName)
|
||||||
"select 1 from {prefix}_sessions where user_name = :user_name and id_server = :id_server and end_time is null");
|
"select 1 from {prefix}_sessions where user_name = :user_name and id_server = :id_server and end_time is null");
|
||||||
query->bindValue(":id_server", server->getServerID());
|
query->bindValue(":id_server", server->getServerID());
|
||||||
query->bindValue(":user_name", userName);
|
query->bindValue(":user_name", userName);
|
||||||
execSqlQuery(query);
|
if (!execSqlQuery(query)) {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
return query->next();
|
return query->next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -745,15 +747,9 @@ void Servatrice_DatabaseInterface::endSession(qint64 sessionId)
|
||||||
if (!checkSql())
|
if (!checkSql())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QSqlQuery *query = prepareQuery("lock tables {prefix}_sessions write");
|
auto *query = prepareQuery("update {prefix}_sessions set end_time=NOW() where id = :id_session");
|
||||||
execSqlQuery(query);
|
|
||||||
|
|
||||||
query = prepareQuery("update {prefix}_sessions set end_time=NOW() where id = :id_session");
|
|
||||||
query->bindValue(":id_session", sessionId);
|
query->bindValue(":id_session", sessionId);
|
||||||
execSqlQuery(query);
|
execSqlQuery(query);
|
||||||
|
|
||||||
query = prepareQuery("unlock tables");
|
|
||||||
execSqlQuery(query);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<QString, ServerInfo_User> Servatrice_DatabaseInterface::getBuddyList(const QString &name)
|
QMap<QString, ServerInfo_User> Servatrice_DatabaseInterface::getBuddyList(const QString &name)
|
||||||
|
|
@ -811,7 +807,10 @@ int Servatrice_DatabaseInterface::getNextGameId()
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
QSqlQuery *query = prepareQuery("insert into {prefix}_games (time_started) values (now())");
|
QSqlQuery *query = prepareQuery("insert into {prefix}_games (time_started) values (now())");
|
||||||
execSqlQuery(query);
|
|
||||||
|
if (!execSqlQuery(query)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return query->lastInsertId().toInt();
|
return query->lastInsertId().toInt();
|
||||||
}
|
}
|
||||||
|
|
@ -822,7 +821,10 @@ int Servatrice_DatabaseInterface::getNextReplayId()
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
QSqlQuery *query = prepareQuery("insert into {prefix}_replays (id_game) values (NULL)");
|
QSqlQuery *query = prepareQuery("insert into {prefix}_replays (id_game) values (NULL)");
|
||||||
execSqlQuery(query);
|
|
||||||
|
if (!execSqlQuery(query)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return query->lastInsertId().toInt();
|
return query->lastInsertId().toInt();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue