Botcraft 26.2
Loading...
Searching...
No Matches
ManagersClient.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <atomic>
4#include <map>
5#include <shared_mutex>
6#include <thread>
7
11
12namespace Botcraft
13{
14 class World;
15 class InventoryManager;
16 class EntityManager;
17 class LocalPlayer;
18 class PhysicsManager;
19
20#if USE_GUI
21 namespace Renderer
22 {
23 class RenderingManager;
24 }
25#endif
26
27 /// @brief A client containing the different managers,
28 /// and performing client-side physics.
29 /// Can be inherited if you want to handle other packets
30 /// without a need of any behaviour tree stuff.
32 {
33 public:
35 virtual ~ManagersClient();
36
37 virtual void Disconnect() override;
38
39 void SetSharedWorld(const std::shared_ptr<World> world_);
40
41 bool GetAutoRespawn() const;
42 void SetAutoRespawn(const bool b);
43
44 // Set the right transaction id, add it to the inventory manager,
45 // update the next transaction id and send it to the server
46 // return the id of the transaction
47 int SendInventoryTransaction(const std::shared_ptr<ProtocolCraft::ServerboundContainerClickPacket>& transaction);
48
49 std::shared_ptr<World> GetWorld() const;
50 std::shared_ptr<EntityManager> GetEntityManager() const;
51 std::shared_ptr<LocalPlayer> GetLocalPlayer() const;
52 std::shared_ptr<InventoryManager> GetInventoryManager() const;
53 std::shared_ptr<PhysicsManager> GetPhysicsManager() const;
54
55 /// @brief Get the name of a connected player
56 /// @param uuid UUID of the player
57 /// @return The name, or empty string if not present
58 std::string GetPlayerName(const ProtocolCraft::UUID& uuid) const;
59
60 /// @brief Get the list of connected player (tab list)
61 /// @return Basically an object you can use as a std::map<ProtocolCraft::UUID, std::string>*.
62 /// **ALL TAB LIST UPDATE WILL BE BLOCKED WHILE THIS OBJECT IS ALIVE**, make sure it goes out of scope
63 /// as soon as you don't need it.
65
66 /// @brief Get the current tick
67 /// @return An int representing the time of day
68 int GetDayTime() const;
69
70 protected:
71 using ConnectionClient::Handle; // Don't hide all Handle() functions from base classes
72#if PROTOCOL_VERSION < 768 /* < 1.21.2 */
73 virtual void Handle(ProtocolCraft::ClientboundGameProfilePacket& packet) override;
74#else
75 virtual void Handle(ProtocolCraft::ClientboundLoginFinishedPacket& packet) override;
76#endif
77 virtual void Handle(ProtocolCraft::ClientboundChangeDifficultyPacket& packet) override;
78 virtual void Handle(ProtocolCraft::ClientboundLoginPacket& packet) override;
79 virtual void Handle(ProtocolCraft::ClientboundSetHealthPacket& packet) override;
80 virtual void Handle(ProtocolCraft::ClientboundPlayerPositionPacket& packet) override;
81 virtual void Handle(ProtocolCraft::ClientboundRespawnPacket& packet) override;
82 virtual void Handle(ProtocolCraft::ClientboundSetTimePacket& packet) override;
83#if PROTOCOL_VERSION < 761 /* < 1.19.3 */
84 virtual void Handle(ProtocolCraft::ClientboundPlayerInfoPacket& packet) override;
85#else
86 virtual void Handle(ProtocolCraft::ClientboundPlayerInfoRemovePacket& packet) override;
87 virtual void Handle(ProtocolCraft::ClientboundPlayerInfoUpdatePacket& packet) override;
88#endif
89
90 protected:
91 std::shared_ptr<World> world;
92 std::shared_ptr<EntityManager> entity_manager;
93 std::shared_ptr<InventoryManager> inventory_manager;
94 std::shared_ptr<PhysicsManager> physics_manager;
95#if USE_GUI
96 std::shared_ptr<Renderer::RenderingManager> rendering_manager;
97#endif
98
100
102#if PROTOCOL_VERSION > 463 /* > 1.13.2 */
104#endif
106 std::atomic<int> day_time;
107
108 /// @brief Names of all connected players
109 std::map<ProtocolCraft::UUID, std::string> player_names;
110 mutable std::shared_mutex player_names_mutex;
111 };
112} //Botcraft
The base client handling connection with a server.
virtual void Handle(ProtocolCraft::ClientboundLoginDisconnectPacket &packet) override
A client containing the different managers, and performing client-side physics.
std::atomic< int > day_time
Utilities::ScopeLockedWrapper< const std::map< ProtocolCraft::UUID, std::string >, std::shared_mutex, std::shared_lock > GetOnlinePlayers() const
Get the list of connected player (tab list)
std::map< ProtocolCraft::UUID, std::string > player_names
Names of all connected players.
std::shared_ptr< EntityManager > GetEntityManager() const
std::shared_ptr< PhysicsManager > GetPhysicsManager() const
void SetSharedWorld(const std::shared_ptr< World > world_)
std::shared_ptr< Renderer::RenderingManager > rendering_manager
std::shared_ptr< LocalPlayer > GetLocalPlayer() const
void SetAutoRespawn(const bool b)
std::shared_ptr< InventoryManager > GetInventoryManager() const
virtual void Disconnect() override
std::shared_ptr< PhysicsManager > physics_manager
std::shared_ptr< InventoryManager > inventory_manager
std::shared_ptr< EntityManager > entity_manager
int SendInventoryTransaction(const std::shared_ptr< ProtocolCraft::ServerboundContainerClickPacket > &transaction)
std::shared_mutex player_names_mutex
std::shared_ptr< World > world
virtual void Handle(ProtocolCraft::ClientboundLoginFinishedPacket &packet) override
int GetDayTime() const
Get the current tick.
std::string GetPlayerName(const ProtocolCraft::UUID &uuid) const
Get the name of a connected player.
std::shared_ptr< World > GetWorld() const
Mutex protected reference, will be locked until destroyed.
std::array< unsigned char, 16 > UUID