mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-03 16:25:35 +00:00
add GetServerVersion
This commit is contained in:
parent
9595ef164e
commit
e11211f201
@ -8,6 +8,14 @@
|
||||
|
||||
#include "TConsole.h"
|
||||
|
||||
struct Version {
|
||||
uint8_t major;
|
||||
uint8_t minor;
|
||||
uint8_t patch;
|
||||
Version(uint8_t major, uint8_t minor, uint8_t patch);
|
||||
std::string AsString();
|
||||
};
|
||||
|
||||
// static class handling application start, shutdown, etc.
|
||||
// yes, static classes, singletons, globals are all pretty
|
||||
// bad idioms. In this case we need a central way to access
|
||||
@ -40,6 +48,7 @@ public:
|
||||
std::string CustomIP;
|
||||
[[nodiscard]] bool HasCustomIP() const { return !CustomIP.empty(); }
|
||||
};
|
||||
|
||||
using TShutdownHandler = std::function<void()>;
|
||||
|
||||
// methods
|
||||
@ -50,9 +59,9 @@ public:
|
||||
// Causes all threads to finish up and exit gracefull gracefully
|
||||
static void GracefullyShutdown();
|
||||
static TConsole& Console() { return *mConsole; }
|
||||
static std::string ServerVersion() { return "2.2.0"; }
|
||||
#warning "change version from 2.2.0 to real version"
|
||||
static std::string ClientVersion() { return "2.0"; }
|
||||
static std::string ServerVersionString();
|
||||
static const Version& ServerVersion() { return mVersion; }
|
||||
static std::string ClientVersionString() { return "2.0"; }
|
||||
static std::string PPS() { return mPPS; }
|
||||
static void SetPPS(std::string NewPPS) { mPPS = NewPPS; }
|
||||
|
||||
@ -67,6 +76,8 @@ private:
|
||||
static std::unique_ptr<TConsole> mConsole;
|
||||
static inline std::mutex mShutdownHandlersMutex {};
|
||||
static inline std::deque<TShutdownHandler> mShutdownHandlers {};
|
||||
|
||||
static inline Version mVersion { 2, 2, 0 };
|
||||
};
|
||||
|
||||
std::string ThreadName();
|
||||
|
@ -24,6 +24,10 @@ void Application::GracefullyShutdown() {
|
||||
}
|
||||
}
|
||||
|
||||
std::string Application::ServerVersionString() {
|
||||
return mVersion.AsString();
|
||||
}
|
||||
|
||||
std::string Comp(std::string Data) {
|
||||
std::array<char, Biggest> C {};
|
||||
// obsolete
|
||||
@ -86,3 +90,14 @@ std::string ThreadName() {
|
||||
void RegisterThread(const std::string str) {
|
||||
threadNameMap[std::this_thread::get_id()] = str;
|
||||
}
|
||||
|
||||
Version::Version(uint8_t major, uint8_t minor, uint8_t patch)
|
||||
: major(major)
|
||||
, minor(minor)
|
||||
, patch(patch) { }
|
||||
|
||||
std::string Version::AsString() {
|
||||
std::stringstream ss {};
|
||||
ss << major << "." << minor << "." << patch;
|
||||
return ss.str();
|
||||
}
|
||||
|
@ -71,8 +71,8 @@ std::string THeartbeatThread::GenerateCall() {
|
||||
<< "&port=" << Application::Settings.Port
|
||||
<< "&map=" << Application::Settings.MapName
|
||||
<< "&private=" << (Application::Settings.Private ? "true" : "false")
|
||||
<< "&version=" << Application::ServerVersion()
|
||||
<< "&clientversion=" << Application::ClientVersion()
|
||||
<< "&version=" << Application::ServerVersionString()
|
||||
<< "&clientversion=" << Application::ClientVersionString()
|
||||
<< "&name=" << Application::Settings.ServerName
|
||||
<< "&modlist=" << mResourceManager.TrimmedList()
|
||||
<< "&modstotalsize=" << mResourceManager.MaxModSize()
|
||||
|
@ -782,6 +782,14 @@ int lua_GetOSName(lua_State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lua_GetServerVersion(lua_State* L) {
|
||||
const auto& ver = Application::ServerVersion();
|
||||
lua_pushinteger(L, ver.major);
|
||||
lua_pushinteger(L, ver.minor);
|
||||
lua_pushinteger(L, ver.patch);
|
||||
return 3;
|
||||
}
|
||||
|
||||
// status, body = HttpsGET(host, port, target)
|
||||
// example usage:
|
||||
// send a GET https://example.com:443/index.html:
|
||||
@ -911,6 +919,7 @@ void TLuaFile::Load() {
|
||||
LuaTable::InsertFunction(mLuaState, "GetOSName", lua_GetOSName);
|
||||
LuaTable::InsertFunction(mLuaState, "HttpsGET", lua_HttpsGET);
|
||||
LuaTable::InsertFunction(mLuaState, "HttpsPOST", lua_HttpsPOST);
|
||||
LuaTable::InsertFunction(mLuaState, "GetServerVersion", lua_GetServerVersion);
|
||||
LuaTable::End(mLuaState, "MP");
|
||||
|
||||
lua_register(mLuaState, "print", lua_Print);
|
||||
|
@ -263,7 +263,7 @@ void TNetwork::Authentication(const TConnection& ClientConnection) {
|
||||
|
||||
if (Rc.size() > 3 && Rc.substr(0, 2) == "VC") {
|
||||
Rc = Rc.substr(2);
|
||||
if (Rc.length() > 4 || Rc != Application::ClientVersion()) {
|
||||
if (Rc.length() > 4 || Rc != Application::ClientVersionString()) {
|
||||
ClientKick(*Client, "Outdated Version!");
|
||||
return;
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
namespace json = rapidjson;
|
||||
|
||||
TServer::TServer(int argc, char** argv) {
|
||||
info("BeamMP Server v" + Application::ServerVersion());
|
||||
info("BeamMP Server v" + Application::ServerVersionString());
|
||||
if (argc > 1) {
|
||||
Application::Settings.CustomIP = argv[1];
|
||||
size_t n = std::count(Application::Settings.CustomIP.begin(), Application::Settings.CustomIP.end(), '.');
|
||||
|
Loading…
x
Reference in New Issue
Block a user