Cuberite
A lightweight, fast and extensible game server for Minecraft
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
cMultiVersionProtocol Class Reference

Meta-protocol that recognizes multiple protocol versions, creates the specific protocol version instance and redirects everything to it. More...

#include <ProtocolRecognizer.h>

Collaboration diagram for cMultiVersionProtocol:
Collaboration graph
[legend]

Public Member Functions

 cMultiVersionProtocol ()
 
void HandleIncomingData (cClientHandle &a_Client, ContiguousByteBuffer &a_Data)
 Directs incoming protocol data along the correct pathway, depending on the state of the version recognition process. More...
 
void HandleOutgoingData (ContiguousByteBuffer &a_Data)
 Allows the protocol (if any) to do a final pass on outgiong data, possibly modifying the provided buffer in-place. More...
 
auto & operator-> ()
 Convenience overload to enable redirecting sends to the underlying implementation. More...
 
void SendDisconnect (cClientHandle &a_Client, const AString &a_Reason)
 Sends a disconnect to the client as a result of a recognition error. More...
 
bool VersionRecognitionSuccessful ()
 Returns if we contain a concrete protocol corresponding to the client's protocol version. More...
 

Static Public Member Functions

static AString GetVersionTextFromInt (cProtocol::Version a_ProtocolVersion)
 Translates protocol version number into protocol version text: 49 -> "1.4.4". More...
 

Private Member Functions

void HandleIncomingDataInOldPingResponseStage (cClientHandle &a_Client, ContiguousByteBufferView a_Data)
 Handles and responds to unsupported clients sending pings. More...
 
void HandleIncomingDataInRecognitionStage (cClientHandle &a_Client, ContiguousByteBuffer &a_Data)
 Handles data reception in a newly-created client handle that doesn't yet have a known protocol. More...
 
void HandlePacketStatusPing (cClientHandle &a_Client)
 
void HandlePacketStatusRequest (cClientHandle &a_Client)
 
bool TryHandleHTTPRequest (cClientHandle &a_Client, ContiguousByteBuffer &a_Data)
 
std::unique_ptr< cProtocolTryRecognizeLengthedProtocol (cClientHandle &a_Client)
 Tries to recognize a protocol in the lengthed family (1.7+), based on m_Buffer. More...
 

Static Private Member Functions

static UInt32 GetPacketID (cProtocol::ePacketType a_PacketType)
 Returns the protocol-specific packet ID given the protocol-agnostic packet enum. More...
 
static void SendPacket (cClientHandle &a_Client, cByteBuffer &a_OutPacketBuffer)
 Sends one packet inside a cByteBuffer. More...
 

Private Attributes

cByteBuffer m_Buffer
 Buffer for received protocol data. More...
 
std::unique_ptr< cProtocolm_Protocol
 The actual protocol implementation. More...
 
bool m_WaitingForData
 If we're still waiting for data required for version recognition to arrive. More...
 

Detailed Description

Meta-protocol that recognizes multiple protocol versions, creates the specific protocol version instance and redirects everything to it.

Definition at line 20 of file ProtocolRecognizer.h.

Constructor & Destructor Documentation

◆ cMultiVersionProtocol()

cMultiVersionProtocol::cMultiVersionProtocol ( )

Definition at line 40 of file ProtocolRecognizer.cpp.

Member Function Documentation

◆ GetPacketID()

UInt32 cMultiVersionProtocol::GetPacketID ( cProtocol::ePacketType  a_PacketType)
staticprivate

Returns the protocol-specific packet ID given the protocol-agnostic packet enum.

Definition at line 395 of file ProtocolRecognizer.cpp.

◆ GetVersionTextFromInt()

AString cMultiVersionProtocol::GetVersionTextFromInt ( cProtocol::Version  a_ProtocolVersion)
static

Translates protocol version number into protocol version text: 49 -> "1.4.4".

Definition at line 50 of file ProtocolRecognizer.cpp.

◆ HandleIncomingData()

void cMultiVersionProtocol::HandleIncomingData ( cClientHandle a_Client,
ContiguousByteBuffer a_Data 
)

Directs incoming protocol data along the correct pathway, depending on the state of the version recognition process.

The protocol modifies the provided buffer in-place.

Definition at line 187 of file ProtocolRecognizer.cpp.

◆ HandleIncomingDataInOldPingResponseStage()

void cMultiVersionProtocol::HandleIncomingDataInOldPingResponseStage ( cClientHandle a_Client,
ContiguousByteBufferView  a_Data 
)
private

Handles and responds to unsupported clients sending pings.

Definition at line 141 of file ProtocolRecognizer.cpp.

◆ HandleIncomingDataInRecognitionStage()

void cMultiVersionProtocol::HandleIncomingDataInRecognitionStage ( cClientHandle a_Client,
ContiguousByteBuffer a_Data 
)
private

Handles data reception in a newly-created client handle that doesn't yet have a known protocol.

a_Data contains a view of data that were just received. Tries to recognize a protocol, populate m_Protocol, and transitions to another mode depending on success.

Definition at line 83 of file ProtocolRecognizer.cpp.

◆ HandleOutgoingData()

void cMultiVersionProtocol::HandleOutgoingData ( ContiguousByteBuffer a_Data)

Allows the protocol (if any) to do a final pass on outgiong data, possibly modifying the provided buffer in-place.

Definition at line 209 of file ProtocolRecognizer.cpp.

◆ HandlePacketStatusPing()

void cMultiVersionProtocol::HandlePacketStatusPing ( cClientHandle a_Client)
private

Definition at line 460 of file ProtocolRecognizer.cpp.

◆ HandlePacketStatusRequest()

void cMultiVersionProtocol::HandlePacketStatusRequest ( cClientHandle a_Client)
private

Definition at line 414 of file ProtocolRecognizer.cpp.

◆ operator->()

auto& cMultiVersionProtocol::operator-> ( )
inline

Convenience overload to enable redirecting sends to the underlying implementation.

Definition at line 36 of file ProtocolRecognizer.h.

◆ SendDisconnect()

void cMultiVersionProtocol::SendDisconnect ( cClientHandle a_Client,
const AString a_Reason 
)

Sends a disconnect to the client as a result of a recognition error.

This function can be used to disconnect before any protocol has been recognised.

Definition at line 224 of file ProtocolRecognizer.cpp.

◆ SendPacket()

void cMultiVersionProtocol::SendPacket ( cClientHandle a_Client,
cByteBuffer a_OutPacketBuffer 
)
staticprivate

Sends one packet inside a cByteBuffer.

This is used only when handling an outdated server ping.

Definition at line 372 of file ProtocolRecognizer.cpp.

◆ TryHandleHTTPRequest()

bool cMultiVersionProtocol::TryHandleHTTPRequest ( cClientHandle a_Client,
ContiguousByteBuffer a_Data 
)
private

Definition at line 248 of file ProtocolRecognizer.cpp.

◆ TryRecognizeLengthedProtocol()

std::unique_ptr< cProtocol > cMultiVersionProtocol::TryRecognizeLengthedProtocol ( cClientHandle a_Client)
private

Tries to recognize a protocol in the lengthed family (1.7+), based on m_Buffer.

Returns a cProtocol_XXX instance if recognized.

Definition at line 279 of file ProtocolRecognizer.cpp.

◆ VersionRecognitionSuccessful()

bool cMultiVersionProtocol::VersionRecognitionSuccessful ( )
inline

Returns if we contain a concrete protocol corresponding to the client's protocol version.

Definition at line 30 of file ProtocolRecognizer.h.

Member Data Documentation

◆ m_Buffer

cByteBuffer cMultiVersionProtocol::m_Buffer
private

Buffer for received protocol data.

Definition at line 83 of file ProtocolRecognizer.h.

◆ m_Protocol

std::unique_ptr<cProtocol> cMultiVersionProtocol::m_Protocol
private

The actual protocol implementation.

Created when recognition of the client version succeeds with a version we support.

Definition at line 87 of file ProtocolRecognizer.h.

◆ m_WaitingForData

bool cMultiVersionProtocol::m_WaitingForData
private

If we're still waiting for data required for version recognition to arrive.

Definition at line 90 of file ProtocolRecognizer.h.


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