Botcraft 1.21.4
Loading...
Searching...
No Matches
MessageFactory.cpp
Go to the documentation of this file.
5
6namespace ProtocolCraft
7{
8 namespace
9 {
10 template<typename TypesTuple>
11 std::shared_ptr<Message> AutomaticMessageFactory(const int id)
12 {
13 std::shared_ptr<Message> output = nullptr;
14
15 Internal::loop<std::tuple_size_v<TypesTuple>>([&](auto i) {
16 if (id == i)
17 {
18 output = std::make_shared<std::tuple_element_t<i, TypesTuple>>();
19 }
20 });
21
22 return output;
23 }
24 }
25
26 std::shared_ptr<Message> CreateClientboundMessage(const ConnectionState state, const int id)
27 {
28 switch (state)
29 {
31 return AutomaticMessageFactory<AllClientboundLoginMessages>(id);
33 return AutomaticMessageFactory<AllClientboundStatusMessages>(id);
35 return AutomaticMessageFactory<AllClientboundPlayMessages>(id);
36#if PROTOCOL_VERSION > 763 /* > 1.20.1 */
38 return AutomaticMessageFactory<AllClientboundConfigurationMessages>(id);
39#endif
40 default:
41 return nullptr;
42 }
43 }
44
45 std::shared_ptr<Message> CreateServerboundMessage(const ConnectionState state, const int id)
46 {
47 switch (state)
48 {
50 return AutomaticMessageFactory<AllServerboundHandshakingMessages>(id);
52 return AutomaticMessageFactory<AllServerboundLoginMessages>(id);
54 return AutomaticMessageFactory<AllServerboundStatusMessages>(id);
56 return AutomaticMessageFactory<AllServerboundPlayMessages>(id);
57#if PROTOCOL_VERSION > 763 /* > 1.20.1 */
59 return AutomaticMessageFactory<AllServerboundConfigurationMessages>(id);
60#endif
61 default:
62 return nullptr;
63 }
64 }
65}
std::shared_ptr< Message > CreateServerboundMessage(const ConnectionState state, const int id)
std::shared_ptr< Message > CreateClientboundMessage(const ConnectionState state, const int id)