Botcraft 1.21.10
Loading...
Searching...
No Matches
Botcraft::ConnectionClient Class Reference

The base client handling connection with a server. More...

#include <ConnectionClient.hpp>

Inheritance diagram for Botcraft::ConnectionClient:
ProtocolCraft::Handler ProtocolCraft::GenericHandler< Packet, AllPackets > Botcraft::ManagersClient Botcraft::BehaviourClient Botcraft::TemplatedBehaviourClient< SimpleBehaviourClient > Botcraft::TemplatedBehaviourClient< TDerived > Botcraft::SimpleBehaviourClient

Public Member Functions

 ConnectionClient ()
 
virtual ~ConnectionClient ()
 
void Connect (const std::string &address, const std::string &login)
 Connect the client in offline mode if login is not empty, fallback to Microsoft auth flow if empty.
 
void ConnectMicrosoft (const std::string &address, const std::string &cache_key="")
 Connect the client in online mode.
 
void ConnectMinecraftToken (const std::string &address, const std::string &minecraft_token)
 Connect the client in online mode using the provided minecraft token.
 
virtual void Disconnect ()
 
bool GetShouldBeClosed () const
 
void SetShouldBeClosed (const bool b)
 
std::shared_ptr< NetworkManagerGetNetworkManager () const
 
void SendChatMessage (const std::string &msg)
 Send a message in the game chat.
 
void SendChatCommand (const std::string &command)
 Send a command in the game chat.
 
void Respawn ()
 Ask to respawn when dead.
 

Protected Member Functions

virtual void Handle (ProtocolCraft::ClientboundLoginDisconnectPacket &packet) override
 
virtual void Handle (ProtocolCraft::ClientboundDisconnectPacket &packet) override
 
virtual void Handle (ProtocolCraft::ClientboundPlayerPositionPacket &packet) override
 
virtual void Handle (ProtocolCraft::ClientboundDisconnectConfigurationPacket &packet) override
 
virtual void Handle (ProtocolCraft::ClientboundLoginPacket &packet) override
 
virtual void Handle (ProtocolCraft::ClientboundRespawnPacket &packet) override
 

Protected Attributes

std::shared_ptr< NetworkManagernetwork_manager
 
bool should_be_closed
 

Detailed Description

The base client handling connection with a server.

Only processes packets required to maintain the connection.

Definition at line 11 of file ConnectionClient.hpp.

Constructor & Destructor Documentation

◆ ConnectionClient()

Botcraft::ConnectionClient::ConnectionClient ( )

Definition at line 9 of file ConnectionClient.cpp.

References network_manager, and should_be_closed.

◆ ~ConnectionClient()

Botcraft::ConnectionClient::~ConnectionClient ( )
virtual

Definition at line 15 of file ConnectionClient.cpp.

References Disconnect().

Member Function Documentation

◆ Connect()

void Botcraft::ConnectionClient::Connect ( const std::string &  address,
const std::string &  login 
)

Connect the client in offline mode if login is not empty, fallback to Microsoft auth flow if empty.

Parameters
addressAddress to connect to, same format as one would type it in a vanilla client
loginUsername the bot will use to connect, will default back to Microsoft auth if empty

Definition at line 20 of file ConnectionClient.cpp.

References ConnectMicrosoft(), network_manager, and Botcraft::NetworkManager::Offline.

◆ ConnectMicrosoft()

void Botcraft::ConnectionClient::ConnectMicrosoft ( const std::string &  address,
const std::string &  cache_key = "" 
)

Connect the client in online mode.

Will prompt user to auth with a valid Microsoft account

Parameters
addressAddress to connect to, same format as one would type it in a vanilla client
cache_keyWill be used to store the auth tokens in a cache file to speed up future connection with the same account. Use different cache keys to store multiple accounts

Definition at line 32 of file ConnectionClient.cpp.

References Botcraft::NetworkManager::Microsoft, and network_manager.

Referenced by Connect().

◆ ConnectMinecraftToken()

void Botcraft::ConnectionClient::ConnectMinecraftToken ( const std::string &  address,
const std::string &  minecraft_token 
)

Connect the client in online mode using the provided minecraft token.

Parameters
addressAddress to connect to, same format as one would type it in a vanilla client
minecraft_tokenMinecraft token to use for auth. It's the user responsability to make sure it's valid.

Definition at line 37 of file ConnectionClient.cpp.

References Botcraft::NetworkManager::McToken, and network_manager.

◆ Disconnect()

void Botcraft::ConnectionClient::Disconnect ( )
virtual

Reimplemented in Botcraft::ManagersClient.

Definition at line 42 of file ConnectionClient.cpp.

References network_manager, and should_be_closed.

Referenced by Botcraft::ManagersClient::Disconnect(), and ~ConnectionClient().

◆ GetNetworkManager()

◆ GetShouldBeClosed()

bool Botcraft::ConnectionClient::GetShouldBeClosed ( ) const

Definition at line 52 of file ConnectionClient.cpp.

◆ Handle() [1/6]

void Botcraft::ConnectionClient::Handle ( ProtocolCraft::ClientboundDisconnectConfigurationPacket packet)
overrideprotectedvirtual

◆ Handle() [2/6]

void Botcraft::ConnectionClient::Handle ( ProtocolCraft::ClientboundDisconnectPacket packet)
overrideprotectedvirtual

◆ Handle() [3/6]

void Botcraft::ConnectionClient::Handle ( ProtocolCraft::ClientboundLoginDisconnectPacket packet)
overrideprotectedvirtual

◆ Handle() [4/6]

void Botcraft::ConnectionClient::Handle ( ProtocolCraft::ClientboundLoginPacket packet)
overrideprotectedvirtual

Reimplemented in Botcraft::ManagersClient, and Botcraft::ManagersClient.

Definition at line 156 of file ConnectionClient.cpp.

References network_manager.

◆ Handle() [5/6]

void Botcraft::ConnectionClient::Handle ( ProtocolCraft::ClientboundPlayerPositionPacket packet)
overrideprotectedvirtual

Reimplemented in Botcraft::ManagersClient, and Botcraft::ManagersClient.

Definition at line 133 of file ConnectionClient.cpp.

References network_manager.

◆ Handle() [6/6]

void Botcraft::ConnectionClient::Handle ( ProtocolCraft::ClientboundRespawnPacket packet)
overrideprotectedvirtual

Reimplemented in Botcraft::ManagersClient, and Botcraft::ManagersClient.

Definition at line 161 of file ConnectionClient.cpp.

References network_manager.

◆ Respawn()

void Botcraft::ConnectionClient::Respawn ( )

Ask to respawn when dead.

Definition at line 83 of file ConnectionClient.cpp.

References network_manager.

Referenced by Botcraft::ManagersClient::Handle().

◆ SendChatCommand()

void Botcraft::ConnectionClient::SendChatCommand ( const std::string &  command)

Send a command in the game chat.

Parameters
commandThe command to send (with no / at start)

Definition at line 75 of file ConnectionClient.cpp.

References network_manager.

◆ SendChatMessage()

void Botcraft::ConnectionClient::SendChatMessage ( const std::string &  msg)

Send a message in the game chat.

Parameters
msgThe message to send

Definition at line 67 of file ConnectionClient.cpp.

References network_manager.

Referenced by Botcraft::SayImpl().

◆ SetShouldBeClosed()

void Botcraft::ConnectionClient::SetShouldBeClosed ( const bool  b)

Definition at line 57 of file ConnectionClient.cpp.

Referenced by Botcraft::Disconnect().

Member Data Documentation

◆ network_manager

◆ should_be_closed


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