From 0baada0aa2e82bae891bb781a4924ec8d7fa01bc Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sun, 26 Feb 2017 23:00:51 +0200 Subject: [PATCH] [Server] Add GetLastPlayerId() script function in Miscellaneous category --- apps/openmw-mp/CMakeLists.txt | 2 +- apps/openmw-mp/Player.cpp | 5 +++++ apps/openmw-mp/Player.hpp | 1 + .../openmw-mp/Script/Functions/Miscellaneous.cpp | 11 +++++++++++ .../openmw-mp/Script/Functions/Miscellaneous.hpp | 16 ++++++++++++++++ apps/openmw-mp/Script/ScriptFunctions.hpp | 2 ++ 6 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 apps/openmw-mp/Script/Functions/Miscellaneous.cpp create mode 100644 apps/openmw-mp/Script/Functions/Miscellaneous.hpp diff --git a/apps/openmw-mp/CMakeLists.txt b/apps/openmw-mp/CMakeLists.txt index abb770efb..0651ba6e6 100644 --- a/apps/openmw-mp/CMakeLists.txt +++ b/apps/openmw-mp/CMakeLists.txt @@ -77,7 +77,7 @@ set(SERVER Script/Functions/CharClass.cpp Script/Functions/Chat.cpp Script/Functions/GUI.cpp Script/Functions/Items.cpp Script/Functions/Quests.cpp Script/Functions/Stats.cpp Script/Functions/Spells.cpp Script/Functions/Timer.cpp Script/Functions/Positions.cpp - Script/Functions/Cells.cpp Script/Functions/World.cpp + Script/Functions/Cells.cpp Script/Functions/World.cpp Script/Functions/Miscellaneous.cpp Script/API/TimerAPI.cpp Script/API/PublicFnAPI.cpp ${PawnScript_Sources} diff --git a/apps/openmw-mp/Player.cpp b/apps/openmw-mp/Player.cpp index db3e7b760..edf974873 100644 --- a/apps/openmw-mp/Player.cpp +++ b/apps/openmw-mp/Player.cpp @@ -64,6 +64,11 @@ TPlayers *Players::getPlayers() return &players; } +unsigned short Players::getLastPlayerId() +{ + return slots.rbegin()->first; +} + Player::Player(RakNet::RakNetGUID guid) : BasePlayer(guid) { handshakeState = false; diff --git a/apps/openmw-mp/Player.hpp b/apps/openmw-mp/Player.hpp index cf83b9688..208abc99b 100644 --- a/apps/openmw-mp/Player.hpp +++ b/apps/openmw-mp/Player.hpp @@ -32,6 +32,7 @@ public: static Player *getPlayer(RakNet::RakNetGUID guid); static Player *getPlayer(unsigned short id); static TPlayers *getPlayers(); + static unsigned short getLastPlayerId(); private: static TPlayers players; diff --git a/apps/openmw-mp/Script/Functions/Miscellaneous.cpp b/apps/openmw-mp/Script/Functions/Miscellaneous.cpp new file mode 100644 index 000000000..7dfcaf48d --- /dev/null +++ b/apps/openmw-mp/Script/Functions/Miscellaneous.cpp @@ -0,0 +1,11 @@ +#include "Miscellaneous.hpp" +#include +#include + +#include +using namespace std; + +unsigned int MiscellaneousFunctions::GetLastPlayerId() noexcept +{ + return Players::getLastPlayerId(); +} diff --git a/apps/openmw-mp/Script/Functions/Miscellaneous.hpp b/apps/openmw-mp/Script/Functions/Miscellaneous.hpp new file mode 100644 index 000000000..c9509713c --- /dev/null +++ b/apps/openmw-mp/Script/Functions/Miscellaneous.hpp @@ -0,0 +1,16 @@ +#ifndef OPENMW_MISCELLANEOUSAPI_HPP +#define OPENMW_MISCELLANEOUSAPI_HPP + +#include "../Types.hpp" + +#define MISCELLANEOUSAPI \ + {"GetLastPlayerId", MiscellaneousFunctions::GetLastPlayerId} + + +class MiscellaneousFunctions +{ +public: + static unsigned int GetLastPlayerId() noexcept; +}; + +#endif //OPENMW_MISCELLANEOUSAPI_HPP diff --git a/apps/openmw-mp/Script/ScriptFunctions.hpp b/apps/openmw-mp/Script/ScriptFunctions.hpp index 9d8817597..684612cda 100644 --- a/apps/openmw-mp/Script/ScriptFunctions.hpp +++ b/apps/openmw-mp/Script/ScriptFunctions.hpp @@ -14,6 +14,7 @@ #include