#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