fix segfault that happens when account tab is closed (#5474)

This commit is contained in:
RickyRister 2025-01-14 22:10:03 -08:00 committed by GitHub
parent d09b9eb533
commit 23bd18a04c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 332 additions and 121 deletions

View file

@ -52,18 +52,6 @@ public:
{
return tr("Account");
}
const UserListWidget *getAllUsersList() const
{
return allUsersList;
}
const UserListWidget *getBuddyList() const
{
return buddyList;
}
const UserListWidget *getIgnoreList() const
{
return ignoreList;
}
};
#endif

View file

@ -123,15 +123,16 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, GameReplay *_replay)
}
TabGame::TabGame(TabSupervisor *_tabSupervisor,
UserlistProxy *_userListProxy,
QList<AbstractClient *> &_clients,
const Event_GameJoined &event,
const QMap<int, QString> &_roomGameTypes)
: Tab(_tabSupervisor), clients(_clients), gameInfo(event.game_info()), roomGameTypes(_roomGameTypes),
hostId(event.host_id()), localPlayerId(event.player_id()), isLocalGame(_tabSupervisor->getIsLocalGame()),
spectator(event.spectator()), judge(event.judge()), gameStateKnown(false), resuming(event.resuming()),
currentPhase(-1), activeCard(nullptr), gameClosed(false), replay(nullptr), replayPlayButton(nullptr),
replayFastForwardButton(nullptr), aReplaySkipForward(nullptr), aReplaySkipBackward(nullptr),
aReplaySkipForwardBig(nullptr), aReplaySkipBackwardBig(nullptr), replayDock(nullptr)
: Tab(_tabSupervisor), userListProxy(_userListProxy), clients(_clients), gameInfo(event.game_info()),
roomGameTypes(_roomGameTypes), hostId(event.host_id()), localPlayerId(event.player_id()),
isLocalGame(_tabSupervisor->getIsLocalGame()), spectator(event.spectator()), judge(event.judge()),
gameStateKnown(false), resuming(event.resuming()), currentPhase(-1), activeCard(nullptr), gameClosed(false),
replay(nullptr), replayPlayButton(nullptr), replayFastForwardButton(nullptr), aReplaySkipForward(nullptr),
aReplaySkipBackward(nullptr), aReplaySkipForwardBig(nullptr), aReplaySkipBackwardBig(nullptr), replayDock(nullptr)
{
// THIS CTOR IS USED ON GAMES
gameInfo.set_started(false);
@ -1683,7 +1684,7 @@ void TabGame::createPlayerListDock(bool bReplay)
void TabGame::createMessageDock(bool bReplay)
{
messageLog = new MessageLogWidget(tabSupervisor, tabSupervisor, this);
messageLog = new MessageLogWidget(tabSupervisor, userListProxy, this);
connect(messageLog, SIGNAL(cardNameHovered(QString)), cardInfoFrameWidget, SLOT(setCard(QString)));
connect(messageLog, &MessageLogWidget::showCardInfoPopup, this, &TabGame::showCardInfoPopup);
connect(messageLog, SIGNAL(deleteCardInfoPopup(QString)), this, SLOT(deleteCardInfoPopup(QString)));

View file

@ -11,6 +11,7 @@
#include <QCompleter>
#include <QMap>
class UserlistProxy;
class DeckViewContainer;
class AbstractClient;
class CardDatabase;
@ -66,6 +67,7 @@ class TabGame : public Tab
private:
QTimer *gameTimer;
int secondsElapsed;
UserlistProxy *userListProxy;
QList<AbstractClient *> clients;
ServerInfo_Game gameInfo;
QMap<int, QString> roomGameTypes;
@ -210,6 +212,7 @@ private slots:
public:
TabGame(TabSupervisor *_tabSupervisor,
UserlistProxy *_userListProxy,
QList<AbstractClient *> &_clients,
const Event_GameJoined &event,
const QMap<int, QString> &_roomGameTypes);

View file

@ -4,6 +4,7 @@
#include "../../main.h"
#include "../../server/chat_view/chat_view.h"
#include "../../server/pending_command.h"
#include "../../server/user/user_list_manager.h"
#include "../../settings/cache_settings.h"
#include "../game_logic/abstract_client.h"
#include "../sound_engine.h"
@ -25,7 +26,7 @@ TabMessage::TabMessage(TabSupervisor *_tabSupervisor,
: Tab(_tabSupervisor), client(_client), ownUserInfo(new ServerInfo_User(_ownUserInfo)),
otherUserInfo(new ServerInfo_User(_otherUserInfo)), userOnline(true)
{
chatView = new ChatView(tabSupervisor, tabSupervisor, 0, true);
chatView = new ChatView(tabSupervisor, tabSupervisor->getUserListManager(), 0, true);
connect(chatView, &ChatView::showCardInfoPopup, this, &TabMessage::showCardInfoPopup);
connect(chatView, SIGNAL(deleteCardInfoPopup(QString)), this, SLOT(deleteCardInfoPopup(QString)));
connect(chatView, SIGNAL(addMentionTag(QString)), this, SLOT(addMentionTag(QString)));

View file

@ -6,6 +6,7 @@
#include "../../main.h"
#include "../../server/chat_view/chat_view.h"
#include "../../server/pending_command.h"
#include "../../server/user/user_list_manager.h"
#include "../../server/user/user_list_widget.h"
#include "../../settings/cache_settings.h"
#include "get_pb_extension.h"
@ -35,9 +36,10 @@
TabRoom::TabRoom(TabSupervisor *_tabSupervisor,
AbstractClient *_client,
ServerInfo_User *_ownUser,
const UserlistProxy *_userListProxy,
const ServerInfo_Room &info)
: Tab(_tabSupervisor), client(_client), roomId(info.room_id()), roomName(QString::fromStdString(info.name())),
ownUser(_ownUser)
ownUser(_ownUser), userListProxy(_userListProxy)
{
const int gameTypeListSize = info.gametype_list_size();
for (int i = 0; i < gameTypeListSize; ++i)
@ -51,7 +53,7 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor,
connect(userList, SIGNAL(openMessageDialog(const QString &, bool)), this,
SIGNAL(openMessageDialog(const QString &, bool)));
chatView = new ChatView(tabSupervisor, tabSupervisor, nullptr, true, this);
chatView = new ChatView(tabSupervisor, userListProxy, nullptr, true, this);
connect(chatView, SIGNAL(showMentionPopup(const QString &)), this, SLOT(actShowMentionPopup(const QString &)));
connect(chatView, SIGNAL(messageClickedSignal()), this, SLOT(focusTab()));
connect(chatView, SIGNAL(openMessageDialog(QString, bool)), this, SIGNAL(openMessageDialog(QString, bool)));
@ -282,7 +284,7 @@ void TabRoom::processRoomSayEvent(const Event_RoomSay &event)
QString senderName = QString::fromStdString(event.name());
QString message = QString::fromStdString(event.message());
if (tabSupervisor->getTabAccount()->getIgnoreList()->getUsers().contains(senderName))
if (userListProxy->getOnlineUser(senderName))
return;
UserListTWI *twi = userList->getUsers().value(senderName);

View file

@ -9,6 +9,8 @@
#include <QKeyEvent>
#include <QMap>
class UserlistProxy;
class UserListManager;
namespace google
{
namespace protobuf
@ -49,6 +51,7 @@ private:
GameSelector *gameSelector;
UserListWidget *userList;
const UserlistProxy *userListProxy;
ChatView *chatView;
QLabel *sayLabel;
LineEditCompleter *sayEdit;
@ -89,6 +92,7 @@ public:
TabRoom(TabSupervisor *_tabSupervisor,
AbstractClient *_client,
ServerInfo_User *_ownUser,
const UserlistProxy *_userListProxy,
const ServerInfo_Room &info);
void retranslateUi() override;
void closeRequest(bool forced = false) override;

View file

@ -2,6 +2,7 @@
#include "../../client/game_logic/abstract_client.h"
#include "../../main.h"
#include "../../server/user/user_list_manager.h"
#include "../../server/user/user_list_widget.h"
#include "../../settings/cache_settings.h"
#include "../ui/pixel_map_generator.h"
@ -114,6 +115,8 @@ TabSupervisor::TabSupervisor(AbstractClient *_client, QMenu *tabsMenu, QWidget *
tabBar()->setStyle(new MacOSTabFixStyle);
#endif
userListManager = new UserListManager(client, this);
// connect tab changes
connect(this, &TabSupervisor::currentChanged, this, &TabSupervisor::updateCurrent);
@ -291,6 +294,8 @@ void TabSupervisor::start(const ServerInfo_User &_userInfo)
isLocalGame = false;
userInfo = new ServerInfo_User(_userInfo);
userListManager->handleConnect();
resetTabsMenu();
tabsMenu->addSeparator();
@ -395,6 +400,8 @@ void TabSupervisor::stop()
tab->closeRequest(true);
}
userListManager->handleDisconnect();
delete userInfo;
userInfo = 0;
}
@ -535,7 +542,7 @@ void TabSupervisor::gameJoined(const Event_GameJoined &event)
roomGameTypes.insert(event.game_types(i).game_type_id(),
QString::fromStdString(event.game_types(i).description()));
TabGame *tab = new TabGame(this, QList<AbstractClient *>() << client, event, roomGameTypes);
TabGame *tab = new TabGame(this, userListManager, QList<AbstractClient *>() << client, event, roomGameTypes);
connect(tab, &TabGame::gameClosing, this, &TabSupervisor::gameLeft);
connect(tab, &TabGame::openMessageDialog, this, &TabSupervisor::addMessageTab);
connect(tab, &TabGame::openDeckEditor, this, &TabSupervisor::addDeckEditorTab);
@ -546,7 +553,7 @@ void TabSupervisor::gameJoined(const Event_GameJoined &event)
void TabSupervisor::localGameJoined(const Event_GameJoined &event)
{
TabGame *tab = new TabGame(this, localClients, event, QMap<int, QString>());
TabGame *tab = new TabGame(this, userListManager, localClients, event, QMap<int, QString>());
connect(tab, &TabGame::gameClosing, this, &TabSupervisor::gameLeft);
connect(tab, &TabGame::openDeckEditor, this, &TabSupervisor::addDeckEditorTab);
myAddTab(tab);
@ -574,7 +581,7 @@ void TabSupervisor::gameLeft(TabGame *tab)
void TabSupervisor::addRoomTab(const ServerInfo_Room &info, bool setCurrent)
{
TabRoom *tab = new TabRoom(this, client, userInfo, info);
TabRoom *tab = new TabRoom(this, client, userInfo, userListManager, info);
connect(tab, &TabRoom::maximizeClient, this, &TabSupervisor::maximizeMainWindow);
connect(tab, &TabRoom::roomClosing, this, &TabSupervisor::roomLeft);
connect(tab, &TabRoom::openMessageDialog, this, &TabSupervisor::addMessageTab);
@ -616,11 +623,11 @@ TabMessage *TabSupervisor::addMessageTab(const QString &receiverName, bool focus
return nullptr;
ServerInfo_User otherUser;
UserListTWI *twi = tabAccount->getAllUsersList()->getUsers().value(receiverName);
if (twi)
otherUser = twi->getUserInfo();
else
if (auto user = userListManager->getOnlineUser(receiverName)) {
otherUser = ServerInfo_User(*user);
} else {
otherUser.set_name(receiverName.toStdString());
}
TabMessage *tab;
tab = messageTabs.value(QString::fromStdString(otherUser.name()));
@ -717,9 +724,9 @@ void TabSupervisor::processUserMessageEvent(const Event_UserMessage &event)
if (!tab)
tab = messageTabs.value(QString::fromStdString(event.receiver_name()));
if (!tab) {
UserListTWI *twi = tabAccount->getAllUsersList()->getUsers().value(senderName);
if (twi) {
UserLevelFlags userLevel = UserLevelFlags(twi->getUserInfo().user_level());
const ServerInfo_User *userInfo = userListManager->getOnlineUser(senderName);
if (userInfo) {
UserLevelFlags userLevel = UserLevelFlags(userInfo->user_level());
if (SettingsCache::instance().getIgnoreUnregisteredUserMessages() &&
!userLevel.testFlag(ServerInfo_User::IsRegistered))
// Flags are additive, so reg/mod/admin are all IsRegistered
@ -753,15 +760,15 @@ void TabSupervisor::processUserLeft(const QString &userName)
void TabSupervisor::processUserJoined(const ServerInfo_User &userInfoJoined)
{
QString userName = QString::fromStdString(userInfoJoined.name());
if (isUserBuddy(userName)) {
Tab *tab = static_cast<Tab *>(getTabAccount());
if (tab != currentWidget()) {
tab->setContentsChanged(true);
QPixmap avatarPixmap =
UserLevelPixmapGenerator::generatePixmap(13, (UserLevelFlags)userInfoJoined.user_level(), true,
QString::fromStdString(userInfoJoined.privlevel()));
setTabIcon(indexOf(tab), QPixmap(avatarPixmap));
if (userListManager->isUserBuddy(userName)) {
if (auto *tab = getTabAccount()) {
if (tab != currentWidget()) {
tab->setContentsChanged(true);
QPixmap avatarPixmap =
UserLevelPixmapGenerator::generatePixmap(13, (UserLevelFlags)userInfoJoined.user_level(), true,
QString::fromStdString(userInfoJoined.privlevel()));
setTabIcon(indexOf(tab), QPixmap(avatarPixmap));
}
}
if (SettingsCache::instance().getBuddyConnectNotificationsEnabled()) {
@ -849,57 +856,6 @@ void TabSupervisor::processNotifyUserEvent(const Event_NotifyUser &event)
}
}
bool TabSupervisor::isOwnUserRegistered() const
{
return userInfo != nullptr && (userInfo->user_level() & ServerInfo_User::IsRegistered) != 0;
}
QString TabSupervisor::getOwnUsername() const
{
return userInfo != nullptr ? QString::fromStdString(userInfo->name()) : QString();
}
bool TabSupervisor::isUserBuddy(const QString &userName) const
{
if (!getTabAccount())
return false;
if (!getTabAccount()->getBuddyList())
return false;
QMap<QString, UserListTWI *> buddyList = getTabAccount()->getBuddyList()->getUsers();
bool senderIsBuddy = buddyList.contains(userName);
return senderIsBuddy;
}
bool TabSupervisor::isUserIgnored(const QString &userName) const
{
if (!getTabAccount())
return false;
if (!getTabAccount()->getIgnoreList())
return false;
QMap<QString, UserListTWI *> buddyList = getTabAccount()->getIgnoreList()->getUsers();
bool senderIsBuddy = buddyList.contains(userName);
return senderIsBuddy;
}
const ServerInfo_User *TabSupervisor::getOnlineUser(const QString &userName) const
{
if (!getTabAccount())
return nullptr;
if (!getTabAccount()->getAllUsersList())
return nullptr;
QMap<QString, UserListTWI *> userList = getTabAccount()->getAllUsersList()->getUsers();
const QString &userNameToMatchLower = userName.toLower();
QMap<QString, UserListTWI *>::iterator i;
for (i = userList.begin(); i != userList.end(); ++i)
if (i.key().toLower() == userNameToMatchLower) {
const ServerInfo_User &_userInfo = i.value()->getUserInfo();
return &_userInfo;
}
return nullptr;
};
bool TabSupervisor::switchToGameTabIfAlreadyExists(const int gameId)
{
bool isGameTabExists = false;

View file

@ -11,6 +11,7 @@
#include <QProxyStyle>
#include <QTabWidget>
class UserListManager;
class QMenu;
class AbstractClient;
class Tab;
@ -62,12 +63,13 @@ protected:
void paintEvent(QPaintEvent *event) override;
};
class TabSupervisor : public QTabWidget, public UserlistProxy
class TabSupervisor : public QTabWidget
{
Q_OBJECT
private:
ServerInfo_User *userInfo;
AbstractClient *client;
UserListManager *userListManager;
QList<AbstractClient *> localClients;
QMenu *tabsMenu;
TabDeckStorageVisual *tabVisualDeckStorage;
@ -117,17 +119,16 @@ public:
return userInfo;
}
AbstractClient *getClient() const;
const UserListManager *getUserListManager() const
{
return userListManager;
}
const QMap<int, TabRoom *> &getRoomTabs() const
{
return roomTabs;
}
bool getAdminLocked() const;
bool closeRequest();
bool isOwnUserRegistered() const override;
QString getOwnUsername() const override;
bool isUserBuddy(const QString &userName) const override;
bool isUserIgnored(const QString &userName) const override;
const ServerInfo_User *getOnlineUser(const QString &userName) const override;
bool switchToGameTabIfAlreadyExists(const int gameId);
void actShowPopup(const QString &message);
signals: