#include "stdafx.h" #include "AuthModule.h" bool AuthModule::validate(const wstring &uid, const wstring &username) { return !uid.empty() && !username.empty() && username.length() <= 16; } bool AuthModule::extractIdentity(const vector> &fields, wstring &outUid, wstring &outUsername) { for (const auto &[key, value] : fields) { if (key == L"uid") outUid = value; else if (key == L"username") outUsername = value; } return validate(outUid, outUsername); } ElyByAuthModule::ElyByAuthModule(const wstring &endpoint) : endpoint(endpoint) { } const wchar_t *ElyByAuthModule::schemeName() { return L"mcconsoles:elyby"; } vector ElyByAuthModule::supportedVariations() { return {L"java"}; } vector> ElyByAuthModule::getSettings(const wstring &variation) { return {{L"endpoint", endpoint}}; } bool ElyByAuthModule::onAuthData(const vector> &fields, wstring &outUid, wstring &outUsername) { return extractIdentity(fields, outUid, outUsername); } MojangAuthModule::MojangAuthModule() : ElyByAuthModule(L"https://sessionserver.mojang.com") { } const wchar_t *MojangAuthModule::schemeName() { return L"mcconsoles:mojang"; } vector MojangAuthModule::supportedVariations() { return {L"java", L"bedrock"}; } // --- KeypairOfflineAuthModule --- const wchar_t *KeypairOfflineAuthModule::schemeName() { return L"mcconsoles:keypair_offline"; } vector KeypairOfflineAuthModule::supportedVariations() { return {L"rsa2048", L"ed25519"}; } vector> KeypairOfflineAuthModule::getSettings(const wstring &variation) { return {{L"key_type", variation}}; } bool KeypairOfflineAuthModule::onAuthData(const vector> &fields, wstring &outUid, wstring &outUsername) { return extractIdentity(fields, outUid, outUsername); } const wchar_t *OfflineAuthModule::schemeName() { return L"mcconsoles:offline"; } vector OfflineAuthModule::supportedVariations() { return {}; } vector> OfflineAuthModule::getSettings(const wstring &variation) { return {}; } bool OfflineAuthModule::onAuthData(const vector> &fields, wstring &outUid, wstring &outUsername) { return extractIdentity(fields, outUid, outUsername); }