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
jmckisson committed Apr 12, 2024
2 parents a0e809a + ec3df4b commit a365885
Show file tree
Hide file tree
Showing 14 changed files with 253 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Expand Up @@ -31,7 +31,7 @@ Don't:
* translate the Mudlet API: functions, events, error messages or constants (e.g. `main` console)
* use numbers in the API - English words are preferred instead
* try to assemble a sentence on the fly - English grammar does not translate into other languages. Present the full sentence to translators instead
* assume English-centric plural forms, other languages do not necessarily have the simple add an "s"/"es" for more/less then the singular case.
* assume English-centric plural forms, other languages do not necessarily have the simple add an "s"/"es" for more/less than the singular case.
* assume universal quote and number punctuation formats. There are languages that use « and » instead of " for "quoting" words or phrases. Qt can provide Locale specific displays of numbers/dates/times.

# Tooltip tips:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/clangtidy-diff-analysis.yml
Expand Up @@ -122,7 +122,7 @@ jobs:
--target autogen
- name: Check C++ changes against style guide
uses: ZedThree/clang-tidy-review@v0.17.1
uses: ZedThree/clang-tidy-review@v0.18.0
id: static_analysis
with:
build_dir: 'b/ninja' # path is relative to checkout directory
Expand All @@ -133,4 +133,4 @@ jobs:
split_workflow: true

- name: Upload check results
uses: ZedThree/clang-tidy-review/upload@v0.17.1
uses: ZedThree/clang-tidy-review/upload@v0.18.0
2 changes: 1 addition & 1 deletion .github/workflows/clangtidy-post-comments.yml
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: ZedThree/clang-tidy-review/post@v0.17.1
- uses: ZedThree/clang-tidy-review/post@v0.18.0
with:
# don't post any comments if the PR is fine
lgtm_comment_body: ''
Expand Down
2 changes: 1 addition & 1 deletion CI/appveyor.functions.ps1
Expand Up @@ -196,7 +196,7 @@ function InstallCmake() {
}

function InstallMingwGet() {
DownloadFile "https://osdn.net/frs/redir.php?m=rwthaachen&f=mingw%2F68260%2Fmingw-get-0.6.3-mingw32-pre-20170905-1-bin.zip" "mingw-get.zip"
DownloadFile "https://osdn.net/frs/redir.php?m=ipconnect&f=mingw%2F68260%2Fmingw-get-0.6.3-mingw32-pre-20170905-1-bin.zip" "mingw-get.zip"
if (!(Test-Path -Path "C:\MinGW" -PathType Container)) {
Step "Creating MinGW path"
New-Item -Path "C:\MinGW" -ItemType "directory" >> "$logFile" 2>&1
Expand Down
47 changes: 26 additions & 21 deletions src/CMakeLists.txt
Expand Up @@ -67,8 +67,8 @@ set(mudlet_SRCS
dlgConnectionProfiles.cpp
dlgIRC.cpp
dlgKeysMainArea.cpp
dlgMapper.cpp
dlgMapLabel.cpp
dlgMapper.cpp
dlgModuleManager.cpp
dlgNotepad.cpp
dlgPackageExporter.cpp
Expand All @@ -87,10 +87,10 @@ set(mudlet_SRCS
dlgVarsMainArea.cpp
EAction.cpp
exitstreewidget.cpp
FontManager.cpp
FileOpenHandler.cpp
FontManager.cpp
GifTracker.cpp
TrailingWhitespaceMarker.cpp
GMCPAuthenticator.cpp
Host.cpp
HostManager.cpp
ircmessageformatter.cpp
Expand All @@ -103,8 +103,9 @@ set(mudlet_SRCS
TLuaInterpreterMMCP.cpp
mudlet.cpp
MudletInstanceCoordinator.cpp
ShortcutsManager.cpp
MxpTag.cpp
ScriptUnit.cpp
ShortcutsManager.cpp
T2DMap.cpp
TAccessibleTextEdit.cpp
TAction.cpp
Expand All @@ -124,7 +125,6 @@ set(mudlet_SRCS
TimerUnit.cpp
TKey.cpp
TLabel.cpp
TScrollBox.cpp
TLinkStore.cpp

TLuaInterpreter.cpp
Expand All @@ -145,26 +145,30 @@ set(mudlet_SRCS
TMxpBRTagHandler.cpp
TMxpColorTagHandler.cpp
TMxpCustomElementTagHandler.cpp
TMxpElementDefinitionHandler.cpp
TMxpElementRegistry.cpp
TMxpEntityTagHandler.cpp
TMxpFontTagHandler.cpp
TMxpFormattingTagsHandler.cpp
TMxpLinkTagHandler.cpp
TMxpMudlet.cpp
TMxpMusicTagHandler.cpp
TMxpNodeBuilder.cpp
TMxpMudlet.cpp
TMxpProcessor.cpp
TMxpSendTagHandler.cpp
TMxpSoundTagHandler.cpp
TMxpSupportTagHandler.cpp
MxpTag.cpp
TMxpTagHandler.cpp
TMxpTagParser.cpp
TMxpTagProcessor.cpp
TMxpVarTagHandler.cpp
TMxpVersionTagHandler.cpp
TrailingWhitespaceMarker.cpp
TriggerUnit.cpp
TRoom.cpp
TRoomDB.cpp
TScript.cpp
TScrollBox.cpp
TSplitter.cpp
TSplitterHandle.cpp
TStringUtils.cpp
Expand Down Expand Up @@ -221,9 +225,9 @@ set(mudlet_UIS

set(mudlet_HDRS
ActionUnit.h
Announcer.h
AliasUnit.h
AltFocusMenuBarDisable.h
Announcer.h
ctelnet.h
DarkTheme.h
discord.h
Expand Down Expand Up @@ -258,7 +262,7 @@ set(mudlet_HDRS
FileOpenHandler.h
FontManager.h
GifTracker.h
TrailingWhitespaceMarker.h
GMCPAuthenticator.h
Host.h
HostManager.h
ircmessageformatter.h
Expand All @@ -270,10 +274,11 @@ set(mudlet_HDRS
MMCPClient.h
mudlet.h
MudletInstanceCoordinator.h
MxpTag.h
post_guard.h
pre_guard.h
ShortcutsManager.h
ScriptUnit.h
ShortcutsManager.h
T2DMap.h
TAccessibleConsole.h
TAccessibleTextEdit.h
Expand All @@ -292,12 +297,11 @@ set(mudlet_HDRS
TEntityResolver.h
testdbg.h
TEvent.h
TForkedProcess.h
TFlipButton.h
TForkedProcess.h
TimerUnit.h
TKey.h
TLabel.h
TScrollBox.h
TLinkStore.h
TLuaInterpreter.h
TMainConsole.h
Expand All @@ -308,32 +312,33 @@ set(mudlet_HDRS
TMxpBRTagHandler.h
TMxpClient.h
TMxpColorTagHandler.h
TMxpContext.h
TMxpCustomElementTagHandler.h
TMxpEntityTagHandler.h
TMxpFontTagHandler.h
TMxpLinkTagHandler.h
TMxpMusicTagHandler.h
TMxpSoundTagHandler.h
TMxpElementDefinitionHandler.h
TMxpElementRegistry.h
TMxpContext.h
TMxpEntityTagHandler.h
TMxpFontTagHandler.h
TMxpFormattingTagsHandler.h
TMxpLinkTagHandler.h
TMxpMudlet.h
TMxpMusicTagHandler.h
TMxpNodeBuilder.h
TMxpProcessor.h
TMxpSendTagHandler.h
MxpTag.h
TMxpSoundTagHandler.h
TMxpSupportTagHandler.cpp
TMxpTagHandler.h
TMxpTagParser.h
TMxpTagProcessor.h
TMxpSupportTagHandler.cpp
TMxpVarTagHandler.h
TMxpVersionTagHandler.h
TrailingWhitespaceMarker.h
Tree.h
TriggerUnit.h
TRoom.h
TRoomDB.h
TScript.h
TScrollBox.h
TSplitter.h
TSplitterHandle.h
TStringUtils.h
Expand All @@ -345,8 +350,8 @@ set(mudlet_HDRS
TTreeWidget.h
TTrigger.h
TVar.h
VarUnit.h
utils.h
VarUnit.h
widechar_width.h
XMLexport.h
XMLimport.h)
Expand Down
129 changes: 129 additions & 0 deletions src/GMCPAuthenticator.cpp
@@ -0,0 +1,129 @@
/***************************************************************************
* Copyright (C) 2024 by Vadim Peretokin - vperetokin@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/

#include "GMCPAuthenticator.h"

#include "Host.h"
#include "ctelnet.h"
#include <QDebug>

GMCPAuthenticator::GMCPAuthenticator(Host* pHost)
: mpHost(pHost)
{}

void GMCPAuthenticator::saveSupportsSet(const QString& data)
{
auto jsonDoc = QJsonDocument::fromJson(data.toUtf8());
auto jsonObj = jsonDoc.object();

if (jsonObj.contains("type")) {
QJsonArray typesArray = jsonObj["type"].toArray();
for (const auto& type : typesArray) {
mSupportedAuthTypes.append(type.toString());
}
}

#if defined(DEBUG_GMCP_AUTHENTICATION)
qDebug() << "Supported auth types:" << mSupportedAuthTypes;
#endif
}

void GMCPAuthenticator::sendCredentials()
{
auto character = mpHost->getLogin();
auto password = mpHost->getPass();
QJsonObject credentials;
if (!character.isEmpty() && !password.isEmpty()) {
credentials["account"] = character;
credentials["password"] = password;
}
QJsonDocument doc(credentials);
QString gmcpMessage = doc.toJson(QJsonDocument::Compact);

std::string output;
output += TN_IAC;
output += TN_SB;
output += OPT_GMCP;
output += "Char.Login.Credentials ";
output += mpHost->mTelnet.encodeAndCookBytes(gmcpMessage.toStdString());
output += TN_IAC;
output += TN_SE;

// Send credentials to server
mpHost->mTelnet.socketOutRaw(output);
#if defined(DEBUG_GMCP_AUTHENTICATION)
qDebug() << "Sent GMCP credentials";
#endif
}


void GMCPAuthenticator::handleAuthResult(const QString& data)
{
auto doc = QJsonDocument::fromJson(data.toUtf8());
auto obj = doc.object();

// some game drivers can parse JSON for true or false, but may not be able to write booleans back
auto result = obj[qsl("success")];
bool success = (result.isBool() && result.toBool()) || (result.isString() && result.toString() == "true");
auto message = obj[qsl("message")].toString();

if (success) {
#if defined(DEBUG_GMCP_AUTHENTICATION)
qDebug() << "GMCP login successful";
#endif
} else {
#if defined(DEBUG_GMCP_AUTHENTICATION)
qDebug() << "GMCP login failed:" << message;
#endif
mpHost->mTelnet.setDontReconnect(true);
if (message.isEmpty()) {
mpHost->postMessage(tr("[ WARN ] - Could not log in to the game, is the login information correct?"));
} else {
mpHost->postMessage(tr("[ WARN ] - Could not log in to the game: %1").arg(message));
}

}
}

// controller for GMCP authentication
void GMCPAuthenticator::handleAuthGMCP(const QString& packageMessage, const QString& data)
{
if (packageMessage == qsl("Char.Login.Default")) {
saveSupportsSet(data);

if (mSupportedAuthTypes.contains(qsl("password-credentials"))) {
mpHost->mTelnet.cancelLoginTimers();
sendCredentials();
} else {
#if defined(DEBUG_GMCP_AUTHENTICATION)
qDebug() << "Server does not support credentials authentication and we don't support any other";
#endif
}
return;
}

if (packageMessage == qsl("Char.Login.Result")) {
handleAuthResult(data);
return;
}

#if defined(DEBUG_GMCP_AUTHENTICATION)
qDebug() << "Unknown GMCP auth package:" << packageMessage;
#endif
}

0 comments on commit a365885

Please sign in to comment.