mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-04 00:36:14 +00:00
add GetServerVersion
This commit is contained in:
parent
e3b6fd7998
commit
ba3fd0e144
@ -12,6 +12,14 @@ extern TSentry Sentry;
|
|||||||
|
|
||||||
#include "TConsole.h"
|
#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.
|
// static class handling application start, shutdown, etc.
|
||||||
// yes, static classes, singletons, globals are all pretty
|
// yes, static classes, singletons, globals are all pretty
|
||||||
// bad idioms. In this case we need a central way to access
|
// bad idioms. In this case we need a central way to access
|
||||||
@ -44,6 +52,7 @@ public:
|
|||||||
std::string CustomIP;
|
std::string CustomIP;
|
||||||
[[nodiscard]] bool HasCustomIP() const { return !CustomIP.empty(); }
|
[[nodiscard]] bool HasCustomIP() const { return !CustomIP.empty(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
using TShutdownHandler = std::function<void()>;
|
using TShutdownHandler = std::function<void()>;
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
@ -54,9 +63,9 @@ public:
|
|||||||
// Causes all threads to finish up and exit gracefull gracefully
|
// Causes all threads to finish up and exit gracefull gracefully
|
||||||
static void GracefullyShutdown();
|
static void GracefullyShutdown();
|
||||||
static TConsole& Console() { return *mConsole; }
|
static TConsole& Console() { return *mConsole; }
|
||||||
static std::string ServerVersion() { return "2.3.1"; }
|
static std::string ServerVersionString();
|
||||||
#warning "change version from 2.2.0 to real version"
|
static const Version& ServerVersion() { return mVersion; }
|
||||||
static std::string ClientVersion() { return "2.0"; }
|
static std::string ClientVersionString() { return "2.0"; }
|
||||||
static std::string PPS() { return mPPS; }
|
static std::string PPS() { return mPPS; }
|
||||||
static void SetPPS(const std::string& NewPPS) { mPPS = NewPPS; }
|
static void SetPPS(const std::string& NewPPS) { mPPS = NewPPS; }
|
||||||
|
|
||||||
@ -76,6 +85,8 @@ private:
|
|||||||
static std::unique_ptr<TConsole> mConsole;
|
static std::unique_ptr<TConsole> mConsole;
|
||||||
static inline std::mutex mShutdownHandlersMutex {};
|
static inline std::mutex mShutdownHandlersMutex {};
|
||||||
static inline std::deque<TShutdownHandler> mShutdownHandlers {};
|
static inline std::deque<TShutdownHandler> mShutdownHandlers {};
|
||||||
|
|
||||||
|
static inline Version mVersion { 2, 2, 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string ThreadName(bool DebugModeOverride = false);
|
std::string ThreadName(bool DebugModeOverride = false);
|
||||||
|
@ -144,6 +144,15 @@ void RegisterThread(const std::string& str) {
|
|||||||
threadNameMap[std::this_thread::get_id()] = 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();
|
||||||
void LogChatMessage(const std::string& name, int id, const std::string& msg) {
|
void LogChatMessage(const std::string& name, int id, const std::string& msg) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "[CHAT] ";
|
ss << "[CHAT] ";
|
||||||
@ -153,5 +162,5 @@ void LogChatMessage(const std::string& name, int id, const std::string& msg) {
|
|||||||
ss << name << "";
|
ss << name << "";
|
||||||
}
|
}
|
||||||
ss << msg;
|
ss << msg;
|
||||||
Application::Console().Write(ss.str());
|
|
||||||
}
|
}
|
@ -95,8 +95,8 @@ std::string THeartbeatThread::GenerateCall() {
|
|||||||
<< "&port=" << Application::Settings.Port
|
<< "&port=" << Application::Settings.Port
|
||||||
<< "&map=" << Application::Settings.MapName
|
<< "&map=" << Application::Settings.MapName
|
||||||
<< "&private=" << (Application::Settings.Private ? "true" : "false")
|
<< "&private=" << (Application::Settings.Private ? "true" : "false")
|
||||||
<< "&version=" << Application::ServerVersion()
|
<< "&version=" << Application::ServerVersionString()
|
||||||
<< "&clientversion=" << Application::ClientVersion()
|
<< "&clientversion=" << Application::ClientVersionString()
|
||||||
<< "&name=" << Application::Settings.ServerName
|
<< "&name=" << Application::Settings.ServerName
|
||||||
<< "&modlist=" << mResourceManager.TrimmedList()
|
<< "&modlist=" << mResourceManager.TrimmedList()
|
||||||
<< "&modstotalsize=" << mResourceManager.MaxModSize()
|
<< "&modstotalsize=" << mResourceManager.MaxModSize()
|
||||||
|
@ -809,6 +809,14 @@ int lua_GetOSName(lua_State* L) {
|
|||||||
return 1;
|
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)
|
// status, body = HttpsGET(host, port, target)
|
||||||
// example usage:
|
// example usage:
|
||||||
// send a GET https://example.com:443/index.html:
|
// send a GET https://example.com:443/index.html:
|
||||||
@ -938,6 +946,7 @@ void TLuaFile::Load() {
|
|||||||
LuaTable::InsertFunction(mLuaState, "GetOSName", lua_GetOSName);
|
LuaTable::InsertFunction(mLuaState, "GetOSName", lua_GetOSName);
|
||||||
LuaTable::InsertFunction(mLuaState, "HttpsGET", lua_HttpsGET);
|
LuaTable::InsertFunction(mLuaState, "HttpsGET", lua_HttpsGET);
|
||||||
LuaTable::InsertFunction(mLuaState, "HttpsPOST", lua_HttpsPOST);
|
LuaTable::InsertFunction(mLuaState, "HttpsPOST", lua_HttpsPOST);
|
||||||
|
LuaTable::InsertFunction(mLuaState, "GetServerVersion", lua_GetServerVersion);
|
||||||
LuaTable::End(mLuaState, "MP");
|
LuaTable::End(mLuaState, "MP");
|
||||||
|
|
||||||
lua_register(mLuaState, "print", lua_Print);
|
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") {
|
if (Rc.size() > 3 && Rc.substr(0, 2) == "VC") {
|
||||||
Rc = Rc.substr(2);
|
Rc = Rc.substr(2);
|
||||||
if (Rc.length() > 4 || Rc != Application::ClientVersion()) {
|
if (Rc.length() > 4 || Rc != Application::ClientVersionString()) {
|
||||||
ClientKick(*Client, "Outdated Version!");
|
ClientKick(*Client, "Outdated Version!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
namespace json = rapidjson;
|
namespace json = rapidjson;
|
||||||
|
|
||||||
TServer::TServer(int argc, char** argv) {
|
TServer::TServer(int argc, char** argv) {
|
||||||
info("BeamMP Server v" + Application::ServerVersion());
|
info("BeamMP Server v" + Application::ServerVersionString());
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
Application::Settings.CustomIP = argv[1];
|
Application::Settings.CustomIP = argv[1];
|
||||||
size_t n = std::count(Application::Settings.CustomIP.begin(), Application::Settings.CustomIP.end(), '.');
|
size_t n = std::count(Application::Settings.CustomIP.begin(), Application::Settings.CustomIP.end(), '.');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user