thread fixes
This commit is contained in:
parent
e6fc20114e
commit
69fce1fb5d
7 changed files with 23 additions and 1 deletions
|
@ -101,7 +101,9 @@ void Server::broadcastRoomUpdate()
|
||||||
QMutexLocker locker(&serverMutex);
|
QMutexLocker locker(&serverMutex);
|
||||||
Server_Room *room = static_cast<Server_Room *>(sender());
|
Server_Room *room = static_cast<Server_Room *>(sender());
|
||||||
QList<ServerInfo_Room *> eventRoomList;
|
QList<ServerInfo_Room *> eventRoomList;
|
||||||
|
room->roomMutex.lock();
|
||||||
eventRoomList.append(new ServerInfo_Room(room->getId(), room->getName(), room->getDescription(), room->getGames().size(), room->size(), room->getAutoJoin()));
|
eventRoomList.append(new ServerInfo_Room(room->getId(), room->getName(), room->getDescription(), room->getGames().size(), room->size(), room->getAutoJoin()));
|
||||||
|
room->roomMutex.unlock();
|
||||||
Event_ListRooms *event = new Event_ListRooms(eventRoomList);
|
Event_ListRooms *event = new Event_ListRooms(eventRoomList);
|
||||||
|
|
||||||
for (int i = 0; i < clients.size(); ++i)
|
for (int i = 0; i < clients.size(); ++i)
|
||||||
|
|
|
@ -31,6 +31,8 @@
|
||||||
Server_Game::Server_Game(Server_ProtocolHandler *_creator, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, const QList<int> &_gameTypes, bool _onlyBuddies, bool _onlyRegistered, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, Server_Room *_room)
|
Server_Game::Server_Game(Server_ProtocolHandler *_creator, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, const QList<int> &_gameTypes, bool _onlyBuddies, bool _onlyRegistered, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, Server_Room *_room)
|
||||||
: QObject(), room(_room), creatorInfo(new ServerInfo_User(_creator->getUserInfo())), gameStarted(false), gameId(_gameId), description(_description), password(_password), maxPlayers(_maxPlayers), gameTypes(_gameTypes), activePlayer(-1), activePhase(-1), onlyBuddies(_onlyBuddies), onlyRegistered(_onlyRegistered), spectatorsAllowed(_spectatorsAllowed), spectatorsNeedPassword(_spectatorsNeedPassword), spectatorsCanTalk(_spectatorsCanTalk), spectatorsSeeEverything(_spectatorsSeeEverything), inactivityCounter(0), secondsElapsed(0), gameMutex(QMutex::Recursive)
|
: QObject(), room(_room), creatorInfo(new ServerInfo_User(_creator->getUserInfo())), gameStarted(false), gameId(_gameId), description(_description), password(_password), maxPlayers(_maxPlayers), gameTypes(_gameTypes), activePlayer(-1), activePhase(-1), onlyBuddies(_onlyBuddies), onlyRegistered(_onlyRegistered), spectatorsAllowed(_spectatorsAllowed), spectatorsNeedPassword(_spectatorsNeedPassword), spectatorsCanTalk(_spectatorsCanTalk), spectatorsSeeEverything(_spectatorsSeeEverything), inactivityCounter(0), secondsElapsed(0), gameMutex(QMutex::Recursive)
|
||||||
{
|
{
|
||||||
|
connect(this, SIGNAL(sigStartGameIfReady()), this, SLOT(doStartGameIfReady()), Qt::QueuedConnection);
|
||||||
|
|
||||||
addPlayer(_creator, false, false);
|
addPlayer(_creator, false, false);
|
||||||
|
|
||||||
if (room->getServer()->getGameShouldPing()) {
|
if (room->getServer()->getGameShouldPing()) {
|
||||||
|
@ -111,7 +113,7 @@ int Server_Game::getSpectatorCount() const
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Game::startGameIfReady()
|
void Server_Game::doStartGameIfReady()
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&gameMutex);
|
QMutexLocker locker(&gameMutex);
|
||||||
|
|
||||||
|
@ -159,6 +161,11 @@ void Server_Game::startGameIfReady()
|
||||||
nextTurn();
|
nextTurn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Server_Game::startGameIfReady()
|
||||||
|
{
|
||||||
|
emit sigStartGameIfReady();
|
||||||
|
}
|
||||||
|
|
||||||
void Server_Game::stopGameIfFinished()
|
void Server_Game::stopGameIfFinished()
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&gameMutex);
|
QMutexLocker locker(&gameMutex);
|
||||||
|
@ -214,6 +221,7 @@ Server_Player *Server_Game::addPlayer(Server_ProtocolHandler *handler, bool spec
|
||||||
int playerId = keyList.isEmpty() ? 0 : (keyList.last() + 1);
|
int playerId = keyList.isEmpty() ? 0 : (keyList.last() + 1);
|
||||||
|
|
||||||
Server_Player *newPlayer = new Server_Player(this, playerId, handler->getUserInfo(), spectator, handler);
|
Server_Player *newPlayer = new Server_Player(this, playerId, handler->getUserInfo(), spectator, handler);
|
||||||
|
newPlayer->moveToThread(thread());
|
||||||
sendGameEvent(new Event_Join(newPlayer->getProperties()));
|
sendGameEvent(new Event_Join(newPlayer->getProperties()));
|
||||||
players.insert(playerId, newPlayer);
|
players.insert(playerId, newPlayer);
|
||||||
|
|
||||||
|
|
|
@ -54,8 +54,10 @@ private:
|
||||||
QTimer *pingClock;
|
QTimer *pingClock;
|
||||||
signals:
|
signals:
|
||||||
void gameClosing();
|
void gameClosing();
|
||||||
|
void sigStartGameIfReady();
|
||||||
private slots:
|
private slots:
|
||||||
void pingClockTimeout();
|
void pingClockTimeout();
|
||||||
|
void doStartGameIfReady();
|
||||||
public:
|
public:
|
||||||
mutable QMutex gameMutex;
|
mutable QMutex gameMutex;
|
||||||
Server_Game(Server_ProtocolHandler *_creator, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, const QList<int> &_gameTypes, bool _onlyBuddies, bool _onlyRegistered, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, Server_Room *parent);
|
Server_Game(Server_ProtocolHandler *_creator, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, const QList<int> &_gameTypes, bool _onlyBuddies, bool _onlyRegistered, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, Server_Room *parent);
|
||||||
|
|
|
@ -29,6 +29,12 @@ Server_Player::~Server_Player()
|
||||||
clearZones();
|
clearZones();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Server_Player::moveToThread(QThread *thread)
|
||||||
|
{
|
||||||
|
QObject::moveToThread(thread);
|
||||||
|
userInfo->moveToThread(thread);
|
||||||
|
}
|
||||||
|
|
||||||
int Server_Player::newCardId()
|
int Server_Player::newCardId()
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&game->gameMutex);
|
QMutexLocker locker(&game->gameMutex);
|
||||||
|
|
|
@ -43,6 +43,7 @@ private:
|
||||||
public:
|
public:
|
||||||
Server_Player(Server_Game *_game, int _playerId, ServerInfo_User *_userInfo, bool _spectator, Server_ProtocolHandler *_handler);
|
Server_Player(Server_Game *_game, int _playerId, ServerInfo_User *_userInfo, bool _spectator, Server_ProtocolHandler *_handler);
|
||||||
~Server_Player();
|
~Server_Player();
|
||||||
|
void moveToThread(QThread *thread);
|
||||||
Server_ProtocolHandler *getProtocolHandler() const { return handler; }
|
Server_ProtocolHandler *getProtocolHandler() const { return handler; }
|
||||||
void setProtocolHandler(Server_ProtocolHandler *_handler) { playerMutex.lock(); handler = _handler; playerMutex.unlock(); }
|
void setProtocolHandler(Server_ProtocolHandler *_handler) { playerMutex.lock(); handler = _handler; playerMutex.unlock(); }
|
||||||
|
|
||||||
|
|
|
@ -821,6 +821,7 @@ ResponseCode Server_ProtocolHandler::cmdCreateToken(Command_CreateToken *cmd, Co
|
||||||
y = 0;
|
y = 0;
|
||||||
|
|
||||||
Server_Card *card = new Server_Card(cmd->getCardName(), player->newCardId(), x, y);
|
Server_Card *card = new Server_Card(cmd->getCardName(), player->newCardId(), x, y);
|
||||||
|
card->moveToThread(player->thread());
|
||||||
card->setPT(cmd->getPt());
|
card->setPT(cmd->getPt());
|
||||||
card->setColor(cmd->getColor());
|
card->setColor(cmd->getColor());
|
||||||
card->setAnnotation(cmd->getAnnotation());
|
card->setAnnotation(cmd->getAnnotation());
|
||||||
|
|
|
@ -103,6 +103,8 @@ void Server_Room::removeGame()
|
||||||
QMutexLocker locker(&roomMutex);
|
QMutexLocker locker(&roomMutex);
|
||||||
|
|
||||||
Server_Game *game = static_cast<Server_Game *>(sender());
|
Server_Game *game = static_cast<Server_Game *>(sender());
|
||||||
|
QMutexLocker gameLocker(&game->gameMutex);
|
||||||
|
|
||||||
broadcastGameListUpdate(game);
|
broadcastGameListUpdate(game);
|
||||||
games.remove(game->getGameId());
|
games.remove(game->getGameId());
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue