mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-01 11:03:54 -07:00
small cleanups
This commit is contained in:
parent
890740bcc9
commit
fa16d86283
27 changed files with 616 additions and 497 deletions
|
|
@ -1,13 +1,10 @@
|
|||
#ifndef CLIENT_H
|
||||
#define CLIENT_H
|
||||
|
||||
#include "servereventdata.h"
|
||||
#include "servergame.h"
|
||||
#include "serverplayer.h"
|
||||
#include "serverzone.h"
|
||||
#include "serverzonecard.h"
|
||||
#include <QTcpSocket>
|
||||
#include <QColor>
|
||||
#include <QStringList>
|
||||
#include <QHash>
|
||||
|
||||
class QTimer;
|
||||
|
||||
|
|
@ -27,25 +24,242 @@ enum ServerResponse {
|
|||
RespErr
|
||||
};
|
||||
|
||||
enum ServerEventType {
|
||||
eventInvalid,
|
||||
eventPlayerId,
|
||||
eventSay,
|
||||
eventName,
|
||||
eventJoin,
|
||||
eventLeave,
|
||||
eventReadyStart,
|
||||
eventSetupZones,
|
||||
eventGameStart,
|
||||
eventShuffle,
|
||||
eventRollDie,
|
||||
eventDraw,
|
||||
eventMoveCard,
|
||||
eventCreateToken,
|
||||
eventSetCardAttr,
|
||||
eventAddCounter,
|
||||
eventSetCounter,
|
||||
eventDelCounter,
|
||||
eventSetActivePlayer,
|
||||
eventSetActivePhase,
|
||||
eventDumpZone,
|
||||
eventStopDumpZone
|
||||
};
|
||||
|
||||
class ServerEventData {
|
||||
private:
|
||||
static QHash<QString, ServerEventType> eventHash;
|
||||
|
||||
bool IsPublic;
|
||||
int PlayerId;
|
||||
QString PlayerName;
|
||||
ServerEventType EventType;
|
||||
QStringList EventData;
|
||||
public:
|
||||
ServerEventData(const QString &line);
|
||||
bool getPublic() const { return IsPublic; }
|
||||
int getPlayerId() const { return PlayerId; }
|
||||
const QString &getPlayerName() const { return PlayerName; }
|
||||
ServerEventType getEventType() const { return EventType; }
|
||||
const QStringList &getEventData() const { return EventData; }
|
||||
};
|
||||
|
||||
enum ChatEventType {
|
||||
eventChatInvalid,
|
||||
eventChatListChannels,
|
||||
eventChatJoinChannel,
|
||||
eventChatListPlayers,
|
||||
eventChatLeaveChannel,
|
||||
eventChatSay,
|
||||
eventChatServerMessage
|
||||
};
|
||||
|
||||
class ChatEventData {
|
||||
private:
|
||||
static QHash<QString, ChatEventType> eventHash;
|
||||
|
||||
ChatEventType eventType;
|
||||
QStringList eventData;
|
||||
public:
|
||||
ChatEventData(const QString &line);
|
||||
ChatEventType getEventType() const { return eventType; }
|
||||
const QStringList &getEventData() const { return eventData; }
|
||||
};
|
||||
|
||||
class ServerGame {
|
||||
private:
|
||||
int gameId;
|
||||
QString creator;
|
||||
QString description;
|
||||
bool hasPassword;
|
||||
unsigned char playerCount;
|
||||
unsigned char maxPlayers;
|
||||
bool spectatorsAllowed;
|
||||
unsigned int spectatorsCount;
|
||||
public:
|
||||
ServerGame(int _gameId, const QString &_creator, const QString &_description, bool _hasPassword, unsigned char _playerCount, unsigned char _maxPlayers, bool _spectatorsAllowed, unsigned int _spectatorsCount)
|
||||
: gameId(_gameId), creator(_creator), description(_description), hasPassword(_hasPassword), playerCount(_playerCount), maxPlayers(_maxPlayers), spectatorsAllowed(_spectatorsAllowed), spectatorsCount(_spectatorsCount) { }
|
||||
int getGameId() const { return gameId; }
|
||||
QString getCreator() const { return creator; }
|
||||
QString getDescription() const { return description; }
|
||||
bool getHasPassword() const { return hasPassword; }
|
||||
unsigned char getPlayerCount() const { return playerCount; }
|
||||
unsigned char getMaxPlayers() const { return maxPlayers; }
|
||||
bool getSpectatorsAllowed() const { return spectatorsAllowed; }
|
||||
unsigned int getSpectatorsCount() const { return spectatorsCount; }
|
||||
};
|
||||
|
||||
class ServerPlayer {
|
||||
private:
|
||||
int PlayerId;
|
||||
QString name;
|
||||
bool local;
|
||||
public:
|
||||
ServerPlayer(int _PlayerId, const QString &_name, bool _local)
|
||||
: PlayerId(_PlayerId), name(_name), local(_local) { }
|
||||
int getPlayerId() const { return PlayerId; }
|
||||
QString getName() const { return name; }
|
||||
bool getLocal() const { return local; }
|
||||
};
|
||||
|
||||
class ServerZoneCard {
|
||||
private:
|
||||
int id;
|
||||
QString name;
|
||||
int x, y;
|
||||
int counters;
|
||||
bool tapped;
|
||||
bool attacking;
|
||||
QString annotation;
|
||||
public:
|
||||
ServerZoneCard(int _id, const QString &_name, int _x, int _y, int _counters, bool _tapped, bool _attacking, const QString &_annotation)
|
||||
: id(_id), name(_name), x(_x), y(_y), counters(_counters), tapped(_tapped), attacking(_attacking), annotation(_annotation) { }
|
||||
int getId() const { return id; }
|
||||
QString getName() const { return name; }
|
||||
int getX() const { return x; }
|
||||
int getY() const { return y; }
|
||||
int getCounters() const { return counters; }
|
||||
bool getTapped() const { return tapped; }
|
||||
bool getAttacking() const { return attacking; }
|
||||
QString getAnnotation() const { return annotation; }
|
||||
};
|
||||
|
||||
class ServerZone {
|
||||
private:
|
||||
QString name;
|
||||
bool isPublic;
|
||||
bool hasCoords;
|
||||
int cardCount;
|
||||
public:
|
||||
ServerZone(const QString &_name, bool _isPublic, bool _hasCoords, int _cardCount)
|
||||
: name(_name), isPublic(_isPublic), hasCoords(_hasCoords), cardCount(_cardCount) { }
|
||||
QString getName() const { return name; }
|
||||
bool getPublic() const { return isPublic; }
|
||||
bool getHasCoords() const { return hasCoords; }
|
||||
int getCardCount() const { return cardCount; }
|
||||
};
|
||||
|
||||
class ServerCounter {
|
||||
private:
|
||||
QString name;
|
||||
int color;
|
||||
int count;
|
||||
public:
|
||||
ServerCounter(const QString &_name, int _color, int _count)
|
||||
: name(_name), color(_color), count(_count) { }
|
||||
QString getName() const { return name; }
|
||||
int getColor() const { return color; }
|
||||
int getCount() const { return count; }
|
||||
};
|
||||
|
||||
class PendingCommand : public QObject {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QString cmd;
|
||||
int msgid;
|
||||
int time;
|
||||
QString extraData;
|
||||
signals:
|
||||
void finished(ServerResponse resp);
|
||||
void timeout();
|
||||
public slots:
|
||||
void responseReceived(int _msgid, ServerResponse _resp);
|
||||
virtual void responseReceived(ServerResponse resp);
|
||||
void checkTimeout();
|
||||
public:
|
||||
PendingCommand(int _msgid = -1);
|
||||
int getMsgId() const { return msgid; }
|
||||
QString getCmd() const { return cmd; }
|
||||
const QString &getExtraData() const { return extraData; }
|
||||
void setExtraData(const QString &_extraData) { extraData = _extraData; }
|
||||
PendingCommand(const QString &_cmd, int _msgid, QObject *parent = 0);
|
||||
void setMsgId(int _msgId) { msgid = _msgId; }
|
||||
};
|
||||
|
||||
class PendingCommand_ChatJoinChannel : public PendingCommand {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QString channelName;
|
||||
public:
|
||||
PendingCommand_ChatJoinChannel(const QString &_channelName)
|
||||
: channelName(_channelName) { }
|
||||
const QString &getChannelName() const { return channelName; }
|
||||
};
|
||||
|
||||
class PendingCommand_ListPlayers : public PendingCommand {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QList<ServerPlayer> playerList;
|
||||
signals:
|
||||
void playerListReceived(QList<ServerPlayer> _playerList);
|
||||
public:
|
||||
void responseReceived(ServerResponse resp);
|
||||
void addPlayer(const ServerPlayer &player);
|
||||
};
|
||||
|
||||
class PendingCommand_ListZones : public PendingCommand {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QList<ServerZone> zoneList;
|
||||
int playerId;
|
||||
signals:
|
||||
void zoneListReceived(QList<ServerZone> _zoneList);
|
||||
public:
|
||||
PendingCommand_ListZones(int _playerId)
|
||||
: playerId(_playerId) { }
|
||||
void responseReceived(ServerResponse resp);
|
||||
void addZone(const ServerZone &zone);
|
||||
int getPlayerId() const { return playerId; }
|
||||
};
|
||||
|
||||
class PendingCommand_DumpZone : public PendingCommand {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QList<ServerZoneCard> cardList;
|
||||
int playerId;
|
||||
QString zoneName;
|
||||
int numberCards;
|
||||
signals:
|
||||
void cardListReceived(QList<ServerZoneCard> _cardList);
|
||||
public:
|
||||
PendingCommand_DumpZone(int _playerId, const QString &_zoneName, int _numberCards)
|
||||
: playerId(_playerId), zoneName(_zoneName), numberCards(_numberCards) { }
|
||||
void responseReceived(ServerResponse resp);
|
||||
void addCard(const ServerZoneCard &card);
|
||||
int getPlayerId() const { return playerId; }
|
||||
QString getZoneName() const { return zoneName; }
|
||||
int getNumberCards() const { return numberCards; }
|
||||
};
|
||||
|
||||
class PendingCommand_ListCounters : public PendingCommand {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QList<ServerCounter> counterList;
|
||||
int playerId;
|
||||
signals:
|
||||
void counterListReceived(QList<ServerCounter> _counterList);
|
||||
public:
|
||||
PendingCommand_ListCounters(int _playerId)
|
||||
: playerId(_playerId) { }
|
||||
void responseReceived(ServerResponse resp);
|
||||
void addCounter(const ServerCounter &counter);
|
||||
int getPlayerId() const { return playerId; }
|
||||
};
|
||||
|
||||
class Client : public QObject {
|
||||
|
|
@ -54,10 +268,6 @@ signals:
|
|||
void statusChanged(ProtocolStatus _status);
|
||||
void welcomeMsgReceived(QString welcomeMsg);
|
||||
void gameListEvent(ServerGame *game);
|
||||
void playerListReceived(QList<ServerPlayer *> players);
|
||||
void zoneListReceived(int commandId, QList<ServerZone *> zones);
|
||||
void zoneDumpReceived(int commandId, QList<ServerZoneCard *> cards);
|
||||
void responseReceived(int msgid, ServerResponse resp);
|
||||
void playerIdReceived(int id, QString name);
|
||||
void gameEvent(const ServerEventData &msg);
|
||||
void chatEvent(const ChatEventData &msg);
|
||||
|
|
@ -65,6 +275,7 @@ signals:
|
|||
void logSocketError(const QString &errorString);
|
||||
void serverError(ServerResponse resp);
|
||||
void protocolVersionMismatch();
|
||||
void protocolError();
|
||||
private slots:
|
||||
void slotConnected();
|
||||
void readLine();
|
||||
|
|
@ -78,14 +289,13 @@ private slots:
|
|||
private:
|
||||
static const int protocolVersion = 1;
|
||||
QTimer *timer;
|
||||
QList<PendingCommand *> PendingCommands;
|
||||
QMap<int, PendingCommand *> pendingCommands;
|
||||
QTcpSocket *socket;
|
||||
ProtocolStatus status;
|
||||
QList<QStringList> msgbuf;
|
||||
QString playerName, password;
|
||||
unsigned int MsgId;
|
||||
void msg(const QString &s);
|
||||
PendingCommand *cmd(const QString &s);
|
||||
PendingCommand *cmd(const QString &s, PendingCommand *_pc = 0);
|
||||
void setStatus(const ProtocolStatus _status);
|
||||
public:
|
||||
Client(QObject *parent = 0);
|
||||
|
|
@ -97,11 +307,11 @@ public:
|
|||
void disconnectFromServer();
|
||||
public slots:
|
||||
PendingCommand *chatListChannels();
|
||||
PendingCommand *chatJoinChannel(const QString &name);
|
||||
PendingCommand_ChatJoinChannel *chatJoinChannel(const QString &name);
|
||||
PendingCommand *chatLeaveChannel(const QString &name);
|
||||
PendingCommand *chatSay(const QString &name, const QString &s);
|
||||
PendingCommand *listGames();
|
||||
PendingCommand *listPlayers();
|
||||
PendingCommand_ListPlayers *listPlayers();
|
||||
PendingCommand *createGame(const QString &description, const QString &password, unsigned int maxPlayers, bool spectatorsAllowed);
|
||||
PendingCommand *joinGame(int gameId, const QString &password, bool spectator);
|
||||
PendingCommand *leaveGame();
|
||||
|
|
@ -119,9 +329,11 @@ public slots:
|
|||
PendingCommand *addCounter(const QString &counter, QColor color, int value);
|
||||
PendingCommand *setCounter(const QString &counter, int value);
|
||||
PendingCommand *delCounter(const QString &counter);
|
||||
PendingCommand_ListCounters *listCounters(int playerId);
|
||||
PendingCommand *nextTurn();
|
||||
PendingCommand *setActivePhase(int phase);
|
||||
PendingCommand *dumpZone(int player, const QString &zone, int numberCards);
|
||||
PendingCommand_ListZones *listZones(int playerId);
|
||||
PendingCommand_DumpZone *dumpZone(int player, const QString &zone, int numberCards);
|
||||
PendingCommand *stopDumpZone(int player, const QString &zone);
|
||||
void submitDeck(const QStringList &deck);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue