everything compiles again; enough for today

This commit is contained in:
Max-Wilhelm Bruker 2009-11-12 00:09:24 +01:00
parent dd5ae4d74d
commit cb0e4d07e4
29 changed files with 340 additions and 766 deletions

View file

@ -1,11 +1,12 @@
TEMPLATE = app
TARGET =
DEPENDPATH += . src
INCLUDEPATH += . src
DEPENDPATH += . src ../common
INCLUDEPATH += . src ../common
MOC_DIR = build
OBJECTS_DIR = build
RESOURCES = cockatrice.qrc
QT += network svg
HEADERS += src/counter.h \
src/gameselector.h \
src/dlg_creategame.h \
@ -41,7 +42,11 @@ HEADERS += src/counter.h \
src/phasestoolbar.h \
src/chatwidget.h \
src/gamescene.h \
src/arrowitem.h
src/arrowitem.h \
../common/protocol.h \
../common/protocol_items.h \
../common/protocol_datastructures.h
SOURCES += src/counter.cpp \
src/gameselector.cpp \
src/dlg_creategame.cpp \
@ -78,6 +83,9 @@ SOURCES += src/counter.cpp \
src/phasestoolbar.cpp \
src/chatwidget.cpp \
src/gamescene.cpp \
src/arrowitem.cpp
src/arrowitem.cpp \
../common/protocol.cpp \
../common/protocol_items.cpp
TRANSLATIONS += translations/cockatrice_de.ts translations/cockatrice_en.ts
CONFIG += qt debug

View file

@ -128,7 +128,7 @@ void ChatWidget::disableChat()
channelList->clear();
hide();
}
/*
void ChatWidget::chatEvent(const ChatEventData &data)
{
const QStringList &msg = data.getEventData();
@ -209,11 +209,11 @@ void ChatWidget::chatEvent(const ChatEventData &data)
}
}
}
*/
void ChatWidget::joinChannel(const QString &channelName)
{
PendingCommand_ChatJoinChannel *pc = client->chatJoinChannel(channelName);
connect(pc, SIGNAL(finished(ServerResponse)), this, SLOT(joinFinished(ServerResponse)));
// PendingCommand_ChatJoinChannel *pc = client->chatJoinChannel(channelName);
// connect(pc, SIGNAL(finished(ServerResponse)), this, SLOT(joinFinished(ServerResponse)));
}
void ChatWidget::joinClicked()
@ -228,15 +228,15 @@ void ChatWidget::joinClicked()
joinChannel(channelName);
}
void ChatWidget::joinFinished(ServerResponse resp)
void ChatWidget::joinFinished(ResponseCode resp)
{
if (resp != RespOk)
return;
PendingCommand_ChatJoinChannel *pc = qobject_cast<PendingCommand_ChatJoinChannel *>(sender());
QString channelName = pc->getChannelName();
ChannelWidget *cw = new ChannelWidget(client, channelName);
tab->addTab(cw, channelName);
// PendingCommand_ChatJoinChannel *pc = qobject_cast<PendingCommand_ChatJoinChannel *>(sender());
// QString channelName = pc->getChannelName();
// ChannelWidget *cw = new ChannelWidget(client, channelName);
// tab->addTab(cw, channelName);
}
ChannelWidget *ChatWidget::getChannel(const QString &name)

View file

@ -2,7 +2,7 @@
#define CHATWIDGET_H
#include <QWidget>
#include "client.h"
#include "protocol_datastructures.h"
class QListWidget;
class QTextEdit;
@ -10,6 +10,7 @@ class QLineEdit;
class QTreeWidget;
class QTabWidget;
class QPushButton;
class Client;
class ChannelWidget : public QWidget {
Q_OBJECT
@ -45,9 +46,9 @@ private:
ChannelWidget *getChannel(const QString &name);
void joinChannel(const QString &channelName);
private slots:
void chatEvent(const ChatEventData &data);
// void chatEvent(const ChatEventData &data);
void joinClicked();
void joinFinished(ServerResponse resp);
void joinFinished(ResponseCode resp);
public:
ChatWidget(Client *_client, QWidget *parent = 0);
void retranslateUi();

View file

@ -1,132 +1,26 @@
#include <QTimer>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include "client.h"
// Message structure for server events:
// {"private","public"}|PlayerId|PlayerName|EventType|EventData
QHash<QString, ServerEventType> ServerEventData::eventHash;
ServerEventData::ServerEventData(const QString &line)
{
if (eventHash.isEmpty()) {
eventHash.insert("say", eventSay);
eventHash.insert("join", eventJoin);
eventHash.insert("leave", eventLeave);
eventHash.insert("game_closed", eventGameClosed);
eventHash.insert("ready_start", eventReadyStart);
eventHash.insert("setup_zones", eventSetupZones);
eventHash.insert("game_start", eventGameStart);
eventHash.insert("shuffle", eventShuffle);
eventHash.insert("roll_die", eventRollDie);
eventHash.insert("draw", eventDraw);
eventHash.insert("move_card", eventMoveCard);
eventHash.insert("create_token", eventCreateToken);
eventHash.insert("create_arrow", eventCreateArrow);
eventHash.insert("delete_arrow", eventDeleteArrow);
eventHash.insert("set_card_attr", eventSetCardAttr);
eventHash.insert("add_counter", eventAddCounter);
eventHash.insert("set_counter", eventSetCounter);
eventHash.insert("del_counter", eventDelCounter);
eventHash.insert("set_active_player", eventSetActivePlayer);
eventHash.insert("set_active_phase", eventSetActivePhase);
eventHash.insert("dump_zone", eventDumpZone);
eventHash.insert("stop_dump_zone", eventStopDumpZone);
}
QStringList values = line.split('|');
IsPublic = !values.takeFirst().compare("public");
bool ok = false;
PlayerId = values.takeFirst().toInt(&ok);
if (!ok)
PlayerId = -1;
PlayerName = values.takeFirst();
EventType = eventHash.value(values.takeFirst(), eventInvalid);
EventData = values;
}
QHash<QString, ChatEventType> ChatEventData::eventHash;
ChatEventData::ChatEventData(const QString &line)
{
if (eventHash.isEmpty()) {
eventHash.insert("list_channels", eventChatListChannels);
eventHash.insert("join_channel", eventChatJoinChannel);
eventHash.insert("list_players", eventChatListPlayers);
eventHash.insert("leave_channel", eventChatLeaveChannel);
eventHash.insert("say", eventChatSay);
eventHash.insert("server_message", eventChatServerMessage);
}
QStringList values = line.split('|');
values.removeFirst();
eventType = eventHash.value(values.takeFirst(), eventChatInvalid);
eventData = values;
}
PendingCommand::PendingCommand(int _msgid)
: QObject(), msgid(_msgid), time(0)
{
}
void PendingCommand::responseReceived(ServerResponse resp)
{
emit finished(resp);
deleteLater();
}
void PendingCommand_ListPlayers::responseReceived(ServerResponse resp)
{
if (resp == RespOk)
emit playerListReceived(playerList);
PendingCommand::responseReceived(resp);
}
void PendingCommand_ListZones::responseReceived(ServerResponse resp)
{
if (resp == RespOk)
emit zoneListReceived(zoneList);
PendingCommand::responseReceived(resp);
}
void PendingCommand_DumpZone::responseReceived(ServerResponse resp)
{
if (resp == RespOk)
emit cardListReceived(cardList);
PendingCommand::responseReceived(resp);
}
void PendingCommand_ListCounters::responseReceived(ServerResponse resp)
{
if (resp == RespOk)
emit counterListReceived(counterList);
PendingCommand::responseReceived(resp);
}
void PendingCommand_DumpAll::responseReceived(ServerResponse resp)
{
if (resp == RespOk) {
emit playerListReceived(playerList);
emit zoneListReceived(zoneList);
emit cardListReceived(cardList);
emit counterListReceived(counterList);
emit arrowListReceived(arrowList);
}
PendingCommand::responseReceived(resp);
}
#include "protocol.h"
#include "protocol_items.h"
Client::Client(QObject *parent)
: QObject(parent), status(StatusDisconnected), MsgId(0)
: QObject(parent), currentItem(0), status(StatusDisconnected)
{
timer = new QTimer(this);
timer->setInterval(1000);
connect(timer, SIGNAL(timeout()), this, SLOT(ping()));
socket = new QTcpSocket(this);
socket->setTextModeEnabled(true);
connect(socket, SIGNAL(connected()), this, SLOT(slotConnected()));
connect(socket, SIGNAL(readyRead()), this, SLOT(readLine()));
connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slotSocketError(QAbstractSocket::SocketError)));
xmlReader = new QXmlStreamReader;
xmlWriter = new QXmlStreamWriter;
xmlWriter->setAutoFormatting(true);
xmlWriter->setDevice(socket);
}
Client::~Client()
@ -148,9 +42,9 @@ void Client::slotConnected()
void Client::removePendingCommand()
{
pendingCommands.remove(static_cast<PendingCommand *>(sender())->getMsgId());
pendingCommands.remove(static_cast<Command *>(sender())->getCmdId());
}
/*
void Client::loginResponse(ServerResponse response)
{
if (response == RespOk)
@ -172,9 +66,40 @@ void Client::leaveGameResponse(ServerResponse response)
if (response == RespOk)
setStatus(StatusIdle);
}
void Client::readLine()
*/
void Client::readData()
{
xmlReader->addData(socket->readAll());
if (currentItem) {
if (!currentItem->read(xmlReader))
return;
currentItem = 0;
}
while (!xmlReader->atEnd()) {
xmlReader->readNext();
if (xmlReader->isStartElement()) {
QString itemType = xmlReader->name().toString();
if (itemType == "cockatrice_server_stream")
continue;
QString itemName = xmlReader->attributes().value("name").toString();
qDebug() << "parseXml: startElement: " << "type =" << itemType << ", name =" << itemName;
currentItem = ProtocolItem::getNewItem(itemType + itemName);
if (!currentItem)
continue;
if (!currentItem->read(xmlReader))
return;
else {
/* Command *command = qobject_cast<Command *>(currentItem);
if (qobject_cast<InvalidCommand *>(command))
sendProtocolItem(new ProtocolResponse(command->getCmdId(), ProtocolResponse::RespInvalidCommand));
else
processCommand(command);
currentItem = 0;
*/ }
}
}
/*
while (socket->canReadLine()) {
QString line = QString(socket->readLine()).trimmed();
@ -337,25 +262,17 @@ void Client::readLine()
} else
emit protocolError();
}
*/
}
void Client::setStatus(const ProtocolStatus _status)
void Client::setStatus(const ClientStatus _status)
{
if (_status != status) {
status = _status;
emit statusChanged(_status);
}
}
void Client::msg(const QString &s)
{
qDebug(QString(">> %1").arg(s).toLatin1());
QTextStream stream(socket);
stream.setCodec("UTF-8");
stream << s << endl;
stream.flush();
}
/*
PendingCommand *Client::cmd(const QString &s, PendingCommand *_pc)
{
msg(QString("%1|%2").arg(++MsgId).arg(s));
@ -369,7 +286,7 @@ PendingCommand *Client::cmd(const QString &s, PendingCommand *_pc)
connect(pc, SIGNAL(finished(ServerResponse)), this, SLOT(removePendingCommand()));
return pc;
}
*/
void Client::connectToServer(const QString &hostname, unsigned int port, const QString &_playerName, const QString &_password)
{
disconnectFromServer();
@ -382,9 +299,12 @@ void Client::connectToServer(const QString &hostname, unsigned int port, const Q
void Client::disconnectFromServer()
{
currentItem = 0;
xmlReader->clear();
timer->stop();
QList<PendingCommand *> pc = pendingCommands.values();
QList<Command *> pc = pendingCommands.values();
for (int i = 0; i < pc.size(); i++)
delete pc[i];
pendingCommands.clear();
@ -396,7 +316,7 @@ void Client::disconnectFromServer()
void Client::ping()
{
int maxTime = 0;
QMapIterator<int, PendingCommand *> i(pendingCommands);
QMapIterator<int, Command *> i(pendingCommands);
while (i.hasNext()) {
int time = i.next().value()->tick();
if (time > maxTime)
@ -406,10 +326,12 @@ void Client::ping()
if (maxTime >= maxTimeout) {
emit serverTimeout();
disconnectFromServer();
} else
}
/* else
cmd("ping");
*/
}
/*
PendingCommand *Client::chatListChannels()
{
return cmd("chat_list_channels");
@ -601,3 +523,4 @@ int Client::colorToNumber(const QColor &color) const
{
return color.red() * 65536 + color.green() * 256 + color.blue();
}
*/

View file

@ -7,410 +7,97 @@
#include <QHash>
class QTimer;
class Command;
class QXmlStreamReader;
class QXmlStreamWriter;
class ProtocolItem;
// Connection state.
// The protocol handler itself is stateless once the connection
// has been established.
enum ProtocolStatus { StatusDisconnected,
enum ClientStatus {
StatusDisconnected,
StatusConnecting,
StatusAwaitingWelcome,
StatusLoggingIn,
StatusIdle,
StatusPlaying };
enum ServerResponse {
RespOk,
RespNameNotFound,
RespLoginNeeded,
RespSyntaxError,
RespContextError,
RespPasswordWrong,
RespSpectatorsNotAllowed,
RespInvalid
};
enum ServerEventType {
eventInvalid,
eventSay,
eventJoin,
eventLeave,
eventGameClosed,
eventReadyStart,
eventSetupZones,
eventGameStart,
eventShuffle,
eventRollDie,
eventDraw,
eventMoveCard,
eventCreateToken,
eventCreateArrow,
eventDeleteArrow,
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 = -1, const QString &_creator = QString(), const QString &_description = QString(), bool _hasPassword = false, unsigned char _playerCount = 0, unsigned char _maxPlayers = 0, bool _spectatorsAllowed = false, unsigned int _spectatorsCount = 0)
: 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 playerId;
QString zoneName;
int id;
QString name;
int x, y;
int counters;
bool tapped;
bool attacking;
QString annotation;
public:
ServerZoneCard(int _playerId, const QString &_zoneName, int _id, const QString &_name, int _x, int _y, int _counters, bool _tapped, bool _attacking, const QString &_annotation)
: playerId(_playerId), zoneName(_zoneName), id(_id), name(_name), x(_x), y(_y), counters(_counters), tapped(_tapped), attacking(_attacking), annotation(_annotation) { }
int getPlayerId() const { return playerId; }
QString getZoneName() const { return zoneName; }
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 {
public:
enum ZoneType { PrivateZone, PublicZone, HiddenZone };
private:
int playerId;
QString name;
ZoneType type;
bool hasCoords;
int cardCount;
public:
ServerZone(int _playerId, const QString &_name, ZoneType _type, bool _hasCoords, int _cardCount)
: playerId(_playerId), name(_name), type(_type), hasCoords(_hasCoords), cardCount(_cardCount) { }
int getPlayerId() const { return playerId; }
QString getName() const { return name; }
ZoneType getType() const { return type; }
bool getHasCoords() const { return hasCoords; }
int getCardCount() const { return cardCount; }
};
class ServerCounter {
private:
int playerId;
int id;
QString name;
QColor color;
int radius;
int count;
public:
ServerCounter(int _playerId, int _id, const QString &_name, QColor _color, int _radius, int _count)
: playerId(_playerId), id(_id), name(_name), color(_color), radius(_radius), count(_count) { }
int getPlayerId() const { return playerId; }
int getId() const { return id; }
QString getName() const { return name; }
QColor getColor() const { return color; }
int getRadius() const { return radius; }
int getCount() const { return count; }
};
class ServerArrow {
private:
int id;
int playerId;
int startPlayerId;
QString startZone;
int startCardId;
int targetPlayerId;
QString targetZone;
int targetCardId;
QColor color;
public:
ServerArrow(int _playerId, int _id, int _startPlayerId, const QString &_startZone, int _startCardId, int _targetPlayerId, const QString &_targetZone, int _targetCardId, const QColor &_color)
: id(_id), playerId(_playerId), startPlayerId(_startPlayerId), startZone(_startZone), startCardId(_startCardId), targetPlayerId(_targetPlayerId), targetZone(_targetZone), targetCardId(_targetCardId), color(_color) { }
int getId() const { return id; }
int getPlayerId() const { return playerId; }
int getStartPlayerId() const { return startPlayerId; }
QString getStartZone() const { return startZone; }
int getStartCardId() const { return startCardId; }
int getTargetPlayerId() const { return targetPlayerId; }
QString getTargetZone() const { return targetZone; }
int getTargetCardId() const { return targetCardId; }
QColor getColor() const { return color; }
};
class PendingCommand : public QObject {
Q_OBJECT
private:
int msgid;
int time;
signals:
void finished(ServerResponse resp);
public slots:
virtual void responseReceived(ServerResponse resp);
public:
PendingCommand(int _msgid = -1);
int tick() { return ++time; }
int getMsgId() const { return msgid; }
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) { playerList.append(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) { zoneList.append(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) { cardList.append(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) { counterList.append(counter); }
int getPlayerId() const { return playerId; }
};
class PendingCommand_DumpAll : public PendingCommand {
Q_OBJECT
private:
QList<ServerPlayer> playerList;
QList<ServerZone> zoneList;
QList<ServerZoneCard> cardList;
QList<ServerCounter> counterList;
QList<ServerArrow> arrowList;
signals:
void playerListReceived(QList<ServerPlayer> _playerList);
void zoneListReceived(QList<ServerZone> _zoneList);
void cardListReceived(QList<ServerZoneCard> _cardList);
void counterListReceived(QList<ServerCounter> _counterList);
void arrowListReceived(QList<ServerArrow> _arrowList);
public:
void responseReceived(ServerResponse resp);
void addPlayer(const ServerPlayer &player) { playerList.append(player); }
void addZone(const ServerZone &zone) { zoneList.append(zone); }
void addCard(const ServerZoneCard &card) { cardList.append(card); }
void addCounter(const ServerCounter &counter) { counterList.append(counter); }
void addArrow(const ServerArrow &arrow) { arrowList.append(arrow); }
StatusLoggedIn,
};
class Client : public QObject {
Q_OBJECT
signals:
void statusChanged(ProtocolStatus _status);
void statusChanged(ClientStatus _status);
void welcomeMsgReceived(QString welcomeMsg);
void gameListEvent(const ServerGame &game);
// void gameListEvent(const ServerGame &game);
void playerIdReceived(int id, QString name);
void gameEvent(const ServerEventData &msg);
void chatEvent(const ChatEventData &msg);
// void gameEvent(const ServerEventData &msg);
// void chatEvent(const ChatEventData &msg);
void maxPingTime(int seconds, int maxSeconds);
void serverTimeout();
void logSocketError(const QString &errorString);
void serverError(ServerResponse resp);
// void serverError(ServerResponse resp);
void protocolVersionMismatch();
void protocolError();
private slots:
void slotConnected();
void readLine();
void readData();
void slotSocketError(QAbstractSocket::SocketError error);
void ping();
void removePendingCommand();
void loginResponse(ServerResponse response);
void enterGameResponse(ServerResponse response);
void leaveGameResponse(ServerResponse response);
// void loginResponse(ServerResponse response);
// void enterGameResponse(ServerResponse response);
// void leaveGameResponse(ServerResponse response);
private:
static const int protocolVersion = 2;
static const int maxTimeout = 10;
QTimer *timer;
QMap<int, PendingCommand *> pendingCommands;
QMap<int, Command *> pendingCommands;
QTcpSocket *socket;
ProtocolStatus status;
QXmlStreamReader *xmlReader;
QXmlStreamWriter *xmlWriter;
ProtocolItem *currentItem;
ClientStatus status;
QString playerName, password;
unsigned int MsgId;
void msg(const QString &s);
PendingCommand *cmd(const QString &s, PendingCommand *_pc = 0);
void setStatus(const ProtocolStatus _status);
void setStatus(ClientStatus _status);
public:
Client(QObject *parent = 0);
~Client();
ProtocolStatus getStatus() const { return status; }
ClientStatus getStatus() const { return status; }
QString peerName() const { return socket->peerName(); }
void connectToServer(const QString &hostname, unsigned int port, const QString &_playerName, const QString &_password);
void disconnectFromServer();
QColor numberToColor(int colorValue) const;
int colorToNumber(const QColor &color) const;
public slots:
PendingCommand *chatListChannels();
PendingCommand_ChatJoinChannel *chatJoinChannel(const QString &name);
PendingCommand *chatLeaveChannel(const QString &name);
PendingCommand *chatSay(const QString &name, const QString &s);
PendingCommand *listGames();
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();
PendingCommand *login(const QString &name, const QString &pass);
PendingCommand *say(const QString &s);
PendingCommand *shuffle();
PendingCommand *rollDie(unsigned int sides);
PendingCommand *drawCard() { return drawCards(1); }
PendingCommand *drawCards(unsigned int number);
PendingCommand *moveCard(int cardid, const QString &startzone, const QString &targetzone, int x, int y = 0, bool faceDown = false);
PendingCommand *createToken(const QString &zone, const QString &name, const QString &powtough, int x, int y);
PendingCommand *createArrow(int startPlayerId, const QString &startZone, int startCardId, int targetPlayerId, const QString &targetPlayerZone, int targetCardId, const QColor &color);
PendingCommand *deleteArrow(int arrowId);
PendingCommand *setCardAttr(const QString &zone, int cardid, const QString &aname, const QString &avalue);
PendingCommand *readyStart();
PendingCommand *incCounter(int counterId, int delta);
PendingCommand *addCounter(const QString &counterName, QColor color, int radius, int value);
PendingCommand *setCounter(int counterId, int value);
PendingCommand *delCounter(int counterId);
PendingCommand_ListCounters *listCounters(int playerId);
PendingCommand *nextTurn();
PendingCommand *setActivePhase(int phase);
PendingCommand_ListZones *listZones(int playerId);
PendingCommand_DumpZone *dumpZone(int player, const QString &zone, int numberCards);
PendingCommand *stopDumpZone(int player, const QString &zone);
PendingCommand_DumpAll *dumpAll();
void submitDeck(const QStringList &deck);
void chatListChannels() { }
void chatJoinChannel(const QString &name) { }
void chatLeaveChannel(const QString &name) { }
void chatSay(const QString &name, const QString &s) { }
void listGames() { }
void listPlayers() { }
void createGame(const QString &description, const QString &password, unsigned int maxPlayers, bool spectatorsAllowed) { }
void joinGame(int gameId, const QString &password, bool spectator) { }
void leaveGame() { }
void login(const QString &name, const QString &pass) { }
void say(const QString &s) { }
void shuffle() { }
void rollDie(unsigned int sides) { }
void drawCard() { return drawCards(1); }
void drawCards(unsigned int number) { }
void moveCard(int cardid, const QString &startzone, const QString &targetzone, int x, int y = 0, bool faceDown = false) { }
void createToken(const QString &zone, const QString &name, const QString &powtough, int x, int y) { }
void createArrow(int startPlayerId, const QString &startZone, int startCardId, int targetPlayerId, const QString &targetPlayerZone, int targetCardId, const QColor &color) { }
void deleteArrow(int arrowId) { }
void setCardAttr(const QString &zone, int cardid, const QString &aname, const QString &avalue) { }
void readyStart() { }
void incCounter(int counterId, int delta) { }
void addCounter(const QString &counterName, QColor color, int radius, int value) { }
void setCounter(int counterId, int value) { }
void delCounter(int counterId) { }
void nextTurn() { }
void setActivePhase(int phase) { }
void dumpZone(int player, const QString &zone, int numberCards) { }
void stopDumpZone(int player, const QString &zone) { }
void dumpAll() { }
void submitDeck(const QStringList &deck) { }
};
#endif

View file

@ -58,13 +58,13 @@ void DlgCreateGame::actOK()
QMessageBox::critical(this, tr("Error"), tr("Invalid number of players."));
return;
}
PendingCommand *createCommand = client->createGame(descriptionEdit->text(), passwordEdit->text(), maxPlayers, spectatorsAllowedCheckBox->isChecked());
connect(createCommand, SIGNAL(finished(ServerResponse)), this, SLOT(checkResponse(ServerResponse)));
// PendingCommand *createCommand = client->createGame(descriptionEdit->text(), passwordEdit->text(), maxPlayers, spectatorsAllowedCheckBox->isChecked());
// connect(createCommand, SIGNAL(finished(ServerResponse)), this, SLOT(checkResponse(ServerResponse)));
okButton->setEnabled(false);
cancelButton->setEnabled(false);
}
void DlgCreateGame::checkResponse(ServerResponse response)
/*void DlgCreateGame::checkResponse(ServerResponse response)
{
okButton->setEnabled(true);
cancelButton->setEnabled(true);
@ -76,3 +76,4 @@ void DlgCreateGame::checkResponse(ServerResponse response)
return;
}
}
*/

View file

@ -15,7 +15,7 @@ public:
DlgCreateGame(Client *_client, QWidget *parent = 0);
private slots:
void actOK();
void checkResponse(ServerResponse response);
// void checkResponse(ServerResponse response);
private:
Client *client;

View file

@ -13,6 +13,7 @@
#include "gamescene.h"
#include "player.h"
#include "arrowitem.h"
#include "protocol_datastructures.h"
Game::Game(CardDatabase *_db, Client *_client, GameScene *_scene, QMenuBar *menuBar, QObject *parent)
: QObject(parent), db(_db), client(_client), scene(_scene), started(false), currentPhase(-1)
@ -151,7 +152,7 @@ Player *Game::addPlayer(int playerId, const QString &playerName, bool local)
return newPlayer;
}
/*
void Game::cardListReceived(QList<ServerZoneCard> list)
{
for (int i = 0; i < list.size(); ++i) {
@ -250,7 +251,7 @@ void Game::playerListReceived(QList<ServerPlayer> playerList)
emit logPlayerListReceived(nameList);
restartGameDialog();
}
*/
void Game::readyStart()
{
client->readyStart();
@ -260,7 +261,7 @@ void Game::restartGameDialog()
{
dlgStartGame->show();
}
/*
void Game::gameEvent(const ServerEventData &msg)
{
qDebug(QString("game::gameEvent: public=%1, player=%2, name=%3, type=%4, data=%5").arg(msg.getPublic()).arg(msg.getPlayerId()).arg(msg.getPlayerName()).arg(msg.getEventType()).arg(msg.getEventData().join("/")).toLatin1());
@ -410,7 +411,7 @@ void Game::gameEvent(const ServerEventData &msg)
}
}
}
*/
void Game::actNextPhase()
{
int phase = currentPhase;
@ -537,13 +538,13 @@ void Game::hoverCardEvent(CardItem *card)
void Game::queryGameState()
{
PendingCommand_DumpAll *pc = client->dumpAll();
/* PendingCommand_DumpAll *pc = client->dumpAll();
connect(pc, SIGNAL(playerListReceived(QList<ServerPlayer>)), this, SLOT(playerListReceived(QList<ServerPlayer>)));
connect(pc, SIGNAL(zoneListReceived(QList<ServerZone>)), this, SLOT(zoneListReceived(QList<ServerZone>)));
connect(pc, SIGNAL(cardListReceived(QList<ServerZoneCard>)), this, SLOT(cardListReceived(QList<ServerZoneCard>)));
connect(pc, SIGNAL(counterListReceived(QList<ServerCounter>)), this, SLOT(counterListReceived(QList<ServerCounter>)));
connect(pc, SIGNAL(arrowListReceived(QList<ServerArrow>)), this, SLOT(arrowListReceived(QList<ServerArrow>)));
}
*/}
void Game::activePlayerDrawCard()
{

View file

@ -10,7 +10,6 @@
class GameScene;
class Player;
class ServerEventData;
class CardDatabase;
class DlgStartGame;
class CardItem;
@ -63,14 +62,14 @@ private slots:
void actMoveToGraveyard(CardItem *card);
void actMoveToExile(CardItem *card);
void gameEvent(const ServerEventData &msg);
/* void gameEvent(const ServerEventData &msg);
void playerListReceived(QList<ServerPlayer> playerList);
void cardListReceived(QList<ServerZoneCard> list);
void zoneListReceived(QList<ServerZone> list);
void counterListReceived(QList<ServerCounter> list);
void arrowListReceived(QList<ServerArrow> list);
*/
void readyStart();
signals:
void submitDecklist();

View file

@ -51,7 +51,7 @@ void GameSelector::actCreate()
disableGameList();
}
void GameSelector::checkResponse(ServerResponse response)
/*void GameSelector::checkResponse(ServerResponse response)
{
createButton->setEnabled(true);
joinButton->setEnabled(true);
@ -66,7 +66,7 @@ void GameSelector::checkResponse(ServerResponse response)
default: ;
}
}
*/
void GameSelector::actJoin()
{
bool spectator = sender() == spectateButton;
@ -74,7 +74,7 @@ void GameSelector::actJoin()
QModelIndex ind = gameListView->currentIndex();
if (!ind.isValid())
return;
const ServerGame &game = gameListModel->getGame(ind.data(Qt::UserRole).toInt());
const ServerGameInfo &game = gameListModel->getGame(ind.data(Qt::UserRole).toInt());
QString password;
if (game.getHasPassword()) {
bool ok;
@ -83,8 +83,8 @@ void GameSelector::actJoin()
return;
}
PendingCommand *joinCommand = client->joinGame(game.getGameId(), password, spectator);
connect(joinCommand, SIGNAL(finished(ServerResponse)), this, SLOT(checkResponse(ServerResponse)));
// PendingCommand *joinCommand = client->joinGame(game.getGameId(), password, spectator);
// connect(joinCommand, SIGNAL(finished(ServerResponse)), this, SLOT(checkResponse(ServerResponse)));
createButton->setEnabled(false);
joinButton->setEnabled(false);
spectateButton->setEnabled(false);
@ -95,7 +95,7 @@ void GameSelector::enableGameList()
if (isVisible())
return;
connect(client, SIGNAL(gameListEvent(const ServerGame &)), gameListModel, SLOT(updateGameList(const ServerGame &)));
connect(client, SIGNAL(gameListEvent(const ServerGameInfo &)), gameListModel, SLOT(updateGameList(const ServerGameInfo &)));
client->listGames();
show();
}

View file

@ -21,7 +21,7 @@ private slots:
void showFullGamesChanged(int state);
void actCreate();
void actJoin();
void checkResponse(ServerResponse response);
// void checkResponse(ServerResponse response);
private:
Client *client;

View file

@ -1,5 +1,5 @@
#include "gamesmodel.h"
#include "client.h"
#include "protocol_datastructures.h"
GamesModel::~GamesModel()
{
@ -17,13 +17,13 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
if ((index.row() >= gameList.size()) || (index.column() >= columnCount()))
return QVariant();
const ServerGame &g = gameList[index.row()];
const ServerGameInfo &g = gameList[index.row()];
switch (index.column()) {
case 0: return g.getDescription();
case 1: return g.getCreator();
case 1: return g.getCreatorName();
case 2: return g.getHasPassword() ? tr("yes") : tr("no");
case 3: return QString("%1/%2").arg(g.getPlayerCount()).arg(g.getMaxPlayers());
case 4: return g.getSpectatorsAllowed() ? QVariant(g.getSpectatorsCount()) : QVariant(tr("not allowed"));
case 4: return g.getSpectatorsAllowed() ? QVariant(g.getSpectatorCount()) : QVariant(tr("not allowed"));
default: return QVariant();
}
}
@ -42,13 +42,13 @@ QVariant GamesModel::headerData(int section, Qt::Orientation orientation, int ro
}
}
const ServerGame &GamesModel::getGame(int row)
const ServerGameInfo &GamesModel::getGame(int row)
{
Q_ASSERT(row < gameList.size());
return gameList[row];
}
void GamesModel::updateGameList(const ServerGame &game)
void GamesModel::updateGameList(const ServerGameInfo &game)
{
for (int i = 0; i < gameList.size(); i++)
if (gameList[i].getGameId() == game.getGameId()) {
@ -100,7 +100,7 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &/*sourc
if (!model)
return false;
const ServerGame &game = model->getGame(sourceRow);
const ServerGameInfo &game = model->getGame(sourceRow);
if (game.getPlayerCount() == game.getMaxPlayers())
return false;

View file

@ -4,7 +4,7 @@
#include <QAbstractTableModel>
#include <QSortFilterProxyModel>
#include <QList>
#include "client.h"
#include "protocol_datastructures.h"
class GamesModel : public QAbstractTableModel {
Q_OBJECT
@ -16,12 +16,12 @@ public:
QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
const ServerGame &getGame(int row);
const ServerGameInfo &getGame(int row);
void cleanList();
public slots:
void updateGameList(const ServerGame &game);
void updateGameList(const ServerGameInfo &game);
private:
QList<ServerGame> gameList;
QList<ServerGameInfo> gameList;
};
class GamesProxyModel : public QSortFilterProxyModel {

View file

@ -32,10 +32,10 @@ void MessageLogWidget::logSocketError(const QString &errorString)
append(sanitizeHtml(errorString));
}
void MessageLogWidget::logServerError(ServerResponse response)
void MessageLogWidget::logServerError(ResponseCode response)
{
switch (response) {
case RespPasswordWrong: append(tr("Invalid password.")); break;
case RespWrongPassword: append(tr("Invalid password.")); break;
default: ;
}
}

View file

@ -3,8 +3,8 @@
#include <QPlainTextEdit>
#include <QAbstractSocket>
#include "client.h"
#include "translation.h"
#include "protocol_datastructures.h"
class Game;
class Player;
@ -20,7 +20,7 @@ public slots:
void logConnected(QString welcomeMsg);
void logDisconnected();
void logSocketError(const QString &errorString);
void logServerError(ServerResponse response);
void logServerError(ResponseCode response);
void logProtocolVersionMismatch();
void logProtocolError();
private slots:

View file

@ -410,7 +410,7 @@ void Player::setCardAttrHelper(CardItem *card, const QString &aname, const QStri
}
}
void Player::gameEvent(const ServerEventData &event)
/*void Player::gameEvent(const ServerEventData &event)
{
QStringList data = event.getEventData();
switch (event.getEventType()) {
@ -643,7 +643,7 @@ void Player::gameEvent(const ServerEventData &event)
qDebug("unhandled player event");
}
}
*/
void Player::showCardMenu(const QPoint &p)
{
emit sigShowCardMenu(p);

View file

@ -114,7 +114,7 @@ public:
const QMap<QString, CardZone *> &getZones() const { return zones; }
const QMap<int, ArrowItem *> &getArrows() const { return arrows; }
TableZone *getTable() const { return table; }
void gameEvent(const ServerEventData &event);
// void gameEvent(const ServerEventData &event);
CardDatabase *getDb() const { return db; }
void showCardMenu(const QPoint &p);
bool getActive() const { return active; }

View file

@ -74,7 +74,7 @@ void MainWindow::playerAdded(Player *player)
connect(player, SIGNAL(closeZoneView(ZoneViewZone *)), zoneLayout, SLOT(removeItem(ZoneViewZone *)));
}
void MainWindow::statusChanged(ProtocolStatus _status)
void MainWindow::statusChanged(ClientStatus _status)
{
switch (_status) {
case StatusConnecting:
@ -101,8 +101,8 @@ void MainWindow::statusChanged(ProtocolStatus _status)
aConnect->setEnabled(false);
aDisconnect->setEnabled(true);
break;
case StatusIdle: {
if (game) {
case StatusLoggedIn: {
/* if (game) {
zoneLayout->clear();
delete game;
game = 0;
@ -115,10 +115,10 @@ void MainWindow::statusChanged(ProtocolStatus _status)
view->hide();
gameSelector->enableGameList();
chatWidget->enableChat();
break;
*/ break;
}
case StatusPlaying: {
chatWidget->disableChat();
// case StatusPlaying: {
/* chatWidget->disableChat();
game = new Game(db, client, scene, menuBar(), this);
connect(game, SIGNAL(hoverCard(QString)), cardInfo, SLOT(setCard(const QString &)));
@ -137,7 +137,7 @@ void MainWindow::statusChanged(ProtocolStatus _status)
view->show();
break;
}
default:
*/ default:
break;
}
}
@ -338,7 +338,7 @@ MainWindow::MainWindow(QTranslator *_translator, QWidget *parent)
connect(client, SIGNAL(maxPingTime(int, int)), pingWidget, SLOT(setPercentage(int, int)));
connect(client, SIGNAL(serverTimeout()), this, SLOT(serverTimeout()));
connect(client, SIGNAL(statusChanged(ProtocolStatus)), this, SLOT(statusChanged(ProtocolStatus)));
connect(client, SIGNAL(statusChanged(ClientStatus)), this, SLOT(statusChanged(ClientStatus)));
connect(this, SIGNAL(logConnecting(QString)), messageLog, SLOT(logConnecting(QString)));
connect(client, SIGNAL(welcomeMsgReceived(QString)), messageLog, SLOT(logConnected(QString)));

View file

@ -60,7 +60,7 @@ class MainWindow : public QMainWindow {
Q_OBJECT
private slots:
void playerAdded(Player *player);
void statusChanged(ProtocolStatus _status);
void statusChanged(ClientStatus _status);
void serverTimeout();
void actSay();

View file

@ -27,8 +27,8 @@ void ZoneViewZone::paint(QPainter */*painter*/, const QStyleOptionGraphicsItem *
void ZoneViewZone::initializeCards()
{
if (!origZone->contentsKnown()) {
PendingCommand_DumpZone *dumpZoneCommand = player->client->dumpZone(player->getId(), name, numberCards);
connect(dumpZoneCommand, SIGNAL(cardListReceived(QList<ServerZoneCard>)), this, SLOT(zoneDumpReceived(QList<ServerZoneCard>)));
// PendingCommand_DumpZone *dumpZoneCommand = player->client->dumpZone(player->getId(), name, numberCards);
// connect(dumpZoneCommand, SIGNAL(cardListReceived(QList<ServerZoneCard>)), this, SLOT(zoneDumpReceived(QList<ServerZoneCard>)));
} else {
const CardList &c = origZone->getCards();
int number = numberCards == -1 ? c.size() : (numberCards < c.size() ? numberCards : c.size());

View file

@ -2,7 +2,7 @@
#define ZONEVIEWERZONE_H
#include "cardzone.h"
#include "client.h"
#include "protocol_datastructures.h"
#include <QGraphicsWidget>
#include <QGraphicsLayoutItem>

View file

@ -69,7 +69,7 @@ void ProtocolItem::initializeHash()
int Command::lastCmdId = 0;
Command::Command(const QString &_itemName, int _cmdId)
: ProtocolItem(_itemName), cmdId(_cmdId)
: ProtocolItem(_itemName), cmdId(_cmdId), ticks(0)
{
if (cmdId == -1)
cmdId = lastCmdId++;
@ -84,7 +84,7 @@ void Command::extractParameters()
cmdId = -1;
}
QHash<QString, ProtocolResponse::ResponseCode> ProtocolResponse::responseHash;
QHash<QString, ResponseCode> ProtocolResponse::responseHash;
ProtocolResponse::ProtocolResponse(int _cmdId, ResponseCode _responseCode)
: ProtocolItem(QString()), cmdId(_cmdId), responseCode(_responseCode)
@ -151,7 +151,7 @@ ChatEvent::ChatEvent(const QString &_eventName, const QString &_channel)
bool Event_ChatListChannels::readElement(QXmlStreamReader *xml)
{
if (xml->isStartElement() && (xml->name() == "channel")) {
channelList.append(ChannelInfo(
channelList.append(ServerChatChannelInfo(
xml->attributes().value("name").toString(),
xml->attributes().value("description").toString(),
xml->attributes().value("player_count").toString().toInt(),
@ -177,7 +177,7 @@ void Event_ChatListChannels::writeElement(QXmlStreamWriter *xml)
bool Event_ChatListPlayers::readElement(QXmlStreamReader *xml)
{
if (xml->isStartElement() && ((xml->name() == "player"))) {
playerList.append(PlayerInfo(
playerList.append(ServerPlayerInfo(
xml->attributes().value("name").toString()
));
return true;
@ -197,7 +197,7 @@ void Event_ChatListPlayers::writeElement(QXmlStreamWriter *xml)
bool Event_ListGames::readElement(QXmlStreamReader *xml)
{
if (xml->isStartElement() && (xml->name() == "game")) {
gameList.append(GameInfo(
gameList.append(ServerGameInfo(
xml->attributes().value("id").toString().toInt(),
xml->attributes().value("description").toString(),
xml->attributes().value("has_password").toString().toInt(),

View file

@ -7,6 +7,7 @@
#include <QObject>
#include <QDebug>
#include "protocol_item_ids.h"
#include "protocol_datastructures.h"
class QXmlStreamReader;
class QXmlStreamWriter;
@ -52,6 +53,7 @@ class Command : public ProtocolItem {
Q_OBJECT
private:
int cmdId;
int ticks;
static int lastCmdId;
protected:
QString getItemType() const { return "cmd"; }
@ -59,6 +61,7 @@ protected:
public:
Command(const QString &_itemName = QString(), int _cmdId = -1);
int getCmdId() const { return cmdId; }
int tick() { return ++ticks; }
};
class InvalidCommand : public Command {
@ -106,8 +109,6 @@ public:
class ProtocolResponse : public ProtocolItem {
Q_OBJECT
public:
enum ResponseCode { RespNothing, RespOk, RespInvalidCommand, RespNameNotFound, RespLoginNeeded, RespContextError, RespWrongPassword, RespSpectatorsNotAllowed };
private:
int cmdId;
ResponseCode responseCode;
@ -158,31 +159,16 @@ public:
class Event_ChatListChannels : public GenericEvent {
Q_OBJECT
public:
class ChannelInfo {
private:
QString name;
QString description;
int playerCount;
bool autoJoin;
public:
ChannelInfo(const QString &_name, const QString &_description, int _playerCount, bool _autoJoin)
: name(_name), description(_description), playerCount(_playerCount), autoJoin(_autoJoin) { }
QString getName() const { return name; }
QString getDescription() const { return description; }
int getPlayerCount() const { return playerCount; }
bool getAutoJoin() const { return autoJoin; }
};
private:
QList<ChannelInfo> channelList;
QList<ServerChatChannelInfo> channelList;
public:
Event_ChatListChannels() : GenericEvent("chat_list_channels") { }
int getItemId() const { return ItemId_Event_ChatListChannels; }
void addChannel(const QString &_name, const QString &_description, int _playerCount, bool _autoJoin)
{
channelList.append(ChannelInfo(_name, _description, _playerCount, _autoJoin));
channelList.append(ServerChatChannelInfo(_name, _description, _playerCount, _autoJoin));
}
const QList<ChannelInfo> &getChannelList() const { return channelList; }
const QList<ServerChatChannelInfo> &getChannelList() const { return channelList; }
bool readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);
@ -190,25 +176,16 @@ public:
class Event_ChatListPlayers : public ChatEvent {
Q_OBJECT
public:
class PlayerInfo {
private:
QString name;
public:
PlayerInfo(const QString &_name)
: name(_name) { }
QString getName() const { return name; }
};
private:
QList<PlayerInfo> playerList;
QList<ServerPlayerInfo> playerList;
public:
Event_ChatListPlayers(const QString &_channel) : ChatEvent("chat_list_players", _channel) { }
int getItemId() const { return ItemId_Event_ChatListPlayers; }
void addPlayer(const QString &_name)
{
playerList.append(PlayerInfo(_name));
playerList.append(ServerPlayerInfo(_name));
}
const QList<PlayerInfo> &getPlayerList() const { return playerList; }
const QList<ServerPlayerInfo> &getPlayerList() const { return playerList; }
bool readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);
@ -216,39 +193,16 @@ public:
class Event_ListGames : public GenericEvent {
Q_OBJECT
public:
class GameInfo {
private:
int gameId;
QString description;
bool hasPassword;
int playerCount;
int maxPlayers;
QString creatorName;
bool spectatorsAllowed;
int spectatorCount;
public:
GameInfo(int _gameId, const QString &_description, bool _hasPassword, int _playerCount, int _maxPlayers, const QString &_creatorName, bool _spectatorsAllowed, int _spectatorCount)
: gameId(_gameId), description(_description), hasPassword(_hasPassword), playerCount(_playerCount), maxPlayers(_maxPlayers), creatorName(_creatorName), spectatorsAllowed(_spectatorsAllowed), spectatorCount(_spectatorCount) { }
int getGameId() const { return gameId; }
QString getDescription() const { return description; }
bool getHasPassword() const { return hasPassword; }
int getPlayerCount() const { return playerCount; }
int getMaxPlayers() const { return maxPlayers; }
QString getCreatorName() const { return creatorName; }
bool getSpectatorsAllowed() const { return spectatorsAllowed; }
int getSpectatorCount() const { return spectatorCount; }
};
private:
QList<GameInfo> gameList;
QList<ServerGameInfo> gameList;
public:
Event_ListGames() : GenericEvent("list_games") { }
int getItemId() const { return ItemId_Event_ListGames; }
void addGame(int _gameId, const QString &_description, bool _hasPassword, int _playerCount, int _maxPlayers, const QString &_creatorName, bool _spectatorsAllowed, int _spectatorCount)
{
gameList.append(GameInfo(_gameId, _description, _hasPassword, _playerCount, _maxPlayers, _creatorName, _spectatorsAllowed, _spectatorCount));
gameList.append(ServerGameInfo(_gameId, _description, _hasPassword, _playerCount, _maxPlayers, _creatorName, _spectatorsAllowed, _spectatorCount));
}
const QList<GameInfo> &getGameList() const { return gameList; }
const QList<ServerGameInfo> &getGameList() const { return gameList; }
bool readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);

View file

@ -77,17 +77,17 @@ void Server_Game::startGameIfReady()
setActivePlayer(0);
}
ProtocolResponse::ResponseCode Server_Game::checkJoin(const QString &_password, bool spectator)
ResponseCode Server_Game::checkJoin(const QString &_password, bool spectator)
{
if (_password != password)
return ProtocolResponse::RespWrongPassword;
return RespWrongPassword;
if (spectator) {
if (!spectatorsAllowed)
return ProtocolResponse::RespSpectatorsNotAllowed;
return RespSpectatorsNotAllowed;
} else if (gameStarted || (getPlayerCount() >= getMaxPlayers()))
return ProtocolResponse::RespContextError;
return RespContextError;
return ProtocolResponse::RespOk;
return RespOk;
}
Server_Player *Server_Game::addPlayer(Server_ProtocolHandler *handler, bool spectator)

View file

@ -56,7 +56,7 @@ public:
QString getPassword() const { return password; }
int getMaxPlayers() const { return maxPlayers; }
bool getSpectatorsAllowed() const { return spectatorsAllowed; }
ProtocolResponse::ResponseCode checkJoin(const QString &_password, bool spectator);
ResponseCode checkJoin(const QString &_password, bool spectator);
Server_Player *addPlayer(Server_ProtocolHandler *handler, bool spectator);
void removePlayer(Server_Player *player);
void startGameIfReady();

View file

@ -22,7 +22,7 @@ Server_ProtocolHandler::~Server_ProtocolHandler()
void Server_ProtocolHandler::processCommand(Command *command)
{
ProtocolResponse::ResponseCode response = ProtocolResponse::RespInvalidCommand;
ResponseCode response = RespInvalidCommand;
ChatCommand *chatCommand = qobject_cast<ChatCommand *>(command);
GameCommand *gameCommand = qobject_cast<GameCommand *>(command);
@ -30,7 +30,7 @@ void Server_ProtocolHandler::processCommand(Command *command)
qDebug() << "received ChatCommand: channel =" << chatCommand->getChannel();
Server_ChatChannel *channel = chatChannels.value(chatCommand->getChannel(), 0);
if (!channel) {
sendProtocolItem(new ProtocolResponse(gameCommand->getCmdId(), ProtocolResponse::RespNameNotFound));
sendProtocolItem(new ProtocolResponse(gameCommand->getCmdId(), RespNameNotFound));
return;
}
switch (command->getItemId()) {
@ -40,7 +40,7 @@ void Server_ProtocolHandler::processCommand(Command *command)
} else if (gameCommand) {
qDebug() << "received GameCommand: game =" << gameCommand->getGameId();
if (!games.contains(gameCommand->getGameId())) {
sendProtocolItem(new ProtocolResponse(gameCommand->getCmdId(), ProtocolResponse::RespNameNotFound));
sendProtocolItem(new ProtocolResponse(gameCommand->getCmdId(), RespNameNotFound));
return;
}
QPair<Server_Game *, Server_Player *> gamePair = games.value(gameCommand->getGameId());
@ -82,7 +82,7 @@ void Server_ProtocolHandler::processCommand(Command *command)
case ItemId_Command_JoinGame: response = cmdJoinGame(qobject_cast<Command_JoinGame *>(command)); break;
}
}
if (response != ProtocolResponse::RespNothing)
if (response != RespNothing)
sendProtocolItem(new ProtocolResponse(command->getCmdId(), response));
delete command;
@ -103,23 +103,23 @@ QPair<Server_Game *, Server_Player *> Server_ProtocolHandler::getGame(int gameId
return QPair<Server_Game *, Server_Player *>(0, 0);
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdPing(Command_Ping * /*cmd*/)
ResponseCode Server_ProtocolHandler::cmdPing(Command_Ping * /*cmd*/)
{
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdLogin(Command_Login *cmd)
ResponseCode Server_ProtocolHandler::cmdLogin(Command_Login *cmd)
{
authState = server->checkUserPassword(cmd->getUsername(), cmd->getPassword());
if (authState == PasswordWrong)
return ProtocolResponse::RespWrongPassword;
return RespWrongPassword;
playerName = cmd->getUsername();
enqueueProtocolItem(new Event_ChatServerMessage(QString(), server->getLoginMessage()));
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdChatListChannels(Command_ChatListChannels * /*cmd*/)
ResponseCode Server_ProtocolHandler::cmdChatListChannels(Command_ChatListChannels * /*cmd*/)
{
Event_ChatListChannels *event = new Event_ChatListChannels;
QMapIterator<QString, Server_ChatChannel *> channelIterator(server->getChatChannels());
@ -130,38 +130,38 @@ ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdChatListChannels(Comma
sendProtocolItem(event);
acceptsChatChannelListChanges = true;
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdChatJoinChannel(Command_ChatJoinChannel *cmd)
ResponseCode Server_ProtocolHandler::cmdChatJoinChannel(Command_ChatJoinChannel *cmd)
{
if (chatChannels.contains(cmd->getChannel()))
return ProtocolResponse::RespContextError;
return RespContextError;
QMap<QString, Server_ChatChannel *> allChannels = server->getChatChannels();
Server_ChatChannel *c = allChannels.value(cmd->getChannel(), 0);
if (!c)
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
c->addClient(this);
chatChannels.insert(cmd->getChannel(), c);
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdChatLeaveChannel(Command_ChatLeaveChannel * /*cmd*/, Server_ChatChannel *channel)
ResponseCode Server_ProtocolHandler::cmdChatLeaveChannel(Command_ChatLeaveChannel * /*cmd*/, Server_ChatChannel *channel)
{
chatChannels.remove(channel->getName());
channel->removeClient(this);
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdChatSay(Command_ChatSay *cmd, Server_ChatChannel *channel)
ResponseCode Server_ProtocolHandler::cmdChatSay(Command_ChatSay *cmd, Server_ChatChannel *channel)
{
channel->say(this, cmd->getMessage());
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdListGames(Command_ListGames * /*cmd*/)
ResponseCode Server_ProtocolHandler::cmdListGames(Command_ListGames * /*cmd*/)
{
Event_ListGames *event = new Event_ListGames;
const QList<Server_Game *> &gameList = server->getGames();
@ -181,57 +181,57 @@ ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdListGames(Command_List
sendProtocolItem(event);
acceptsGameListChanges = true;
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd)
ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd)
{
Server_Game *game = server->createGame(cmd->getDescription(), cmd->getPassword(), cmd->getMaxPlayers(), cmd->getSpectatorsAllowed(), this);
games.insert(game->getGameId(), QPair<Server_Game *, Server_Player *>(game, game->getCreator()));
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd)
ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd)
{
Server_Game *g = server->getGame(cmd->getGameId());
if (!g)
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
ProtocolResponse::ResponseCode result = g->checkJoin(cmd->getPassword(), cmd->getSpectator());
if (result == ProtocolResponse::RespOk) {
ResponseCode result = g->checkJoin(cmd->getPassword(), cmd->getSpectator());
if (result == RespOk) {
Server_Player *player = g->addPlayer(this, cmd->getSpectator());
games.insert(cmd->getGameId(), QPair<Server_Game *, Server_Player *>(g, player));
}
return result;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdLeaveGame(Command_LeaveGame * /*cmd*/, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdLeaveGame(Command_LeaveGame * /*cmd*/, Server_Game *game, Server_Player *player)
{
game->removePlayer(player);
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdSay(Command_Say *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdSay(Command_Say *cmd, Server_Game *game, Server_Player *player)
{
game->sendGameEvent(new Event_Say(-1, player->getPlayerId(), cmd->getMessage()));
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdShuffle(Command_Shuffle * /*cmd*/, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdShuffle(Command_Shuffle * /*cmd*/, Server_Game *game, Server_Player *player)
{
player->getZones().value("deck")->shuffle();
game->sendGameEvent(new Event_Shuffle(-1, player->getPlayerId()));
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdRollDie(Command_RollDie *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdRollDie(Command_RollDie *cmd, Server_Game *game, Server_Player *player)
{
game->sendGameEvent(new Event_RollDie(-1, player->getPlayerId(), cmd->getSides(), rng->getNumber(1, cmd->getSides())));
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdDrawCards(Command_DrawCards *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdDrawCards(Command_DrawCards *cmd, Server_Game *game, Server_Player *player)
{
Server_CardZone *deck = player->getZones().value("deck");
Server_CardZone *hand = player->getZones().value("hand");
@ -246,21 +246,21 @@ ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdDrawCards(Command_Draw
}
// game->broadcastEvent(QString("draw|%1").arg(number), player);
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdMoveCard(Command_MoveCard *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdMoveCard(Command_MoveCard *cmd, Server_Game *game, Server_Player *player)
{
// ID Karte, Startzone, Zielzone, Koordinaten X, Y, Facedown
Server_CardZone *startzone = player->getZones().value(cmd->getStartZone());
Server_CardZone *targetzone = player->getZones().value(cmd->getTargetZone());
if ((!startzone) || (!targetzone))
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
int position = -1;
Server_Card *card = startzone->getCard(cmd->getCardId(), true, &position);
if (!card)
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
int x = cmd->getX();
if (x == -1)
x = targetzone->cards.size();
@ -345,42 +345,42 @@ ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdMoveCard(Command_MoveC
}
}
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdCreateToken(Command_CreateToken *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdCreateToken(Command_CreateToken *cmd, Server_Game *game, Server_Player *player)
{
// powtough wird erst mal ignoriert
Server_CardZone *zone = player->getZones().value(cmd->getZone());
if (!zone)
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
Server_Card *card = new Server_Card(cmd->getCardName(), player->newCardId(), cmd->getX(), cmd->getY());
zone->insertCard(card, cmd->getX(), cmd->getY());
game->sendGameEvent(new Event_CreateToken(-1, player->getPlayerId(), zone->getName(), card->getId(), card->getName(), cmd->getPt(), cmd->getX(), cmd->getY()));
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdCreateArrow(Command_CreateArrow *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdCreateArrow(Command_CreateArrow *cmd, Server_Game *game, Server_Player *player)
{
Server_Player *startPlayer = game->getPlayer(cmd->getStartPlayerId());
Server_Player *targetPlayer = game->getPlayer(cmd->getTargetPlayerId());
if (!startPlayer || !targetPlayer)
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
Server_CardZone *startZone = startPlayer->getZones().value(cmd->getStartZone());
Server_CardZone *targetZone = targetPlayer->getZones().value(cmd->getTargetZone());
if (!startZone || !targetZone)
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
Server_Card *startCard = startZone->getCard(cmd->getStartCardId(), false);
Server_Card *targetCard = targetZone->getCard(cmd->getTargetCardId(), false);
if (!startCard || !targetCard || (startCard == targetCard))
return ProtocolResponse::RespContextError;
return RespContextError;
QMapIterator<int, Server_Arrow *> arrowIterator(player->getArrows());
while (arrowIterator.hasNext()) {
Server_Arrow *temp = arrowIterator.next().value();
if ((temp->getStartCard() == startCard) && (temp->getTargetCard() == targetCard))
return ProtocolResponse::RespContextError;
return RespContextError;
}
Server_Arrow *arrow = new Server_Arrow(player->newArrowId(), startCard, targetCard, cmd->getColor());
@ -397,148 +397,148 @@ ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdCreateArrow(Command_Cr
targetCard->getId(),
cmd->getColor()
));
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdDeleteArrow(Command_DeleteArrow *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdDeleteArrow(Command_DeleteArrow *cmd, Server_Game *game, Server_Player *player)
{
if (!player->deleteArrow(cmd->getArrowId()))
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
game->sendGameEvent(new Event_DeleteArrow(-1, player->getPlayerId(), cmd->getArrowId()));
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdSetCardAttr(Command_SetCardAttr *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdSetCardAttr(Command_SetCardAttr *cmd, Server_Game *game, Server_Player *player)
{
// zone, card id, attr name, attr value
// card id = -1 => affects all cards in the specified zone
Server_CardZone *zone = player->getZones().value(cmd->getZone());
if (!zone)
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
if (cmd->getCardId() == -1) {
QListIterator<Server_Card *> CardIterator(zone->cards);
while (CardIterator.hasNext())
if (!CardIterator.next()->setAttribute(cmd->getAttrName(), cmd->getAttrValue(), true))
return ProtocolResponse::RespInvalidCommand;
return RespInvalidCommand;
} else {
Server_Card *card = zone->getCard(cmd->getCardId(), false);
if (!card)
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
if (!card->setAttribute(cmd->getAttrName(), cmd->getAttrValue(), false))
return ProtocolResponse::RespInvalidCommand;
return RespInvalidCommand;
}
game->sendGameEvent(new Event_SetCardAttr(-1, player->getPlayerId(), zone->getName(), cmd->getCardId(), cmd->getAttrName(), cmd->getAttrValue()));
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdReadyStart(Command_ReadyStart * /*cmd*/, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdReadyStart(Command_ReadyStart * /*cmd*/, Server_Game *game, Server_Player *player)
{
player->setStatus(StatusReadyStart);
game->sendGameEvent(new Event_ReadyStart(-1, player->getPlayerId()));
game->startGameIfReady();
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdIncCounter(Command_IncCounter *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdIncCounter(Command_IncCounter *cmd, Server_Game *game, Server_Player *player)
{
const QMap<int, Server_Counter *> counters = player->getCounters();
Server_Counter *c = counters.value(cmd->getCounterId(), 0);
if (!c)
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
c->setCount(c->getCount() + cmd->getDelta());
game->sendGameEvent(new Event_SetCounter(-1, player->getPlayerId(), c->getId(), c->getCount()));
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdAddCounter(Command_AddCounter *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdAddCounter(Command_AddCounter *cmd, Server_Game *game, Server_Player *player)
{
Server_Counter *c = new Server_Counter(player->newCounterId(), cmd->getCounterName(), cmd->getColor(), cmd->getRadius(), cmd->getValue());
player->addCounter(c);
game->sendGameEvent(new Event_AddCounter(-1, player->getPlayerId(), c->getId(), c->getName(), c->getColor(), c->getRadius(), c->getCount()));
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdSetCounter(Command_SetCounter *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdSetCounter(Command_SetCounter *cmd, Server_Game *game, Server_Player *player)
{
Server_Counter *c = player->getCounters().value(cmd->getCounterId(), 0);;
if (!c)
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
c->setCount(cmd->getValue());
game->sendGameEvent(new Event_SetCounter(-1, player->getPlayerId(), c->getId(), c->getCount()));
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdDelCounter(Command_DelCounter *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdDelCounter(Command_DelCounter *cmd, Server_Game *game, Server_Player *player)
{
if (!player->deleteCounter(cmd->getCounterId()))
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
game->sendGameEvent(new Event_DelCounter(-1, player->getPlayerId(), cmd->getCounterId()));
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdNextTurn(Command_NextTurn * /*cmd*/, Server_Game *game, Server_Player * /*player*/)
ResponseCode Server_ProtocolHandler::cmdNextTurn(Command_NextTurn * /*cmd*/, Server_Game *game, Server_Player * /*player*/)
{
int activePlayer = game->getActivePlayer();
if (++activePlayer == game->getPlayerCount())
activePlayer = 0;
game->setActivePlayer(activePlayer);
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdSetActivePhase(Command_SetActivePhase *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdSetActivePhase(Command_SetActivePhase *cmd, Server_Game *game, Server_Player *player)
{
if (game->getActivePlayer() != player->getPlayerId())
return ProtocolResponse::RespContextError;
return RespContextError;
game->setActivePhase(cmd->getPhase());
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdDumpZone(Command_DumpZone *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdDumpZone(Command_DumpZone *cmd, Server_Game *game, Server_Player *player)
{
Server_Player *otherPlayer = game->getPlayer(cmd->getPlayerId());
if (!otherPlayer)
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
Server_CardZone *zone = otherPlayer->getZones().value(cmd->getZoneName());
if (!zone)
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
if (!((zone->getType() == Server_CardZone::PublicZone) || (player == otherPlayer)))
return ProtocolResponse::RespContextError;
return RespContextError;
if (zone->getType() == Server_CardZone::HiddenZone) {
// game->broadcastEvent(QString("dump_zone|%1|%2|%3").arg(player_id).arg(zone->getName()).arg(number_cards), player);
}
// remsg->sendList(dumpZoneHelper(otherPlayer, zone, number_cards));
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdStopDumpZone(Command_StopDumpZone *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdStopDumpZone(Command_StopDumpZone *cmd, Server_Game *game, Server_Player *player)
{
Server_Player *otherPlayer = game->getPlayer(cmd->getPlayerId());
if (!otherPlayer)
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
Server_CardZone *zone = otherPlayer->getZones().value(cmd->getZoneName());
if (!zone)
return ProtocolResponse::RespNameNotFound;
return RespNameNotFound;
if (zone->getType() == Server_CardZone::HiddenZone) {
zone->setCardsBeingLookedAt(0);
game->sendGameEvent(new Event_StopDumpZone(-1, player->getPlayerId(), cmd->getPlayerId(), zone->getName()));
}
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdDumpAll(Command_DumpAll *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdDumpAll(Command_DumpAll *cmd, Server_Game *game, Server_Player *player)
{
return ProtocolResponse::RespOk;
return RespOk;
}
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdSubmitDeck(Command_SubmitDeck *cmd, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdSubmitDeck(Command_SubmitDeck *cmd, Server_Game *game, Server_Player *player)
{
return ProtocolResponse::RespOk;
return RespOk;
}

View file

@ -26,36 +26,36 @@ private:
QList<ProtocolItem *> itemQueue;
ProtocolResponse::ResponseCode cmdPing(Command_Ping *cmd);
ProtocolResponse::ResponseCode cmdLogin(Command_Login *cmd);
ProtocolResponse::ResponseCode cmdChatListChannels(Command_ChatListChannels *cmd);
ProtocolResponse::ResponseCode cmdChatJoinChannel(Command_ChatJoinChannel *cmd);
ProtocolResponse::ResponseCode cmdChatLeaveChannel(Command_ChatLeaveChannel *cmd, Server_ChatChannel *channel);
ProtocolResponse::ResponseCode cmdChatSay(Command_ChatSay *cmd, Server_ChatChannel *channel);
ProtocolResponse::ResponseCode cmdListGames(Command_ListGames *cmd);
ProtocolResponse::ResponseCode cmdCreateGame(Command_CreateGame *cmd);
ProtocolResponse::ResponseCode cmdJoinGame(Command_JoinGame *cmd);
ProtocolResponse::ResponseCode cmdLeaveGame(Command_LeaveGame *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdSay(Command_Say *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdShuffle(Command_Shuffle *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdRollDie(Command_RollDie *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdDrawCards(Command_DrawCards *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdMoveCard(Command_MoveCard *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdCreateToken(Command_CreateToken *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdCreateArrow(Command_CreateArrow *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdDeleteArrow(Command_DeleteArrow *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdSetCardAttr(Command_SetCardAttr *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdReadyStart(Command_ReadyStart *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdIncCounter(Command_IncCounter *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdAddCounter(Command_AddCounter *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdSetCounter(Command_SetCounter *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdDelCounter(Command_DelCounter *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdNextTurn(Command_NextTurn *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdSetActivePhase(Command_SetActivePhase *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdDumpZone(Command_DumpZone *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdStopDumpZone(Command_StopDumpZone *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdDumpAll(Command_DumpAll *cmd, Server_Game *game, Server_Player *player);
ProtocolResponse::ResponseCode cmdSubmitDeck(Command_SubmitDeck *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdPing(Command_Ping *cmd);
ResponseCode cmdLogin(Command_Login *cmd);
ResponseCode cmdChatListChannels(Command_ChatListChannels *cmd);
ResponseCode cmdChatJoinChannel(Command_ChatJoinChannel *cmd);
ResponseCode cmdChatLeaveChannel(Command_ChatLeaveChannel *cmd, Server_ChatChannel *channel);
ResponseCode cmdChatSay(Command_ChatSay *cmd, Server_ChatChannel *channel);
ResponseCode cmdListGames(Command_ListGames *cmd);
ResponseCode cmdCreateGame(Command_CreateGame *cmd);
ResponseCode cmdJoinGame(Command_JoinGame *cmd);
ResponseCode cmdLeaveGame(Command_LeaveGame *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdSay(Command_Say *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdShuffle(Command_Shuffle *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdRollDie(Command_RollDie *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdDrawCards(Command_DrawCards *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdMoveCard(Command_MoveCard *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdCreateToken(Command_CreateToken *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdCreateArrow(Command_CreateArrow *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdDeleteArrow(Command_DeleteArrow *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdSetCardAttr(Command_SetCardAttr *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdReadyStart(Command_ReadyStart *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdIncCounter(Command_IncCounter *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdAddCounter(Command_AddCounter *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdSetCounter(Command_SetCounter *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdDelCounter(Command_DelCounter *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdNextTurn(Command_NextTurn *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdSetActivePhase(Command_SetActivePhase *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdDumpZone(Command_DumpZone *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdStopDumpZone(Command_StopDumpZone *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdDumpAll(Command_DumpAll *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdSubmitDeck(Command_SubmitDeck *cmd, Server_Game *game, Server_Player *player);
public:
Server_ProtocolHandler(Server *_server, QObject *parent = 0);
~Server_ProtocolHandler();

View file

@ -11,12 +11,12 @@ OBJECTS_DIR = build
CONFIG += qt debug
QT += network sql
QT -= gui
HEADERS += src/servatrice.h \
src/serversocketinterface.h \
../common/protocol.h \
../common/protocol_items.h \
../common/protocol_datastructures.h \
../common/rng_abstract.h \
../common/rng_qt.h \
../common/server.h \

View file

@ -88,7 +88,7 @@ void ServerSocketInterface::readClient()
else {
Command *command = qobject_cast<Command *>(currentItem);
if (qobject_cast<InvalidCommand *>(command))
sendProtocolItem(new ProtocolResponse(command->getCmdId(), ProtocolResponse::RespInvalidCommand));
sendProtocolItem(new ProtocolResponse(command->getCmdId(), RespInvalidCommand));
else
processCommand(command);
currentItem = 0;