diff --git a/Minecraft.Client/ClientConnection.cpp b/Minecraft.Client/ClientConnection.cpp index 5a33545b..b584ffb5 100644 --- a/Minecraft.Client/ClientConnection.cpp +++ b/Minecraft.Client/ClientConnection.cpp @@ -4173,6 +4173,12 @@ void ClientConnection::handleAuth(const shared_ptr &packet) if (handshakeManager->isComplete()) { authComplete = true; + const wstring &authName = handshakeManager->finalUsername; + minecraft->user->name = authName; + extern char g_Win64Username[17]; + extern wchar_t g_Win64UsernameW[17]; + wcsncpy_s(g_Win64UsernameW, authName.c_str(), 16); + wcstombs_s(nullptr, g_Win64Username, g_Win64UsernameW, 16); } else if (handshakeManager->isFailed()) { diff --git a/Minecraft.Client/Common/Consoles_App.cpp b/Minecraft.Client/Common/Consoles_App.cpp index 0a2fd159..39c2807e 100644 --- a/Minecraft.Client/Common/Consoles_App.cpp +++ b/Minecraft.Client/Common/Consoles_App.cpp @@ -4589,6 +4589,9 @@ int CMinecraftApp::SignoutExitWorldThreadProc( void* lpParameter ) case DisconnectPacket::eDisconnect_OutdatedClient: exitReasonStringId = IDS_DISCONNECTED_CLIENT_OLD; break; + case DisconnectPacket::eDisconnect_AuthFailed: + exitReasonStringId = IDS_DISCONNECTED_AUTH_FAILED; + break; default: exitReasonStringId = IDS_DISCONNECTED; } @@ -4649,6 +4652,10 @@ int CMinecraftApp::SignoutExitWorldThreadProc( void* lpParameter ) break; case DisconnectPacket::eDisconnect_OutdatedClient: exitReasonStringId = IDS_DISCONNECTED_CLIENT_OLD; + break; + case DisconnectPacket::eDisconnect_AuthFailed: + exitReasonStringId = IDS_DISCONNECTED_AUTH_FAILED; + break; default: exitReasonStringId = IDS_DISCONNECTED; } diff --git a/Minecraft.Client/Common/UI/IUIScene_PauseMenu.cpp b/Minecraft.Client/Common/UI/IUIScene_PauseMenu.cpp index e88ed08c..036e5bec 100644 --- a/Minecraft.Client/Common/UI/IUIScene_PauseMenu.cpp +++ b/Minecraft.Client/Common/UI/IUIScene_PauseMenu.cpp @@ -508,6 +508,10 @@ void IUIScene_PauseMenu::_ExitWorld(LPVOID lpParameter) exitReasonTitleId = IDS_CONNECTION_FAILED; break; #endif + case DisconnectPacket::eDisconnect_AuthFailed: + exitReasonStringId = IDS_DISCONNECTED_AUTH_FAILED; + exitReasonTitleId = IDS_CONNECTION_FAILED; + break; default: exitReasonStringId = IDS_CONNECTION_LOST_SERVER; } @@ -609,6 +613,10 @@ void IUIScene_PauseMenu::_ExitWorld(LPVOID lpParameter) exitReasonTitleId = IDS_CONNECTION_FAILED; break; #endif + case DisconnectPacket::eDisconnect_AuthFailed: + exitReasonStringId = IDS_DISCONNECTED_AUTH_FAILED; + exitReasonTitleId = IDS_CONNECTION_FAILED; + break; default: exitReasonStringId = IDS_DISCONNECTED; } diff --git a/Minecraft.Client/Common/UI/UIScene_ConnectingProgress.cpp b/Minecraft.Client/Common/UI/UIScene_ConnectingProgress.cpp index 40557cd5..ae75ec03 100644 --- a/Minecraft.Client/Common/UI/UIScene_ConnectingProgress.cpp +++ b/Minecraft.Client/Common/UI/UIScene_ConnectingProgress.cpp @@ -133,6 +133,9 @@ void UIScene_ConnectingProgress::tick() case DisconnectPacket::eDisconnect_Banned: exitReasonStringId = IDS_DISCONNECTED_KICKED; break; + case DisconnectPacket::eDisconnect_AuthFailed: + exitReasonStringId = IDS_DISCONNECTED_AUTH_FAILED; + break; default: exitReasonStringId = IDS_CONNECTION_LOST_SERVER; break; @@ -277,6 +280,9 @@ void UIScene_ConnectingProgress::handleTimerComplete(int id) exitReasonStringId = IDS_DISCONNECTED_NAT_TYPE_MISMATCH; break; #endif + case DisconnectPacket::eDisconnect_AuthFailed: + exitReasonStringId = IDS_DISCONNECTED_AUTH_FAILED; + break; default: exitReasonStringId = IDS_CONNECTION_LOST_SERVER; break; diff --git a/Minecraft.Client/MinecraftServer.cpp b/Minecraft.Client/MinecraftServer.cpp index 27ee68b6..8304007f 100644 --- a/Minecraft.Client/MinecraftServer.cpp +++ b/Minecraft.Client/MinecraftServer.cpp @@ -59,6 +59,7 @@ #include "PlayerChunkMap.h" #include "Common\Telemetry\TelemetryManager.h" #include "PlayerConnection.h" +#include "AuthScreen.h" #ifdef _XBOX_ONE #include "Durango\Network\NetworkPlayerDurango.h" #endif @@ -648,6 +649,19 @@ bool MinecraftServer::initServer(int64_t seed, NetworkGameInitData *initData, DW //motd = settings->getString(L"motd", L"A Minecraft Server"); //motd.replace('�', '$'); + if (ShouldUseDedicatedServerProperties()) + { + wstring am = GetDedicatedServerString(settings, L"auth-mode", L"session"); + authMode = (am == L"offline") ? "offline" : "session"; + } + else + { + int idx = AuthProfileManager::getSelectedIndex(); + const auto &profiles = AuthProfileManager::getProfiles(); + authMode = (idx >= 0 && idx < static_cast(profiles.size()) && + profiles[idx].type != AuthProfile::OFFLINE) ? "session" : "offline"; + } + setAnimals(GetDedicatedServerBool(settings, L"spawn-animals", true)); setNpcsEnabled(GetDedicatedServerBool(settings, L"spawn-npcs", true)); setPvpAllowed(app.GetGameHostOption( eGameHostOption_PvP )>0?true:false); diff --git a/Minecraft.Client/MinecraftServer.h b/Minecraft.Client/MinecraftServer.h index 1ed5db9d..4db4e101 100644 --- a/Minecraft.Client/MinecraftServer.h +++ b/Minecraft.Client/MinecraftServer.h @@ -113,6 +113,7 @@ private: CRITICAL_SECTION m_consoleInputCS; public: bool onlineMode; + std::string authMode; bool animals; bool npcs; bool pvp; diff --git a/Minecraft.Client/PendingConnection.cpp b/Minecraft.Client/PendingConnection.cpp index 88fdb969..6ff5cac1 100644 --- a/Minecraft.Client/PendingConnection.cpp +++ b/Minecraft.Client/PendingConnection.cpp @@ -125,7 +125,8 @@ void PendingConnection::handlePreLogin(shared_ptr packet) return; } // printf("Server: handlePreLogin\n"); - name = packet->loginKey; // 4J Stu - Change from the login packet as we know better on client end during the pre-login packet + if (!authComplete) + name = packet->loginKey; sendPreLoginResponse(); } @@ -411,9 +412,10 @@ bool PendingConnection::isDisconnected() void PendingConnection::initAuth() { handshakeManager = new HandshakeManager(true); - handshakeManager->registerModule(new SessionAuthModule()); - handshakeManager->registerModule(new KeypairOfflineAuthModule()); - handshakeManager->registerModule(new OfflineAuthModule()); + if (server->authMode == "session") + handshakeManager->registerModule(new SessionAuthModule()); + else + handshakeManager->registerModule(new OfflineAuthModule()); } void PendingConnection::handleAuth(const shared_ptr &packet) @@ -433,6 +435,6 @@ void PendingConnection::handleAuth(const shared_ptr &packet) } else if (handshakeManager->isFailed()) { - disconnect(DisconnectPacket::eDisconnect_Closed); + disconnect(DisconnectPacket::eDisconnect_AuthFailed); } } diff --git a/Minecraft.Client/Windows64Media/loc/stringsGeneric.xml b/Minecraft.Client/Windows64Media/loc/stringsGeneric.xml index b5e58a9b..2b41f1da 100644 --- a/Minecraft.Client/Windows64Media/loc/stringsGeneric.xml +++ b/Minecraft.Client/Windows64Media/loc/stringsGeneric.xml @@ -5867,6 +5867,10 @@ Press{*CONTROLLER_VK_B*} if you already know about Fireworks. You cannot join this game as the player you are trying to join is running a newer version of the game. + + Authentication required. This server requires you to be signed in. + + New World diff --git a/Minecraft.Client/Windows64Media/strings.h b/Minecraft.Client/Windows64Media/strings.h index 19a50eee..b7812b0f 100644 --- a/Minecraft.Client/Windows64Media/strings.h +++ b/Minecraft.Client/Windows64Media/strings.h @@ -2290,3 +2290,4 @@ #define IDS_RICHPRESENCESTATE_BREWING 2284 #define IDS_RICHPRESENCESTATE_ANVIL 2285 #define IDS_RICHPRESENCESTATE_TRADING 2286 +#define IDS_DISCONNECTED_AUTH_FAILED 2287 diff --git a/Minecraft.Server/ServerLogManager.cpp b/Minecraft.Server/ServerLogManager.cpp index 84805f7e..53f83f74 100644 --- a/Minecraft.Server/ServerLogManager.cpp +++ b/Minecraft.Server/ServerLogManager.cpp @@ -196,6 +196,7 @@ namespace ServerRuntime case DisconnectPacket::eDisconnect_Banned: return "banned"; case DisconnectPacket::eDisconnect_NotFriendsWithHost: return "not-friends-with-host"; case DisconnectPacket::eDisconnect_NATMismatch: return "nat-mismatch"; + case DisconnectPacket::eDisconnect_AuthFailed: return "auth-failed"; default: return "unknown"; } } diff --git a/Minecraft.Server/ServerProperties.cpp b/Minecraft.Server/ServerProperties.cpp index d6ba64e7..da509557 100644 --- a/Minecraft.Server/ServerProperties.cpp +++ b/Minecraft.Server/ServerProperties.cpp @@ -40,6 +40,7 @@ static const ServerPropertyDefault kServerPropertyDefaults[] = { { "allow-flight", "true" }, { "allow-nether", "true" }, + { "auth-mode", "session" }, { "autosave-interval", "60" }, { "bedrock-fog", "true" }, { "bonus-chest", "false" }, @@ -864,6 +865,9 @@ ServerPropertiesConfig LoadServerPropertiesConfig() config.maxBuildHeight = ReadNormalizedIntProperty(&merged, "max-build-height", 256, 64, 256, &shouldWrite); config.motd = ReadNormalizedStringProperty(&merged, "motd", "A Minecraft Server", 255, &shouldWrite); + config.authMode = ReadNormalizedStringProperty(&merged, "auth-mode", "session", 16, &shouldWrite); + if (config.authMode != "session" && config.authMode != "offline") + config.authMode = "session"; if (shouldWrite) { diff --git a/Minecraft.Server/ServerProperties.h b/Minecraft.Server/ServerProperties.h index 3bb5aca8..03073ab9 100644 --- a/Minecraft.Server/ServerProperties.h +++ b/Minecraft.Server/ServerProperties.h @@ -73,7 +73,7 @@ namespace ServerRuntime bool doTileDrops; bool naturalRegeneration; bool doDaylightCycle; - + std::string authMode; /** other MinecraftServer runtime settings */ int maxBuildHeight; std::string levelType; diff --git a/Minecraft.World/DisconnectPacket.h b/Minecraft.World/DisconnectPacket.h index 3c96a429..22036a59 100644 --- a/Minecraft.World/DisconnectPacket.h +++ b/Minecraft.World/DisconnectPacket.h @@ -44,6 +44,7 @@ public: eDisconnect_Banned, eDisconnect_NotFriendsWithHost, eDisconnect_NATMismatch, + eDisconnect_AuthFailed, #ifdef __ORBIS__ eDisconnect_NetworkError, #endif