mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-07-02 03:21:34 +00:00
[Server] Clean up recent additions to ServerFunctions
This commit is contained in:
parent
331fa86844
commit
b46767de6e
2 changed files with 52 additions and 19 deletions
|
@ -35,6 +35,11 @@ void ServerFunctions::UnbanAddress(const char *ipAddress) noexcept
|
||||||
mwmp::Networking::getPtr()->unbanAddress(ipAddress);
|
mwmp::Networking::getPtr()->unbanAddress(ipAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* ServerFunctions::GetDataPath() noexcept
|
||||||
|
{
|
||||||
|
return Script::GetModDir();
|
||||||
|
}
|
||||||
|
|
||||||
const char *ServerFunctions::GetOperatingSystemType() noexcept
|
const char *ServerFunctions::GetOperatingSystemType() noexcept
|
||||||
{
|
{
|
||||||
return Utils::getOperatingSystemType().c_str();
|
return Utils::getOperatingSystemType().c_str();
|
||||||
|
@ -137,34 +142,41 @@ void ServerFunctions::SetRuleValue(const char *key, double value) noexcept
|
||||||
mc->SetRuleValue(key, value);
|
mc->SetRuleValue(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerFunctions::AddPluginHash(const char *pluginName, const char *hashStr) noexcept
|
void ServerFunctions::AddDataFileRequirement(const char *dataFilename, const char *checksumString) noexcept
|
||||||
{
|
{
|
||||||
auto &samples = mwmp::Networking::getPtr()->getSamples();
|
auto &samples = mwmp::Networking::getPtr()->getSamples();
|
||||||
auto it = std::find_if(samples.begin(), samples.end(), [&pluginName](mwmp::PacketPreInit::PluginPair &item) {
|
auto it = std::find_if(samples.begin(), samples.end(), [&dataFilename](mwmp::PacketPreInit::PluginPair &item) {
|
||||||
return item.first == pluginName;
|
return item.first == dataFilename;
|
||||||
});
|
});
|
||||||
if (it != samples.end())
|
if (it != samples.end())
|
||||||
it->second.push_back((unsigned) std::stoul(hashStr));
|
it->second.push_back((unsigned) std::stoul(checksumString));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mwmp::PacketPreInit::HashList hashList;
|
mwmp::PacketPreInit::HashList checksumList;
|
||||||
|
|
||||||
unsigned hash = 0;
|
unsigned checksum = 0;
|
||||||
|
|
||||||
if (strlen(hashStr) != 0)
|
if (strlen(checksumString) != 0)
|
||||||
{
|
{
|
||||||
hash = (unsigned) std::stoul(hashStr);
|
checksum = (unsigned) std::stoul(checksumString);
|
||||||
hashList.push_back(hash);
|
checksumList.push_back(checksum);
|
||||||
}
|
}
|
||||||
samples.emplace_back(pluginName, hashList);
|
samples.emplace_back(dataFilename, checksumList);
|
||||||
|
|
||||||
auto mclient = mwmp::Networking::getPtr()->getMasterClient();
|
auto mclient = mwmp::Networking::getPtr()->getMasterClient();
|
||||||
if (mclient)
|
if (mclient)
|
||||||
mclient->PushPlugin({pluginName, hash});
|
mclient->PushPlugin({dataFilename, checksum});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// All methods below are deprecated versions of methods from above
|
||||||
|
|
||||||
const char* ServerFunctions::GetModDir() noexcept
|
const char* ServerFunctions::GetModDir() noexcept
|
||||||
{
|
{
|
||||||
return Script::GetModDir();
|
return GetDataPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServerFunctions::AddPluginHash(const char *pluginName, const char *checksumString) noexcept
|
||||||
|
{
|
||||||
|
AddDataFileRequirement(pluginName, checksumString);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
{"BanAddress", ServerFunctions::BanAddress},\
|
{"BanAddress", ServerFunctions::BanAddress},\
|
||||||
{"UnbanAddress", ServerFunctions::UnbanAddress},\
|
{"UnbanAddress", ServerFunctions::UnbanAddress},\
|
||||||
\
|
\
|
||||||
|
{"GetDataPath", ServerFunctions::GetDataPath},\
|
||||||
{"GetOperatingSystemType", ServerFunctions::GetOperatingSystemType},\
|
{"GetOperatingSystemType", ServerFunctions::GetOperatingSystemType},\
|
||||||
{"GetArchitectureType", ServerFunctions::GetArchitectureType},\
|
{"GetArchitectureType", ServerFunctions::GetArchitectureType},\
|
||||||
{"GetServerVersion", ServerFunctions::GetServerVersion},\
|
{"GetServerVersion", ServerFunctions::GetServerVersion},\
|
||||||
|
@ -29,8 +30,11 @@
|
||||||
{"SetScriptErrorIgnoringState", ServerFunctions::SetScriptErrorIgnoringState},\
|
{"SetScriptErrorIgnoringState", ServerFunctions::SetScriptErrorIgnoringState},\
|
||||||
{"SetRuleString", ServerFunctions::SetRuleString},\
|
{"SetRuleString", ServerFunctions::SetRuleString},\
|
||||||
{"SetRuleValue", ServerFunctions::SetRuleValue},\
|
{"SetRuleValue", ServerFunctions::SetRuleValue},\
|
||||||
{"AddPluginHash", ServerFunctions::AddPluginHash},\
|
\
|
||||||
{"GetModDir", ServerFunctions::GetModDir}
|
{"AddDataFileRequirement", ServerFunctions::AddDataFileRequirement},\
|
||||||
|
\
|
||||||
|
{"GetModDir", ServerFunctions::GetModDir},\
|
||||||
|
{"AddPluginHash", ServerFunctions::AddPluginHash}
|
||||||
|
|
||||||
class ServerFunctions
|
class ServerFunctions
|
||||||
{
|
{
|
||||||
|
@ -68,6 +72,13 @@ public:
|
||||||
*/
|
*/
|
||||||
static void UnbanAddress(const char *ipAddress) noexcept;
|
static void UnbanAddress(const char *ipAddress) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Get the path of the server's data folder.
|
||||||
|
*
|
||||||
|
* \return The data path.
|
||||||
|
*/
|
||||||
|
static const char *GetDataPath() 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.
|
||||||
*
|
*
|
||||||
|
@ -119,7 +130,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* \brief Get the port used by the server.
|
* \brief Get the port used by the server.
|
||||||
*
|
*
|
||||||
* \return Port
|
* \return The port.
|
||||||
*/
|
*/
|
||||||
static unsigned short GetPort() noexcept;
|
static unsigned short GetPort() noexcept;
|
||||||
|
|
||||||
|
@ -220,13 +231,23 @@ public:
|
||||||
static void SetRuleValue(const char *key, double value) noexcept;
|
static void SetRuleValue(const char *key, double value) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Adds plugins to the internal server structure to validate players.
|
* \brief Add a data file and a corresponding CRC32 checksum to the data file loadout
|
||||||
* @param pluginName Name with extension of the plugin or master file.
|
* that connecting clients need to match.
|
||||||
* @param hash Hash string
|
*
|
||||||
|
* It can be used multiple times to set multiple checksums for the same data file.
|
||||||
|
*
|
||||||
|
* Note: If an empty string is provided for the checksum, a checksum will not be
|
||||||
|
* required for that data file.
|
||||||
|
*
|
||||||
|
* @param dataFilename The filename of the data file.
|
||||||
|
* @param checksumString A string with the CRC32 checksum required.
|
||||||
*/
|
*/
|
||||||
static void AddPluginHash(const char *pluginName, const char *hash) noexcept;
|
static void AddDataFileRequirement(const char *dataFilename, const char *checksumString) noexcept;
|
||||||
|
|
||||||
|
// All methods below are deprecated versions of methods from above
|
||||||
|
|
||||||
static const char *GetModDir() noexcept;
|
static const char *GetModDir() noexcept;
|
||||||
|
static void AddPluginHash(const char *pluginName, const char *checksumString) noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //OPENMW_SERVERAPI_HPP
|
#endif //OPENMW_SERVERAPI_HPP
|
||||||
|
|
Loading…
Reference in a new issue