From 8797d58c942b01f542ed40ace3886efc19a9b366 Mon Sep 17 00:00:00 2001 From: "Robin C. Ladiges" Date: Tue, 9 Jul 2024 09:02:57 +0200 Subject: [PATCH] [mod menu] new: tell the user to restart the game after changing the server --- include/server/Client.hpp | 2 ++ source/server/Client.cpp | 15 +++++++++++++++ source/states/StageSceneStateServerConfig.cpp | 8 ++++++++ 3 files changed, 25 insertions(+) diff --git a/include/server/Client.hpp b/include/server/Client.hpp index 7d4c5eb..9b66214 100644 --- a/include/server/Client.hpp +++ b/include/server/Client.hpp @@ -135,6 +135,8 @@ class Client { static const int getCurrentPort(); + static const bool hasServerChanged(); + static int getConnectCount() { if (sInstance) { return sInstance->mConnectCount; diff --git a/source/server/Client.cpp b/source/server/Client.cpp index b612c85..8d32145 100644 --- a/source/server/Client.cpp +++ b/source/server/Client.cpp @@ -1305,6 +1305,21 @@ const int Client::getCurrentPort() { return -1; } +/** + * @brief + * + * @return const bool + */ +const bool Client::hasServerChanged() { + if (!sInstance) { + return false; + } + return ( + getCurrentPort() != sInstance->mSocket->getPort() + || strcmp(getCurrentIP(), sInstance->mSocket->getIP()) != 0 + ); +} + /** * @brief sets server IP to supplied string, used specifically for loading IP from the save file. * diff --git a/source/states/StageSceneStateServerConfig.cpp b/source/states/StageSceneStateServerConfig.cpp index 7729f73..039e01c 100644 --- a/source/states/StageSceneStateServerConfig.cpp +++ b/source/states/StageSceneStateServerConfig.cpp @@ -109,6 +109,14 @@ void StageSceneStateServerConfig::appear(void) { void StageSceneStateServerConfig::kill(void) { mCurrentMenu->startEnd("End"); al::NerveStateBase::kill(); + + if (Client::hasServerChanged()) { + #if EMU + Client::showUIMessage(u"You changed the server and have to restart the emulator now."); + #else + Client::showUIMessage(u"You changed the server and have to restart the game now."); + #endif + } } al::MessageSystem* StageSceneStateServerConfig::getMessageSystem(void) const {