Response::ResponseCode Server_ProtocolHandler::cmdGetGamesOfUser(const Command_GetGamesOfUser &cmd, ResponseContainer &rc) { if (authState == NotLoggedIn) return Response::RespLoginNeeded; // We don't need to check whether the user is logged in; persistent games should also work. // The client needs to deal with an empty result list. Response_GetGamesOfUser *re = new Response_GetGamesOfUser; server->roomsLock.lockForRead(); QMapIterator<int, Server_Room *> roomIterator(server->getRooms()); while (roomIterator.hasNext()) { Server_Room *room = roomIterator.next().value(); room->gamesLock.lockForRead(); room->getInfo(*re->add_room_list(), false, true); QListIterator<ServerInfo_Game> gameIterator(room->getGamesOfUser(QString::fromStdString(cmd.user_name()))); while (gameIterator.hasNext()) re->add_game_list()->CopyFrom(gameIterator.next()); room->gamesLock.unlock(); } server->roomsLock.unlock(); rc.setResponseExtension(re); return Response::RespOk; }
void TabSupervisor::retranslateUi() { QList<Tab *> tabs; tabs.append(tabServer); tabs.append(tabReplays); tabs.append(tabDeckStorage); tabs.append(tabAdmin); tabs.append(tabUserLists); tabs.append(tabLog); QMapIterator<int, TabRoom *> roomIterator(roomTabs); while (roomIterator.hasNext()) tabs.append(roomIterator.next().value()); QMapIterator<int, TabGame *> gameIterator(gameTabs); while (gameIterator.hasNext()) tabs.append(gameIterator.next().value()); QListIterator<TabGame *> replayIterator(replayTabs); while (replayIterator.hasNext()) tabs.append(replayIterator.next()); QListIterator<TabDeckEditor *> deckEditorIterator(deckEditorTabs); while (deckEditorIterator.hasNext()) tabs.append(deckEditorIterator.next()); QMapIterator<QString, TabMessage *> messageIterator(messageTabs); while (messageIterator.hasNext()) tabs.append(messageIterator.next().value()); for (int i = 0; i < tabs.size(); ++i) if (tabs[i]) { int idx = indexOf(tabs[i]); QString tabText = tabs[i]->getTabText(); setTabText(idx, sanitizeTabName(tabText)); setTabToolTip(idx, sanitizeHtml(tabText)); tabs[i]->retranslateUi(); } }
ServerInfo_Room *Server_Room::getInfo(bool complete) const { QList<ServerInfo_Game *> gameList; QList<ServerInfo_User *> userList; if (complete) { QMapIterator<int, Server_Game *> gameIterator(games); while (gameIterator.hasNext()) gameList.append(gameIterator.next().value()->getInfo()); for (int i = 0; i < size(); ++i) userList.append(new ServerInfo_User(at(i)->getUserInfo(), false)); } return new ServerInfo_Room(id, name, description, games.size(), size(), autoJoin, gameList, userList); }
// This function must only be called from the thread this object lives in. // The thread must not hold any server locks when calling this (e.g. clientsLock, roomsLock). void Server_ProtocolHandler::prepareDestroy() { if (deleted) return; deleted = true; QMapIterator<int, Server_Room *> roomIterator(rooms); while (roomIterator.hasNext()) roomIterator.next().value()->removeClient(this); QMap<int, QPair<int, int> > tempGames(getGames()); server->roomsLock.lockForRead(); QMapIterator<int, QPair<int, int> > gameIterator(tempGames); while (gameIterator.hasNext()) { gameIterator.next(); Server_Room *r = server->getRooms().value(gameIterator.value().first); if (!r) continue; r->gamesLock.lockForRead(); Server_Game *g = r->getGames().value(gameIterator.key()); if (!g) { r->gamesLock.unlock(); continue; } g->gameMutex.lock(); Server_Player *p = g->getPlayers().value(gameIterator.value().second); if (!p) { g->gameMutex.unlock(); r->gamesLock.unlock(); continue; } p->disconnectClient(); g->gameMutex.unlock(); r->gamesLock.unlock(); } server->roomsLock.unlock(); server->removeClient(this); deleteLater(); }
Server_ProtocolHandler::~Server_ProtocolHandler() { // The socket has to be removed from the server's list before it is removed from the game's list // so it will not receive the game update event. server->removeClient(this); QMapIterator<int, Server_Room *> roomIterator(rooms); while (roomIterator.hasNext()) roomIterator.next().value()->removeClient(this); QMapIterator<int, QPair<Server_Game *, Server_Player *> > gameIterator(games); while (gameIterator.hasNext()) { gameIterator.next(); Server_Game *g = gameIterator.value().first; Server_Player *p = gameIterator.value().second; if (authState == UnknownUser) g->removePlayer(p); else p->setProtocolHandler(0); } delete userInfo; }