All checks were successful
Linux arm64 / Build (push) Successful in 4m55s
améliorer l'interface, déplacement de certains boutons etc. Co-authored-by: Persson-dev <sim16.prib@gmail.com> Co-authored-by: Morph01 <145839520+Morph01@users.noreply.github.com> Co-authored-by: Simon Pribylski <sim16.prib@gmail.com> Reviewed-on: #15 Co-authored-by: Morph01 <thibaut6969delastreet@gmail.com> Co-committed-by: Morph01 <thibaut6969delastreet@gmail.com>
101 lines
2.8 KiB
C++
101 lines
2.8 KiB
C++
#pragma once
|
|
|
|
/**
|
|
* \file Protocol.h
|
|
* \brief File describing protocol
|
|
*/
|
|
|
|
#include "blitz/common/DataBuffer.h"
|
|
|
|
namespace blitz {
|
|
namespace protocol {
|
|
|
|
class PacketHandler;
|
|
|
|
/**
|
|
* \enum PacketType
|
|
* \brief Map the packets name to their ID
|
|
*/
|
|
enum class PacketType : std::uint8_t {
|
|
// client --> server
|
|
|
|
PlayerLogin = 0, /**< Corresponds to PlayerLoginPacket */
|
|
UpdateHealth, /**< Corresponds to UpdateHealthPacket */
|
|
|
|
// client <-- server
|
|
|
|
ConnexionInfo, /**< Corresponds to ConnexionInfoPacket */
|
|
PlayerJoin, /**< Corresponds to PlayerJoinPacket */
|
|
PlayerLeave, /**< Corresponds to PlayerLeavePacket */
|
|
PlayerList, /**< Corresponds to PlayerListPacket */
|
|
PlayerStats, /**< Corresponds to PlayerStatsPacket */
|
|
ServerTps, /**< Corresponds to ServerTpsPacket */
|
|
|
|
// client <--> server
|
|
|
|
KeepAlive, /**< Corresponds to KeepAlivePacket */
|
|
Disconnect, /**< Corresponds to DisconnectPacket */
|
|
Chat, /**< Corresponds to ChatPacket */
|
|
PlayerPositionAndRotation, /**< Corresponds to PlayerPositionAndRotationPacket */
|
|
PlayerShoot, /**< Corresponds to PlayerShootPacket */
|
|
|
|
PACKET_COUNT
|
|
};
|
|
|
|
/**
|
|
* \class Packet
|
|
* \brief Represents a network packet <br/>
|
|
* %Packet data structure :
|
|
*| Field Name | Field Type | Notes |
|
|
*|---------------------|---------------|-------------------------------|
|
|
*| Length | Long | Length of whole Packet |
|
|
*| Uncompressed Length | VarInt | Length of Packet ID + Data |
|
|
*| Packet ID | Byte | Represents the #PacketType |
|
|
*| Data | Byte Array | Depends on the packet ID |
|
|
*/
|
|
class Packet {
|
|
public:
|
|
Packet() {}
|
|
virtual ~Packet() {}
|
|
|
|
/**
|
|
* \brief Serialize the Packet into a DataBuffer to be sent over the network
|
|
* \param packetID Set to false if you don't want to write the Packet ID for some reason
|
|
* \returns A DataBuffer filled with the serialized Packet
|
|
*/
|
|
virtual DataBuffer Serialize(bool packetID = true) const = 0;
|
|
|
|
/**
|
|
* \brief Deserialize the DataBuffer into a Packet to be read by the client/server
|
|
* \param data The DataBuffer containing the data from the network
|
|
*/
|
|
virtual void Deserialize(DataBuffer& data) = 0;
|
|
|
|
/**
|
|
* \brief Dispatches the Packet
|
|
* \param handler The class to dispatch the Packet to
|
|
*/
|
|
virtual void Dispatch(PacketHandler* handler) const = 0;
|
|
|
|
/**
|
|
* \brief Writes the Packet ID into a buffer
|
|
* \param data The DataBuffer to write to
|
|
* \param packetID If set to false, this function does nothing
|
|
*/
|
|
void WritePacketID(DataBuffer& data, bool packetID) const;
|
|
|
|
/**
|
|
* \returns The type of the Packet
|
|
*/
|
|
virtual PacketType GetType() const = 0;
|
|
|
|
/**
|
|
* \returns The Packet ID corresponding to the PacketType of this Packet
|
|
*/
|
|
std::uint8_t GetID() const {
|
|
return static_cast<std::uint8_t>(GetType());
|
|
}
|
|
};
|
|
|
|
} // namespace protocol
|
|
} // namespace blitz
|