From b249162ca1bcda0bde82bf6decbfe3702734571a Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sun, 11 Mar 2018 04:50:59 +0200 Subject: [PATCH] [General] Implement setting of enforced client log level in GameSettings Certain servers do not want the players to have debug information about the locations and actions of other players, so a client's log level can now be enforced by the server via the GameSettings packet. --- apps/openmw-mp/Script/Functions/Settings.cpp | 8 ++++++++ apps/openmw-mp/Script/Functions/Settings.hpp | 19 +++++++++++++++++++ apps/openmw/mwmp/LocalPlayer.cpp | 1 + .../player/ProcessorGameSettings.hpp | 15 +++++++++++++++ components/openmw-mp/Base/BasePlayer.hpp | 1 + components/openmw-mp/Log.cpp | 5 +++++ components/openmw-mp/Log.hpp | 1 + .../Packets/Player/PacketGameSettings.cpp | 3 ++- 8 files changed, 52 insertions(+), 1 deletion(-) diff --git a/apps/openmw-mp/Script/Functions/Settings.cpp b/apps/openmw-mp/Script/Functions/Settings.cpp index eaee5a56c..f021e7338 100644 --- a/apps/openmw-mp/Script/Functions/Settings.cpp +++ b/apps/openmw-mp/Script/Functions/Settings.cpp @@ -17,6 +17,14 @@ void SettingFunctions::SetDifficulty(unsigned short pid, int difficulty) player->difficulty = difficulty; } +void SettingFunctions::SetEnforcedLogLevel(unsigned short pid, int enforcedLogLevel) +{ + Player *player; + GET_PLAYER(pid, player, ); + + player->enforcedLogLevel = enforcedLogLevel; +} + void SettingFunctions::SetPhysicsFramerate(unsigned short pid, double physicsFramerate) { Player *player; diff --git a/apps/openmw-mp/Script/Functions/Settings.hpp b/apps/openmw-mp/Script/Functions/Settings.hpp index 763a5e69e..48437028d 100644 --- a/apps/openmw-mp/Script/Functions/Settings.hpp +++ b/apps/openmw-mp/Script/Functions/Settings.hpp @@ -5,6 +5,7 @@ #define SETTINGSAPI \ {"SetDifficulty", SettingFunctions::SetDifficulty},\ + {"SetEnforcedLogLevel", SettingFunctions::SetEnforcedLogLevel},\ {"SetPhysicsFramerate", SettingFunctions::SetPhysicsFramerate},\ \ {"SetConsoleAllowed", SettingFunctions::SetConsoleAllowed},\ @@ -30,6 +31,24 @@ public: */ static void SetDifficulty(unsigned short pid, int difficulty); + /** + * \brief Set the client log level enforced for a player. + * + * This changes the enforced log level for that player in the server memory, but does not by itself + * send a packet. + * + * Enforcing a certain log level is necessary to prevent players from learning information from + * their console window that they are otherwise unable to obtain, such as the locations of + * other players. + * + * If you do not wish to enforce a log level, simply set enforcedLogLevel to -1 + * + * \param pid The player ID. + * \param bool The enforced log level. + * \return void + */ + static void SetEnforcedLogLevel(unsigned short pid, int enforcedLogLevel); + /** * \brief Set the physics framerate for a player. * diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index d9d0fc665..c70b2e499 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -48,6 +48,7 @@ LocalPlayer::LocalPlayer() charGenStage.end = 1; difficulty = 0; + enforcedLogLevel = -1; physicsFramerate = 60.0; consoleAllowed = false; bedRestAllowed = true; diff --git a/apps/openmw/mwmp/processors/player/ProcessorGameSettings.hpp b/apps/openmw/mwmp/processors/player/ProcessorGameSettings.hpp index dc3027bdd..1e48d5308 100644 --- a/apps/openmw/mwmp/processors/player/ProcessorGameSettings.hpp +++ b/apps/openmw/mwmp/processors/player/ProcessorGameSettings.hpp @@ -19,8 +19,12 @@ namespace mwmp virtual void Do(PlayerPacket &packet, BasePlayer *player) { + static const int initialLogLevel = Log::GetLevel(); + if (isLocal()) { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_GAME_SETTINGS"); + if (MWBase::Environment::get().getWindowManager()->isGuiMode()) { if (MWBase::Environment::get().getWindowManager()->getMode() == MWGui::GM_Console && !player->consoleAllowed) @@ -30,6 +34,17 @@ namespace mwmp MWBase::Environment::get().getWindowManager()->popGuiMode(); } + if (player->enforcedLogLevel > -1) + { + LOG_APPEND(Log::LOG_INFO, "- server is enforcing log level %i", player->enforcedLogLevel); + Log::SetLevel(player->enforcedLogLevel); + } + else if (initialLogLevel != Log::GetLevel()) + { + LOG_APPEND(Log::LOG_INFO, "- log level has been reset to initial value %i", initialLogLevel); + Log::SetLevel(initialLogLevel); + } + MWBase::Environment::get().getWorld()->setPhysicsFramerate(player->physicsFramerate); } } diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index 04aafb4d4..717ddd266 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -253,6 +253,7 @@ namespace mwmp CurrentContainer currentContainer; int difficulty; + int enforcedLogLevel; float physicsFramerate; bool consoleAllowed; bool bedRestAllowed; diff --git a/components/openmw-mp/Log.cpp b/components/openmw-mp/Log.cpp index 0ed414337..6efbd56f8 100644 --- a/components/openmw-mp/Log.cpp +++ b/components/openmw-mp/Log.cpp @@ -41,6 +41,11 @@ const Log &Log::Get() return *sLog; } +int Log::GetLevel() +{ + return sLog->logLevel; +} + void Log::SetLevel(int level) { sLog->logLevel = level; diff --git a/components/openmw-mp/Log.hpp b/components/openmw-mp/Log.hpp index 7483a3663..58b296c7f 100644 --- a/components/openmw-mp/Log.hpp +++ b/components/openmw-mp/Log.hpp @@ -44,6 +44,7 @@ public: static void Create(int logLevel); static void Delete(); static const Log &Get(); + static int GetLevel(); static void SetLevel(int level); void print(int level, bool hasPrefix, const char *file, int line, const char *message, ...) const; diff --git a/components/openmw-mp/Packets/Player/PacketGameSettings.cpp b/components/openmw-mp/Packets/Player/PacketGameSettings.cpp index 24c275e71..e83031322 100644 --- a/components/openmw-mp/Packets/Player/PacketGameSettings.cpp +++ b/components/openmw-mp/Packets/Player/PacketGameSettings.cpp @@ -14,9 +14,10 @@ void PacketGameSettings::Packet(RakNet::BitStream *bs, bool send) PlayerPacket::Packet(bs, send); RW(player->difficulty, send); - RW(player->physicsFramerate, send); RW(player->consoleAllowed, send); RW(player->bedRestAllowed, send); RW(player->wildernessRestAllowed, send); RW(player->waitAllowed, send); + RW(player->enforcedLogLevel, send); + RW(player->physicsFramerate, send); }