Botcraft 1.21.4
Loading...
Searching...
No Matches
ConnectionClient.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace Botcraft
6{
7 class NetworkManager;
8
9 /// @brief The base client handling connection with a server.
10 /// Only processes packets required to maintain the connection.
12 {
13 public:
15 virtual ~ConnectionClient();
16
17 /// @brief Connect the client to the server at address
18 /// @param address Address to connect to, as written in minecraft multiplayer window
19 /// @param login If login is empty, will try to connect with a Microsoft account
20 /// @param force_microsoft_account If true, then Microsoft auth flow will be used. In this case, login is used as key to cache the credentials
21 void Connect(const std::string& address, const std::string& login, const bool force_microsoft_account = false);
22 virtual void Disconnect();
23
24 bool GetShouldBeClosed() const;
25 void SetShouldBeClosed(const bool b);
26
27 std::shared_ptr<NetworkManager> GetNetworkManager() const;
28
29 /// @brief Send a message in the game chat
30 /// @param msg The message to send
31 void SendChatMessage(const std::string& msg);
32
33 /// @brief Send a command in the game chat
34 /// @param command The command to send (with no / at start)
35 void SendChatCommand(const std::string& command);
36
37 /// @brief Ask to respawn when dead
38 void Respawn();
39
40 protected:
41 using ProtocolCraft::Handler::Handle; // Don't hide all Handle() functions from base classes
43#if PROTOCOL_VERSION < 755 /* < 1.17 */
44 virtual void Handle(ProtocolCraft::ClientboundContainerAckPacket& msg) override;
45#endif
46 virtual void Handle(ProtocolCraft::ClientboundDisconnectPacket& msg) override;
48#if PROTOCOL_VERSION > 763 /* > 1.20.1 */
50#endif
51#if PROTOCOL_VERSION > 768 /* > 1.21.3 */
52 virtual void Handle(ProtocolCraft::ClientboundLoginPacket& msg) override;
53 virtual void Handle(ProtocolCraft::ClientboundRespawnPacket& msg) override;
54#endif
55
56 protected:
57 std::shared_ptr<NetworkManager> network_manager;
58
60 };
61} //Botcraft
The base client handling connection with a server.
void Respawn()
Ask to respawn when dead.
std::shared_ptr< NetworkManager > GetNetworkManager() const
void SendChatMessage(const std::string &msg)
Send a message in the game chat.
virtual void Handle(ProtocolCraft::ClientboundLoginDisconnectPacket &msg) override
void SendChatCommand(const std::string &command)
Send a command in the game chat.
void Connect(const std::string &address, const std::string &login, const bool force_microsoft_account=false)
Connect the client to the server at address.
std::shared_ptr< NetworkManager > network_manager
void SetShouldBeClosed(const bool b)