2019-01-23 00:04:03 +01:00
|
|
|
/*
|
|
|
|
* =====================================================================================
|
|
|
|
*
|
2020-02-08 18:34:26 +09:00
|
|
|
* OpenMiner
|
2020-02-25 01:42:10 +09:00
|
|
|
*
|
2020-02-08 18:34:26 +09:00
|
|
|
* Copyright (C) 2018-2020 Unarelith, Quentin Bazin <openminer@unarelith.net>
|
2020-02-25 01:42:10 +09:00
|
|
|
* Copyright (C) 2019-2020 the OpenMiner contributors (see CONTRIBUTORS.md)
|
|
|
|
*
|
|
|
|
* This file is part of OpenMiner.
|
2019-01-23 00:04:03 +01:00
|
|
|
*
|
2020-02-25 01:42:10 +09:00
|
|
|
* OpenMiner is free software; you can redistribute it and/or
|
2020-02-08 18:34:26 +09:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2019-01-23 00:04:03 +01:00
|
|
|
*
|
2020-02-25 01:42:10 +09:00
|
|
|
* OpenMiner is distributed in the hope that it will be useful,
|
2020-02-08 18:34:26 +09:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2019-01-23 00:04:03 +01:00
|
|
|
*
|
2020-02-08 18:34:26 +09:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2020-02-25 01:42:10 +09:00
|
|
|
* along with OpenMiner; if not, write to the Free Software Foundation, Inc.,
|
2020-02-08 18:34:26 +09:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2019-01-23 00:04:03 +01:00
|
|
|
*
|
|
|
|
* =====================================================================================
|
|
|
|
*/
|
|
|
|
#ifndef SERVERPLAYER_HPP_
|
|
|
|
#define SERVERPLAYER_HPP_
|
|
|
|
|
2020-12-29 05:38:06 +01:00
|
|
|
#include <unordered_set>
|
|
|
|
|
2020-06-02 05:51:10 +02:00
|
|
|
#include <gk/core/Debug.hpp>
|
|
|
|
|
2020-03-04 14:38:31 +01:00
|
|
|
#include "ClientInfo.hpp"
|
2019-01-23 00:04:03 +01:00
|
|
|
#include "Player.hpp"
|
|
|
|
|
|
|
|
class ServerPlayer : public Player {
|
|
|
|
public:
|
2020-06-26 04:52:04 +02:00
|
|
|
ServerPlayer(const std::string &name, bool isNewPlayer) {
|
|
|
|
m_name = name;
|
|
|
|
m_isNewPlayer = isNewPlayer;
|
|
|
|
}
|
2020-01-19 18:22:50 +09:00
|
|
|
|
2020-06-26 04:52:04 +02:00
|
|
|
const ClientInfo *client() const { return m_client; }
|
|
|
|
void setClient(ClientInfo *client) { m_client = client; }
|
2020-01-19 18:22:50 +09:00
|
|
|
|
2020-06-26 04:52:04 +02:00
|
|
|
bool isOnline() const { return m_client != nullptr; }
|
|
|
|
bool isNewPlayer() const { return m_isNewPlayer; }
|
|
|
|
void setNewPlayer(bool isNewPlayer) { m_isNewPlayer = isNewPlayer; }
|
2020-06-23 18:40:16 +02:00
|
|
|
|
2020-12-29 05:38:06 +01:00
|
|
|
bool isReady() const { return m_isReady; }
|
|
|
|
void setReady(bool isReady) { m_isReady = isReady; }
|
|
|
|
|
2021-05-17 02:52:49 +02:00
|
|
|
bool isChunkLoaded(const gk::Vector3i &chunk) const { return m_loadedChunks.find(chunk) != m_loadedChunks.end(); }
|
2020-12-29 05:38:06 +01:00
|
|
|
void addLoadedChunk(const gk::Vector3i &chunk) { m_loadedChunks.emplace(chunk); }
|
|
|
|
void removeLoadedChunk(const gk::Vector3i &chunk) { m_loadedChunks.erase(chunk); }
|
2021-01-03 19:10:29 +01:00
|
|
|
void clearLoadedChunks() { m_loadedChunks.clear(); }
|
2021-05-16 17:38:47 +02:00
|
|
|
const std::unordered_set<gk::Vector3i> &loadedChunks() const { return m_loadedChunks; }
|
2020-12-29 05:38:06 +01:00
|
|
|
|
2020-05-22 04:54:34 +02:00
|
|
|
static void initUsertype(sol::state &lua);
|
|
|
|
|
2020-12-29 05:38:06 +01:00
|
|
|
public:
|
2020-12-29 19:15:30 +01:00
|
|
|
std::unordered_set<gk::Vector3i> sentChunks; // Cleared every tick
|
|
|
|
|
2020-01-19 18:22:50 +09:00
|
|
|
private:
|
2020-06-26 04:52:04 +02:00
|
|
|
ClientInfo *m_client = nullptr;
|
2020-06-02 05:51:10 +02:00
|
|
|
|
2020-06-26 04:52:04 +02:00
|
|
|
bool m_isNewPlayer = false;
|
2020-12-29 05:38:06 +01:00
|
|
|
bool m_isReady = false; // Is player ready to receive chunks?
|
|
|
|
|
|
|
|
std::unordered_set<gk::Vector3i> m_loadedChunks;
|
2019-01-23 00:04:03 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SERVERPLAYER_HPP_
|