]> git.localhorst.tv Git - blank.git/blobdiff - src/net/Packet.hpp
defined and implemented join and part packets
[blank.git] / src / net / Packet.hpp
index b7c8a5fa5aeb90d3b018cd2d791a771ff687f041..0d99fee2992c74c61a1979dfe251813c69e607ca 100644 (file)
@@ -2,11 +2,14 @@
 #define BLANK_NET_PACKET_HPP_
 
 #include <cstdint>
+#include <ostream>
 #include <string>
 
 
 namespace blank {
 
+class Entity;
+
 struct Packet {
 
        static constexpr std::uint32_t TAG = 0xFB1AB1AF;
@@ -14,8 +17,12 @@ struct Packet {
        enum Type {
                PING = 0,
                LOGIN = 1,
+               JOIN = 2,
+               PART = 3,
        };
 
+       static const char *Type2String(Type) noexcept;
+
        struct TControl {
                std::uint16_t seq;
                std::uint16_t ack;
@@ -31,13 +38,21 @@ struct Packet {
        std::uint8_t payload[500 - sizeof(Header)];
 
 
+       Type GetType() const noexcept { return Type(header.type); }
+
        void Tag() noexcept;
 
-       std::size_t Ping() noexcept;
-       std::size_t Login(const std::string &name) noexcept;
+       std::size_t MakePing() noexcept;
+       std::size_t MakeLogin(const std::string &name) noexcept;
+       std::size_t MakeJoin(const Entity &player, const std::string &world_name) noexcept;
+       std::size_t MakePart() noexcept;
 
 };
 
+inline std::ostream &operator <<(std::ostream &out, Packet::Type t) {
+       return out << Packet::Type2String(t);
+}
+
 }
 
 #endif