Skip to content

Commit

Permalink
Merge branch 'development' into mmcp-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
jlabmckisson committed Apr 30, 2024
2 parents c01f5f1 + f56291b commit 0e55b62
Show file tree
Hide file tree
Showing 27 changed files with 730 additions and 452 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/dangerjs.yml
Expand Up @@ -14,11 +14,7 @@ jobs:
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
fetch-depth: 0
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "14.x"
- name: Install yarn dependencies
- name: Install yarn dependencies and run danger
run: |
yarn add danger --dev
yarn danger ci
Expand Down
2 changes: 1 addition & 1 deletion 3rdparty/edbee-lib
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Expand Up @@ -139,6 +139,7 @@ set(mudlet_SRCS
TMap.cpp
TMapLabel.cpp
TMedia.cpp
TMediaPlaylist.cpp
TMxpElementDefinitionHandler.cpp
TMxpElementRegistry.cpp
TMxpFormattingTagsHandler.cpp
Expand Down Expand Up @@ -309,6 +310,7 @@ set(mudlet_HDRS
TMapLabel.h
TMatchState.h
TMedia.h
TMediaPlaylist.h
TMxpBRTagHandler.h
TMxpClient.h
TMxpColorTagHandler.h
Expand Down
164 changes: 111 additions & 53 deletions src/Host.cpp
Expand Up @@ -245,7 +245,6 @@ Host::Host(int port, const QString& hostname, const QString& login, const QStrin
, mSslIgnoreAll(false)
, mUseProxy(false)
, mProxyPort(0)
, mIsGoingDown(false)
, mIsProfileLoadingSequence(false)
, mNoAntiAlias(false)
, mpEditorDialog(nullptr)
Expand Down Expand Up @@ -360,7 +359,6 @@ Host::Host(int port, const QString& hostname, const QString& login, const QStrin
, mGifTracker()
, mHostID(id)
, mHostName(hostname)
, mIsClosingDown(false)
, mLogin(login)
, mPass(pass)
, mPort(port)
Expand All @@ -382,7 +380,7 @@ Host::Host(int port, const QString& hostname, const QString& login, const QStrin
, mDebugShowAllProblemCodepoints(false)
, mCompactInputLine(false)
{
TDebug::addHost(this);
TDebug::addHost(this, mHostName);

// The "autolog" sentinel file controls whether logging the game's text as
// plain text or HTML is immediately resumed on profile loading. Do not
Expand Down Expand Up @@ -495,11 +493,114 @@ Host::~Host()
if (mpDockableMapWidget) {
mpDockableMapWidget->deleteLater();
}
mIsGoingDown = true;
mIsClosingDown = true;
mErrorLogStream.flush();
mErrorLogFile.close();
TDebug::removeHost(this);
// Since this is a destructor, it's risky to rely on member variables within the destructor itself.
// To avoid this, we can pass the profile name as an argument instead of accessing it
// directly as a member variable. This ensures the destructor doesn't depend on the
// object's state being valid.

TDebug::removeHost(this, mHostName);
}

void Host::forceClose()
{
if (!mpConsole) {
// The main console has gone away so we must already be dying
return;
}

mForcedClose = true;
postMessage(tr("[ ALERT ] - This profile will now save and close."));
// Ensure the above is displayed before proceeding...
qApp->processEvents();

// Because we have set the mForcedClose flag above a requestClose()
// afterwards WILL succeed
}

// Returns true if we are closing down
bool Host::requestClose()
{
if (!mpConsole) {
// The main console has gone away so we must already be dying
return true;
}

// This call ends up at the (void) TMainConsole::closeEvent(...) and causes
// the close() method called here to return a true if the event was
// accepted:
if (!mpConsole->close()) {
// Nope the user doesn't want this to close - and it won't have set its
// mEnableClose flag:
return false;
}

// The above will have initiated a save of the profile (and its map) if it
// got a true returned from the TMainConsole::close() call.

// Get rid of any dialogs we might have open:
closeChildren();

// This time this will succeed as mEnableClose is set:
mpConsole->close();
return true;
}

void Host::closeChildren()
{
mIsClosingDown = true;
const auto hostToolBarMap = getActionUnit()->getToolBarList();
// disconnect before removing objects from memory as sysDisconnectionEvent needs that stuff.
if (mSslTsl) {
mTelnet.abortConnection();
} else {
mTelnet.disconnectIt();
}

stopAllTriggers();

if (mpEditorDialog) {
mpEditorDialog->setAttribute(Qt::WA_DeleteOnClose);
mpEditorDialog->close();
mpEditorDialog = nullptr;
}

for (const QString& consoleName : mpConsole->mSubConsoleMap.keys()) {
// Only user-windows will be in this map:
auto pD = mpConsole->mDockWidgetMap.value(consoleName);
// All User TConsole's will be in this map:
auto pC = mpConsole->mSubConsoleMap.value(consoleName);
if (pD) {
// This undocks the widget
mudlet::self()->removeDockWidget(pD);
}

// This will remove both what pD and pC point at from their respective
// QMaps:
pC->close();
}

if (mpNotePad) {
mpNotePad->save();
mpNotePad->setAttribute(Qt::WA_DeleteOnClose);
mpNotePad->close();
mpNotePad = nullptr;
}

for (TToolBar* pTB : hostToolBarMap) {
if (pTB) {
pTB->setAttribute(Qt::WA_DeleteOnClose);
pTB->deleteLater();
}
}

// close IRC client window if it is open.
if (mpDlgIRC) {
mpDlgIRC->setAttribute(Qt::WA_DeleteOnClose);
mpDlgIRC->deleteLater();
mpDlgIRC = nullptr;
}
}

void Host::loadMap()
Expand Down Expand Up @@ -845,7 +946,7 @@ std::tuple<bool, QString, QString> Host::saveProfile(const QString& saveFolder,
}

if (mIsProfileLoadingSequence) {
//If we're inside of profile loading sequence modules might not be loaded yet, thus we can accidetnally clear their contents
//If we're inside of profile loading sequence modules might not be loaded yet, thus we can accidentally clear their contents
return {false, filename_xml, qsl("profile loading is in progress")};
}

Expand All @@ -860,8 +961,9 @@ std::tuple<bool, QString, QString> Host::saveProfile(const QString& saveFolder,

if (saveFolder.isEmpty() && saveName.isEmpty()) {
// This is likely to be the save as the profile is closed
qDebug().noquote().nospace() << "Host::saveProfile(...) INFO - called with no saveFolder or saveName arguments "
"so assuming it is a end of session save and the TCommandLines' histories need saving...";
qDebug().noquote().nospace() << "Host::saveProfile(...) INFO - called with no saveFolder or saveName arguments for profile '"
<< mHostName
<< "' so assuming it is an end of session save and the TCommandLines' histories need saving...";
emit signal_saveCommandLinesHistory();
}

Expand Down Expand Up @@ -1703,16 +1805,6 @@ bool Host::killTrigger(const QString& name)
return mTriggerUnit.killTrigger(name);
}

void Host::closingDown()
{
mIsClosingDown = true;
}

bool Host::isClosingDown()
{
return mIsClosingDown;
}

std::pair<bool, QString> Host::installPackage(const QString& fileName, int module)
{
// As the pointer to dialog is only used now WITHIN this method and this
Expand Down Expand Up @@ -3297,40 +3389,6 @@ void Host::hideMudletsVariables()
}
}

void Host::close()
{
// disconnect before removing objects from memory as sysDisconnectionEvent needs that stuff.
if (mSslTsl) {
mTelnet.abortConnection();
} else {
mTelnet.disconnectIt();
}

// close script editor
if (mpEditorDialog) {
mpEditorDialog->setAttribute(Qt::WA_DeleteOnClose);
mpEditorDialog->close();
mpEditorDialog = nullptr;
}
// close notepad
if (mpNotePad) {
mpNotePad->save();
mpNotePad->setAttribute(Qt::WA_DeleteOnClose);
mpNotePad->close();
mpNotePad = nullptr;
}
// close IRC client window
if (mpDlgIRC) {
mpDlgIRC->setAttribute(Qt::WA_DeleteOnClose);
mpDlgIRC->deleteLater();
mpDlgIRC = nullptr;
}
if (mpConsole) {
mpConsole->close();
mpConsole = nullptr;
}
}

bool Host::createBuffer(const QString& name)
{
if (!mpConsole) {
Expand Down
16 changes: 11 additions & 5 deletions src/Host.h
Expand Up @@ -213,8 +213,11 @@ class Host : public QObject
bool getLargeAreaExitArrows() const { return mLargeAreaExitArrows; }
void setLargeAreaExitArrows(const bool);

void closingDown();
bool isClosingDown();
void forceClose();
bool isClosingDown() const { return mIsClosingDown; }
bool isClosingForced() const { return mForcedClose; }
bool requestClose();

unsigned int assemblePath();
bool checkForMappingScript();
bool checkForCustomSpeedwalk();
Expand Down Expand Up @@ -367,7 +370,6 @@ class Host : public QObject
void setCompactInputLine(const bool state);
bool getCompactInputLine() const { return mCompactInputLine; }
QPointer<TConsole> findConsole(QString name);
void close();

QPair<bool, QStringList> getLines(const QString& windowName, const int lineFrom, const int lineTo);
std::pair<bool, QString> openWindow(const QString& name, bool loadLayout, bool autoDock, const QString& area);
Expand Down Expand Up @@ -489,7 +491,6 @@ class Host : public QObject
QString mProxyUsername;
QString mProxyPassword;

bool mIsGoingDown;
// Used to force the test compilation of the scripts for TActions ("Buttons")
// that are pushdown buttons that run when they are "pushed down" during
// loading even though the buttons start out with themselves NOT being
Expand Down Expand Up @@ -763,6 +764,7 @@ private slots:
void autoSaveMap();
QString sanitizePackageName(const QString packageName) const;
TCommandLine* activeCommandLine();
void closeChildren();


QFont mDisplayFont;
Expand All @@ -786,7 +788,7 @@ private slots:
int mHostID;
QString mHostName;
QString mDiscordGameName; // Discord self-reported game name
bool mIsClosingDown;
bool mIsClosingDown = false;

QString mLine;
QString mLogin;
Expand Down Expand Up @@ -937,6 +939,10 @@ private slots:

// Whether to display each item's ID number in the editor:
bool mShowIDsInEditor = false;

// Set when the mudlet singleton demands that we close - used to force an
// attempt to save the profile and map - without asking:
bool mForcedClose = false;
};

Q_DECLARE_OPERATORS_FOR_FLAGS(Host::DiscordOptionFlags)
Expand Down
14 changes: 8 additions & 6 deletions src/HostManager.cpp
Expand Up @@ -25,16 +25,18 @@
#include "dlgMapper.h"
#include "mudlet.h"

bool HostManager::deleteHost(const QString& hostname)
void HostManager::deleteHost(const QString& hostname)
{
// make sure this is really a new host
// make sure this is really an existing host
if (!mHostPool.contains(hostname)) {
qDebug() << "HostManager::deleteHost(" << hostname.toUtf8().constData() << ") ERROR: not a member of host pool... aborting!";
return false;
} else {
const int ret = mHostPool.remove(hostname);
return ret;
return;
}

// As this pulls the QSharedPointer that hostname identifies out of the pool
// the Host goes out of scope when execution leaves this method and thus
// gets destroyed:
mHostPool.remove(hostname);
}

bool HostManager::addHost(const QString& hostname, const QString& port, const QString& login, const QString& pass)
Expand Down
4 changes: 2 additions & 2 deletions src/HostManager.h
Expand Up @@ -52,12 +52,12 @@ class HostManager


public:
HostManager() = default; /* : mpActiveHost() - Not needed */
HostManager() = default;

Host* getHost(const QString& hostname);
bool addHost(const QString& name, const QString& port, const QString& login, const QString& pass);
int getHostCount();
bool deleteHost(const QString&);
void deleteHost(const QString&);
void postIrcMessage(const QString&, const QString&, const QString&);
void postInterHostEvent(const Host*, const TEvent&, const bool = false);
void changeAllHostColour(const Host*);
Expand Down
5 changes: 5 additions & 0 deletions src/TBuffer.cpp
Expand Up @@ -2750,8 +2750,13 @@ inline int TBuffer::wrap(int startLine)
return insertedLines > 0 ? insertedLines : 0;
}

// This only works on the Main Console for a profile
void TBuffer::log(int fromLine, int toLine)
{
if (mpHost.isNull()) {
return;
}

TBuffer* pB = &mpHost->mpConsole->buffer;
if (pB != this || !mpHost->mpConsole->mLogToLogFile) {
return;
Expand Down

0 comments on commit 0e55b62

Please sign in to comment.