From dcd925377081ff234614ecf84e6a6ff2cc6e43cb Mon Sep 17 00:00:00 2001 From: Joe Date: Tue, 17 Feb 2026 20:48:39 -0600 Subject: [PATCH] Refactor version rejection logic in ApiContext - Renamed the `rejectWrongProtocolVersion` function to `rejectWrongVersion` for clarity. - Enhanced version mismatch handling by providing detailed error messages when the plugin and server versions do not match. - Updated the expected server version format in the configuration to include the patch version, ensuring accurate version checks. These changes improve error reporting and version management in the plugin's API context. --- plugin/src/ApiContext.lua | 34 +++++++++++++++++++++------------- plugin/src/Config.lua | 2 +- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/plugin/src/ApiContext.lua b/plugin/src/ApiContext.lua index 8fb3e0af..61496366 100644 --- a/plugin/src/ApiContext.lua +++ b/plugin/src/ApiContext.lua @@ -24,20 +24,28 @@ local function rejectFailedRequests(response) return response end -local function rejectWrongProtocolVersion(infoResponseBody) +local function rejectWrongVersion(infoResponseBody) + local pluginVersion = Version.display(Config.version) + local serverVersion = infoResponseBody.serverVersion + + if serverVersion ~= pluginVersion then + local message = ( + "Found a server, but it's a different version than this plugin." + .. "\nThe Atlas plugin requires an exact version match with the server." + .. "\n\nYour plugin is version %s." + .. "\nYour server is version %s." + .. "\n\nPlease update your plugin or server so both are the same version." + ):format(pluginVersion, serverVersion) + + return Promise.reject(message) + end + if infoResponseBody.protocolVersion ~= Config.protocolVersion then local message = ( - "Found a server, but it's using a different protocol version, and is incompatible." - .. "\nMake sure you have matching versions of both the Atlas plugin and server!" - .. "\n\nYour client is version %s, with protocol version %s. It expects server version %s." - .. "\nYour server is version %s, with protocol version %s." - ):format( - Version.display(Config.version), - Config.protocolVersion, - Config.expectedServerVersionString, - infoResponseBody.serverVersion, - infoResponseBody.protocolVersion - ) + "Found a server with the same version, but a different protocol version." + .. "\nThis should not happen — please report this as a bug." + .. "\n\nPlugin protocol: %s, Server protocol: %s" + ):format(Config.protocolVersion, infoResponseBody.protocolVersion) return Promise.reject(message) end @@ -159,7 +167,7 @@ function ApiContext:connect() return Http.get(url) :andThen(rejectFailedRequests) :andThen(Http.Response.msgpack) - :andThen(rejectWrongProtocolVersion) + :andThen(rejectWrongVersion) :andThen(rejectWrongFork) :andThen(function(body) assert(validateApiInfo(body)) diff --git a/plugin/src/Config.lua b/plugin/src/Config.lua index eac96626..acb7b2f6 100644 --- a/plugin/src/Config.lua +++ b/plugin/src/Config.lua @@ -26,7 +26,7 @@ return strict("Config", { isDevBuild = isDevBuild, codename = "Epiphany", version = realVersion, - expectedServerVersionString = ("%d.%d or newer"):format(realVersion[1], realVersion[2]), + expectedServerVersionString = ("%d.%d.%d"):format(realVersion[1], realVersion[2], realVersion[3]), protocolVersion = 6, defaultHost = "localhost", defaultPort = "34873",