diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index 47091c0f4..7a0339c81 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -33,6 +33,7 @@ using namespace std; Networking *Networking::sThis = 0; static int currentMpNum = 0; +static bool pluginEnforcementState = true; Networking::Networking(RakNet::RakPeerInterface *peer) : mclient(nullptr) { @@ -232,14 +233,16 @@ void Networking::update(RakNet::Packet *packet) packetPreInit.SetSendStream(&bs); // If the loop above was broken, then the client's plugins do not match the server's - if (plugin != plugins.end()) + if (pluginEnforcementState && plugin != plugins.end()) { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s was not allowed to connect due to incompatible plugins", packet->systemAddress.ToString()); packetPreInit.setChecksums(&samples); packetPreInit.Send(packet->systemAddress); peer->CloseConnection(packet->systemAddress, true); } else { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "%s was allowed to connect", packet->systemAddress.ToString()); PacketPreInit::PluginContainer tmp; packetPreInit.setChecksums(&tmp); packetPreInit.Send(packet->systemAddress); @@ -373,6 +376,16 @@ int Networking::incrementMpNum() return currentMpNum; } +bool Networking::getPluginEnforcementState() +{ + return pluginEnforcementState; +} + +void Networking::setPluginEnforcementState(bool state) +{ + pluginEnforcementState = state; +} + const Networking &Networking::get() { return *sThis; diff --git a/apps/openmw-mp/Networking.hpp b/apps/openmw-mp/Networking.hpp index 7deadd537..913377b0b 100644 --- a/apps/openmw-mp/Networking.hpp +++ b/apps/openmw-mp/Networking.hpp @@ -52,6 +52,9 @@ namespace mwmp void setCurrentMpNum(int value); int incrementMpNum(); + bool getPluginEnforcementState(); + void setPluginEnforcementState(bool state); + MasterClient *getMasterClient(); void InitQuery(std::string queryAddr, unsigned short queryPort); void setServerPassword(std::string passw) noexcept; diff --git a/apps/openmw-mp/Script/Functions/Miscellaneous.cpp b/apps/openmw-mp/Script/Functions/Miscellaneous.cpp index 7270fe3e0..3127a14c9 100644 --- a/apps/openmw-mp/Script/Functions/Miscellaneous.cpp +++ b/apps/openmw-mp/Script/Functions/Miscellaneous.cpp @@ -43,6 +43,16 @@ void MiscellaneousFunctions::SetCurrentMpNum(int mpNum) noexcept mwmp::Networking::getPtr()->setCurrentMpNum(mpNum); } +int MiscellaneousFunctions::GetPluginEnforcementState() noexcept +{ + return mwmp::Networking::getPtr()->getPluginEnforcementState(); +} + +void MiscellaneousFunctions::SetPluginEnforcementState(bool state) noexcept +{ + mwmp::Networking::getPtr()->setPluginEnforcementState(state); +} + void MiscellaneousFunctions::LogMessage(unsigned short level, const char *message) noexcept { LOG_MESSAGE_SIMPLE(level, "[Script]: %s", message); diff --git a/apps/openmw-mp/Script/Functions/Miscellaneous.hpp b/apps/openmw-mp/Script/Functions/Miscellaneous.hpp index 487b924ec..d5193fa24 100644 --- a/apps/openmw-mp/Script/Functions/Miscellaneous.hpp +++ b/apps/openmw-mp/Script/Functions/Miscellaneous.hpp @@ -11,6 +11,9 @@ {"GetCurrentMpNum", MiscellaneousFunctions::GetCurrentMpNum},\ {"SetCurrentMpNum", MiscellaneousFunctions::SetCurrentMpNum},\ \ + {"GetPluginEnforcementState", MiscellaneousFunctions::GetPluginEnforcementState},\ + {"SetPluginEnforcementState", MiscellaneousFunctions::SetPluginEnforcementState},\ + \ {"LogMessage", MiscellaneousFunctions::LogMessage},\ {"LogAppend", MiscellaneousFunctions::LogAppend} @@ -64,6 +67,25 @@ public: */ static void SetCurrentMpNum(int mpNum) noexcept; + /** + * \brief Get the plugin enforcement state of the server. + * + * If true, clients are required to use the same plugins as set for the server. + * + * \return The enforcement state. + */ + static int GetPluginEnforcementState() noexcept; + + /** + * \brief Set the plugin enforcement state of the server. + * + * If true, clients are required to use the same plugins as set for the server. + * + * \param state The new enforcement state. + * \return void + */ + static void SetPluginEnforcementState(bool state) noexcept; + /** * \brief Write a log message with its own timestamp. *