From 73ba2a95f5bd4a0dd09af52d5864800be2b0a4c6 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Fri, 26 Jan 2024 15:43:00 +0100 Subject: Added support for the "persistentIp" server info setting This option was added in ManaPlus and support for it is required to connect to The Mana World as it is currently set up, since the server sends 127.0.0.1 for the character server and map server IP. Can't play yet, because of an unknown packet 0x226 being received once connecting to the map server. --- src/gui/serverdialog.cpp | 13 +++++++++++-- src/net/serverinfo.h | 38 ++++++-------------------------------- src/net/tmwa/charserverhandler.cpp | 9 ++++++++- src/net/tmwa/loginhandler.cpp | 12 +++++++++++- src/net/tmwa/network.cpp | 2 +- src/net/tmwa/network.h | 2 +- 6 files changed, 38 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index 50510d15..3ea978e1 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -501,9 +501,18 @@ void ServerDialog::loadServers() server.port = ServerInfo::defaultPortForServerType(server.type); } } - else if (xmlStrEqual(subNode->name, BAD_CAST "description")) + else if (subNode->xmlChildrenNode && subNode->xmlChildrenNode->content) { - server.description = (const char*) subNode->xmlChildrenNode->content; + const char *text = (const char*) subNode->xmlChildrenNode->content; + + if (xmlStrEqual(subNode->name, BAD_CAST "description")) + { + server.description = text; + } + else if (xmlStrEqual(subNode->name, BAD_CAST "persistentIp")) + { + server.persistentIp = strcmp(text, "1") == 0 || strcmp(text, "true") == 0; + } } } diff --git a/src/net/serverinfo.h b/src/net/serverinfo.h index 8e2ee5b0..98881931 100644 --- a/src/net/serverinfo.h +++ b/src/net/serverinfo.h @@ -38,35 +38,16 @@ public: typedef std::pair VersionString; - Type type; + Type type = UNKNOWN; std::string name; std::string hostname; - unsigned short port; + unsigned short port = 0; std::string description; - VersionString version; + VersionString version = std::make_pair(0, std::string()); - bool save; - - ServerInfo() - { - type = UNKNOWN; - port = 0; - save = false; - version.first = 0; - } - - ServerInfo(const ServerInfo &info) - { - type = info.type; - name = info.name; - hostname = info.hostname; - port = info.port; - description = info.description; - version.first = info.version.first; - version.second = info.version.second; - save = info.save; - } + bool save = false; + bool persistentIp = true; bool isValid() const { @@ -75,14 +56,7 @@ public: void clear() { - type = UNKNOWN; - name.clear(); - hostname.clear(); - port = 0; - description.clear(); - version.first = 0; - version.second.clear(); - save = false; + *this = ServerInfo(); } bool operator==(const ServerInfo &other) const diff --git a/src/net/tmwa/charserverhandler.cpp b/src/net/tmwa/charserverhandler.cpp index 7c5f5c88..a8e87622 100644 --- a/src/net/tmwa/charserverhandler.cpp +++ b/src/net/tmwa/charserverhandler.cpp @@ -158,7 +158,14 @@ void CharServerHandler::handleMessage(MessageIn &msg) msg.skip(4); // CharID, must be the same as local_player->charID GameHandler *gh = static_cast(Net::getGameHandler()); gh->setMap(msg.readString(16)); - mapServer.hostname = ipToString(msg.readInt32()); + + const auto ip = msg.readInt32(); + + if (charServer.persistentIp) + mapServer.hostname = charServer.hostname; + else + mapServer.hostname = ipToString(ip); + mapServer.port = msg.readInt16(); local_player = mSelectedCharacter->dummy; diff --git a/src/net/tmwa/loginhandler.cpp b/src/net/tmwa/loginhandler.cpp index 77b545fd..2fbc02d4 100644 --- a/src/net/tmwa/loginhandler.cpp +++ b/src/net/tmwa/loginhandler.cpp @@ -274,7 +274,17 @@ void LoginHandler::chooseServer(unsigned int server) return; charServer.clear(); - charServer.hostname = ipToString(mWorlds[server]->address); + + if (mServer.persistentIp) + { + charServer.hostname = mServer.hostname; + charServer.persistentIp = mServer.persistentIp; + } + else + { + charServer.hostname = ipToString(mWorlds[server]->address); + } + charServer.port = mWorlds[server]->port; Client::setState(STATE_UPDATE); diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp index ed564b46..5ff4f7e5 100644 --- a/src/net/tmwa/network.cpp +++ b/src/net/tmwa/network.cpp @@ -132,7 +132,7 @@ Network::~Network() SDLNet_Quit(); } -bool Network::connect(ServerInfo server) +bool Network::connect(const ServerInfo &server) { if (mState != IDLE && mState != NET_ERROR) { diff --git a/src/net/tmwa/network.h b/src/net/tmwa/network.h index 08943327..079e71ca 100644 --- a/src/net/tmwa/network.h +++ b/src/net/tmwa/network.h @@ -51,7 +51,7 @@ class Network ~Network(); - bool connect(ServerInfo server); + bool connect(const ServerInfo &server); void disconnect(); -- cgit v1.2.3-70-g09d2