mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 09:04:53 -07:00
fixed 'open deck in deck editor' option in game, fixed freeze when closing local game
This commit is contained in:
parent
9af69f53af
commit
d7e7606104
9 changed files with 30 additions and 23 deletions
|
|
@ -35,8 +35,8 @@
|
|||
#include <QThread>
|
||||
#include <QDebug>
|
||||
|
||||
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>("ServerInfo_Game");
|
||||
qRegisterMetaType<ServerInfo_Room>("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<int, Server_Room *> roomIterator(rooms);
|
||||
|
|
|
|||
|
|
@ -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<int, Server_Room *> &getRooms() { return rooms; }
|
||||
|
|
@ -79,6 +79,7 @@ public:
|
|||
void removePersistentPlayer(const QString &userName, int roomId, int gameId, int playerId);
|
||||
QList<PlayerReference> getPersistentPlayerReferences(const QString &userName) const;
|
||||
private:
|
||||
bool threaded;
|
||||
QMultiMap<QString, PlayerReference> persistentPlayers;
|
||||
mutable QReadWriteLock persistentPlayersLock;
|
||||
protected slots:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue