From bef36f77ca54a46673171830b84b0232c953f9c1 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Tue, 15 May 2018 20:58:09 +0300 Subject: [PATCH] [Server] Create WorldstateFunctions and move GameTime functions there --- apps/openmw-mp/CMakeLists.txt | 1 + apps/openmw-mp/Script/Functions/Objects.cpp | 40 --------------- apps/openmw-mp/Script/Functions/Objects.hpp | 32 +----------- .../openmw-mp/Script/Functions/Worldstate.cpp | 50 +++++++++++++++++++ .../openmw-mp/Script/Functions/Worldstate.hpp | 44 ++++++++++++++++ apps/openmw-mp/Script/ScriptFunctions.hpp | 6 ++- 6 files changed, 100 insertions(+), 73 deletions(-) create mode 100644 apps/openmw-mp/Script/Functions/Worldstate.cpp create mode 100644 apps/openmw-mp/Script/Functions/Worldstate.hpp diff --git a/apps/openmw-mp/CMakeLists.txt b/apps/openmw-mp/CMakeLists.txt index 7723e79aa..fd693135a 100644 --- a/apps/openmw-mp/CMakeLists.txt +++ b/apps/openmw-mp/CMakeLists.txt @@ -83,6 +83,7 @@ set(SERVER Script/ScriptFunctions.cpp Script/Functions/Actors.cpp Script/Functions/Objects.cpp Script/Functions/Miscellaneous.cpp + Script/Functions/Worldstate.cpp Script/Functions/Books.cpp Script/Functions/Cells.cpp Script/Functions/CharClass.cpp Script/Functions/Chat.cpp Script/Functions/Dialogue.cpp Script/Functions/Factions.cpp diff --git a/apps/openmw-mp/Script/Functions/Objects.cpp b/apps/openmw-mp/Script/Functions/Objects.cpp index ccc3b95fc..878b1a198 100644 --- a/apps/openmw-mp/Script/Functions/Objects.cpp +++ b/apps/openmw-mp/Script/Functions/Objects.cpp @@ -449,43 +449,3 @@ void ObjectFunctions::SendConsoleCommand(bool broadcast) noexcept if (broadcast) packet->Send(true); } - -void ObjectFunctions::SetHour(unsigned short pid, double hour) noexcept -{ - Player *player; - GET_PLAYER(pid, player,); - - player->hour = hour; - player->month = -1; - player->day = -1; - - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_TIME)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_TIME)->Send(false); -} - -void ObjectFunctions::SetMonth(unsigned short pid, int month) noexcept -{ - Player *player; - GET_PLAYER(pid, player,); - - player->hour = -1; - player->month = month; - player->day = -1; - - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_TIME)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_TIME)->Send(false); - -} - -void ObjectFunctions::SetDay(unsigned short pid, int day) noexcept -{ - Player *player; - GET_PLAYER(pid, player,); - - player->hour = -1; - player->month = -1; - player->day = day; - - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_TIME)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_TIME)->Send(false); -} diff --git a/apps/openmw-mp/Script/Functions/Objects.hpp b/apps/openmw-mp/Script/Functions/Objects.hpp index e4a49ef6c..f8992b7de 100644 --- a/apps/openmw-mp/Script/Functions/Objects.hpp +++ b/apps/openmw-mp/Script/Functions/Objects.hpp @@ -81,11 +81,7 @@ {"SendDoorState", ObjectFunctions::SendDoorState},\ {"SendDoorDestination", ObjectFunctions::SendDoorDestination},\ {"SendContainer", ObjectFunctions::SendContainer},\ - {"SendConsoleCommand", ObjectFunctions::SendConsoleCommand},\ - \ - {"SetHour", ObjectFunctions::SetHour},\ - {"SetMonth", ObjectFunctions::SetMonth},\ - {"SetDay", ObjectFunctions::SetDay} + {"SendConsoleCommand", ObjectFunctions::SendConsoleCommand} class ObjectFunctions { @@ -751,32 +747,6 @@ public: */ static void SendConsoleCommand(bool broadcast = false) noexcept; - /** - * \brief Set the game hour for a player and send a GameTime packet to that player. - * - * \param pid The player ID. - * \param hour The hour. - * \return void - */ - static void SetHour(unsigned short pid, double hour) noexcept; - - /** - * \brief Set the game month for a player and send a GameTime packet to that player. - * - * \param pid The player ID. - * \param month The month. - * \return void - */ - static void SetMonth(unsigned short pid, int month) noexcept; - - /** - * \brief Set the game day for a player and send a GameTime packet to that player. - * - * \param pid The player ID. - * \param day The day. - * \return void - */ - static void SetDay(unsigned short pid, int day) noexcept; }; diff --git a/apps/openmw-mp/Script/Functions/Worldstate.cpp b/apps/openmw-mp/Script/Functions/Worldstate.cpp new file mode 100644 index 000000000..b95b67d14 --- /dev/null +++ b/apps/openmw-mp/Script/Functions/Worldstate.cpp @@ -0,0 +1,50 @@ +#include + +#include +#include +#include + +#include "Worldstate.hpp" + +#include +using namespace std; + +void WorldstateFunctions::SetHour(unsigned short pid, double hour) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + player->hour = hour; + player->month = -1; + player->day = -1; + + mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_TIME)->setPlayer(player); + mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_TIME)->Send(false); +} + +void WorldstateFunctions::SetMonth(unsigned short pid, int month) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + player->hour = -1; + player->month = month; + player->day = -1; + + mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_TIME)->setPlayer(player); + mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_TIME)->Send(false); + +} + +void WorldstateFunctions::SetDay(unsigned short pid, int day) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + player->hour = -1; + player->month = -1; + player->day = day; + + mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_TIME)->setPlayer(player); + mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_TIME)->Send(false); +} diff --git a/apps/openmw-mp/Script/Functions/Worldstate.hpp b/apps/openmw-mp/Script/Functions/Worldstate.hpp new file mode 100644 index 000000000..5a1f6ee8a --- /dev/null +++ b/apps/openmw-mp/Script/Functions/Worldstate.hpp @@ -0,0 +1,44 @@ +#ifndef OPENMW_WORLDSTATEAPI_HPP +#define OPENMW_WORLDSTATEAPI_HPP + +#include "../Types.hpp" + +#define WORLDSTATEAPI \ + {"SetHour", WorldstateFunctions::SetHour},\ + {"SetMonth", WorldstateFunctions::SetMonth},\ + {"SetDay", WorldstateFunctions::SetDay} + +class WorldstateFunctions +{ +public: + + /** + * \brief Set the game hour for a player and send a GameTime packet to that player. + * + * \param pid The player ID. + * \param hour The hour. + * \return void + */ + static void SetHour(unsigned short pid, double hour) noexcept; + + /** + * \brief Set the game month for a player and send a GameTime packet to that player. + * + * \param pid The player ID. + * \param month The month. + * \return void + */ + static void SetMonth(unsigned short pid, int month) noexcept; + + /** + * \brief Set the game day for a player and send a GameTime packet to that player. + * + * \param pid The player ID. + * \param day The day. + * \return void + */ + static void SetDay(unsigned short pid, int day) noexcept; + +}; + +#endif //OPENMW_WORLDSTATEAPI_HPP diff --git a/apps/openmw-mp/Script/ScriptFunctions.hpp b/apps/openmw-mp/Script/ScriptFunctions.hpp index 401bfdd1a..f110bd8bb 100644 --- a/apps/openmw-mp/Script/ScriptFunctions.hpp +++ b/apps/openmw-mp/Script/ScriptFunctions.hpp @@ -15,13 +15,14 @@ #include