mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-15 06:52:15 -07:00
Turn things in common into separate libs.
Took 2 hours 27 minutes
This commit is contained in:
parent
53d80efab8
commit
01378b8314
389 changed files with 336 additions and 233 deletions
183
libs/server/include/game/server_abstract_participant.h
Normal file
183
libs/server/include/game/server_abstract_participant.h
Normal file
|
|
@ -0,0 +1,183 @@
|
|||
#ifndef ABSTRACT_PARTICIPANT_H
|
||||
#define ABSTRACT_PARTICIPANT_H
|
||||
|
||||
#include "../serverinfo_user_container.h"
|
||||
#include "pb/card_attributes.pb.h"
|
||||
#include "pb/response.pb.h"
|
||||
#include "server_arrowtarget.h"
|
||||
|
||||
#include <QMutex>
|
||||
|
||||
class Server_Game;
|
||||
class Server_AbstractUserInterface;
|
||||
class ServerInfo_User;
|
||||
class ServerInfo_Player;
|
||||
class ServerInfo_PlayerProperties;
|
||||
class GameEventContainer;
|
||||
class GameEventStorage;
|
||||
class ResponseContainer;
|
||||
class GameCommand;
|
||||
|
||||
class Command_KickFromGame;
|
||||
class Command_LeaveGame;
|
||||
class Command_GameSay;
|
||||
class Command_Shuffle;
|
||||
class Command_Mulligan;
|
||||
class Command_RollDie;
|
||||
class Command_DrawCards;
|
||||
class Command_UndoDraw;
|
||||
class Command_FlipCard;
|
||||
class Command_AttachCard;
|
||||
class Command_CreateToken;
|
||||
class Command_CreateArrow;
|
||||
class Command_DeleteArrow;
|
||||
class Command_SetCardAttr;
|
||||
class Command_SetCardCounter;
|
||||
class Command_IncCardCounter;
|
||||
class Command_ReadyStart;
|
||||
class Command_Concede;
|
||||
class Command_Unconcede;
|
||||
class Command_Judge;
|
||||
class Command_IncCounter;
|
||||
class Command_CreateCounter;
|
||||
class Command_SetCounter;
|
||||
class Command_DelCounter;
|
||||
class Command_NextTurn;
|
||||
class Command_SetActivePhase;
|
||||
class Command_DumpZone;
|
||||
class Command_RevealCards;
|
||||
class Command_ReverseTurn;
|
||||
class Command_MoveCard;
|
||||
class Command_SetSideboardPlan;
|
||||
class Command_DeckSelect;
|
||||
class Command_SetSideboardLock;
|
||||
class Command_ChangeZoneProperties;
|
||||
|
||||
class Server_AbstractParticipant : public Server_ArrowTarget, public ServerInfo_User_Container
|
||||
{
|
||||
Q_OBJECT
|
||||
protected:
|
||||
Server_Game *game;
|
||||
Server_AbstractUserInterface *userInterface;
|
||||
int pingTime;
|
||||
int playerId;
|
||||
bool spectator;
|
||||
bool judge;
|
||||
virtual void getPlayerProperties(ServerInfo_PlayerProperties &result);
|
||||
mutable QMutex playerMutex;
|
||||
|
||||
public:
|
||||
Server_AbstractParticipant(Server_Game *_game,
|
||||
int _playerId,
|
||||
const ServerInfo_User &_userInfo,
|
||||
bool _judge,
|
||||
Server_AbstractUserInterface *_handler);
|
||||
~Server_AbstractParticipant() override;
|
||||
virtual void prepareDestroy()
|
||||
{
|
||||
removeFromGame();
|
||||
};
|
||||
void removeFromGame();
|
||||
Server_AbstractUserInterface *getUserInterface() const
|
||||
{
|
||||
return userInterface;
|
||||
}
|
||||
void setUserInterface(Server_AbstractUserInterface *_userInterface);
|
||||
void disconnectClient();
|
||||
|
||||
int getPlayerId() const
|
||||
{
|
||||
return playerId;
|
||||
}
|
||||
bool getSpectator() const
|
||||
{
|
||||
return spectator;
|
||||
}
|
||||
bool getJudge() const
|
||||
{
|
||||
return judge;
|
||||
}
|
||||
Server_Game *getGame() const
|
||||
{
|
||||
return game;
|
||||
}
|
||||
int getPingTime() const
|
||||
{
|
||||
return pingTime;
|
||||
}
|
||||
bool updatePingTime();
|
||||
void getProperties(ServerInfo_PlayerProperties &result, bool withUserInfo);
|
||||
|
||||
virtual Response::ResponseCode
|
||||
cmdLeaveGame(const Command_LeaveGame &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode
|
||||
cmdKickFromGame(const Command_KickFromGame &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode cmdConcede(const Command_Concede &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode
|
||||
cmdUnconcede(const Command_Unconcede &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode cmdJudge(const Command_Judge &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode
|
||||
cmdReadyStart(const Command_ReadyStart &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode
|
||||
cmdDeckSelect(const Command_DeckSelect &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode
|
||||
cmdSetSideboardPlan(const Command_SetSideboardPlan &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode
|
||||
cmdSetSideboardLock(const Command_SetSideboardLock &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode cmdGameSay(const Command_GameSay &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode cmdShuffle(const Command_Shuffle &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode
|
||||
cmdMulligan(const Command_Mulligan &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode
|
||||
cmdRollDie(const Command_RollDie &cmd, ResponseContainer &rc, GameEventStorage &ges) const;
|
||||
virtual Response::ResponseCode
|
||||
cmdDrawCards(const Command_DrawCards &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode
|
||||
cmdUndoDraw(const Command_UndoDraw &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode
|
||||
cmdMoveCard(const Command_MoveCard &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode
|
||||
cmdFlipCard(const Command_FlipCard &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode
|
||||
cmdAttachCard(const Command_AttachCard &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode
|
||||
cmdCreateToken(const Command_CreateToken &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode
|
||||
cmdCreateArrow(const Command_CreateArrow &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode
|
||||
cmdDeleteArrow(const Command_DeleteArrow &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode
|
||||
cmdSetCardAttr(const Command_SetCardAttr &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode
|
||||
cmdSetCardCounter(const Command_SetCardCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode
|
||||
cmdIncCardCounter(const Command_IncCardCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode
|
||||
cmdIncCounter(const Command_IncCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode
|
||||
cmdCreateCounter(const Command_CreateCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode
|
||||
cmdSetCounter(const Command_SetCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode
|
||||
cmdDelCounter(const Command_DelCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode
|
||||
cmdNextTurn(const Command_NextTurn &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode
|
||||
cmdSetActivePhase(const Command_SetActivePhase &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode
|
||||
cmdDumpZone(const Command_DumpZone &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode
|
||||
cmdRevealCards(const Command_RevealCards &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode
|
||||
cmdReverseTurn(const Command_ReverseTurn & /*cmd*/, ResponseContainer & /*rc*/, GameEventStorage &ges);
|
||||
virtual Response::ResponseCode
|
||||
cmdChangeZoneProperties(const Command_ChangeZoneProperties &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
|
||||
Response::ResponseCode processGameCommand(const GameCommand &command, ResponseContainer &rc, GameEventStorage &ges);
|
||||
void sendGameEvent(const GameEventContainer &event);
|
||||
|
||||
virtual void
|
||||
getInfo(ServerInfo_Player *info, Server_AbstractParticipant *recipient, bool omniscient, bool withUserInfo);
|
||||
};
|
||||
|
||||
#endif
|
||||
52
libs/server/include/game/server_arrow.h
Normal file
52
libs/server/include/game/server_arrow.h
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#ifndef SERVER_ARROW_H
|
||||
#define SERVER_ARROW_H
|
||||
|
||||
#include "pb/color.pb.h"
|
||||
|
||||
class Server_Card;
|
||||
class Server_ArrowTarget;
|
||||
class ServerInfo_Arrow;
|
||||
|
||||
class Server_Arrow
|
||||
{
|
||||
private:
|
||||
int id;
|
||||
Server_Card *startCard;
|
||||
Server_ArrowTarget *targetItem;
|
||||
color arrowColor;
|
||||
|
||||
public:
|
||||
Server_Arrow(int _id, Server_Card *_startCard, Server_ArrowTarget *_targetItem, const color &_arrowColor);
|
||||
int getId() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
void setId(int _id)
|
||||
{
|
||||
id = _id;
|
||||
}
|
||||
Server_Card *getStartCard() const
|
||||
{
|
||||
return startCard;
|
||||
}
|
||||
void setStartCard(Server_Card *startCard_)
|
||||
{
|
||||
startCard = startCard_;
|
||||
}
|
||||
Server_ArrowTarget *getTargetItem() const
|
||||
{
|
||||
return targetItem;
|
||||
}
|
||||
void setTargetItem(Server_ArrowTarget *targetItem_)
|
||||
{
|
||||
targetItem = targetItem_;
|
||||
}
|
||||
const color &getColor() const
|
||||
{
|
||||
return arrowColor;
|
||||
}
|
||||
|
||||
void getInfo(ServerInfo_Arrow *info);
|
||||
};
|
||||
|
||||
#endif
|
||||
11
libs/server/include/game/server_arrowtarget.h
Normal file
11
libs/server/include/game/server_arrowtarget.h
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#ifndef SERVER_ARROWTARGET_H
|
||||
#define SERVER_ARROWTARGET_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class Server_ArrowTarget : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
};
|
||||
|
||||
#endif
|
||||
227
libs/server/include/game/server_card.h
Normal file
227
libs/server/include/game/server_card.h
Normal file
|
|
@ -0,0 +1,227 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Max-Wilhelm Bruker *
|
||||
* brukie@laptop *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef SERVER_CARD_H
|
||||
#define SERVER_CARD_H
|
||||
|
||||
#include "pb/card_attributes.pb.h"
|
||||
#include "pb/serverinfo_card.pb.h"
|
||||
#include "server_arrowtarget.h"
|
||||
#include "utility/card_ref.h"
|
||||
|
||||
#include <QMap>
|
||||
#include <QString>
|
||||
|
||||
class Server_CardZone;
|
||||
class Event_SetCardCounter;
|
||||
class Event_SetCardAttr;
|
||||
|
||||
class Server_Card : public Server_ArrowTarget
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
Server_CardZone *zone;
|
||||
int id;
|
||||
int coord_x, coord_y;
|
||||
CardRef cardRef;
|
||||
QMap<int, int> counters;
|
||||
bool tapped;
|
||||
bool attacking;
|
||||
bool facedown;
|
||||
QString color;
|
||||
QString ptString;
|
||||
QString annotation;
|
||||
bool destroyOnZoneChange;
|
||||
bool doesntUntap;
|
||||
|
||||
Server_Card *parentCard;
|
||||
QList<Server_Card *> attachedCards;
|
||||
Server_Card *stashedCard;
|
||||
|
||||
public:
|
||||
Server_Card(const CardRef &cardRef, int _id, int _coord_x, int _coord_y, Server_CardZone *_zone = nullptr);
|
||||
~Server_Card() override;
|
||||
|
||||
Server_CardZone *getZone() const
|
||||
{
|
||||
return zone;
|
||||
}
|
||||
void setZone(Server_CardZone *_zone)
|
||||
{
|
||||
zone = _zone;
|
||||
}
|
||||
|
||||
int getId() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
CardRef getCardRef() const
|
||||
{
|
||||
return cardRef;
|
||||
}
|
||||
QString getProviderId() const
|
||||
{
|
||||
return cardRef.providerId;
|
||||
}
|
||||
int getX() const
|
||||
{
|
||||
return coord_x;
|
||||
}
|
||||
int getY() const
|
||||
{
|
||||
return coord_y;
|
||||
}
|
||||
QString getName() const
|
||||
{
|
||||
return cardRef.name;
|
||||
}
|
||||
const QMap<int, int> &getCounters() const
|
||||
{
|
||||
return counters;
|
||||
}
|
||||
int getCounter(int counter_id) const
|
||||
{
|
||||
return counters.value(counter_id, 0);
|
||||
}
|
||||
bool getTapped() const
|
||||
{
|
||||
return tapped;
|
||||
}
|
||||
bool getAttacking() const
|
||||
{
|
||||
return attacking;
|
||||
}
|
||||
bool getFaceDown() const
|
||||
{
|
||||
return facedown;
|
||||
}
|
||||
QString getColor() const
|
||||
{
|
||||
return color;
|
||||
}
|
||||
QString getPT() const
|
||||
{
|
||||
return ptString;
|
||||
}
|
||||
QString getAnnotation() const
|
||||
{
|
||||
return annotation;
|
||||
}
|
||||
bool getDoesntUntap() const
|
||||
{
|
||||
return doesntUntap;
|
||||
}
|
||||
bool getDestroyOnZoneChange() const
|
||||
{
|
||||
return destroyOnZoneChange;
|
||||
}
|
||||
Server_Card *getParentCard() const
|
||||
{
|
||||
return parentCard;
|
||||
}
|
||||
const QList<Server_Card *> &getAttachedCards() const
|
||||
{
|
||||
return attachedCards;
|
||||
}
|
||||
|
||||
void setId(int _id)
|
||||
{
|
||||
id = _id;
|
||||
}
|
||||
void setCoords(int x, int y)
|
||||
{
|
||||
coord_x = x;
|
||||
coord_y = y;
|
||||
}
|
||||
void setCardRef(const CardRef &_cardRef)
|
||||
{
|
||||
cardRef = _cardRef;
|
||||
}
|
||||
void setCounter(int _id, int value, Event_SetCardCounter *event = nullptr);
|
||||
void setTapped(bool _tapped)
|
||||
{
|
||||
tapped = _tapped;
|
||||
}
|
||||
void setAttacking(bool _attacking)
|
||||
{
|
||||
attacking = _attacking;
|
||||
}
|
||||
void setFaceDown(bool _facedown)
|
||||
{
|
||||
facedown = _facedown;
|
||||
}
|
||||
void setColor(const QString &_color)
|
||||
{
|
||||
color = _color;
|
||||
}
|
||||
void setPT(const QString &_pt)
|
||||
{
|
||||
ptString = _pt;
|
||||
}
|
||||
void setAnnotation(const QString &_annotation)
|
||||
{
|
||||
annotation = _annotation;
|
||||
}
|
||||
void setDestroyOnZoneChange(bool _destroy)
|
||||
{
|
||||
destroyOnZoneChange = _destroy;
|
||||
}
|
||||
void setDoesntUntap(bool _doesntUntap)
|
||||
{
|
||||
doesntUntap = _doesntUntap;
|
||||
}
|
||||
void setParentCard(Server_Card *_parentCard);
|
||||
void addAttachedCard(Server_Card *card)
|
||||
{
|
||||
attachedCards.append(card);
|
||||
}
|
||||
void removeAttachedCard(Server_Card *card)
|
||||
{
|
||||
attachedCards.removeOne(card);
|
||||
}
|
||||
void setStashedCard(Server_Card *card)
|
||||
{
|
||||
// setStashedCard should only be called on creation of a new card, so
|
||||
// there should never be an already existing stashed card.
|
||||
Q_ASSERT(!stashedCard);
|
||||
|
||||
// Stashed cards can't themselves have stashed cards, and tokens can't
|
||||
// be stashed.
|
||||
if (card->stashedCard || card->getDestroyOnZoneChange()) {
|
||||
stashedCard = card->takeStashedCard();
|
||||
card->deleteLater();
|
||||
} else {
|
||||
stashedCard = card;
|
||||
}
|
||||
}
|
||||
Server_Card *takeStashedCard()
|
||||
{
|
||||
Server_Card *oldStashedCard = stashedCard;
|
||||
stashedCard = nullptr;
|
||||
return oldStashedCard;
|
||||
}
|
||||
|
||||
void resetState(bool keepAnnotations = false);
|
||||
QString setAttribute(CardAttribute attribute, const QString &avalue, bool allCards);
|
||||
QString setAttribute(CardAttribute attribute, const QString &avalue, Event_SetCardAttr *event = nullptr);
|
||||
|
||||
void getInfo(ServerInfo_Card *info);
|
||||
};
|
||||
|
||||
#endif
|
||||
125
libs/server/include/game/server_cardzone.h
Normal file
125
libs/server/include/game/server_cardzone.h
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Max-Wilhelm Bruker *
|
||||
* brukie@laptop *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef SERVER_CARDZONE_H
|
||||
#define SERVER_CARDZONE_H
|
||||
|
||||
#include "pb/serverinfo_zone.pb.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QSet>
|
||||
#include <QString>
|
||||
|
||||
class Server_Card;
|
||||
class Server_Player;
|
||||
class Server_AbstractParticipant;
|
||||
class Server_Game;
|
||||
class GameEventStorage;
|
||||
|
||||
class Server_CardZone
|
||||
{
|
||||
private:
|
||||
Server_Player *player;
|
||||
QString name;
|
||||
bool has_coords; // having coords means this zone has x and y coordinates
|
||||
ServerInfo_Zone::ZoneType type;
|
||||
int cardsBeingLookedAt;
|
||||
QSet<int> playersWithWritePermission;
|
||||
bool alwaysRevealTopCard;
|
||||
bool alwaysLookAtTopCard;
|
||||
QList<Server_Card *> cards;
|
||||
QMap<int, QMap<int, Server_Card *>> coordinateMap; // y -> (x -> card)
|
||||
QMap<int, QMultiMap<QString, int>> freePilesMap; // y -> (cardName -> x)
|
||||
QMap<int, int> freeSpaceMap; // y -> x
|
||||
void removeCardFromCoordMap(Server_Card *card, int oldX, int oldY);
|
||||
void insertCardIntoCoordMap(Server_Card *card, int x, int y);
|
||||
|
||||
public:
|
||||
Server_CardZone(Server_Player *_player, const QString &_name, bool _has_coords, ServerInfo_Zone::ZoneType _type);
|
||||
~Server_CardZone();
|
||||
|
||||
const QList<Server_Card *> &getCards() const
|
||||
{
|
||||
return cards;
|
||||
}
|
||||
int removeCard(Server_Card *card);
|
||||
int removeCard(Server_Card *card, bool &wasLookedAt);
|
||||
Server_Card *getCard(int id, int *position = nullptr, bool remove = false);
|
||||
|
||||
int getCardsBeingLookedAt() const
|
||||
{
|
||||
return cardsBeingLookedAt;
|
||||
}
|
||||
void setCardsBeingLookedAt(int _cardsBeingLookedAt)
|
||||
{
|
||||
cardsBeingLookedAt = qMax(0, _cardsBeingLookedAt);
|
||||
}
|
||||
bool isCardAtPosLookedAt(int pos) const;
|
||||
bool hasCoords() const
|
||||
{
|
||||
return has_coords;
|
||||
}
|
||||
ServerInfo_Zone::ZoneType getType() const
|
||||
{
|
||||
return type;
|
||||
}
|
||||
QString getName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
Server_Player *getPlayer() const
|
||||
{
|
||||
return player;
|
||||
}
|
||||
void getInfo(ServerInfo_Zone *info, Server_AbstractParticipant *recipient, bool omniscient);
|
||||
|
||||
int getFreeGridColumn(int x, int y, const QString &cardName, bool dontStackSameName) const;
|
||||
bool isColumnEmpty(int x, int y) const;
|
||||
bool isColumnStacked(int x, int y) const;
|
||||
void fixFreeSpaces(GameEventStorage &ges);
|
||||
void moveCardInRow(GameEventStorage &ges, Server_Card *card, int x, int y);
|
||||
void insertCard(Server_Card *card, int x, int y);
|
||||
void updateCardCoordinates(Server_Card *card, int oldX, int oldY);
|
||||
void shuffle(int start = 0, int end = -1);
|
||||
void clear();
|
||||
void addWritePermission(int playerId);
|
||||
const QSet<int> &getPlayersWithWritePermission() const
|
||||
{
|
||||
return playersWithWritePermission;
|
||||
}
|
||||
bool getAlwaysRevealTopCard() const
|
||||
{
|
||||
return alwaysRevealTopCard;
|
||||
}
|
||||
void setAlwaysRevealTopCard(bool _alwaysRevealTopCard)
|
||||
{
|
||||
alwaysRevealTopCard = _alwaysRevealTopCard;
|
||||
}
|
||||
bool getAlwaysLookAtTopCard() const
|
||||
{
|
||||
return alwaysLookAtTopCard;
|
||||
}
|
||||
void setAlwaysLookAtTopCard(bool _alwaysLookAtTopCard)
|
||||
{
|
||||
alwaysLookAtTopCard = _alwaysLookAtTopCard;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
71
libs/server/include/game/server_counter.h
Normal file
71
libs/server/include/game/server_counter.h
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Max-Wilhelm Bruker *
|
||||
* brukie@laptop *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef SERVER_COUNTER_H
|
||||
#define SERVER_COUNTER_H
|
||||
|
||||
#include "pb/color.pb.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
class ServerInfo_Counter;
|
||||
|
||||
class Server_Counter
|
||||
{
|
||||
protected:
|
||||
int id;
|
||||
QString name;
|
||||
color counterColor;
|
||||
int radius;
|
||||
int count;
|
||||
|
||||
public:
|
||||
Server_Counter(int _id, const QString &_name, const color &_counterColor, int _radius, int _count = 0);
|
||||
~Server_Counter()
|
||||
{
|
||||
}
|
||||
int getId() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
QString getName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
const color &getColor() const
|
||||
{
|
||||
return counterColor;
|
||||
}
|
||||
int getRadius() const
|
||||
{
|
||||
return radius;
|
||||
}
|
||||
int getCount() const
|
||||
{
|
||||
return count;
|
||||
}
|
||||
void setCount(int _count)
|
||||
{
|
||||
count = _count;
|
||||
}
|
||||
|
||||
void getInfo(ServerInfo_Counter *info);
|
||||
};
|
||||
|
||||
#endif
|
||||
226
libs/server/include/game/server_game.h
Normal file
226
libs/server/include/game/server_game.h
Normal file
|
|
@ -0,0 +1,226 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Max-Wilhelm Bruker *
|
||||
* brukie@laptop *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef SERVERGAME_H
|
||||
#define SERVERGAME_H
|
||||
|
||||
#include "../server_response_containers.h"
|
||||
#include "pb/event_leave.pb.h"
|
||||
#include "pb/response.pb.h"
|
||||
#include "pb/serverinfo_game.pb.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QMap>
|
||||
#include <QMutex>
|
||||
#include <QObject>
|
||||
#include <QSet>
|
||||
#include <QStringList>
|
||||
|
||||
class QTimer;
|
||||
class GameEventContainer;
|
||||
class GameReplay;
|
||||
class Server_Room;
|
||||
class Server_Player;
|
||||
class Server_AbstractParticipant;
|
||||
class ServerInfo_User;
|
||||
class ServerInfo_Game;
|
||||
class Server_AbstractUserInterface;
|
||||
class Event_GameStateChanged;
|
||||
|
||||
class Server_Game : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
Server_Room *room;
|
||||
int nextPlayerId;
|
||||
int hostId;
|
||||
ServerInfo_User *creatorInfo;
|
||||
QMap<int, Server_AbstractParticipant *> participants;
|
||||
QSet<QString> allPlayersEver, allSpectatorsEver;
|
||||
bool gameStarted;
|
||||
bool gameClosed;
|
||||
int gameId;
|
||||
QString description;
|
||||
QString password;
|
||||
int maxPlayers;
|
||||
QList<int> gameTypes;
|
||||
int activePlayer, activePhase;
|
||||
bool onlyBuddies, onlyRegistered;
|
||||
bool spectatorsAllowed;
|
||||
bool spectatorsNeedPassword;
|
||||
bool spectatorsCanTalk;
|
||||
bool spectatorsSeeEverything;
|
||||
int startingLifeTotal;
|
||||
bool shareDecklistsOnLoad;
|
||||
int inactivityCounter;
|
||||
int startTimeOfThisGame, secondsElapsed;
|
||||
bool firstGameStarted;
|
||||
bool turnOrderReversed;
|
||||
QDateTime startTime;
|
||||
QTimer *pingClock;
|
||||
QList<GameReplay *> replayList;
|
||||
GameReplay *currentReplay;
|
||||
|
||||
void createGameStateChangedEvent(Event_GameStateChanged *event,
|
||||
Server_AbstractParticipant *recipient,
|
||||
bool omniscient,
|
||||
bool withUserInfo);
|
||||
void storeGameInformation();
|
||||
signals:
|
||||
void sigStartGameIfReady(bool override);
|
||||
void gameInfoChanged(ServerInfo_Game gameInfo);
|
||||
private slots:
|
||||
void pingClockTimeout();
|
||||
void doStartGameIfReady(bool forceStartGame = false);
|
||||
|
||||
public:
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
mutable QRecursiveMutex gameMutex;
|
||||
#else
|
||||
mutable QMutex gameMutex;
|
||||
#endif
|
||||
Server_Game(const ServerInfo_User &_creatorInfo,
|
||||
int _gameId,
|
||||
const QString &_description,
|
||||
const QString &_password,
|
||||
int _maxPlayers,
|
||||
const QList<int> &_gameTypes,
|
||||
bool _onlyBuddies,
|
||||
bool _onlyRegistered,
|
||||
bool _spectatorsAllowed,
|
||||
bool _spectatorsNeedPassword,
|
||||
bool _spectatorsCanTalk,
|
||||
bool _spectatorsSeeEverything,
|
||||
int _startingLifeTotal,
|
||||
bool _shareDecklistsOnLoad,
|
||||
Server_Room *parent);
|
||||
~Server_Game() override;
|
||||
Server_Room *getRoom() const
|
||||
{
|
||||
return room;
|
||||
}
|
||||
void getInfo(ServerInfo_Game &result) const;
|
||||
int getHostId() const
|
||||
{
|
||||
return hostId;
|
||||
}
|
||||
ServerInfo_User *getCreatorInfo() const
|
||||
{
|
||||
return creatorInfo;
|
||||
}
|
||||
bool getGameStarted() const
|
||||
{
|
||||
return gameStarted;
|
||||
}
|
||||
int getPlayerCount() const;
|
||||
int getSpectatorCount() const;
|
||||
QMap<int, Server_Player *> getPlayers() const;
|
||||
Server_Player *getPlayer(int id) const;
|
||||
const QMap<int, Server_AbstractParticipant *> &getParticipants() const
|
||||
{
|
||||
return participants;
|
||||
}
|
||||
int getGameId() const
|
||||
{
|
||||
return gameId;
|
||||
}
|
||||
QString getDescription() const
|
||||
{
|
||||
return description;
|
||||
}
|
||||
QString getPassword() const
|
||||
{
|
||||
return password;
|
||||
}
|
||||
int getMaxPlayers() const
|
||||
{
|
||||
return maxPlayers;
|
||||
}
|
||||
bool getSpectatorsAllowed() const
|
||||
{
|
||||
return spectatorsAllowed;
|
||||
}
|
||||
bool getSpectatorsNeedPassword() const
|
||||
{
|
||||
return spectatorsNeedPassword;
|
||||
}
|
||||
bool getSpectatorsCanTalk() const
|
||||
{
|
||||
return spectatorsCanTalk;
|
||||
}
|
||||
bool getSpectatorsSeeEverything() const
|
||||
{
|
||||
return spectatorsSeeEverything;
|
||||
}
|
||||
int getStartingLifeTotal() const
|
||||
{
|
||||
return startingLifeTotal;
|
||||
}
|
||||
bool getShareDecklistsOnLoad() const
|
||||
{
|
||||
return shareDecklistsOnLoad;
|
||||
}
|
||||
Response::ResponseCode
|
||||
checkJoin(ServerInfo_User *user, const QString &_password, bool spectator, bool overrideRestrictions, bool asJudge);
|
||||
bool containsUser(const QString &userName) const;
|
||||
void addPlayer(Server_AbstractUserInterface *userInterface,
|
||||
ResponseContainer &rc,
|
||||
bool spectator,
|
||||
bool judge,
|
||||
bool broadcastUpdate = true);
|
||||
void removeParticipant(Server_AbstractParticipant *participant, Event_Leave::LeaveReason reason);
|
||||
void removeArrowsRelatedToPlayer(GameEventStorage &ges, Server_Player *player);
|
||||
void unattachCards(GameEventStorage &ges, Server_Player *player);
|
||||
bool kickParticipant(int playerId);
|
||||
void startGameIfReady(bool forceStartGame);
|
||||
void stopGameIfFinished();
|
||||
int getActivePlayer() const
|
||||
{
|
||||
return activePlayer;
|
||||
}
|
||||
int getActivePhase() const
|
||||
{
|
||||
return activePhase;
|
||||
}
|
||||
void setActivePlayer(int _activePlayer);
|
||||
void setActivePhase(int _activePhase);
|
||||
void nextTurn();
|
||||
int getSecondsElapsed() const
|
||||
{
|
||||
return secondsElapsed;
|
||||
}
|
||||
bool reverseTurnOrder()
|
||||
{
|
||||
return turnOrderReversed = !turnOrderReversed;
|
||||
}
|
||||
|
||||
void createGameJoinedEvent(Server_AbstractParticipant *participant, ResponseContainer &rc, bool resuming);
|
||||
|
||||
GameEventContainer *
|
||||
prepareGameEvent(const ::google::protobuf::Message &gameEvent, int playerId, GameEventContext *context = 0);
|
||||
GameEventContext prepareGameEventContext(const ::google::protobuf::Message &gameEventContext);
|
||||
|
||||
void sendGameStateToPlayers();
|
||||
void sendGameEventContainer(GameEventContainer *cont,
|
||||
GameEventStorageItem::EventRecipients recipients = GameEventStorageItem::SendToPrivate |
|
||||
GameEventStorageItem::SendToOthers,
|
||||
int privatePlayerId = -1);
|
||||
};
|
||||
|
||||
#endif
|
||||
178
libs/server/include/game/server_player.h
Normal file
178
libs/server/include/game/server_player.h
Normal file
|
|
@ -0,0 +1,178 @@
|
|||
#ifndef PLAYER_H
|
||||
#define PLAYER_H
|
||||
|
||||
#include "../serverinfo_user_container.h"
|
||||
#include "server_abstract_participant.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QString>
|
||||
|
||||
class DeckList;
|
||||
class Server_CardZone;
|
||||
class Server_Counter;
|
||||
class Server_Arrow;
|
||||
class Server_Card;
|
||||
class CardToMove;
|
||||
|
||||
class Server_Player : public Server_AbstractParticipant
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
class MoveCardCompareFunctor;
|
||||
DeckList *deck;
|
||||
QMap<QString, Server_CardZone *> zones;
|
||||
QMap<int, Server_Counter *> counters;
|
||||
QMap<int, Server_Arrow *> arrows;
|
||||
QList<int> lastDrawList;
|
||||
int nextCardId;
|
||||
bool readyStart;
|
||||
bool conceded;
|
||||
bool sideboardLocked;
|
||||
void revealTopCardIfNeeded(Server_CardZone *zone, GameEventStorage &ges);
|
||||
void sendCreateTokenEvents(Server_CardZone *zone, Server_Card *card, int xCoord, int yCoord, GameEventStorage &ges);
|
||||
void getPlayerProperties(ServerInfo_PlayerProperties &result) override;
|
||||
|
||||
public:
|
||||
Server_Player(Server_Game *_game,
|
||||
int _playerId,
|
||||
const ServerInfo_User &_userInfo,
|
||||
bool _judge,
|
||||
Server_AbstractUserInterface *_handler);
|
||||
~Server_Player() override;
|
||||
void prepareDestroy() override;
|
||||
const DeckList *getDeckList() const
|
||||
{
|
||||
return deck;
|
||||
}
|
||||
bool getReadyStart() const
|
||||
{
|
||||
return readyStart;
|
||||
}
|
||||
void setReadyStart(bool _readyStart)
|
||||
{
|
||||
readyStart = _readyStart;
|
||||
}
|
||||
bool getConceded() const
|
||||
{
|
||||
return conceded;
|
||||
}
|
||||
void setConceded(bool _conceded)
|
||||
{
|
||||
conceded = _conceded;
|
||||
}
|
||||
|
||||
const QMap<QString, Server_CardZone *> &getZones() const
|
||||
{
|
||||
return zones;
|
||||
}
|
||||
const QMap<int, Server_Counter *> &getCounters() const
|
||||
{
|
||||
return counters;
|
||||
}
|
||||
const QMap<int, Server_Arrow *> &getArrows() const
|
||||
{
|
||||
return arrows;
|
||||
}
|
||||
|
||||
int newCardId();
|
||||
int newCounterId() const;
|
||||
int newArrowId() const;
|
||||
|
||||
void addZone(Server_CardZone *zone);
|
||||
void addArrow(Server_Arrow *arrow);
|
||||
void updateArrowId(int id);
|
||||
bool deleteArrow(int arrowId);
|
||||
void addCounter(Server_Counter *counter);
|
||||
|
||||
void clearZones();
|
||||
void setupZones();
|
||||
|
||||
Response::ResponseCode drawCards(GameEventStorage &ges, int number);
|
||||
Response::ResponseCode moveCard(GameEventStorage &ges,
|
||||
Server_CardZone *startzone,
|
||||
const QList<const CardToMove *> &_cards,
|
||||
Server_CardZone *targetzone,
|
||||
int xCoord,
|
||||
int yCoord,
|
||||
bool fixFreeSpaces = true,
|
||||
bool undoingDraw = false,
|
||||
bool isReversed = false);
|
||||
void unattachCard(GameEventStorage &ges, Server_Card *card);
|
||||
Response::ResponseCode setCardAttrHelper(GameEventStorage &ges,
|
||||
int targetPlayerId,
|
||||
const QString &zone,
|
||||
int cardId,
|
||||
CardAttribute attribute,
|
||||
const QString &attrValue,
|
||||
Server_Card *unzonedCard = nullptr);
|
||||
|
||||
Response::ResponseCode
|
||||
cmdConcede(const Command_Concede &cmd, ResponseContainer &rc, GameEventStorage &ges) override;
|
||||
Response::ResponseCode
|
||||
cmdUnconcede(const Command_Unconcede &cmd, ResponseContainer &rc, GameEventStorage &ges) override;
|
||||
Response::ResponseCode
|
||||
cmdReadyStart(const Command_ReadyStart &cmd, ResponseContainer &rc, GameEventStorage &ges) override;
|
||||
Response::ResponseCode
|
||||
cmdDeckSelect(const Command_DeckSelect &cmd, ResponseContainer &rc, GameEventStorage &ges) override;
|
||||
Response::ResponseCode
|
||||
cmdSetSideboardPlan(const Command_SetSideboardPlan &cmd, ResponseContainer &rc, GameEventStorage &ges) override;
|
||||
Response::ResponseCode
|
||||
cmdSetSideboardLock(const Command_SetSideboardLock &cmd, ResponseContainer &rc, GameEventStorage &ges) override;
|
||||
Response::ResponseCode
|
||||
cmdShuffle(const Command_Shuffle &cmd, ResponseContainer &rc, GameEventStorage &ges) override;
|
||||
Response::ResponseCode
|
||||
cmdMulligan(const Command_Mulligan &cmd, ResponseContainer &rc, GameEventStorage &ges) override;
|
||||
Response::ResponseCode
|
||||
cmdRollDie(const Command_RollDie &cmd, ResponseContainer &rc, GameEventStorage &ges) const override;
|
||||
Response::ResponseCode
|
||||
cmdDrawCards(const Command_DrawCards &cmd, ResponseContainer &rc, GameEventStorage &ges) override;
|
||||
Response::ResponseCode
|
||||
cmdUndoDraw(const Command_UndoDraw &cmd, ResponseContainer &rc, GameEventStorage &ges) override;
|
||||
Response::ResponseCode
|
||||
cmdMoveCard(const Command_MoveCard &cmd, ResponseContainer &rc, GameEventStorage &ges) override;
|
||||
Response::ResponseCode
|
||||
cmdFlipCard(const Command_FlipCard &cmd, ResponseContainer &rc, GameEventStorage &ges) override;
|
||||
Response::ResponseCode
|
||||
cmdAttachCard(const Command_AttachCard &cmd, ResponseContainer &rc, GameEventStorage &ges) override;
|
||||
Response::ResponseCode
|
||||
cmdCreateToken(const Command_CreateToken &cmd, ResponseContainer &rc, GameEventStorage &ges) override;
|
||||
Response::ResponseCode
|
||||
cmdCreateArrow(const Command_CreateArrow &cmd, ResponseContainer &rc, GameEventStorage &ges) override;
|
||||
Response::ResponseCode
|
||||
cmdDeleteArrow(const Command_DeleteArrow &cmd, ResponseContainer &rc, GameEventStorage &ges) override;
|
||||
Response::ResponseCode
|
||||
cmdSetCardAttr(const Command_SetCardAttr &cmd, ResponseContainer &rc, GameEventStorage &ges) override;
|
||||
Response::ResponseCode
|
||||
cmdSetCardCounter(const Command_SetCardCounter &cmd, ResponseContainer &rc, GameEventStorage &ges) override;
|
||||
Response::ResponseCode
|
||||
cmdIncCardCounter(const Command_IncCardCounter &cmd, ResponseContainer &rc, GameEventStorage &ges) override;
|
||||
Response::ResponseCode
|
||||
cmdIncCounter(const Command_IncCounter &cmd, ResponseContainer &rc, GameEventStorage &ges) override;
|
||||
Response::ResponseCode
|
||||
cmdCreateCounter(const Command_CreateCounter &cmd, ResponseContainer &rc, GameEventStorage &ges) override;
|
||||
Response::ResponseCode
|
||||
cmdSetCounter(const Command_SetCounter &cmd, ResponseContainer &rc, GameEventStorage &ges) override;
|
||||
Response::ResponseCode
|
||||
cmdDelCounter(const Command_DelCounter &cmd, ResponseContainer &rc, GameEventStorage &ges) override;
|
||||
Response::ResponseCode
|
||||
cmdNextTurn(const Command_NextTurn &cmd, ResponseContainer &rc, GameEventStorage &ges) override;
|
||||
Response::ResponseCode
|
||||
cmdSetActivePhase(const Command_SetActivePhase &cmd, ResponseContainer &rc, GameEventStorage &ges) override;
|
||||
Response::ResponseCode
|
||||
cmdDumpZone(const Command_DumpZone &cmd, ResponseContainer &rc, GameEventStorage &ges) override;
|
||||
Response::ResponseCode
|
||||
cmdRevealCards(const Command_RevealCards &cmd, ResponseContainer &rc, GameEventStorage &ges) override;
|
||||
Response::ResponseCode
|
||||
cmdReverseTurn(const Command_ReverseTurn & /*cmd*/, ResponseContainer & /*rc*/, GameEventStorage &ges) override;
|
||||
Response::ResponseCode cmdChangeZoneProperties(const Command_ChangeZoneProperties &cmd,
|
||||
ResponseContainer &rc,
|
||||
GameEventStorage &ges) override;
|
||||
|
||||
void getInfo(ServerInfo_Player *info,
|
||||
Server_AbstractParticipant *playerWhosAsking,
|
||||
bool omniscient,
|
||||
bool withUserInfo) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
17
libs/server/include/game/server_spectator.h
Normal file
17
libs/server/include/game/server_spectator.h
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef SPECTATOR_H
|
||||
#define SPECTATOR_H
|
||||
|
||||
#include "server_abstract_participant.h"
|
||||
|
||||
class Server_Spectator : public Server_AbstractParticipant
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Server_Spectator(Server_Game *_game,
|
||||
int _playerId,
|
||||
const ServerInfo_User &_userInfo,
|
||||
bool _judge,
|
||||
Server_AbstractUserInterface *_handler);
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue