//------------------------------------------------------------------------------ static void load_lua_scripts(const char* path) { int i; char path_buf[1024]; HANDLE find; WIN32_FIND_DATA fd; str_cpy(path_buf, path, sizeof_array(path_buf)); str_cat(path_buf, "\\", sizeof_array(path_buf)); i = strlen(path_buf); str_cat(path_buf, "*.lua", sizeof_array(path_buf)); find = FindFirstFile(path_buf, &fd); path_buf[i] = '\0'; while (find != INVALID_HANDLE_VALUE) { if (_stricmp(fd.cFileName, "clink.lua") != 0) { str_cat(path_buf, fd.cFileName, sizeof_array(path_buf)); load_lua_script(path_buf); path_buf[i] = '\0'; } if (FindNextFile(find, &fd) == FALSE) { FindClose(find); break; } } }
int reload_global_data() { /*unregister all timer callbacks*/ unregister_timers_callback(); init_funcs(); init_attck_proc_func(); init_attck_proc_pet_func(); if (load_lua_script() != 0){ ERROR_LOG("load ai script failed"); return -1; } init_attck_check_func(); if ((load_xmlconf("../conf/skills_price.xml", load_skill_use_mp) == -1) || (load_xmlconf("../conf/BattleActionList.xml", load_skill_attr) == -1) || (load_xmlconf("../conf/BattleMonsterTalk.xml", load_beast_topic) == -1) || init_all_timer_type(0) == -1 ){ return -1; } init_cli_handle_funs(); refresh_timers_callback(); return 0; }
int init_service(int isparent) { if (!isparent) { DEBUG_LOG("==INIT_SERVICE BEGIN== "); DEBUG_LOG("INIT_SERVICE"); const char *ip= get_ip_ex(0x01); if ( strncmp( ip,"10.",3 )==0 ) { g_is_test_env=true; DEBUG_LOG("=============TEST ENV TRUE ============="); }else{ g_is_test_env=false; DEBUG_LOG("=============TEST ENV FALSE ============="); } g_log_send_buf_hex_flag=g_is_test_env?1:0; setup_timer(); if (init_battles() != 0){ ERROR_LOG("init battserv failed"); return -1; } init_funcs(); init_attck_proc_func(); init_attck_proc_pet_func(); if (load_lua_script() != 0){ ERROR_LOG("load ai script failed"); return -1; } init_attck_check_func(); if ((load_xmlconf("../conf/skills_price.xml", load_skill_use_mp) == -1) || (load_xmlconf("../conf/BattleActionList.xml", load_skill_attr) == -1) || (load_xmlconf("../conf/BattleMonsterTalk.xml", load_beast_topic) == -1) || init_all_timer_type(0) == -1 ){ return -1; } init_cli_handle_funs(); DEBUG_LOG("==INIT_SERVICE END== "); } return 0; }
//------------------------------------------------------------------------------ lua_State* initialise_lua() { static int once = 0; int i; int path_hash; char buffer[1024]; struct luaL_Reg clink_native_methods[] = { { "chdir", change_dir }, { "execute", lua_execute }, { "find_dirs", find_dirs }, { "find_files", find_files }, { "get_console_aliases", get_console_aliases }, { "get_cwd", get_cwd }, { "get_env", get_env }, { "get_env_var_names", get_env_var_names }, { "get_host_process", get_host_process }, { "get_rl_variable", get_rl_variable }, { "get_screen_info", get_screen_info }, { "get_setting_int", get_setting_int }, { "get_setting_str", get_setting_str }, { "is_dir", is_dir }, { "is_rl_variable_true", is_rl_variable_true }, { "lower", to_lowercase }, { "matches_are_files", matches_are_files }, { "slash_translation", slash_translation }, { "suppress_char_append", suppress_char_append }, { "suppress_quoting", suppress_quoting }, { NULL, NULL } }; if (g_lua != NULL) { return g_lua; } // Initialise Lua. g_lua = luaL_newstate(); luaL_openlibs(g_lua); // Add our API. lua_createtable(g_lua, 0, 0); lua_setglobal(g_lua, "clink"); lua_getglobal(g_lua, "clink"); luaL_setfuncs(g_lua, clink_native_methods, 0); lua_pop(g_lua, 1); // Load all the .lua files alongside the dll and in the script folder. if (g_inject_args.script_path[0] == '\0') { get_dll_dir(buffer, sizeof_array(buffer)); } else { buffer[0] = '\0'; str_cat(buffer, g_inject_args.script_path, sizeof_array(buffer)); } path_hash = hash_string(buffer); i = (int)strlen(buffer); str_cat(buffer, "/clink.lua", sizeof_array(buffer)); load_lua_script(buffer); buffer[i] = '\0'; load_lua_scripts(buffer); get_config_dir(buffer, sizeof(buffer)); if (hash_string(buffer) != path_hash) { load_lua_scripts(buffer); } if (!once) { rl_add_funmap_entry("reload-lua-state", reload_lua_state); once = 1; } return g_lua; }