From bdb0e36571cdba349f601b8b404b7f7845958c18 Mon Sep 17 00:00:00 2001 From: RickyRister Date: Sat, 16 Aug 2025 23:02:43 -0700 Subject: [PATCH] Prevent adding duplicate replays --- servatrice/src/serversocketinterface.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/servatrice/src/serversocketinterface.cpp b/servatrice/src/serversocketinterface.cpp index 3b8fb67a6..d94eb3be8 100644 --- a/servatrice/src/serversocketinterface.cpp +++ b/servatrice/src/serversocketinterface.cpp @@ -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;