small cleanups
This commit is contained in:
parent
890740bcc9
commit
fa16d86283
27 changed files with 616 additions and 497 deletions
|
@ -13,8 +13,6 @@ HEADERS += src/counter.h \
|
||||||
src/gamesmodel.h \
|
src/gamesmodel.h \
|
||||||
src/client.h \
|
src/client.h \
|
||||||
src/window_main.h \
|
src/window_main.h \
|
||||||
src/servergame.h \
|
|
||||||
src/servereventdata.h \
|
|
||||||
src/zonelist.h \
|
src/zonelist.h \
|
||||||
src/cardzone.h \
|
src/cardzone.h \
|
||||||
src/player.h \
|
src/player.h \
|
||||||
|
@ -30,7 +28,6 @@ HEADERS += src/counter.h \
|
||||||
src/dlg_startgame.h \
|
src/dlg_startgame.h \
|
||||||
src/cardinfowidget.h \
|
src/cardinfowidget.h \
|
||||||
src/messagelogwidget.h \
|
src/messagelogwidget.h \
|
||||||
src/serverzonecard.h \
|
|
||||||
src/zoneviewzone.h \
|
src/zoneviewzone.h \
|
||||||
src/zoneviewwidget.h \
|
src/zoneviewwidget.h \
|
||||||
src/pilezone.h \
|
src/pilezone.h \
|
||||||
|
@ -53,7 +50,6 @@ SOURCES += src/counter.cpp \
|
||||||
src/client.cpp \
|
src/client.cpp \
|
||||||
src/main.cpp \
|
src/main.cpp \
|
||||||
src/window_main.cpp \
|
src/window_main.cpp \
|
||||||
src/servereventdata.cpp \
|
|
||||||
src/gamesmodel.cpp \
|
src/gamesmodel.cpp \
|
||||||
src/player.cpp \
|
src/player.cpp \
|
||||||
src/cardzone.cpp \
|
src/cardzone.cpp \
|
||||||
|
|
|
@ -212,8 +212,7 @@ void ChatWidget::chatEvent(const ChatEventData &data)
|
||||||
|
|
||||||
void ChatWidget::joinChannel(const QString &channelName)
|
void ChatWidget::joinChannel(const QString &channelName)
|
||||||
{
|
{
|
||||||
PendingCommand *pc = client->chatJoinChannel(channelName);
|
PendingCommand_ChatJoinChannel *pc = client->chatJoinChannel(channelName);
|
||||||
pc->setExtraData(channelName);
|
|
||||||
connect(pc, SIGNAL(finished(ServerResponse)), this, SLOT(joinFinished(ServerResponse)));
|
connect(pc, SIGNAL(finished(ServerResponse)), this, SLOT(joinFinished(ServerResponse)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,8 +233,8 @@ void ChatWidget::joinFinished(ServerResponse resp)
|
||||||
if (resp != RespOk)
|
if (resp != RespOk)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
PendingCommand *pc = qobject_cast<PendingCommand *>(sender());
|
PendingCommand_ChatJoinChannel *pc = qobject_cast<PendingCommand_ChatJoinChannel *>(sender());
|
||||||
QString channelName = pc->getExtraData();
|
QString channelName = pc->getChannelName();
|
||||||
ChannelWidget *cw = new ChannelWidget(client, channelName);
|
ChannelWidget *cw = new ChannelWidget(client, channelName);
|
||||||
tab->addTab(cw, channelName);
|
tab->addTab(cw, channelName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#define CHATWIDGET_H
|
#define CHATWIDGET_H
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include "servereventdata.h"
|
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
|
|
||||||
class QListWidget;
|
class QListWidget;
|
||||||
|
|
|
@ -1,17 +1,74 @@
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
|
|
||||||
PendingCommand::PendingCommand(const QString &_cmd, int _msgid, QObject *parent)
|
// Message structure for server events:
|
||||||
: QObject(parent), cmd(_cmd), msgid(_msgid), time(0)
|
// {"private","public"}|PlayerId|PlayerName|EventType|EventData
|
||||||
|
|
||||||
|
QHash<QString, ServerEventType> ServerEventData::eventHash;
|
||||||
|
|
||||||
|
ServerEventData::ServerEventData(const QString &line)
|
||||||
|
{
|
||||||
|
if (eventHash.isEmpty()) {
|
||||||
|
eventHash.insert("player_id", eventPlayerId);
|
||||||
|
eventHash.insert("say", eventSay);
|
||||||
|
eventHash.insert("name", eventName);
|
||||||
|
eventHash.insert("join", eventJoin);
|
||||||
|
eventHash.insert("leave", eventLeave);
|
||||||
|
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("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");
|
||||||
|
PlayerId = values.takeFirst().toInt();
|
||||||
|
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(int _msgid, ServerResponse _resp)
|
void PendingCommand::responseReceived(ServerResponse resp)
|
||||||
{
|
{
|
||||||
if (_msgid == msgid) {
|
emit finished(resp);
|
||||||
emit finished(_resp);
|
|
||||||
deleteLater();
|
deleteLater();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PendingCommand::checkTimeout()
|
void PendingCommand::checkTimeout()
|
||||||
|
@ -20,6 +77,54 @@ void PendingCommand::checkTimeout()
|
||||||
emit timeout();
|
emit timeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PendingCommand_ListPlayers::responseReceived(ServerResponse resp)
|
||||||
|
{
|
||||||
|
if (resp == RespOk)
|
||||||
|
emit playerListReceived(playerList);
|
||||||
|
PendingCommand::responseReceived(resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PendingCommand_ListPlayers::addPlayer(const ServerPlayer &player)
|
||||||
|
{
|
||||||
|
playerList.append(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PendingCommand_ListZones::responseReceived(ServerResponse resp)
|
||||||
|
{
|
||||||
|
if (resp == RespOk)
|
||||||
|
emit zoneListReceived(zoneList);
|
||||||
|
PendingCommand::responseReceived(resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PendingCommand_ListZones::addZone(const ServerZone &zone)
|
||||||
|
{
|
||||||
|
zoneList.append(zone);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PendingCommand_DumpZone::responseReceived(ServerResponse resp)
|
||||||
|
{
|
||||||
|
if (resp == RespOk)
|
||||||
|
emit cardListReceived(cardList);
|
||||||
|
PendingCommand::responseReceived(resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PendingCommand_DumpZone::addCard(const ServerZoneCard &card)
|
||||||
|
{
|
||||||
|
cardList.append(card);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PendingCommand_ListCounters::responseReceived(ServerResponse resp)
|
||||||
|
{
|
||||||
|
if (resp == RespOk)
|
||||||
|
emit counterListReceived(counterList);
|
||||||
|
PendingCommand::responseReceived(resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PendingCommand_ListCounters::addCounter(const ServerCounter &counter)
|
||||||
|
{
|
||||||
|
counterList.append(counter);
|
||||||
|
}
|
||||||
|
|
||||||
Client::Client(QObject *parent)
|
Client::Client(QObject *parent)
|
||||||
: QObject(parent), status(StatusDisconnected), MsgId(0)
|
: QObject(parent), status(StatusDisconnected), MsgId(0)
|
||||||
{
|
{
|
||||||
|
@ -59,7 +164,7 @@ void Client::slotConnected()
|
||||||
|
|
||||||
void Client::removePendingCommand()
|
void Client::removePendingCommand()
|
||||||
{
|
{
|
||||||
PendingCommands.removeAt(PendingCommands.indexOf(static_cast<PendingCommand *>(sender())));
|
pendingCommands.remove(static_cast<PendingCommand *>(sender())->getMsgId());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::loginResponse(ServerResponse response)
|
void Client::loginResponse(ServerResponse response)
|
||||||
|
@ -114,14 +219,16 @@ void Client::readLine()
|
||||||
emit chatEvent(ChatEventData(line));
|
emit chatEvent(ChatEventData(line));
|
||||||
} else if (prefix == "resp") {
|
} else if (prefix == "resp") {
|
||||||
if (values.size() != 2) {
|
if (values.size() != 2) {
|
||||||
// XXX
|
qDebug("Client::parseCommand: Invalid response");
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
bool ok;
|
bool ok;
|
||||||
int msgid = values.takeFirst().toInt(&ok);
|
int msgid = values.takeFirst().toInt(&ok);
|
||||||
if (!ok) {
|
PendingCommand *pc = pendingCommands.value(msgid, 0);
|
||||||
// XXX
|
if (!ok || !pc) {
|
||||||
|
qDebug("Client::parseCommand: Invalid msgid");
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerResponse resp;
|
ServerResponse resp;
|
||||||
if (values[0] == "ok")
|
if (values[0] == "ok")
|
||||||
resp = RespOk;
|
resp = RespOk;
|
||||||
|
@ -129,14 +236,14 @@ void Client::readLine()
|
||||||
resp = RespPassword;
|
resp = RespPassword;
|
||||||
else
|
else
|
||||||
resp = RespErr;
|
resp = RespErr;
|
||||||
emit responseReceived(msgid, resp);
|
pc->responseReceived(resp);
|
||||||
} else if (prefix == "list_games") {
|
} else if (prefix == "list_games") {
|
||||||
if (values.size() != 8)
|
if (values.size() != 8)
|
||||||
return;
|
continue;
|
||||||
emit gameListEvent(new ServerGame(values[0].toInt(), values[5], values[1], values[2].toInt(), values[3].toInt(), values[4].toInt(), values[6].toInt(), values[7].toInt()));
|
emit gameListEvent(new ServerGame(values[0].toInt(), values[5], values[1], values[2].toInt(), values[3].toInt(), values[4].toInt(), values[6].toInt(), values[7].toInt()));
|
||||||
} else if (prefix == "welcome") {
|
} else if (prefix == "welcome") {
|
||||||
if (values.size() != 2) {
|
if (values.size() != 2) {
|
||||||
emit protocolVersionMismatch();
|
emit protocolError();
|
||||||
disconnectFromServer();
|
disconnectFromServer();
|
||||||
} else if (values[0].toInt() != protocolVersion) {
|
} else if (values[0].toInt() != protocolVersion) {
|
||||||
emit protocolVersionMismatch();
|
emit protocolVersionMismatch();
|
||||||
|
@ -146,40 +253,45 @@ void Client::readLine()
|
||||||
setStatus(StatusLoggingIn);
|
setStatus(StatusLoggingIn);
|
||||||
login(playerName, password);
|
login(playerName, password);
|
||||||
}
|
}
|
||||||
} else if ((prefix == "list_players") || (prefix == "list_counters") || (prefix == "list_zones") || (prefix == "dump_zone")) {
|
} else if (prefix == "list_players") {
|
||||||
|
if (values.size() != 4) {
|
||||||
|
emit protocolError();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
int cmdid = values.takeFirst().toInt();
|
int cmdid = values.takeFirst().toInt();
|
||||||
if (values[0] == ".") {
|
PendingCommand_ListPlayers *pc = qobject_cast<PendingCommand_ListPlayers *>(pendingCommands.value(cmdid, 0));
|
||||||
QListIterator<QStringList> i(msgbuf);
|
if (!pc) {
|
||||||
QList<ServerPlayer *> playerlist;
|
emit protocolError();
|
||||||
QList<ServerZone *> zonelist;
|
continue;
|
||||||
QList<ServerZoneCard *> zonedump;
|
|
||||||
while (i.hasNext()) {
|
|
||||||
QStringList val = i.next();
|
|
||||||
|
|
||||||
// XXX Parametergültigkeit überprüfen
|
|
||||||
if (prefix == "list_players")
|
|
||||||
playerlist << new ServerPlayer(val[0].toInt(), val[1], val[2].toInt());
|
|
||||||
else if (prefix == "list_counters")
|
|
||||||
{ }
|
|
||||||
else if (prefix == "list_zones")
|
|
||||||
zonelist << new ServerZone(val[0], val[1] == "1", val[2] == "1", val[3].toInt());
|
|
||||||
else if (prefix == "dump_zone")
|
|
||||||
zonedump << new ServerZoneCard(val[0].toInt(), val[1], val[2].toInt(), val[3].toInt(), val[4].toInt(), val[5] == "1", val[6]);
|
|
||||||
}
|
}
|
||||||
if (prefix == "list_players")
|
pc->addPlayer(ServerPlayer(values[0].toInt(), values[1], values[2].toInt()));
|
||||||
emit playerListReceived(playerlist);
|
} else if (prefix == "dump_zone") {
|
||||||
else if (prefix == "list_counters")
|
if (values.size() != 9) {
|
||||||
{ }
|
emit protocolError();
|
||||||
else if (prefix == "list_zones")
|
continue;
|
||||||
emit zoneListReceived(cmdid, zonelist);
|
}
|
||||||
else if (prefix == "dump_zone")
|
int cmdid = values.takeFirst().toInt();
|
||||||
emit zoneDumpReceived(cmdid, zonedump);
|
PendingCommand_DumpZone *pc = qobject_cast<PendingCommand_DumpZone *>(pendingCommands.value(cmdid, 0));
|
||||||
msgbuf.clear();
|
if (!pc) {
|
||||||
|
emit protocolError();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
pc->addCard(ServerZoneCard(values[0].toInt(), values[1], values[2].toInt(), values[3].toInt(), values[4].toInt(), values[5] == "1", values[6] == "1", values[7]));
|
||||||
|
} else if (prefix == "list_zones") {
|
||||||
|
if (values.size() != 5) {
|
||||||
|
emit protocolError();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int cmdid = values.takeFirst().toInt();
|
||||||
|
PendingCommand_ListZones *pc = qobject_cast<PendingCommand_ListZones *>(pendingCommands.value(cmdid, 0));
|
||||||
|
if (!pc) {
|
||||||
|
emit protocolError();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
pc->addZone(ServerZone(values[0], values[1] == "1", values[2] == "1", values[3].toInt()));
|
||||||
|
} else if (prefix == "list_counters") {
|
||||||
} else
|
} else
|
||||||
msgbuf << values;
|
emit protocolError();
|
||||||
} else {
|
|
||||||
// XXX
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,12 +312,16 @@ void Client::msg(const QString &s)
|
||||||
stream.flush();
|
stream.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
PendingCommand *Client::cmd(const QString &s)
|
PendingCommand *Client::cmd(const QString &s, PendingCommand *_pc)
|
||||||
{
|
{
|
||||||
msg(QString("%1|%2").arg(++MsgId).arg(s));
|
msg(QString("%1|%2").arg(++MsgId).arg(s));
|
||||||
PendingCommand *pc = new PendingCommand(s, MsgId, this);
|
PendingCommand *pc;
|
||||||
PendingCommands << pc;
|
if (_pc) {
|
||||||
connect(this, SIGNAL(responseReceived(int, ServerResponse)), pc, SLOT(responseReceived(int, ServerResponse)));
|
pc = _pc;
|
||||||
|
pc->setMsgId(MsgId);
|
||||||
|
} else
|
||||||
|
pc = new PendingCommand(MsgId);
|
||||||
|
pendingCommands.insert(MsgId, pc);
|
||||||
connect(pc, SIGNAL(finished(ServerResponse)), this, SLOT(removePendingCommand()));
|
connect(pc, SIGNAL(finished(ServerResponse)), this, SLOT(removePendingCommand()));
|
||||||
connect(pc, SIGNAL(timeout()), this, SLOT(timeout()));
|
connect(pc, SIGNAL(timeout()), this, SLOT(timeout()));
|
||||||
connect(timer, SIGNAL(timeout()), pc, SLOT(checkTimeout()));
|
connect(timer, SIGNAL(timeout()), pc, SLOT(checkTimeout()));
|
||||||
|
@ -226,9 +342,10 @@ void Client::disconnectFromServer()
|
||||||
{
|
{
|
||||||
timer->stop();
|
timer->stop();
|
||||||
|
|
||||||
for (int i = 0; i < PendingCommands.size(); i++)
|
QList<PendingCommand *> pc = pendingCommands.values();
|
||||||
delete PendingCommands[i];
|
for (int i = 0; i < pc.size(); i++)
|
||||||
PendingCommands.clear();
|
delete pc[i];
|
||||||
|
pendingCommands.clear();
|
||||||
|
|
||||||
setStatus(StatusDisconnected);
|
setStatus(StatusDisconnected);
|
||||||
socket->close();
|
socket->close();
|
||||||
|
@ -244,9 +361,9 @@ PendingCommand *Client::chatListChannels()
|
||||||
return cmd("chat_list_channels");
|
return cmd("chat_list_channels");
|
||||||
}
|
}
|
||||||
|
|
||||||
PendingCommand *Client::chatJoinChannel(const QString &name)
|
PendingCommand_ChatJoinChannel *Client::chatJoinChannel(const QString &name)
|
||||||
{
|
{
|
||||||
return cmd(QString("chat_join_channel|%1").arg(name));
|
return static_cast<PendingCommand_ChatJoinChannel *>(cmd(QString("chat_join_channel|%1").arg(name), new PendingCommand_ChatJoinChannel(name)));
|
||||||
}
|
}
|
||||||
|
|
||||||
PendingCommand *Client::chatLeaveChannel(const QString &name)
|
PendingCommand *Client::chatLeaveChannel(const QString &name)
|
||||||
|
@ -264,9 +381,9 @@ PendingCommand *Client::listGames()
|
||||||
return cmd("list_games");
|
return cmd("list_games");
|
||||||
}
|
}
|
||||||
|
|
||||||
PendingCommand *Client::listPlayers()
|
PendingCommand_ListPlayers *Client::listPlayers()
|
||||||
{
|
{
|
||||||
return cmd("list_players");
|
return static_cast<PendingCommand_ListPlayers *>(cmd("list_players", new PendingCommand_ListPlayers));
|
||||||
}
|
}
|
||||||
|
|
||||||
PendingCommand *Client::createGame(const QString &description, const QString &password, unsigned int maxPlayers, bool spectatorsAllowed)
|
PendingCommand *Client::createGame(const QString &description, const QString &password, unsigned int maxPlayers, bool spectatorsAllowed)
|
||||||
|
@ -368,6 +485,13 @@ PendingCommand *Client::delCounter(const QString &counter)
|
||||||
return cmd(QString("del_counter|%1").arg(counter));
|
return cmd(QString("del_counter|%1").arg(counter));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PendingCommand_ListCounters *Client::listCounters(int playerId)
|
||||||
|
{
|
||||||
|
PendingCommand_ListCounters *pc = new PendingCommand_ListCounters(playerId);
|
||||||
|
cmd(QString("list_counters|%1").arg(playerId), pc);
|
||||||
|
return pc;
|
||||||
|
}
|
||||||
|
|
||||||
PendingCommand *Client::nextTurn()
|
PendingCommand *Client::nextTurn()
|
||||||
{
|
{
|
||||||
return cmd(QString("next_turn"));
|
return cmd(QString("next_turn"));
|
||||||
|
@ -378,9 +502,18 @@ PendingCommand *Client::setActivePhase(int phase)
|
||||||
return cmd(QString("set_active_phase|%1").arg(phase));
|
return cmd(QString("set_active_phase|%1").arg(phase));
|
||||||
}
|
}
|
||||||
|
|
||||||
PendingCommand *Client::dumpZone(int player, const QString &zone, int numberCards)
|
PendingCommand_ListZones *Client::listZones(int playerId)
|
||||||
{
|
{
|
||||||
return cmd(QString("dump_zone|%1|%2|%3").arg(player).arg(zone).arg(numberCards));
|
PendingCommand_ListZones *pc = new PendingCommand_ListZones(playerId);
|
||||||
|
cmd(QString("list_zones|%1").arg(playerId), pc);
|
||||||
|
return pc;
|
||||||
|
}
|
||||||
|
|
||||||
|
PendingCommand_DumpZone *Client::dumpZone(int player, const QString &zone, int numberCards)
|
||||||
|
{
|
||||||
|
PendingCommand_DumpZone *pc = new PendingCommand_DumpZone(player, zone, numberCards);
|
||||||
|
cmd(QString("dump_zone|%1|%2|%3").arg(player).arg(zone).arg(numberCards), pc);
|
||||||
|
return pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
PendingCommand *Client::stopDumpZone(int player, const QString &zone)
|
PendingCommand *Client::stopDumpZone(int player, const QString &zone)
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
#ifndef CLIENT_H
|
#ifndef CLIENT_H
|
||||||
#define CLIENT_H
|
#define CLIENT_H
|
||||||
|
|
||||||
#include "servereventdata.h"
|
|
||||||
#include "servergame.h"
|
|
||||||
#include "serverplayer.h"
|
|
||||||
#include "serverzone.h"
|
|
||||||
#include "serverzonecard.h"
|
|
||||||
#include <QTcpSocket>
|
#include <QTcpSocket>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QHash>
|
||||||
|
|
||||||
class QTimer;
|
class QTimer;
|
||||||
|
|
||||||
|
@ -27,25 +24,242 @@ enum ServerResponse {
|
||||||
RespErr
|
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 {
|
class PendingCommand : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QString cmd;
|
|
||||||
int msgid;
|
int msgid;
|
||||||
int time;
|
int time;
|
||||||
QString extraData;
|
|
||||||
signals:
|
signals:
|
||||||
void finished(ServerResponse resp);
|
void finished(ServerResponse resp);
|
||||||
void timeout();
|
void timeout();
|
||||||
public slots:
|
public slots:
|
||||||
void responseReceived(int _msgid, ServerResponse _resp);
|
virtual void responseReceived(ServerResponse resp);
|
||||||
void checkTimeout();
|
void checkTimeout();
|
||||||
public:
|
public:
|
||||||
|
PendingCommand(int _msgid = -1);
|
||||||
int getMsgId() const { return msgid; }
|
int getMsgId() const { return msgid; }
|
||||||
QString getCmd() const { return cmd; }
|
void setMsgId(int _msgId) { msgid = _msgId; }
|
||||||
const QString &getExtraData() const { return extraData; }
|
};
|
||||||
void setExtraData(const QString &_extraData) { extraData = _extraData; }
|
|
||||||
PendingCommand(const QString &_cmd, int _msgid, QObject *parent = 0);
|
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 {
|
class Client : public QObject {
|
||||||
|
@ -54,10 +268,6 @@ signals:
|
||||||
void statusChanged(ProtocolStatus _status);
|
void statusChanged(ProtocolStatus _status);
|
||||||
void welcomeMsgReceived(QString welcomeMsg);
|
void welcomeMsgReceived(QString welcomeMsg);
|
||||||
void gameListEvent(ServerGame *game);
|
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 playerIdReceived(int id, QString name);
|
||||||
void gameEvent(const ServerEventData &msg);
|
void gameEvent(const ServerEventData &msg);
|
||||||
void chatEvent(const ChatEventData &msg);
|
void chatEvent(const ChatEventData &msg);
|
||||||
|
@ -65,6 +275,7 @@ signals:
|
||||||
void logSocketError(const QString &errorString);
|
void logSocketError(const QString &errorString);
|
||||||
void serverError(ServerResponse resp);
|
void serverError(ServerResponse resp);
|
||||||
void protocolVersionMismatch();
|
void protocolVersionMismatch();
|
||||||
|
void protocolError();
|
||||||
private slots:
|
private slots:
|
||||||
void slotConnected();
|
void slotConnected();
|
||||||
void readLine();
|
void readLine();
|
||||||
|
@ -78,14 +289,13 @@ private slots:
|
||||||
private:
|
private:
|
||||||
static const int protocolVersion = 1;
|
static const int protocolVersion = 1;
|
||||||
QTimer *timer;
|
QTimer *timer;
|
||||||
QList<PendingCommand *> PendingCommands;
|
QMap<int, PendingCommand *> pendingCommands;
|
||||||
QTcpSocket *socket;
|
QTcpSocket *socket;
|
||||||
ProtocolStatus status;
|
ProtocolStatus status;
|
||||||
QList<QStringList> msgbuf;
|
|
||||||
QString playerName, password;
|
QString playerName, password;
|
||||||
unsigned int MsgId;
|
unsigned int MsgId;
|
||||||
void msg(const QString &s);
|
void msg(const QString &s);
|
||||||
PendingCommand *cmd(const QString &s);
|
PendingCommand *cmd(const QString &s, PendingCommand *_pc = 0);
|
||||||
void setStatus(const ProtocolStatus _status);
|
void setStatus(const ProtocolStatus _status);
|
||||||
public:
|
public:
|
||||||
Client(QObject *parent = 0);
|
Client(QObject *parent = 0);
|
||||||
|
@ -97,11 +307,11 @@ public:
|
||||||
void disconnectFromServer();
|
void disconnectFromServer();
|
||||||
public slots:
|
public slots:
|
||||||
PendingCommand *chatListChannels();
|
PendingCommand *chatListChannels();
|
||||||
PendingCommand *chatJoinChannel(const QString &name);
|
PendingCommand_ChatJoinChannel *chatJoinChannel(const QString &name);
|
||||||
PendingCommand *chatLeaveChannel(const QString &name);
|
PendingCommand *chatLeaveChannel(const QString &name);
|
||||||
PendingCommand *chatSay(const QString &name, const QString &s);
|
PendingCommand *chatSay(const QString &name, const QString &s);
|
||||||
PendingCommand *listGames();
|
PendingCommand *listGames();
|
||||||
PendingCommand *listPlayers();
|
PendingCommand_ListPlayers *listPlayers();
|
||||||
PendingCommand *createGame(const QString &description, const QString &password, unsigned int maxPlayers, bool spectatorsAllowed);
|
PendingCommand *createGame(const QString &description, const QString &password, unsigned int maxPlayers, bool spectatorsAllowed);
|
||||||
PendingCommand *joinGame(int gameId, const QString &password, bool spectator);
|
PendingCommand *joinGame(int gameId, const QString &password, bool spectator);
|
||||||
PendingCommand *leaveGame();
|
PendingCommand *leaveGame();
|
||||||
|
@ -119,9 +329,11 @@ public slots:
|
||||||
PendingCommand *addCounter(const QString &counter, QColor color, int value);
|
PendingCommand *addCounter(const QString &counter, QColor color, int value);
|
||||||
PendingCommand *setCounter(const QString &counter, int value);
|
PendingCommand *setCounter(const QString &counter, int value);
|
||||||
PendingCommand *delCounter(const QString &counter);
|
PendingCommand *delCounter(const QString &counter);
|
||||||
|
PendingCommand_ListCounters *listCounters(int playerId);
|
||||||
PendingCommand *nextTurn();
|
PendingCommand *nextTurn();
|
||||||
PendingCommand *setActivePhase(int phase);
|
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);
|
PendingCommand *stopDumpZone(int player, const QString &zone);
|
||||||
void submitDeck(const QStringList &deck);
|
void submitDeck(const QStringList &deck);
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,9 +3,7 @@
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "serverplayer.h"
|
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "servereventdata.h"
|
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
#include "tablezone.h"
|
#include "tablezone.h"
|
||||||
#include "handzone.h"
|
#include "handzone.h"
|
||||||
|
@ -18,7 +16,6 @@ Game::Game(CardDatabase *_db, Client *_client, GameScene *_scene, QMenuBar *menu
|
||||||
: QObject(parent), db(_db), client(_client), scene(_scene), started(false), currentPhase(-1)
|
: QObject(parent), db(_db), client(_client), scene(_scene), started(false), currentPhase(-1)
|
||||||
{
|
{
|
||||||
connect(client, SIGNAL(gameEvent(const ServerEventData &)), this, SLOT(gameEvent(const ServerEventData &)));
|
connect(client, SIGNAL(gameEvent(const ServerEventData &)), this, SLOT(gameEvent(const ServerEventData &)));
|
||||||
connect(client, SIGNAL(playerListReceived(QList<ServerPlayer *>)), this, SLOT(playerListReceived(QList<ServerPlayer *>)));
|
|
||||||
|
|
||||||
aNextPhase = new QAction(this);
|
aNextPhase = new QAction(this);
|
||||||
connect(aNextPhase, SIGNAL(triggered()), this, SLOT(actNextPhase()));
|
connect(aNextPhase, SIGNAL(triggered()), this, SLOT(actNextPhase()));
|
||||||
|
@ -82,7 +79,8 @@ Game::Game(CardDatabase *_db, Client *_client, GameScene *_scene, QMenuBar *menu
|
||||||
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
|
|
||||||
client->listPlayers();
|
PendingCommand_ListPlayers *pc = client->listPlayers();
|
||||||
|
connect(pc, SIGNAL(playerListReceived(QList<ServerPlayer>)), this, SLOT(playerListReceived(QList<ServerPlayer>)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::~Game()
|
Game::~Game()
|
||||||
|
@ -143,18 +141,12 @@ Player *Game::addPlayer(int playerId, const QString &playerName, bool local)
|
||||||
return newPlayer;
|
return newPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::playerListReceived(QList<ServerPlayer *> playerList)
|
void Game::playerListReceived(QList<ServerPlayer> playerList)
|
||||||
{
|
{
|
||||||
QListIterator<ServerPlayer *> i(playerList);
|
|
||||||
QStringList nameList;
|
QStringList nameList;
|
||||||
while (i.hasNext()) {
|
for (int i = 0; i < playerList.size(); ++i) {
|
||||||
ServerPlayer *temp = i.next();
|
nameList << playerList[i].getName();
|
||||||
nameList << temp->getName();
|
addPlayer(playerList[i].getPlayerId(), playerList[i].getName(), playerList[i].getLocal());
|
||||||
int id = temp->getPlayerId();
|
|
||||||
|
|
||||||
addPlayer(id, temp->getName(), temp->getLocal());
|
|
||||||
|
|
||||||
delete temp;
|
|
||||||
}
|
}
|
||||||
emit logPlayerListReceived(nameList);
|
emit logPlayerListReceived(nameList);
|
||||||
restartGameDialog();
|
restartGameDialog();
|
||||||
|
|
|
@ -4,11 +4,10 @@
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include "playerlist.h"
|
#include "playerlist.h"
|
||||||
|
#include "client.h"
|
||||||
|
|
||||||
class ServerPlayer;
|
|
||||||
class GameScene;
|
class GameScene;
|
||||||
class Player;
|
class Player;
|
||||||
class Client;
|
|
||||||
class ServerEventData;
|
class ServerEventData;
|
||||||
class CardDatabase;
|
class CardDatabase;
|
||||||
class DlgStartGame;
|
class DlgStartGame;
|
||||||
|
@ -56,7 +55,7 @@ private slots:
|
||||||
void actMoveToExile(CardItem *card);
|
void actMoveToExile(CardItem *card);
|
||||||
|
|
||||||
void gameEvent(const ServerEventData &msg);
|
void gameEvent(const ServerEventData &msg);
|
||||||
void playerListReceived(QList<ServerPlayer *> playerList);
|
void playerListReceived(QList<ServerPlayer> playerList);
|
||||||
void readyStart();
|
void readyStart();
|
||||||
signals:
|
signals:
|
||||||
void submitDecklist();
|
void submitDecklist();
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include "gamesmodel.h"
|
#include "gamesmodel.h"
|
||||||
#include "servergame.h"
|
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
|
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include "gamesmodel.h"
|
#include "gamesmodel.h"
|
||||||
#include "servergame.h"
|
#include "client.h"
|
||||||
|
|
||||||
GamesModel::~GamesModel()
|
GamesModel::~GamesModel()
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
|
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include "servergame.h"
|
|
||||||
|
class ServerGame;
|
||||||
|
|
||||||
class GamesModel : public QAbstractTableModel {
|
class GamesModel : public QAbstractTableModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
|
@ -45,6 +45,11 @@ void MessageLogWidget::logProtocolVersionMismatch()
|
||||||
append(tr("Protocol version mismatch."));
|
append(tr("Protocol version mismatch."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MessageLogWidget::logProtocolError()
|
||||||
|
{
|
||||||
|
append(tr("Protocol error."));
|
||||||
|
}
|
||||||
|
|
||||||
void MessageLogWidget::logPlayerListReceived(QStringList players)
|
void MessageLogWidget::logPlayerListReceived(QStringList players)
|
||||||
{
|
{
|
||||||
append("---");
|
append("---");
|
||||||
|
|
|
@ -22,6 +22,7 @@ public slots:
|
||||||
void logSocketError(const QString &errorString);
|
void logSocketError(const QString &errorString);
|
||||||
void logServerError(ServerResponse response);
|
void logServerError(ServerResponse response);
|
||||||
void logProtocolVersionMismatch();
|
void logProtocolVersionMismatch();
|
||||||
|
void logProtocolError();
|
||||||
private slots:
|
private slots:
|
||||||
void logPlayerListReceived(QStringList players);
|
void logPlayerListReceived(QStringList players);
|
||||||
void logJoin(Player *player);
|
void logJoin(Player *player);
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
#include "zonelist.h"
|
#include "zonelist.h"
|
||||||
#include "servereventdata.h"
|
|
||||||
|
|
||||||
class Client;
|
class Client;
|
||||||
class CardDatabase;
|
class CardDatabase;
|
||||||
|
@ -15,6 +14,7 @@ class Game;
|
||||||
class Counter;
|
class Counter;
|
||||||
class TableZone;
|
class TableZone;
|
||||||
class HandZone;
|
class HandZone;
|
||||||
|
class ServerEventData;
|
||||||
|
|
||||||
class Player : public QObject, public QGraphicsItem {
|
class Player : public QObject, public QGraphicsItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
|
@ -1,60 +0,0 @@
|
||||||
#include "servereventdata.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("player_id", eventPlayerId);
|
|
||||||
eventHash.insert("say", eventSay);
|
|
||||||
eventHash.insert("name", eventName);
|
|
||||||
eventHash.insert("join", eventJoin);
|
|
||||||
eventHash.insert("leave", eventLeave);
|
|
||||||
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("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");
|
|
||||||
PlayerId = values.takeFirst().toInt();
|
|
||||||
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;
|
|
||||||
}
|
|
|
@ -1,72 +0,0 @@
|
||||||
#ifndef SERVEREVENTDATA_H
|
|
||||||
#define SERVEREVENTDATA_H
|
|
||||||
|
|
||||||
#include <QStringList>
|
|
||||||
#include <QHash>
|
|
||||||
|
|
||||||
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; }
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,27 +0,0 @@
|
||||||
#ifndef SERVERGAME_H
|
|
||||||
#define SERVERGAME_H
|
|
||||||
|
|
||||||
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; }
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,19 +0,0 @@
|
||||||
#ifndef SERVERPLAYER_H
|
|
||||||
#define SERVERPLAYER_H
|
|
||||||
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
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; }
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,21 +0,0 @@
|
||||||
#ifndef SERVERZONE_H
|
|
||||||
#define SERVERZONE_H
|
|
||||||
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
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; }
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,28 +0,0 @@
|
||||||
#ifndef SERVERZONECARD_H
|
|
||||||
#define SERVERZONECARD_H
|
|
||||||
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
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 _attacking, const QString &_annotation)
|
|
||||||
: id(_id), name(_name), x(_x), y(_y), counters(_counters), 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; }
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -307,6 +307,7 @@ MainWindow::MainWindow(QTranslator *_translator, QWidget *parent)
|
||||||
connect(client, SIGNAL(logSocketError(const QString &)), messageLog, SLOT(logSocketError(const QString &)));
|
connect(client, SIGNAL(logSocketError(const QString &)), messageLog, SLOT(logSocketError(const QString &)));
|
||||||
connect(client, SIGNAL(serverError(ServerResponse)), messageLog, SLOT(logServerError(ServerResponse)));
|
connect(client, SIGNAL(serverError(ServerResponse)), messageLog, SLOT(logServerError(ServerResponse)));
|
||||||
connect(client, SIGNAL(protocolVersionMismatch()), messageLog, SLOT(logProtocolVersionMismatch()));
|
connect(client, SIGNAL(protocolVersionMismatch()), messageLog, SLOT(logProtocolVersionMismatch()));
|
||||||
|
connect(client, SIGNAL(protocolError()), messageLog, SLOT(logProtocolError()));
|
||||||
connect(phasesToolbar, SIGNAL(signalSetPhase(int)), client, SLOT(setActivePhase(int)));
|
connect(phasesToolbar, SIGNAL(signalSetPhase(int)), client, SLOT(setActivePhase(int)));
|
||||||
connect(phasesToolbar, SIGNAL(signalNextTurn()), client, SLOT(nextTurn()));
|
connect(phasesToolbar, SIGNAL(signalNextTurn()), client, SLOT(nextTurn()));
|
||||||
connect(phasesToolbar, SIGNAL(signalDrawCard()), client, SLOT(drawCard()));
|
connect(phasesToolbar, SIGNAL(signalDrawCard()), client, SLOT(drawCard()));
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
#include <QGraphicsWidget>
|
#include <QGraphicsWidget>
|
||||||
#include "serverzonecard.h"
|
|
||||||
|
|
||||||
class CardZone;
|
class CardZone;
|
||||||
class ZoneViewZone;
|
class ZoneViewZone;
|
||||||
|
|
|
@ -27,9 +27,8 @@ void ZoneViewZone::paint(QPainter */*painter*/, const QStyleOptionGraphicsItem *
|
||||||
void ZoneViewZone::initializeCards()
|
void ZoneViewZone::initializeCards()
|
||||||
{
|
{
|
||||||
if (!origZone->contentsKnown()) {
|
if (!origZone->contentsKnown()) {
|
||||||
connect(player->client, SIGNAL(zoneDumpReceived(int, QList<ServerZoneCard *>)), this, SLOT(zoneDumpReceived(int, QList<ServerZoneCard *>)));
|
PendingCommand_DumpZone *dumpZoneCommand = player->client->dumpZone(player->getId(), name, numberCards);
|
||||||
PendingCommand *dumpZoneCommand = player->client->dumpZone(player->getId(), name, numberCards);
|
connect(dumpZoneCommand, SIGNAL(cardListReceived(QList<ServerZoneCard>)), this, SLOT(zoneDumpReceived(QList<ServerZoneCard>)));
|
||||||
cmdId = dumpZoneCommand->getMsgId();
|
|
||||||
} else {
|
} else {
|
||||||
const CardList &c = origZone->getCards();
|
const CardList &c = origZone->getCards();
|
||||||
int number = numberCards == -1 ? c.size() : (numberCards < c.size() ? numberCards : c.size());
|
int number = numberCards == -1 ? c.size() : (numberCards < c.size() ? numberCards : c.size());
|
||||||
|
@ -42,18 +41,11 @@ void ZoneViewZone::initializeCards()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneViewZone::zoneDumpReceived(int commandId, QList<ServerZoneCard *> cards)
|
void ZoneViewZone::zoneDumpReceived(QList<ServerZoneCard> cards)
|
||||||
{
|
{
|
||||||
if (commandId != cmdId)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (int i = 0; i < cards.size(); i++) {
|
for (int i = 0; i < cards.size(); i++) {
|
||||||
ServerZoneCard *temp = cards[i];
|
CardItem *card = new CardItem(player->getDb(), cards[i].getName(), i, this);
|
||||||
|
|
||||||
CardItem *card = new CardItem(player->getDb(), temp->getName(), i, this);
|
|
||||||
addCard(card, false, i);
|
addCard(card, false, i);
|
||||||
|
|
||||||
delete temp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
emit contentsChanged();
|
emit contentsChanged();
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#define ZONEVIEWERZONE_H
|
#define ZONEVIEWERZONE_H
|
||||||
|
|
||||||
#include "cardzone.h"
|
#include "cardzone.h"
|
||||||
#include "serverzonecard.h"
|
#include "client.h"
|
||||||
#include <QGraphicsWidget>
|
#include <QGraphicsWidget>
|
||||||
#include <QGraphicsLayoutItem>
|
#include <QGraphicsLayoutItem>
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@ private:
|
||||||
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown);
|
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown);
|
||||||
CardZone *origZone;
|
CardZone *origZone;
|
||||||
bool sortingEnabled;
|
bool sortingEnabled;
|
||||||
int cmdId;
|
|
||||||
public:
|
public:
|
||||||
ZoneViewZone(Player *_p, CardZone *_origZone, int _numberCards = -1, QGraphicsItem *parent = 0);
|
ZoneViewZone(Player *_p, CardZone *_origZone, int _numberCards = -1, QGraphicsItem *parent = 0);
|
||||||
~ZoneViewZone();
|
~ZoneViewZone();
|
||||||
|
@ -30,7 +29,7 @@ public:
|
||||||
public slots:
|
public slots:
|
||||||
void setSortingEnabled(int _sortingEnabled);
|
void setSortingEnabled(int _sortingEnabled);
|
||||||
private slots:
|
private slots:
|
||||||
void zoneDumpReceived(int commandId, QList<ServerZoneCard *> cards);
|
void zoneDumpReceived(QList<ServerZoneCard> cards);
|
||||||
protected:
|
protected:
|
||||||
void addCardImpl(CardItem *card, int x, int y);
|
void addCardImpl(CardItem *card, int x, int y);
|
||||||
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
|
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
|
||||||
|
|
|
@ -30,9 +30,10 @@ protected:
|
||||||
public:
|
public:
|
||||||
Counter(QString _name, int _color, int _count = 0) : name(_name), color(_color), count(_count) { }
|
Counter(QString _name, int _color, int _count = 0) : name(_name), color(_color), count(_count) { }
|
||||||
~Counter() { }
|
~Counter() { }
|
||||||
|
QString getName() const { return name; }
|
||||||
|
int getColor() const { return color; }
|
||||||
int getCount() const { return count; }
|
int getCount() const { return count; }
|
||||||
void setCount(int _count) { count = _count; }
|
void setCount(int _count) { count = _count; }
|
||||||
QString getName() const { return name; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -32,7 +32,5 @@ bool ReturnMessage::sendList(const QStringList &args)
|
||||||
s->msg(QString("%1|%2|%3").arg(cmd)
|
s->msg(QString("%1|%2|%3").arg(cmd)
|
||||||
.arg(msg_id)
|
.arg(msg_id)
|
||||||
.arg(args[i]));
|
.arg(args[i]));
|
||||||
s->msg(QString("%1|%2|.").arg(cmd).arg(msg_id));
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,94 @@
|
||||||
#include "abstractrng.h"
|
#include "abstractrng.h"
|
||||||
#include "chatchannel.h"
|
#include "chatchannel.h"
|
||||||
|
|
||||||
|
QHash<QString, ServerSocket::CommandProperties> ServerSocket::commandHash;
|
||||||
|
|
||||||
ServerSocket::ServerSocket(Server *_server, QObject *parent)
|
ServerSocket::ServerSocket(Server *_server, QObject *parent)
|
||||||
: QTcpSocket(parent), server(_server), game(0), spectator(false), PlayerStatus(StatusNormal), authState(PasswordWrong), acceptsGameListChanges(false)
|
: QTcpSocket(parent), server(_server), game(0), spectator(false), PlayerStatus(StatusNormal), authState(PasswordWrong), acceptsGameListChanges(false)
|
||||||
{
|
{
|
||||||
|
if (commandHash.isEmpty()) {
|
||||||
|
commandHash.insert("ping", CommandProperties(false, false, false, true, QList<QVariant::Type>(), &ServerSocket::cmdPing));
|
||||||
|
commandHash.insert("login", CommandProperties(false, false, false, true, QList<QVariant::Type>()
|
||||||
|
<< QVariant::String
|
||||||
|
<< QVariant::String, &ServerSocket::cmdLogin));
|
||||||
|
commandHash.insert("chat_list_channels", CommandProperties(true, false, false, true, QList<QVariant::Type>(), &ServerSocket::cmdChatListChannels));
|
||||||
|
commandHash.insert("chat_join_channel", CommandProperties(true, false, false, true, QList<QVariant::Type>()
|
||||||
|
<< QVariant::String, &ServerSocket::cmdChatJoinChannel));
|
||||||
|
commandHash.insert("chat_leave_channel", CommandProperties(true, false, false, true, QList<QVariant::Type>()
|
||||||
|
<< QVariant::String, &ServerSocket::cmdChatLeaveChannel));
|
||||||
|
commandHash.insert("chat_say", CommandProperties(true, false, false, true, QList<QVariant::Type>()
|
||||||
|
<< QVariant::String
|
||||||
|
<< QVariant::String, &ServerSocket::cmdChatSay));
|
||||||
|
commandHash.insert("list_games", CommandProperties(true, false, false, true, QList<QVariant::Type>(), &ServerSocket::cmdListGames));
|
||||||
|
commandHash.insert("create_game", CommandProperties(true, false, false, true, QList<QVariant::Type>()
|
||||||
|
<< QVariant::String
|
||||||
|
<< QVariant::String
|
||||||
|
<< QVariant::Int
|
||||||
|
<< QVariant::Bool, &ServerSocket::cmdCreateGame));
|
||||||
|
commandHash.insert("join_game", CommandProperties(true, false, false, true, QList<QVariant::Type>()
|
||||||
|
<< QVariant::Int
|
||||||
|
<< QVariant::String
|
||||||
|
<< QVariant::Bool, &ServerSocket::cmdJoinGame));
|
||||||
|
commandHash.insert("leave_game", CommandProperties(true, true, false, true, QList<QVariant::Type>(), &ServerSocket::cmdLeaveGame));
|
||||||
|
commandHash.insert("list_players", CommandProperties(true, true, false, true, QList<QVariant::Type>(), &ServerSocket::cmdListPlayers));
|
||||||
|
commandHash.insert("say", CommandProperties(true, true, false, false, QList<QVariant::Type>()
|
||||||
|
<< QVariant::String, &ServerSocket::cmdSay));
|
||||||
|
commandHash.insert("submit_deck", CommandProperties(true, true, false, false, QList<QVariant::Type>(), &ServerSocket::cmdSubmitDeck));
|
||||||
|
commandHash.insert("ready_start", CommandProperties(true, true, false, false, QList<QVariant::Type>(), &ServerSocket::cmdReadyStart));
|
||||||
|
commandHash.insert("shuffle", CommandProperties(true, true, true, false, QList<QVariant::Type>(), &ServerSocket::cmdShuffle));
|
||||||
|
commandHash.insert("draw_cards", CommandProperties(true, true, true, false, QList<QVariant::Type>()
|
||||||
|
<< QVariant::Int, &ServerSocket::cmdDrawCards));
|
||||||
|
commandHash.insert("reveal_card", CommandProperties(true, true, true, false, QList<QVariant::Type>()
|
||||||
|
<< QVariant::Int
|
||||||
|
<< QVariant::String, &ServerSocket::cmdRevealCard));
|
||||||
|
commandHash.insert("move_card", CommandProperties(true, true, true, false, QList<QVariant::Type>()
|
||||||
|
<< QVariant::Int
|
||||||
|
<< QVariant::String
|
||||||
|
<< QVariant::String
|
||||||
|
<< QVariant::Int
|
||||||
|
<< QVariant::Int
|
||||||
|
<< QVariant::Bool, &ServerSocket::cmdMoveCard));
|
||||||
|
commandHash.insert("create_token", CommandProperties(true, true, true, false, QList<QVariant::Type>()
|
||||||
|
<< QVariant::String
|
||||||
|
<< QVariant::String
|
||||||
|
<< QVariant::String
|
||||||
|
<< QVariant::Int
|
||||||
|
<< QVariant::Int, &ServerSocket::cmdCreateToken));
|
||||||
|
commandHash.insert("set_card_attr", CommandProperties(true, true, true, false, QList<QVariant::Type>()
|
||||||
|
<< QVariant::String
|
||||||
|
<< QVariant::Int
|
||||||
|
<< QVariant::String
|
||||||
|
<< QVariant::String, &ServerSocket::cmdSetCardAttr));
|
||||||
|
commandHash.insert("inc_counter", CommandProperties(true, true, true, false, QList<QVariant::Type>()
|
||||||
|
<< QVariant::String
|
||||||
|
<< QVariant::Int, &ServerSocket::cmdIncCounter));
|
||||||
|
commandHash.insert("add_counter", CommandProperties(true, true, true, false, QList<QVariant::Type>()
|
||||||
|
<< QVariant::String
|
||||||
|
<< QVariant::Int
|
||||||
|
<< QVariant::Int, &ServerSocket::cmdAddCounter));
|
||||||
|
commandHash.insert("set_counter", CommandProperties(true, true, true, false, QList<QVariant::Type>()
|
||||||
|
<< QVariant::String
|
||||||
|
<< QVariant::Int, &ServerSocket::cmdSetCounter));
|
||||||
|
commandHash.insert("del_counter", CommandProperties(true, true, true, false, QList<QVariant::Type>()
|
||||||
|
<< QVariant::String, &ServerSocket::cmdDelCounter));
|
||||||
|
commandHash.insert("list_counters", CommandProperties(true, true, true, true, QList<QVariant::Type>()
|
||||||
|
<< QVariant::Int, &ServerSocket::cmdListCounters));
|
||||||
|
commandHash.insert("list_zones", CommandProperties(true, true, true, true, QList<QVariant::Type>()
|
||||||
|
<< QVariant::Int, &ServerSocket::cmdListZones));
|
||||||
|
commandHash.insert("dump_zone", CommandProperties(true, true, true, true, QList<QVariant::Type>()
|
||||||
|
<< QVariant::Int
|
||||||
|
<< QVariant::String
|
||||||
|
<< QVariant::Int, &ServerSocket::cmdDumpZone));
|
||||||
|
commandHash.insert("stop_dump_zone", CommandProperties(true, true, true, true, QList<QVariant::Type>()
|
||||||
|
<< QVariant::Int
|
||||||
|
<< QVariant::String, &ServerSocket::cmdStopDumpZone));
|
||||||
|
commandHash.insert("roll_die", CommandProperties(true, true, true, false, QList<QVariant::Type>()
|
||||||
|
<< QVariant::Int, &ServerSocket::cmdRollDie));
|
||||||
|
commandHash.insert("next_turn", CommandProperties(true, true, true, false, QList<QVariant::Type>(), &ServerSocket::cmdNextTurn));
|
||||||
|
commandHash.insert("set_active_phase", CommandProperties(true, true, true, false, QList<QVariant::Type>()
|
||||||
|
<< QVariant::Int, &ServerSocket::cmdSetActivePhase));
|
||||||
|
}
|
||||||
|
|
||||||
remsg = new ReturnMessage(this);
|
remsg = new ReturnMessage(this);
|
||||||
connect(this, SIGNAL(readyRead()), this, SLOT(readClient()));
|
connect(this, SIGNAL(readyRead()), this, SLOT(readClient()));
|
||||||
connect(this, SIGNAL(disconnected()), this, SLOT(deleteLater()));
|
connect(this, SIGNAL(disconnected()), this, SLOT(deleteLater()));
|
||||||
|
@ -165,67 +250,6 @@ void ServerSocket::readClient()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const ServerSocket::CommandProperties ServerSocket::commandList[ServerSocket::numberCommands] = {
|
|
||||||
{"ping", false, false, false, true, QList<QVariant::Type>(), &ServerSocket::cmdPing},
|
|
||||||
{"login", false, false, false, true, QList<QVariant::Type>() << QVariant::String
|
|
||||||
<< QVariant::String, &ServerSocket::cmdLogin},
|
|
||||||
{"chat_list_channels", true, false, false, true, QList<QVariant::Type>(), &ServerSocket::cmdChatListChannels},
|
|
||||||
{"chat_join_channel", true, false, false, true, QList<QVariant::Type>() << QVariant::String, &ServerSocket::cmdChatJoinChannel},
|
|
||||||
{"chat_leave_channel", true, false, false, true, QList<QVariant::Type>() << QVariant::String, &ServerSocket::cmdChatLeaveChannel},
|
|
||||||
{"chat_say", true, false, false, true, QList<QVariant::Type>() << QVariant::String
|
|
||||||
<< QVariant::String, &ServerSocket::cmdChatSay},
|
|
||||||
{"list_games", true, false, false, true, QList<QVariant::Type>(), &ServerSocket::cmdListGames},
|
|
||||||
{"create_game", true, false, false, true, QList<QVariant::Type>() << QVariant::String
|
|
||||||
<< QVariant::String
|
|
||||||
<< QVariant::Int
|
|
||||||
<< QVariant::Bool, &ServerSocket::cmdCreateGame},
|
|
||||||
{"join_game", true, false, false, true, QList<QVariant::Type>() << QVariant::Int
|
|
||||||
<< QVariant::String
|
|
||||||
<< QVariant::Bool, &ServerSocket::cmdJoinGame},
|
|
||||||
{"leave_game", true, true, false, true, QList<QVariant::Type>(), &ServerSocket::cmdLeaveGame},
|
|
||||||
{"list_players", true, true, false, true, QList<QVariant::Type>(), &ServerSocket::cmdListPlayers},
|
|
||||||
{"say", true, true, false, false, QList<QVariant::Type>() << QVariant::String, &ServerSocket::cmdSay},
|
|
||||||
{"submit_deck", true, true, false, false, QList<QVariant::Type>(), &ServerSocket::cmdSubmitDeck},
|
|
||||||
{"ready_start", true, true, false, false, QList<QVariant::Type>(), &ServerSocket::cmdReadyStart},
|
|
||||||
{"shuffle", true, true, true, false, QList<QVariant::Type>(), &ServerSocket::cmdShuffle},
|
|
||||||
{"draw_cards", true, true, true, false, QList<QVariant::Type>() << QVariant::Int, &ServerSocket::cmdDrawCards},
|
|
||||||
{"reveal_card", true, true, true, false, QList<QVariant::Type>() << QVariant::Int
|
|
||||||
<< QVariant::String, &ServerSocket::cmdRevealCard},
|
|
||||||
{"move_card", true, true, true, false, QList<QVariant::Type>() << QVariant::Int
|
|
||||||
<< QVariant::String
|
|
||||||
<< QVariant::String
|
|
||||||
<< QVariant::Int
|
|
||||||
<< QVariant::Int
|
|
||||||
<< QVariant::Bool, &ServerSocket::cmdMoveCard},
|
|
||||||
{"create_token", true, true, true, false, QList<QVariant::Type>() << QVariant::String
|
|
||||||
<< QVariant::String
|
|
||||||
<< QVariant::String
|
|
||||||
<< QVariant::Int
|
|
||||||
<< QVariant::Int, &ServerSocket::cmdCreateToken},
|
|
||||||
{"set_card_attr", true, true, true, false, QList<QVariant::Type>() << QVariant::String
|
|
||||||
<< QVariant::Int
|
|
||||||
<< QVariant::String
|
|
||||||
<< QVariant::String, &ServerSocket::cmdSetCardAttr},
|
|
||||||
{"inc_counter", true, true, true, false, QList<QVariant::Type>() << QVariant::String
|
|
||||||
<< QVariant::Int, &ServerSocket::cmdIncCounter},
|
|
||||||
{"add_counter", true, true, true, false, QList<QVariant::Type>() << QVariant::String
|
|
||||||
<< QVariant::Int
|
|
||||||
<< QVariant::Int, &ServerSocket::cmdAddCounter},
|
|
||||||
{"set_counter", true, true, true, false, QList<QVariant::Type>() << QVariant::String
|
|
||||||
<< QVariant::Int, &ServerSocket::cmdSetCounter},
|
|
||||||
{"del_counter", true, true, true, false, QList<QVariant::Type>() << QVariant::String, &ServerSocket::cmdDelCounter},
|
|
||||||
{"list_counters", true, true, true, true, QList<QVariant::Type>() << QVariant::Int, &ServerSocket::cmdListCounters},
|
|
||||||
{"list_zones", true, true, true, true, QList<QVariant::Type>() << QVariant::Int, &ServerSocket::cmdListZones},
|
|
||||||
{"dump_zone", true, true, true, true, QList<QVariant::Type>() << QVariant::Int
|
|
||||||
<< QVariant::String
|
|
||||||
<< QVariant::Int, &ServerSocket::cmdDumpZone},
|
|
||||||
{"stop_dump_zone", true, true, true, true, QList<QVariant::Type>() << QVariant::Int
|
|
||||||
<< QVariant::String, &ServerSocket::cmdStopDumpZone},
|
|
||||||
{"roll_die", true, true, true, false, QList<QVariant::Type>() << QVariant::Int, &ServerSocket::cmdRollDie},
|
|
||||||
{"next_turn", true, true, true, false, QList<QVariant::Type>(), &ServerSocket::cmdNextTurn},
|
|
||||||
{"set_active_phase", true, true, true, false, QList<QVariant::Type>() << QVariant::Int, &ServerSocket::cmdSetActivePhase}
|
|
||||||
};
|
|
||||||
|
|
||||||
ReturnMessage::ReturnCode ServerSocket::cmdPing(const QList<QVariant> &/*params*/)
|
ReturnMessage::ReturnCode ServerSocket::cmdPing(const QList<QVariant> &/*params*/)
|
||||||
{
|
{
|
||||||
return ReturnMessage::ReturnOk;
|
return ReturnMessage::ReturnOk;
|
||||||
|
@ -614,7 +638,13 @@ ReturnMessage::ReturnCode ServerSocket::cmdListCounters(const QList<QVariant> &p
|
||||||
ServerSocket *player = game->getPlayer(player_id);
|
ServerSocket *player = game->getPlayer(player_id);
|
||||||
if (!player)
|
if (!player)
|
||||||
return ReturnMessage::ReturnContextError;
|
return ReturnMessage::ReturnContextError;
|
||||||
remsg->sendList(player->listCounters());
|
|
||||||
|
QStringList result;
|
||||||
|
const QList<Counter *> &counterList = player->getCounters();
|
||||||
|
for (int i = 0; i < counterList.size(); ++i)
|
||||||
|
result << QString("%1|%2|%3").arg(counterList[i]->getName()).arg(counterList[i]->getColor()).arg(counterList[i]->getCount());
|
||||||
|
|
||||||
|
remsg->sendList(result);
|
||||||
return ReturnMessage::ReturnOk;
|
return ReturnMessage::ReturnOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -624,7 +654,12 @@ ReturnMessage::ReturnCode ServerSocket::cmdListZones(const QList<QVariant> ¶
|
||||||
ServerSocket *player = game->getPlayer(player_id);
|
ServerSocket *player = game->getPlayer(player_id);
|
||||||
if (!player)
|
if (!player)
|
||||||
return ReturnMessage::ReturnContextError;
|
return ReturnMessage::ReturnContextError;
|
||||||
remsg->sendList(player->listZones());
|
|
||||||
|
QStringList result;
|
||||||
|
const QList<PlayerZone *> &zoneList = player->getZones();
|
||||||
|
for (int i = 0; i < zoneList.size(); ++i)
|
||||||
|
result << QString("%1|%2|%3|%4").arg(zoneList[i]->getName()).arg(zoneList[i]->getType() == PlayerZone::PublicZone ? 1 : 0).arg(zoneList[i]->hasCoords()).arg(zoneList[i]->cards.size());
|
||||||
|
remsg->sendList(result);
|
||||||
return ReturnMessage::ReturnOk;
|
return ReturnMessage::ReturnOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -660,8 +695,8 @@ ReturnMessage::ReturnCode ServerSocket::cmdDumpZone(const QList<QVariant> ¶m
|
||||||
result << QString("%1|%2||||||").arg(i).arg(tmp->getName());
|
result << QString("%1|%2||||||").arg(i).arg(tmp->getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
remsg->sendList(result);
|
|
||||||
emit broadcastEvent(QString("dump_zone|%1|%2|%3").arg(player_id).arg(zone->getName()).arg(number_cards), this);
|
emit broadcastEvent(QString("dump_zone|%1|%2|%3").arg(player_id).arg(zone->getName()).arg(number_cards), this);
|
||||||
|
remsg->sendList(result);
|
||||||
return ReturnMessage::ReturnOk;
|
return ReturnMessage::ReturnOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -727,26 +762,28 @@ bool ServerSocket::parseCommand(QString line)
|
||||||
|
|
||||||
// Extract command
|
// Extract command
|
||||||
QString cmd = params.takeFirst();
|
QString cmd = params.takeFirst();
|
||||||
|
if (!commandHash.contains(cmd))
|
||||||
|
return remsg->send(ReturnMessage::ReturnSyntaxError);
|
||||||
remsg->setCmd(cmd);
|
remsg->setCmd(cmd);
|
||||||
|
|
||||||
for (int i = 0; i < numberCommands; i++)
|
const CommandProperties &cp = commandHash[cmd];
|
||||||
if (commandList[i].name == cmd) {
|
|
||||||
// Check login
|
// Check login
|
||||||
if (commandList[i].needsLogin && (authState == PasswordWrong))
|
if (cp.getNeedsLogin() && (authState == PasswordWrong))
|
||||||
return remsg->send(ReturnMessage::ReturnLoginNeeded);
|
return remsg->send(ReturnMessage::ReturnLoginNeeded);
|
||||||
// Check context
|
// Check context
|
||||||
if (!commandList[i].allowedToSpectator && spectator)
|
if (!cp.getAllowedToSpectator() && spectator)
|
||||||
return remsg->send(ReturnMessage::ReturnContextError);
|
return remsg->send(ReturnMessage::ReturnContextError);
|
||||||
if (commandList[i].needsGame && !game)
|
if (cp.getNeedsGame() && !game)
|
||||||
return remsg->send(ReturnMessage::ReturnContextError);
|
return remsg->send(ReturnMessage::ReturnContextError);
|
||||||
if (commandList[i].needsStartedGame && !game->getGameStarted())
|
if (cp.getNeedsStartedGame() && !game->getGameStarted())
|
||||||
return remsg->send(ReturnMessage::ReturnContextError);
|
return remsg->send(ReturnMessage::ReturnContextError);
|
||||||
// Validate parameters
|
// Validate parameters
|
||||||
if (commandList[i].paramTypes.size() != params.size())
|
if (cp.getParamTypes().size() != params.size())
|
||||||
return remsg->send(ReturnMessage::ReturnSyntaxError);
|
return remsg->send(ReturnMessage::ReturnSyntaxError);
|
||||||
QList<QVariant> paramList;
|
QList<QVariant> paramList;
|
||||||
for (int j = 0; j < commandList[i].paramTypes.size(); j++)
|
for (int j = 0; j < cp.getParamTypes().size(); j++)
|
||||||
switch (commandList[i].paramTypes[j]) {
|
switch (cp.getParamTypes()[j]) {
|
||||||
case QVariant::String: {
|
case QVariant::String: {
|
||||||
paramList << QVariant(params[j]);
|
paramList << QVariant(params[j]);
|
||||||
break;
|
break;
|
||||||
|
@ -772,10 +809,7 @@ bool ServerSocket::parseCommand(QString line)
|
||||||
paramList << QVariant(params[j]);
|
paramList << QVariant(params[j]);
|
||||||
}
|
}
|
||||||
// Call handler function
|
// Call handler function
|
||||||
CommandHandler handler = commandList[i].handler;
|
return remsg->send((this->*(cp.getHandler()))(paramList));
|
||||||
return remsg->send((this->*handler)(paramList));
|
|
||||||
}
|
|
||||||
return remsg->send(ReturnMessage::ReturnSyntaxError);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerSocket::privateEvent(const QString &line)
|
void ServerSocket::privateEvent(const QString &line)
|
||||||
|
@ -788,28 +822,6 @@ void ServerSocket::setGame(ServerGame *g)
|
||||||
game = g;
|
game = g;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList ServerSocket::listCounters() const
|
|
||||||
{
|
|
||||||
QStringList counter_list;
|
|
||||||
QListIterator<Counter *> i(counters);
|
|
||||||
while (i.hasNext()) {
|
|
||||||
Counter *tmp = i.next();
|
|
||||||
counter_list << QString("%1|%2").arg(tmp->getName()).arg(tmp->getCount());
|
|
||||||
}
|
|
||||||
return counter_list;
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList ServerSocket::listZones() const
|
|
||||||
{
|
|
||||||
QStringList zone_list;
|
|
||||||
QListIterator<PlayerZone *> i(zones);
|
|
||||||
while (i.hasNext()) {
|
|
||||||
PlayerZone *tmp = i.next();
|
|
||||||
zone_list << QString("%1|%2|%3|%4").arg(tmp->getName()).arg(tmp->getType() == PlayerZone::PublicZone ? 1 : 0).arg(tmp->hasCoords()).arg(tmp->cards.size());
|
|
||||||
}
|
|
||||||
return zone_list;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ServerSocket::msg(const QString &s)
|
void ServerSocket::msg(const QString &s)
|
||||||
{
|
{
|
||||||
qDebug(QString("OUT id=%1 name=%2 >>> %3").arg(playerId).arg(playerName).arg(s).toLatin1());
|
qDebug(QString("OUT id=%1 name=%2 >>> %3").arg(playerId).arg(playerName).arg(s).toLatin1());
|
||||||
|
|
|
@ -46,17 +46,25 @@ signals:
|
||||||
void startGameIfReady();
|
void startGameIfReady();
|
||||||
private:
|
private:
|
||||||
typedef ReturnMessage::ReturnCode (ServerSocket::*CommandHandler)(const QList<QVariant> &);
|
typedef ReturnMessage::ReturnCode (ServerSocket::*CommandHandler)(const QList<QVariant> &);
|
||||||
struct CommandProperties {
|
class CommandProperties {
|
||||||
QString name;
|
private:
|
||||||
bool needsLogin;
|
bool needsLogin;
|
||||||
bool needsGame;
|
bool needsGame;
|
||||||
bool needsStartedGame;
|
bool needsStartedGame;
|
||||||
bool allowedToSpectator;
|
bool allowedToSpectator;
|
||||||
QList<QVariant::Type> paramTypes;
|
QList<QVariant::Type> paramTypes;
|
||||||
CommandHandler handler;
|
CommandHandler handler;
|
||||||
|
public:
|
||||||
|
CommandProperties(bool _needsLogin = false, bool _needsGame = false, bool _needsStartedGame = false, bool _allowedToSpectator = false, const QList<QVariant::Type> &_paramTypes = QList<QVariant::Type>(), CommandHandler _handler = 0)
|
||||||
|
: needsLogin(_needsLogin), needsGame(_needsGame), needsStartedGame(_needsStartedGame), allowedToSpectator(_allowedToSpectator), paramTypes(_paramTypes), handler(_handler) { }
|
||||||
|
bool getNeedsLogin() const { return needsLogin; }
|
||||||
|
bool getNeedsGame() const { return needsGame; }
|
||||||
|
bool getNeedsStartedGame() const { return needsStartedGame; }
|
||||||
|
bool getAllowedToSpectator() const { return allowedToSpectator; }
|
||||||
|
const QList<QVariant::Type> &getParamTypes() const { return paramTypes; }
|
||||||
|
CommandHandler getHandler() const { return handler; }
|
||||||
};
|
};
|
||||||
static const int numberCommands = 31;
|
static QHash<QString, CommandProperties> commandHash;
|
||||||
static const CommandProperties commandList[numberCommands];
|
|
||||||
|
|
||||||
ReturnMessage::ReturnCode cmdPing(const QList<QVariant> ¶ms);
|
ReturnMessage::ReturnCode cmdPing(const QList<QVariant> ¶ms);
|
||||||
ReturnMessage::ReturnCode cmdLogin(const QList<QVariant> ¶ms);
|
ReturnMessage::ReturnCode cmdLogin(const QList<QVariant> ¶ms);
|
||||||
|
@ -127,8 +135,8 @@ public:
|
||||||
QString getPlayerName() const { return playerName; }
|
QString getPlayerName() const { return playerName; }
|
||||||
bool getAcceptsGameListChanges() const { return acceptsGameListChanges; }
|
bool getAcceptsGameListChanges() const { return acceptsGameListChanges; }
|
||||||
bool getAcceptsChatChannelListChanges() const { return acceptsChatChannelListChanges; }
|
bool getAcceptsChatChannelListChanges() const { return acceptsChatChannelListChanges; }
|
||||||
QStringList listCounters() const;
|
const QList<PlayerZone *> &getZones() const { return zones; }
|
||||||
QStringList listZones() const;
|
const QList<Counter *> &getCounters() const { return counters; }
|
||||||
void setupZones();
|
void setupZones();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue