Horizon Official Technical Documentation
Zone.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_ZONEMAIN_HPP
31#define HORIZON_ZONE_ZONEMAIN_HPP
32
33#include "Server/pch.hpp"
34
38
39namespace Horizon
40{
41 namespace Zone
42 {
43 namespace Game
44 {
45 namespace Units
46 {
47 class Player;
48 }
49 }
50 }
51}
52
53namespace Horizon
54{
55namespace Zone
56{
57class ZoneSession;
58
60{
61 void set_natural_heal_hp_interval(int interval) { natural_heal_hp_interval = interval; }
62 void set_natural_heal_sp_interval(int interval) { natural_heal_sp_interval = interval; }
63
66
69};
70
72{
73 // create copy and move constructors for s_zone_server_configuration
75
77 {
78 if (this != &other)
79 {
88 }
89 return *this;
90 }
91
93 {
94 _static_db_path = std::move(other._static_db_path);
95 _mapcache_path = std::move(other._mapcache_path);
96 _session_max_timeout = other._session_max_timeout;
97 _script_root_path = std::move(other._script_root_path);
98 _max_network_threads = other._max_network_threads;
99 _max_game_logic_threads = other._max_game_logic_threads;
100 _max_persistence_threads = other._max_persistence_threads;
101 _max_script_vm_threads = other._max_script_vm_threads;
102 }
103
105 {
114 }
115
116 boost::filesystem::path &get_mapcache_path() { return _mapcache_path; }
117 void set_mapcache_path(boost::filesystem::path p) { _mapcache_path = p; }
118
119 boost::filesystem::path &get_static_db_path() { return _static_db_path; }
120 void set_static_db_path(boost::filesystem::path p) { _static_db_path = p; }
121
122 boost::filesystem::path &get_script_root_path() { return _script_root_path; }
123 void set_script_root_path(boost::filesystem::path p) { _script_root_path = p; }
124
126 void set_session_max_timeout(std::time_t timeout) { _session_max_timeout = timeout; }
127
129 void set_max_network_threads(int threads) { _max_network_threads = threads; }
130
133
136
138 void set_max_script_vm_threads(int threads) { _max_script_vm_threads = threads; }
139
140 boost::filesystem::path _static_db_path;
141 boost::filesystem::path _mapcache_path;
143 boost::filesystem::path _script_root_path;
148};
149
150class ZoneKernel : public Server
151{
152public:
154 ~ZoneKernel();
155
156 void initialize();
157 void finalize();
158
161
163
165
166protected:
169};
170
172{
173public:
174 ZoneRuntime();
175
176 virtual void initialize(int segment_number = 1) override
177 {
178 set_segment_number(segment_number);
179
180 _is_initialized.exchange(true);
181
182 _thread = std::thread(&ZoneRuntime::start, this);
183 }
184
185 virtual void finalize() override
186 {
187 if (_thread.joinable())
188 _thread.join();
189
190 _is_finalized.exchange(true);
191 }
192
193 void start();
194 virtual void update(int64_t diff);
195
196 bool is_initialized() override { return _is_initialized; }
197 bool is_finalized() override { return _is_finalized; }
198
199protected:
203public:
205private:
206 std::thread _thread;
207 std::atomic<bool> _is_initialized{false};
208 std::atomic<bool> _is_finalized{false};
209
210};
211
212class ZoneServer : public ZoneKernel
213{
214public:
215 ZoneServer();
216 ~ZoneServer();
217
219 {
220 static ZoneServer instance;
221 return &instance;
222 }
223
224 bool read_config();
225 void initialize();
226 void finalize();
227
228 void update(int64_t diff);
229
232
233 uint64_t to_uuid(uint8_t type, uint32_t uid, uint16_t uid2, uint8_t uid3);
234 void from_uuid(uint64_t unit_uuid, uint8_t& type, uint32_t& uid, uint16_t& uid2, uint8_t& uid3);
235
237
238private:
242 boost::asio::deadline_timer _update_timer;
243};
244}
245}
246
247#define sZone Horizon::Zone::ZoneServer::getInstance()
248
249#endif // HORIZON_ZONE_ZONEMAIN_HPP
Manager of client sockets.
Definition: ClientSocketMgr.hpp:134
Definition: Zone.hpp:151
~ZoneKernel()
Definition: Zone.cpp:48
void finalize()
Definition: Zone.cpp:64
TaskScheduler & getScheduler()
Definition: Zone.hpp:162
s_zone_server_configuration & config()
Definition: Zone.hpp:159
TaskScheduler _task_scheduler
Definition: Zone.hpp:167
void set_config(s_zone_server_configuration &config)
Definition: Zone.hpp:160
s_zone_server_configuration _config
Definition: Zone.hpp:168
ZoneKernel(s_zone_server_configuration &config)
Definition: Zone.cpp:42
void verify_connected_sessions()
Definition: Zone.cpp:71
void initialize()
Definition: Zone.cpp:54
Definition: Zone.hpp:172
bool is_initialized() override
Definition: Zone.hpp:196
ResourceManager _resource_manager
Definition: Zone.hpp:202
virtual void finalize() override
Definition: Zone.hpp:185
std::atomic< bool > _is_initialized
Definition: Zone.hpp:207
ZoneRuntime()
Definition: Zone.cpp:321
void start()
Definition: Zone.cpp:327
bool is_finalized() override
Definition: Zone.hpp:197
virtual void initialize(int segment_number=1) override
Definition: Zone.hpp:176
std::atomic< bool > _is_finalized
Definition: Zone.hpp:208
std::thread _thread
Definition: Zone.hpp:206
ResourceManager & get_resource_manager()
Definition: Zone.hpp:204
virtual void update(int64_t diff)
Definition: Zone.cpp:335
Definition: Zone.hpp:213
s_game_process_configuration & game_config()
Definition: Zone.hpp:231
s_zone_server_configuration _zone_server_config
Definition: Zone.hpp:239
void from_uuid(uint64_t unit_uuid, uint8_t &type, uint32_t &uid, uint16_t &uid2, uint8_t &uid3)
Definition: Zone.cpp:185
static ZoneServer * getInstance()
Definition: Zone.hpp:218
void finalize()
Definition: Zone.cpp:293
void initialize()
Definition: Zone.cpp:236
s_zone_server_configuration & config()
Definition: Zone.hpp:230
ClientSocketMgr & get_client_socket_mgr()
Definition: Zone.hpp:236
void update(int64_t diff)
Definition: Zone.cpp:209
boost::asio::deadline_timer _update_timer
Definition: Zone.hpp:242
s_game_process_configuration _game_process_config
Definition: Zone.hpp:240
~ZoneServer()
Zone Main server destructor.
Definition: Zone.cpp:111
bool read_config()
Read /config/zone-server.yaml.
Definition: Zone.cpp:122
ClientSocketMgr _client_socket_mgr
Definition: Zone.hpp:241
ZoneServer()
Zone Main server constructor.
Definition: Zone.cpp:103
uint64_t to_uuid(uint8_t type, uint32_t uid, uint16_t uid2, uint8_t uid3)
Definition: Zone.cpp:180
Definition: Server.hpp:192
void set_segment_number(int64_t segment_number)
Definition: Server.hpp:206
Definition: ReferenceListTest.cpp:114
Definition: Server.hpp:554
Definition: Server.hpp:113
The TaskScheduler class provides the ability to schedule std::function's in the near future....
Definition: TaskScheduler.hpp:58
Definition: Element.hpp:7
int natural_heal_sp_interval
Definition: Zone.hpp:68
void set_natural_heal_hp_interval(int interval)
Definition: Zone.hpp:61
void set_natural_heal_sp_interval(int interval)
Definition: Zone.hpp:62
int get_natural_heal_sp_interval()
Definition: Zone.hpp:65
int natural_heal_hp_interval
Definition: Zone.hpp:67
int get_natural_heal_hp_interval()
Definition: Zone.hpp:64
int _max_script_vm_threads
Definition: Zone.hpp:147
int max_network_threads()
Definition: Zone.hpp:128
int _max_persistence_threads
Definition: Zone.hpp:146
s_zone_server_configuration(const s_zone_server_configuration &other)
Definition: Zone.hpp:104
void set_session_max_timeout(std::time_t timeout)
Definition: Zone.hpp:126
int max_persistence_threads()
Definition: Zone.hpp:134
int max_script_vm_threads()
Definition: Zone.hpp:137
std::time_t _session_max_timeout
Definition: Zone.hpp:142
void set_max_script_vm_threads(int threads)
Definition: Zone.hpp:138
boost::filesystem::path & get_script_root_path()
Definition: Zone.hpp:122
std::time_t session_max_timeout()
Definition: Zone.hpp:125
int max_game_logic_threads()
Definition: Zone.hpp:131
int _max_game_logic_threads
Definition: Zone.hpp:145
void set_script_root_path(boost::filesystem::path p)
Definition: Zone.hpp:123
s_zone_server_configuration & operator=(const s_zone_server_configuration &other)
Definition: Zone.hpp:76
boost::filesystem::path & get_static_db_path()
Definition: Zone.hpp:119
int _max_network_threads
Definition: Zone.hpp:144
boost::filesystem::path & get_mapcache_path()
Definition: Zone.hpp:116
boost::filesystem::path _mapcache_path
Definition: Zone.hpp:141
void set_mapcache_path(boost::filesystem::path p)
Definition: Zone.hpp:117
void set_max_game_logic_threads(int threads)
Definition: Zone.hpp:132
s_zone_server_configuration(s_zone_server_configuration &&other)
Definition: Zone.hpp:92
void set_max_network_threads(int threads)
Definition: Zone.hpp:129
void set_static_db_path(boost::filesystem::path p)
Definition: Zone.hpp:120
void set_max_persistence_threads(int threads)
Definition: Zone.hpp:135
boost::filesystem::path _static_db_path
Definition: Zone.hpp:140
boost::filesystem::path _script_root_path
Definition: Zone.hpp:143
Definition: Unit.hpp:80