mirror of
https://github.com/TES3MP/TES3MP.git
synced 2025-09-30 00:28:08 -04:00
[Server] Move most MiscellaneousFunctions to ServerFunctions
This commit is contained in:
parent
b46767de6e
commit
2cdabddc0e
@ -1,38 +1,12 @@
|
|||||||
#include "Miscellaneous.hpp"
|
#include "Miscellaneous.hpp"
|
||||||
|
|
||||||
#include <components/misc/stringops.hpp>
|
|
||||||
#include <components/openmw-mp/Log.hpp>
|
#include <components/openmw-mp/Log.hpp>
|
||||||
|
|
||||||
#include <apps/openmw-mp/Script/ScriptFunctions.hpp>
|
|
||||||
#include <apps/openmw-mp/Networking.hpp>
|
#include <apps/openmw-mp/Networking.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
static std::string tempFilename;
|
|
||||||
|
|
||||||
bool MiscellaneousFunctions::DoesFileExist(const char *filePath) noexcept
|
|
||||||
{
|
|
||||||
return boost::filesystem::exists(filePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *MiscellaneousFunctions::GetCaseInsensitiveFilename(const char *folderPath, const char *filename) noexcept
|
|
||||||
{
|
|
||||||
if (!boost::filesystem::exists(folderPath)) return "invalid";
|
|
||||||
|
|
||||||
boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
|
|
||||||
|
|
||||||
for (boost::filesystem::directory_iterator itr(folderPath); itr != end_itr; ++itr)
|
|
||||||
{
|
|
||||||
if (Misc::StringUtils::ciEqual(itr->path().filename().string(), filename))
|
|
||||||
{
|
|
||||||
tempFilename = itr->path().filename().string();
|
|
||||||
return tempFilename.c_str();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "invalid";
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int MiscellaneousFunctions::GetLastPlayerId() noexcept
|
unsigned int MiscellaneousFunctions::GetLastPlayerId() noexcept
|
||||||
{
|
{
|
||||||
return Players::getLastPlayerId();
|
return Players::getLastPlayerId();
|
||||||
@ -47,13 +21,3 @@ void MiscellaneousFunctions::SetCurrentMpNum(int mpNum) noexcept
|
|||||||
{
|
{
|
||||||
mwmp::Networking::getPtr()->setCurrentMpNum(mpNum);
|
mwmp::Networking::getPtr()->setCurrentMpNum(mpNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MiscellaneousFunctions::LogMessage(unsigned short level, const char *message) noexcept
|
|
||||||
{
|
|
||||||
LOG_MESSAGE_SIMPLE(level, "[Script]: %s", message);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MiscellaneousFunctions::LogAppend(unsigned short level, const char *message) noexcept
|
|
||||||
{
|
|
||||||
LOG_APPEND(level, "[Script]: %s", message);
|
|
||||||
}
|
|
||||||
|
@ -4,42 +4,15 @@
|
|||||||
#include "../Types.hpp"
|
#include "../Types.hpp"
|
||||||
|
|
||||||
#define MISCELLANEOUSAPI \
|
#define MISCELLANEOUSAPI \
|
||||||
{"DoesFileExist", MiscellaneousFunctions::DoesFileExist},\
|
|
||||||
{"GetCaseInsensitiveFilename", MiscellaneousFunctions::GetCaseInsensitiveFilename},\
|
|
||||||
\
|
|
||||||
{"GetLastPlayerId", MiscellaneousFunctions::GetLastPlayerId},\
|
{"GetLastPlayerId", MiscellaneousFunctions::GetLastPlayerId},\
|
||||||
\
|
\
|
||||||
{"GetCurrentMpNum", MiscellaneousFunctions::GetCurrentMpNum},\
|
{"GetCurrentMpNum", MiscellaneousFunctions::GetCurrentMpNum},\
|
||||||
{"SetCurrentMpNum", MiscellaneousFunctions::SetCurrentMpNum},\
|
{"SetCurrentMpNum", MiscellaneousFunctions::SetCurrentMpNum}
|
||||||
\
|
|
||||||
{"LogMessage", MiscellaneousFunctions::LogMessage},\
|
|
||||||
{"LogAppend", MiscellaneousFunctions::LogAppend}
|
|
||||||
|
|
||||||
class MiscellaneousFunctions
|
class MiscellaneousFunctions
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Check whether a certain file exists.
|
|
||||||
*
|
|
||||||
* This will be a case sensitive check on case sensitive filesystems.
|
|
||||||
*
|
|
||||||
* Whenever you want to enforce case insensitivity, use GetCaseInsensitiveFilename() instead.
|
|
||||||
*
|
|
||||||
* \return Whether the file exists or not.
|
|
||||||
*/
|
|
||||||
static bool DoesFileExist(const char *filePath) noexcept;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Get the first filename in a folder that has a case insensitive match with the filename
|
|
||||||
* argument.
|
|
||||||
*
|
|
||||||
* This is used to retain case insensitivity when opening data files on Linux.
|
|
||||||
*
|
|
||||||
* \return The filename that matches.
|
|
||||||
*/
|
|
||||||
static const char *GetCaseInsensitiveFilename(const char *folderPath, const char *filename) noexcept;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Get the last player ID currently connected to the server.
|
* \brief Get the last player ID currently connected to the server.
|
||||||
*
|
*
|
||||||
@ -75,30 +48,6 @@ public:
|
|||||||
* \return void
|
* \return void
|
||||||
*/
|
*/
|
||||||
static void SetCurrentMpNum(int mpNum) noexcept;
|
static void SetCurrentMpNum(int mpNum) noexcept;
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Write a log message with its own timestamp.
|
|
||||||
*
|
|
||||||
* It will have "[Script]:" prepended to it so as to mark it as a script-generated log message.
|
|
||||||
*
|
|
||||||
* \param level The logging level used (0 for LOG_VERBOSE, 1 for LOG_INFO, 2 for LOG_WARN,
|
|
||||||
* 3 for LOG_ERROR, 4 for LOG_FATAL).
|
|
||||||
* \param message The message logged.
|
|
||||||
* \return void
|
|
||||||
*/
|
|
||||||
static void LogMessage(unsigned short level, const char *message) noexcept;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Write a log message without its own timestamp.
|
|
||||||
*
|
|
||||||
* It will have "[Script]:" prepended to it so as to mark it as a script-generated log message.
|
|
||||||
*
|
|
||||||
* \param level The logging level used (0 for LOG_VERBOSE, 1 for LOG_INFO, 2 for LOG_WARN,
|
|
||||||
* 3 for LOG_ERROR, 4 for LOG_FATAL).
|
|
||||||
* \param message The message logged.
|
|
||||||
* \return void
|
|
||||||
*/
|
|
||||||
static void LogAppend(unsigned short level, const char *message) noexcept;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //OPENMW_MISCELLANEOUSAPI_HPP
|
#endif //OPENMW_MISCELLANEOUSAPI_HPP
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "Server.hpp"
|
#include "Server.hpp"
|
||||||
|
|
||||||
|
#include <components/misc/stringops.hpp>
|
||||||
#include <components/openmw-mp/NetworkMessages.hpp>
|
#include <components/openmw-mp/NetworkMessages.hpp>
|
||||||
#include <components/openmw-mp/Log.hpp>
|
#include <components/openmw-mp/Log.hpp>
|
||||||
#include <components/openmw-mp/Version.hpp>
|
#include <components/openmw-mp/Version.hpp>
|
||||||
@ -9,6 +10,17 @@
|
|||||||
#include <apps/openmw-mp/MasterClient.hpp>
|
#include <apps/openmw-mp/MasterClient.hpp>
|
||||||
#include <Script/Script.hpp>
|
#include <Script/Script.hpp>
|
||||||
|
|
||||||
|
static std::string tempFilename;
|
||||||
|
|
||||||
|
void ServerFunctions::LogMessage(unsigned short level, const char *message) noexcept
|
||||||
|
{
|
||||||
|
LOG_MESSAGE_SIMPLE(level, "[Script]: %s", message);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServerFunctions::LogAppend(unsigned short level, const char *message) noexcept
|
||||||
|
{
|
||||||
|
LOG_APPEND(level, "[Script]: %s", message);
|
||||||
|
}
|
||||||
|
|
||||||
void ServerFunctions::StopServer(int code) noexcept
|
void ServerFunctions::StopServer(int code) noexcept
|
||||||
{
|
{
|
||||||
@ -35,6 +47,28 @@ void ServerFunctions::UnbanAddress(const char *ipAddress) noexcept
|
|||||||
mwmp::Networking::getPtr()->unbanAddress(ipAddress);
|
mwmp::Networking::getPtr()->unbanAddress(ipAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ServerFunctions::DoesFileExist(const char *filePath) noexcept
|
||||||
|
{
|
||||||
|
return boost::filesystem::exists(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *ServerFunctions::GetCaseInsensitiveFilename(const char *folderPath, const char *filename) noexcept
|
||||||
|
{
|
||||||
|
if (!boost::filesystem::exists(folderPath)) return "invalid";
|
||||||
|
|
||||||
|
boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
|
||||||
|
|
||||||
|
for (boost::filesystem::directory_iterator itr(folderPath); itr != end_itr; ++itr)
|
||||||
|
{
|
||||||
|
if (Misc::StringUtils::ciEqual(itr->path().filename().string(), filename))
|
||||||
|
{
|
||||||
|
tempFilename = itr->path().filename().string();
|
||||||
|
return tempFilename.c_str();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "invalid";
|
||||||
|
}
|
||||||
|
|
||||||
const char* ServerFunctions::GetDataPath() noexcept
|
const char* ServerFunctions::GetDataPath() noexcept
|
||||||
{
|
{
|
||||||
return Script::GetModDir();
|
return Script::GetModDir();
|
||||||
|
@ -4,12 +4,17 @@
|
|||||||
#include "../Types.hpp"
|
#include "../Types.hpp"
|
||||||
|
|
||||||
#define SERVERAPI \
|
#define SERVERAPI \
|
||||||
|
{"LogMessage", ServerFunctions::LogMessage},\
|
||||||
|
{"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},\
|
||||||
\
|
\
|
||||||
|
{"DoesFileExist", ServerFunctions::DoesFileExist},\
|
||||||
|
{"GetCaseInsensitiveFilename", ServerFunctions::GetCaseInsensitiveFilename},\
|
||||||
{"GetDataPath", ServerFunctions::GetDataPath},\
|
{"GetDataPath", ServerFunctions::GetDataPath},\
|
||||||
{"GetOperatingSystemType", ServerFunctions::GetOperatingSystemType},\
|
{"GetOperatingSystemType", ServerFunctions::GetOperatingSystemType},\
|
||||||
{"GetArchitectureType", ServerFunctions::GetArchitectureType},\
|
{"GetArchitectureType", ServerFunctions::GetArchitectureType},\
|
||||||
@ -40,6 +45,30 @@ class ServerFunctions
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Write a log message with its own timestamp.
|
||||||
|
*
|
||||||
|
* It will have "[Script]:" prepended to it so as to mark it as a script-generated log message.
|
||||||
|
*
|
||||||
|
* \param level The logging level used (0 for LOG_VERBOSE, 1 for LOG_INFO, 2 for LOG_WARN,
|
||||||
|
* 3 for LOG_ERROR, 4 for LOG_FATAL).
|
||||||
|
* \param message The message logged.
|
||||||
|
* \return void
|
||||||
|
*/
|
||||||
|
static void LogMessage(unsigned short level, const char *message) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Write a log message without its own timestamp.
|
||||||
|
*
|
||||||
|
* It will have "[Script]:" prepended to it so as to mark it as a script-generated log message.
|
||||||
|
*
|
||||||
|
* \param level The logging level used (0 for LOG_VERBOSE, 1 for LOG_INFO, 2 for LOG_WARN,
|
||||||
|
* 3 for LOG_ERROR, 4 for LOG_FATAL).
|
||||||
|
* \param message The message logged.
|
||||||
|
* \return void
|
||||||
|
*/
|
||||||
|
static void LogAppend(unsigned short level, const char *message) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Shut down the server.
|
* \brief Shut down the server.
|
||||||
*
|
*
|
||||||
@ -72,6 +101,27 @@ public:
|
|||||||
*/
|
*/
|
||||||
static void UnbanAddress(const char *ipAddress) noexcept;
|
static void UnbanAddress(const char *ipAddress) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Check whether a certain file exists.
|
||||||
|
*
|
||||||
|
* This will be a case sensitive check on case sensitive filesystems.
|
||||||
|
*
|
||||||
|
* Whenever you want to enforce case insensitivity, use GetCaseInsensitiveFilename() instead.
|
||||||
|
*
|
||||||
|
* \return Whether the file exists or not.
|
||||||
|
*/
|
||||||
|
static bool DoesFileExist(const char *filePath) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Get the first filename in a folder that has a case insensitive match with the filename
|
||||||
|
* argument.
|
||||||
|
*
|
||||||
|
* This is used to retain case insensitivity when opening data files on Linux.
|
||||||
|
*
|
||||||
|
* \return The filename that matches.
|
||||||
|
*/
|
||||||
|
static const char *GetCaseInsensitiveFilename(const char *folderPath, const char *filename) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Get the path of the server's data folder.
|
* \brief Get the path of the server's data folder.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user