local playing bugfixes

This commit is contained in:
Max-Wilhelm Bruker 2010-08-11 04:23:12 +02:00
parent 00077565ab
commit 168d184e8f
21 changed files with 71 additions and 52 deletions

View file

@ -5,7 +5,6 @@
#include <QXmlStreamWriter>
#include <QVariant>
#include "decklist.h"
#include <QDebug>
MoveCardToZone::MoveCardToZone(const QString &_cardName, const QString &_startZone, const QString &_targetZone)
: SerializableItem_Map("move_card_to_zone")

View file

@ -1,12 +1,11 @@
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QDebug>
#include "protocol.h"
#include "protocol_items.h"
#include "decklist.h"
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)
gameEventQueuePublic = new GameEventContainer(QList<GameEvent *>(), gameId);
gameEventQueuePublic->appendItem(event);
gameEventQueuePublic->addGameEvent(event);
}
void CommandContainer::enqueueGameEventOmniscient(GameEvent *event, int gameId)
{
if (!gameEventQueueOmniscient)
gameEventQueueOmniscient = new GameEventContainer(QList<GameEvent *>(), gameId);
gameEventQueueOmniscient->appendItem(event);
gameEventQueueOmniscient->addGameEvent(event);
}
void CommandContainer::enqueueGameEventPrivate(GameEvent *event, int gameId)
{
if (!gameEventQueuePrivate)
gameEventQueuePrivate = new GameEventContainer(QList<GameEvent *>(), gameId);
gameEventQueuePrivate->appendItem(event);
gameEventQueuePrivate->addGameEvent(event);
}
Command_DeckUpload::Command_DeckUpload(DeckList *_deck, const QString &_path)
@ -307,6 +306,7 @@ GameEventContainer::GameEventContainer(const QList<GameEvent *> &_eventList, int
if (_context)
itemList.append(_context);
eventList = _eventList;
for (int i = 0; i < _eventList.size(); ++i)
itemList.append(_eventList[i]);
}
@ -337,6 +337,12 @@ void GameEventContainer::setContext(GameEventContext *_context)
context = _context;
}
void GameEventContainer::addGameEvent(GameEvent *event)
{
appendItem(event);
eventList.append(event);
}
GameEventContainer *GameEventContainer::makeNew(GameEvent *event, int _gameId)
{
return new GameEventContainer(QList<GameEvent *>() << event, _gameId);

View file

@ -46,10 +46,13 @@ class ProtocolItem : public SerializableItem_Map {
Q_OBJECT
private:
static void initializeHashAuto();
bool receiverMayDelete;
public:
static const int protocolVersion = 7;
static void initializeHash();
virtual int getItemId() const = 0;
bool getReceiverMayDelete() const { return receiverMayDelete; }
void setReceiverMayDelete(bool _receiverMayDelete) { receiverMayDelete = _receiverMayDelete; }
ProtocolItem(const QString &_itemType, const QString &_itemSubType);
};
@ -269,6 +272,7 @@ public:
QList<GameEvent *> getEventList() const { return eventList; }
GameEventContext *getContext() const { return context; }
void setContext(GameEventContext *_context);
void addGameEvent(GameEvent *event);
static GameEventContainer *makeNew(GameEvent *event, int _gameId);
int getGameId() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->getData(); }

View file

@ -148,10 +148,13 @@ ServerInfo_Player::ServerInfo_Player(ServerInfo_PlayerProperties *_properties, D
else
insertItem(new DeckList(_deck));
zoneList = _zoneList;
for (int i = 0; i < _zoneList.size(); ++i)
itemList.append(_zoneList[i]);
counterList = _counterList;
for (int i = 0; i < _counterList.size(); ++i)
itemList.append(_counterList[i]);
arrowList = _arrowList;
for (int i = 0; i < _arrowList.size(); ++i)
itemList.append(_arrowList[i]);
}

View file

@ -1,7 +1,6 @@
#include "serializable_item.h"
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QDebug>
QHash<QString, SerializableItem::NewItemFunction> SerializableItem::itemNameHash;

View file

@ -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));
Event_ListGames *event = new Event_ListGames(eventGameList);
bool mayDelete = true;
for (int i = 0; i < clients.size(); i++)
if (clients[i]->getAcceptsGameListChanges())
mayDelete = clients[i]->sendProtocolItem(event, false);
if (mayDelete)
delete event;
clients[i]->sendProtocolItem(event, false);
delete event;
}
void Server::broadcastChannelUpdate()
@ -107,12 +105,10 @@ void Server::broadcastChannelUpdate()
eventChannelList.append(new ServerInfo_ChatChannel(channel->getName(), channel->getDescription(), channel->size(), channel->getAutoJoin()));
Event_ListChatChannels *event = new Event_ListChatChannels(eventChannelList);
bool mayDelete = true;
for (int i = 0; i < clients.size(); ++i)
if (clients[i]->getAcceptsChatChannelListChanges())
mayDelete = clients[i]->sendProtocolItem(event, false);
if (mayDelete)
delete event;
clients[i]->sendProtocolItem(event, false);
delete event;
}
void Server::gameClosing()

View file

@ -36,9 +36,7 @@ void Server_ChatChannel::say(Server_ProtocolHandler *client, const QString &s)
void Server_ChatChannel::sendChatEvent(ChatEvent *event)
{
bool mayDelete = true;
for (int i = 0; i < size(); ++i)
mayDelete = at(i)->sendProtocolItem(event, false);
if (mayDelete)
delete event;
at(i)->sendProtocolItem(event, false);
delete event;
}

View file

@ -25,6 +25,7 @@
#include "server_cardzone.h"
#include "server_counter.h"
#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)
: 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)
{
bool mayDelete = true;
cont->setGameId(gameId);
QMapIterator<int, Server_Player *> playerIterator(players);
while (playerIterator.hasNext()) {
Server_Player *p = playerIterator.next().value();
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)
{
bool mayDelete = true;
cont->setGameId(gameId);
QMapIterator<int, Server_Player *> playerIterator(players);
while (playerIterator.hasNext()) {
Server_Player *p = playerIterator.next().value();
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)

View file

@ -196,10 +196,8 @@ bool Server_Player::deleteCounter(int counterId)
return true;
}
bool Server_Player::sendProtocolItem(ProtocolItem *item, bool deleteItem)
void Server_Player::sendProtocolItem(ProtocolItem *item, bool deleteItem)
{
if (handler)
return handler->sendProtocolItem(item, deleteItem);
else
return true;
handler->sendProtocolItem(item, deleteItem);
}

View file

@ -70,7 +70,7 @@ public:
void clearZones();
void setupZones();
bool sendProtocolItem(ProtocolItem *item, bool deleteItem = true);
void sendProtocolItem(ProtocolItem *item, bool deleteItem = true);
};
#endif

View file

@ -145,7 +145,7 @@ void Server_ProtocolHandler::processCommandContainer(CommandContainer *cont)
ProtocolResponse *pr = cont->getResponse();
if (!pr)
pr = new ProtocolResponse(cont->getCmdId(), finalResponseCode);
GameEventContainer *gQPublic = cont->getGameEventQueuePublic();
if (gQPublic) {
Server_Game *game = games.value(gQPublic->getGameId()).first;
@ -169,10 +169,11 @@ void Server_ProtocolHandler::processCommandContainer(CommandContainer *cont)
sendProtocolItem(pr);
delete cont;
while (!itemQueue.isEmpty())
sendProtocolItem(itemQueue.takeFirst());
if (cont->getReceiverMayDelete())
delete cont;
}
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)
{
if (authState == PasswordWrong)
return RespLoginNeeded;
const QList<Server_Game *> &gameList = server->getGames();
QList<ServerInfo_Game *> eventGameList;
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)
{
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_Player *creator = game->getCreator();
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)
{
if (authState == PasswordWrong)
return RespLoginNeeded;
if (games.contains(cmd->getGameId()))
return RespContextError;
@ -485,7 +495,6 @@ ResponseCode Server_ProtocolHandler::drawCards(Server_Game *game, Server_Player
cardListPrivate.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->enqueueGameEventOmniscient(new Event_DrawCards(player->getPlayerId(), cardListOmniscient.size(), cardListOmniscient), game->getGameId());
cont->enqueueGameEventPublic(new Event_DrawCards(player->getPlayerId(), cardListPrivate.size()), game->getGameId());

View file

@ -94,7 +94,7 @@ public:
const QDateTime &getLastCommandTime() const { return lastCommandTime; }
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);
};