From 4ad87faac1885f9c9edcdb15ea0b2c2938477e43 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Tue, 20 Jun 2017 07:24:15 +0300 Subject: [PATCH] [Server] Create new Settings category for script functions --- apps/openmw-mp/CMakeLists.txt | 3 +- apps/openmw-mp/Script/Functions/GUI.cpp | 13 -------- apps/openmw-mp/Script/Functions/GUI.hpp | 5 +-- apps/openmw-mp/Script/Functions/Settings.cpp | 33 ++++++++++++++++++++ apps/openmw-mp/Script/Functions/Settings.hpp | 21 +++++++++++++ apps/openmw-mp/Script/ScriptFunctions.hpp | 2 ++ 6 files changed, 59 insertions(+), 18 deletions(-) create mode 100644 apps/openmw-mp/Script/Functions/Settings.cpp create mode 100644 apps/openmw-mp/Script/Functions/Settings.hpp diff --git a/apps/openmw-mp/CMakeLists.txt b/apps/openmw-mp/CMakeLists.txt index c3da17823..f4725f259 100644 --- a/apps/openmw-mp/CMakeLists.txt +++ b/apps/openmw-mp/CMakeLists.txt @@ -80,7 +80,8 @@ set(SERVER Script/Functions/Cells.cpp Script/Functions/CharClass.cpp Script/Functions/Chat.cpp Script/Functions/Dialogue.cpp Script/Functions/Factions.cpp Script/Functions/GUI.cpp Script/Functions/Items.cpp Script/Functions/Positions.cpp Script/Functions/Quests.cpp - Script/Functions/Spells.cpp Script/Functions/Stats.cpp Script/Functions/Timer.cpp + Script/Functions/Settings.cpp Script/Functions/Spells.cpp Script/Functions/Stats.cpp + Script/Functions/Timer.cpp ProcessorInitializer.cpp PlayerProcessor.cpp ActorProcessor.cpp WorldProcessor.cpp diff --git a/apps/openmw-mp/Script/Functions/GUI.cpp b/apps/openmw-mp/Script/Functions/GUI.cpp index b8614d57c..34d8405eb 100644 --- a/apps/openmw-mp/Script/Functions/GUI.cpp +++ b/apps/openmw-mp/Script/Functions/GUI.cpp @@ -7,8 +7,6 @@ #include #include - - void GUIFunctions::_MessageBox(unsigned short pid, int id, const char *label) noexcept { Player *player; @@ -85,14 +83,3 @@ void GUIFunctions::SetMapVisibilityAll(unsigned short targetPID, unsigned short { LOG_MESSAGE(Log::LOG_WARN, "stub"); } - -void GUIFunctions::SetConsoleAllow(unsigned short pid, bool state) -{ - Player *player; - GET_PLAYER(pid, player,); - - player->consoleAllowed = state; - - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_SETTINGS)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_SETTINGS)->Send(false); -} diff --git a/apps/openmw-mp/Script/Functions/GUI.hpp b/apps/openmw-mp/Script/Functions/GUI.hpp index 1618e05c0..0b38a22dd 100644 --- a/apps/openmw-mp/Script/Functions/GUI.hpp +++ b/apps/openmw-mp/Script/Functions/GUI.hpp @@ -12,8 +12,7 @@ {"PasswordDialog", GUIFunctions::PasswordDialog},\ {"ListBox", GUIFunctions::ListBox},\ {"SetMapVisibility", GUIFunctions::SetMapVisibility},\ - {"SetMapVisibilityAll", GUIFunctions::SetMapVisibilityAll},\ - {"SetConsoleAllow", GUIFunctions::SetConsoleAllow}\ + {"SetMapVisibilityAll", GUIFunctions::SetMapVisibilityAll} class GUIFunctions { @@ -30,8 +29,6 @@ public: //state 0 - disallow, 1 - allow static void SetMapVisibility(unsigned short targetPID, unsigned short affectedPID, unsigned short state) noexcept; static void SetMapVisibilityAll(unsigned short targetPID, unsigned short state) noexcept; - - static void SetConsoleAllow(unsigned short pid, bool state); }; #endif //OPENMW_GUIAPI_HPP diff --git a/apps/openmw-mp/Script/Functions/Settings.cpp b/apps/openmw-mp/Script/Functions/Settings.cpp new file mode 100644 index 000000000..7572c1d3a --- /dev/null +++ b/apps/openmw-mp/Script/Functions/Settings.cpp @@ -0,0 +1,33 @@ +#include "Settings.hpp" +#include +#include +#include +#include + +#include +using namespace std; + +void SettingFunctions::SetConsoleAllow(unsigned short pid, bool state) +{ + Player *player; + GET_PLAYER(pid, player,); + + player->consoleAllowed = state; +} + +void SettingFunctions::SetDifficulty(unsigned short pid, int difficulty) +{ + Player *player; + GET_PLAYER(pid, player,); + + player->difficulty = difficulty; +} + +void SettingFunctions::SendSettings(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player,); + + mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_SETTINGS)->setPlayer(player); + mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_SETTINGS)->Send(false); +} diff --git a/apps/openmw-mp/Script/Functions/Settings.hpp b/apps/openmw-mp/Script/Functions/Settings.hpp new file mode 100644 index 000000000..fc674fd06 --- /dev/null +++ b/apps/openmw-mp/Script/Functions/Settings.hpp @@ -0,0 +1,21 @@ +#ifndef OPENMW_SETTINGSAPI_HPP +#define OPENMW_SETTINGSAPI_HPP + +#include "../Types.hpp" + +#define SETTINGSAPI \ + {"SetConsoleAllow", SettingFunctions::SetConsoleAllow},\ + {"SetDifficulty", SettingFunctions::SetDifficulty},\ + \ + {"SendSettings", SettingFunctions::SendSettings} + +class SettingFunctions +{ +public: + static void SetConsoleAllow(unsigned short pid, bool state); + static void SetDifficulty(unsigned short pid, int difficulty); + + static void SendSettings(unsigned short pid) noexcept; +}; + +#endif //OPENMW_SETTINGSAPI_HPP diff --git a/apps/openmw-mp/Script/ScriptFunctions.hpp b/apps/openmw-mp/Script/ScriptFunctions.hpp index db660b9fb..b2bcd4f9e 100644 --- a/apps/openmw-mp/Script/ScriptFunctions.hpp +++ b/apps/openmw-mp/Script/ScriptFunctions.hpp @@ -15,6 +15,7 @@ #include