osb/source/core/StarNetCompatibility.hpp

55 lines
1.3 KiB
C++
Raw Normal View History

2024-09-05 19:15:47 +10:00
#pragma once
#include "StarVersion.hpp"
#include "StarHash.hpp"
2024-09-05 19:15:47 +10:00
namespace Star {
extern VersionNumber const OpenProtocolVersion;
2024-09-05 19:15:47 +10:00
constexpr VersionNumber AnyVersion = 0xFFFFFFFF;
constexpr VersionNumber LegacyVersion = 0;
2024-09-05 19:15:47 +10:00
class NetCompatibilityRules {
public:
NetCompatibilityRules();
2024-09-05 19:15:47 +10:00
NetCompatibilityRules(uint64_t) = delete;
NetCompatibilityRules(VersionNumber version);
VersionNumber version() const;
void setVersion(VersionNumber version);
bool isLegacy() const;
2024-09-05 19:15:47 +10:00
bool operator==(NetCompatibilityRules const& a) const;
2024-09-05 19:15:47 +10:00
private:
VersionNumber m_version = OpenProtocolVersion;
2024-09-05 19:15:47 +10:00
};
inline NetCompatibilityRules::NetCompatibilityRules() : m_version(OpenProtocolVersion) {}
inline NetCompatibilityRules::NetCompatibilityRules(VersionNumber v) : m_version(v) {}
inline VersionNumber NetCompatibilityRules::version() const {
return m_version;
}
inline void NetCompatibilityRules::setVersion(VersionNumber version) {
m_version = version;
}
inline bool NetCompatibilityRules::isLegacy() const {
return m_version == LegacyVersion;
}
2024-09-05 19:15:47 +10:00
inline bool NetCompatibilityRules::operator==(NetCompatibilityRules const& a) const {
return m_version == a.m_version;
2024-09-05 19:15:47 +10:00
}
template <>
struct hash<NetCompatibilityRules> {
size_t operator()(NetCompatibilityRules const& s) const {
return s.version();
2024-09-05 19:15:47 +10:00
}
};
}