Horizon Official Technical Documentation
Horizon::Zone::ZoneKernel Class Reference

#include <Zone.hpp>

+ Inheritance diagram for Horizon::Zone::ZoneKernel:
+ Collaboration diagram for Horizon::Zone::ZoneKernel:

Public Member Functions

 ZoneKernel (s_zone_server_configuration &config)
 
 ~ZoneKernel ()
 
void initialize ()
 
void finalize ()
 
s_zone_server_configurationconfig ()
 
void set_config (s_zone_server_configuration &config)
 
TaskSchedulergetScheduler ()
 
void verify_connected_sessions ()
 
- Public Member Functions inherited from Server
 Server ()
 
 ~Server ()
 
void parse_exec_args (const char *argv[], int argc)
 
virtual void initialize ()
 
virtual void finalize ()
 
virtual void post_initialize ()
 
virtual void post_finalize ()
 
void print_help ()
 
struct general_server_configurationgeneral_conf ()
 
bool parse_common_configs (sol::table &cfg)
 
std::shared_ptr< boost::mysql::tcp_ssl_connection > get_database_connection ()
 
bool test_database_connection ()
 
- Public Member Functions inherited from Kernel
 Kernel (general_server_configuration &config)
 
 ~Kernel ()
 
virtual void initialize ()=0
 
virtual void finalize ()=0
 
virtual void post_initialize ()=0
 
virtual void post_finalize ()=0
 
struct general_server_configurationgeneral_conf ()
 
template<typename T >
std::shared_ptr< T > get_component (std::string uuid)
 
template<typename T >
std::shared_ptr< T > get_component_of_type (Horizon::System::runtime_module_type type, int segment_number=1)
 
template<typename T >
void register_component (Horizon::System::runtime_module_type type, T &&component)
 
template<typename T >
void register_component (Horizon::System::runtime_module_type type, std::shared_ptr< T > component)
 
void deregister_component (Horizon::System::runtime_module_type type, int segment_number=1)
 
int get_registered_component_count_of_type (Horizon::System::runtime_module_type type)
 
template<typename ComponentType , std::size_t Priority, typename Key , typename Value >
int get_segment_number_for_resource (Horizon::System::runtime_module_type module_t, Key resource_key, Value resource_not_found_value)
 
int get_component_count ()
 
KernelComponentsget_components ()
 
void system_routine_queue_push (std::shared_ptr< Horizon::System::RuntimeContext > context)
 
void system_routine_queue_push (std::shared_ptr< Horizon::System::RuntimeContextChain > context)
 
void system_routine_process_queue ()
 
void system_routine_register (Horizon::System::runtime_module_type module_t, Horizon::System::runtime_synchronization_method sync_t, std::shared_ptr< Horizon::System::RuntimeContext > context)
 
Horizon::System::SystemRoutineManagerget_system_routine_manager ()
 
boost::asio::io_context & get_io_context ()
 
void set_signal_interrupt_command_line_loop (bool signal)
 
bool get_signal_interrupt_command_line_loop ()
 

Protected Attributes

TaskScheduler _task_scheduler
 
s_zone_server_configuration _config
 
- Protected Attributes inherited from Server
struct general_server_configuration general_config
 
- Protected Attributes inherited from Kernel
boost::asio::io_context _io_context_global
 
KernelComponents _components
 
general_server_configuration _config
 

Constructor & Destructor Documentation

◆ ZoneKernel()

ZoneKernel::ZoneKernel ( s_zone_server_configuration config)
44{
45
46}
s_zone_server_configuration & config()
Definition: Zone.hpp:159
s_zone_server_configuration _config
Definition: Zone.hpp:168
Server()
Definition: Server.cpp:300

◆ ~ZoneKernel()

ZoneKernel::~ZoneKernel ( )
49{
50 if (!get_io_context().stopped())
51 get_io_context().stop();
52}
boost::asio::io_context & get_io_context()
Definition: Server.cpp:70

References Kernel::get_io_context().

+ Here is the call graph for this function:

Member Function Documentation

◆ config()

s_zone_server_configuration & Horizon::Zone::ZoneKernel::config ( )
inline
159{ return _config; }

References _config.

Referenced by set_config(), and verify_connected_sessions().

+ Here is the caller graph for this function:

◆ finalize()

void ZoneKernel::finalize ( )
virtual

Reimplemented from Server.

Reimplemented in Horizon::Zone::ZoneServer.

65{
67
69}
TaskScheduler _task_scheduler
Definition: Zone.hpp:167
virtual void finalize()
Definition: Server.cpp:439
TaskScheduler & CancelAll()
Cancels all tasks. Never call this from within a task context! Use TaskContext::CancelAll instead!
Definition: TaskScheduler.cpp:43

References _task_scheduler, TaskScheduler::CancelAll(), and Server::finalize().

Referenced by Horizon::Zone::ZoneServer::finalize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getScheduler()

TaskScheduler & Horizon::Zone::ZoneKernel::getScheduler ( )
inline
162{ return _task_scheduler; }

References _task_scheduler.

◆ initialize()

void ZoneKernel::initialize ( )
virtual

Reimplemented from Server.

Reimplemented in Horizon::Zone::ZoneServer.

55{
56 _task_scheduler.Schedule(Seconds(0), [this] (TaskContext context) {
58 context.Repeat(Seconds(60));
59 });
60
62}
std::chrono::seconds Seconds
Seconds shorthand typedef.
Definition: TaskScheduler.hpp:34
void verify_connected_sessions()
Definition: Zone.cpp:71
virtual void initialize()
Definition: Server.cpp:425
Definition: TaskScheduler.hpp:487
TaskContext & Repeat(std::chrono::duration< _Rep, _Period > const &duration)
Repeats the event and sets a new duration. std::chrono::seconds(5) for example. This will consume the...
Definition: TaskScheduler.hpp:560
TaskScheduler & Schedule(std::chrono::duration< _Rep, _Period > const &time, task_handler_t const &task)
Schedule an event with a fixed rate. Never call this from within a task context! Use TaskContext::Sch...
Definition: TaskScheduler.hpp:278

References _task_scheduler, Server::initialize(), TaskContext::Repeat(), TaskScheduler::Schedule(), and verify_connected_sessions().

Referenced by Horizon::Zone::ZoneServer::initialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_config()

void Horizon::Zone::ZoneKernel::set_config ( s_zone_server_configuration config)
inline
160{ _config = config; }

References _config, and config().

+ Here is the call graph for this function:

◆ verify_connected_sessions()

void ZoneKernel::verify_connected_sessions ( )
72{
73 std::shared_ptr<boost::mysql::tcp_ssl_connection> conn = sZone->get_database_connection();
74
75 try {
76 int64_t time = std::time(nullptr) - config().session_max_timeout();
77 boost::mysql::statement stmt = conn->prepare_statement("DELETE FROM `session_data` WHERE `current_server` = ? AND `last_update` < ?");
78 auto b1 = stmt.bind("Z", time);
79 boost::mysql::results results;
80 conn->execute(b1, results);
81
82 stmt = conn->prepare_statement("SELECT COUNT(`game_account_id`) FROM `session_data` WHERE `current_server` = ?");
83 auto b2 = stmt.bind("Z");
84 conn->execute(b2, results);
85
86 if (results.rows().empty()) {
87 HLog(info) << "There are no connected session(s).";
88 return;
89 }
90
91 int32_t count = results.rows()[0][0].as_int64();
92
93 HLog(info) << count << " connected session(s).";
94 } catch (boost::mysql::error_with_diagnostics &err) {
95 HLog(error) << "Error while verifying connected sessions: " << err.what();
96 return;
97 }
98}
#define HLog(type)
Definition: Logger.hpp:122
#define sZone
Definition: Zone.hpp:247
size_t count(GridTypeListContainer< SPECIFIC_TYPE > const &elements, SPECIFIC_TYPE *)
Definition: GridReferenceContainer.hpp:100
std::time_t session_max_timeout()
Definition: Zone.hpp:125

References config(), GridTypeListIterator::count(), HLog, Horizon::Zone::s_zone_server_configuration::session_max_timeout(), and sZone.

Referenced by initialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ _config

s_zone_server_configuration Horizon::Zone::ZoneKernel::_config
protected

Referenced by config(), and set_config().

◆ _task_scheduler

TaskScheduler Horizon::Zone::ZoneKernel::_task_scheduler
protected

The documentation for this class was generated from the following files: