server crash fix; protocol response fix
This commit is contained in:
parent
970da7d214
commit
b0b58ca7bd
4 changed files with 18 additions and 17 deletions
|
@ -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);
|
||||
|
|
|
@ -194,7 +194,7 @@ class ProtocolResponse : public ProtocolItem {
|
|||
private:
|
||||
static QHash<QString, ResponseCode> 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; }
|
||||
|
|
|
@ -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<Server_Card *> &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<Server_Player *> &players = game->getPlayers().values();
|
||||
for (int i = 0; i < players.size(); ++i) {
|
||||
QList<int> arrowsToDelete;
|
||||
QMapIterator<int, Server_Arrow *> 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<Server_Player *> &players = game->getPlayers().values();
|
||||
for (int i = 0; i < players.size(); ++i) {
|
||||
QList<int> arrowsToDelete;
|
||||
QMapIterator<int, Server_Arrow *> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ method=none
|
|||
|
||||
[database]
|
||||
type=none
|
||||
prefix=cockatrice
|
||||
hostname=localhost
|
||||
database=servatrice
|
||||
user=servatrice
|
||||
|
|
Loading…
Reference in a new issue