local playing bugfixes
This commit is contained in:
parent
00077565ab
commit
168d184e8f
21 changed files with 71 additions and 52 deletions
|
@ -7,7 +7,8 @@ class QGraphicsScene;
|
||||||
class CardZone;
|
class CardZone;
|
||||||
class CardInfo;
|
class CardInfo;
|
||||||
|
|
||||||
class AbstractCardDragItem : public QGraphicsItem {
|
class AbstractCardDragItem : public QObject, public QGraphicsItem {
|
||||||
|
Q_OBJECT
|
||||||
protected:
|
protected:
|
||||||
AbstractCardItem *item;
|
AbstractCardItem *item;
|
||||||
QPointF hotSpot;
|
QPointF hotSpot;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "abstractclient.h"
|
#include "abstractclient.h"
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
#include "protocol_items.h"
|
#include "protocol_items.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
AbstractClient::AbstractClient(QObject *parent)
|
AbstractClient::AbstractClient(QObject *parent)
|
||||||
: QObject(parent), status(StatusDisconnected)
|
: QObject(parent), status(StatusDisconnected)
|
||||||
|
@ -21,8 +22,9 @@ void AbstractClient::processProtocolItem(ProtocolItem *item)
|
||||||
|
|
||||||
pendingCommands.remove(cmdCont->getCmdId());
|
pendingCommands.remove(cmdCont->getCmdId());
|
||||||
cmdCont->processResponse(response);
|
cmdCont->processResponse(response);
|
||||||
delete response;
|
if (response->getReceiverMayDelete())
|
||||||
delete cmdCont;
|
delete response;
|
||||||
|
cmdCont->deleteLater();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -35,21 +37,24 @@ void AbstractClient::processProtocolItem(ProtocolItem *item)
|
||||||
case ItemId_Event_ListChatChannels: emit listChatChannelsEventReceived(qobject_cast<Event_ListChatChannels *>(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;
|
case ItemId_Event_GameJoined: emit gameJoinedEventReceived(qobject_cast<Event_GameJoined *>(item)); break;
|
||||||
}
|
}
|
||||||
delete genericEvent;
|
if (genericEvent->getReceiverMayDelete())
|
||||||
|
delete genericEvent;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GameEventContainer *gameEventContainer = qobject_cast<GameEventContainer *>(item);
|
GameEventContainer *gameEventContainer = qobject_cast<GameEventContainer *>(item);
|
||||||
if (gameEventContainer) {
|
if (gameEventContainer) {
|
||||||
emit gameEventContainerReceived(gameEventContainer);
|
emit gameEventContainerReceived(gameEventContainer);
|
||||||
delete gameEventContainer;
|
if (gameEventContainer->getReceiverMayDelete())
|
||||||
|
delete gameEventContainer;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatEvent *chatEvent = qobject_cast<ChatEvent *>(item);
|
ChatEvent *chatEvent = qobject_cast<ChatEvent *>(item);
|
||||||
if (chatEvent) {
|
if (chatEvent) {
|
||||||
emit chatEventReceived(chatEvent);
|
emit chatEventReceived(chatEvent);
|
||||||
delete chatEvent;
|
if (chatEvent->getReceiverMayDelete())
|
||||||
|
delete chatEvent;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -284,7 +284,7 @@ CardDragItem *CardItem::createDragItem(int _id, const QPointF &_pos, const QPoin
|
||||||
|
|
||||||
void CardItem::deleteDragItem()
|
void CardItem::deleteDragItem()
|
||||||
{
|
{
|
||||||
delete dragItem;
|
dragItem->deleteLater();
|
||||||
dragItem = NULL;
|
dragItem = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,7 +376,7 @@ void CardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
cardMenu->exec(event->screenPos());
|
cardMenu->exec(event->screenPos());
|
||||||
} else if ((event->button() == Qt::LeftButton) && !settingsCache->getDoubleClickToPlay())
|
} else if ((event->button() == Qt::LeftButton) && !settingsCache->getDoubleClickToPlay())
|
||||||
playCard(event);
|
playCard(event);
|
||||||
|
|
||||||
setCursor(Qt::OpenHandCursor);
|
setCursor(Qt::OpenHandCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ LocalClient::LocalClient(LocalServerInterface *_lsi, QObject *parent)
|
||||||
: AbstractClient(parent), lsi(_lsi)
|
: AbstractClient(parent), lsi(_lsi)
|
||||||
{
|
{
|
||||||
connect(lsi, SIGNAL(itemToClient(ProtocolItem *)), this, SLOT(itemFromServer(ProtocolItem *)));
|
connect(lsi, SIGNAL(itemToClient(ProtocolItem *)), this, SLOT(itemFromServer(ProtocolItem *)));
|
||||||
|
sendCommand(new Command_Login("Player", QString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalClient::~LocalClient()
|
LocalClient::~LocalClient()
|
||||||
|
@ -14,6 +15,8 @@ LocalClient::~LocalClient()
|
||||||
|
|
||||||
void LocalClient::sendCommandContainer(CommandContainer *cont)
|
void LocalClient::sendCommandContainer(CommandContainer *cont)
|
||||||
{
|
{
|
||||||
|
cont->setReceiverMayDelete(false);
|
||||||
|
pendingCommands.insert(cont->getCmdId(), cont);
|
||||||
lsi->itemFromClient(cont);
|
lsi->itemFromClient(cont);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "localserverinterface.h"
|
#include "localserverinterface.h"
|
||||||
#include "localserver.h"
|
#include "localserver.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
LocalServerInterface::LocalServerInterface(LocalServer *_server)
|
LocalServerInterface::LocalServerInterface(LocalServer *_server)
|
||||||
: Server_ProtocolHandler(_server, _server)
|
: Server_ProtocolHandler(_server, _server)
|
||||||
|
@ -10,10 +11,12 @@ LocalServerInterface::~LocalServerInterface()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LocalServerInterface::sendProtocolItem(ProtocolItem *item, bool deleteItem)
|
void LocalServerInterface::sendProtocolItem(ProtocolItem *item, bool deleteItem)
|
||||||
{
|
{
|
||||||
|
item->setReceiverMayDelete(false);
|
||||||
emit itemToClient(item);
|
emit itemToClient(item);
|
||||||
return false;
|
if (deleteItem)
|
||||||
|
delete item;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalServerInterface::itemFromClient(ProtocolItem *item)
|
void LocalServerInterface::itemFromClient(ProtocolItem *item)
|
||||||
|
|
|
@ -20,7 +20,7 @@ public:
|
||||||
LocalServerInterface(LocalServer *_server);
|
LocalServerInterface(LocalServer *_server);
|
||||||
~LocalServerInterface();
|
~LocalServerInterface();
|
||||||
|
|
||||||
bool sendProtocolItem(ProtocolItem *item, bool deleteItem = true);
|
void sendProtocolItem(ProtocolItem *item, bool deleteItem = true);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void itemToClient(ProtocolItem *item);
|
void itemToClient(ProtocolItem *item);
|
||||||
|
|
|
@ -739,6 +739,7 @@ void Player::eventDrawCards(Event_DrawCards *event)
|
||||||
|
|
||||||
void Player::processGameEvent(GameEvent *event, GameEventContext *context)
|
void Player::processGameEvent(GameEvent *event, GameEventContext *context)
|
||||||
{
|
{
|
||||||
|
qDebug() << "player event: id=" << event->getItemId();
|
||||||
switch (event->getItemId()) {
|
switch (event->getItemId()) {
|
||||||
case ItemId_Event_Say: eventSay(qobject_cast<Event_Say *>(event)); break;
|
case ItemId_Event_Say: eventSay(qobject_cast<Event_Say *>(event)); break;
|
||||||
case ItemId_Event_Shuffle: eventShuffle(qobject_cast<Event_Shuffle *>(event)); break;
|
case ItemId_Event_Shuffle: eventShuffle(qobject_cast<Event_Shuffle *>(event)); break;
|
||||||
|
|
|
@ -128,7 +128,7 @@ void ZoneViewZone::removeCard(int position)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CardItem *card = cards.takeAt(position);
|
CardItem *card = cards.takeAt(position);
|
||||||
delete card;
|
card->deleteLater();
|
||||||
reorganizeCards();
|
reorganizeCards();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
#include <QXmlStreamWriter>
|
#include <QXmlStreamWriter>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include "decklist.h"
|
#include "decklist.h"
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
MoveCardToZone::MoveCardToZone(const QString &_cardName, const QString &_startZone, const QString &_targetZone)
|
MoveCardToZone::MoveCardToZone(const QString &_cardName, const QString &_startZone, const QString &_targetZone)
|
||||||
: SerializableItem_Map("move_card_to_zone")
|
: SerializableItem_Map("move_card_to_zone")
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
#include <QXmlStreamReader>
|
#include <QXmlStreamReader>
|
||||||
#include <QXmlStreamWriter>
|
#include <QXmlStreamWriter>
|
||||||
#include <QDebug>
|
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
#include "protocol_items.h"
|
#include "protocol_items.h"
|
||||||
#include "decklist.h"
|
#include "decklist.h"
|
||||||
|
|
||||||
ProtocolItem::ProtocolItem(const QString &_itemType, const QString &_itemSubType)
|
ProtocolItem::ProtocolItem(const QString &_itemType, const QString &_itemSubType)
|
||||||
: SerializableItem_Map(_itemType, _itemSubType)
|
: SerializableItem_Map(_itemType, _itemSubType), receiverMayDelete(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,21 +134,21 @@ void CommandContainer::enqueueGameEventPublic(GameEvent *event, int gameId)
|
||||||
{
|
{
|
||||||
if (!gameEventQueuePublic)
|
if (!gameEventQueuePublic)
|
||||||
gameEventQueuePublic = new GameEventContainer(QList<GameEvent *>(), gameId);
|
gameEventQueuePublic = new GameEventContainer(QList<GameEvent *>(), gameId);
|
||||||
gameEventQueuePublic->appendItem(event);
|
gameEventQueuePublic->addGameEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandContainer::enqueueGameEventOmniscient(GameEvent *event, int gameId)
|
void CommandContainer::enqueueGameEventOmniscient(GameEvent *event, int gameId)
|
||||||
{
|
{
|
||||||
if (!gameEventQueueOmniscient)
|
if (!gameEventQueueOmniscient)
|
||||||
gameEventQueueOmniscient = new GameEventContainer(QList<GameEvent *>(), gameId);
|
gameEventQueueOmniscient = new GameEventContainer(QList<GameEvent *>(), gameId);
|
||||||
gameEventQueueOmniscient->appendItem(event);
|
gameEventQueueOmniscient->addGameEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandContainer::enqueueGameEventPrivate(GameEvent *event, int gameId)
|
void CommandContainer::enqueueGameEventPrivate(GameEvent *event, int gameId)
|
||||||
{
|
{
|
||||||
if (!gameEventQueuePrivate)
|
if (!gameEventQueuePrivate)
|
||||||
gameEventQueuePrivate = new GameEventContainer(QList<GameEvent *>(), gameId);
|
gameEventQueuePrivate = new GameEventContainer(QList<GameEvent *>(), gameId);
|
||||||
gameEventQueuePrivate->appendItem(event);
|
gameEventQueuePrivate->addGameEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
Command_DeckUpload::Command_DeckUpload(DeckList *_deck, const QString &_path)
|
Command_DeckUpload::Command_DeckUpload(DeckList *_deck, const QString &_path)
|
||||||
|
@ -307,6 +306,7 @@ GameEventContainer::GameEventContainer(const QList<GameEvent *> &_eventList, int
|
||||||
if (_context)
|
if (_context)
|
||||||
itemList.append(_context);
|
itemList.append(_context);
|
||||||
|
|
||||||
|
eventList = _eventList;
|
||||||
for (int i = 0; i < _eventList.size(); ++i)
|
for (int i = 0; i < _eventList.size(); ++i)
|
||||||
itemList.append(_eventList[i]);
|
itemList.append(_eventList[i]);
|
||||||
}
|
}
|
||||||
|
@ -337,6 +337,12 @@ void GameEventContainer::setContext(GameEventContext *_context)
|
||||||
context = _context;
|
context = _context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameEventContainer::addGameEvent(GameEvent *event)
|
||||||
|
{
|
||||||
|
appendItem(event);
|
||||||
|
eventList.append(event);
|
||||||
|
}
|
||||||
|
|
||||||
GameEventContainer *GameEventContainer::makeNew(GameEvent *event, int _gameId)
|
GameEventContainer *GameEventContainer::makeNew(GameEvent *event, int _gameId)
|
||||||
{
|
{
|
||||||
return new GameEventContainer(QList<GameEvent *>() << event, _gameId);
|
return new GameEventContainer(QList<GameEvent *>() << event, _gameId);
|
||||||
|
|
|
@ -46,10 +46,13 @@ class ProtocolItem : public SerializableItem_Map {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
static void initializeHashAuto();
|
static void initializeHashAuto();
|
||||||
|
bool receiverMayDelete;
|
||||||
public:
|
public:
|
||||||
static const int protocolVersion = 7;
|
static const int protocolVersion = 7;
|
||||||
static void initializeHash();
|
static void initializeHash();
|
||||||
virtual int getItemId() const = 0;
|
virtual int getItemId() const = 0;
|
||||||
|
bool getReceiverMayDelete() const { return receiverMayDelete; }
|
||||||
|
void setReceiverMayDelete(bool _receiverMayDelete) { receiverMayDelete = _receiverMayDelete; }
|
||||||
ProtocolItem(const QString &_itemType, const QString &_itemSubType);
|
ProtocolItem(const QString &_itemType, const QString &_itemSubType);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -269,6 +272,7 @@ public:
|
||||||
QList<GameEvent *> getEventList() const { return eventList; }
|
QList<GameEvent *> getEventList() const { return eventList; }
|
||||||
GameEventContext *getContext() const { return context; }
|
GameEventContext *getContext() const { return context; }
|
||||||
void setContext(GameEventContext *_context);
|
void setContext(GameEventContext *_context);
|
||||||
|
void addGameEvent(GameEvent *event);
|
||||||
static GameEventContainer *makeNew(GameEvent *event, int _gameId);
|
static GameEventContainer *makeNew(GameEvent *event, int _gameId);
|
||||||
|
|
||||||
int getGameId() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->getData(); }
|
int getGameId() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->getData(); }
|
||||||
|
|
|
@ -148,10 +148,13 @@ ServerInfo_Player::ServerInfo_Player(ServerInfo_PlayerProperties *_properties, D
|
||||||
else
|
else
|
||||||
insertItem(new DeckList(_deck));
|
insertItem(new DeckList(_deck));
|
||||||
|
|
||||||
|
zoneList = _zoneList;
|
||||||
for (int i = 0; i < _zoneList.size(); ++i)
|
for (int i = 0; i < _zoneList.size(); ++i)
|
||||||
itemList.append(_zoneList[i]);
|
itemList.append(_zoneList[i]);
|
||||||
|
counterList = _counterList;
|
||||||
for (int i = 0; i < _counterList.size(); ++i)
|
for (int i = 0; i < _counterList.size(); ++i)
|
||||||
itemList.append(_counterList[i]);
|
itemList.append(_counterList[i]);
|
||||||
|
arrowList = _arrowList;
|
||||||
for (int i = 0; i < _arrowList.size(); ++i)
|
for (int i = 0; i < _arrowList.size(); ++i)
|
||||||
itemList.append(_arrowList[i]);
|
itemList.append(_arrowList[i]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#include "serializable_item.h"
|
#include "serializable_item.h"
|
||||||
#include <QXmlStreamReader>
|
#include <QXmlStreamReader>
|
||||||
#include <QXmlStreamWriter>
|
#include <QXmlStreamWriter>
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
QHash<QString, SerializableItem::NewItemFunction> SerializableItem::itemNameHash;
|
QHash<QString, SerializableItem::NewItemFunction> SerializableItem::itemNameHash;
|
||||||
|
|
||||||
|
|
|
@ -92,12 +92,10 @@ 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())
|
||||||
mayDelete = clients[i]->sendProtocolItem(event, false);
|
clients[i]->sendProtocolItem(event, false);
|
||||||
if (mayDelete)
|
delete event;
|
||||||
delete event;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::broadcastChannelUpdate()
|
void Server::broadcastChannelUpdate()
|
||||||
|
@ -107,12 +105,10 @@ 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())
|
||||||
mayDelete = clients[i]->sendProtocolItem(event, false);
|
clients[i]->sendProtocolItem(event, false);
|
||||||
if (mayDelete)
|
delete event;
|
||||||
delete event;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::gameClosing()
|
void Server::gameClosing()
|
||||||
|
|
|
@ -36,9 +36,7 @@ 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)
|
||||||
mayDelete = at(i)->sendProtocolItem(event, false);
|
at(i)->sendProtocolItem(event, false);
|
||||||
if (mayDelete)
|
delete event;
|
||||||
delete event;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "server_cardzone.h"
|
#include "server_cardzone.h"
|
||||||
#include "server_counter.h"
|
#include "server_counter.h"
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
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)
|
||||||
: QObject(parent), gameStarted(false), gameId(_gameId), description(_description), password(_password), maxPlayers(_maxPlayers), activePlayer(-1), activePhase(-1), spectatorsAllowed(_spectatorsAllowed), spectatorsNeedPassword(_spectatorsNeedPassword), spectatorsCanTalk(_spectatorsCanTalk), spectatorsSeeEverything(_spectatorsSeeEverything), inactivityCounter(0)
|
: QObject(parent), gameStarted(false), gameId(_gameId), description(_description), password(_password), maxPlayers(_maxPlayers), activePlayer(-1), activePhase(-1), spectatorsAllowed(_spectatorsAllowed), spectatorsNeedPassword(_spectatorsNeedPassword), spectatorsCanTalk(_spectatorsCanTalk), spectatorsSeeEverything(_spectatorsSeeEverything), inactivityCounter(0)
|
||||||
|
@ -344,34 +345,28 @@ 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))
|
||||||
mayDelete = p->sendProtocolItem(cont, false);
|
p->sendProtocolItem(cont, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mayDelete)
|
delete cont;
|
||||||
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))
|
||||||
mayDelete = p->sendProtocolItem(cont, false);
|
p->sendProtocolItem(cont, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mayDelete)
|
delete cont;
|
||||||
delete cont;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Game::sendGameEventToPlayer(Server_Player *player, GameEvent *event)
|
void Server_Game::sendGameEventToPlayer(Server_Player *player, GameEvent *event)
|
||||||
|
|
|
@ -196,10 +196,8 @@ bool Server_Player::deleteCounter(int counterId)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Server_Player::sendProtocolItem(ProtocolItem *item, bool deleteItem)
|
void Server_Player::sendProtocolItem(ProtocolItem *item, bool deleteItem)
|
||||||
{
|
{
|
||||||
if (handler)
|
if (handler)
|
||||||
return handler->sendProtocolItem(item, deleteItem);
|
handler->sendProtocolItem(item, deleteItem);
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ public:
|
||||||
void clearZones();
|
void clearZones();
|
||||||
void setupZones();
|
void setupZones();
|
||||||
|
|
||||||
bool sendProtocolItem(ProtocolItem *item, bool deleteItem = true);
|
void sendProtocolItem(ProtocolItem *item, bool deleteItem = true);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -145,7 +145,7 @@ void Server_ProtocolHandler::processCommandContainer(CommandContainer *cont)
|
||||||
ProtocolResponse *pr = cont->getResponse();
|
ProtocolResponse *pr = cont->getResponse();
|
||||||
if (!pr)
|
if (!pr)
|
||||||
pr = new ProtocolResponse(cont->getCmdId(), finalResponseCode);
|
pr = new ProtocolResponse(cont->getCmdId(), finalResponseCode);
|
||||||
|
|
||||||
GameEventContainer *gQPublic = cont->getGameEventQueuePublic();
|
GameEventContainer *gQPublic = cont->getGameEventQueuePublic();
|
||||||
if (gQPublic) {
|
if (gQPublic) {
|
||||||
Server_Game *game = games.value(gQPublic->getGameId()).first;
|
Server_Game *game = games.value(gQPublic->getGameId()).first;
|
||||||
|
@ -169,10 +169,11 @@ void Server_ProtocolHandler::processCommandContainer(CommandContainer *cont)
|
||||||
|
|
||||||
sendProtocolItem(pr);
|
sendProtocolItem(pr);
|
||||||
|
|
||||||
delete cont;
|
|
||||||
|
|
||||||
while (!itemQueue.isEmpty())
|
while (!itemQueue.isEmpty())
|
||||||
sendProtocolItem(itemQueue.takeFirst());
|
sendProtocolItem(itemQueue.takeFirst());
|
||||||
|
|
||||||
|
if (cont->getReceiverMayDelete())
|
||||||
|
delete cont;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_ProtocolHandler::pingClockTimeout()
|
void Server_ProtocolHandler::pingClockTimeout()
|
||||||
|
@ -281,6 +282,9 @@ ResponseCode Server_ProtocolHandler::cmdChatSay(Command_ChatSay *cmd, CommandCon
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdListGames(Command_ListGames * /*cmd*/, CommandContainer *cont)
|
ResponseCode Server_ProtocolHandler::cmdListGames(Command_ListGames * /*cmd*/, CommandContainer *cont)
|
||||||
{
|
{
|
||||||
|
if (authState == PasswordWrong)
|
||||||
|
return RespLoginNeeded;
|
||||||
|
|
||||||
const QList<Server_Game *> &gameList = server->getGames();
|
const QList<Server_Game *> &gameList = server->getGames();
|
||||||
QList<ServerInfo_Game *> eventGameList;
|
QList<ServerInfo_Game *> eventGameList;
|
||||||
for (int i = 0; i < gameList.size(); ++i) {
|
for (int i = 0; i < gameList.size(); ++i) {
|
||||||
|
@ -305,6 +309,9 @@ ResponseCode Server_ProtocolHandler::cmdListGames(Command_ListGames * /*cmd*/, C
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd, CommandContainer *cont)
|
ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd, CommandContainer *cont)
|
||||||
{
|
{
|
||||||
|
if (authState == PasswordWrong)
|
||||||
|
return RespLoginNeeded;
|
||||||
|
|
||||||
Server_Game *game = server->createGame(cmd->getDescription(), cmd->getPassword(), cmd->getMaxPlayers(), cmd->getSpectatorsAllowed(), cmd->getSpectatorsNeedPassword(), cmd->getSpectatorsCanTalk(), cmd->getSpectatorsSeeEverything(), this);
|
Server_Game *game = server->createGame(cmd->getDescription(), cmd->getPassword(), cmd->getMaxPlayers(), cmd->getSpectatorsAllowed(), cmd->getSpectatorsNeedPassword(), cmd->getSpectatorsCanTalk(), cmd->getSpectatorsSeeEverything(), this);
|
||||||
Server_Player *creator = game->getCreator();
|
Server_Player *creator = game->getCreator();
|
||||||
games.insert(game->getGameId(), QPair<Server_Game *, Server_Player *>(game, creator));
|
games.insert(game->getGameId(), QPair<Server_Game *, Server_Player *>(game, creator));
|
||||||
|
@ -316,6 +323,9 @@ ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd, Comm
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd, CommandContainer *cont)
|
ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd, CommandContainer *cont)
|
||||||
{
|
{
|
||||||
|
if (authState == PasswordWrong)
|
||||||
|
return RespLoginNeeded;
|
||||||
|
|
||||||
if (games.contains(cmd->getGameId()))
|
if (games.contains(cmd->getGameId()))
|
||||||
return RespContextError;
|
return RespContextError;
|
||||||
|
|
||||||
|
@ -485,7 +495,6 @@ ResponseCode Server_ProtocolHandler::drawCards(Server_Game *game, Server_Player
|
||||||
cardListPrivate.append(new ServerInfo_Card(card->getId(), card->getName()));
|
cardListPrivate.append(new ServerInfo_Card(card->getId(), card->getName()));
|
||||||
cardListOmniscient.append(new ServerInfo_Card(card->getId(), card->getName()));
|
cardListOmniscient.append(new ServerInfo_Card(card->getId(), card->getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
cont->enqueueGameEventPrivate(new Event_DrawCards(player->getPlayerId(), cardListPrivate.size(), cardListPrivate), game->getGameId());
|
cont->enqueueGameEventPrivate(new Event_DrawCards(player->getPlayerId(), cardListPrivate.size(), cardListPrivate), game->getGameId());
|
||||||
cont->enqueueGameEventOmniscient(new Event_DrawCards(player->getPlayerId(), cardListOmniscient.size(), cardListOmniscient), game->getGameId());
|
cont->enqueueGameEventOmniscient(new Event_DrawCards(player->getPlayerId(), cardListOmniscient.size(), cardListOmniscient), game->getGameId());
|
||||||
cont->enqueueGameEventPublic(new Event_DrawCards(player->getPlayerId(), cardListPrivate.size()), game->getGameId());
|
cont->enqueueGameEventPublic(new Event_DrawCards(player->getPlayerId(), cardListPrivate.size()), game->getGameId());
|
||||||
|
|
|
@ -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 bool sendProtocolItem(ProtocolItem *item, bool deleteItem = true) = 0;
|
virtual void sendProtocolItem(ProtocolItem *item, bool deleteItem = true) = 0;
|
||||||
void enqueueProtocolItem(ProtocolItem *item);
|
void enqueueProtocolItem(ProtocolItem *item);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,6 @@ 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