From bb8182663f76a53d0f842ddcf2fb76ca02ff7737 Mon Sep 17 00:00:00 2001 From: uramer Date: Fri, 28 Feb 2020 00:40:00 +0100 Subject: [PATCH] [General] Set any settings from the Game category with the GAME_SETTINGS packet --- apps/openmw-mp/Script/Functions/Settings.cpp | 21 +++++++++++++-- apps/openmw-mp/Script/Functions/Settings.hpp | 27 ++++++++++++++++++- .../player/ProcessorGameSettings.hpp | 5 ++++ components/openmw-mp/Base/BasePlayer.hpp | 1 + .../Packets/Player/PacketGameSettings.cpp | 27 +++++++++++++++++++ 5 files changed, 78 insertions(+), 3 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/Settings.cpp b/apps/openmw-mp/Script/Functions/Settings.cpp index 71fad5d01..3f86074f0 100644 --- a/apps/openmw-mp/Script/Functions/Settings.cpp +++ b/apps/openmw-mp/Script/Functions/Settings.cpp @@ -65,7 +65,21 @@ void SettingFunctions::SetWaitAllowed(unsigned short pid, bool state) player->waitAllowed = state; } -void SettingFunctions::SendSettings(unsigned short pid) noexcept +void SettingFunctions::SetGameSettingValue(unsigned short pid, const char* setting, const char* value) { + Player* player; + GET_PLAYER(pid, player, ); + + player->gameSettings[setting] = value; +} + +void SettingFunctions::ClearGameSettingValues(unsigned short pid) { + Player* player; + GET_PLAYER(pid, player, ); + + player->gameSettings.clear(); +} + +void SettingFunctions::SendSettings(unsigned short pid, bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept { Player *player; GET_PLAYER(pid, player,); @@ -73,5 +87,8 @@ void SettingFunctions::SendSettings(unsigned short pid) noexcept mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_SETTINGS); packet->setPlayer(player); - packet->Send(false); + if (!skipAttachedPlayer) + packet->Send(false); + if (sendToOtherPlayers) + packet->Send(true); } diff --git a/apps/openmw-mp/Script/Functions/Settings.hpp b/apps/openmw-mp/Script/Functions/Settings.hpp index 1d5275c58..86b99f37d 100644 --- a/apps/openmw-mp/Script/Functions/Settings.hpp +++ b/apps/openmw-mp/Script/Functions/Settings.hpp @@ -13,6 +13,9 @@ {"SetWildernessRestAllowed", SettingFunctions::SetWildernessRestAllowed},\ {"SetWaitAllowed", SettingFunctions::SetWaitAllowed},\ \ + {"SetGameSettingValue", SettingFunctions::SetGameSettingValue},\ + {"ClearGameSettingValues", SettingFunctions::ClearGameSettingValues},\ + \ {"SendSettings", SettingFunctions::SendSettings} class SettingFunctions @@ -109,13 +112,35 @@ public: */ static void SetWaitAllowed(unsigned short pid, bool state); + /** + * \brief Set value for a game setting. + * + * This overrides the setting value set in OpenMW Launcher. Only applies to the Game category. + * + * \param pid The player ID. + * \param setting Name of a setting in the Game category + * \param value Value of the setting (as a string) + * \return void + */ + static void SetGameSettingValue(unsigned short pid, const char* setting, const char* value); + + /** + * \brief Clear the settings values + * + * Clear any changes done by SetGameSettingValue + * + * \param pid The player ID. + * \return void + */ + static void ClearGameSettingValues(unsigned short pid); + /** * \brief Send a PlayerSettings packet to the player affected by it. * * \param pid The player ID to send it to. * \return void */ - static void SendSettings(unsigned short pid) noexcept; + static void SendSettings(unsigned short pid, bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept; }; #endif //OPENMW_SETTINGSAPI_HPP diff --git a/apps/openmw/mwmp/processors/player/ProcessorGameSettings.hpp b/apps/openmw/mwmp/processors/player/ProcessorGameSettings.hpp index 28ac3a962..28751d201 100644 --- a/apps/openmw/mwmp/processors/player/ProcessorGameSettings.hpp +++ b/apps/openmw/mwmp/processors/player/ProcessorGameSettings.hpp @@ -11,6 +11,7 @@ namespace mwmp { class ProcessorGameSettings final: public PlayerProcessor { + const std::string GAME_SETTING_CATEGORY = "Game"; public: ProcessorGameSettings() { @@ -49,6 +50,10 @@ namespace mwmp } MWBase::Environment::get().getWorld()->setPhysicsFramerate(player->physicsFramerate); + + for (auto setting : player->gameSettings) { + Settings::Manager::setString(setting.first, GAME_SETTING_CATEGORY, setting.second); + } } } }; diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index f4dcbbf05..ae71a66ab 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -250,6 +250,7 @@ namespace mwmp std::string birthsign; std::string chatMessage; CharGenState charGenState; + std::map gameSettings; std::string sound; Animation animation; diff --git a/components/openmw-mp/Packets/Player/PacketGameSettings.cpp b/components/openmw-mp/Packets/Player/PacketGameSettings.cpp index 8999557f2..cff2061d1 100644 --- a/components/openmw-mp/Packets/Player/PacketGameSettings.cpp +++ b/components/openmw-mp/Packets/Player/PacketGameSettings.cpp @@ -20,4 +20,31 @@ void PacketGameSettings::Packet(RakNet::BitStream *newBitstream, bool send) RW(player->waitAllowed, send); RW(player->enforcedLogLevel, send); RW(player->physicsFramerate, send); + + uint32_t gameSettingCount = static_cast(player->gameSettings.size()); + RW(gameSettingCount, send); + + std::string mapIndex; + std::string mapValue; + + if (send) + { + for (auto&& gameSetting : player->gameSettings) + { + mapIndex = gameSetting.first; + mapValue = gameSetting.second; + RW(mapIndex, send, false); + RW(mapValue, send, false); + } + } + else + { + player->gameSettings.clear(); + for (unsigned int n = 0; n < gameSettingCount; n++) + { + RW(mapIndex, send, false); + RW(mapValue, send, false); + player->gameSettings[mapIndex] = mapValue; + } + } }