[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.
pull/396/head
David Cernat 6 years ago
parent a3a341fee6
commit b249162ca1

@ -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;

@ -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.
*

@ -48,6 +48,7 @@ LocalPlayer::LocalPlayer()
charGenStage.end = 1;
difficulty = 0;
enforcedLogLevel = -1;
physicsFramerate = 60.0;
consoleAllowed = false;
bedRestAllowed = true;

@ -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);
}
}

@ -253,6 +253,7 @@ namespace mwmp
CurrentContainer currentContainer;
int difficulty;
int enforcedLogLevel;
float physicsFramerate;
bool consoleAllowed;
bool bedRestAllowed;

@ -41,6 +41,11 @@ const Log &Log::Get()
return *sLog;
}
int Log::GetLevel()
{
return sLog->logLevel;
}
void Log::SetLevel(int level)
{
sLog->logLevel = level;

@ -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;

@ -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);
}

Loading…
Cancel
Save