servatrice: stub for reveal_card, database changes
This commit is contained in:
parent
03847a9b36
commit
08df264556
5 changed files with 49 additions and 5 deletions
|
@ -7,7 +7,7 @@
|
|||
#include "client.h"
|
||||
|
||||
ZoneViewWidget::ZoneViewWidget(CardDatabase *_db, Player *_player, CardZone *_origZone, int numberCards, QGraphicsItem *parent)
|
||||
: QGraphicsWidget(parent, Qt::Tool | Qt::CustomizeWindowHint | Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint), db(_db), player(_player)
|
||||
: QGraphicsWidget(parent, Qt::Tool | Qt::CustomizeWindowHint | Qt::WindowSystemMenuHint | Qt::WindowTitleHint/* | Qt::WindowCloseButtonHint*/), db(_db), player(_player)
|
||||
{
|
||||
setWindowTitle(QString("%1's %2").arg(player->getName()).arg(_origZone->getName()));
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include <QSettings>
|
||||
|
||||
Server::Server(QObject *parent)
|
||||
: QTcpServer(parent), nextGameId(1)
|
||||
: QTcpServer(parent), nextGameId(0)
|
||||
{
|
||||
settings = new QSettings("servatrice.ini", QSettings::IniFormat, this);
|
||||
}
|
||||
|
@ -44,7 +44,19 @@ bool Server::openDatabase()
|
|||
sqldb.setPassword(settings->value("password").toString());
|
||||
settings->endGroup();
|
||||
|
||||
return sqldb.open();
|
||||
if (!sqldb.open())
|
||||
return false;
|
||||
|
||||
if (!nextGameId) {
|
||||
QSqlQuery query;
|
||||
if (!query.exec("select max(id) from games"))
|
||||
return false;
|
||||
if (!query.next())
|
||||
return false;
|
||||
nextGameId = query.value(0).toInt() + 1;
|
||||
qDebug(QString("set nextGameId to %1").arg(nextGameId).toLatin1());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Server::addGame(const QString description, const QString password, const int maxPlayers, ServerSocket *creator)
|
||||
|
@ -73,7 +85,7 @@ AuthenticationResult Server::checkUserPassword(const QString &user, const QStrin
|
|||
}
|
||||
|
||||
QSqlQuery query;
|
||||
query.prepare("select password from users where name = :name");
|
||||
query.prepare("select password from players where name = :name");
|
||||
query.bindValue(":name", user);
|
||||
if (!query.exec()) {
|
||||
qCritical(QString("Database error: %1").arg(query.lastError().text()).toLatin1());
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "servergame.h"
|
||||
#include "random.h"
|
||||
#include "serversocket.h"
|
||||
#include <QSqlQuery>
|
||||
|
||||
ServerGame::ServerGame(ServerSocket *_creator, int _gameId, QString _description, QString _password, int _maxPlayers, QObject *parent)
|
||||
: QObject(parent), gameStarted(false), rnd(0), creator(_creator), gameId(_gameId), description(_description), password(_password), maxPlayers(_maxPlayers)
|
||||
|
@ -88,6 +89,20 @@ void ServerGame::startGameIfReady()
|
|||
if (players.at(i)->getStatus() != StatusReadyStart)
|
||||
return;
|
||||
|
||||
QSqlQuery query;
|
||||
query.prepare("insert into games (id, descr, password, time_started) values(:id, :descr, :password, now())");
|
||||
query.bindValue(":id", gameId);
|
||||
query.bindValue(":descr", description);
|
||||
query.bindValue(":password", !password.isEmpty());
|
||||
query.exec();
|
||||
|
||||
for (int i = 0; i < players.size(); i++) {
|
||||
query.prepare("insert into games_players (id_game, player) values(:id, :player)");
|
||||
query.bindValue(":id", gameId);
|
||||
query.bindValue(":player", players.at(i)->PlayerName);
|
||||
query.exec();
|
||||
}
|
||||
|
||||
if (!rnd) {
|
||||
rnd = new Random(this);
|
||||
rnd->init();
|
||||
|
|
|
@ -184,6 +184,8 @@ const ServerSocket::CommandProperties ServerSocket::commandList[ServerSocket::nu
|
|||
{"ready_start", true, true, false, QList<QVariant::Type>(), &ServerSocket::cmdReadyStart},
|
||||
{"shuffle", true, true, true, QList<QVariant::Type>(), &ServerSocket::cmdShuffle},
|
||||
{"draw_cards", true, true, true, QList<QVariant::Type>() << QVariant::Int, &ServerSocket::cmdDrawCards},
|
||||
{"reveal_card", true, true, true, QList<QVariant::Type>() << QVariant::Int
|
||||
<< QVariant::String, &ServerSocket::cmdRevealCard},
|
||||
{"move_card", true, true, true, QList<QVariant::Type>() << QVariant::Int
|
||||
<< QVariant::String
|
||||
<< QVariant::String
|
||||
|
@ -337,6 +339,20 @@ ReturnMessage::ReturnCode ServerSocket::cmdDrawCards(const QList<QVariant> ¶
|
|||
return ReturnMessage::ReturnOk;
|
||||
}
|
||||
|
||||
ReturnMessage::ReturnCode ServerSocket::cmdRevealCard(const QList<QVariant> ¶ms)
|
||||
{
|
||||
int cardid = params[0].toInt();
|
||||
PlayerZone *zone = getZone(params[1].toString());
|
||||
if (!zone)
|
||||
return ReturnMessage::ReturnContextError;
|
||||
int position = -1;
|
||||
Card *card = zone->getCard(cardid, false, &position);
|
||||
if (!card)
|
||||
return ReturnMessage::ReturnContextError;
|
||||
emit broadcastEvent(QString("reveal_card|%1|%2|%3").arg(cardid).arg(zone->getName()).arg(card->getName()), this);
|
||||
return ReturnMessage::ReturnOk;
|
||||
}
|
||||
|
||||
ReturnMessage::ReturnCode ServerSocket::cmdMoveCard(const QList<QVariant> ¶ms)
|
||||
{
|
||||
// ID Karte, Startzone, Zielzone, Koordinaten X, Y, Facedown
|
||||
|
|
|
@ -55,7 +55,7 @@ private:
|
|||
QList<QVariant::Type> paramTypes;
|
||||
CommandHandler handler;
|
||||
};
|
||||
static const int numberCommands = 25;
|
||||
static const int numberCommands = 26;
|
||||
static const CommandProperties commandList[numberCommands];
|
||||
|
||||
ReturnMessage::ReturnCode cmdPing(const QList<QVariant> ¶ms);
|
||||
|
@ -70,6 +70,7 @@ private:
|
|||
ReturnMessage::ReturnCode cmdReadyStart(const QList<QVariant> ¶ms);
|
||||
ReturnMessage::ReturnCode cmdShuffle(const QList<QVariant> ¶ms);
|
||||
ReturnMessage::ReturnCode cmdDrawCards(const QList<QVariant> ¶ms);
|
||||
ReturnMessage::ReturnCode cmdRevealCard(const QList<QVariant> ¶ms);
|
||||
ReturnMessage::ReturnCode cmdMoveCard(const QList<QVariant> ¶ms);
|
||||
ReturnMessage::ReturnCode cmdCreateToken(const QList<QVariant> ¶ms);
|
||||
ReturnMessage::ReturnCode cmdSetCardAttr(const QList<QVariant> ¶ms);
|
||||
|
|
Loading…
Reference in a new issue