Skip to content

Commit bcf142a

Browse files
authored
Merge pull request #568 from openmultiplayer/supported-version
Check supported major version when loading components.
2 parents de26f64 + d403d36 commit bcf142a

2 files changed

Lines changed: 30 additions & 13 deletions

File tree

SDK/include/component.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#define BUILD_NUMBER 0
77
#endif
88

9+
#define OMP_VERSION_SUPPORTED 1
10+
911
/// Should always be used in classes inheriting IExtension
1012
#define PROVIDE_EXT_UID(uuid) \
1113
static constexpr UID ExtensionIID = uuid; \
@@ -190,6 +192,17 @@ struct IEarlyConfig;
190192
/// A component interface
191193
struct IComponent : public IExtensible, public IUIDProvider
192194
{
195+
/// The idea is for the SDK to be totally forward compatible, so code built at any time will
196+
/// always work, thanks to ABI compatibility. This method is an emergency trap door, just in
197+
/// case that's ever not the problem. Check which major version this component was built for,
198+
/// if it isn't the current major version, fail to load it. Always just returns a constant,
199+
/// recompiling will often be enough to upgrade. `virtual` and `final` to be the vtable, but it
200+
/// can't be overridden because it is a constant.
201+
virtual int supportedVersion() const final
202+
{
203+
return OMP_VERSION_SUPPORTED;
204+
}
205+
193206
/// Get the component's name
194207
virtual StringView componentName() const = 0;
195208

Server/Source/core_impl.hpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -973,25 +973,29 @@ class Core final : public ICore, public PlayerConnectEventHandler, public Consol
973973
return nullptr;
974974
}
975975
IComponent* component = OnComponentLoad();
976-
if (component != nullptr)
976+
if (component == nullptr)
977977
{
978-
SemanticVersion ver = component->componentVersion();
979-
printLn(
980-
"\tSuccessfully loaded component %.*s (%u.%u.%u.%u) with UID %016llx",
981-
PRINT_VIEW(component->componentName()),
982-
ver.major,
983-
ver.minor,
984-
ver.patch,
985-
ver.prerel,
986-
component->getUID());
987-
return component;
978+
printLn("\tFailed to load component.");
979+
LIBRARY_FREE(componentLib);
980+
return nullptr;
988981
}
989-
else
982+
int supports = component->supportedVersion();
983+
if (supports != OMP_VERSION_MAJOR)
990984
{
991-
printLn("\tFailed to load component.");
985+
printLn("\tFailed to load component: Built for open.mp version %d, now on %d.", supports, OMP_VERSION_MAJOR);
992986
LIBRARY_FREE(componentLib);
993987
return nullptr;
994988
}
989+
SemanticVersion ver = component->componentVersion();
990+
printLn(
991+
"\tSuccessfully loaded component %.*s (%u.%u.%u.%u) with UID %016llx",
992+
PRINT_VIEW(component->componentName()),
993+
ver.major,
994+
ver.minor,
995+
ver.patch,
996+
ver.prerel,
997+
component->getUID());
998+
return component;
995999
}
9961000

9971001
void loadComponents(const ghc::filesystem::path& path)

0 commit comments

Comments
 (0)