diff --git a/docs/lua-api-cpp.md b/docs/lua-api-cpp.md index b1fe5d35..66efc818 100644 --- a/docs/lua-api-cpp.md +++ b/docs/lua-api-cpp.md @@ -123,6 +123,7 @@ - `const ClientInfo &client()` - `ItemStack held_item_stack()` +- `bool is_online()` ## ServerWorld diff --git a/source/server/core/PlayerList.hpp b/source/server/core/PlayerList.hpp index b2c8ac85..2dd9c9e2 100644 --- a/source/server/core/PlayerList.hpp +++ b/source/server/core/PlayerList.hpp @@ -32,9 +32,9 @@ #include "ServerPlayer.hpp" class PlayerList { - using Container = std::unordered_map; - using Iterator = Container::iterator; - using ConstIterator = Container::const_iterator; + using PlayerMap = std::unordered_map; + using Iterator = PlayerMap::iterator; + using ConstIterator = PlayerMap::const_iterator; public: ServerPlayer &addPlayer(ClientInfo &client); @@ -50,7 +50,7 @@ class PlayerList { ConstIterator end() const { return m_players.end(); } private: - Container m_players; + PlayerMap m_players; }; #endif // PLAYERLIST_HPP_ diff --git a/source/server/core/ServerApplication.cpp b/source/server/core/ServerApplication.cpp index c22a47b1..5782ce6e 100644 --- a/source/server/core/ServerApplication.cpp +++ b/source/server/core/ServerApplication.cpp @@ -115,12 +115,12 @@ bool ServerApplication::init() { gkInfo() << ("Server is running on localhost:" + std::to_string(m_server.port())).c_str(); - if (m_eventHandler) - m_eventHandler->emplaceEvent(true, m_server.port()); - if (!m_worldName.empty()) m_worldController.load(m_worldName); + if (m_eventHandler) + m_eventHandler->emplaceEvent(true, m_server.port()); + return true; } diff --git a/source/server/world/ServerPlayer.cpp b/source/server/world/ServerPlayer.cpp index 9ac371de..9f8f4cab 100644 --- a/source/server/world/ServerPlayer.cpp +++ b/source/server/world/ServerPlayer.cpp @@ -35,7 +35,8 @@ void ServerPlayer::initUsertype(sol::state &lua) { lua.new_usertype("ServerPlayer", sol::base_classes, sol::bases(), "client", &ServerPlayer::client, - "held_item_stack", &ServerPlayer::heldItemStack + "held_item_stack", &ServerPlayer::heldItemStack, + "is_online", &ServerPlayer::isOnline ); } diff --git a/source/server/world/ServerPlayer.hpp b/source/server/world/ServerPlayer.hpp index bec7821e..8971003d 100644 --- a/source/server/world/ServerPlayer.hpp +++ b/source/server/world/ServerPlayer.hpp @@ -41,12 +41,17 @@ class ServerPlayer : public Player { const ItemStack &heldItemStack() { return m_inventory.getStack(m_heldItemSlot, 0); } void setHeldItemSlot(u8 heldItemSlot) { m_heldItemSlot = heldItemSlot; } + bool isOnline() const { return m_isOnline; } + void setOnline(bool isOnline) { m_isOnline = isOnline; } + static void initUsertype(sol::state &lua); private: ClientInfo &m_client; u8 m_heldItemSlot = 0; + + bool m_isOnline = false; }; #endif // SERVERPLAYER_HPP_