diff --git a/apps/openmw-mp/Script/Functions/Settings.cpp b/apps/openmw-mp/Script/Functions/Settings.cpp index 36486b17f..c158a282d 100644 --- a/apps/openmw-mp/Script/Functions/Settings.cpp +++ b/apps/openmw-mp/Script/Functions/Settings.cpp @@ -9,7 +9,15 @@ #include using namespace std; -void SettingFunctions::SetConsoleAllow(unsigned short pid, bool state) +void SettingFunctions::SetDifficulty(unsigned short pid, int difficulty) +{ + Player *player; + GET_PLAYER(pid, player, ); + + player->difficulty = difficulty; +} + +void SettingFunctions::SetConsoleAllowed(unsigned short pid, bool state) { Player *player; GET_PLAYER(pid, player,); @@ -17,12 +25,20 @@ void SettingFunctions::SetConsoleAllow(unsigned short pid, bool state) player->consoleAllowed = state; } -void SettingFunctions::SetDifficulty(unsigned short pid, int difficulty) +void SettingFunctions::SetRestAllowed(unsigned short pid, bool state) { Player *player; - GET_PLAYER(pid, player,); + GET_PLAYER(pid, player, ); - player->difficulty = difficulty; + player->restAllowed = state; +} + +void SettingFunctions::SetWaitAllowed(unsigned short pid, bool state) +{ + Player *player; + GET_PLAYER(pid, player, ); + + player->waitAllowed = state; } void SettingFunctions::SendSettings(unsigned short pid) noexcept diff --git a/apps/openmw-mp/Script/Functions/Settings.hpp b/apps/openmw-mp/Script/Functions/Settings.hpp index 62e6d05d3..7c4e9a032 100644 --- a/apps/openmw-mp/Script/Functions/Settings.hpp +++ b/apps/openmw-mp/Script/Functions/Settings.hpp @@ -4,15 +4,29 @@ #include "../Types.hpp" #define SETTINGSAPI \ - {"SetConsoleAllow", SettingFunctions::SetConsoleAllow},\ - {"SetDifficulty", SettingFunctions::SetDifficulty},\ + {"SetDifficulty", SettingFunctions::SetDifficulty},\ + {"SetConsoleAllowed", SettingFunctions::SetConsoleAllowed},\ + {"SetRestAllowed", SettingFunctions::SetRestAllowed},\ + {"SetWaitAllowed", SettingFunctions::SetWaitAllowed},\ \ - {"SendSettings", SettingFunctions::SendSettings} + {"SendSettings", SettingFunctions::SendSettings} class SettingFunctions { public: + /** + * \brief Set the difficulty for a player. + * + * This changes the difficulty for that player in the server memory, but does not by itself + * send a packet. + * + * \param pid The player ID. + * \param bool The difficulty. + * \return void + */ + static void SetDifficulty(unsigned short pid, int difficulty); + /** * \brief Set whether the console is allowed for a player. * @@ -23,19 +37,31 @@ public: * \param bool The console permission state. * \return void */ - static void SetConsoleAllow(unsigned short pid, bool state); + static void SetConsoleAllowed(unsigned short pid, bool state); /** - * \brief Set the difficulty for a player. + * \brief Set whether resting is allowed for a player. * - * This changes the difficulty for that player in the server memory, but does not by itself - * send a packet. + * This changes the resting permission for that player in the server memory, but does not + * by itself send a packet. * * \param pid The player ID. - * \param bool The difficulty. + * \param bool The resting permission state. * \return void */ - static void SetDifficulty(unsigned short pid, int difficulty); + static void SetRestAllowed(unsigned short pid, bool state); + + /** + * \brief Set whether waiting is allowed for a player. + * + * This changes the waiting permission for that player in the server memory, but does not + * by itself send a packet. + * + * \param pid The player ID. + * \param bool The waiting permission state. + * \return void + */ + static void SetWaitAllowed(unsigned short pid, bool state); /** * \brief Send a PlayerSettings packet to the player affected by it. diff --git a/apps/openmw/mwinput/inputmanagerimp.cpp b/apps/openmw/mwinput/inputmanagerimp.cpp index 301a73d6f..6e4cd4a97 100644 --- a/apps/openmw/mwinput/inputmanagerimp.cpp +++ b/apps/openmw/mwinput/inputmanagerimp.cpp @@ -1011,6 +1011,28 @@ namespace MWInput MWBase::Environment::get().getWindowManager()->messageBox("#{sNotifyMessage2}"); //Nope, return; } + + /* + Start of tes3mp addition + + Prevent resting and waiting if they have been disabled by the server for the local player + */ + int canRest = MWBase::Environment::get().getWorld()->canRest(); + + if (canRest == 0 && !mwmp::Main::get().getLocalPlayer()->restAllowed) + { + MWBase::Environment::get().getWindowManager()->messageBox("You are not allowed to rest."); + return; + } + else if (canRest == 1 && !mwmp::Main::get().getLocalPlayer()->waitAllowed) + { + MWBase::Environment::get().getWindowManager()->messageBox("You are not allowed to wait."); + return; + } + /* + End of tes3mp addition + */ + MWBase::Environment::get().getWindowManager()->pushGuiMode (MWGui::GM_Rest); //Open rest GUI } diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 98a6497b0..ed578035d 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -48,8 +48,10 @@ LocalPlayer::LocalPlayer() charGenStage.current = 0; charGenStage.end = 1; - consoleAllowed = false; difficulty = 0; + consoleAllowed = false; + restAllowed = true; + waitAllowed = true; ignorePosPacket = false; ignoreJailTeleportation = false; diff --git a/apps/openmw/mwmp/processors/player/ProcessorGameSettings.hpp b/apps/openmw/mwmp/processors/player/ProcessorGameSettings.hpp index a17d92f13..3fa2d71b4 100644 --- a/apps/openmw/mwmp/processors/player/ProcessorGameSettings.hpp +++ b/apps/openmw/mwmp/processors/player/ProcessorGameSettings.hpp @@ -26,6 +26,12 @@ namespace mwmp { MWBase::Environment::get().getWindowManager()->popGuiMode(); } + else if ((MWBase::Environment::get().getWindowManager()->getMode() == MWGui::GM_Rest || + MWBase::Environment::get().getWindowManager()->getMode() == MWGui::GM_RestBed) && + (!player->restAllowed || !player->waitAllowed)) + { + MWBase::Environment::get().getWindowManager()->popGuiMode(); + } } } } diff --git a/apps/openmw/mwscript/guiextensions.cpp b/apps/openmw/mwscript/guiextensions.cpp index 254da56d6..eeeb102a6 100644 --- a/apps/openmw/mwscript/guiextensions.cpp +++ b/apps/openmw/mwscript/guiextensions.cpp @@ -1,5 +1,16 @@ #include "guiextensions.hpp" +/* + Start of tes3mp addition + + Include additional headers for multiplayer purposes +*/ +#include "../mwmp/Main.hpp" +#include "../mwmp/LocalPlayer.hpp" +/* + End of tes3mp addition +*/ + #include #include @@ -56,8 +67,21 @@ namespace MWScript MWWorld::Ptr bed = R()(runtime, false); if (bed.isEmpty() || !MWBase::Environment::get().getMechanicsManager()->sleepInBed(MWMechanics::getPlayer(), - bed)) - MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_RestBed); + bed)) + /* + Start of tes3mp change (minor) + + Prevent resting if it has been disabled by the server for the local player + */ + { + if (!mwmp::Main::get().getLocalPlayer()->restAllowed) + MWBase::Environment::get().getWindowManager()->messageBox("You are not allowed to rest."); + else + MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_RestBed); + } + /* + End of tes3mp change (minor) + */ } }; diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index b6c3d5630..24b3e20cc 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -246,8 +246,10 @@ namespace mwmp ESM::ActiveSpells activeSpells; CurrentContainer currentContainer; - bool consoleAllowed; int difficulty; + bool consoleAllowed; + bool restAllowed; + bool waitAllowed; bool ignorePosPacket; diff --git a/components/openmw-mp/Packets/Player/PacketGameSettings.cpp b/components/openmw-mp/Packets/Player/PacketGameSettings.cpp index 4e90d6c34..baee27ab2 100644 --- a/components/openmw-mp/Packets/Player/PacketGameSettings.cpp +++ b/components/openmw-mp/Packets/Player/PacketGameSettings.cpp @@ -13,6 +13,8 @@ void PacketGameSettings::Packet(RakNet::BitStream *bs, bool send) { PlayerPacket::Packet(bs, send); - RW(player->consoleAllowed, send); RW(player->difficulty, send); + RW(player->consoleAllowed, send); + RW(player->restAllowed, send); + RW(player->waitAllowed, send); }