[Server] Refer to data files instead of plugins in var & function names

pull/526/head
David Cernat 6 years ago
parent a2f110ae6d
commit d8919dcec6

@ -30,7 +30,7 @@ using namespace std;
Networking *Networking::sThis = 0;
static int currentMpNum = 0;
static bool pluginEnforcementState = true;
static bool dataFileEnforcementState = true;
static bool scriptErrorIgnoringState = false;
Networking::Networking(RakNet::RakPeerInterface *peer) : mclient(nullptr)
@ -228,34 +228,34 @@ bool Networking::preInit(RakNet::Packet *packet, RakNet::BitStream &bsIn)
}
DEBUG_PRINTF("ID_GAME_PREINIT");
PacketPreInit::PluginContainer plugins;
PacketPreInit::PluginContainer dataFiles;
PacketPreInit packetPreInit(peer);
packetPreInit.SetReadStream(&bsIn);
packetPreInit.setChecksums(&plugins);
packetPreInit.setChecksums(&dataFiles);
packetPreInit.Read();
if (!packetPreInit.isPacketValid() || plugins.empty())
if (!packetPreInit.isPacketValid() || dataFiles.empty())
{
LOG_APPEND(Log::LOG_ERROR, "Invalid packetPreInit");
peer->CloseConnection(packet->systemAddress, false); // close connection without notification
return false;
}
auto plugin = plugins.begin();
if (samples.size() == plugins.size())
auto dataFile = dataFiles.begin();
if (samples.size() == dataFiles.size())
{
for (int i = 0; plugin != plugins.end(); plugin++, i++)
for (int i = 0; dataFile != dataFiles.end(); dataFile++, i++)
{
LOG_APPEND(Log::LOG_VERBOSE, "- %X\t%s", plugin->second[0], plugin->first.c_str());
LOG_APPEND(Log::LOG_VERBOSE, "- %X\t%s", dataFile->second[0], dataFile->first.c_str());
// Check if the filenames match, ignoring case
if (Misc::StringUtils::ciEqual(samples[i].first, plugin->first))
if (Misc::StringUtils::ciEqual(samples[i].first, dataFile->first))
{
auto &hashList = samples[i].second;
// Proceed if no checksums have been listed for this plugin on the server
// Proceed if no checksums have been listed for this dataFile on the server
if (hashList.empty())
continue;
auto it = find(hashList.begin(), hashList.end(), plugin->second[0]);
auto it = find(hashList.begin(), hashList.end(), dataFile->second[0]);
// Break the loop if the client's checksum isn't among those accepted by
// the server
if (it == hashList.end())
@ -268,10 +268,10 @@ bool Networking::preInit(RakNet::Packet *packet, RakNet::BitStream &bsIn)
RakNet::BitStream bs;
packetPreInit.SetSendStream(&bs);
// If the loop above was broken, then the client's plugins do not match the server's
if (pluginEnforcementState && plugin != plugins.end())
// If the loop above was broken, then the client's data files do not match the server's
if (dataFileEnforcementState && dataFile != dataFiles.end())
{
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s was not allowed to connect due to incompatible plugins", packet->systemAddress.ToString());
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s was not allowed to connect due to incompatible data files", packet->systemAddress.ToString());
packetPreInit.setChecksums(&samples);
packetPreInit.Send(packet->systemAddress);
peer->CloseConnection(packet->systemAddress, true);
@ -427,14 +427,14 @@ int Networking::incrementMpNum()
return currentMpNum;
}
bool Networking::getPluginEnforcementState()
bool Networking::getDataFileEnforcementState()
{
return pluginEnforcementState;
return dataFileEnforcementState;
}
void Networking::setPluginEnforcementState(bool state)
void Networking::setDataFileEnforcementState(bool state)
{
pluginEnforcementState = state;
dataFileEnforcementState = state;
}
bool Networking::getScriptErrorIgnoringState()

@ -53,8 +53,8 @@ namespace mwmp
void setCurrentMpNum(int value);
int incrementMpNum();
bool getPluginEnforcementState();
void setPluginEnforcementState(bool state);
bool getDataFileEnforcementState();
void setDataFileEnforcementState(bool state);
bool getScriptErrorIgnoringState();
void setScriptErrorIgnoringState(bool state);

@ -133,9 +133,9 @@ bool ServerFunctions::HasPassword() noexcept
return mwmp::Networking::get().isPassworded();
}
bool ServerFunctions::GetPluginEnforcementState() noexcept
bool ServerFunctions::GetDataFileEnforcementState() noexcept
{
return mwmp::Networking::getPtr()->getPluginEnforcementState();
return mwmp::Networking::getPtr()->getDataFileEnforcementState();
}
bool ServerFunctions::GetScriptErrorIgnoringState() noexcept
@ -160,9 +160,9 @@ void ServerFunctions::SetServerPassword(const char *password) noexcept
mwmp::Networking::getPtr()->setServerPassword(password);
}
void ServerFunctions::SetPluginEnforcementState(bool state) noexcept
void ServerFunctions::SetDataFileEnforcementState(bool state) noexcept
{
mwmp::Networking::getPtr()->setPluginEnforcementState(state);
mwmp::Networking::getPtr()->setDataFileEnforcementState(state);
}
void ServerFunctions::SetScriptErrorIgnoringState(bool state) noexcept
@ -223,6 +223,16 @@ const char* ServerFunctions::GetModDir() noexcept
return GetDataPath();
}
bool ServerFunctions::GetPluginEnforcementState() noexcept
{
return mwmp::Networking::getPtr()->getDataFileEnforcementState();
}
void ServerFunctions::SetPluginEnforcementState(bool state) noexcept
{
SetDataFileEnforcementState(state);
}
void ServerFunctions::AddPluginHash(const char *pluginName, const char *checksumString) noexcept
{
AddDataFileRequirement(pluginName, checksumString);

@ -26,13 +26,13 @@
{"GetMaxPlayers", ServerFunctions::GetMaxPlayers},\
{"GetPort", ServerFunctions::GetPort},\
{"HasPassword", ServerFunctions::HasPassword},\
{"GetPluginEnforcementState", ServerFunctions::GetPluginEnforcementState},\
{"GetDataFileEnforcementState", ServerFunctions::GetDataFileEnforcementState},\
{"GetScriptErrorIgnoringState", ServerFunctions::GetScriptErrorIgnoringState},\
\
{"SetGameMode", ServerFunctions::SetGameMode},\
{"SetHostname", ServerFunctions::SetHostname},\
{"SetServerPassword", ServerFunctions::SetServerPassword},\
{"SetPluginEnforcementState", ServerFunctions::SetPluginEnforcementState},\
{"SetDataFileEnforcementState", ServerFunctions::SetDataFileEnforcementState},\
{"SetScriptErrorIgnoringState", ServerFunctions::SetScriptErrorIgnoringState},\
{"SetRuleString", ServerFunctions::SetRuleString},\
{"SetRuleValue", ServerFunctions::SetRuleValue},\
@ -41,6 +41,8 @@
\
{"DoesFileExist", ServerFunctions::DoesFileExist},\
{"GetModDir", ServerFunctions::GetModDir},\
{"GetPluginEnforcementState", ServerFunctions::GetPluginEnforcementState},\
{"SetPluginEnforcementState", ServerFunctions::SetPluginEnforcementState},\
{"AddPluginHash", ServerFunctions::AddPluginHash}
class ServerFunctions
@ -208,13 +210,13 @@ public:
static bool HasPassword() noexcept;
/**
* \brief Get the plugin enforcement state of the server.
* \brief Get the data file enforcement state of the server.
*
* If true, clients are required to use the same plugins as set for the server.
* If true, clients are required to use the same data files as set for the server.
*
* \return The enforcement state.
*/
static bool GetPluginEnforcementState() noexcept;
static bool GetDataFileEnforcementState() noexcept;
/**
* \brief Get the script error ignoring state of the server.
@ -250,14 +252,14 @@ public:
static void SetServerPassword(const char *password) noexcept;
/**
* \brief Set the plugin enforcement state of the server.
* \brief Set the data file enforcement state of the server.
*
* If true, clients are required to use the same plugins as set for the server.
* If true, clients are required to use the same data files as set for the server.
*
* \param state The new enforcement state.
* \return void
*/
static void SetPluginEnforcementState(bool state) noexcept;
static void SetDataFileEnforcementState(bool state) noexcept;
/**
* \brief Set whether script errors should be ignored or not.
@ -307,6 +309,8 @@ public:
static bool DoesFileExist(const char *filePath) noexcept;
static const char *GetModDir() noexcept;
static bool GetPluginEnforcementState() noexcept;
static void SetPluginEnforcementState(bool state) noexcept;
static void AddPluginHash(const char *pluginName, const char *checksumString) noexcept;
};

Loading…
Cancel
Save