[Server] Add GetMillisecondsSinceServerStart() server function

pull/516/head
David Cernat 6 years ago
parent bd677726bf
commit 91f82d845c

@ -11,6 +11,7 @@
#include <Script/Script.hpp> #include <Script/Script.hpp>
static std::string tempFilename; static std::string tempFilename;
static std::chrono::high_resolution_clock::time_point startupTime = std::chrono::high_resolution_clock::now();
void ServerFunctions::LogMessage(unsigned short level, const char *message) noexcept void ServerFunctions::LogMessage(unsigned short level, const char *message) noexcept
{ {
@ -74,6 +75,13 @@ const char* ServerFunctions::GetDataPath() noexcept
return Script::GetModDir(); return Script::GetModDir();
} }
unsigned int ServerFunctions::GetMillisecondsSinceServerStart() noexcept
{
std::chrono::high_resolution_clock::time_point currentTime = std::chrono::high_resolution_clock::now();
std::chrono::milliseconds milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(currentTime - startupTime);
return milliseconds.count();
}
const char *ServerFunctions::GetOperatingSystemType() noexcept const char *ServerFunctions::GetOperatingSystemType() noexcept
{ {
return Utils::getOperatingSystemType().c_str(); return Utils::getOperatingSystemType().c_str();

@ -4,43 +4,44 @@
#include "../Types.hpp" #include "../Types.hpp"
#define SERVERAPI \ #define SERVERAPI \
{"LogMessage", ServerFunctions::LogMessage},\ {"LogMessage", ServerFunctions::LogMessage},\
{"LogAppend", ServerFunctions::LogAppend},\ {"LogAppend", ServerFunctions::LogAppend},\
\ \
{"StopServer", ServerFunctions::StopServer},\ {"StopServer", ServerFunctions::StopServer},\
\ \
{"Kick", ServerFunctions::Kick},\ {"Kick", ServerFunctions::Kick},\
{"BanAddress", ServerFunctions::BanAddress},\ {"BanAddress", ServerFunctions::BanAddress},\
{"UnbanAddress", ServerFunctions::UnbanAddress},\ {"UnbanAddress", ServerFunctions::UnbanAddress},\
\ \
{"DoesFilePathExist", ServerFunctions::DoesFilePathExist},\ {"DoesFilePathExist", ServerFunctions::DoesFilePathExist},\
{"GetCaseInsensitiveFilename", ServerFunctions::GetCaseInsensitiveFilename},\ {"GetCaseInsensitiveFilename", ServerFunctions::GetCaseInsensitiveFilename},\
{"GetDataPath", ServerFunctions::GetDataPath},\ {"GetDataPath", ServerFunctions::GetDataPath},\
{"GetOperatingSystemType", ServerFunctions::GetOperatingSystemType},\ {"GetMillisecondsSinceServerStart", ServerFunctions::GetMillisecondsSinceServerStart},\
{"GetArchitectureType", ServerFunctions::GetArchitectureType},\ {"GetOperatingSystemType", ServerFunctions::GetOperatingSystemType},\
{"GetServerVersion", ServerFunctions::GetServerVersion},\ {"GetArchitectureType", ServerFunctions::GetArchitectureType},\
{"GetProtocolVersion", ServerFunctions::GetProtocolVersion},\ {"GetServerVersion", ServerFunctions::GetServerVersion},\
{"GetAvgPing", ServerFunctions::GetAvgPing},\ {"GetProtocolVersion", ServerFunctions::GetProtocolVersion},\
{"GetIP", ServerFunctions::GetIP},\ {"GetAvgPing", ServerFunctions::GetAvgPing},\
{"GetMaxPlayers", ServerFunctions::GetMaxPlayers},\ {"GetIP", ServerFunctions::GetIP},\
{"GetPort", ServerFunctions::GetPort},\ {"GetMaxPlayers", ServerFunctions::GetMaxPlayers},\
{"HasPassword", ServerFunctions::HasPassword},\ {"GetPort", ServerFunctions::GetPort},\
{"GetPluginEnforcementState", ServerFunctions::GetPluginEnforcementState},\ {"HasPassword", ServerFunctions::HasPassword},\
{"GetScriptErrorIgnoringState", ServerFunctions::GetScriptErrorIgnoringState},\ {"GetPluginEnforcementState", ServerFunctions::GetPluginEnforcementState},\
{"GetScriptErrorIgnoringState", ServerFunctions::GetScriptErrorIgnoringState},\
\ \
{"SetGameMode", ServerFunctions::SetGameMode},\ {"SetGameMode", ServerFunctions::SetGameMode},\
{"SetHostname", ServerFunctions::SetHostname},\ {"SetHostname", ServerFunctions::SetHostname},\
{"SetServerPassword", ServerFunctions::SetServerPassword},\ {"SetServerPassword", ServerFunctions::SetServerPassword},\
{"SetPluginEnforcementState", ServerFunctions::SetPluginEnforcementState},\ {"SetPluginEnforcementState", ServerFunctions::SetPluginEnforcementState},\
{"SetScriptErrorIgnoringState", ServerFunctions::SetScriptErrorIgnoringState},\ {"SetScriptErrorIgnoringState", ServerFunctions::SetScriptErrorIgnoringState},\
{"SetRuleString", ServerFunctions::SetRuleString},\ {"SetRuleString", ServerFunctions::SetRuleString},\
{"SetRuleValue", ServerFunctions::SetRuleValue},\ {"SetRuleValue", ServerFunctions::SetRuleValue},\
\ \
{"AddDataFileRequirement", ServerFunctions::AddDataFileRequirement},\ {"AddDataFileRequirement", ServerFunctions::AddDataFileRequirement},\
\ \
{"DoesFileExist", ServerFunctions::DoesFileExist},\ {"DoesFileExist", ServerFunctions::DoesFileExist},\
{"GetModDir", ServerFunctions::GetModDir},\ {"GetModDir", ServerFunctions::GetModDir},\
{"AddPluginHash", ServerFunctions::AddPluginHash} {"AddPluginHash", ServerFunctions::AddPluginHash}
class ServerFunctions class ServerFunctions
{ {
@ -130,6 +131,13 @@ public:
*/ */
static const char *GetDataPath() noexcept; static const char *GetDataPath() noexcept;
/**
* \brief Get the milliseconds elapsed since the server was started.
*
* \return The time since the server's startup in milliseconds.
*/
static unsigned int GetMillisecondsSinceServerStart() noexcept;
/** /**
* \brief Get the type of the operating system used by the server. * \brief Get the type of the operating system used by the server.
* *

Loading…
Cancel
Save