- "main" entry point for Lua scripts, when all the scripts are loaded and user can make initialiation there
- load Lua scripts alphabetically and recursively: first directories and then files
This commit is contained in:
parent
6a43773b43
commit
e17fa89497
3 changed files with 142 additions and 130 deletions
src
|
@ -82,6 +82,7 @@ namespace pvpgn
|
|||
|
||||
try
|
||||
{
|
||||
// init lua virtual machine
|
||||
vm.initialize();
|
||||
|
||||
std::vector<std::string> files = dir_getfiles(scriptdir, ".lua", true);
|
||||
|
@ -108,6 +109,9 @@ namespace pvpgn
|
|||
{
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "lua exception\n");
|
||||
}
|
||||
|
||||
// handle start event
|
||||
lua_handle_server(0, luaevent_server_start);
|
||||
}
|
||||
|
||||
|
||||
|
@ -146,137 +150,136 @@ namespace pvpgn
|
|||
g.update("PVPGN_SOFTWARE", PVPGN_SOFTWARE);
|
||||
g.update("PVPGN_VERSION", PVPGN_VERSION);
|
||||
|
||||
|
||||
// config variables from bnetd.conf
|
||||
lua::transaction bind(vm);
|
||||
bind.lookup("config");
|
||||
{
|
||||
lua::table bnetd = bind.table();
|
||||
g.update("filedir", prefs_get_filedir());
|
||||
g.update("scriptdir", prefs_get_scriptdir());
|
||||
g.update("reportdir", prefs_get_reportdir());
|
||||
g.update("chanlogdir", prefs_get_chanlogdir());
|
||||
g.update("motdfile", prefs_get_motdfile());
|
||||
g.update("motdw3file", prefs_get_motdw3file());
|
||||
g.update("issuefile", prefs_get_issuefile());
|
||||
g.update("channelfile", prefs_get_channelfile());
|
||||
g.update("newsfile", prefs_get_newsfile());
|
||||
g.update("adfile", prefs_get_adfile());
|
||||
g.update("topicfile", prefs_get_topicfile());
|
||||
g.update("ipbanfile", prefs_get_ipbanfile());
|
||||
g.update("helpfile", prefs_get_helpfile());
|
||||
g.update("mpqfile", prefs_get_mpqfile());
|
||||
g.update("logfile", prefs_get_logfile());
|
||||
g.update("realmfile", prefs_get_realmfile());
|
||||
g.update("maildir", prefs_get_maildir());
|
||||
g.update("versioncheck_file", prefs_get_versioncheck_file());
|
||||
g.update("mapsfile", prefs_get_mapsfile());
|
||||
g.update("xplevelfile", prefs_get_xplevel_file());
|
||||
g.update("xpcalcfile", prefs_get_xpcalc_file());
|
||||
g.update("ladderdir", prefs_get_ladderdir());
|
||||
g.update("command_groups_file", prefs_get_command_groups_file());
|
||||
g.update("tournament_file", prefs_get_tournament_file());
|
||||
g.update("statusdir", prefs_get_outputdir());
|
||||
g.update("aliasfile", prefs_get_aliasfile());
|
||||
g.update("anongame_infos_file", prefs_get_anongame_infos_file());
|
||||
g.update("DBlayoutfile", prefs_get_DBlayoutfile());
|
||||
g.update("supportfile", prefs_get_supportfile());
|
||||
g.update("transfile", prefs_get_transfile());
|
||||
g.update("customicons_file", prefs_get_customicons_file());
|
||||
g.update("loglevels", prefs_get_loglevels());
|
||||
g.update("d2cs_version", prefs_get_d2cs_version());
|
||||
g.update("allow_d2cs_setname", prefs_allow_d2cs_setname());
|
||||
g.update("iconfile", prefs_get_iconfile());
|
||||
g.update("war3_iconfile", prefs_get_war3_iconfile());
|
||||
g.update("star_iconfile", prefs_get_star_iconfile());
|
||||
g.update("tosfile", prefs_get_tosfile());
|
||||
g.update("allowed_clients", prefs_get_allowed_clients());
|
||||
g.update("skip_versioncheck", prefs_get_skip_versioncheck());
|
||||
g.update("allow_bad_version", prefs_get_allow_bad_version());
|
||||
g.update("allow_unknown_version", prefs_get_allow_unknown_version());
|
||||
g.update("version_exeinfo_match", prefs_get_version_exeinfo_match());
|
||||
g.update("version_exeinfo_maxdiff", prefs_get_version_exeinfo_maxdiff());
|
||||
g.update("usersync", prefs_get_user_sync_timer());
|
||||
g.update("userflush", prefs_get_user_flush_timer());
|
||||
g.update("userstep", prefs_get_user_step());
|
||||
g.update("latency", prefs_get_latency());
|
||||
g.update("nullmsg", prefs_get_nullmsg());
|
||||
g.update("shutdown_delay", prefs_get_shutdown_delay());
|
||||
g.update("shutdown_decr", prefs_get_shutdown_decr());
|
||||
g.update("ipban_check_int", prefs_get_ipban_check_int());
|
||||
g.update("new_accounts", prefs_get_allow_new_accounts());
|
||||
g.update("max_accounts", prefs_get_max_accounts());
|
||||
g.update("kick_old_login", prefs_get_kick_old_login());
|
||||
g.update("ask_new_channel", prefs_get_ask_new_channel());
|
||||
g.update("report_all_games", prefs_get_report_all_games());
|
||||
g.update("report_diablo_games", prefs_get_report_diablo_games());
|
||||
g.update("hide_pass_games", prefs_get_hide_pass_games());
|
||||
g.update("hide_started_games", prefs_get_hide_started_games());
|
||||
g.update("hide_temp_channels", prefs_get_hide_temp_channels());
|
||||
g.update("extra_commands", prefs_get_extra_commands());
|
||||
g.update("disc_is_loss", prefs_get_discisloss());
|
||||
g.update("ladder_games", prefs_get_ladder_games());
|
||||
g.update("ladder_prefix", prefs_get_ladder_prefix());
|
||||
g.update("enable_conn_all", prefs_get_enable_conn_all());
|
||||
g.update("hide_addr", prefs_get_hide_addr());
|
||||
g.update("chanlog", prefs_get_chanlog());
|
||||
g.update("quota", prefs_get_quota());
|
||||
g.update("quota_lines", prefs_get_quota_lines());
|
||||
g.update("quota_time", prefs_get_quota_time());
|
||||
g.update("quota_wrapline", prefs_get_quota_wrapline());
|
||||
g.update("quota_maxline", prefs_get_quota_maxline());
|
||||
g.update("quota_dobae", prefs_get_quota_dobae());
|
||||
g.update("mail_support", prefs_get_mail_support());
|
||||
g.update("mail_quota", prefs_get_mail_quota());
|
||||
g.update("log_notice", prefs_get_log_notice());
|
||||
g.update("passfail_count", prefs_get_passfail_count());
|
||||
g.update("passfail_bantime", prefs_get_passfail_bantime());
|
||||
g.update("maxusers_per_channel", prefs_get_maxusers_per_channel());
|
||||
g.update("savebyname", prefs_get_savebyname());
|
||||
g.update("sync_on_logoff", prefs_get_sync_on_logoff());
|
||||
g.update("hashtable_size", prefs_get_hashtable_size());
|
||||
g.update("account_allowed_symbols", prefs_get_account_allowed_symbols());
|
||||
g.update("account_force_username", prefs_get_account_force_username());
|
||||
g.update("max_friends", prefs_get_max_friends());
|
||||
g.update("track", prefs_get_track());
|
||||
g.update("trackaddrs", prefs_get_trackserv_addrs());
|
||||
g.update("location", prefs_get_location());
|
||||
g.update("description", prefs_get_description());
|
||||
g.update("url", prefs_get_url());
|
||||
g.update("contact_name", prefs_get_contact_name());
|
||||
g.update("contact_email", prefs_get_contact_email());
|
||||
g.update("servername", prefs_get_servername());
|
||||
g.update("max_connections", prefs_get_max_connections());
|
||||
g.update("max_concurrent_logins", prefs_get_max_concurrent_logins());
|
||||
g.update("use_keepalive", prefs_get_use_keepalive());
|
||||
g.update("max_conns_per_IP", prefs_get_max_conns_per_IP());
|
||||
g.update("servaddrs", prefs_get_bnetdserv_addrs());
|
||||
g.update("udptest_port", prefs_get_udptest_port());
|
||||
g.update("w3routeaddr", prefs_get_w3route_addr());
|
||||
g.update("initkill_timer", prefs_get_initkill_timer());
|
||||
g.update("wolv1addrs", prefs_get_wolv1_addrs());
|
||||
g.update("wolv2addrs", prefs_get_wolv2_addrs());
|
||||
g.update("wgameresaddrs", prefs_get_wgameres_addrs());
|
||||
g.update("apiregaddrs", prefs_get_apireg_addrs());
|
||||
g.update("woltimezone", prefs_get_wol_timezone());
|
||||
g.update("wollongitude", prefs_get_wol_longitude());
|
||||
g.update("wollatitude", prefs_get_wol_latitude());
|
||||
g.update("wol_autoupdate_serverhost", prefs_get_wol_autoupdate_serverhost());
|
||||
g.update("wol_autoupdate_username", prefs_get_wol_autoupdate_username());
|
||||
g.update("wol_autoupdate_password", prefs_get_wol_autoupdate_password());
|
||||
g.update("ircaddrs", prefs_get_irc_addrs());
|
||||
g.update("irc_network_name", prefs_get_irc_network_name());
|
||||
g.update("hostname", prefs_get_hostname());
|
||||
g.update("irc_latency", prefs_get_irc_latency());
|
||||
g.update("telnetaddrs", prefs_get_telnet_addrs());
|
||||
g.update("war3_ladder_update_secs", prefs_get_war3_ladder_update_secs());
|
||||
g.update("XML_output_ladder", prefs_get_XML_output_ladder());
|
||||
g.update("output_update_secs", prefs_get_output_update_secs());
|
||||
g.update("XML_status_output", prefs_get_XML_status_output());
|
||||
g.update("clan_newer_time", prefs_get_clan_newer_time());
|
||||
g.update("clan_max_members", prefs_get_clan_max_members());
|
||||
g.update("clan_channel_default_private", prefs_get_clan_channel_default_private());
|
||||
g.update("clan_min_invites", prefs_get_clan_min_invites());
|
||||
lua::table config = bind.table();
|
||||
config.update("filedir", prefs_get_filedir());
|
||||
config.update("scriptdir", prefs_get_scriptdir());
|
||||
config.update("reportdir", prefs_get_reportdir());
|
||||
config.update("chanlogdir", prefs_get_chanlogdir());
|
||||
config.update("motdfile", prefs_get_motdfile());
|
||||
config.update("motdw3file", prefs_get_motdw3file());
|
||||
config.update("issuefile", prefs_get_issuefile());
|
||||
config.update("channelfile", prefs_get_channelfile());
|
||||
config.update("newsfile", prefs_get_newsfile());
|
||||
config.update("adfile", prefs_get_adfile());
|
||||
config.update("topicfile", prefs_get_topicfile());
|
||||
config.update("ipbanfile", prefs_get_ipbanfile());
|
||||
config.update("helpfile", prefs_get_helpfile());
|
||||
config.update("mpqfile", prefs_get_mpqfile());
|
||||
config.update("logfile", prefs_get_logfile());
|
||||
config.update("realmfile", prefs_get_realmfile());
|
||||
config.update("maildir", prefs_get_maildir());
|
||||
config.update("versioncheck_file", prefs_get_versioncheck_file());
|
||||
config.update("mapsfile", prefs_get_mapsfile());
|
||||
config.update("xplevelfile", prefs_get_xplevel_file());
|
||||
config.update("xpcalcfile", prefs_get_xpcalc_file());
|
||||
config.update("ladderdir", prefs_get_ladderdir());
|
||||
config.update("command_groups_file", prefs_get_command_groups_file());
|
||||
config.update("tournament_file", prefs_get_tournament_file());
|
||||
config.update("statusdir", prefs_get_outputdir());
|
||||
config.update("aliasfile", prefs_get_aliasfile());
|
||||
config.update("anongame_infos_file", prefs_get_anongame_infos_file());
|
||||
config.update("DBlayoutfile", prefs_get_DBlayoutfile());
|
||||
config.update("supportfile", prefs_get_supportfile());
|
||||
config.update("transfile", prefs_get_transfile());
|
||||
config.update("customicons_file", prefs_get_customicons_file());
|
||||
config.update("loglevels", prefs_get_loglevels());
|
||||
config.update("d2cs_version", prefs_get_d2cs_version());
|
||||
config.update("allow_d2cs_setname", prefs_allow_d2cs_setname());
|
||||
config.update("iconfile", prefs_get_iconfile());
|
||||
config.update("war3_iconfile", prefs_get_war3_iconfile());
|
||||
config.update("star_iconfile", prefs_get_star_iconfile());
|
||||
config.update("tosfile", prefs_get_tosfile());
|
||||
config.update("allowed_clients", prefs_get_allowed_clients());
|
||||
config.update("skip_versioncheck", prefs_get_skip_versioncheck());
|
||||
config.update("allow_bad_version", prefs_get_allow_bad_version());
|
||||
config.update("allow_unknown_version", prefs_get_allow_unknown_version());
|
||||
config.update("version_exeinfo_match", prefs_get_version_exeinfo_match());
|
||||
config.update("version_exeinfo_maxdiff", prefs_get_version_exeinfo_maxdiff());
|
||||
config.update("usersync", prefs_get_user_sync_timer());
|
||||
config.update("userflush", prefs_get_user_flush_timer());
|
||||
config.update("userstep", prefs_get_user_step());
|
||||
config.update("latency", prefs_get_latency());
|
||||
config.update("nullmsg", prefs_get_nullmsg());
|
||||
config.update("shutdown_delay", prefs_get_shutdown_delay());
|
||||
config.update("shutdown_decr", prefs_get_shutdown_decr());
|
||||
config.update("ipban_check_int", prefs_get_ipban_check_int());
|
||||
config.update("new_accounts", prefs_get_allow_new_accounts());
|
||||
config.update("max_accounts", prefs_get_max_accounts());
|
||||
config.update("kick_old_login", prefs_get_kick_old_login());
|
||||
config.update("ask_new_channel", prefs_get_ask_new_channel());
|
||||
config.update("report_all_games", prefs_get_report_all_games());
|
||||
config.update("report_diablo_games", prefs_get_report_diablo_games());
|
||||
config.update("hide_pass_games", prefs_get_hide_pass_games());
|
||||
config.update("hide_started_games", prefs_get_hide_started_games());
|
||||
config.update("hide_temp_channels", prefs_get_hide_temp_channels());
|
||||
config.update("extra_commands", prefs_get_extra_commands());
|
||||
config.update("disc_is_loss", prefs_get_discisloss());
|
||||
config.update("ladder_games", prefs_get_ladder_games());
|
||||
config.update("ladder_prefix", prefs_get_ladder_prefix());
|
||||
config.update("enable_conn_all", prefs_get_enable_conn_all());
|
||||
config.update("hide_addr", prefs_get_hide_addr());
|
||||
config.update("chanlog", prefs_get_chanlog());
|
||||
config.update("quota", prefs_get_quota());
|
||||
config.update("quota_lines", prefs_get_quota_lines());
|
||||
config.update("quota_time", prefs_get_quota_time());
|
||||
config.update("quota_wrapline", prefs_get_quota_wrapline());
|
||||
config.update("quota_maxline", prefs_get_quota_maxline());
|
||||
config.update("quota_dobae", prefs_get_quota_dobae());
|
||||
config.update("mail_support", prefs_get_mail_support());
|
||||
config.update("mail_quota", prefs_get_mail_quota());
|
||||
config.update("log_notice", prefs_get_log_notice());
|
||||
config.update("passfail_count", prefs_get_passfail_count());
|
||||
config.update("passfail_bantime", prefs_get_passfail_bantime());
|
||||
config.update("maxusers_per_channel", prefs_get_maxusers_per_channel());
|
||||
config.update("savebyname", prefs_get_savebyname());
|
||||
config.update("sync_on_logoff", prefs_get_sync_on_logoff());
|
||||
config.update("hashtable_size", prefs_get_hashtable_size());
|
||||
config.update("account_allowed_symbols", prefs_get_account_allowed_symbols());
|
||||
config.update("account_force_username", prefs_get_account_force_username());
|
||||
config.update("max_friends", prefs_get_max_friends());
|
||||
config.update("track", prefs_get_track());
|
||||
config.update("trackaddrs", prefs_get_trackserv_addrs());
|
||||
config.update("location", prefs_get_location());
|
||||
config.update("description", prefs_get_description());
|
||||
config.update("url", prefs_get_url());
|
||||
config.update("contact_name", prefs_get_contact_name());
|
||||
config.update("contact_email", prefs_get_contact_email());
|
||||
config.update("servername", prefs_get_servername());
|
||||
config.update("max_connections", prefs_get_max_connections());
|
||||
config.update("max_concurrent_logins", prefs_get_max_concurrent_logins());
|
||||
config.update("use_keepalive", prefs_get_use_keepalive());
|
||||
config.update("max_conns_per_IP", prefs_get_max_conns_per_IP());
|
||||
config.update("servaddrs", prefs_get_bnetdserv_addrs());
|
||||
config.update("udptest_port", prefs_get_udptest_port());
|
||||
config.update("w3routeaddr", prefs_get_w3route_addr());
|
||||
config.update("initkill_timer", prefs_get_initkill_timer());
|
||||
config.update("wolv1addrs", prefs_get_wolv1_addrs());
|
||||
config.update("wolv2addrs", prefs_get_wolv2_addrs());
|
||||
config.update("wgameresaddrs", prefs_get_wgameres_addrs());
|
||||
config.update("apiregaddrs", prefs_get_apireg_addrs());
|
||||
config.update("woltimezone", prefs_get_wol_timezone());
|
||||
config.update("wollongitude", prefs_get_wol_longitude());
|
||||
config.update("wollatitude", prefs_get_wol_latitude());
|
||||
config.update("wol_autoupdate_serverhost", prefs_get_wol_autoupdate_serverhost());
|
||||
config.update("wol_autoupdate_username", prefs_get_wol_autoupdate_username());
|
||||
config.update("wol_autoupdate_password", prefs_get_wol_autoupdate_password());
|
||||
config.update("ircaddrs", prefs_get_irc_addrs());
|
||||
config.update("irc_network_name", prefs_get_irc_network_name());
|
||||
config.update("hostname", prefs_get_hostname());
|
||||
config.update("irc_latency", prefs_get_irc_latency());
|
||||
config.update("telnetaddrs", prefs_get_telnet_addrs());
|
||||
config.update("war3_ladder_update_secs", prefs_get_war3_ladder_update_secs());
|
||||
config.update("XML_output_ladder", prefs_get_XML_output_ladder());
|
||||
config.update("output_update_secs", prefs_get_output_update_secs());
|
||||
config.update("XML_status_output", prefs_get_XML_status_output());
|
||||
config.update("clan_newer_time", prefs_get_clan_newer_time());
|
||||
config.update("clan_max_members", prefs_get_clan_max_members());
|
||||
config.update("clan_channel_default_private", prefs_get_clan_channel_default_private());
|
||||
config.update("clan_min_invites", prefs_get_clan_min_invites());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -475,6 +478,9 @@ namespace pvpgn
|
|||
const char * func_name;
|
||||
switch (luaevent)
|
||||
{
|
||||
case luaevent_server_start:
|
||||
func_name = "main";
|
||||
break;
|
||||
case luaevent_server_mainloop:
|
||||
func_name = "handle_server_mainloop"; // one time per second
|
||||
break;
|
||||
|
|
|
@ -52,6 +52,7 @@ namespace pvpgn
|
|||
luaevent_user_login,
|
||||
luaevent_user_disconnect,
|
||||
|
||||
luaevent_server_start,
|
||||
luaevent_server_mainloop
|
||||
|
||||
} t_luaevent_type;
|
||||
|
|
|
@ -156,7 +156,7 @@ namespace pvpgn
|
|||
/* Returns a list of files in a directory (except the ones that begin with a dot) */
|
||||
extern std::vector<std::string> dir_getfiles(const char * directory, const char* ext, bool recursive)
|
||||
{
|
||||
std::vector<std::string> files;
|
||||
std::vector<std::string> files, dfiles;
|
||||
const char* _ext;
|
||||
|
||||
DIR *dir;
|
||||
|
@ -166,7 +166,8 @@ namespace pvpgn
|
|||
if (!dir)
|
||||
return files;
|
||||
|
||||
while ((ent = readdir(dir)) != NULL) {
|
||||
while ((ent = readdir(dir)) != NULL)
|
||||
{
|
||||
const std::string file_name = ent->d_name;
|
||||
const std::string full_file_name = std::string(directory) + "/" + file_name;
|
||||
|
||||
|
@ -181,7 +182,7 @@ namespace pvpgn
|
|||
std::vector<std::string> subfiles = dir_getfiles(full_file_name.c_str(), ext, recursive);
|
||||
|
||||
for (int i = 0; i < subfiles.size(); ++i)
|
||||
files.push_back(subfiles[i]);
|
||||
dfiles.push_back(subfiles[i]);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
@ -196,6 +197,10 @@ namespace pvpgn
|
|||
}
|
||||
closedir(dir);
|
||||
|
||||
// merge files and files from directories, so we will receive directories at begin, files at the end
|
||||
// (otherwise files and directories are read alphabetically - as is)
|
||||
files.insert(files.begin(), dfiles.begin(), dfiles.end());
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue