added mutex for RNG, moved game command implementation from S_PH to S_Player in preparation for forwarding of game commands via tunneling interface

This commit is contained in:
Max-Wilhelm Bruker 2012-03-17 22:26:12 +01:00
parent 671214c60e
commit 9706ecd98a
11 changed files with 1090 additions and 1092 deletions

View file

@ -29,6 +29,7 @@
#include "server_logger.h"
#include "main.h"
#include "passwordhasher.h"
#include "decklist.h"
#include "pb/game_replay.pb.h"
#include "pb/event_replay_added.pb.h"
#include "pb/event_server_message.pb.h"
@ -815,6 +816,27 @@ void Servatrice::storeGameInformation(int secondsElapsed, const QSet<QString> &a
query3.execBatch();
}
DeckList *Servatrice::getDeckFromDatabase(int deckId, const QString &userName)
{
checkSql();
QMutexLocker locker(&dbMutex);
QSqlQuery query;
query.prepare("select content from " + dbPrefix + "_decklist_files where id = :id and user = :user");
query.bindValue(":id", deckId);
query.bindValue(":user", userName);
execSqlQuery(query);
if (!query.next())
throw Response::RespNameNotFound;
QXmlStreamReader deckReader(query.value(0).toString());
DeckList *deck = new DeckList;
deck->loadFromXml(&deckReader);
return deck;
}
void Servatrice::scheduleShutdown(const QString &reason, int minutes)
{
shutdownReason = reason;

View file

@ -116,6 +116,7 @@ public:
void incRxBytes(quint64 num);
int getUserIdInDB(const QString &name);
void storeGameInformation(int secondsElapsed, const QSet<QString> &allPlayersEver, const QSet<QString> &allSpectatorsEver, const QList<GameReplay *> &replays);
DeckList *getDeckFromDatabase(int deckId, const QString &userName);
bool islConnectionExists(int serverId) const;
void addIslInterface(int serverId, IslInterface *interface);

View file

@ -451,27 +451,6 @@ Response::ResponseCode ServerSocketInterface::cmdDeckUpload(const Command_DeckUp
return Response::RespOk;
}
DeckList *ServerSocketInterface::getDeckFromDatabase(int deckId)
{
servatrice->checkSql();
QMutexLocker locker(&servatrice->dbMutex);
QSqlQuery query;
query.prepare("select content from " + servatrice->getDbPrefix() + "_decklist_files where id = :id and user = :user");
query.bindValue(":id", deckId);
query.bindValue(":user", QString::fromStdString(userInfo->name()));
servatrice->execSqlQuery(query);
if (!query.next())
throw Response::RespNameNotFound;
QXmlStreamReader deckReader(query.value(0).toString());
DeckList *deck = new DeckList;
deck->loadFromXml(&deckReader);
return deck;
}
Response::ResponseCode ServerSocketInterface::cmdDeckDownload(const Command_DeckDownload &cmd, ResponseContainer &rc)
{
if (authState != PasswordRight)
@ -479,7 +458,7 @@ Response::ResponseCode ServerSocketInterface::cmdDeckDownload(const Command_Deck
DeckList *deck;
try {
deck = getDeckFromDatabase(cmd.deck_id());
deck = servatrice->getDeckFromDatabase(cmd.deck_id(), QString::fromStdString(userInfo->name()));
} catch(Response::ResponseCode r) {
return r;
}