From 5971ac5773ffd838f34c1797ab8e4b069738a552 Mon Sep 17 00:00:00 2001 From: Y_Less Date: Thu, 5 Jan 2023 11:09:22 +0000 Subject: [PATCH 1/2] Check supported major version when loading components. --- SDK/include/component.hpp | 13 +++++++++++++ Server/Source/core_impl.hpp | 31 ++++++++++++++++++------------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/SDK/include/component.hpp b/SDK/include/component.hpp index dd073fc63..bcf1a4c9b 100644 --- a/SDK/include/component.hpp +++ b/SDK/include/component.hpp @@ -6,6 +6,8 @@ #define BUILD_NUMBER 0 #endif +#define OMP_VERSION_SUPPORTED 1 + /// Should always be used in classes inheriting IExtension #define PROVIDE_EXT_UID(uuid) \ static constexpr UID ExtensionIID = uuid; \ @@ -190,6 +192,17 @@ struct IEarlyConfig; /// A component interface struct IComponent : public IExtensible, public IUIDProvider { + /// The idea is for the SDK to be totally forward compatible, so code built at any time will + /// always work, thanks to ABI compatibility. This method is an emergency trap door, just in + /// case that's ever not the problem. Check which major version this component was built for, + /// if it isn't the current major version, fail to load it. Always just returns a constant, + /// recompiling will often be enough to upgrade. `virtual` and `final` to be the vtable, but it + /// can't be overridden because it is a constant. + virtual int supportedVersion() const final + { + return OMP_VERSION_SUPPORTED; + } + /// Get the component's name virtual StringView componentName() const = 0; diff --git a/Server/Source/core_impl.hpp b/Server/Source/core_impl.hpp index e31f893a5..a017b0b63 100644 --- a/Server/Source/core_impl.hpp +++ b/Server/Source/core_impl.hpp @@ -973,25 +973,30 @@ class Core final : public ICore, public PlayerConnectEventHandler, public Consol return nullptr; } IComponent* component = OnComponentLoad(); - if (component != nullptr) + if (component == nullptr) { - SemanticVersion ver = component->componentVersion(); - printLn( - "\tSuccessfully loaded component %.*s (%u.%u.%u.%u) with UID %016llx", - PRINT_VIEW(component->componentName()), - ver.major, - ver.minor, - ver.patch, - ver.prerel, - component->getUID()); - return component; + printLn("\tFailed to load component."); + LIBRARY_FREE(componentLib); + return nullptr; } - else + int supports = component->supportedVersion(); + printLn("\tComponent supported version: %d.", supports); + if (supports != OMP_VERSION_MAJOR) { - printLn("\tFailed to load component."); + printLn("\tFailed to load component: Built for open.mp version %d, now on %d.", supports, OMP_VERSION_MAJOR); LIBRARY_FREE(componentLib); return nullptr; } + SemanticVersion ver = component->componentVersion(); + printLn( + "\tSuccessfully loaded component %.*s (%u.%u.%u.%u) with UID %016llx", + PRINT_VIEW(component->componentName()), + ver.major, + ver.minor, + ver.patch, + ver.prerel, + component->getUID()); + return component; } void loadComponents(const ghc::filesystem::path& path) From d403d3699f130c94bebe225446288dc5f0e4edf4 Mon Sep 17 00:00:00 2001 From: Y_Less Date: Thu, 5 Jan 2023 12:01:41 +0000 Subject: [PATCH 2/2] Remove debugging line. --- Server/Source/core_impl.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Server/Source/core_impl.hpp b/Server/Source/core_impl.hpp index a017b0b63..e42090e98 100644 --- a/Server/Source/core_impl.hpp +++ b/Server/Source/core_impl.hpp @@ -980,7 +980,6 @@ class Core final : public ICore, public PlayerConnectEventHandler, public Consol return nullptr; } int supports = component->supportedVersion(); - printLn("\tComponent supported version: %d.", supports); if (supports != OMP_VERSION_MAJOR) { printLn("\tFailed to load component: Built for open.mp version %d, now on %d.", supports, OMP_VERSION_MAJOR);