Botcraft 1.21.10
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 in offline mode if login is not empty, fallback to Microsoft auth flow if empty.
18 /// @param address Address to connect to, same format as one would type it in a vanilla client
19 /// @param login Username the bot will use to connect, will default back to Microsoft auth if empty
20 void Connect(const std::string& address, const std::string& login);
21 /// @brief Connect the client in online mode. Will prompt user to auth with a valid Microsoft account
22 /// @param address Address to connect to, same format as one would type it in a vanilla client
23 /// @param cache_key Will be used to store the auth tokens in a cache file to speed up future connection with the same account.
24 /// Use different cache keys to store multiple accounts
25 void ConnectMicrosoft(const std::string& address, const std::string& cache_key = "");
26 /// @brief Connect the client in online mode using the provided minecraft token
27 /// @param address Address to connect to, same format as one would type it in a vanilla client
28 /// @param minecraft_token Minecraft token to use for auth. It's the user responsability to make sure it's valid.
29 void ConnectMinecraftToken(const std::string& address, const std::string& minecraft_token);
30 virtual void Disconnect();
31
32 bool GetShouldBeClosed() const;
33 void SetShouldBeClosed(const bool b);
34
35 std::shared_ptr<NetworkManager> GetNetworkManager() const;
36
37 /// @brief Send a message in the game chat
38 /// @param msg The message to send
39 void SendChatMessage(const std::string& msg);
40
41 /// @brief Send a command in the game chat
42 /// @param command The command to send (with no / at start)
43 void SendChatCommand(const std::string& command);
44
45 /// @brief Ask to respawn when dead
46 void Respawn();
47
48 protected:
49 using ProtocolCraft::Handler::Handle; // Don't hide all Handle() functions from base classes
50 virtual void Handle(ProtocolCraft::ClientboundLoginDisconnectPacket& packet) override;
51#if PROTOCOL_VERSION < 755 /* < 1.17 */
52 virtual void Handle(ProtocolCraft::ClientboundContainerAckPacket& packet) override;
53#endif
54 virtual void Handle(ProtocolCraft::ClientboundDisconnectPacket& packet) override;
55 virtual void Handle(ProtocolCraft::ClientboundPlayerPositionPacket& packet) override;
56#if PROTOCOL_VERSION > 763 /* > 1.20.1 */
58#endif
59#if PROTOCOL_VERSION > 768 /* > 1.21.3 */
60 virtual void Handle(ProtocolCraft::ClientboundLoginPacket& packet) override;
61 virtual void Handle(ProtocolCraft::ClientboundRespawnPacket& packet) override;
62#endif
63
64 protected:
65 std::shared_ptr<NetworkManager> network_manager;
66
68 };
69} //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.
void ConnectMinecraftToken(const std::string &address, const std::string &minecraft_token)
Connect the client in online mode using the provided minecraft token.
void ConnectMicrosoft(const std::string &address, const std::string &cache_key="")
Connect the client in online mode.
void SendChatCommand(const std::string &command)
Send a command in the game chat.
virtual void Handle(ProtocolCraft::ClientboundLoginDisconnectPacket &packet) override
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.
std::shared_ptr< NetworkManager > network_manager
void SetShouldBeClosed(const bool b)