]> git.localhorst.tv Git - blank.git/blobdiff - src/server/ClientConnection.hpp
make gcc nag more
[blank.git] / src / server / ClientConnection.hpp
index c5efb51bbd412d7d9aeffbe7e5b29803b83f4a2d..3ab0453e87a1d46e5c18262ad974bd3e01287f84 100644 (file)
@@ -2,19 +2,27 @@
 #define BLANK_SERVER_CLIENTCONNECTION_HPP_
 
 #include "ChunkTransmitter.hpp"
+#include "NetworkCLIFeedback.hpp"
 #include "Server.hpp"
 #include "../app/IntervalTimer.hpp"
+#include "../ui/DirectInput.hpp"
 #include "../net/Connection.hpp"
 #include "../net/ConnectionHandler.hpp"
 #include "../world/EntityState.hpp"
 #include "../world/Player.hpp"
 
+#include <cstdint>
 #include <deque>
 #include <list>
+#include <memory>
 #include <SDL_net.h>
+#include <vector>
 
 
 namespace blank {
+
+class Model;
+
 namespace server {
 
 class Server;
@@ -33,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<class Type>
        Type Prepare() const noexcept {
@@ -40,16 +50,24 @@ 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(const Player &);
+       void AttachPlayer(Player &);
        void DetachPlayer();
-       bool HasPlayer() const noexcept { return player.entity; }
-       Entity &PlayerEntity() noexcept { return *player.entity; }
-       const Entity &PlayerEntity() const noexcept { return *player.entity; }
-       ChunkIndex &PlayerChunks() noexcept { return *player.chunks; }
-       const ChunkIndex &PlayerChunks() const noexcept { return *player.chunks; }
+       bool HasPlayer() const noexcept { return !!input; }
+       Entity &PlayerEntity() noexcept { return input->GetPlayer().GetEntity(); }
+       const Entity &PlayerEntity() const noexcept { return input->GetPlayer().GetEntity(); }
+       ChunkIndex &PlayerChunks() noexcept { return input->GetPlayer().GetChunks(); }
+       const ChunkIndex &PlayerChunks() const noexcept { return input->GetPlayer().GetChunks(); }
+
+       void SetPlayerModel(const Model &) noexcept;
+       bool HasPlayerModel() 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 {
@@ -71,13 +89,19 @@ 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 &);
-       void SendUpdate(SpawnStatus &);
+       /// true if entity updates are pushed to the client this frame
+       bool SendingUpdates() const noexcept;
+       void QueueUpdate(SpawnStatus &);
+       void SendUpdates();
 
        void CheckPlayerFix();
 
@@ -86,17 +110,24 @@ private:
 private:
        Server &server;
        Connection conn;
-       Player player;
+       std::unique_ptr<DirectInput> input;
+       std::unique_ptr<NetworkCLIFeedback> cli_ctx;
+       const Model *player_model;
        std::list<SpawnStatus> spawns;
        unsigned int confirm_wait;
 
+       std::vector<SpawnStatus *> 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<glm::ivec3> chunk_queue;
        glm::ivec3 old_base;
+       unsigned int chunk_blocks_skipped;
 
 };