mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 00:24:47 -07:00
filter running games; minor server code cleanup
This commit is contained in:
parent
9727a38956
commit
898623f1ba
24 changed files with 369 additions and 289 deletions
|
|
@ -40,7 +40,7 @@ ServerInfo_UserList::ServerInfo_UserList(const QString &_itemType, const QList<S
|
|||
itemList.append(_userList[i]);
|
||||
}
|
||||
|
||||
ServerInfo_Game::ServerInfo_Game(int _roomId, int _gameId, const QString &_description, bool _hasPassword, int _playerCount, int _maxPlayers, const QList<GameTypeId *> &_gameTypes, ServerInfo_User *_creatorInfo, bool _onlyBuddies, bool _onlyRegistered, bool _spectatorsAllowed, bool _spectatorsNeedPassword, int _spectatorCount)
|
||||
ServerInfo_Game::ServerInfo_Game(int _roomId, int _gameId, const QString &_description, bool _hasPassword, int _playerCount, int _maxPlayers, bool _started, const QList<GameTypeId *> &_gameTypes, ServerInfo_User *_creatorInfo, bool _onlyBuddies, bool _onlyRegistered, bool _spectatorsAllowed, bool _spectatorsNeedPassword, int _spectatorCount)
|
||||
: SerializableItem_Map("game")
|
||||
{
|
||||
insertItem(new SerializableItem_Int("room_id", _roomId));
|
||||
|
|
@ -49,6 +49,7 @@ ServerInfo_Game::ServerInfo_Game(int _roomId, int _gameId, const QString &_descr
|
|||
insertItem(new SerializableItem_Bool("has_password", _hasPassword));
|
||||
insertItem(new SerializableItem_Int("player_count", _playerCount));
|
||||
insertItem(new SerializableItem_Int("max_players", _maxPlayers));
|
||||
insertItem(new SerializableItem_Bool("started", _started));
|
||||
if (!_creatorInfo)
|
||||
_creatorInfo = new ServerInfo_User;
|
||||
insertItem(_creatorInfo);
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ public:
|
|||
|
||||
class ServerInfo_Game : public SerializableItem_Map {
|
||||
public:
|
||||
ServerInfo_Game(int _roomId = -1, int _gameId = -1, const QString &_description = QString(), bool _hasPassword = false, int _playerCount = -1, int _maxPlayers = -1, const QList<GameTypeId *> &_gameTypes = QList<GameTypeId *>(), ServerInfo_User *creatorInfo = 0, bool _onlyBuddies = false, bool _onlyRegistered = false, bool _spectatorsAllowed = false, bool _spectatorsNeedPassword = false, int _spectatorCount = -1);
|
||||
ServerInfo_Game(int _roomId = -1, int _gameId = -1, const QString &_description = QString(), bool _hasPassword = false, int _playerCount = -1, int _maxPlayers = -1, bool _started = false, const QList<GameTypeId *> &_gameTypes = QList<GameTypeId *>(), ServerInfo_User *creatorInfo = 0, bool _onlyBuddies = false, bool _onlyRegistered = false, bool _spectatorsAllowed = false, bool _spectatorsNeedPassword = false, int _spectatorCount = -1);
|
||||
static SerializableItem *newItem() { return new ServerInfo_Game; }
|
||||
int getRoomId() const { return static_cast<SerializableItem_Int *>(itemMap.value("room_id"))->getData(); }
|
||||
int getGameId() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->getData(); }
|
||||
|
|
@ -77,6 +77,7 @@ public:
|
|||
bool getHasPassword() const { return static_cast<SerializableItem_Bool *>(itemMap.value("has_password"))->getData(); }
|
||||
int getPlayerCount() const { return static_cast<SerializableItem_Int *>(itemMap.value("player_count"))->getData(); }
|
||||
int getMaxPlayers() const { return static_cast<SerializableItem_Int *>(itemMap.value("max_players"))->getData(); }
|
||||
bool getStarted() const { return static_cast<SerializableItem_Bool *>(itemMap.value("started"))->getData(); }
|
||||
QList<GameTypeId *> getGameTypes() const { return typecastItemList<GameTypeId *>(); }
|
||||
ServerInfo_User *getCreatorInfo() const { return static_cast<ServerInfo_User *>(itemMap.value("user")); }
|
||||
bool getOnlyBuddies() const { return static_cast<SerializableItem_Bool *>(itemMap.value("only_buddies"))->getData(); }
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@
|
|||
***************************************************************************/
|
||||
#include "server_card.h"
|
||||
|
||||
Server_Card::Server_Card(QString _name, int _id, int _coord_x, int _coord_y)
|
||||
: id(_id), coord_x(_coord_x), coord_y(_coord_y), name(_name), tapped(false), attacking(false), facedown(false), color(QString()), power(-1), toughness(-1), annotation(QString()), destroyOnZoneChange(false), doesntUntap(false), parentCard(0)
|
||||
Server_Card::Server_Card(QString _name, int _id, int _coord_x, int _coord_y, Server_CardZone *_zone)
|
||||
: zone(_zone), id(_id), coord_x(_coord_x), coord_y(_coord_y), name(_name), tapped(false), attacking(false), facedown(false), color(QString()), power(-1), toughness(-1), annotation(QString()), destroyOnZoneChange(false), doesntUntap(false), parentCard(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ private:
|
|||
Server_Card *parentCard;
|
||||
QList<Server_Card *> attachedCards;
|
||||
public:
|
||||
Server_Card(QString _name, int _id, int _coord_x, int _coord_y);
|
||||
Server_Card(QString _name, int _id, int _coord_x, int _coord_y, Server_CardZone *_zone = 0);
|
||||
~Server_Card();
|
||||
|
||||
Server_CardZone *getZone() const { return zone; }
|
||||
|
|
|
|||
|
|
@ -52,10 +52,12 @@ int Server_CardZone::removeCard(Server_Card *card)
|
|||
|
||||
int index = cards.indexOf(card);
|
||||
cards.removeAt(index);
|
||||
card->setZone(0);
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
Server_Card *Server_CardZone::getCard(int id, bool remove, int *position)
|
||||
Server_Card *Server_CardZone::getCard(int id, int *position)
|
||||
{
|
||||
QMutexLocker locker(&player->getGame()->gameMutex);
|
||||
|
||||
|
|
@ -65,10 +67,6 @@ Server_Card *Server_CardZone::getCard(int id, bool remove, int *position)
|
|||
while (CardIterator.hasNext()) {
|
||||
Server_Card *tmp = CardIterator.next();
|
||||
if (tmp->getId() == id) {
|
||||
if (remove) {
|
||||
cards.removeAt(i);
|
||||
tmp->setZone(0);
|
||||
}
|
||||
if (position)
|
||||
*position = i;
|
||||
return tmp;
|
||||
|
|
@ -80,10 +78,6 @@ Server_Card *Server_CardZone::getCard(int id, bool remove, int *position)
|
|||
if ((id >= cards.size()) || (id < 0))
|
||||
return NULL;
|
||||
Server_Card *tmp = cards[id];
|
||||
if (remove) {
|
||||
cards.removeAt(id);
|
||||
tmp->setZone(0);
|
||||
}
|
||||
if (position)
|
||||
*position = id;
|
||||
return tmp;
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ public:
|
|||
~Server_CardZone();
|
||||
|
||||
int removeCard(Server_Card *card);
|
||||
Server_Card *getCard(int id, bool remove, int *position = NULL);
|
||||
Server_Card *getCard(int id, int *position = NULL);
|
||||
|
||||
int getCardsBeingLookedAt() const { return cardsBeingLookedAt; }
|
||||
void setCardsBeingLookedAt(int _cardsBeingLookedAt) { cardsBeingLookedAt = _cardsBeingLookedAt; }
|
||||
|
|
|
|||
|
|
@ -160,6 +160,8 @@ void Server_Game::doStartGameIfReady()
|
|||
*/
|
||||
activePlayer = -1;
|
||||
nextTurn();
|
||||
|
||||
room->broadcastGameListUpdate(this);
|
||||
}
|
||||
|
||||
void Server_Game::startGameIfReady()
|
||||
|
|
@ -490,7 +492,7 @@ ServerInfo_Game *Server_Game::getInfo() const
|
|||
|
||||
if (players.isEmpty())
|
||||
// Game is closing
|
||||
return new ServerInfo_Game(room->getId(), getGameId(), QString(), false, 0, getMaxPlayers(), QList<GameTypeId *>(), 0, false, 0);
|
||||
return new ServerInfo_Game(room->getId(), getGameId(), QString(), false, 0, getMaxPlayers(), false, QList<GameTypeId *>(), 0, false, 0);
|
||||
else {
|
||||
// Game is open
|
||||
|
||||
|
|
@ -505,6 +507,7 @@ ServerInfo_Game *Server_Game::getInfo() const
|
|||
!getPassword().isEmpty(),
|
||||
getPlayerCount(),
|
||||
getMaxPlayers(),
|
||||
gameStarted,
|
||||
gameTypeList,
|
||||
new ServerInfo_User(getCreatorInfo(), false),
|
||||
onlyBuddies,
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ void Server_Player::setupZones()
|
|||
if (!currentCard)
|
||||
continue;
|
||||
for (int k = 0; k < currentCard->getNumber(); ++k)
|
||||
z->cards.append(new Server_Card(currentCard->getName(), nextCardId++, 0, 0));
|
||||
z->cards.append(new Server_Card(currentCard->getName(), nextCardId++, 0, 0, z));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -334,7 +334,7 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st
|
|||
QMap<Server_Card *, CardToMove *> cardProperties;
|
||||
for (int i = 0; i < _cards.size(); ++i) {
|
||||
int position;
|
||||
Server_Card *card = startzone->getCard(_cards[i]->getCardId(), false, &position);
|
||||
Server_Card *card = startzone->getCard(_cards[i]->getCardId(), &position);
|
||||
if (!card)
|
||||
return RespNameNotFound;
|
||||
if (!card->getAttachedCards().isEmpty() && !targetzone->isColumnEmpty(x, y))
|
||||
|
|
@ -510,7 +510,7 @@ ResponseCode Server_Player::setCardAttrHelper(CommandContainer *cont, const QStr
|
|||
return RespInvalidCommand;
|
||||
}
|
||||
} else {
|
||||
Server_Card *card = zone->getCard(cardId, false);
|
||||
Server_Card *card = zone->getCard(cardId);
|
||||
if (!card)
|
||||
return RespNameNotFound;
|
||||
result = card->setAttribute(attrName, attrValue, false);
|
||||
|
|
|
|||
|
|
@ -768,7 +768,7 @@ ResponseCode Server_ProtocolHandler::cmdFlipCard(Command_FlipCard *cmd, CommandC
|
|||
if (!zone->hasCoords())
|
||||
return RespContextError;
|
||||
|
||||
Server_Card *card = zone->getCard(cmd->getCardId(), false);
|
||||
Server_Card *card = zone->getCard(cmd->getCardId());
|
||||
if (!card)
|
||||
return RespNameNotFound;
|
||||
|
||||
|
|
@ -797,7 +797,7 @@ ResponseCode Server_ProtocolHandler::cmdAttachCard(Command_AttachCard *cmd, Comm
|
|||
if (!startzone)
|
||||
return RespNameNotFound;
|
||||
|
||||
Server_Card *card = startzone->getCard(cmd->getCardId(), false);
|
||||
Server_Card *card = startzone->getCard(cmd->getCardId());
|
||||
if (!card)
|
||||
return RespNameNotFound;
|
||||
|
||||
|
|
@ -819,7 +819,7 @@ ResponseCode Server_ProtocolHandler::cmdAttachCard(Command_AttachCard *cmd, Comm
|
|||
// Possibly a flag will have to be introduced for this sometime.
|
||||
if (!targetzone->hasCoords())
|
||||
return RespContextError;
|
||||
targetCard = targetzone->getCard(cmd->getTargetCardId(), false);
|
||||
targetCard = targetzone->getCard(cmd->getTargetCardId());
|
||||
if (targetCard)
|
||||
if (targetCard->getParentCard())
|
||||
return RespContextError;
|
||||
|
|
@ -929,14 +929,14 @@ ResponseCode Server_ProtocolHandler::cmdCreateArrow(Command_CreateArrow *cmd, Co
|
|||
return RespNameNotFound;
|
||||
if (startZone->getType() != PublicZone)
|
||||
return RespContextError;
|
||||
Server_Card *startCard = startZone->getCard(cmd->getStartCardId(), false);
|
||||
Server_Card *startCard = startZone->getCard(cmd->getStartCardId());
|
||||
if (!startCard)
|
||||
return RespNameNotFound;
|
||||
Server_Card *targetCard = 0;
|
||||
if (!playerTarget) {
|
||||
if (targetZone->getType() != PublicZone)
|
||||
return RespContextError;
|
||||
targetCard = targetZone->getCard(cmd->getTargetCardId(), false);
|
||||
targetCard = targetZone->getCard(cmd->getTargetCardId());
|
||||
}
|
||||
|
||||
Server_ArrowTarget *targetItem;
|
||||
|
|
@ -1015,7 +1015,7 @@ ResponseCode Server_ProtocolHandler::cmdSetCardCounter(Command_SetCardCounter *c
|
|||
if (!zone->hasCoords())
|
||||
return RespContextError;
|
||||
|
||||
Server_Card *card = zone->getCard(cmd->getCardId(), false);
|
||||
Server_Card *card = zone->getCard(cmd->getCardId());
|
||||
if (!card)
|
||||
return RespNameNotFound;
|
||||
|
||||
|
|
@ -1042,7 +1042,7 @@ ResponseCode Server_ProtocolHandler::cmdIncCardCounter(Command_IncCardCounter *c
|
|||
if (!zone->hasCoords())
|
||||
return RespContextError;
|
||||
|
||||
Server_Card *card = zone->getCard(cmd->getCardId(), false);
|
||||
Server_Card *card = zone->getCard(cmd->getCardId());
|
||||
if (!card)
|
||||
return RespNameNotFound;
|
||||
|
||||
|
|
@ -1255,7 +1255,7 @@ ResponseCode Server_ProtocolHandler::cmdRevealCards(Command_RevealCards *cmd, Co
|
|||
return RespContextError;
|
||||
cardsToReveal.append(zone->cards.at(rng->getNumber(0, zone->cards.size() - 1)));
|
||||
} else {
|
||||
Server_Card *card = zone->getCard(cmd->getCardId(), false);
|
||||
Server_Card *card = zone->getCard(cmd->getCardId());
|
||||
if (!card)
|
||||
return RespNameNotFound;
|
||||
cardsToReveal.append(card);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue