From b0b58ca7bd4e90754fd416f8475946c8b8dd84c9 Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Wed, 13 Oct 2010 20:08:10 +0200 Subject: [PATCH] server crash fix; protocol response fix --- common/protocol.cpp | 1 + common/protocol.h | 2 +- common/server_protocolhandler.cpp | 31 +++++++++++++++---------------- servatrice/servatrice.ini.example | 1 + 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/common/protocol.cpp b/common/protocol.cpp index dac2c55c..c957692f 100644 --- a/common/protocol.cpp +++ b/common/protocol.cpp @@ -206,6 +206,7 @@ ProtocolResponse::ProtocolResponse(int _cmdId, ResponseCode _responseCode, const void ProtocolResponse::initializeHash() { + responseHash.insert(QString(), RespNothing); responseHash.insert("ok", RespOk); responseHash.insert("invalid_command", RespInvalidCommand); responseHash.insert("name_not_found", RespNameNotFound); diff --git a/common/protocol.h b/common/protocol.h index 53532e6e..e60a7162 100644 --- a/common/protocol.h +++ b/common/protocol.h @@ -194,7 +194,7 @@ class ProtocolResponse : public ProtocolItem { private: static QHash responseHash; public: - ProtocolResponse(int _cmdId = -1, ResponseCode _responseCode = RespOk, const QString &_itemName = QString()); + ProtocolResponse(int _cmdId = -1, ResponseCode _responseCode = RespNothing, const QString &_itemName = QString()); int getItemId() const { return ItemId_Other; } static void initializeHash(); static SerializableItem *newItem() { return new ProtocolResponse; } diff --git a/common/server_protocolhandler.cpp b/common/server_protocolhandler.cpp index 283df98d..56645dfc 100644 --- a/common/server_protocolhandler.cpp +++ b/common/server_protocolhandler.cpp @@ -583,12 +583,27 @@ ResponseCode Server_ProtocolHandler::moveCard(Server_Game *game, Server_Player * return RespNameNotFound; if (startzone != targetzone) { + // Delete all attachment relationships if (card->getParentCard()) card->setParentCard(0); const QList &attachedCards = card->getAttachedCards(); for (int i = 0; i < attachedCards.size(); ++i) unattachCard(game, attachedCards[i]->getZone()->getPlayer(), cont, attachedCards[i]); + + // Delete all arrows from and to the card + const QList &players = game->getPlayers().values(); + for (int i = 0; i < players.size(); ++i) { + QList arrowsToDelete; + QMapIterator arrowIterator(players[i]->getArrows()); + while (arrowIterator.hasNext()) { + Server_Arrow *arrow = arrowIterator.next().value(); + if ((arrow->getStartCard() == card) || (arrow->getTargetItem() == card)) + arrowsToDelete.append(arrow->getId()); + } + for (int j = 0; j < arrowsToDelete.size(); ++j) + players[i]->deleteArrow(arrowsToDelete[j]); + } } if (card->getDestroyOnZoneChange() && (startzone != targetzone)) { @@ -659,22 +674,6 @@ ResponseCode Server_ProtocolHandler::moveCard(Server_Game *game, Server_Player * if (tapped) setCardAttrHelper(cont, game, player, targetzone->getName(), card->getId(), "tapped", "1"); - // If the card was moved to another zone, delete all arrows from and to the card - if (startzone != targetzone) { - const QList &players = game->getPlayers().values(); - for (int i = 0; i < players.size(); ++i) { - QList arrowsToDelete; - QMapIterator arrowIterator(players[i]->getArrows()); - while (arrowIterator.hasNext()) { - Server_Arrow *arrow = arrowIterator.next().value(); - if ((arrow->getStartCard() == card) || (arrow->getTargetItem() == card)) - arrowsToDelete.append(arrow->getId()); - } - for (int j = 0; j < arrowsToDelete.size(); ++j) - players[i]->deleteArrow(arrowsToDelete[j]); - } - } - return RespOk; } diff --git a/servatrice/servatrice.ini.example b/servatrice/servatrice.ini.example index 1a8f0ac6..e75d0c45 100644 --- a/servatrice/servatrice.ini.example +++ b/servatrice/servatrice.ini.example @@ -6,6 +6,7 @@ method=none [database] type=none +prefix=cockatrice hostname=localhost database=servatrice user=servatrice