minor visual change, server crash fix, multiplayer leave/concede fixes
This commit is contained in:
parent
6bdc8914a9
commit
d4f600393f
10 changed files with 169 additions and 58 deletions
|
@ -69,12 +69,13 @@ void AbstractCardItem::transformPainter(QPainter *painter, const QSizeF &transla
|
||||||
painter->setTransform(pixmapTransform);
|
painter->setTransform(pixmapTransform);
|
||||||
|
|
||||||
QFont f;
|
QFont f;
|
||||||
int fontSize = translatedSize.height() / 8;
|
int fontSize = round(translatedSize.height() / 8);
|
||||||
if (fontSize < 9)
|
if (fontSize < 9)
|
||||||
fontSize = 9;
|
fontSize = 9;
|
||||||
if (fontSize > 12)
|
if (fontSize > 10)
|
||||||
fontSize = 12;
|
fontSize = 10;
|
||||||
f.setPixelSize(fontSize);
|
f.setPixelSize(fontSize);
|
||||||
|
|
||||||
painter->setFont(f);
|
painter->setFont(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -330,7 +330,6 @@ void CardInfo::imageLoaded(const QImage &image)
|
||||||
|
|
||||||
QPixmap *CardInfo::getPixmap(QSize size)
|
QPixmap *CardInfo::getPixmap(QSize size)
|
||||||
{
|
{
|
||||||
qDebug() << "CardInfo::getPixmap(" << size.width() << size.height() << ") for" << getName();
|
|
||||||
QPixmap *cachedPixmap = scaledPixmapCache.value(size.width());
|
QPixmap *cachedPixmap = scaledPixmapCache.value(size.width());
|
||||||
if (cachedPixmap)
|
if (cachedPixmap)
|
||||||
return cachedPixmap;
|
return cachedPixmap;
|
||||||
|
|
|
@ -26,6 +26,7 @@ void GameScene::addPlayer(Player *player)
|
||||||
addItem(player);
|
addItem(player);
|
||||||
rearrange();
|
rearrange();
|
||||||
connect(player, SIGNAL(sizeChanged()), this, SLOT(rearrange()));
|
connect(player, SIGNAL(sizeChanged()), this, SLOT(rearrange()));
|
||||||
|
connect(player, SIGNAL(gameConceded()), this, SLOT(rearrange()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScene::removePlayer(Player *player)
|
void GameScene::removePlayer(Player *player)
|
||||||
|
@ -41,6 +42,9 @@ void GameScene::rearrange()
|
||||||
struct PlayerProcessor {
|
struct PlayerProcessor {
|
||||||
static void processPlayer(Player *p, qreal &w, QPointF &b, bool singlePlayer)
|
static void processPlayer(Player *p, qreal &w, QPointF &b, bool singlePlayer)
|
||||||
{
|
{
|
||||||
|
if (p->getConceded())
|
||||||
|
return;
|
||||||
|
|
||||||
const QRectF br = p->boundingRect();
|
const QRectF br = p->boundingRect();
|
||||||
if (br.width() > w)
|
if (br.width() > w)
|
||||||
w = br.width();
|
w = br.width();
|
||||||
|
@ -52,7 +56,8 @@ void GameScene::rearrange()
|
||||||
|
|
||||||
qreal sceneHeight = -playerAreaSpacing;
|
qreal sceneHeight = -playerAreaSpacing;
|
||||||
for (int i = 0; i < players.size(); ++i)
|
for (int i = 0; i < players.size(); ++i)
|
||||||
sceneHeight += players[i]->boundingRect().height() + playerAreaSpacing;
|
if (!players[i]->getConceded())
|
||||||
|
sceneHeight += players[i]->boundingRect().height() + playerAreaSpacing;
|
||||||
phasesToolbar->setHeight(sceneHeight);
|
phasesToolbar->setHeight(sceneHeight);
|
||||||
qreal phasesWidth = phasesToolbar->getWidth();
|
qreal phasesWidth = phasesToolbar->getWidth();
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
Player::Player(ServerInfo_User *info, int _id, bool _local, TabGame *_parent)
|
Player::Player(ServerInfo_User *info, int _id, bool _local, TabGame *_parent)
|
||||||
: QObject(_parent), shortcutsActive(false), defaultNumberTopCards(3), lastTokenDestroy(true), userInfo(new ServerInfo_User(info)), id(_id), active(false), local(_local), mirrored(false), dialogSemaphore(false)
|
: QObject(_parent), shortcutsActive(false), defaultNumberTopCards(3), lastTokenDestroy(true), userInfo(new ServerInfo_User(info)), id(_id), active(false), local(_local), mirrored(false), conceded(false), dialogSemaphore(false)
|
||||||
{
|
{
|
||||||
setCacheMode(DeviceCoordinateCache);
|
setCacheMode(DeviceCoordinateCache);
|
||||||
|
|
||||||
|
@ -264,15 +264,25 @@ Player::~Player()
|
||||||
|
|
||||||
static_cast<GameScene *>(scene())->removePlayer(this);
|
static_cast<GameScene *>(scene())->removePlayer(this);
|
||||||
|
|
||||||
|
clear();
|
||||||
|
QMapIterator<QString, CardZone *> i(zones);
|
||||||
|
while (i.hasNext())
|
||||||
|
delete i.next().value();
|
||||||
|
zones.clear();
|
||||||
|
|
||||||
|
delete playerMenu;
|
||||||
|
delete userInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Player::clear()
|
||||||
|
{
|
||||||
clearArrows();
|
clearArrows();
|
||||||
|
|
||||||
QMapIterator<QString, CardZone *> i(zones);
|
QMapIterator<QString, CardZone *> i(zones);
|
||||||
while (i.hasNext())
|
while (i.hasNext())
|
||||||
delete i.next().value();
|
i.next().value()->clearContents();
|
||||||
|
|
||||||
clearCounters();
|
clearCounters();
|
||||||
delete playerMenu;
|
|
||||||
delete userInfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::addPlayer(Player *player)
|
void Player::addPlayer(Player *player)
|
||||||
|
@ -362,6 +372,11 @@ void Player::rearrangeZones()
|
||||||
rearrangeCounters();
|
rearrangeCounters();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Player::updateZones()
|
||||||
|
{
|
||||||
|
table->reorganizeCards();
|
||||||
|
}
|
||||||
|
|
||||||
void Player::updateBgPixmap()
|
void Player::updateBgPixmap()
|
||||||
{
|
{
|
||||||
QString bgPath = settingsCache->getPlayerBgPath();
|
QString bgPath = settingsCache->getPlayerBgPath();
|
||||||
|
@ -1485,6 +1500,16 @@ qreal Player::getMinimumWidth() const
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Player::setConceded(bool _conceded)
|
||||||
|
{
|
||||||
|
conceded = _conceded;
|
||||||
|
setVisible(!conceded);
|
||||||
|
if (conceded) {
|
||||||
|
clear();
|
||||||
|
emit gameConceded();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Player::setMirrored(bool _mirrored)
|
void Player::setMirrored(bool _mirrored)
|
||||||
{
|
{
|
||||||
if (mirrored != _mirrored) {
|
if (mirrored != _mirrored) {
|
||||||
|
|
|
@ -74,6 +74,7 @@ signals:
|
||||||
void logRevealCards(Player *player, CardZone *zone, int cardId, QString cardName, Player *otherPlayer);
|
void logRevealCards(Player *player, CardZone *zone, int cardId, QString cardName, Player *otherPlayer);
|
||||||
|
|
||||||
void sizeChanged();
|
void sizeChanged();
|
||||||
|
void gameConceded();
|
||||||
public slots:
|
public slots:
|
||||||
void actUntapAll();
|
void actUntapAll();
|
||||||
void actRollDie();
|
void actRollDie();
|
||||||
|
@ -102,7 +103,6 @@ public slots:
|
||||||
void actSetAnnotation(QAction *action);
|
void actSetAnnotation(QAction *action);
|
||||||
void cardMenuAction(QAction *action);
|
void cardMenuAction(QAction *action);
|
||||||
void actCardCounterTrigger(QAction *action);
|
void actCardCounterTrigger(QAction *action);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void addPlayer(Player *player);
|
void addPlayer(Player *player);
|
||||||
void removePlayer(Player *player);
|
void removePlayer(Player *player);
|
||||||
|
@ -134,6 +134,7 @@ private:
|
||||||
bool active;
|
bool active;
|
||||||
bool local;
|
bool local;
|
||||||
bool mirrored;
|
bool mirrored;
|
||||||
|
bool conceded;
|
||||||
|
|
||||||
bool dialogSemaphore;
|
bool dialogSemaphore;
|
||||||
bool clearCardsToDelete();
|
bool clearCardsToDelete();
|
||||||
|
@ -203,6 +204,7 @@ public:
|
||||||
Player(ServerInfo_User *info, int _id, bool _local, TabGame *_parent);
|
Player(ServerInfo_User *info, int _id, bool _local, TabGame *_parent);
|
||||||
~Player();
|
~Player();
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
|
void clear();
|
||||||
QMenu *getPlayerMenu() const { return playerMenu; }
|
QMenu *getPlayerMenu() const { return playerMenu; }
|
||||||
int getId() const { return id; }
|
int getId() const { return id; }
|
||||||
QString getName() const;
|
QString getName() const;
|
||||||
|
@ -211,13 +213,16 @@ public:
|
||||||
bool getMirrored() const { return mirrored; }
|
bool getMirrored() const { return mirrored; }
|
||||||
const QMap<QString, CardZone *> &getZones() const { return zones; }
|
const QMap<QString, CardZone *> &getZones() const { return zones; }
|
||||||
const QMap<int, ArrowItem *> &getArrows() const { return arrows; }
|
const QMap<int, ArrowItem *> &getArrows() const { return arrows; }
|
||||||
TableZone *getTable() const { return table; }
|
|
||||||
void setCardMenu(QMenu *menu);
|
void setCardMenu(QMenu *menu);
|
||||||
QMenu *getCardMenu() const;
|
QMenu *getCardMenu() const;
|
||||||
bool getActive() const { return active; }
|
bool getActive() const { return active; }
|
||||||
void setActive(bool _active);
|
void setActive(bool _active);
|
||||||
void setShortcutsActive();
|
void setShortcutsActive();
|
||||||
void setShortcutsInactive();
|
void setShortcutsInactive();
|
||||||
|
void updateZones();
|
||||||
|
|
||||||
|
void setConceded(bool _conceded);
|
||||||
|
bool getConceded() const { return conceded; }
|
||||||
|
|
||||||
qreal getMinimumWidth() const;
|
qreal getMinimumWidth() const;
|
||||||
void setMirrored(bool _mirrored);
|
void setMirrored(bool _mirrored);
|
||||||
|
|
|
@ -477,6 +477,10 @@ void TabGame::startGame()
|
||||||
}
|
}
|
||||||
mainLayout->removeItem(deckViewContainerLayout);
|
mainLayout->removeItem(deckViewContainerLayout);
|
||||||
|
|
||||||
|
QMapIterator<int, Player *> playerIterator(players);
|
||||||
|
while (playerIterator.hasNext())
|
||||||
|
playerIterator.next().value()->setConceded(false);
|
||||||
|
|
||||||
playerListWidget->setGameStarted(true);
|
playerListWidget->setGameStarted(true);
|
||||||
started = true;
|
started = true;
|
||||||
gameView->show();
|
gameView->show();
|
||||||
|
@ -581,7 +585,16 @@ void TabGame::eventPlayerPropertiesChanged(Event_PlayerPropertiesChanged *event,
|
||||||
messageLog->logNotReadyStart(player);
|
messageLog->logNotReadyStart(player);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ItemId_Context_Concede: messageLog->logConcede(player); break;
|
case ItemId_Context_Concede: {
|
||||||
|
messageLog->logConcede(player);
|
||||||
|
player->setConceded(true);
|
||||||
|
|
||||||
|
QMapIterator<int, Player *> playerIterator(players);
|
||||||
|
while (playerIterator.hasNext())
|
||||||
|
playerIterator.next().value()->updateZones();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
case ItemId_Context_DeckSelect: messageLog->logDeckSelect(player, static_cast<Context_DeckSelect *>(context)->getDeckId()); break;
|
case ItemId_Context_DeckSelect: messageLog->logDeckSelect(player, static_cast<Context_DeckSelect *>(context)->getDeckId()); break;
|
||||||
default: ;
|
default: ;
|
||||||
}
|
}
|
||||||
|
@ -609,13 +622,21 @@ void TabGame::eventLeave(Event_Leave *event, GameEventContext * /*context*/)
|
||||||
int playerId = event->getPlayerId();
|
int playerId = event->getPlayerId();
|
||||||
|
|
||||||
Player *player = players.value(playerId, 0);
|
Player *player = players.value(playerId, 0);
|
||||||
if (player) {
|
if (!player)
|
||||||
messageLog->logLeave(player);
|
return;
|
||||||
playerListWidget->removePlayer(playerId);
|
|
||||||
players.remove(playerId);
|
messageLog->logLeave(player);
|
||||||
emit playerRemoved(player);
|
playerListWidget->removePlayer(playerId);
|
||||||
player->deleteLater();
|
players.remove(playerId);
|
||||||
}
|
emit playerRemoved(player);
|
||||||
|
player->clear();
|
||||||
|
player->deleteLater();
|
||||||
|
|
||||||
|
// Rearrange all remaining zones so that attachment relationship updates take place
|
||||||
|
QMapIterator<int, Player *> playerIterator(players);
|
||||||
|
while (playerIterator.hasNext())
|
||||||
|
playerIterator.next().value()->updateZones();
|
||||||
|
|
||||||
emit userEvent();
|
emit userEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,6 @@ Server_Card::Server_Card(QString _name, int _id, int _coord_x, int _coord_y)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Server_Card::~Server_Card()
|
Server_Card::~Server_Card()
|
||||||
{
|
{
|
||||||
// setParentCard(0) leads to the item being removed from our list, so we can't iterate properly
|
// setParentCard(0) leads to the item being removed from our list, so we can't iterate properly
|
||||||
|
|
|
@ -227,13 +227,17 @@ void Server_Game::removePlayer(Server_Player *player)
|
||||||
}
|
}
|
||||||
|
|
||||||
sendGameEvent(new Event_Leave(player->getPlayerId()));
|
sendGameEvent(new Event_Leave(player->getPlayerId()));
|
||||||
|
bool playerActive = activePlayer == player->getPlayerId();
|
||||||
bool spectator = player->getSpectator();
|
bool spectator = player->getSpectator();
|
||||||
delete player;
|
delete player;
|
||||||
|
|
||||||
if (!getPlayerCount())
|
if (!getPlayerCount())
|
||||||
deleteLater();
|
deleteLater();
|
||||||
else if (!spectator)
|
else if (!spectator) {
|
||||||
stopGameIfFinished();
|
stopGameIfFinished();
|
||||||
|
if (gameStarted && playerActive)
|
||||||
|
nextTurn();
|
||||||
|
}
|
||||||
qobject_cast<Server_Room *>(parent())->broadcastGameListUpdate(this);
|
qobject_cast<Server_Room *>(parent())->broadcastGameListUpdate(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,7 +275,7 @@ void Server_Game::nextTurn()
|
||||||
++listPos;
|
++listPos;
|
||||||
if (listPos == keys.size())
|
if (listPos == keys.size())
|
||||||
listPos = 0;
|
listPos = 0;
|
||||||
} while (players.value(keys[listPos])->getSpectator());
|
} while (players.value(keys[listPos])->getSpectator() || players.value(keys[listPos])->getConceded());
|
||||||
|
|
||||||
setActivePlayer(keys[listPos]);
|
setActivePlayer(keys[listPos]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,8 @@ Server_Player::~Server_Player()
|
||||||
if (handler)
|
if (handler)
|
||||||
handler->playerRemovedFromGame(game);
|
handler->playerRemovedFromGame(game);
|
||||||
delete userInfo;
|
delete userInfo;
|
||||||
|
|
||||||
|
clearZones();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Server_Player::newCardId()
|
int Server_Player::newCardId()
|
||||||
|
|
|
@ -322,14 +322,14 @@ ResponseCode Server_ProtocolHandler::cmdJoinRoom(Command_JoinRoom *cmd, CommandC
|
||||||
return RespNothing;
|
return RespNothing;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdLeaveRoom(Command_LeaveRoom * /*cmd*/, CommandContainer *cont, Server_Room *room)
|
ResponseCode Server_ProtocolHandler::cmdLeaveRoom(Command_LeaveRoom * /*cmd*/, CommandContainer * /*cont*/, Server_Room *room)
|
||||||
{
|
{
|
||||||
rooms.remove(room->getId());
|
rooms.remove(room->getId());
|
||||||
room->removeClient(this);
|
room->removeClient(this);
|
||||||
return RespOk;
|
return RespOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdRoomSay(Command_RoomSay *cmd, CommandContainer *cont, Server_Room *room)
|
ResponseCode Server_ProtocolHandler::cmdRoomSay(Command_RoomSay *cmd, CommandContainer * /*cont*/, Server_Room *room)
|
||||||
{
|
{
|
||||||
room->say(this, cmd->getMessage());
|
room->say(this, cmd->getMessage());
|
||||||
return RespOk;
|
return RespOk;
|
||||||
|
@ -351,7 +351,7 @@ ResponseCode Server_ProtocolHandler::cmdListUsers(Command_ListUsers * /*cmd*/, C
|
||||||
return RespNothing;
|
return RespNothing;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd, CommandContainer *cont, Server_Room *room)
|
ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd, CommandContainer * /*cont*/, Server_Room *room)
|
||||||
{
|
{
|
||||||
if (authState == PasswordWrong)
|
if (authState == PasswordWrong)
|
||||||
return RespLoginNeeded;
|
return RespLoginNeeded;
|
||||||
|
@ -370,7 +370,7 @@ ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd, Comm
|
||||||
return RespOk;
|
return RespOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd, CommandContainer *cont, Server_Room *room)
|
ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd, CommandContainer * /*cont*/, Server_Room *room)
|
||||||
{
|
{
|
||||||
if (authState == PasswordWrong)
|
if (authState == PasswordWrong)
|
||||||
return RespLoginNeeded;
|
return RespLoginNeeded;
|
||||||
|
@ -392,7 +392,7 @@ ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd, CommandC
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdLeaveGame(Command_LeaveGame * /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
ResponseCode Server_ProtocolHandler::cmdLeaveGame(Command_LeaveGame * /*cmd*/, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player)
|
||||||
{
|
{
|
||||||
game->removePlayer(player);
|
game->removePlayer(player);
|
||||||
return RespOk;
|
return RespOk;
|
||||||
|
@ -423,7 +423,7 @@ ResponseCode Server_ProtocolHandler::cmdDeckSelect(Command_DeckSelect *cmd, Comm
|
||||||
return RespNothing;
|
return RespNothing;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdSetSideboardPlan(Command_SetSideboardPlan *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
ResponseCode Server_ProtocolHandler::cmdSetSideboardPlan(Command_SetSideboardPlan *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player)
|
||||||
{
|
{
|
||||||
if (player->getSpectator())
|
if (player->getSpectator())
|
||||||
return RespFunctionNotAllowed;
|
return RespFunctionNotAllowed;
|
||||||
|
@ -438,18 +438,24 @@ ResponseCode Server_ProtocolHandler::cmdSetSideboardPlan(Command_SetSideboardPla
|
||||||
return RespOk;
|
return RespOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdConcede(Command_Concede * /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
ResponseCode Server_ProtocolHandler::cmdConcede(Command_Concede * /*cmd*/, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player)
|
||||||
{
|
{
|
||||||
if (player->getSpectator())
|
if (player->getSpectator())
|
||||||
return RespFunctionNotAllowed;
|
return RespFunctionNotAllowed;
|
||||||
|
if (player->getConceded())
|
||||||
|
return RespContextError;
|
||||||
|
|
||||||
player->setConceded(true);
|
player->setConceded(true);
|
||||||
|
player->clearZones();
|
||||||
game->sendGameEvent(new Event_PlayerPropertiesChanged(player->getPlayerId(), player->getProperties()), new Context_Concede);
|
game->sendGameEvent(new Event_PlayerPropertiesChanged(player->getPlayerId(), player->getProperties()), new Context_Concede);
|
||||||
game->stopGameIfFinished();
|
game->stopGameIfFinished();
|
||||||
|
if (game->getGameStarted() && (game->getActivePlayer() == player->getPlayerId()))
|
||||||
|
game->nextTurn();
|
||||||
|
|
||||||
return RespOk;
|
return RespOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdReadyStart(Command_ReadyStart *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
ResponseCode Server_ProtocolHandler::cmdReadyStart(Command_ReadyStart *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player)
|
||||||
{
|
{
|
||||||
if (player->getSpectator())
|
if (player->getSpectator())
|
||||||
return RespFunctionNotAllowed;
|
return RespFunctionNotAllowed;
|
||||||
|
@ -466,7 +472,7 @@ ResponseCode Server_ProtocolHandler::cmdReadyStart(Command_ReadyStart *cmd, Comm
|
||||||
return RespOk;
|
return RespOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdSay(Command_Say *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
ResponseCode Server_ProtocolHandler::cmdSay(Command_Say *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player)
|
||||||
{
|
{
|
||||||
if (player->getSpectator() && !game->getSpectatorsCanTalk())
|
if (player->getSpectator() && !game->getSpectatorsCanTalk())
|
||||||
return RespFunctionNotAllowed;
|
return RespFunctionNotAllowed;
|
||||||
|
@ -475,13 +481,15 @@ ResponseCode Server_ProtocolHandler::cmdSay(Command_Say *cmd, CommandContainer *
|
||||||
return RespOk;
|
return RespOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdShuffle(Command_Shuffle * /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
ResponseCode Server_ProtocolHandler::cmdShuffle(Command_Shuffle * /*cmd*/, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player)
|
||||||
{
|
{
|
||||||
if (player->getSpectator())
|
if (player->getSpectator())
|
||||||
return RespFunctionNotAllowed;
|
return RespFunctionNotAllowed;
|
||||||
|
|
||||||
if (!game->getGameStarted())
|
if (!game->getGameStarted())
|
||||||
return RespGameNotStarted;
|
return RespGameNotStarted;
|
||||||
|
if (player->getConceded())
|
||||||
|
return RespContextError;
|
||||||
|
|
||||||
player->getZones().value("deck")->shuffle();
|
player->getZones().value("deck")->shuffle();
|
||||||
game->sendGameEvent(new Event_Shuffle(player->getPlayerId()));
|
game->sendGameEvent(new Event_Shuffle(player->getPlayerId()));
|
||||||
|
@ -495,6 +503,8 @@ ResponseCode Server_ProtocolHandler::cmdMulligan(Command_Mulligan * /*cmd*/, Com
|
||||||
|
|
||||||
if (!game->getGameStarted())
|
if (!game->getGameStarted())
|
||||||
return RespGameNotStarted;
|
return RespGameNotStarted;
|
||||||
|
if (player->getConceded())
|
||||||
|
return RespContextError;
|
||||||
|
|
||||||
Server_CardZone *hand = player->getZones().value("hand");
|
Server_CardZone *hand = player->getZones().value("hand");
|
||||||
int number = (hand->cards.size() <= 1) ? player->getInitialCards() : hand->cards.size() - 1;
|
int number = (hand->cards.size() <= 1) ? player->getInitialCards() : hand->cards.size() - 1;
|
||||||
|
@ -512,10 +522,12 @@ ResponseCode Server_ProtocolHandler::cmdMulligan(Command_Mulligan * /*cmd*/, Com
|
||||||
return RespOk;
|
return RespOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdRollDie(Command_RollDie *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
ResponseCode Server_ProtocolHandler::cmdRollDie(Command_RollDie *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player)
|
||||||
{
|
{
|
||||||
if (player->getSpectator())
|
if (player->getSpectator())
|
||||||
return RespFunctionNotAllowed;
|
return RespFunctionNotAllowed;
|
||||||
|
if (player->getConceded())
|
||||||
|
return RespContextError;
|
||||||
|
|
||||||
game->sendGameEvent(new Event_RollDie(player->getPlayerId(), cmd->getSides(), rng->getNumber(1, cmd->getSides())));
|
game->sendGameEvent(new Event_RollDie(player->getPlayerId(), cmd->getSides(), rng->getNumber(1, cmd->getSides())));
|
||||||
return RespOk;
|
return RespOk;
|
||||||
|
@ -528,17 +540,21 @@ ResponseCode Server_ProtocolHandler::cmdDrawCards(Command_DrawCards *cmd, Comman
|
||||||
|
|
||||||
if (!game->getGameStarted())
|
if (!game->getGameStarted())
|
||||||
return RespGameNotStarted;
|
return RespGameNotStarted;
|
||||||
|
if (player->getConceded())
|
||||||
|
return RespContextError;
|
||||||
|
|
||||||
return player->drawCards(cont, cmd->getNumber());
|
return player->drawCards(cont, cmd->getNumber());
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdUndoDraw(Command_UndoDraw *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
ResponseCode Server_ProtocolHandler::cmdUndoDraw(Command_UndoDraw * /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||||
{
|
{
|
||||||
if (player->getSpectator())
|
if (player->getSpectator())
|
||||||
return RespFunctionNotAllowed;
|
return RespFunctionNotAllowed;
|
||||||
|
|
||||||
if (!game->getGameStarted())
|
if (!game->getGameStarted())
|
||||||
return RespGameNotStarted;
|
return RespGameNotStarted;
|
||||||
|
if (player->getConceded())
|
||||||
|
return RespContextError;
|
||||||
|
|
||||||
return player->undoDraw(cont);
|
return player->undoDraw(cont);
|
||||||
}
|
}
|
||||||
|
@ -550,6 +566,8 @@ ResponseCode Server_ProtocolHandler::cmdMoveCard(Command_MoveCard *cmd, CommandC
|
||||||
|
|
||||||
if (!game->getGameStarted())
|
if (!game->getGameStarted())
|
||||||
return RespGameNotStarted;
|
return RespGameNotStarted;
|
||||||
|
if (player->getConceded())
|
||||||
|
return RespContextError;
|
||||||
|
|
||||||
QList<int> cardIds;
|
QList<int> cardIds;
|
||||||
const QList<CardId *> &temp = cmd->getCardIds();
|
const QList<CardId *> &temp = cmd->getCardIds();
|
||||||
|
@ -566,6 +584,8 @@ ResponseCode Server_ProtocolHandler::cmdFlipCard(Command_FlipCard *cmd, CommandC
|
||||||
|
|
||||||
if (!game->getGameStarted())
|
if (!game->getGameStarted())
|
||||||
return RespGameNotStarted;
|
return RespGameNotStarted;
|
||||||
|
if (player->getConceded())
|
||||||
|
return RespContextError;
|
||||||
|
|
||||||
Server_CardZone *zone = player->getZones().value(cmd->getZone());
|
Server_CardZone *zone = player->getZones().value(cmd->getZone());
|
||||||
if (!zone)
|
if (!zone)
|
||||||
|
@ -595,6 +615,8 @@ ResponseCode Server_ProtocolHandler::cmdAttachCard(Command_AttachCard *cmd, Comm
|
||||||
|
|
||||||
if (!game->getGameStarted())
|
if (!game->getGameStarted())
|
||||||
return RespGameNotStarted;
|
return RespGameNotStarted;
|
||||||
|
if (player->getConceded())
|
||||||
|
return RespContextError;
|
||||||
|
|
||||||
Server_CardZone *startzone = player->getZones().value(cmd->getStartZone());
|
Server_CardZone *startzone = player->getZones().value(cmd->getStartZone());
|
||||||
if (!startzone)
|
if (!startzone)
|
||||||
|
@ -670,13 +692,15 @@ ResponseCode Server_ProtocolHandler::cmdAttachCard(Command_AttachCard *cmd, Comm
|
||||||
return RespOk;
|
return RespOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdCreateToken(Command_CreateToken *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
ResponseCode Server_ProtocolHandler::cmdCreateToken(Command_CreateToken *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player)
|
||||||
{
|
{
|
||||||
if (player->getSpectator())
|
if (player->getSpectator())
|
||||||
return RespFunctionNotAllowed;
|
return RespFunctionNotAllowed;
|
||||||
|
|
||||||
if (!game->getGameStarted())
|
if (!game->getGameStarted())
|
||||||
return RespGameNotStarted;
|
return RespGameNotStarted;
|
||||||
|
if (player->getConceded())
|
||||||
|
return RespContextError;
|
||||||
|
|
||||||
Server_CardZone *zone = player->getZones().value(cmd->getZone());
|
Server_CardZone *zone = player->getZones().value(cmd->getZone());
|
||||||
if (!zone)
|
if (!zone)
|
||||||
|
@ -703,13 +727,15 @@ ResponseCode Server_ProtocolHandler::cmdCreateToken(Command_CreateToken *cmd, Co
|
||||||
return RespOk;
|
return RespOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdCreateArrow(Command_CreateArrow *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
ResponseCode Server_ProtocolHandler::cmdCreateArrow(Command_CreateArrow *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player)
|
||||||
{
|
{
|
||||||
if (player->getSpectator())
|
if (player->getSpectator())
|
||||||
return RespFunctionNotAllowed;
|
return RespFunctionNotAllowed;
|
||||||
|
|
||||||
if (!game->getGameStarted())
|
if (!game->getGameStarted())
|
||||||
return RespGameNotStarted;
|
return RespGameNotStarted;
|
||||||
|
if (player->getConceded())
|
||||||
|
return RespContextError;
|
||||||
|
|
||||||
Server_Player *startPlayer = game->getPlayer(cmd->getStartPlayerId());
|
Server_Player *startPlayer = game->getPlayer(cmd->getStartPlayerId());
|
||||||
Server_Player *targetPlayer = game->getPlayer(cmd->getTargetPlayerId());
|
Server_Player *targetPlayer = game->getPlayer(cmd->getTargetPlayerId());
|
||||||
|
@ -764,13 +790,15 @@ ResponseCode Server_ProtocolHandler::cmdCreateArrow(Command_CreateArrow *cmd, Co
|
||||||
return RespOk;
|
return RespOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdDeleteArrow(Command_DeleteArrow *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
ResponseCode Server_ProtocolHandler::cmdDeleteArrow(Command_DeleteArrow *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player)
|
||||||
{
|
{
|
||||||
if (player->getSpectator())
|
if (player->getSpectator())
|
||||||
return RespFunctionNotAllowed;
|
return RespFunctionNotAllowed;
|
||||||
|
|
||||||
if (!game->getGameStarted())
|
if (!game->getGameStarted())
|
||||||
return RespGameNotStarted;
|
return RespGameNotStarted;
|
||||||
|
if (player->getConceded())
|
||||||
|
return RespContextError;
|
||||||
|
|
||||||
if (!player->deleteArrow(cmd->getArrowId()))
|
if (!player->deleteArrow(cmd->getArrowId()))
|
||||||
return RespNameNotFound;
|
return RespNameNotFound;
|
||||||
|
@ -786,6 +814,8 @@ ResponseCode Server_ProtocolHandler::cmdSetCardAttr(Command_SetCardAttr *cmd, Co
|
||||||
|
|
||||||
if (!game->getGameStarted())
|
if (!game->getGameStarted())
|
||||||
return RespGameNotStarted;
|
return RespGameNotStarted;
|
||||||
|
if (player->getConceded())
|
||||||
|
return RespContextError;
|
||||||
|
|
||||||
return player->setCardAttrHelper(cont, cmd->getZone(), cmd->getCardId(), cmd->getAttrName(), cmd->getAttrValue());
|
return player->setCardAttrHelper(cont, cmd->getZone(), cmd->getCardId(), cmd->getAttrName(), cmd->getAttrValue());
|
||||||
}
|
}
|
||||||
|
@ -797,6 +827,8 @@ ResponseCode Server_ProtocolHandler::cmdSetCardCounter(Command_SetCardCounter *c
|
||||||
|
|
||||||
if (!game->getGameStarted())
|
if (!game->getGameStarted())
|
||||||
return RespGameNotStarted;
|
return RespGameNotStarted;
|
||||||
|
if (player->getConceded())
|
||||||
|
return RespContextError;
|
||||||
|
|
||||||
Server_CardZone *zone = player->getZones().value(cmd->getZone());
|
Server_CardZone *zone = player->getZones().value(cmd->getZone());
|
||||||
if (!zone)
|
if (!zone)
|
||||||
|
@ -822,6 +854,8 @@ ResponseCode Server_ProtocolHandler::cmdIncCardCounter(Command_IncCardCounter *c
|
||||||
|
|
||||||
if (!game->getGameStarted())
|
if (!game->getGameStarted())
|
||||||
return RespGameNotStarted;
|
return RespGameNotStarted;
|
||||||
|
if (player->getConceded())
|
||||||
|
return RespContextError;
|
||||||
|
|
||||||
Server_CardZone *zone = player->getZones().value(cmd->getZone());
|
Server_CardZone *zone = player->getZones().value(cmd->getZone());
|
||||||
if (!zone)
|
if (!zone)
|
||||||
|
@ -841,13 +875,15 @@ ResponseCode Server_ProtocolHandler::cmdIncCardCounter(Command_IncCardCounter *c
|
||||||
return RespOk;
|
return RespOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdIncCounter(Command_IncCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
ResponseCode Server_ProtocolHandler::cmdIncCounter(Command_IncCounter *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player)
|
||||||
{
|
{
|
||||||
if (player->getSpectator())
|
if (player->getSpectator())
|
||||||
return RespFunctionNotAllowed;
|
return RespFunctionNotAllowed;
|
||||||
|
|
||||||
if (!game->getGameStarted())
|
if (!game->getGameStarted())
|
||||||
return RespGameNotStarted;
|
return RespGameNotStarted;
|
||||||
|
if (player->getConceded())
|
||||||
|
return RespContextError;
|
||||||
|
|
||||||
const QMap<int, Server_Counter *> counters = player->getCounters();
|
const QMap<int, Server_Counter *> counters = player->getCounters();
|
||||||
Server_Counter *c = counters.value(cmd->getCounterId(), 0);
|
Server_Counter *c = counters.value(cmd->getCounterId(), 0);
|
||||||
|
@ -859,13 +895,15 @@ ResponseCode Server_ProtocolHandler::cmdIncCounter(Command_IncCounter *cmd, Comm
|
||||||
return RespOk;
|
return RespOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdCreateCounter(Command_CreateCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
ResponseCode Server_ProtocolHandler::cmdCreateCounter(Command_CreateCounter *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player)
|
||||||
{
|
{
|
||||||
if (player->getSpectator())
|
if (player->getSpectator())
|
||||||
return RespFunctionNotAllowed;
|
return RespFunctionNotAllowed;
|
||||||
|
|
||||||
if (!game->getGameStarted())
|
if (!game->getGameStarted())
|
||||||
return RespGameNotStarted;
|
return RespGameNotStarted;
|
||||||
|
if (player->getConceded())
|
||||||
|
return RespContextError;
|
||||||
|
|
||||||
Server_Counter *c = new Server_Counter(player->newCounterId(), cmd->getCounterName(), cmd->getColor(), cmd->getRadius(), cmd->getValue());
|
Server_Counter *c = new Server_Counter(player->newCounterId(), cmd->getCounterName(), cmd->getColor(), cmd->getRadius(), cmd->getValue());
|
||||||
player->addCounter(c);
|
player->addCounter(c);
|
||||||
|
@ -874,13 +912,15 @@ ResponseCode Server_ProtocolHandler::cmdCreateCounter(Command_CreateCounter *cmd
|
||||||
return RespOk;
|
return RespOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdSetCounter(Command_SetCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
ResponseCode Server_ProtocolHandler::cmdSetCounter(Command_SetCounter *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player)
|
||||||
{
|
{
|
||||||
if (player->getSpectator())
|
if (player->getSpectator())
|
||||||
return RespFunctionNotAllowed;
|
return RespFunctionNotAllowed;
|
||||||
|
|
||||||
if (!game->getGameStarted())
|
if (!game->getGameStarted())
|
||||||
return RespGameNotStarted;
|
return RespGameNotStarted;
|
||||||
|
if (player->getConceded())
|
||||||
|
return RespContextError;
|
||||||
|
|
||||||
Server_Counter *c = player->getCounters().value(cmd->getCounterId(), 0);;
|
Server_Counter *c = player->getCounters().value(cmd->getCounterId(), 0);;
|
||||||
if (!c)
|
if (!c)
|
||||||
|
@ -891,13 +931,15 @@ ResponseCode Server_ProtocolHandler::cmdSetCounter(Command_SetCounter *cmd, Comm
|
||||||
return RespOk;
|
return RespOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdDelCounter(Command_DelCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
ResponseCode Server_ProtocolHandler::cmdDelCounter(Command_DelCounter *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player)
|
||||||
{
|
{
|
||||||
if (player->getSpectator())
|
if (player->getSpectator())
|
||||||
return RespFunctionNotAllowed;
|
return RespFunctionNotAllowed;
|
||||||
|
|
||||||
if (!game->getGameStarted())
|
if (!game->getGameStarted())
|
||||||
return RespGameNotStarted;
|
return RespGameNotStarted;
|
||||||
|
if (player->getConceded())
|
||||||
|
return RespContextError;
|
||||||
|
|
||||||
if (!player->deleteCounter(cmd->getCounterId()))
|
if (!player->deleteCounter(cmd->getCounterId()))
|
||||||
return RespNameNotFound;
|
return RespNameNotFound;
|
||||||
|
@ -905,25 +947,29 @@ ResponseCode Server_ProtocolHandler::cmdDelCounter(Command_DelCounter *cmd, Comm
|
||||||
return RespOk;
|
return RespOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdNextTurn(Command_NextTurn * /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
ResponseCode Server_ProtocolHandler::cmdNextTurn(Command_NextTurn * /*cmd*/, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player)
|
||||||
{
|
{
|
||||||
if (player->getSpectator())
|
if (player->getSpectator())
|
||||||
return RespFunctionNotAllowed;
|
return RespFunctionNotAllowed;
|
||||||
|
|
||||||
if (!game->getGameStarted())
|
if (!game->getGameStarted())
|
||||||
return RespGameNotStarted;
|
return RespGameNotStarted;
|
||||||
|
if (player->getConceded())
|
||||||
|
return RespContextError;
|
||||||
|
|
||||||
game->nextTurn();
|
game->nextTurn();
|
||||||
return RespOk;
|
return RespOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdSetActivePhase(Command_SetActivePhase *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
ResponseCode Server_ProtocolHandler::cmdSetActivePhase(Command_SetActivePhase *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player)
|
||||||
{
|
{
|
||||||
if (player->getSpectator())
|
if (player->getSpectator())
|
||||||
return RespFunctionNotAllowed;
|
return RespFunctionNotAllowed;
|
||||||
|
|
||||||
if (!game->getGameStarted())
|
if (!game->getGameStarted())
|
||||||
return RespGameNotStarted;
|
return RespGameNotStarted;
|
||||||
|
if (player->getConceded())
|
||||||
|
return RespContextError;
|
||||||
|
|
||||||
if (game->getActivePlayer() != player->getPlayerId())
|
if (game->getActivePlayer() != player->getPlayerId())
|
||||||
return RespContextError;
|
return RespContextError;
|
||||||
|
@ -981,10 +1027,12 @@ ResponseCode Server_ProtocolHandler::cmdDumpZone(Command_DumpZone *cmd, CommandC
|
||||||
return RespNothing;
|
return RespNothing;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdStopDumpZone(Command_StopDumpZone *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
ResponseCode Server_ProtocolHandler::cmdStopDumpZone(Command_StopDumpZone *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player)
|
||||||
{
|
{
|
||||||
if (!game->getGameStarted())
|
if (!game->getGameStarted())
|
||||||
return RespGameNotStarted;
|
return RespGameNotStarted;
|
||||||
|
if (player->getConceded())
|
||||||
|
return RespContextError;
|
||||||
|
|
||||||
Server_Player *otherPlayer = game->getPlayer(cmd->getPlayerId());
|
Server_Player *otherPlayer = game->getPlayer(cmd->getPlayerId());
|
||||||
if (!otherPlayer)
|
if (!otherPlayer)
|
||||||
|
@ -1007,6 +1055,8 @@ ResponseCode Server_ProtocolHandler::cmdRevealCards(Command_RevealCards *cmd, Co
|
||||||
|
|
||||||
if (!game->getGameStarted())
|
if (!game->getGameStarted())
|
||||||
return RespGameNotStarted;
|
return RespGameNotStarted;
|
||||||
|
if (player->getConceded())
|
||||||
|
return RespContextError;
|
||||||
|
|
||||||
Server_Player *otherPlayer = 0;
|
Server_Player *otherPlayer = 0;
|
||||||
if (cmd->getPlayerId() != -1) {
|
if (cmd->getPlayerId() != -1) {
|
||||||
|
|
Loading…
Reference in a new issue