Horizon Official Technical Documentation
ZoneSystem.hpp
Go to the documentation of this file.
1/***************************************************
2 * _ _ _ *
3 * | | | | (_) *
4 * | |_| | ___ _ __ _ _______ _ __ *
5 * | _ |/ _ \| '__| |_ / _ \| '_ \ *
6 * | | | | (_) | | | |/ / (_) | | | | *
7 * \_| |_/\___/|_| |_/___\___/|_| |_| *
8 ***************************************************
9 * This file is part of Horizon (c).
10 *
11 * Copyright (c) 2019 Sagun K. (sagunxp@gmail.com).
12 * Copyright (c) 2019 Horizon Dev Team.
13 *
14 * Base Author - Sagun K. (sagunxp@gmail.com)
15 *
16 * This library is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this library. If not, see <http://www.gnu.org/licenses/>.
28 **************************************************/
29
30#ifndef HORIZON_ZONE_ZONESYSTEM_HPP
31#define HORIZON_ZONE_ZONESYSTEM_HPP
32
35
38
39#include <boost/mysql/error_with_diagnostics.hpp>
40#include <boost/mysql/handshake_params.hpp>
41#include <boost/mysql/results.hpp>
42#include <boost/mysql/static_results.hpp>
43#include <boost/mysql/tcp_ssl.hpp>
44#include <boost/describe/class.hpp>
45
46class DatabaseProcess;
47
49{
50 int32_t character_id{0};
51 int16_t slot{0};
52 int8_t online{0};
53 std::string gender{""};
55 int64_t last_unique_id{0};
56 int8_t font{0};
57 int32_t unban_time{0};
58 int32_t rename_count{0};
59 int16_t hotkey_row_index{0};
61 int8_t show_equip{0};
62 int8_t allow_party{0};
63 int32_t partner_aid{0};
64 int32_t father_aid{0}, mother_aid{0}, child_aid{0};
65 int32_t party_id{0}, guild_id{0};
66 int32_t homun_id{0}, pet_id{0}, elemental_id{0};
67 std::string saved_map{""};
68 int32_t saved_x{0}, saved_y{0};
69 std::string current_map{""};
70 int32_t current_x{0}, current_y{0};
71};
72
73BOOST_DESCRIBE_STRUCT(s_character_info, (), (character_id, slot, online,
74 gender, max_inventory_size, last_unique_id, font, unban_time, rename_count,
75 hotkey_row_index, change_slot_count, show_equip, allow_party, partner_aid,
76 father_aid, mother_aid, child_aid, party_id, guild_id,
77 homun_id, pet_id, elemental_id, saved_map, saved_x, saved_y,
78 current_map, current_x, current_y))
79
80struct s_login_info_query_result
81{
82 int64_t id;
83 int64_t account_id;
84 std::string current_map;
85 int32_t current_x;
86 int32_t current_y;
87};
88
89BOOST_DESCRIBE_STRUCT(s_login_info_query_result, (), (id, account_id, current_map, current_x, current_y))
90
91namespace Horizon
92{
93namespace Zone
94{
95
96class ZoneSession;
97
98struct s_scenario_login_request
99{
100 uint32_t account_id;
101 uint32_t char_id;
102 uint32_t auth_code;
103 uint32_t client_time;
104 uint8_t gender;
105};
106
107class ActiveRuntimeScenario : public Horizon::System::RuntimeRoutineContext
108{
109public:
112
113 std::shared_ptr<ZoneSession> get_session() { return _session; }
114 void set_session(std::shared_ptr<ZoneSession> session) { _session = session; }
115
116 std::shared_ptr<ZoneSession> _session;
117};
118
119class PassiveRuntimeScenario : public Horizon::System::RuntimeRoutineContext
120{
121public:
122 PassiveRuntimeScenario(std::shared_ptr<KernelComponent> component, Horizon::System::runtime_module_type module_t, Horizon::System::runtime_synchronization_method sync_t)
123 : Horizon::System::RuntimeRoutineContext(component->get_system_routine_manager(), sync_t), _component(component), _module_type(module_t) { }
124
125 std::shared_ptr<KernelComponent> get_component() { return _component.expired() == false ? _component.lock() : nullptr; }
126
127 Horizon::System::runtime_module_type get_module_type() { return _module_type; }
128
129protected:
130 std::weak_ptr<KernelComponent> _component;
132};
133
134class SCENARIO_LOGIN : public ActiveRuntimeScenario
135{
136public:
137 SCENARIO_LOGIN(Horizon::System::SystemRoutineManager &srm)
138 : ActiveRuntimeScenario(srm, Horizon::System::RUNTIME_SYNC_WAIT_CHECK_STATE) { }
139
141 {
142 public:
143 Login(std::shared_ptr<SCENARIO_LOGIN> parent_context)
145
146 void set_request(s_scenario_login_request req) { _request = req; }
147 s_scenario_login_request get_request() { return _request; }
148
149 bool execute();
150
151 s_scenario_login_request _request;
152 };
153
154 Horizon::System::Result<s_login_info_query_result> get_result() { return _context_result; }
155 void set_result(Horizon::System::Result<s_login_info_query_result> result) { _context_result = result; }
156
158};
159
160struct s_player_loaded_data
161{
162 int32_t account_id;
163 int32_t char_id;
164 std::string map;
165 int32_t current_x, current_y;
166};
167
168class SCENARIO_CREATE_PLAYER : public ActiveRuntimeScenario
169{
170public:
171 SCENARIO_CREATE_PLAYER(Horizon::System::SystemRoutineManager &srm)
172 : ActiveRuntimeScenario(srm, Horizon::System::RUNTIME_SYNC_WAIT_CHECK_STATE),
173 _previous_context_result(s_login_info_query_result{})
174 { }
175
176 class CreatePlayer : public Horizon::System::RuntimeRoutineContext::Work
177 {
178 public:
179 CreatePlayer(std::shared_ptr<SCENARIO_CREATE_PLAYER> parent_context)
181 { }
182
183 void set_request(s_player_loaded_data req) { }
184 s_player_loaded_data get_request() { return _request; }
185
186 bool execute();
187
188 s_player_loaded_data _request;
189 };
190
191 void set_previous_context_result(Horizon::System::Result<s_login_info_query_result> result)
192 {
193 _previous_context_result = result;
194 }
195
196 Horizon::System::Result<s_login_info_query_result> get_previous_context_result()
197 {
198 return _previous_context_result;
199 }
200
201 bool run() override
202 {
203
204 // use result in work.
205 if (RuntimeRoutineContext::run()) {
206 return true;
207 }
208
209 return false;
210 }
211
213};
214
215class SCENARIO_LOGIN_RESPONSE : public ActiveRuntimeScenario
216{
217public:
218 SCENARIO_LOGIN_RESPONSE(Horizon::System::SystemRoutineManager &srm)
219 : ActiveRuntimeScenario(srm, Horizon::System::RUNTIME_SYNC_WAIT_CHECK_STATE) { }
220
221 struct s_scenario_login_response_request
222 {
223 uint32_t account_id;
224 uint32_t current_x, current_y;
225 int8_t font;
226 };
227
228 class LoginResponse : public Horizon::System::RuntimeRoutineContext::Work
229 {
230 public:
231 LoginResponse(std::shared_ptr<SCENARIO_LOGIN_RESPONSE> parent_context)
233
234 bool execute();
235
236 void set_request(s_scenario_login_response_request req) { _request = req; }
237 s_scenario_login_response_request get_request() { return _request; }
238
239 s_scenario_login_response_request _request;
240 };
241};
242
243class SCENARIO_GENERIC_TASK : public ActiveRuntimeScenario
244{
245public:
246 SCENARIO_GENERIC_TASK(Horizon::System::SystemRoutineManager &srm)
247 : ActiveRuntimeScenario(srm, Horizon::System::RUNTIME_SYNC_WAIT_CHECK_STATE) { }
248
249 class GenericTask : public Horizon::System::RuntimeRoutineContext::Work
250 {
251 public:
252 GenericTask(std::shared_ptr<SCENARIO_GENERIC_TASK> parent_context)
254
255 bool execute();
256
257 void set_task(std::function<void(std::shared_ptr<GenericTask> generic_task)> task) { _generic_task = task; }
258 std::function<void(std::shared_ptr<GenericTask> send_packet)> get_task() { return _generic_task; }
259
260 std::function<void(std::shared_ptr<GenericTask> send_packet)> _generic_task;
261 };
262};
263
264class SCENARIO_REGISTER_MONSTER_SPAWN : public PassiveRuntimeScenario
265{
266public:
267 SCENARIO_REGISTER_MONSTER_SPAWN(std::shared_ptr<KernelComponent> component)
269
270 struct s_register_monster_spawn_request
271 {
273 };
274
275 class RegisterMonsterSpawn : public Horizon::System::RuntimeRoutineContext::Work
276 {
277 public:
278 RegisterMonsterSpawn(std::shared_ptr<SCENARIO_REGISTER_MONSTER_SPAWN> parent_context)
280
281 bool execute();
282
283 void set_request(s_register_monster_spawn_request request) { _request = request; }
284 s_register_monster_spawn_request get_request() { return _request; }
285
286 s_register_monster_spawn_request _request;
287 };
288};
289
290class SCENARIO_SPAWN_MONSTERS_IN_MAP : public PassiveRuntimeScenario
291{
292public:
293 SCENARIO_SPAWN_MONSTERS_IN_MAP(std::shared_ptr<KernelComponent> component)
295
296 struct s_spawn_monster_request
297 {
298 std::string map_name;
299 };
300
301 class SpawnMonsters : public Horizon::System::RuntimeRoutineContext::Work
302 {
303 public:
304 SpawnMonsters(std::shared_ptr<SCENARIO_SPAWN_MONSTERS_IN_MAP> parent_context)
306
307 bool execute();
308
309 void set_request(s_spawn_monster_request request) { _request = request; }
310 s_spawn_monster_request get_request() { return _request; }
311
312 s_spawn_monster_request _request;
313 };
314};
315
316class SCENARIO_REMOVE_MONSTERS_IN_MAP : public PassiveRuntimeScenario
317{
318public:
319 SCENARIO_REMOVE_MONSTERS_IN_MAP(std::shared_ptr<KernelComponent> component)
321
322 struct s_remove_monster_request
323 {
324 std::string map_name;
325 };
326
327 class RemoveMonsters : public Horizon::System::RuntimeRoutineContext::Work
328 {
329 public:
330 RemoveMonsters(std::shared_ptr<SCENARIO_REMOVE_MONSTERS_IN_MAP> parent_context)
332
333 bool execute();
334
335 void set_request(s_remove_monster_request request) { _request = request; }
336 s_remove_monster_request get_request() { return _request; }
337
338 s_remove_monster_request _request;
339 };
340};
341}
342}
343#endif // HORIZON_ZONE_ZONESYSTEM_HPP
#define MAX_INVENTORY_SIZE
Definition: ItemDefinitions.hpp:54
BOOST_DESCRIBE_STRUCT(s_character_info,(),(character_id, slot, online, gender, max_inventory_size, last_unique_id, font, unban_time, rename_count, hotkey_row_index, change_slot_count, show_equip, allow_party, partner_aid, father_aid, mother_aid, child_aid, party_id, guild_id, homun_id, pet_id, elemental_id, saved_map, saved_x, saved_y, current_map, current_x, current_y)) struct s_login_info_query_result
Definition: ZoneSystem.hpp:73
Definition: Server.hpp:371
Definition: System.hpp:379
Definition: System.hpp:389
Definition: System.hpp:600
runtime_module_type
Definition: System.hpp:81
@ RUNTIME_GAMELOGIC
Definition: System.hpp:86
@ RUNTIME_RUNTIME
Definition: System.hpp:92
runtime_synchronization_method
Definition: System.hpp:97
@ RUNTIME_SYNC_WAIT_CHECK_STATE
Definition: System.hpp:100
Definition: Element.hpp:7
Definition: MonsterDefinitions.hpp:169
Definition: ZoneSystem.hpp:49
int32_t pet_id
Definition: ZoneSystem.hpp:66
int32_t child_aid
Definition: ZoneSystem.hpp:64
int32_t current_x
Definition: ZoneSystem.hpp:70
int32_t guild_id
Definition: ZoneSystem.hpp:65
int16_t slot
Definition: ZoneSystem.hpp:51
int32_t party_id
Definition: ZoneSystem.hpp:65
int32_t mother_aid
Definition: ZoneSystem.hpp:64
int32_t father_aid
Definition: ZoneSystem.hpp:64
int8_t show_equip
Definition: ZoneSystem.hpp:61
int32_t max_inventory_size
Definition: ZoneSystem.hpp:54
int32_t saved_y
Definition: ZoneSystem.hpp:68
int32_t character_id
Definition: ZoneSystem.hpp:50
int32_t current_y
Definition: ZoneSystem.hpp:70
int32_t partner_aid
Definition: ZoneSystem.hpp:63
int32_t elemental_id
Definition: ZoneSystem.hpp:66
int32_t homun_id
Definition: ZoneSystem.hpp:66
std::string gender
Definition: ZoneSystem.hpp:53
int16_t hotkey_row_index
Definition: ZoneSystem.hpp:59
int32_t unban_time
Definition: ZoneSystem.hpp:57
int32_t rename_count
Definition: ZoneSystem.hpp:58
int8_t online
Definition: ZoneSystem.hpp:52
std::string saved_map
Definition: ZoneSystem.hpp:67
int8_t font
Definition: ZoneSystem.hpp:56
int32_t saved_x
Definition: ZoneSystem.hpp:68
int64_t last_unique_id
Definition: ZoneSystem.hpp:55
int8_t allow_party
Definition: ZoneSystem.hpp:62
int32_t change_slot_count
Definition: ZoneSystem.hpp:60
std::string current_map
Definition: ZoneSystem.hpp:69