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

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

@ -30,7 +30,7 @@ using namespace std;
Networking *Networking::sThis = 0; Networking *Networking::sThis = 0;
static int currentMpNum = 0; static int currentMpNum = 0;
static bool pluginEnforcementState = true; static bool dataFileEnforcementState = true;
static bool scriptErrorIgnoringState = false; static bool scriptErrorIgnoringState = false;
Networking::Networking(RakNet::RakPeerInterface *peer) : mclient(nullptr) 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"); DEBUG_PRINTF("ID_GAME_PREINIT");
PacketPreInit::PluginContainer plugins; PacketPreInit::PluginContainer dataFiles;
PacketPreInit packetPreInit(peer); PacketPreInit packetPreInit(peer);
packetPreInit.SetReadStream(&bsIn); packetPreInit.SetReadStream(&bsIn);
packetPreInit.setChecksums(&plugins); packetPreInit.setChecksums(&dataFiles);
packetPreInit.Read(); packetPreInit.Read();
if (!packetPreInit.isPacketValid() || plugins.empty()) if (!packetPreInit.isPacketValid() || dataFiles.empty())
{ {
LOG_APPEND(Log::LOG_ERROR, "Invalid packetPreInit"); LOG_APPEND(Log::LOG_ERROR, "Invalid packetPreInit");
peer->CloseConnection(packet->systemAddress, false); // close connection without notification peer->CloseConnection(packet->systemAddress, false); // close connection without notification
return false; return false;
} }
auto plugin = plugins.begin(); auto dataFile = dataFiles.begin();
if (samples.size() == plugins.size()) 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 // 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; 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()) if (hashList.empty())
continue; 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 // Break the loop if the client's checksum isn't among those accepted by
// the server // the server
if (it == hashList.end()) if (it == hashList.end())
@ -268,10 +268,10 @@ bool Networking::preInit(RakNet::Packet *packet, RakNet::BitStream &bsIn)
RakNet::BitStream bs; RakNet::BitStream bs;
packetPreInit.SetSendStream(&bs); packetPreInit.SetSendStream(&bs);
// If the loop above was broken, then the client's plugins do not match the server's // If the loop above was broken, then the client's data files do not match the server's
if (pluginEnforcementState && plugin != plugins.end()) 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.setChecksums(&samples);
packetPreInit.Send(packet->systemAddress); packetPreInit.Send(packet->systemAddress);
peer->CloseConnection(packet->systemAddress, true); peer->CloseConnection(packet->systemAddress, true);
@ -427,14 +427,14 @@ int Networking::incrementMpNum()
return currentMpNum; 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() bool Networking::getScriptErrorIgnoringState()

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

@ -133,9 +133,9 @@ bool ServerFunctions::HasPassword() noexcept
return mwmp::Networking::get().isPassworded(); 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 bool ServerFunctions::GetScriptErrorIgnoringState() noexcept
@ -160,9 +160,9 @@ void ServerFunctions::SetServerPassword(const char *password) noexcept
mwmp::Networking::getPtr()->setServerPassword(password); 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 void ServerFunctions::SetScriptErrorIgnoringState(bool state) noexcept
@ -223,6 +223,16 @@ const char* ServerFunctions::GetModDir() noexcept
return GetDataPath(); 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 void ServerFunctions::AddPluginHash(const char *pluginName, const char *checksumString) noexcept
{ {
AddDataFileRequirement(pluginName, checksumString); AddDataFileRequirement(pluginName, checksumString);

@ -26,13 +26,13 @@
{"GetMaxPlayers", ServerFunctions::GetMaxPlayers},\ {"GetMaxPlayers", ServerFunctions::GetMaxPlayers},\
{"GetPort", ServerFunctions::GetPort},\ {"GetPort", ServerFunctions::GetPort},\
{"HasPassword", ServerFunctions::HasPassword},\ {"HasPassword", ServerFunctions::HasPassword},\
{"GetPluginEnforcementState", ServerFunctions::GetPluginEnforcementState},\ {"GetDataFileEnforcementState", ServerFunctions::GetDataFileEnforcementState},\
{"GetScriptErrorIgnoringState", ServerFunctions::GetScriptErrorIgnoringState},\ {"GetScriptErrorIgnoringState", ServerFunctions::GetScriptErrorIgnoringState},\
\ \
{"SetGameMode", ServerFunctions::SetGameMode},\ {"SetGameMode", ServerFunctions::SetGameMode},\
{"SetHostname", ServerFunctions::SetHostname},\ {"SetHostname", ServerFunctions::SetHostname},\
{"SetServerPassword", ServerFunctions::SetServerPassword},\ {"SetServerPassword", ServerFunctions::SetServerPassword},\
{"SetPluginEnforcementState", ServerFunctions::SetPluginEnforcementState},\ {"SetDataFileEnforcementState", ServerFunctions::SetDataFileEnforcementState},\
{"SetScriptErrorIgnoringState", ServerFunctions::SetScriptErrorIgnoringState},\ {"SetScriptErrorIgnoringState", ServerFunctions::SetScriptErrorIgnoringState},\
{"SetRuleString", ServerFunctions::SetRuleString},\ {"SetRuleString", ServerFunctions::SetRuleString},\
{"SetRuleValue", ServerFunctions::SetRuleValue},\ {"SetRuleValue", ServerFunctions::SetRuleValue},\
@ -41,6 +41,8 @@
\ \
{"DoesFileExist", ServerFunctions::DoesFileExist},\ {"DoesFileExist", ServerFunctions::DoesFileExist},\
{"GetModDir", ServerFunctions::GetModDir},\ {"GetModDir", ServerFunctions::GetModDir},\
{"GetPluginEnforcementState", ServerFunctions::GetPluginEnforcementState},\
{"SetPluginEnforcementState", ServerFunctions::SetPluginEnforcementState},\
{"AddPluginHash", ServerFunctions::AddPluginHash} {"AddPluginHash", ServerFunctions::AddPluginHash}
class ServerFunctions class ServerFunctions
@ -208,13 +210,13 @@ public:
static bool HasPassword() noexcept; 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. * \return The enforcement state.
*/ */
static bool GetPluginEnforcementState() noexcept; static bool GetDataFileEnforcementState() noexcept;
/** /**
* \brief Get the script error ignoring state of the server. * \brief Get the script error ignoring state of the server.
@ -250,14 +252,14 @@ public:
static void SetServerPassword(const char *password) noexcept; 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. * \param state The new enforcement state.
* \return void * \return void
*/ */
static void SetPluginEnforcementState(bool state) noexcept; static void SetDataFileEnforcementState(bool state) noexcept;
/** /**
* \brief Set whether script errors should be ignored or not. * \brief Set whether script errors should be ignored or not.
@ -307,6 +309,8 @@ public:
static bool DoesFileExist(const char *filePath) noexcept; static bool DoesFileExist(const char *filePath) noexcept;
static const char *GetModDir() 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; static void AddPluginHash(const char *pluginName, const char *checksumString) noexcept;
}; };

Loading…
Cancel
Save