X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fnet%2FPacket.hpp;h=0d99fee2992c74c61a1979dfe251813c69e607ca;hb=da5073a7fdb1ca066e778a02db33d5d15073aea0;hp=7b482e58726ca8215df125a121ff968db696927d;hpb=9ebe2c320fd9f94266ab93fa2f9d9908a0a284d3;p=blank.git diff --git a/src/net/Packet.hpp b/src/net/Packet.hpp index 7b482e5..0d99fee 100644 --- a/src/net/Packet.hpp +++ b/src/net/Packet.hpp @@ -2,32 +2,57 @@ #define BLANK_NET_PACKET_HPP_ #include +#include +#include namespace blank { +class Entity; + struct Packet { static constexpr std::uint32_t TAG = 0xFB1AB1AF; enum Type { - PING, + PING = 0, + LOGIN = 1, + JOIN = 2, + PART = 3, + }; + + static const char *Type2String(Type) noexcept; + + struct TControl { + std::uint16_t seq; + std::uint16_t ack; + std::uint32_t hist; }; struct Header { std::uint32_t tag; + TControl ctrl; std::uint8_t type; } header; 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 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