static int on_d2gs_initconn(t_connection * c) { t_d2gs * gs; eventlog(eventlog_level_info, __FUNCTION__, "[%d] client initiated d2gs connection",conn_get_socket(c)); if (!(gs=d2gslist_find_gs_by_ip(conn_get_addr(c)))) { /* reload list and see if any dns addy's has changed */ if (d2gslist_reload(prefs_get_d2gs_list())<0) { eventlog(eventlog_level_error, __FUNCTION__, "error reloading game server list,exitting"); return -1; } /* recheck */ if (!(gs=d2gslist_find_gs_by_ip(conn_get_addr(c)))) { eventlog(eventlog_level_error, __FUNCTION__, "d2gs connection from invalid ip address %s",addr_num_to_ip_str(conn_get_addr(c))); return -1; } } conn_set_class(c,conn_class_d2gs); conn_set_state(c,conn_state_connected); conn_set_d2gs_id(c,d2gs_get_id(gs)); if (handle_d2gs_init(c)<0) { eventlog(eventlog_level_error, __FUNCTION__, "failed to init d2gs connection"); return -1; } return 0; }
extern int d2gslist_create(void) { if (!(d2gslist_head=list_create())) return -1; return d2gslist_reload(prefs_get_d2gs_list()); }
extern int handle_signal(void) { std::time_t now; char const * levels; char * temp; char const * tok; if (signal_data.cancel_quit) { signal_data.cancel_quit=0; if (!signal_data.exit_time) { eventlog(eventlog_level_info,__FUNCTION__,"there is no previous shutdown to be canceled"); } else { signal_data.exit_time=0; eventlog(eventlog_level_info,__FUNCTION__,"shutdown was canceled due to std::signal"); } } if (signal_data.do_quit) { signal_data.do_quit=0; now=std::time(NULL); if (!signal_data.exit_time) { signal_data.exit_time=now+d2cs_prefs_get_shutdown_delay(); } else { signal_data.exit_time-=d2cs_prefs_get_shutdown_decr(); } eventlog(eventlog_level_info,__FUNCTION__,"the server is going to shutdown in {} minutes",(signal_data.exit_time-now)/60); } if (signal_data.exit_time) { now=std::time(NULL); if (now >= (signed)signal_data.exit_time) { signal_data.exit_time=0; eventlog(eventlog_level_info,__FUNCTION__,"shutdown server due to std::signal"); return -1; } } if (signal_data.reload_config) { signal_data.reload_config=0; eventlog(eventlog_level_info,__FUNCTION__,"reloading configuartion file due to std::signal"); if (prefs_reload(cmdline_get_preffile())<0) { eventlog(eventlog_level_error,__FUNCTION__,"error reload configuration file,exitting"); return -1; } if (d2gslist_reload(prefs_get_d2gs_list())<0) { eventlog(eventlog_level_error,__FUNCTION__,"error reloading game server list,exitting"); return -1; } if (trans_reload(d2cs_prefs_get_transfile(),TRANS_D2CS)<0) { eventlog(eventlog_level_error,__FUNCTION__,"could not reload trans list"); } eventlog_clear_level(); if ((levels = d2cs_prefs_get_loglevels())) { temp = xstrdup(levels); tok = std::strtok(temp,","); /* std::strtok modifies the string it is passed */ while (tok) { if (eventlog_add_level(tok)<0) eventlog(eventlog_level_error,__FUNCTION__,"could not add std::log level \"{}\"",tok); tok = std::strtok(NULL,","); } xfree(temp); } #ifdef DO_DAEMONIZE if (!cmdline_get_foreground()) #endif eventlog_open(d2cs_prefs_get_logfile()); } if (signal_data.reload_ladder) { signal_data.reload_ladder=0; eventlog(eventlog_level_info,__FUNCTION__,"reloading ladder data due to std::signal"); d2ladder_refresh(); } if (signal_data.restart_d2gs) { signal_data.restart_d2gs=0; eventlog(eventlog_level_info,__FUNCTION__,"restarting all game servers due to std::signal"); d2gs_restart_all_gs(); } return 0; }
extern int handle_signal(void) { time_t now; char const * levels; char * temp; char const * tok; if (signal_data.cancel_quit) { signal_data.cancel_quit=0; if (!signal_data.exit_time) { log_info("there is no previous shutdown to be canceled"); } else { signal_data.exit_time=0; log_info("shutdown was canceled due to signal"); } } if (signal_data.do_quit) { signal_data.do_quit=0; now=time(NULL); if (!signal_data.exit_time) { signal_data.exit_time=now+prefs_get_shutdown_delay(); } else { signal_data.exit_time-=prefs_get_shutdown_decr(); } if (now >= signal_data.exit_time) { log_info("shutdown server due to signal"); return -1; } log_info("the server is going to shutdown in %lu minutes",(signal_data.exit_time-now)/60); } if (signal_data.reload_config) { signal_data.reload_config=0; log_info("reloading configuartion file due to signal"); if (prefs_reload(cmdline_get_prefs_file())<0) { log_error("error reload configuration file,exitting"); return -1; } if (d2gslist_reload(prefs_get_d2gs_list())<0) { log_error("error reloading game server list,exitting"); return -1; } eventlog_clear_level(); if ((levels = prefs_get_loglevels())) { if (!(temp = strdup(levels))) { eventlog(eventlog_level_fatal,"handle_signal","could not allocate memory for temp (exiting)"); return -1; } tok = strtok(temp,","); /* strtok modifies the string it is passed */ while (tok) { if (eventlog_add_level(tok)<0) eventlog(eventlog_level_error,"handle_signal","could not add log level \"%s\"",tok); tok = strtok(NULL,","); } free(temp); } if (!cmdline_get_logstderr()) eventlog_open(prefs_get_logfile()); } if (signal_data.reload_ladder) { signal_data.reload_ladder=0; log_info("reloading ladder data due to signal"); d2ladder_refresh(); } return 0; }
extern int d2gslist_create(void) { d2gslist_head=list_create(); return d2gslist_reload(prefs_get_d2gs_list()); }