diff --git a/cockatrice/src/localserver.cpp b/cockatrice/src/localserver.cpp index e8722fb3..26c5427c 100644 --- a/cockatrice/src/localserver.cpp +++ b/cockatrice/src/localserver.cpp @@ -3,7 +3,7 @@ #include "server_room.h" LocalServer::LocalServer(QObject *parent) - : Server(parent) + : Server(false, parent) { setDatabaseInterface(new LocalServer_DatabaseInterface(this)); addRoom(new Server_Room(0, QString(), QString(), false, QString(), QStringList(), this)); diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp index 6fd7250a..9ffc456a 100644 --- a/cockatrice/src/player.cpp +++ b/cockatrice/src/player.cpp @@ -792,7 +792,7 @@ void Player::actAlwaysRevealTopCard() void Player::actOpenDeckInDeckEditor() { - emit openDeckEditor(*deck); + emit openDeckEditor(deck); } void Player::actViewGraveyard() diff --git a/cockatrice/src/player.h b/cockatrice/src/player.h index c04e2c42..f55d0fd7 100644 --- a/cockatrice/src/player.h +++ b/cockatrice/src/player.h @@ -77,7 +77,7 @@ public: class Player : public QObject, public QGraphicsItem { Q_OBJECT signals: - void openDeckEditor(const DeckLoader &deck); + void openDeckEditor(const DeckLoader *deck); void newCardAdded(AbstractCardItem *card); // Log events void logSay(Player *player, QString message); diff --git a/cockatrice/src/tab_game.cpp b/cockatrice/src/tab_game.cpp index 32144445..a8f12cc6 100644 --- a/cockatrice/src/tab_game.cpp +++ b/cockatrice/src/tab_game.cpp @@ -733,7 +733,7 @@ Player *TabGame::addPlayer(int playerId, const ServerInfo_User &info) { bool local = ((clients.size() > 1) || (playerId == localPlayerId)); Player *newPlayer = new Player(info, playerId, local, this); - connect(newPlayer, SIGNAL(openDeckEditor(DeckList *)), this, SIGNAL(openDeckEditor(DeckList *))); + connect(newPlayer, SIGNAL(openDeckEditor(const DeckLoader *)), this, SIGNAL(openDeckEditor(const DeckLoader *))); scene->addPlayer(newPlayer); connect(newPlayer, SIGNAL(newCardAdded(AbstractCardItem *)), this, SLOT(newCardAdded(AbstractCardItem *))); diff --git a/cockatrice/src/tab_game.h b/cockatrice/src/tab_game.h index ebb4d25f..db82d06d 100644 --- a/cockatrice/src/tab_game.h +++ b/cockatrice/src/tab_game.h @@ -171,7 +171,7 @@ signals: void containerProcessingStarted(const GameEventContext &context); void containerProcessingDone(); void openMessageDialog(const QString &userName, bool focus); - void openDeckEditor(const DeckLoader &deck); + void openDeckEditor(const DeckLoader *deck); private slots: void replayNextEvent(); void replayFinished(); diff --git a/cockatrice/src/tab_supervisor.cpp b/cockatrice/src/tab_supervisor.cpp index 56ce55b8..4aeb294e 100644 --- a/cockatrice/src/tab_supervisor.cpp +++ b/cockatrice/src/tab_supervisor.cpp @@ -280,8 +280,7 @@ void TabSupervisor::gameJoined(const Event_GameJoined &event) TabGame *tab = new TabGame(this, QList() << client, event, roomGameTypes); connect(tab, SIGNAL(gameClosing(TabGame *)), this, SLOT(gameLeft(TabGame *))); connect(tab, SIGNAL(openMessageDialog(const QString &, bool)), this, SLOT(addMessageTab(const QString &, bool))); - connect(tab, SIGNAL(openDeckEditor(DeckList *, QString, DeckList::FileFormat)), this, SLOT(addDeckEditorTab(DeckList *, QString, DeckList::FileFormat))); - connect(tab, SIGNAL(openDeckEditor(DeckList *, int)), this, SLOT(addDeckEditorTab(DeckList *, int))); + connect(tab, SIGNAL(openDeckEditor(const DeckLoader *)), this, SLOT(addDeckEditorTab(const DeckLoader *))); int tabIndex = myAddTab(tab); addCloseButtonToTab(tab, tabIndex); gameTabs.insert(event.game_info().game_id(), tab); @@ -292,7 +291,7 @@ void TabSupervisor::localGameJoined(const Event_GameJoined &event) { TabGame *tab = new TabGame(this, localClients, event, QMap()); connect(tab, SIGNAL(gameClosing(TabGame *)), this, SLOT(gameLeft(TabGame *))); - connect(tab, SIGNAL(openDeckEditor(DeckList *)), this, SLOT(addDeckEditorTab(DeckList *))); + connect(tab, SIGNAL(openDeckEditor(const DeckLoader *)), this, SLOT(addDeckEditorTab(const DeckLoader *))); int tabIndex = myAddTab(tab); addCloseButtonToTab(tab, tabIndex); gameTabs.insert(event.game_info().game_id(), tab); diff --git a/common/server.cpp b/common/server.cpp index 5fc9b2b8..24a80efa 100644 --- a/common/server.cpp +++ b/common/server.cpp @@ -35,8 +35,8 @@ #include #include -Server::Server(QObject *parent) - : QObject(parent), clientsLock(QReadWriteLock::Recursive) +Server::Server(bool _threaded, QObject *parent) + : QObject(parent), threaded(_threaded), clientsLock(QReadWriteLock::Recursive) { qRegisterMetaType("ServerInfo_Game"); qRegisterMetaType("ServerInfo_Room"); @@ -56,20 +56,27 @@ Server::~Server() void Server::prepareDestroy() { - clientsLock.lockForRead(); - for (int i = 0; i < clients.size(); ++i) - QMetaObject::invokeMethod(clients.at(i), "prepareDestroy", Qt::QueuedConnection); - clientsLock.unlock(); - // dirty :( - bool done = false; - do { - usleep(10000); + if (threaded) { clientsLock.lockForRead(); - if (clients.isEmpty()) - done = true; + for (int i = 0; i < clients.size(); ++i) + QMetaObject::invokeMethod(clients.at(i), "prepareDestroy", Qt::QueuedConnection); clientsLock.unlock(); - } while (!done); + + bool done = false; + do { + usleep(10000); + clientsLock.lockForRead(); + if (clients.isEmpty()) + done = true; + clientsLock.unlock(); + } while (!done); + } else { + clientsLock.lockForWrite(); + while (!clients.isEmpty()) + clients.first()->prepareDestroy(); + clientsLock.unlock(); + } roomsLock.lockForWrite(); QMapIterator roomIterator(rooms); diff --git a/common/server.h b/common/server.h index ac7bb6d6..4b61b4fe 100644 --- a/common/server.h +++ b/common/server.h @@ -41,7 +41,7 @@ private slots: void broadcastRoomUpdate(const ServerInfo_Room &roomInfo, bool sendToIsl = false); public: mutable QReadWriteLock clientsLock, roomsLock; // locking order: roomsLock before clientsLock - Server(QObject *parent = 0); + Server(bool _threaded, QObject *parent = 0); ~Server(); AuthenticationResult loginUser(Server_ProtocolHandler *session, QString &name, const QString &password, QString &reason, int &secondsLeft); const QMap &getRooms() { return rooms; } @@ -79,6 +79,7 @@ public: void removePersistentPlayer(const QString &userName, int roomId, int gameId, int playerId); QList getPersistentPlayerReferences(const QString &userName) const; private: + bool threaded; QMultiMap persistentPlayers; mutable QReadWriteLock persistentPlayersLock; protected slots: diff --git a/servatrice/src/servatrice.cpp b/servatrice/src/servatrice.cpp index 01ea3809..b31b573b 100644 --- a/servatrice/src/servatrice.cpp +++ b/servatrice/src/servatrice.cpp @@ -108,7 +108,7 @@ void Servatrice_IslServer::incomingConnection(int socketDescriptor) } Servatrice::Servatrice(QSettings *_settings, QObject *parent) - : Server(parent), settings(_settings), uptime(0), shutdownTimer(0) + : Server(true, parent), settings(_settings), uptime(0), shutdownTimer(0) { qRegisterMetaType("QSqlDatabase"); }