Luanti 5.11.0-dev
 
Loading...
Searching...
No Matches
NetworkPacket Class Reference

#include <networkpacket.h>

+ Collaboration diagram for NetworkPacket:

Public Member Functions

 NetworkPacket (u16 command, u32 preallocate, session_t peer_id)
 
 NetworkPacket (u16 command, u32 preallocate)
 
 NetworkPacket ()=default
 
 ~NetworkPacket ()=default
 
void putRawPacket (const u8 *data, u32 datasize, session_t peer_id)
 
void clear ()
 
u32 getSize () const
 
session_t getPeerId () const
 
u16 getCommand () const
 
u32 getRemainingBytes () const
 
const char * getRemainingString ()
 
const char * getString (u32 from_offset) const
 
void putRawString (const char *src, u32 len)
 
void putRawString (std::string_view src)
 
NetworkPacketoperator>> (std::string &dst)
 
NetworkPacketoperator<< (std::string_view src)
 
void putLongString (std::string_view src)
 
NetworkPacketoperator>> (std::wstring &dst)
 
NetworkPacketoperator<< (std::wstring_view src)
 
std::string readLongString ()
 
NetworkPacketoperator>> (char &dst)
 
NetworkPacketoperator<< (char src)
 
NetworkPacketoperator>> (bool &dst)
 
NetworkPacketoperator<< (bool src)
 
u8 getU8 (u32 offset)
 
NetworkPacketoperator>> (u8 &dst)
 
NetworkPacketoperator<< (u8 src)
 
u8 * getU8Ptr (u32 offset)
 
u16 getU16 (u32 from_offset)
 
NetworkPacketoperator>> (u16 &dst)
 
NetworkPacketoperator<< (u16 src)
 
NetworkPacketoperator>> (u32 &dst)
 
NetworkPacketoperator<< (u32 src)
 
NetworkPacketoperator>> (u64 &dst)
 
NetworkPacketoperator<< (u64 src)
 
NetworkPacketoperator>> (float &dst)
 
NetworkPacketoperator<< (float src)
 
NetworkPacketoperator>> (v2f &dst)
 
NetworkPacketoperator<< (v2f src)
 
NetworkPacketoperator>> (v3f &dst)
 
NetworkPacketoperator<< (v3f src)
 
NetworkPacketoperator>> (s16 &dst)
 
NetworkPacketoperator<< (s16 src)
 
NetworkPacketoperator>> (s32 &dst)
 
NetworkPacketoperator<< (s32 src)
 
NetworkPacketoperator>> (v2s32 &dst)
 
NetworkPacketoperator<< (v2s32 src)
 
NetworkPacketoperator>> (v3s16 &dst)
 
NetworkPacketoperator<< (v3s16 src)
 
NetworkPacketoperator>> (v3s32 &dst)
 
NetworkPacketoperator<< (v3s32 src)
 
NetworkPacketoperator>> (video::SColor &dst)
 
NetworkPacketoperator<< (video::SColor src)
 
Buffer< u8 > oldForgePacket ()
 

Private Member Functions

void checkReadOffset (u32 from_offset, u32 field_size) const
 
void checkDataSize (u32 field_size)
 

Private Attributes

std::vector< u8 > m_data
 
u32 m_datasize = 0
 
u32 m_read_offset = 0
 
u16 m_command = 0
 
session_t m_peer_id = 0
 

Constructor & Destructor Documentation

◆ NetworkPacket() [1/3]

NetworkPacket::NetworkPacket ( u16 command,
u32 preallocate,
session_t peer_id )
inline

References m_data.

◆ NetworkPacket() [2/3]

NetworkPacket::NetworkPacket ( u16 command,
u32 preallocate )
inline

References m_data.

◆ NetworkPacket() [3/3]

NetworkPacket::NetworkPacket ( )
default

◆ ~NetworkPacket()

NetworkPacket::~NetworkPacket ( )
default

Member Function Documentation

◆ checkDataSize()

void NetworkPacket::checkDataSize ( u32 field_size)
inlineprivate

References m_data, m_datasize, and m_read_offset.

Referenced by operator<<(), operator<<(), operator<<(), operator<<(), operator<<(), operator<<(), operator<<(), operator<<(), and putRawString().

+ Here is the caller graph for this function:

◆ checkReadOffset()

void NetworkPacket::checkReadOffset ( u32 from_offset,
u32 field_size ) const
private

References getSize(), and m_datasize.

Referenced by getString(), getU16(), getU8(), getU8Ptr(), operator>>(), operator>>(), operator>>(), operator>>(), operator>>(), operator>>(), operator>>(), operator>>(), operator>>(), operator>>(), operator>>(), operator>>(), operator>>(), operator>>(), operator>>(), operator>>(), operator>>(), and readLongString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clear()

void NetworkPacket::clear ( )

References m_command, m_data, m_datasize, m_peer_id, and m_read_offset.

Referenced by Server::Receive(), and Client::ReceiveAll().

+ Here is the caller graph for this function:

◆ getCommand()

u16 NetworkPacket::getCommand ( ) const
inline

◆ getPeerId()

◆ getRemainingBytes()

u32 NetworkPacket::getRemainingBytes ( ) const
inline

References m_datasize, and m_read_offset.

Referenced by Client::handleCommand_AccessDenied(), Server::handleCommand_ClientReady(), Client::handleCommand_CloudParams(), Client::handleCommand_DetachedInventory(), Client::handleCommand_HudSetSky(), Client::handleCommand_SetLighting(), and Server::process_PlayerPos().

+ Here is the caller graph for this function:

◆ getRemainingString()

const char * NetworkPacket::getRemainingString ( )
inline

References getString(), and m_read_offset.

Referenced by Client::handleCommand_DetachedInventory().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSize()

◆ getString()

const char * NetworkPacket::getString ( u32 from_offset) const

References checkReadOffset(), and m_data.

Referenced by getRemainingString(), Client::handleCommand_ActiveObjectMessages(), Client::handleCommand_AddParticleSpawner(), Client::handleCommand_BlockData(), Client::handleCommand_HudSetSky(), Client::handleCommand_Inventory(), Server::handleCommand_InventoryAction(), and Client::handleCommand_SpawnParticle().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getU16()

u16 NetworkPacket::getU16 ( u32 from_offset)

References checkReadOffset(), m_data, and readU16().

+ Here is the call graph for this function:

◆ getU8()

u8 NetworkPacket::getU8 ( u32 offset)

References checkReadOffset(), m_data, and readU8().

Referenced by Client::handleCommand_AddNode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getU8Ptr()

u8 * NetworkPacket::getU8Ptr ( u32 offset)

References checkReadOffset(), m_data, and m_datasize.

Referenced by Client::handleCommand_AddNode(), and TestConnection::testConnectSendReceive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ oldForgePacket()

Buffer< u8 > NetworkPacket::oldForgePacket ( )

References m_command, m_data, m_datasize, and writeU16().

Referenced by con::ConnectionCommand::send(), TestConnection::testConnectSendReceive(), and TestConnection::testNetworkPacketSerialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator<<() [1/17]

NetworkPacket & NetworkPacket::operator<< ( bool src)

References checkDataSize(), m_data, m_read_offset, and writeU8().

+ Here is the call graph for this function:

◆ operator<<() [2/17]

NetworkPacket & NetworkPacket::operator<< ( char src)

References checkDataSize(), m_data, m_read_offset, and writeU8().

+ Here is the call graph for this function:

◆ operator<<() [3/17]

NetworkPacket & NetworkPacket::operator<< ( float src)

References checkDataSize(), m_data, m_read_offset, and writeF32().

+ Here is the call graph for this function:

◆ operator<<() [4/17]

NetworkPacket & NetworkPacket::operator<< ( s16 src)

◆ operator<<() [5/17]

NetworkPacket & NetworkPacket::operator<< ( s32 src)

◆ operator<<() [6/17]

NetworkPacket & NetworkPacket::operator<< ( std::string_view src)

References putRawString(), and STRING_MAX_LEN.

+ Here is the call graph for this function:

◆ operator<<() [7/17]

NetworkPacket & NetworkPacket::operator<< ( std::wstring_view src)

References m_data, m_read_offset, NEED_SURROGATE_CODING, WIDE_STRING_MAX_LEN, and writeU16().

+ Here is the call graph for this function:

◆ operator<<() [8/17]

NetworkPacket & NetworkPacket::operator<< ( u16 src)

References checkDataSize(), m_data, m_read_offset, and writeU16().

+ Here is the call graph for this function:

◆ operator<<() [9/17]

NetworkPacket & NetworkPacket::operator<< ( u32 src)

References checkDataSize(), m_data, m_read_offset, and writeU32().

+ Here is the call graph for this function:

◆ operator<<() [10/17]

NetworkPacket & NetworkPacket::operator<< ( u64 src)

References checkDataSize(), m_data, m_read_offset, and writeU64().

+ Here is the call graph for this function:

◆ operator<<() [11/17]

NetworkPacket & NetworkPacket::operator<< ( u8 src)

References checkDataSize(), m_data, m_read_offset, and writeU8().

+ Here is the call graph for this function:

◆ operator<<() [12/17]

NetworkPacket & NetworkPacket::operator<< ( v2f src)

◆ operator<<() [13/17]

NetworkPacket & NetworkPacket::operator<< ( v2s32 src)

◆ operator<<() [14/17]

NetworkPacket & NetworkPacket::operator<< ( v3f src)

◆ operator<<() [15/17]

NetworkPacket & NetworkPacket::operator<< ( v3s16 src)

◆ operator<<() [16/17]

NetworkPacket & NetworkPacket::operator<< ( v3s32 src)

◆ operator<<() [17/17]

NetworkPacket & NetworkPacket::operator<< ( video::SColor src)

References checkDataSize(), m_data, m_read_offset, and writeU32().

+ Here is the call graph for this function:

◆ operator>>() [1/17]

NetworkPacket & NetworkPacket::operator>> ( bool & dst)

References checkReadOffset(), m_data, m_read_offset, and readU8().

+ Here is the call graph for this function:

◆ operator>>() [2/17]

NetworkPacket & NetworkPacket::operator>> ( char & dst)

References checkReadOffset(), m_data, m_read_offset, and readU8().

+ Here is the call graph for this function:

◆ operator>>() [3/17]

NetworkPacket & NetworkPacket::operator>> ( float & dst)

References checkReadOffset(), m_data, m_read_offset, and readF32().

+ Here is the call graph for this function:

◆ operator>>() [4/17]

NetworkPacket & NetworkPacket::operator>> ( s16 & dst)

References checkReadOffset(), m_data, m_read_offset, and readS16().

+ Here is the call graph for this function:

◆ operator>>() [5/17]

NetworkPacket & NetworkPacket::operator>> ( s32 & dst)

References checkReadOffset(), m_data, m_read_offset, and readS32().

+ Here is the call graph for this function:

◆ operator>>() [6/17]

NetworkPacket & NetworkPacket::operator>> ( std::string & dst)

References checkReadOffset(), m_data, m_read_offset, and readU16().

+ Here is the call graph for this function:

◆ operator>>() [7/17]

NetworkPacket & NetworkPacket::operator>> ( std::wstring & dst)

References checkReadOffset(), m_data, m_read_offset, NEED_SURROGATE_CODING, and readU16().

+ Here is the call graph for this function:

◆ operator>>() [8/17]

NetworkPacket & NetworkPacket::operator>> ( u16 & dst)

References checkReadOffset(), m_data, m_read_offset, and readU16().

+ Here is the call graph for this function:

◆ operator>>() [9/17]

NetworkPacket & NetworkPacket::operator>> ( u32 & dst)

References checkReadOffset(), m_data, m_read_offset, and readU32().

+ Here is the call graph for this function:

◆ operator>>() [10/17]

NetworkPacket & NetworkPacket::operator>> ( u64 & dst)

References checkReadOffset(), m_data, m_read_offset, and readU64().

+ Here is the call graph for this function:

◆ operator>>() [11/17]

NetworkPacket & NetworkPacket::operator>> ( u8 & dst)

References checkReadOffset(), m_data, m_read_offset, and readU8().

+ Here is the call graph for this function:

◆ operator>>() [12/17]

NetworkPacket & NetworkPacket::operator>> ( v2f & dst)

References checkReadOffset(), m_data, m_read_offset, and readV2F32().

+ Here is the call graph for this function:

◆ operator>>() [13/17]

NetworkPacket & NetworkPacket::operator>> ( v2s32 & dst)

References checkReadOffset(), m_data, m_read_offset, and readV2S32().

+ Here is the call graph for this function:

◆ operator>>() [14/17]

NetworkPacket & NetworkPacket::operator>> ( v3f & dst)

References checkReadOffset(), m_data, m_read_offset, and readV3F32().

+ Here is the call graph for this function:

◆ operator>>() [15/17]

NetworkPacket & NetworkPacket::operator>> ( v3s16 & dst)

References checkReadOffset(), m_data, m_read_offset, and readV3S16().

+ Here is the call graph for this function:

◆ operator>>() [16/17]

NetworkPacket & NetworkPacket::operator>> ( v3s32 & dst)

References checkReadOffset(), m_data, m_read_offset, and readV3S32().

+ Here is the call graph for this function:

◆ operator>>() [17/17]

NetworkPacket & NetworkPacket::operator>> ( video::SColor & dst)

References checkReadOffset(), m_data, m_read_offset, and readARGB8().

+ Here is the call graph for this function:

◆ putLongString()

void NetworkPacket::putLongString ( std::string_view src)

References LONG_STRING_MAX_LEN, and putRawString().

Referenced by Server::dynamicAddMedia(), Client::interact(), Server::SendActiveObjectRemoveAdd(), Server::SendAddParticleSpawner(), Client::sendInventoryFields(), Server::SendItemDef(), Server::sendMetadataChanged(), Server::SendNodeDef(), Client::sendNodemetaFields(), Server::SendPlayerInventoryFormspec(), Server::sendRequestedMedia(), and Server::SendShowFormspecMessage().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ putRawPacket()

void NetworkPacket::putRawPacket ( const u8 * data,
u32 datasize,
session_t peer_id )

References m_command, m_data, m_datasize, m_peer_id, and readU16().

Referenced by con::Connection::ReceiveTimeoutMs(), and TestConnection::testNetworkPacketSerialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ putRawString() [1/2]

void NetworkPacket::putRawString ( const char * src,
u32 len )

References checkDataSize(), m_data, and m_read_offset.

Referenced by operator<<(), putLongString(), putRawString(), Server::SendActiveObjectMessages(), Server::SendAddParticleSpawner(), Server::SendBlockNoLock(), Server::sendDetachedInventory(), Server::SendInventory(), Client::sendInventoryAction(), Client::sendReady(), Server::SendSpawnParticle(), and TestConnection::testConnectSendReceive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ putRawString() [2/2]

void NetworkPacket::putRawString ( std::string_view src)
inline

References putRawString().

+ Here is the call graph for this function:

◆ readLongString()

std::string NetworkPacket::readLongString ( )

References checkReadOffset(), LONG_STRING_MAX_LEN, m_data, m_read_offset, and readU32().

Referenced by Client::handleCommand_ActiveObjectRemoveAdd(), Server::handleCommand_Interact(), Client::handleCommand_InventoryFormSpec(), Client::handleCommand_ItemDef(), Client::handleCommand_Media(), Client::handleCommand_MediaPush(), Client::handleCommand_NodeDef(), Client::handleCommand_NodemetaChanged(), Client::handleCommand_ShowFormSpec(), and pkt_read_formspec_fields().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_command

u16 NetworkPacket::m_command = 0
private

◆ m_data

◆ m_datasize

u32 NetworkPacket::m_datasize = 0
private

◆ m_peer_id

session_t NetworkPacket::m_peer_id = 0
private

Referenced by clear(), getPeerId(), and putRawPacket().

◆ m_read_offset


The documentation for this class was generated from the following files: