initial commit of local server code
This commit is contained in:
parent
cbfbc542e7
commit
7921b5f82d
35 changed files with 143 additions and 365 deletions
|
@ -6,13 +6,15 @@ MOC_DIR = build
|
||||||
OBJECTS_DIR = build
|
OBJECTS_DIR = build
|
||||||
RESOURCES = cockatrice.qrc
|
RESOURCES = cockatrice.qrc
|
||||||
QT += network svg
|
QT += network svg
|
||||||
|
CONFIG += debug
|
||||||
|
|
||||||
HEADERS += src/counter.h \
|
HEADERS += src/counter.h \
|
||||||
src/dlg_creategame.h \
|
src/dlg_creategame.h \
|
||||||
src/dlg_connect.h \
|
src/dlg_connect.h \
|
||||||
src/dlg_create_token.h \
|
src/dlg_create_token.h \
|
||||||
src/gamesmodel.h \
|
src/gamesmodel.h \
|
||||||
src/client.h \
|
src/abstractclient.h \
|
||||||
|
src/remoteclient.h \
|
||||||
src/window_main.h \
|
src/window_main.h \
|
||||||
src/cardzone.h \
|
src/cardzone.h \
|
||||||
src/player.h \
|
src/player.h \
|
||||||
|
@ -58,17 +60,33 @@ HEADERS += src/counter.h \
|
||||||
src/playerlistwidget.h \
|
src/playerlistwidget.h \
|
||||||
src/pingpixmapgenerator.h \
|
src/pingpixmapgenerator.h \
|
||||||
src/settingscache.h \
|
src/settingscache.h \
|
||||||
|
src/localserver.h \
|
||||||
|
src/localserverinterface.h \
|
||||||
|
src/localclient.h \
|
||||||
../common/serializable_item.h \
|
../common/serializable_item.h \
|
||||||
../common/decklist.h \
|
../common/decklist.h \
|
||||||
../common/protocol.h \
|
../common/protocol.h \
|
||||||
../common/protocol_items.h \
|
../common/protocol_items.h \
|
||||||
../common/protocol_datastructures.h
|
../common/protocol_datastructures.h \
|
||||||
|
../common/rng_abstract.h \
|
||||||
|
../common/rng_qt.h \
|
||||||
|
../common/server.h \
|
||||||
|
../common/server_arrow.h \
|
||||||
|
../common/server_card.h \
|
||||||
|
../common/server_cardzone.h \
|
||||||
|
../common/server_chatchannel.h \
|
||||||
|
../common/server_counter.h \
|
||||||
|
../common/server_game.h \
|
||||||
|
../common/server_player.h \
|
||||||
|
../common/server_protocolhandler.h \
|
||||||
|
../common/server_arrowtarget.h
|
||||||
|
|
||||||
SOURCES += src/counter.cpp \
|
SOURCES += src/counter.cpp \
|
||||||
src/dlg_creategame.cpp \
|
src/dlg_creategame.cpp \
|
||||||
src/dlg_connect.cpp \
|
src/dlg_connect.cpp \
|
||||||
src/dlg_create_token.cpp \
|
src/dlg_create_token.cpp \
|
||||||
src/client.cpp \
|
src/abstractclient.cpp \
|
||||||
|
src/remoteclient.cpp \
|
||||||
src/main.cpp \
|
src/main.cpp \
|
||||||
src/window_main.cpp \
|
src/window_main.cpp \
|
||||||
src/gamesmodel.cpp \
|
src/gamesmodel.cpp \
|
||||||
|
@ -115,12 +133,24 @@ SOURCES += src/counter.cpp \
|
||||||
src/playerlistwidget.cpp \
|
src/playerlistwidget.cpp \
|
||||||
src/pingpixmapgenerator.cpp \
|
src/pingpixmapgenerator.cpp \
|
||||||
src/settingscache.cpp \
|
src/settingscache.cpp \
|
||||||
|
src/localserver.cpp \
|
||||||
|
src/localserverinterface.cpp \
|
||||||
|
src/localclient.cpp \
|
||||||
../common/serializable_item.cpp \
|
../common/serializable_item.cpp \
|
||||||
../common/decklist.cpp \
|
../common/decklist.cpp \
|
||||||
../common/protocol.cpp \
|
../common/protocol.cpp \
|
||||||
../common/protocol_items.cpp \
|
../common/protocol_items.cpp \
|
||||||
../common/protocol_datastructures.cpp
|
../common/protocol_datastructures.cpp \
|
||||||
|
../common/rng_abstract.cpp \
|
||||||
|
../common/rng_qt.cpp \
|
||||||
|
../common/server.cpp \
|
||||||
|
../common/server_card.cpp \
|
||||||
|
../common/server_cardzone.cpp \
|
||||||
|
../common/server_chatchannel.cpp \
|
||||||
|
../common/server_game.cpp \
|
||||||
|
../common/server_player.cpp \
|
||||||
|
../common/server_protocolhandler.cpp
|
||||||
|
|
||||||
TRANSLATIONS += translations/cockatrice_de.ts translations/cockatrice_en.ts
|
TRANSLATIONS += translations/cockatrice_de.ts translations/cockatrice_en.ts
|
||||||
win32 {
|
win32 {
|
||||||
RC_FILE = cockatrice.rc
|
RC_FILE = cockatrice.rc
|
||||||
|
|
|
@ -1,194 +0,0 @@
|
||||||
#include <QTimer>
|
|
||||||
#include <QXmlStreamReader>
|
|
||||||
#include <QXmlStreamWriter>
|
|
||||||
#include "client.h"
|
|
||||||
#include "protocol.h"
|
|
||||||
#include "protocol_items.h"
|
|
||||||
|
|
||||||
Client::Client(QObject *parent)
|
|
||||||
: QObject(parent), topLevelItem(0), status(StatusDisconnected)
|
|
||||||
{
|
|
||||||
ProtocolItem::initializeHash();
|
|
||||||
|
|
||||||
timer = new QTimer(this);
|
|
||||||
timer->setInterval(1000);
|
|
||||||
connect(timer, SIGNAL(timeout()), this, SLOT(ping()));
|
|
||||||
|
|
||||||
socket = new QTcpSocket(this);
|
|
||||||
connect(socket, SIGNAL(connected()), this, SLOT(slotConnected()));
|
|
||||||
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()
|
|
||||||
{
|
|
||||||
disconnectFromServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Client::slotSocketError(QAbstractSocket::SocketError /*error*/)
|
|
||||||
{
|
|
||||||
emit socketError(socket->errorString());
|
|
||||||
disconnectFromServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Client::slotConnected()
|
|
||||||
{
|
|
||||||
timer->start();
|
|
||||||
setStatus(StatusAwaitingWelcome);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Client::loginResponse(ResponseCode response)
|
|
||||||
{
|
|
||||||
if (response == RespOk)
|
|
||||||
setStatus(StatusLoggedIn);
|
|
||||||
else {
|
|
||||||
emit serverError(response);
|
|
||||||
setStatus(StatusDisconnecting);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Client::readData()
|
|
||||||
{
|
|
||||||
QByteArray data = socket->readAll();
|
|
||||||
qDebug() << data;
|
|
||||||
xmlReader->addData(data);
|
|
||||||
|
|
||||||
while (!xmlReader->atEnd()) {
|
|
||||||
xmlReader->readNext();
|
|
||||||
if (topLevelItem)
|
|
||||||
topLevelItem->readElement(xmlReader);
|
|
||||||
else if (xmlReader->isStartElement() && (xmlReader->name().toString() == "cockatrice_server_stream")) {
|
|
||||||
int serverVersion = xmlReader->attributes().value("version").toString().toInt();
|
|
||||||
if (serverVersion != ProtocolItem::protocolVersion) {
|
|
||||||
emit protocolVersionMismatch(ProtocolItem::protocolVersion, serverVersion);
|
|
||||||
disconnectFromServer();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
xmlWriter->writeStartDocument();
|
|
||||||
xmlWriter->writeStartElement("cockatrice_client_stream");
|
|
||||||
xmlWriter->writeAttribute("version", QString::number(ProtocolItem::protocolVersion));
|
|
||||||
|
|
||||||
topLevelItem = new TopLevelProtocolItem;
|
|
||||||
connect(topLevelItem, SIGNAL(protocolItemReceived(ProtocolItem *)), this, SLOT(processProtocolItem(ProtocolItem *)));
|
|
||||||
|
|
||||||
setStatus(StatusLoggingIn);
|
|
||||||
Command_Login *cmdLogin = new Command_Login(userName, password);
|
|
||||||
connect(cmdLogin, SIGNAL(finished(ResponseCode)), this, SLOT(loginResponse(ResponseCode)));
|
|
||||||
sendCommand(cmdLogin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (status == StatusDisconnecting)
|
|
||||||
disconnectFromServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Client::processProtocolItem(ProtocolItem *item)
|
|
||||||
{
|
|
||||||
ProtocolResponse *response = qobject_cast<ProtocolResponse *>(item);
|
|
||||||
if (response) {
|
|
||||||
CommandContainer *cmdCont = pendingCommands.value(response->getCmdId(), 0);
|
|
||||||
if (!cmdCont)
|
|
||||||
return;
|
|
||||||
|
|
||||||
pendingCommands.remove(cmdCont->getCmdId());
|
|
||||||
cmdCont->processResponse(response);
|
|
||||||
delete response;
|
|
||||||
delete cmdCont;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
GenericEvent *genericEvent = qobject_cast<GenericEvent *>(item);
|
|
||||||
if (genericEvent) {
|
|
||||||
switch (genericEvent->getItemId()) {
|
|
||||||
case ItemId_Event_ListGames: emit listGamesEventReceived(qobject_cast<Event_ListGames *>(item)); break;
|
|
||||||
case ItemId_Event_ServerMessage: emit serverMessageEventReceived(qobject_cast<Event_ServerMessage *>(item)); break;
|
|
||||||
case ItemId_Event_ListChatChannels: emit listChatChannelsEventReceived(qobject_cast<Event_ListChatChannels *>(item)); break;
|
|
||||||
case ItemId_Event_GameJoined: emit gameJoinedEventReceived(qobject_cast<Event_GameJoined *>(item)); break;
|
|
||||||
}
|
|
||||||
delete genericEvent;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
GameEventContainer *gameEventContainer = qobject_cast<GameEventContainer *>(item);
|
|
||||||
if (gameEventContainer) {
|
|
||||||
emit gameEventContainerReceived(gameEventContainer);
|
|
||||||
delete gameEventContainer;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ChatEvent *chatEvent = qobject_cast<ChatEvent *>(item);
|
|
||||||
if (chatEvent) {
|
|
||||||
emit chatEventReceived(chatEvent);
|
|
||||||
delete chatEvent;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Client::setStatus(const ClientStatus _status)
|
|
||||||
{
|
|
||||||
if (_status != status) {
|
|
||||||
status = _status;
|
|
||||||
emit statusChanged(_status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Client::sendCommand(Command *cmd)
|
|
||||||
{
|
|
||||||
sendCommandContainer(new CommandContainer(QList<Command *>() << cmd));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Client::sendCommandContainer(CommandContainer *cont)
|
|
||||||
{
|
|
||||||
cont->write(xmlWriter);
|
|
||||||
pendingCommands.insert(cont->getCmdId(), cont);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Client::connectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password)
|
|
||||||
{
|
|
||||||
disconnectFromServer();
|
|
||||||
|
|
||||||
userName = _userName;
|
|
||||||
password = _password;
|
|
||||||
socket->connectToHost(hostname, port);
|
|
||||||
setStatus(StatusConnecting);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Client::disconnectFromServer()
|
|
||||||
{
|
|
||||||
delete topLevelItem;
|
|
||||||
topLevelItem = 0;
|
|
||||||
|
|
||||||
xmlReader->clear();
|
|
||||||
|
|
||||||
timer->stop();
|
|
||||||
|
|
||||||
QList<CommandContainer *> pc = pendingCommands.values();
|
|
||||||
for (int i = 0; i < pc.size(); i++)
|
|
||||||
delete pc[i];
|
|
||||||
pendingCommands.clear();
|
|
||||||
|
|
||||||
setStatus(StatusDisconnected);
|
|
||||||
socket->close();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Client::ping()
|
|
||||||
{
|
|
||||||
int maxTime = 0;
|
|
||||||
QMapIterator<int, CommandContainer *> i(pendingCommands);
|
|
||||||
while (i.hasNext()) {
|
|
||||||
int time = i.next().value()->tick();
|
|
||||||
if (time > maxTime)
|
|
||||||
maxTime = time;
|
|
||||||
}
|
|
||||||
emit maxPingTime(maxTime, maxTimeout);
|
|
||||||
if (maxTime >= maxTimeout) {
|
|
||||||
emit serverTimeout();
|
|
||||||
disconnectFromServer();
|
|
||||||
} else
|
|
||||||
sendCommand(new Command_Ping);
|
|
||||||
}
|
|
|
@ -1,88 +0,0 @@
|
||||||
#ifndef CLIENT_H
|
|
||||||
#define CLIENT_H
|
|
||||||
|
|
||||||
#include <QTcpSocket>
|
|
||||||
#include <QColor>
|
|
||||||
#include <QStringList>
|
|
||||||
#include <QHash>
|
|
||||||
#include "protocol_datastructures.h"
|
|
||||||
|
|
||||||
class QTimer;
|
|
||||||
class Command;
|
|
||||||
class CommandContainer;
|
|
||||||
class QXmlStreamReader;
|
|
||||||
class QXmlStreamWriter;
|
|
||||||
|
|
||||||
class ProtocolItem;
|
|
||||||
class ProtocolResponse;
|
|
||||||
class TopLevelProtocolItem;
|
|
||||||
class CommandContainer;
|
|
||||||
class ChatEvent;
|
|
||||||
class GameEventContainer;
|
|
||||||
class Event_ListGames;
|
|
||||||
class Event_ServerMessage;
|
|
||||||
class Event_ListChatChannels;
|
|
||||||
class Event_GameJoined;
|
|
||||||
|
|
||||||
enum ClientStatus {
|
|
||||||
StatusDisconnected,
|
|
||||||
StatusDisconnecting,
|
|
||||||
StatusConnecting,
|
|
||||||
StatusAwaitingWelcome,
|
|
||||||
StatusLoggingIn,
|
|
||||||
StatusLoggedIn,
|
|
||||||
};
|
|
||||||
|
|
||||||
class Client : public QObject {
|
|
||||||
Q_OBJECT
|
|
||||||
signals:
|
|
||||||
void statusChanged(ClientStatus _status);
|
|
||||||
void maxPingTime(int seconds, int maxSeconds);
|
|
||||||
void serverTimeout();
|
|
||||||
void socketError(const QString &errorString);
|
|
||||||
void serverError(ResponseCode resp);
|
|
||||||
void protocolVersionMismatch(int clientVersion, int serverVersion);
|
|
||||||
void protocolError();
|
|
||||||
|
|
||||||
// Chat events
|
|
||||||
void chatEventReceived(ChatEvent *event);
|
|
||||||
// Game events
|
|
||||||
void gameEventContainerReceived(GameEventContainer *event);
|
|
||||||
// Generic events
|
|
||||||
void listGamesEventReceived(Event_ListGames *event);
|
|
||||||
void serverMessageEventReceived(Event_ServerMessage *event);
|
|
||||||
void listChatChannelsEventReceived(Event_ListChatChannels *event);
|
|
||||||
void gameJoinedEventReceived(Event_GameJoined *event);
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void slotConnected();
|
|
||||||
void readData();
|
|
||||||
void slotSocketError(QAbstractSocket::SocketError error);
|
|
||||||
void ping();
|
|
||||||
void loginResponse(ResponseCode response);
|
|
||||||
void processProtocolItem(ProtocolItem *item);
|
|
||||||
private:
|
|
||||||
static const int maxTimeout = 10;
|
|
||||||
|
|
||||||
QTimer *timer;
|
|
||||||
QMap<int, CommandContainer *> pendingCommands;
|
|
||||||
QTcpSocket *socket;
|
|
||||||
QXmlStreamReader *xmlReader;
|
|
||||||
QXmlStreamWriter *xmlWriter;
|
|
||||||
TopLevelProtocolItem *topLevelItem;
|
|
||||||
ClientStatus status;
|
|
||||||
QString userName, password;
|
|
||||||
void setStatus(ClientStatus _status);
|
|
||||||
public:
|
|
||||||
Client(QObject *parent = 0);
|
|
||||||
~Client();
|
|
||||||
ClientStatus getStatus() const { return status; }
|
|
||||||
QString peerName() const { return socket->peerName(); }
|
|
||||||
|
|
||||||
void connectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password);
|
|
||||||
void disconnectFromServer();
|
|
||||||
void sendCommand(Command *cmd);
|
|
||||||
void sendCommandContainer(CommandContainer *cont);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include "counter.h"
|
#include "counter.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "client.h"
|
|
||||||
#include "protocol_items.h"
|
#include "protocol_items.h"
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include "dlg_creategame.h"
|
#include "dlg_creategame.h"
|
||||||
#include "protocol_items.h"
|
#include "protocol_items.h"
|
||||||
|
|
||||||
DlgCreateGame::DlgCreateGame(Client *_client, QWidget *parent)
|
DlgCreateGame::DlgCreateGame(AbstractClient *_client, QWidget *parent)
|
||||||
: QDialog(parent), client(_client)
|
: QDialog(parent), client(_client)
|
||||||
{
|
{
|
||||||
descriptionLabel = new QLabel(tr("&Description:"));
|
descriptionLabel = new QLabel(tr("&Description:"));
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#define DLG_CREATEGAME_H
|
#define DLG_CREATEGAME_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include "client.h"
|
#include "abstractclient.h"
|
||||||
|
|
||||||
class QLabel;
|
class QLabel;
|
||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
|
@ -14,13 +14,13 @@ class QSpinBox;
|
||||||
class DlgCreateGame : public QDialog {
|
class DlgCreateGame : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
DlgCreateGame(Client *_client, QWidget *parent = 0);
|
DlgCreateGame(AbstractClient *_client, QWidget *parent = 0);
|
||||||
private slots:
|
private slots:
|
||||||
void actOK();
|
void actOK();
|
||||||
void checkResponse(ResponseCode response);
|
void checkResponse(ResponseCode response);
|
||||||
void spectatorsAllowedChanged(int state);
|
void spectatorsAllowedChanged(int state);
|
||||||
private:
|
private:
|
||||||
Client *client;
|
AbstractClient *client;
|
||||||
|
|
||||||
QGroupBox *spectatorsGroupBox;
|
QGroupBox *spectatorsGroupBox;
|
||||||
QLabel *descriptionLabel, *passwordLabel, *maxPlayersLabel;
|
QLabel *descriptionLabel, *passwordLabel, *maxPlayersLabel;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include "dlg_load_remote_deck.h"
|
#include "dlg_load_remote_deck.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
DlgLoadRemoteDeck::DlgLoadRemoteDeck(Client *_client, QWidget *parent)
|
DlgLoadRemoteDeck::DlgLoadRemoteDeck(AbstractClient *_client, QWidget *parent)
|
||||||
: QDialog(parent), client(_client)
|
: QDialog(parent), client(_client)
|
||||||
{
|
{
|
||||||
dirView = new RemoteDeckList_TreeWidget(client);
|
dirView = new RemoteDeckList_TreeWidget(client);
|
||||||
|
|
|
@ -5,19 +5,19 @@
|
||||||
|
|
||||||
class RemoteDeckList_TreeWidget;
|
class RemoteDeckList_TreeWidget;
|
||||||
class QModelIndex;
|
class QModelIndex;
|
||||||
class Client;
|
class AbstractClient;
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
|
|
||||||
class DlgLoadRemoteDeck: public QDialog {
|
class DlgLoadRemoteDeck: public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
Client *client;
|
AbstractClient *client;
|
||||||
RemoteDeckList_TreeWidget *dirView;
|
RemoteDeckList_TreeWidget *dirView;
|
||||||
QPushButton *okButton, *cancelButton;
|
QPushButton *okButton, *cancelButton;
|
||||||
private slots:
|
private slots:
|
||||||
void currentItemChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
void currentItemChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||||
public:
|
public:
|
||||||
DlgLoadRemoteDeck(Client *_client, QWidget *parent = 0);
|
DlgLoadRemoteDeck(AbstractClient *_client, QWidget *parent = 0);
|
||||||
int getDeckId() const;
|
int getDeckId() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
#include "pilezone.h"
|
#include "pilezone.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "client.h"
|
|
||||||
#include "carddragitem.h"
|
#include "carddragitem.h"
|
||||||
#include "zoneviewzone.h"
|
#include "zoneviewzone.h"
|
||||||
#include "protocol_items.h"
|
#include "protocol_items.h"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "client.h"
|
#include "abstractclient.h"
|
||||||
#include "cardzone.h"
|
#include "cardzone.h"
|
||||||
#include "playertarget.h"
|
#include "playertarget.h"
|
||||||
#include "counter.h"
|
#include "counter.h"
|
||||||
|
@ -19,8 +19,9 @@
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
Player::Player(const QString &_name, int _id, bool _local, Client *_client, TabGame *_parent)
|
Player::Player(const QString &_name, int _id, bool _local, AbstractClient *_client, TabGame *_parent)
|
||||||
: QObject(_parent), defaultNumberTopCards(3), lastTokenDestroy(true), name(_name), id(_id), active(false), local(_local), mirrored(false), client(_client)
|
: QObject(_parent), defaultNumberTopCards(3), lastTokenDestroy(true), name(_name), id(_id), active(false), local(_local), mirrored(false), client(_client)
|
||||||
{
|
{
|
||||||
setCacheMode(DeviceCoordinateCache);
|
setCacheMode(DeviceCoordinateCache);
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include "carditem.h"
|
#include "carditem.h"
|
||||||
|
|
||||||
class Client;
|
class AbstractClient;
|
||||||
class CardDatabase;
|
class CardDatabase;
|
||||||
class QMenu;
|
class QMenu;
|
||||||
class QAction;
|
class QAction;
|
||||||
|
@ -171,8 +171,8 @@ public:
|
||||||
void clearArrows();
|
void clearArrows();
|
||||||
PlayerTarget *getPlayerTarget() const { return playerTarget; }
|
PlayerTarget *getPlayerTarget() const { return playerTarget; }
|
||||||
|
|
||||||
Client *client;
|
AbstractClient *client;
|
||||||
Player(const QString &_name, int _id, bool _local, Client *_client, TabGame *_parent);
|
Player(const QString &_name, int _id, bool _local, AbstractClient *_client, TabGame *_parent);
|
||||||
~Player();
|
~Player();
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
QMenu *getPlayerMenu() const { return playerMenu; }
|
QMenu *getPlayerMenu() const { return playerMenu; }
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
#include "remotedecklist_treewidget.h"
|
#include "remotedecklist_treewidget.h"
|
||||||
#include "protocol_items.h"
|
#include "protocol_items.h"
|
||||||
#include "client.h"
|
#include "abstractclient.h"
|
||||||
|
|
||||||
RemoteDeckList_TreeModel::DirectoryNode::DirectoryNode(const QString &_name, RemoteDeckList_TreeModel::DirectoryNode *_parent)
|
RemoteDeckList_TreeModel::DirectoryNode::DirectoryNode(const QString &_name, RemoteDeckList_TreeModel::DirectoryNode *_parent)
|
||||||
: RemoteDeckList_TreeModel::Node(_name, _parent)
|
: RemoteDeckList_TreeModel::Node(_name, _parent)
|
||||||
|
@ -72,7 +72,7 @@ RemoteDeckList_TreeModel::FileNode *RemoteDeckList_TreeModel::DirectoryNode::get
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteDeckList_TreeModel::RemoteDeckList_TreeModel(Client *_client, QObject *parent)
|
RemoteDeckList_TreeModel::RemoteDeckList_TreeModel(AbstractClient *_client, QObject *parent)
|
||||||
: QAbstractItemModel(parent), client(_client)
|
: QAbstractItemModel(parent), client(_client)
|
||||||
{
|
{
|
||||||
QFileIconProvider fip;
|
QFileIconProvider fip;
|
||||||
|
@ -256,7 +256,7 @@ void RemoteDeckList_TreeModel::deckListFinished(ProtocolResponse *r)
|
||||||
emit treeRefreshed();
|
emit treeRefreshed();
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteDeckList_TreeWidget::RemoteDeckList_TreeWidget(Client *_client, QWidget *parent)
|
RemoteDeckList_TreeWidget::RemoteDeckList_TreeWidget(AbstractClient *_client, QWidget *parent)
|
||||||
: QTreeView(parent)
|
: QTreeView(parent)
|
||||||
{
|
{
|
||||||
treeModel = new RemoteDeckList_TreeModel(_client, this);
|
treeModel = new RemoteDeckList_TreeModel(_client, this);
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#include <QTreeView>
|
#include <QTreeView>
|
||||||
|
|
||||||
class ProtocolResponse;
|
class ProtocolResponse;
|
||||||
class Client;
|
class AbstractClient;
|
||||||
class QSortFilterProxyModel;
|
class QSortFilterProxyModel;
|
||||||
class DeckList_File;
|
class DeckList_File;
|
||||||
class DeckList_Directory;
|
class DeckList_Directory;
|
||||||
|
@ -55,7 +55,7 @@ public:
|
||||||
return dynamic_cast<T>(static_cast<Node *>(index.internalPointer()));
|
return dynamic_cast<T>(static_cast<Node *>(index.internalPointer()));
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
Client *client;
|
AbstractClient *client;
|
||||||
DirectoryNode *root;
|
DirectoryNode *root;
|
||||||
|
|
||||||
QIcon fileIcon, dirIcon;
|
QIcon fileIcon, dirIcon;
|
||||||
|
@ -66,7 +66,7 @@ signals:
|
||||||
private slots:
|
private slots:
|
||||||
void deckListFinished(ProtocolResponse *r);
|
void deckListFinished(ProtocolResponse *r);
|
||||||
public:
|
public:
|
||||||
RemoteDeckList_TreeModel(Client *_client, QObject *parent = 0);
|
RemoteDeckList_TreeModel(AbstractClient *_client, QObject *parent = 0);
|
||||||
~RemoteDeckList_TreeModel();
|
~RemoteDeckList_TreeModel();
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const;
|
int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const;
|
||||||
|
@ -89,7 +89,7 @@ private:
|
||||||
RemoteDeckList_TreeModel *treeModel;
|
RemoteDeckList_TreeModel *treeModel;
|
||||||
QSortFilterProxyModel *proxyModel;
|
QSortFilterProxyModel *proxyModel;
|
||||||
public:
|
public:
|
||||||
RemoteDeckList_TreeWidget(Client *_client, QWidget *parent = 0);
|
RemoteDeckList_TreeWidget(AbstractClient *_client, QWidget *parent = 0);
|
||||||
RemoteDeckList_TreeModel::Node *getNode(const QModelIndex &ind) const;
|
RemoteDeckList_TreeModel::Node *getNode(const QModelIndex &ind) const;
|
||||||
RemoteDeckList_TreeModel::Node *getCurrentItem() const;
|
RemoteDeckList_TreeModel::Node *getCurrentItem() const;
|
||||||
RemoteDeckList_TreeModel::DirectoryNode *getNodeByPath(const QString &path) const;
|
RemoteDeckList_TreeModel::DirectoryNode *getNodeByPath(const QString &path) const;
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
#include "tab_chatchannel.h"
|
#include "tab_chatchannel.h"
|
||||||
#include "client.h"
|
#include "abstractclient.h"
|
||||||
#include "protocol_items.h"
|
#include "protocol_items.h"
|
||||||
|
|
||||||
TabChatChannel::TabChatChannel(Client *_client, const QString &_channelName)
|
TabChatChannel::TabChatChannel(AbstractClient *_client, const QString &_channelName)
|
||||||
: Tab(), client(_client), channelName(_channelName)
|
: Tab(), client(_client), channelName(_channelName)
|
||||||
{
|
{
|
||||||
playerList = new QListWidget;
|
playerList = new QListWidget;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include "tab.h"
|
#include "tab.h"
|
||||||
|
|
||||||
class Client;
|
class AbstractClient;
|
||||||
class QListWidget;
|
class QListWidget;
|
||||||
class QTextEdit;
|
class QTextEdit;
|
||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
|
@ -16,7 +16,7 @@ class Event_ChatSay;
|
||||||
class TabChatChannel : public Tab {
|
class TabChatChannel : public Tab {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
Client *client;
|
AbstractClient *client;
|
||||||
QString channelName;
|
QString channelName;
|
||||||
|
|
||||||
QListWidget *playerList;
|
QListWidget *playerList;
|
||||||
|
@ -35,7 +35,7 @@ private slots:
|
||||||
void processLeaveChannelEvent(Event_ChatLeaveChannel *event);
|
void processLeaveChannelEvent(Event_ChatLeaveChannel *event);
|
||||||
void processSayEvent(Event_ChatSay *event);
|
void processSayEvent(Event_ChatSay *event);
|
||||||
public:
|
public:
|
||||||
TabChatChannel(Client *_client, const QString &_channelName);
|
TabChatChannel(AbstractClient *_client, const QString &_channelName);
|
||||||
~TabChatChannel();
|
~TabChatChannel();
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
void processChatEvent(ChatEvent *event);
|
void processChatEvent(ChatEvent *event);
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
#include "tab_deck_storage.h"
|
#include "tab_deck_storage.h"
|
||||||
#include "remotedecklist_treewidget.h"
|
#include "remotedecklist_treewidget.h"
|
||||||
#include "client.h"
|
#include "abstractclient.h"
|
||||||
#include "decklist.h"
|
#include "decklist.h"
|
||||||
#include "protocol_items.h"
|
#include "protocol_items.h"
|
||||||
#include "window_deckeditor.h"
|
#include "window_deckeditor.h"
|
||||||
|
|
||||||
TabDeckStorage::TabDeckStorage(Client *_client)
|
TabDeckStorage::TabDeckStorage(AbstractClient *_client)
|
||||||
: Tab(), client(_client)
|
: Tab(), client(_client)
|
||||||
{
|
{
|
||||||
localDirModel = new QFileSystemModel(this);
|
localDirModel = new QFileSystemModel(this);
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include "tab.h"
|
#include "tab.h"
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
|
|
||||||
class Client;
|
class AbstractClient;
|
||||||
class QTreeView;
|
class QTreeView;
|
||||||
class QFileSystemModel;
|
class QFileSystemModel;
|
||||||
class QSortFilterProxyModel;
|
class QSortFilterProxyModel;
|
||||||
|
@ -18,7 +18,7 @@ class RemoteDeckList_TreeWidget;
|
||||||
class TabDeckStorage : public Tab {
|
class TabDeckStorage : public Tab {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
Client *client;
|
AbstractClient *client;
|
||||||
QTreeView *localDirView;
|
QTreeView *localDirView;
|
||||||
QFileSystemModel *localDirModel;
|
QFileSystemModel *localDirModel;
|
||||||
QSortFilterProxyModel *sortFilter;
|
QSortFilterProxyModel *sortFilter;
|
||||||
|
@ -45,7 +45,7 @@ private slots:
|
||||||
void actDelete();
|
void actDelete();
|
||||||
void deleteFinished(ResponseCode resp);
|
void deleteFinished(ResponseCode resp);
|
||||||
public:
|
public:
|
||||||
TabDeckStorage(Client *_client);
|
TabDeckStorage(AbstractClient *_client);
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
QString getTabText() const { return tr("Deck storage"); }
|
QString getTabText() const { return tr("Deck storage"); }
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
#include "deck_picturecacher.h"
|
#include "deck_picturecacher.h"
|
||||||
#include "protocol_items.h"
|
#include "protocol_items.h"
|
||||||
#include "dlg_load_remote_deck.h"
|
#include "dlg_load_remote_deck.h"
|
||||||
#include "client.h"
|
#include "abstractclient.h"
|
||||||
#include "carditem.h"
|
#include "carditem.h"
|
||||||
#include "arrowitem.h"
|
#include "arrowitem.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
@ -42,7 +42,7 @@ void ReadyStartButton::setReadyStart(bool _readyStart)
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
TabGame::TabGame(Client *_client, int _gameId, const QString &_gameDescription, int _localPlayerId, bool _spectator, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, bool _resuming)
|
TabGame::TabGame(AbstractClient *_client, int _gameId, const QString &_gameDescription, int _localPlayerId, bool _spectator, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, bool _resuming)
|
||||||
: Tab(), client(_client), gameId(_gameId), gameDescription(_gameDescription), localPlayerId(_localPlayerId), spectator(_spectator), spectatorsCanTalk(_spectatorsCanTalk), spectatorsSeeEverything(_spectatorsSeeEverything), started(false), resuming(_resuming), currentPhase(-1)
|
: Tab(), client(_client), gameId(_gameId), gameDescription(_gameDescription), localPlayerId(_localPlayerId), spectator(_spectator), spectatorsCanTalk(_spectatorsCanTalk), spectatorsSeeEverything(_spectatorsSeeEverything), started(false), resuming(_resuming), currentPhase(-1)
|
||||||
{
|
{
|
||||||
scene = new GameScene(this);
|
scene = new GameScene(this);
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include "tab.h"
|
#include "tab.h"
|
||||||
|
|
||||||
class Client;
|
class AbstractClient;
|
||||||
class CardDatabase;
|
class CardDatabase;
|
||||||
class GameView;
|
class GameView;
|
||||||
class DeckView;
|
class DeckView;
|
||||||
|
@ -55,7 +55,7 @@ protected:
|
||||||
class TabGame : public Tab {
|
class TabGame : public Tab {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
Client *client;
|
AbstractClient *client;
|
||||||
int gameId;
|
int gameId;
|
||||||
QString gameDescription;
|
QString gameDescription;
|
||||||
int localPlayerId;
|
int localPlayerId;
|
||||||
|
@ -120,7 +120,7 @@ private slots:
|
||||||
void actNextPhase();
|
void actNextPhase();
|
||||||
void actNextTurn();
|
void actNextTurn();
|
||||||
public:
|
public:
|
||||||
TabGame(Client *_client, int _gameId, const QString &_gameDescription, int _localPlayerId, bool _spectator, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, bool _resuming);
|
TabGame(AbstractClient *_client, int _gameId, const QString &_gameDescription, int _localPlayerId, bool _spectator, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, bool _resuming);
|
||||||
~TabGame();
|
~TabGame();
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
const QMap<int, Player *> &getPlayers() const { return players; }
|
const QMap<int, Player *> &getPlayers() const { return players; }
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
#include "tab_server.h"
|
#include "tab_server.h"
|
||||||
#include "gamesmodel.h"
|
#include "gamesmodel.h"
|
||||||
#include "dlg_creategame.h"
|
#include "dlg_creategame.h"
|
||||||
#include "client.h"
|
#include "abstractclient.h"
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
#include "protocol_items.h"
|
#include "protocol_items.h"
|
||||||
|
|
||||||
GameSelector::GameSelector(Client *_client, QWidget *parent)
|
GameSelector::GameSelector(AbstractClient *_client, QWidget *parent)
|
||||||
: QGroupBox(parent), client(_client)
|
: QGroupBox(parent), client(_client)
|
||||||
{
|
{
|
||||||
gameListView = new QTreeView;
|
gameListView = new QTreeView;
|
||||||
|
@ -113,7 +113,7 @@ void GameSelector::processListGamesEvent(Event_ListGames *event)
|
||||||
gameListModel->updateGameList(gamesToUpdate[i]);
|
gameListModel->updateGameList(gamesToUpdate[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatChannelSelector::ChatChannelSelector(Client *_client, QWidget *parent)
|
ChatChannelSelector::ChatChannelSelector(AbstractClient *_client, QWidget *parent)
|
||||||
: QGroupBox(parent), client(_client)
|
: QGroupBox(parent), client(_client)
|
||||||
{
|
{
|
||||||
channelList = new QTreeWidget;
|
channelList = new QTreeWidget;
|
||||||
|
@ -200,7 +200,7 @@ void ChatChannelSelector::joinFinished(ResponseCode resp)
|
||||||
emit channelJoined(channelName);
|
emit channelJoined(channelName);
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerMessageLog::ServerMessageLog(Client *_client, QWidget *parent)
|
ServerMessageLog::ServerMessageLog(AbstractClient *_client, QWidget *parent)
|
||||||
: QGroupBox(parent)
|
: QGroupBox(parent)
|
||||||
{
|
{
|
||||||
textEdit = new QTextEdit;
|
textEdit = new QTextEdit;
|
||||||
|
@ -225,7 +225,7 @@ void ServerMessageLog::processServerMessageEvent(Event_ServerMessage *event)
|
||||||
textEdit->append(event->getMessage());
|
textEdit->append(event->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
TabServer::TabServer(Client *_client, QWidget *parent)
|
TabServer::TabServer(AbstractClient *_client, QWidget *parent)
|
||||||
: Tab(parent), client(_client)
|
: Tab(parent), client(_client)
|
||||||
{
|
{
|
||||||
gameSelector = new GameSelector(client);
|
gameSelector = new GameSelector(client);
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include "tab.h"
|
#include "tab.h"
|
||||||
#include "protocol_datastructures.h"
|
#include "protocol_datastructures.h"
|
||||||
|
|
||||||
class Client;
|
class AbstractClient;
|
||||||
class QTreeView;
|
class QTreeView;
|
||||||
class QTreeWidget;
|
class QTreeWidget;
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
|
@ -22,7 +22,7 @@ class Event_ServerMessage;
|
||||||
class GameSelector : public QGroupBox {
|
class GameSelector : public QGroupBox {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
GameSelector(Client *_client, QWidget *parent = 0);
|
GameSelector(AbstractClient *_client, QWidget *parent = 0);
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
private slots:
|
private slots:
|
||||||
void processListGamesEvent(Event_ListGames *event);
|
void processListGamesEvent(Event_ListGames *event);
|
||||||
|
@ -33,7 +33,7 @@ private slots:
|
||||||
signals:
|
signals:
|
||||||
void gameJoined(int gameId);
|
void gameJoined(int gameId);
|
||||||
private:
|
private:
|
||||||
Client *client;
|
AbstractClient *client;
|
||||||
|
|
||||||
QTreeView *gameListView;
|
QTreeView *gameListView;
|
||||||
GamesModel *gameListModel;
|
GamesModel *gameListModel;
|
||||||
|
@ -47,7 +47,7 @@ class ChatChannelSelector : public QGroupBox {
|
||||||
private:
|
private:
|
||||||
QTreeWidget *channelList;
|
QTreeWidget *channelList;
|
||||||
QPushButton *joinButton;
|
QPushButton *joinButton;
|
||||||
Client *client;
|
AbstractClient *client;
|
||||||
|
|
||||||
void joinChannel(const QString &channelName);
|
void joinChannel(const QString &channelName);
|
||||||
private slots:
|
private slots:
|
||||||
|
@ -57,7 +57,7 @@ private slots:
|
||||||
signals:
|
signals:
|
||||||
void channelJoined(const QString &channelName);
|
void channelJoined(const QString &channelName);
|
||||||
public:
|
public:
|
||||||
ChatChannelSelector(Client *_client, QWidget *parent = 0);
|
ChatChannelSelector(AbstractClient *_client, QWidget *parent = 0);
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ private:
|
||||||
private slots:
|
private slots:
|
||||||
void processServerMessageEvent(Event_ServerMessage *event);
|
void processServerMessageEvent(Event_ServerMessage *event);
|
||||||
public:
|
public:
|
||||||
ServerMessageLog(Client *_client, QWidget *parent = 0);
|
ServerMessageLog(AbstractClient *_client, QWidget *parent = 0);
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -78,12 +78,12 @@ signals:
|
||||||
void chatChannelJoined(const QString &channelName);
|
void chatChannelJoined(const QString &channelName);
|
||||||
void gameJoined(int gameId);
|
void gameJoined(int gameId);
|
||||||
private:
|
private:
|
||||||
Client *client;
|
AbstractClient *client;
|
||||||
GameSelector *gameSelector;
|
GameSelector *gameSelector;
|
||||||
ChatChannelSelector *chatChannelSelector;
|
ChatChannelSelector *chatChannelSelector;
|
||||||
ServerMessageLog *serverMessageLog;
|
ServerMessageLog *serverMessageLog;
|
||||||
public:
|
public:
|
||||||
TabServer(Client *_client, QWidget *parent = 0);
|
TabServer(AbstractClient *_client, QWidget *parent = 0);
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
QString getTabText() const { return tr("Server"); }
|
QString getTabText() const { return tr("Server"); }
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include "tab_supervisor.h"
|
#include "tab_supervisor.h"
|
||||||
#include "client.h"
|
#include "abstractclient.h"
|
||||||
#include "tab_server.h"
|
#include "tab_server.h"
|
||||||
#include "tab_chatchannel.h"
|
#include "tab_chatchannel.h"
|
||||||
#include "tab_game.h"
|
#include "tab_game.h"
|
||||||
#include "tab_deck_storage.h"
|
#include "tab_deck_storage.h"
|
||||||
#include "protocol_items.h"
|
#include "protocol_items.h"
|
||||||
#include "pingpixmapgenerator.h"
|
#include "pingpixmapgenerator.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
TabSupervisor:: TabSupervisor(QWidget *parent)
|
TabSupervisor:: TabSupervisor(QWidget *parent)
|
||||||
: QTabWidget(parent), client(0), tabServer(0), tabDeckStorage(0)
|
: QTabWidget(parent), client(0), tabServer(0), tabDeckStorage(0)
|
||||||
|
@ -48,7 +49,7 @@ void TabSupervisor::myAddTab(Tab *tab)
|
||||||
addTab(tab, tab->getTabText());
|
addTab(tab, tab->getTabText());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabSupervisor::start(Client *_client)
|
void TabSupervisor::start(AbstractClient *_client)
|
||||||
{
|
{
|
||||||
client = _client;
|
client = _client;
|
||||||
connect(client, SIGNAL(chatEventReceived(ChatEvent *)), this, SLOT(processChatEvent(ChatEvent *)));
|
connect(client, SIGNAL(chatEventReceived(ChatEvent *)), this, SLOT(processChatEvent(ChatEvent *)));
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
|
||||||
class QMenu;
|
class QMenu;
|
||||||
class Client;
|
class AbstractClient;
|
||||||
class Tab;
|
class Tab;
|
||||||
class TabServer;
|
class TabServer;
|
||||||
class TabChatChannel;
|
class TabChatChannel;
|
||||||
|
@ -19,7 +19,7 @@ class TabSupervisor : public QTabWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QIcon *tabChangedIcon;
|
QIcon *tabChangedIcon;
|
||||||
Client *client;
|
AbstractClient *client;
|
||||||
TabServer *tabServer;
|
TabServer *tabServer;
|
||||||
TabDeckStorage *tabDeckStorage;
|
TabDeckStorage *tabDeckStorage;
|
||||||
QMap<QString, TabChatChannel *> chatChannelTabs;
|
QMap<QString, TabChatChannel *> chatChannelTabs;
|
||||||
|
@ -29,7 +29,7 @@ public:
|
||||||
TabSupervisor(QWidget *parent = 0);
|
TabSupervisor(QWidget *parent = 0);
|
||||||
~TabSupervisor();
|
~TabSupervisor();
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
void start(Client *_client);
|
void start(AbstractClient *_client);
|
||||||
void stop();
|
void stop();
|
||||||
int getGameCount() const { return gameTabs.size(); }
|
int getGameCount() const { return gameTabs.size(); }
|
||||||
signals:
|
signals:
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
#include "tablezone.h"
|
#include "tablezone.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "client.h"
|
|
||||||
#include "protocol_items.h"
|
#include "protocol_items.h"
|
||||||
#include "settingscache.h"
|
#include "settingscache.h"
|
||||||
#include "arrowitem.h"
|
#include "arrowitem.h"
|
||||||
|
|
|
@ -24,6 +24,10 @@
|
||||||
#include "dlg_settings.h"
|
#include "dlg_settings.h"
|
||||||
#include "window_deckeditor.h"
|
#include "window_deckeditor.h"
|
||||||
#include "tab_supervisor.h"
|
#include "tab_supervisor.h"
|
||||||
|
#include "remoteclient.h"
|
||||||
|
#include "localserver.h"
|
||||||
|
#include "localserverinterface.h"
|
||||||
|
#include "localclient.h"
|
||||||
|
|
||||||
const QString MainWindow::appName = "Cockatrice";
|
const QString MainWindow::appName = "Cockatrice";
|
||||||
|
|
||||||
|
@ -74,6 +78,15 @@ void MainWindow::actDisconnect()
|
||||||
client->disconnectFromServer();
|
client->disconnectFromServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::actSinglePlayer()
|
||||||
|
{
|
||||||
|
LocalServer *ls = new LocalServer(this);
|
||||||
|
LocalServerInterface *mainLsi = ls->newConnection();
|
||||||
|
LocalClient *mainClient = new LocalClient(mainLsi, this);
|
||||||
|
tabSupervisor->start(mainClient);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::actDeckEditor()
|
void MainWindow::actDeckEditor()
|
||||||
{
|
{
|
||||||
WndDeckEditor *deckEditor = new WndDeckEditor(this);
|
WndDeckEditor *deckEditor = new WndDeckEditor(this);
|
||||||
|
@ -138,6 +151,7 @@ void MainWindow::retranslateUi()
|
||||||
|
|
||||||
aConnect->setText(tr("&Connect..."));
|
aConnect->setText(tr("&Connect..."));
|
||||||
aDisconnect->setText(tr("&Disconnect"));
|
aDisconnect->setText(tr("&Disconnect"));
|
||||||
|
aSinglePlayer->setText(tr("Start &local game..."));
|
||||||
aDeckEditor->setText(tr("&Deck editor"));
|
aDeckEditor->setText(tr("&Deck editor"));
|
||||||
aFullScreen->setText(tr("&Full screen"));
|
aFullScreen->setText(tr("&Full screen"));
|
||||||
aFullScreen->setShortcut(tr("Ctrl+F"));
|
aFullScreen->setShortcut(tr("Ctrl+F"));
|
||||||
|
@ -156,6 +170,8 @@ void MainWindow::createActions()
|
||||||
aDisconnect = new QAction(this);
|
aDisconnect = new QAction(this);
|
||||||
aDisconnect->setEnabled(false);
|
aDisconnect->setEnabled(false);
|
||||||
connect(aDisconnect, SIGNAL(triggered()), this, SLOT(actDisconnect()));
|
connect(aDisconnect, SIGNAL(triggered()), this, SLOT(actDisconnect()));
|
||||||
|
aSinglePlayer = new QAction(this);
|
||||||
|
connect(aSinglePlayer, SIGNAL(triggered()), this, SLOT(actSinglePlayer()));
|
||||||
aDeckEditor = new QAction(this);
|
aDeckEditor = new QAction(this);
|
||||||
connect(aDeckEditor, SIGNAL(triggered()), this, SLOT(actDeckEditor()));
|
connect(aDeckEditor, SIGNAL(triggered()), this, SLOT(actDeckEditor()));
|
||||||
aFullScreen = new QAction(this);
|
aFullScreen = new QAction(this);
|
||||||
|
@ -172,6 +188,7 @@ void MainWindow::createMenus()
|
||||||
cockatriceMenu = menuBar()->addMenu(QString());
|
cockatriceMenu = menuBar()->addMenu(QString());
|
||||||
cockatriceMenu->addAction(aConnect);
|
cockatriceMenu->addAction(aConnect);
|
||||||
cockatriceMenu->addAction(aDisconnect);
|
cockatriceMenu->addAction(aDisconnect);
|
||||||
|
cockatriceMenu->addAction(aSinglePlayer);
|
||||||
cockatriceMenu->addSeparator();
|
cockatriceMenu->addSeparator();
|
||||||
cockatriceMenu->addAction(aDeckEditor);
|
cockatriceMenu->addAction(aDeckEditor);
|
||||||
cockatriceMenu->addSeparator();
|
cockatriceMenu->addSeparator();
|
||||||
|
@ -187,7 +204,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
{
|
{
|
||||||
QPixmapCache::setCacheLimit(200000);
|
QPixmapCache::setCacheLimit(200000);
|
||||||
|
|
||||||
client = new Client(this);
|
client = new RemoteClient(this);
|
||||||
connect(client, SIGNAL(serverError(ResponseCode)), this, SLOT(serverError(ResponseCode)));
|
connect(client, SIGNAL(serverError(ResponseCode)), this, SLOT(serverError(ResponseCode)));
|
||||||
connect(client, SIGNAL(socketError(const QString &)), this, SLOT(socketError(const QString &)));
|
connect(client, SIGNAL(socketError(const QString &)), this, SLOT(socketError(const QString &)));
|
||||||
connect(client, SIGNAL(serverTimeout()), this, SLOT(serverTimeout()));
|
connect(client, SIGNAL(serverTimeout()), this, SLOT(serverTimeout()));
|
||||||
|
|
|
@ -21,10 +21,11 @@
|
||||||
#define WINDOW_H
|
#define WINDOW_H
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include "client.h"
|
#include "abstractclient.h"
|
||||||
#include "protocol_datastructures.h"
|
#include "protocol_datastructures.h"
|
||||||
|
|
||||||
class TabSupervisor;
|
class TabSupervisor;
|
||||||
|
class RemoteClient;
|
||||||
|
|
||||||
class MainWindow : public QMainWindow {
|
class MainWindow : public QMainWindow {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -38,6 +39,7 @@ private slots:
|
||||||
|
|
||||||
void actConnect();
|
void actConnect();
|
||||||
void actDisconnect();
|
void actDisconnect();
|
||||||
|
void actSinglePlayer();
|
||||||
void actDeckEditor();
|
void actDeckEditor();
|
||||||
void actFullScreen(bool checked);
|
void actFullScreen(bool checked);
|
||||||
void actSettings();
|
void actSettings();
|
||||||
|
@ -49,10 +51,10 @@ private:
|
||||||
void createActions();
|
void createActions();
|
||||||
void createMenus();
|
void createMenus();
|
||||||
QMenu *cockatriceMenu, *tabMenu;
|
QMenu *cockatriceMenu, *tabMenu;
|
||||||
QAction *aConnect, *aDisconnect, *aDeckEditor, *aFullScreen, *aSettings, *aExit;
|
QAction *aConnect, *aDisconnect, *aSinglePlayer, *aDeckEditor, *aFullScreen, *aSettings, *aExit;
|
||||||
TabSupervisor *tabSupervisor;
|
TabSupervisor *tabSupervisor;
|
||||||
|
|
||||||
Client *client;
|
RemoteClient *client;
|
||||||
public:
|
public:
|
||||||
MainWindow(QWidget *parent = 0);
|
MainWindow(QWidget *parent = 0);
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
#include "carditem.h"
|
#include "carditem.h"
|
||||||
#include "zoneviewzone.h"
|
#include "zoneviewzone.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "client.h"
|
|
||||||
#include "gamescene.h"
|
#include "gamescene.h"
|
||||||
#include "protocol_items.h"
|
#include "protocol_items.h"
|
||||||
#include "settingscache.h"
|
#include "settingscache.h"
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
#include "zoneviewzone.h"
|
#include "zoneviewzone.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "client.h"
|
|
||||||
#include "protocol_items.h"
|
#include "protocol_items.h"
|
||||||
|
|
||||||
ZoneViewZone::ZoneViewZone(Player *_p, CardZone *_origZone, int _numberCards, QGraphicsItem *parent)
|
ZoneViewZone::ZoneViewZone(Player *_p, CardZone *_origZone, int _numberCards, QGraphicsItem *parent)
|
||||||
|
|
|
@ -92,10 +92,12 @@ void Server::broadcastGameListUpdate(Server_Game *game)
|
||||||
eventGameList.append(new ServerInfo_Game(game->getGameId(), QString(), false, 0, game->getMaxPlayers(), QString(), false, 0));
|
eventGameList.append(new ServerInfo_Game(game->getGameId(), QString(), false, 0, game->getMaxPlayers(), QString(), false, 0));
|
||||||
Event_ListGames *event = new Event_ListGames(eventGameList);
|
Event_ListGames *event = new Event_ListGames(eventGameList);
|
||||||
|
|
||||||
|
bool mayDelete = true;
|
||||||
for (int i = 0; i < clients.size(); i++)
|
for (int i = 0; i < clients.size(); i++)
|
||||||
if (clients[i]->getAcceptsGameListChanges())
|
if (clients[i]->getAcceptsGameListChanges())
|
||||||
clients[i]->sendProtocolItem(event, false);
|
mayDelete = clients[i]->sendProtocolItem(event, false);
|
||||||
delete event;
|
if (mayDelete)
|
||||||
|
delete event;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::broadcastChannelUpdate()
|
void Server::broadcastChannelUpdate()
|
||||||
|
@ -105,10 +107,12 @@ void Server::broadcastChannelUpdate()
|
||||||
eventChannelList.append(new ServerInfo_ChatChannel(channel->getName(), channel->getDescription(), channel->size(), channel->getAutoJoin()));
|
eventChannelList.append(new ServerInfo_ChatChannel(channel->getName(), channel->getDescription(), channel->size(), channel->getAutoJoin()));
|
||||||
Event_ListChatChannels *event = new Event_ListChatChannels(eventChannelList);
|
Event_ListChatChannels *event = new Event_ListChatChannels(eventChannelList);
|
||||||
|
|
||||||
|
bool mayDelete = true;
|
||||||
for (int i = 0; i < clients.size(); ++i)
|
for (int i = 0; i < clients.size(); ++i)
|
||||||
if (clients[i]->getAcceptsChatChannelListChanges())
|
if (clients[i]->getAcceptsChatChannelListChanges())
|
||||||
clients[i]->sendProtocolItem(event, false);
|
mayDelete = clients[i]->sendProtocolItem(event, false);
|
||||||
delete event;
|
if (mayDelete)
|
||||||
|
delete event;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::gameClosing()
|
void Server::gameClosing()
|
||||||
|
|
|
@ -36,7 +36,9 @@ void Server_ChatChannel::say(Server_ProtocolHandler *client, const QString &s)
|
||||||
|
|
||||||
void Server_ChatChannel::sendChatEvent(ChatEvent *event)
|
void Server_ChatChannel::sendChatEvent(ChatEvent *event)
|
||||||
{
|
{
|
||||||
|
bool mayDelete = true;
|
||||||
for (int i = 0; i < size(); ++i)
|
for (int i = 0; i < size(); ++i)
|
||||||
at(i)->sendProtocolItem(event, false);
|
mayDelete = at(i)->sendProtocolItem(event, false);
|
||||||
delete event;
|
if (mayDelete)
|
||||||
|
delete event;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
#include "server_card.h"
|
#include "server_card.h"
|
||||||
#include "server_cardzone.h"
|
#include "server_cardzone.h"
|
||||||
#include "server_counter.h"
|
#include "server_counter.h"
|
||||||
#include <QSqlQuery>
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
Server_Game::Server_Game(Server_ProtocolHandler *_creator, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, QObject *parent)
|
Server_Game::Server_Game(Server_ProtocolHandler *_creator, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, QObject *parent)
|
||||||
|
@ -345,28 +344,34 @@ void Server_Game::sendGameEvent(GameEvent *event, GameEventContext *context, Ser
|
||||||
|
|
||||||
void Server_Game::sendGameEventContainer(GameEventContainer *cont, Server_Player *exclude, bool excludeOmniscient)
|
void Server_Game::sendGameEventContainer(GameEventContainer *cont, Server_Player *exclude, bool excludeOmniscient)
|
||||||
{
|
{
|
||||||
|
bool mayDelete = true;
|
||||||
|
|
||||||
cont->setGameId(gameId);
|
cont->setGameId(gameId);
|
||||||
QMapIterator<int, Server_Player *> playerIterator(players);
|
QMapIterator<int, Server_Player *> playerIterator(players);
|
||||||
while (playerIterator.hasNext()) {
|
while (playerIterator.hasNext()) {
|
||||||
Server_Player *p = playerIterator.next().value();
|
Server_Player *p = playerIterator.next().value();
|
||||||
if ((p != exclude) && !(excludeOmniscient && p->getSpectator() && spectatorsSeeEverything))
|
if ((p != exclude) && !(excludeOmniscient && p->getSpectator() && spectatorsSeeEverything))
|
||||||
p->sendProtocolItem(cont, false);
|
mayDelete = p->sendProtocolItem(cont, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete cont;
|
if (mayDelete)
|
||||||
|
delete cont;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Game::sendGameEventContainerOmniscient(GameEventContainer *cont, Server_Player *exclude)
|
void Server_Game::sendGameEventContainerOmniscient(GameEventContainer *cont, Server_Player *exclude)
|
||||||
{
|
{
|
||||||
|
bool mayDelete = true;
|
||||||
|
|
||||||
cont->setGameId(gameId);
|
cont->setGameId(gameId);
|
||||||
QMapIterator<int, Server_Player *> playerIterator(players);
|
QMapIterator<int, Server_Player *> playerIterator(players);
|
||||||
while (playerIterator.hasNext()) {
|
while (playerIterator.hasNext()) {
|
||||||
Server_Player *p = playerIterator.next().value();
|
Server_Player *p = playerIterator.next().value();
|
||||||
if ((p != exclude) && (p->getSpectator() && spectatorsSeeEverything))
|
if ((p != exclude) && (p->getSpectator() && spectatorsSeeEverything))
|
||||||
p->sendProtocolItem(cont, false);
|
mayDelete = p->sendProtocolItem(cont, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete cont;
|
if (mayDelete)
|
||||||
|
delete cont;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Game::sendGameEventToPlayer(Server_Player *player, GameEvent *event)
|
void Server_Game::sendGameEventToPlayer(Server_Player *player, GameEvent *event)
|
||||||
|
|
|
@ -196,8 +196,10 @@ bool Server_Player::deleteCounter(int counterId)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Player::sendProtocolItem(ProtocolItem *item, bool deleteItem)
|
bool Server_Player::sendProtocolItem(ProtocolItem *item, bool deleteItem)
|
||||||
{
|
{
|
||||||
if (handler)
|
if (handler)
|
||||||
handler->sendProtocolItem(item, deleteItem);
|
return handler->sendProtocolItem(item, deleteItem);
|
||||||
|
else
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ public:
|
||||||
void clearZones();
|
void clearZones();
|
||||||
void setupZones();
|
void setupZones();
|
||||||
|
|
||||||
void sendProtocolItem(ProtocolItem *item, bool deleteItem = true);
|
bool sendProtocolItem(ProtocolItem *item, bool deleteItem = true);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -94,7 +94,7 @@ public:
|
||||||
const QDateTime &getLastCommandTime() const { return lastCommandTime; }
|
const QDateTime &getLastCommandTime() const { return lastCommandTime; }
|
||||||
|
|
||||||
void processCommandContainer(CommandContainer *cont);
|
void processCommandContainer(CommandContainer *cont);
|
||||||
virtual void sendProtocolItem(ProtocolItem *item, bool deleteItem = true) = 0;
|
virtual bool sendProtocolItem(ProtocolItem *item, bool deleteItem = true) = 0;
|
||||||
void enqueueProtocolItem(ProtocolItem *item);
|
void enqueueProtocolItem(ProtocolItem *item);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -96,6 +96,7 @@ void ServerSocketInterface::sendProtocolItem(ProtocolItem *item, bool deleteItem
|
||||||
item->write(xmlWriter);
|
item->write(xmlWriter);
|
||||||
if (deleteItem)
|
if (deleteItem)
|
||||||
delete item;
|
delete item;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ServerSocketInterface::getDeckPathId(int basePathId, QStringList path)
|
int ServerSocketInterface::getDeckPathId(int basePathId, QStringList path)
|
||||||
|
|
Loading…
Reference in a new issue