mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-14 22:42:14 -07:00
Change hash method
This commit is contained in:
parent
fc73ef304e
commit
375b0981f0
1 changed files with 9 additions and 6 deletions
|
|
@ -744,15 +744,18 @@ Response::ResponseCode AbstractServerSocketInterface::cmdReplayDeleteMatch(const
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a hash for the given replay folder, used for auth when replay sharing
|
* Generates a hash for the given replay folder, used for auth when replay sharing.
|
||||||
* This is a separate function in case we change the hash implementation in the future
|
* This is a separate function in case we change the hash implementation in the future.
|
||||||
|
*
|
||||||
|
* Currently, we append together the first 128 bytes of the first 3 replays in the game, and hash that.
|
||||||
*
|
*
|
||||||
* @param gameId The replay match to hash
|
* @param gameId The replay match to hash
|
||||||
* @return The hash as a QString. Returns an empty string if failed
|
* @return The hash as a QString. Returns an empty string if failed
|
||||||
*/
|
*/
|
||||||
QString AbstractServerSocketInterface::createHashForReplay(int gameId)
|
QString AbstractServerSocketInterface::createHashForReplay(int gameId)
|
||||||
{
|
{
|
||||||
QSqlQuery *query = sqlInterface->prepareQuery("select replay from {prefix}_replays where id_game = :id_game");
|
QSqlQuery *query =
|
||||||
|
sqlInterface->prepareQuery("select replay from {prefix}_replays where id_game = :id_game limit 3");
|
||||||
query->bindValue(":id_game", gameId);
|
query->bindValue(":id_game", gameId);
|
||||||
|
|
||||||
if (!sqlInterface->execSqlQuery(query))
|
if (!sqlInterface->execSqlQuery(query))
|
||||||
|
|
@ -761,11 +764,11 @@ QString AbstractServerSocketInterface::createHashForReplay(int gameId)
|
||||||
QByteArray replaysBytes;
|
QByteArray replaysBytes;
|
||||||
while (query->next()) {
|
while (query->next()) {
|
||||||
QByteArray replay = query->value(0).toByteArray();
|
QByteArray replay = query->value(0).toByteArray();
|
||||||
replay.truncate(127);
|
replay.truncate(128);
|
||||||
replaysBytes.append(replay);
|
replaysBytes.append(replay);
|
||||||
}
|
}
|
||||||
|
|
||||||
return QCryptographicHash::hash(replaysBytes, QCryptographicHash::Md5).toHex();
|
return QCryptographicHash::hash(replaysBytes, QCryptographicHash::Md5);
|
||||||
}
|
}
|
||||||
|
|
||||||
Response::ResponseCode AbstractServerSocketInterface::cmdReplayGetCode(const Command_ReplayGetCode &cmd,
|
Response::ResponseCode AbstractServerSocketInterface::cmdReplayGetCode(const Command_ReplayGetCode &cmd,
|
||||||
|
|
@ -804,7 +807,7 @@ Response::ResponseCode AbstractServerSocketInterface::cmdReplayGetCode(const Com
|
||||||
Response::ResponseCode AbstractServerSocketInterface::cmdReplaySubmitCode(const Command_ReplaySubmitCode &cmd,
|
Response::ResponseCode AbstractServerSocketInterface::cmdReplaySubmitCode(const Command_ReplaySubmitCode &cmd,
|
||||||
ResponseContainer & /*rc*/)
|
ResponseContainer & /*rc*/)
|
||||||
{
|
{
|
||||||
// code is of the form <game-id>-<hash of replay data>
|
// code is of the form <game-id>-<hash>
|
||||||
QString code = QString::fromStdString(cmd.replay_code());
|
QString code = QString::fromStdString(cmd.replay_code());
|
||||||
QStringList split = code.split("-");
|
QStringList split = code.split("-");
|
||||||
if (split.size() != 2) {
|
if (split.size() != 2) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue