From cf1a0113a16aa62105d03e1ec00900172fcebdfb Mon Sep 17 00:00:00 2001 From: Koncord Date: Tue, 30 Aug 2016 13:24:31 +0800 Subject: [PATCH] Time API --- apps/openmw-mp/CMakeLists.txt | 3 +- apps/openmw-mp/Script/Functions/World.cpp | 46 +++++++++++++++++++++ apps/openmw-mp/Script/Functions/World.hpp | 22 ++++++++++ apps/openmw-mp/Script/ScriptFunctions.hpp | 2 + apps/openmw/mwmp/Networking.cpp | 14 +++++++ components/CMakeLists.txt | 2 +- components/openmw-mp/Base/BasePlayer.hpp | 3 ++ components/openmw-mp/NetworkMessages.hpp | 3 +- components/openmw-mp/Packets/PacketTime.cpp | 22 ++++++++++ components/openmw-mp/Packets/PacketTime.hpp | 24 +++++++++++ components/openmw-mp/PacketsController.cpp | 3 ++ 11 files changed, 141 insertions(+), 3 deletions(-) create mode 100644 apps/openmw-mp/Script/Functions/World.cpp create mode 100644 apps/openmw-mp/Script/Functions/World.hpp create mode 100644 components/openmw-mp/Packets/PacketTime.cpp create mode 100644 components/openmw-mp/Packets/PacketTime.hpp diff --git a/apps/openmw-mp/CMakeLists.txt b/apps/openmw-mp/CMakeLists.txt index 2d06394e8..c5313be64 100644 --- a/apps/openmw-mp/CMakeLists.txt +++ b/apps/openmw-mp/CMakeLists.txt @@ -51,7 +51,8 @@ set(SERVER Script/Script.cpp Script/ScriptFunction.cpp Script/ScriptFunctions.cpp Script/Functions/Translocations.cpp Script/Functions/Stats.cpp Script/Functions/Items.cpp - Script/Functions/Timer.cpp Script/Functions/Chat.cpp Script/Functions/GUI.cpp Script/Functions/CharClass.cpp Script/Functions/CharClass.hpp + Script/Functions/Timer.cpp Script/Functions/Chat.cpp Script/Functions/GUI.cpp + Script/Functions/CharClass.cpp Script/Functions/CharClass.hpp Script/Functions/World.cpp Script/API/TimerAPI.cpp Script/API/PublicFnAPI.cpp ${PawnScript_Sources} ${LuaScript_Sources} diff --git a/apps/openmw-mp/Script/Functions/World.cpp b/apps/openmw-mp/Script/Functions/World.cpp new file mode 100644 index 000000000..15c22592f --- /dev/null +++ b/apps/openmw-mp/Script/Functions/World.cpp @@ -0,0 +1,46 @@ +// +// Created by koncord on 30.08.16. +// + +#include +#include +#include +#include +#include "World.hpp" + +void WorldFunctions::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().GetController()->GetPacket(ID_GAME_TIME)->Send(player, false); +} + +void WorldFunctions::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().GetController()->GetPacket(ID_GAME_TIME)->Send(player, false); + +} + +void WorldFunctions::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().GetController()->GetPacket(ID_GAME_TIME)->Send(player, false); +} diff --git a/apps/openmw-mp/Script/Functions/World.hpp b/apps/openmw-mp/Script/Functions/World.hpp new file mode 100644 index 000000000..6bffb268c --- /dev/null +++ b/apps/openmw-mp/Script/Functions/World.hpp @@ -0,0 +1,22 @@ +// +// Created by koncord on 30.08.16. +// + +#ifndef OPENMW_WORLD_HPP +#define OPENMW_WORLD_HPP + +#define WORLDFUNCTIONS \ + {"SetHour", WorldFunctions::SetHour},\ + {"SetMonth", WorldFunctions::SetMonth},\ + {"SetDay", WorldFunctions::SetDay} + +class WorldFunctions +{ +public: + static void SetHour(unsigned short pid, double hour) noexcept; + static void SetMonth(unsigned short pid, int month) noexcept; + static void SetDay(unsigned short pid, int day) noexcept; +}; + + +#endif //OPENMW_WORLD_HPP diff --git a/apps/openmw-mp/Script/ScriptFunctions.hpp b/apps/openmw-mp/Script/ScriptFunctions.hpp index d120108ab..8d59b7d57 100644 --- a/apps/openmw-mp/Script/ScriptFunctions.hpp +++ b/apps/openmw-mp/Script/ScriptFunctions.hpp @@ -10,6 +10,7 @@ #include