From 1cc08c51eb4b0f95c30c0a98ad1fc5ad3459b2df Mon Sep 17 00:00:00 2001 From: Nicolas James Date: Wed, 12 Feb 2025 18:05:18 +1100 Subject: initial commit --- src/server/client.hh | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/server/client.hh (limited to 'src/server/client.hh') diff --git a/src/server/client.hh b/src/server/client.hh new file mode 100644 index 0000000..5866035 --- /dev/null +++ b/src/server/client.hh @@ -0,0 +1,67 @@ +#ifndef SERVER_CLIENT_HH_ +#define SERVER_CLIENT_HH_ + +#include +#include +#include +#include +#include +#include + +#include "server/chunk_data.hh" +#include "server/world.hh" +#include "shared/net/connection.hh" +#include "shared/player.hh" +#include "shared/world.hh" + +namespace server { + +// Client represents the entire state of a player. +class client { +public: + shared::net::connection connection; + shared::player::index_t index; + + // If this is set a disconnect packet should be set + std::optional disconnect_reason; + + struct player_info { + std::string username; + std::string password; + shared::player player; + }; + // If this is nullopt, we haven't got our init packet yet which contained + // their user + pass. + std::optional> player_info; + + // flag for disconnecting, the client must stay while the server is writing + // its contents to a db + bool disconnecting = false; + + // Chunks for which the player is associated with. + std::unordered_set + chunks{4096, shared::world::chunk::hash, shared::world::chunk::equal}; + +public: + client(shared::net::connection&& con, const shared::player::index_t& index) + : connection(std::move(con)), index(index) {} + + bool has_initialised() const noexcept { + return this->player_info.has_value(); + } + shared::player& get_player() noexcept { + return (*this->player_info)->player; + } + const std::string& get_username() const noexcept { + return (*this->player_info)->username; + } + const std::string& get_password() const noexcept { + return (*this->player_info)->password; + } +}; + +} // namespace server + +#endif -- cgit v1.2.3