Horizon Official Technical Documentation
Horizon::Auth::AuthServer Class Reference

#include <Auth.hpp>

+ Inheritance diagram for Horizon::Auth::AuthServer:
+ Collaboration diagram for Horizon::Auth::AuthServer:

Public Member Functions

 AuthServer ()
 Horizon Constructor. More...
 
 ~AuthServer ()
 Horizon Destructor. More...
 
bool read_config ()
 Read /config/horizon-server.yaml. More...
 
void initialize () override
 
void finalize () override
 
void generate_salt (std::vector< unsigned char > &salt)
 
void hash_password (const std::string &password, const std::vector< unsigned char > &salt, std::vector< unsigned char > &hash)
 
void initialize_cli_commands ()
 Initialize CLI Comamnds. More...
 
bool clicmd_reload_config (std::string)
 CLI Command: Reload Configuration. More...
 
bool clicmd_create_new_account (std::string)
 
bool clicmd_reset_password (std::string)
 
void verify_connected_sessions ()
 
TaskSchedulergetScheduler ()
 
auth_config_typeget_auth_config ()
 
void update (uint64_t time)
 
- 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 ()
 

Static Public Member Functions

static AuthServergetInstance ()
 

Protected Attributes

TaskScheduler _task_scheduler
 
std::mutex _conf_lock
 
auth_config_type _auth_config
 
boost::asio::deadline_timer _update_timer
 
- 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

◆ AuthServer()

AuthServer::AuthServer ( )

Horizon Constructor.

44{
45}
boost::asio::deadline_timer _update_timer
Definition: Auth.hpp:125
boost::asio::io_context & get_io_context()
Definition: Server.cpp:70
Server()
Definition: Server.cpp:300

◆ ~AuthServer()

AuthServer::~AuthServer ( )

Horizon Destructor.

51{
52}

Member Function Documentation

◆ clicmd_create_new_account()

bool AuthServer::clicmd_create_new_account ( std::string  cmd)
150{
151 std::vector<std::string> separated_args;
152 std::string help_str = "Usage: create-account <username> <password> <email> <birthdate: YYYY-MM-DD> <pincode> {"
153 "{<account_gender = 'M' or 'F' or 'C' (Character Dependent)>}, {<group_id>}, {<character_slots>}}";
154
155 boost::algorithm::split(separated_args, cmd, boost::algorithm::is_any_of(" "));
156
157 if (separated_args.size() < 6) {
158 HLog(error) << "create-account command requires at least 5 arguments.";
159 HLog(error) << help_str;
160 return false;
161 }
162
163 std::string username = separated_args[1];
164 std::string password = separated_args[2];
165 std::string email = separated_args[3];
166 std::string birthdate = separated_args[4];
167 std::string pincode = separated_args[5];
168
169 game_account_gender_type gender = separated_args.size() >= 7 ? ((separated_args[6] == "M" ? ACCOUNT_GENDER_MALE : (separated_args[6] == "F" ? ACCOUNT_GENDER_FEMALE : ACCOUNT_GENDER_NONE))) : ACCOUNT_GENDER_NONE;
170 int group_id = separated_args.size() >= 8 ? std::stoi(separated_args[7]) : 0;
171 int character_slots = separated_args.size() >= 9 ? std::stoi(separated_args[8]) : 3;
172
173 try {
174 auto b1 = get_database_connection()->prepare_statement("SELECT `id` FROM game_accounts WHERE `username` = ?").bind(username);
175 boost::mysql::results results;
176 get_database_connection()->execute(b1, results);
177
178 if (!results.rows().empty()) {
179 HLog(error) << "Account with username '" << username << "' already exists.";
180 return false;
181 }
182
183 std::vector<unsigned char> salt;
184 std::vector<unsigned char> hash;
185
186 sAuth->generate_salt(salt);
187 sAuth->hash_password(password, salt, hash);
188 boost::mysql::statement stmt = get_database_connection()->prepare_statement("INSERT INTO `game_accounts` (`username`, `hash`, `salt`, `gender`, `email`, `birth_date`, `character_slots`, `pincode`, `group_id`, `state`) "
189 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
190 auto b2 = stmt.bind(username, hash, salt, gender == ACCOUNT_GENDER_MALE ? "M" : (gender == ACCOUNT_GENDER_FEMALE ? "F" : "NA"),
191 email, birthdate, character_slots, pincode, group_id, (int)ACCOUNT_STATE_NONE);
192 get_database_connection()->execute(b2, results);
193 }
194 catch (boost::mysql::error_with_diagnostics &error) {
195 HLog(error) << error.what();
196 return false;
197 }
198
199 HLog(info) << "Account '" << username << "' has been created successfully.";
200
201 return true;
202}
#define sAuth
Definition: Auth.hpp:131
@ ACCOUNT_STATE_NONE
Definition: Database.hpp:41
game_account_gender_type
Definition: Database.hpp:33
@ ACCOUNT_GENDER_MALE
Definition: Database.hpp:34
@ ACCOUNT_GENDER_NONE
Definition: Database.hpp:36
@ ACCOUNT_GENDER_FEMALE
Definition: Database.hpp:35
#define HLog(type)
Definition: Logger.hpp:122
std::shared_ptr< boost::mysql::tcp_ssl_connection > get_database_connection()
Definition: Server.hpp:574

References ACCOUNT_GENDER_FEMALE, ACCOUNT_GENDER_MALE, ACCOUNT_GENDER_NONE, ACCOUNT_STATE_NONE, Server::get_database_connection(), HLog, and sAuth.

Referenced by initialize_cli_commands().

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

◆ clicmd_reload_config()

bool AuthServer::clicmd_reload_config ( std::string  )

CLI Command: Reload Configuration.

Returns
boolean value from AuthServer->ReadConfig()
143{
144 HLog(info) << "Reloading configuration from '" << general_conf().get_config_file_path() << "'";
145
146 return read_config();
147}
bool read_config()
Read /config/horizon-server.yaml.
Definition: Auth.cpp:61
struct general_server_configuration & general_conf()
Definition: Server.hpp:570
const boost::filesystem::path & get_config_file_path() const
Definition: ServerConfiguration.hpp:55

References Server::general_conf(), general_server_configuration::get_config_file_path(), HLog, and read_config().

Referenced by initialize_cli_commands().

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

◆ clicmd_reset_password()

bool AuthServer::clicmd_reset_password ( std::string  cmd)
205{
206 std::vector<std::string> separated_args;
207 std::string help_str = "Usage: reset-password <username> <new_password>";
208
209 boost::algorithm::split(separated_args, cmd, boost::algorithm::is_any_of(" "));
210
211 if (separated_args.size() < 3) {
212 HLog(error) << "reset-password command requires 2 arguments.";
213 HLog(error) << help_str;
214 return false;
215 }
216
217 std::string username = separated_args[1];
218 std::string new_password = separated_args[2];
219
220 try {
221 auto b1 = get_database_connection()->prepare_statement("SELECT `id` FROM game_accounts WHERE `username` = ?").bind(username);
222 boost::mysql::results results;
223 get_database_connection()->execute(b1, results);
224
225 if (results.rows().empty()) {
226 HLog(error) << "Account with username '" << username << "' does not exist.";
227 return false;
228 }
229
230 std::vector<unsigned char> salt;
231
232 sAuth->generate_salt(salt);
233
234 std::vector<unsigned char> hash;
235 sAuth->hash_password(new_password, salt, hash);
236
237 boost::mysql::statement stmt = get_database_connection()->prepare_statement("UPDATE `game_accounts` SET `hash` = ?, `salt` = ? WHERE `username` = ?");
238 auto b2 = stmt.bind(hash, salt, username);
239 get_database_connection()->execute(b2, results);
240
241 HLog(info) << "Password for account '" << username << "' has been reset successfully.";
242 }
243 catch (boost::mysql::error_with_diagnostics &error) {
244 HLog(error) << error.what();
245 return false;
246 }
247 return true;
248}

References Server::get_database_connection(), HLog, and sAuth.

Referenced by initialize_cli_commands().

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

◆ finalize()

void AuthServer::finalize ( )
overridevirtual

Server shutdown routine begins here...

Reimplemented from Server.

391{
392 HLog(info) << "Shutdown process initiated...";
393
394 if (!get_io_context().stopped())
395 get_io_context().stop();
396
401
403}
virtual void post_finalize()
Definition: Server.cpp:459
virtual void finalize()
Definition: Server.cpp:439

References Server::finalize(), Kernel::get_io_context(), HLog, and Server::post_finalize().

Referenced by update().

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

◆ generate_salt()

void Horizon::Auth::AuthServer::generate_salt ( std::vector< unsigned char > &  salt)
inline
88 {
89 salt.resize(SALT_LEN);
90 if (!RAND_bytes(salt.data(), SALT_LEN)) {
91 throw std::runtime_error("Failed to generate salt");
92 }
93 }
const int SALT_LEN
Definition: Auth.hpp:67

References Horizon::Auth::SALT_LEN.

◆ get_auth_config()

auth_config_type & Horizon::Auth::AuthServer::get_auth_config ( )
inline
114 {
115 std::lock_guard<std::mutex> lock(_conf_lock);
116 return _auth_config;
117 }
std::mutex _conf_lock
Definition: Auth.hpp:123
auth_config_type _auth_config
Definition: Auth.hpp:124

References _auth_config, and _conf_lock.

Referenced by initialize(), read_config(), and verify_connected_sessions().

+ Here is the caller graph for this function:

◆ getInstance()

static AuthServer * Horizon::Auth::AuthServer::getInstance ( )
inlinestatic
78 {
79 static AuthServer instance;
80 return &instance;
81 }
AuthServer()
Horizon Constructor.
Definition: Auth.cpp:42

◆ getScheduler()

TaskScheduler & Horizon::Auth::AuthServer::getScheduler ( )
inline
111{ return _task_scheduler; }
TaskScheduler _task_scheduler
Definition: Auth.hpp:122

References _task_scheduler.

Referenced by update().

+ Here is the caller graph for this function:

◆ hash_password()

void Horizon::Auth::AuthServer::hash_password ( const std::string &  password,
const std::vector< unsigned char > &  salt,
std::vector< unsigned char > &  hash 
)
inline
95 {
96 hash.resize(HASH_LEN);
97 if (!PKCS5_PBKDF2_HMAC(password.c_str(), password.length(), salt.data(), salt.size(), ITERATIONS, EVP_sha256(), HASH_LEN, hash.data())) {
98 throw std::runtime_error("Failed to hash password");
99 }
100 }
const int HASH_LEN
Definition: Auth.hpp:68
const int ITERATIONS
Definition: Auth.hpp:69

References Horizon::Auth::HASH_LEN, and Horizon::Auth::ITERATIONS.

◆ initialize()

void AuthServer::initialize ( )
overridevirtual

Core Signal Handler

Reimplemented from Server.

343{
347 signal(SIGINT, SignalHandler);
348 signal(SIGTERM, SignalHandler);
349#ifndef WIN32
350 signal(SIGQUIT, SignalHandler);
351#endif
352
353 // Start Horizon Network
355 general_conf().get_listen_ip(),
356 general_conf().get_listen_port(),
357 get_auth_config().max_network_threads(),
358 general_conf().is_test_run() && general_conf().is_test_run_with_network() == false);
359
360 // Initialize core.
362
364
366
367 _update_timer.expires_from_now(boost::posix_time::microseconds(MAX_CORE_UPDATE_INTERVAL));
368 _update_timer.async_wait(std::bind(&AuthServer::update, this, MAX_CORE_UPDATE_INTERVAL));
369
370 _task_scheduler.Schedule(Seconds(0), [this] (TaskContext context) {
372 context.Repeat(Seconds(60));
373 });
374
375 // Run the io_context until stop is called from the internal, finalizing thread.
376 // After stopping, execution will continue through the next line onwards.
377 // We actually finalize on this thread and not in any of io_context's internal threads.
378 get_io_context().run();
379
380 /*
381 * Core Cleanup
382 */
383 HLog(info) << "Server shutting down...";
384
386
388}
#define sClientSocketMgr
Definition: ClientSocketMgr.hpp:176
void SignalHandler(int signal_num)
Signal Handler from the main thread.
Definition: Auth.cpp:299
#define MAX_CORE_UPDATE_INTERVAL
Definition: Horizon.hpp:63
#define HLogShutdown
Definition: Logger.hpp:123
@ SHUTDOWN_CLEANUP_COMPLETE
Definition: Server.hpp:66
void set_shutdown_stage(shutdown_stages new_stage)
Definition: Server.hpp:75
std::chrono::seconds Seconds
Seconds shorthand typedef.
Definition: TaskScheduler.hpp:34
auth_config_type & get_auth_config()
Definition: Auth.hpp:113
void initialize_cli_commands()
Initialize CLI Comamnds.
Definition: Auth.cpp:253
void verify_connected_sessions()
Definition: Auth.cpp:263
void update(uint64_t time)
Definition: Auth.cpp:311
virtual void initialize()
Definition: Server.cpp:425
virtual void post_initialize()
Definition: Server.cpp:450
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, _update_timer, Server::general_conf(), get_auth_config(), Kernel::get_io_context(), HLog, HLogShutdown, Server::initialize(), initialize_cli_commands(), MAX_CORE_UPDATE_INTERVAL, Server::post_initialize(), TaskContext::Repeat(), TaskScheduler::Schedule(), sClientSocketMgr, set_shutdown_stage(), SHUTDOWN_CLEANUP_COMPLETE, SignalHandler(), update(), and verify_connected_sessions().

+ Here is the call graph for this function:

◆ initialize_cli_commands()

void AuthServer::initialize_cli_commands ( )

Initialize CLI Comamnds.

254{
255 if (general_conf().is_test_run() && general_conf().is_test_run_minimal())
256 return;
257
258 get_component_of_type<CommandLineProcess>(Horizon::System::RUNTIME_COMMANDLINE)->add_function("reloadconf", std::bind(&AuthServer::clicmd_reload_config, this, std::placeholders::_1));
259 get_component_of_type<CommandLineProcess>(Horizon::System::RUNTIME_COMMANDLINE)->add_function("create-account", std::bind(&AuthServer::clicmd_create_new_account, this, std::placeholders::_1));
260 get_component_of_type<CommandLineProcess>(Horizon::System::RUNTIME_COMMANDLINE)->add_function("reset-password", std::bind(&AuthServer::clicmd_reset_password, this, std::placeholders::_1));
261}
bool clicmd_reset_password(std::string)
Definition: Auth.cpp:204
bool clicmd_reload_config(std::string)
CLI Command: Reload Configuration.
Definition: Auth.cpp:142
bool clicmd_create_new_account(std::string)
Definition: Auth.cpp:149
@ RUNTIME_COMMANDLINE
Definition: System.hpp:83

References clicmd_create_new_account(), clicmd_reload_config(), clicmd_reset_password(), Server::general_conf(), and Horizon::System::RUNTIME_COMMANDLINE.

Referenced by initialize().

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

◆ read_config()

bool AuthServer::read_config ( )

Read /config/horizon-server.yaml.

Returns
true on success, false on failure.

Process Configuration that is common between servers.

62{
63 sol::state lua;
64
65 std::string file_path = general_conf().get_config_file_path().string();
66 std::string tmp_string;
67 sol::table tbl;
68
69 if (!boost::filesystem::exists(file_path)) {
70 HLog(error) << "Configuration file does not exist at " << file_path << "." << std::endl;
71 return false;
72 }
73
74 // Read the file. If there is an error, report it and exit.
75 try {
76 lua.script_file(file_path);
77 tbl = lua["horizon_config"];
78 } catch (const std::exception &error) {
79 HLog(error) << "Horizon::ReadConfig: '" << error.what() << "'.";
80 return false;
81 }
82
83 try {
84 sol::table char_servers = tbl.get<sol::table>("character_servers");
85 char_servers.for_each([&](sol::object const &key, sol::object const &value) {
87 sol::table cfg = value.as<sol::table>();
88
89 c._name = cfg.get<std::string>("Name");
90 c._host = cfg.get<std::string>("Host");
91 c._port = cfg.get<uint16_t>("Port");
92 c._type = cfg.get<uint16_t>("Type");
93 c._is_new = cfg.get<uint16_t>("IsNew");
94
96
97 HLog(info) << "Character server '" << c._name << "' is configured.";
98 });
99 } catch (std::exception &error) {
100 HLog(error) << "Character server configuration error:" << error.what() << ".";
101 return false;
102 }
103
104 int char_server_count = get_auth_config().get_char_servers().size();
105 HLog(info) << char_server_count << " character servers were configured.";
106
107 // Max network threads
108 if (tbl.get<sol::object>("max_network_threads") != sol::lua_nil) {
109 get_auth_config().set_max_network_threads(tbl.get<int>("max_network_threads"));
110 } else {
111 horizon_config_error("max_network_threads", 1);
112 }
113
114 try {
115 int32_t session_max_timeout = tbl.get_or("session_max_timeout", 60);
116 get_auth_config().set_session_max_timeout(session_max_timeout);
117 HLog(info) << "Session maximum timeout set to '" << get_auth_config().session_max_timeout() << "',"
118 << " sessions surpassing this time limit will be disconnected.";
119 } catch (sol::error &err) {
120 HLog(error) << "Error for setting session_max_timeout:" << err.what();
121 }
122
123 HLog(info) << "Max Network Threads set to '" << get_auth_config().max_network_threads() << "'.";
124
128 if (!parse_common_configs(tbl))
129 return false;
130
131 HLog(info) << "Done reading server configuration from '" << file_path << "'.";
132
133 return true;
134}
#define horizon_config_error(setting_name, default)
Definition: Auth.cpp:54
bool parse_common_configs(sol::table &cfg)
Definition: Server.cpp:372
uint16_t _is_new
Definition: Auth.hpp:50
std::string _name
Definition: Auth.hpp:49
uint16_t _port
Definition: Auth.hpp:50
std::string _host
Definition: Auth.hpp:49
uint16_t _type
Definition: Auth.hpp:50
void set_session_max_timeout(int timeout)
Definition: Auth.hpp:60
void add_char_server(char_server c)
Definition: Auth.hpp:53
void set_max_network_threads(int threads)
Definition: Auth.hpp:57
std::vector< char_server > & get_char_servers()
Definition: Auth.hpp:54
int max_network_threads()
Definition: Auth.hpp:56
int session_max_timeout()
Definition: Auth.hpp:59

References Horizon::Auth::auth_config_type::char_server::_host, Horizon::Auth::auth_config_type::char_server::_is_new, Horizon::Auth::auth_config_type::char_server::_name, Horizon::Auth::auth_config_type::char_server::_port, Horizon::Auth::auth_config_type::char_server::_type, Horizon::Auth::auth_config_type::add_char_server(), Server::general_conf(), get_auth_config(), Horizon::Auth::auth_config_type::get_char_servers(), general_server_configuration::get_config_file_path(), HLog, horizon_config_error, Horizon::Auth::auth_config_type::max_network_threads(), Server::parse_common_configs(), Horizon::Auth::auth_config_type::session_max_timeout(), Horizon::Auth::auth_config_type::set_max_network_threads(), and Horizon::Auth::auth_config_type::set_session_max_timeout().

Referenced by clicmd_reload_config().

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

◆ update()

void AuthServer::update ( uint64_t  time)

Cancel all pending tasks.

Stop all networks

312{
314
315 sClientSocketMgr->manage_sockets(time);
316 sClientSocketMgr->update_sessions(time);
317
318 if (get_shutdown_stage() == SHUTDOWN_NOT_STARTED && !general_conf().is_test_run_minimal()) {
319 _update_timer.expires_from_now(boost::posix_time::microseconds(MAX_CORE_UPDATE_INTERVAL));
320 _update_timer.async_wait(std::bind(&AuthServer::update, this, std::time(nullptr)));
322 } else {
323
324 for (auto i = _components.begin(); i != _components.end(); i++) {
325 HLog(info) << "Kernel component '" << i->second.ptr->get_type_string() << " (" << i->second.segment_number << ")': " << (i->second.ptr->is_finalized() == true ? "Offline" : "Online (Shutting Down)") << " { CPU: " << i->second.ptr->get_thread_cpu_id() << ", uuid: " << i->first << " }";
326 }
327
332
336 sClientSocketMgr->stop();
337
338 finalize();
339 }
340}
shutdown_stages get_shutdown_stage()
Definition: Server.hpp:74
@ SHUTDOWN_NOT_STARTED
Definition: Server.hpp:64
TaskScheduler & getScheduler()
Definition: Auth.hpp:111
void finalize() override
Definition: Auth.cpp:390
KernelComponents _components
Definition: Server.hpp:545
TaskScheduler & CancelAll()
Cancels all tasks. Never call this from within a task context! Use TaskContext::CancelAll instead!
Definition: TaskScheduler.cpp:43
TaskScheduler & Update(success_t const &callback=EmptyCallback)
Update the scheduler to the current time. Calls the optional callback on successfully finish.
Definition: TaskScheduler.cpp:25

References Kernel::_components, _task_scheduler, _update_timer, TaskScheduler::CancelAll(), finalize(), Server::general_conf(), get_shutdown_stage(), getScheduler(), HLog, MAX_CORE_UPDATE_INTERVAL, sClientSocketMgr, SHUTDOWN_NOT_STARTED, TaskScheduler::Update(), and update().

Referenced by initialize(), and update().

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

◆ verify_connected_sessions()

void AuthServer::verify_connected_sessions ( )
264{
265 try {
266 std::shared_ptr<boost::mysql::tcp_ssl_connection> conn = sAuth->get_database_connection();
267 boost::mysql::statement stmt = conn->prepare_statement("DELETE FROM `session_data` WHERE `current_server` = ? AND `last_update` < ?");
268 auto b = stmt.bind("A", std::time(nullptr) - get_auth_config().session_max_timeout());
269 boost::mysql::results results;
270 conn->execute(b, results);
271
272 stmt = conn->prepare_statement("SELECT COUNT(`game_account_id`) FROM `session_data` WHERE `current_server` = ?");
273 auto b2 = stmt.bind("A");
274 conn->execute(b2, results);
275
276 if (results.rows().empty()) {
277 HLog(info) << "There are no connected session(s).";
278 return;
279 }
280
281 int32_t count = results.rows()[0][0].as_int64();
282
283 HLog(info) << count << " connected session(s).";
284
285 }
286 catch (boost::mysql::error_with_diagnostics &error) {
287 HLog(error) << error.what();
288 }
289 catch (std::exception& error) {
290 HLog(error) << error.what();
291 }
292}
size_t count(GridTypeListContainer< SPECIFIC_TYPE > const &elements, SPECIFIC_TYPE *)
Definition: GridReferenceContainer.hpp:100

References GridTypeListIterator::count(), get_auth_config(), HLog, and sAuth.

Referenced by initialize().

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

Member Data Documentation

◆ _auth_config

auth_config_type Horizon::Auth::AuthServer::_auth_config
protected

Referenced by get_auth_config().

◆ _conf_lock

std::mutex Horizon::Auth::AuthServer::_conf_lock
protected

Referenced by get_auth_config().

◆ _task_scheduler

TaskScheduler Horizon::Auth::AuthServer::_task_scheduler
protected

Referenced by getScheduler(), initialize(), and update().

◆ _update_timer

boost::asio::deadline_timer Horizon::Auth::AuthServer::_update_timer
protected

Referenced by initialize(), and update().


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