-
Notifications
You must be signed in to change notification settings - Fork 35
Upgrade xiloader to use json, add SHA-1 OTP support, upgrade CPM, mbedtls #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| CPMAddPackage( | ||
| NAME ftxui | ||
| GITHUB_REPOSITORY arthursonzogni/ftxui | ||
| GIT_TAG v6.1.9 | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| CPMAddPackage( | ||
| NAME nlohmann_json | ||
| GITHUB_REPOSITORY nlohmann/json | ||
| GIT_TAG v3.12.0 | ||
| OPTIONS | ||
| "JSON_ImplicitConversions OFF" #Recommended by the author | ||
| "JSON_BuildTests OFF" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| CPMAddPackage( | ||
| NAME qr-code-generator | ||
| GITHUB_REPOSITORY nayuki/QR-Code-generator | ||
| GIT_TAG 720f62bddb7226106071d4728c292cb1df519ceb | ||
| LANGUAGES CXX | ||
| DOWNLOAD_ONLY | ||
| ) | ||
|
|
||
| if(qr-code-generator_ADDED) | ||
| add_library(qr-code-generator | ||
| STATIC | ||
| ${qr-code-generator_SOURCE_DIR}/cpp/qrcodegen.cpp | ||
| ${qr-code-generator_SOURCE_DIR}/cpp/qrcodegen.hpp | ||
| ) | ||
| target_include_directories(qr-code-generator | ||
| SYSTEM INTERFACE | ||
| ${qr-code-generator_SOURCE_DIR}/cpp | ||
| ) | ||
| endif() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,203 @@ | ||
| /* | ||
| =========================================================================== | ||
|
|
||
| Copyright (c) 2025 LandSandBoat Dev Teams | ||
|
|
||
| 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 3 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, see http://www.gnu.org/licenses/ | ||
|
|
||
| =========================================================================== | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| /* Externals */ | ||
| namespace globals | ||
| { | ||
| extern std::string g_ServerAddress; | ||
| extern std::string g_Username; | ||
| extern std::string g_Password; | ||
| extern std::string g_OtpCode; | ||
| extern char g_SessionHash[16]; | ||
| extern std::string g_Email; | ||
| extern std::array<uint8_t, 3> g_VersionNumber; | ||
| extern uint16_t g_ServerPort; | ||
| extern uint16_t g_LoginDataPort; | ||
| extern uint16_t g_LoginViewPort; | ||
| extern uint16_t g_LoginAuthPort; | ||
| extern char* g_CharacterList; | ||
| extern bool g_IsRunning; | ||
| extern bool g_FirstLogin; | ||
| } // namespace globals | ||
|
|
||
| #include "defines.h" | ||
| #include "helpers.h" | ||
| #include "network.h" | ||
|
|
||
| #include <nlohmann/json.hpp> | ||
| #include <qrcodegen.hpp> | ||
|
|
||
| using json = nlohmann::json; | ||
|
|
||
| bool handleLoginCommand(int8_t command, json& login_reply_json, uint32_t& accountId, SOCKET& sock) | ||
| { | ||
| /* Handle the obtained result.. */ | ||
| switch (command) | ||
| { | ||
| case 0x0001: // Success (Login) | ||
| { | ||
| std::optional maybeAccountId = jsonGet<uint32_t>(login_reply_json, "account_id"); | ||
| if (maybeAccountId.has_value()) | ||
| { | ||
| accountId = maybeAccountId.value(); | ||
| } | ||
| else | ||
| { | ||
| xiloader::console::output(xiloader::color::error, "xi_connect failed to reply with an account ID"); | ||
| break; | ||
| } | ||
|
|
||
| auto maybeSessionHash = jsonGet<char, 16>(login_reply_json, "session_hash"); | ||
|
|
||
| if (maybeSessionHash.has_value()) | ||
| { | ||
| std::memcpy(&globals::g_SessionHash, maybeSessionHash.value().data(), maybeSessionHash.value().size()); | ||
| } | ||
| else | ||
| { | ||
| xiloader::console::output(xiloader::color::error, "xi_connect failed to reply with a valid session hash"); | ||
| break; | ||
| } | ||
|
|
||
| xiloader::console::output(xiloader::color::success, "Successfully logged in as %s!", globals::g_Username.c_str()); | ||
|
|
||
| shutdown(sock, SD_BOTH); | ||
|
|
||
| return true; | ||
| } | ||
| case 0x0002: // Error (Login) | ||
| { | ||
| xiloader::console::output(xiloader::color::error, "Failed to login. Invalid username or password."); | ||
|
|
||
| return false; | ||
| } | ||
| case 0x0003: // Success (Create Account) | ||
| { | ||
| xiloader::console::output(xiloader::color::success, "Account successfully created!"); | ||
|
|
||
| return false; | ||
| } | ||
| case 0x0004: // Error (Create Account) | ||
| { | ||
| xiloader::console::output(xiloader::color::error, "Failed to create the new account. Username already taken."); | ||
|
|
||
| return false; | ||
| } | ||
| case 0x0006: // Success (Changed Password) | ||
| { | ||
| xiloader::console::output(xiloader::color::success, "Password updated successfully!"); | ||
| globals::g_Password.clear(); | ||
|
|
||
| return false; | ||
| } | ||
| case 0x0007: // Error (Changed Password) | ||
| { | ||
| xiloader::console::output(xiloader::color::error, "Failed to change password."); | ||
| globals::g_Password.clear(); | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| // Commands 0x0008 through 0x0008 are currently unused | ||
|
|
||
| case 0x000A: | ||
| { | ||
| xiloader::console::output(xiloader::color::error, "Failed to login. Account already logged in."); | ||
|
|
||
| return false; | ||
| } | ||
| case 0x000B: | ||
| { | ||
| xiloader::console::output(xiloader::color::error, "Failed to login. Expected xiloader version mismatch; check with your provider."); | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| // LOGIN_SUCCESS_CREATE_TOTP | ||
| case 0x0010: | ||
| { | ||
| std::string uri = ""; | ||
| std::optional<std::string> maybeURI = jsonGet<std::string>(login_reply_json, "TOTP_uri"); | ||
| if (maybeURI.has_value()) | ||
| { | ||
| uri = maybeURI.value(); | ||
| } | ||
| else | ||
| { | ||
| xiloader::console::output(xiloader::color::error, "xi_connect failed to reply with a valid TOTP_uri"); | ||
| return false; | ||
| } | ||
|
|
||
| qrcodegen::QrCode qrCode = qrcodegen::QrCode::encodeText(uri.c_str(), qrcodegen::QrCode::Ecc::LOW); | ||
|
|
||
| std::string svgString = qrToSvgString(qrCode, 4); | ||
| std::string svgFilePath = writeSvgToDisk("temp.svg", svgString); | ||
|
|
||
| xiloader::console::output(xiloader::color::info, "Open your authenticator application on your phone and prepare to scan the QR code."); | ||
|
|
||
| bool display = menus::okCancelDialog("Open QR code in my default browser"); | ||
| if (display) | ||
| { | ||
| ShellExecuteA(nullptr, "open", svgFilePath.c_str(), nullptr, nullptr, SW_SHOWNORMAL); | ||
| xiloader::console::output(xiloader::color::info, "Once saved please use the \"Validate 2FA OTP\" option to verify the OTP."); | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| // LOGIN_SUCCESS_VERIFY_TOTP | ||
| case 0x0011: | ||
| { | ||
| xiloader::console::output(xiloader::color::info, "Your TOTP has been registered with the server"); | ||
| xiloader::console::output(xiloader::color::info, "You are now required to use an OTP to login."); | ||
|
|
||
| std::optional<std::string> maybeRecoveryCode = jsonGet<std::string>(login_reply_json, "recovery_code"); | ||
| if (maybeRecoveryCode.has_value()) | ||
| { | ||
| xiloader::console::output(xiloader::color::info, "Your recovery code is '%s'. Please write this down!", maybeRecoveryCode.value().c_str()); | ||
| xiloader::console::output(xiloader::color::info, "Tip: Try using shift + leftclick to select the text if it doesn't work.", maybeRecoveryCode.value().c_str()); | ||
| xiloader::console::output(xiloader::color::info, "You may remove you may remove your TOTP with this recovery code."); | ||
| } | ||
|
|
||
| std::string svgFilePath = getTemporaryPath() + "temp.svg"; | ||
| if (std::filesystem::exists(svgFilePath)) | ||
| { | ||
| std::filesystem::remove(svgFilePath); | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| // LOGIN_SUCCESS_REMOVE_TOTP | ||
| case 0x0012: | ||
| { | ||
| xiloader::console::output(xiloader::color::info, "Your TOTP has been removed."); | ||
| xiloader::console::output(xiloader::color::info, "You no longer need to use an OTP code to login."); | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| return false; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if you're not going to build this, or it doesn't come with a cmake file, you should still mark this as
DOWNLOAD_ONLYThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added