diff options
| author | Nicolas James <Eele1Ephe7uZahRie@tutanota.com> | 2025-02-12 18:05:18 +1100 |
|---|---|---|
| committer | Nicolas James <Eele1Ephe7uZahRie@tutanota.com> | 2025-02-12 18:05:18 +1100 |
| commit | 1cc08c51eb4b0f95c30c0a98ad1fc5ad3459b2df (patch) | |
| tree | 222dfcd07a1e40716127a347bbfd7119ce3d0984 /src/server/client.hh | |
initial commit
Diffstat (limited to 'src/server/client.hh')
| -rw-r--r-- | src/server/client.hh | 67 |
1 files changed, 67 insertions, 0 deletions
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 <deque> +#include <memory> +#include <optional> +#include <string> +#include <unordered_map> +#include <unordered_set> + +#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<std::string> 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<std::shared_ptr<player_info>> 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<shared::math::coords, + decltype(&shared::world::chunk::hash), + decltype(&shared::world::chunk::equal)> + 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 |
