X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fserver%2FClientConnection.hpp;h=3ab0453e87a1d46e5c18262ad974bd3e01287f84;hb=3185bad87c06739e4ec19b456c7158437ba9621f;hp=4927d1ce831fb9ab26c15cbeb68db9826b3c497c;hpb=c1da86ebab41895bf49ed747c75ecf722e8c5586;p=blank.git diff --git a/src/server/ClientConnection.hpp b/src/server/ClientConnection.hpp index 4927d1c..3ab0453 100644 --- a/src/server/ClientConnection.hpp +++ b/src/server/ClientConnection.hpp @@ -2,6 +2,7 @@ #define BLANK_SERVER_CLIENTCONNECTION_HPP_ #include "ChunkTransmitter.hpp" +#include "NetworkCLIFeedback.hpp" #include "Server.hpp" #include "../app/IntervalTimer.hpp" #include "../ui/DirectInput.hpp" @@ -10,6 +11,7 @@ #include "../world/EntityState.hpp" #include "../world/Player.hpp" +#include #include #include #include @@ -19,7 +21,7 @@ namespace blank { -class CompositeModel; +class Model; namespace server { @@ -39,6 +41,8 @@ public: Connection &GetConnection() noexcept { return conn; } bool Disconnected() const noexcept { return conn.Closed(); } + Server &GetServer() noexcept { return server; } + /// prepare a packet of given type template Type Prepare() const noexcept { @@ -46,7 +50,7 @@ public: } /// send the previously prepared packet std::uint16_t Send(); - /// send the previously prepared packet of non-default length + /// send the previously prepared packet of given payload length std::uint16_t Send(std::size_t len); void AttachPlayer(Player &); @@ -57,9 +61,13 @@ public: ChunkIndex &PlayerChunks() noexcept { return input->GetPlayer().GetChunks(); } const ChunkIndex &PlayerChunks() const noexcept { return input->GetPlayer().GetChunks(); } - void SetPlayerModel(const CompositeModel &) noexcept; + void SetPlayerModel(const Model &) noexcept; bool HasPlayerModel() const noexcept; - const CompositeModel &GetPlayerModel() const noexcept; + const Model &GetPlayerModel() const noexcept; + + bool ChunkInRange(const glm::ivec3 &) const noexcept; + + std::uint16_t SendMessage(std::uint8_t type, std::uint32_t from, const std::string &msg); private: struct SpawnStatus { @@ -81,12 +89,17 @@ private: void On(const Packet::Login &) override; void On(const Packet::Part &) override; void On(const Packet::PlayerUpdate &) override; + void On(const Packet::ChunkBegin &) override; + void On(const Packet::Message &) override; + void CheckEntities(); bool CanSpawn(const Entity &) const noexcept; bool CanDespawn(const Entity &) const noexcept; void SendSpawn(SpawnStatus &); void SendDespawn(SpawnStatus &); + /// true if entity updates are pushed to the client this frame + bool SendingUpdates() const noexcept; void QueueUpdate(SpawnStatus &); void SendUpdates(); @@ -98,20 +111,23 @@ private: Server &server; Connection conn; std::unique_ptr input; - const CompositeModel *player_model; + std::unique_ptr cli_ctx; + const Model *player_model; std::list spawns; unsigned int confirm_wait; std::vector entity_updates; + unsigned int entity_updates_skipped; EntityState player_update_state; std::uint16_t player_update_pack; - IntervalTimer player_update_timer; + CoarseTimer player_update_timer; std::uint8_t old_actions; ChunkTransmitter transmitter; std::deque chunk_queue; glm::ivec3 old_base; + unsigned int chunk_blocks_skipped; };