Skip to content

Class endstone::PacketReceiveEvent

ClassList > endstone > PacketReceiveEvent

Called when the server receives a packet from a connected client.

  • #include <endstone/event/server/packet_receive_event.h>

Inherits the following classes: endstone::Cancellable

Public Functions

Type Name
ENDSTONE_EVENT (PacketReceiveEvent)
PacketReceiveEvent (Player * player, const int packet_id, std::string_view payload, SocketAddress address, const int sub_client_id)
SocketAddress getAddress () const
Gets the network address of the client that sent this packet.
int getPacketId () const
Gets the ID of the packet.
std::string_view getPayload () const
Gets the raw packet data excluding the header.
Player * getPlayer () const
Returns the player involved in this event.
int getSubClientId () const
Gets the SubClient ID.
void setPayload (std::string_view payload)
Sets the raw packet data excluding the header.

Public Functions inherited from endstone::Cancellable

See endstone::Cancellable

Type Name
virtual void cancel ()
Cancel this event.
virtual bool isCancelled () override const
Gets the cancellation state of this event.
virtual void setCancelled (bool cancel) override
Sets the cancellation state of this event.

Public Functions inherited from endstone::ICancellable

See endstone::ICancellable

Type Name
virtual void cancel () = 0
Cancels this event.
virtual bool isCancelled () const = 0
Gets the cancellation state of this event.
virtual void setCancelled (bool cancel) = 0
Sets the cancellation state of this event.
virtual ~ICancellable () = default

Public Functions Documentation

function ENDSTONE_EVENT

endstone::PacketReceiveEvent::ENDSTONE_EVENT (
    PacketReceiveEvent
) 

function PacketReceiveEvent

inline endstone::PacketReceiveEvent::PacketReceiveEvent (
    Player * player,
    const  int packet_id,
    std::string_view payload,
    SocketAddress address,
    const  int sub_client_id
) 

function getAddress

Gets the network address of the client that sent this packet.

inline SocketAddress endstone::PacketReceiveEvent::getAddress () const

Returns:

The SocketAddress of the source client.


function getPacketId

Gets the ID of the packet.

inline int endstone::PacketReceiveEvent::getPacketId () const

Returns:

The packet ID.


function getPayload

Gets the raw packet data excluding the header.

inline std::string_view endstone::PacketReceiveEvent::getPayload () const

Returns:

The packet payload data.


function getPlayer

Returns the player involved in this event.

inline Player * endstone::PacketReceiveEvent::getPlayer () const

Note:

This may return nullptr if the packet is sent before the player completes the login process.

Returns:

Player who is involved in this event


function getSubClientId

Gets the SubClient ID.

inline int endstone::PacketReceiveEvent::getSubClientId () const

Note:

Range is 0 to 3 (0 = primary client; 1-3 = split-screen clients).

Returns:

The SubClient ID.


function setPayload

Sets the raw packet data excluding the header.

inline void endstone::PacketReceiveEvent::setPayload (
    std::string_view payload
) 

Parameters:

  • payload The new packet payload data.


The documentation for this class was generated from the following file include/endstone/event/server/packet_receive_event.h