mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-14 22:42:14 -07:00
Prevent adding duplicate replays
This commit is contained in:
parent
375b0981f0
commit
bdb0e36571
1 changed files with 15 additions and 3 deletions
|
|
@ -817,10 +817,10 @@ Response::ResponseCode AbstractServerSocketInterface::cmdReplaySubmitCode(const
|
|||
QString gameId = split[0];
|
||||
QString hash = split[1];
|
||||
|
||||
// Determine if the replay actually exists already
|
||||
// Determine if the replay actually exists
|
||||
auto *replayExistsQuery =
|
||||
sqlInterface->prepareQuery("select count(*) from {prefix}_replays_access where id_game = :idgame");
|
||||
replayExistsQuery->bindValue(":idgame", gameId);
|
||||
sqlInterface->prepareQuery("select count(*) from {prefix}_replays_access where id_game = :id_game");
|
||||
replayExistsQuery->bindValue(":id_game", gameId);
|
||||
if (!sqlInterface->execSqlQuery(replayExistsQuery)) {
|
||||
return Response::RespInternalError;
|
||||
}
|
||||
|
|
@ -833,6 +833,18 @@ Response::ResponseCode AbstractServerSocketInterface::cmdReplaySubmitCode(const
|
|||
return Response::RespNameNotFound;
|
||||
}
|
||||
|
||||
// Determine if user already has access to replay
|
||||
auto *alreadyAccessQuery = sqlInterface->prepareQuery(
|
||||
"select 1 from {prefix}_replays_access where id_game = :id_game and id_player = :id_player");
|
||||
alreadyAccessQuery->bindValue(":id_game", gameId);
|
||||
alreadyAccessQuery->bindValue(":id_player", userInfo->id());
|
||||
if (!sqlInterface->execSqlQuery(alreadyAccessQuery)) {
|
||||
return Response::RespInternalError;
|
||||
}
|
||||
if (alreadyAccessQuery->next()) {
|
||||
return Response::RespOk;
|
||||
}
|
||||
|
||||
// Check if hash is correct
|
||||
if (hash != createHashForReplay(gameId.toInt())) {
|
||||
return Response::RespNameNotFound;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue