@@ -9,6 +9,10 @@ PluginInfo* g_Info;
99
1010sol::state Lua;
1111
12+ static std::vector<std::string> s_ScriptFiles;
13+
14+ void reload_scripts ();
15+
1216int my_exception_handler (lua_State* L, sol::optional<const std::exception&> maybe_exception, sol::string_view description) {
1317 std::cout << " An exception occurred in a function " ;
1418 if (maybe_exception) {
@@ -61,6 +65,8 @@ extern "C" EXPORT unsigned int VcmpPluginInit(PluginFuncs * pluginFuncs, PluginC
6165 RegisterClasses (&Lua);
6266 RegisterVCMPCallbacks ();
6367
68+ bool experimental_mode = false ;
69+
6470 // Load Configuration
6571 {
6672 std::list<CSimpleIniA::Entry> configOptions;
@@ -78,6 +84,9 @@ extern "C" EXPORT unsigned int VcmpPluginInit(PluginFuncs * pluginFuncs, PluginC
7884 else if (strcmp (setting.pItem , " logfile" ) == 0 ) {
7985 Logger::setFile (conf.GetValue (" config" , setting.pItem ), 0 , 0 );
8086 }
87+ else if (strcmp (setting.pItem , " experimental" ) == 0 ) {
88+ experimental_mode = static_cast <bool >(conf.GetValue (" config" , setting.pItem ));
89+ }
8190 }
8291 }
8392 else spdlog::warn (" No configuration settings supplied, using defaults" );
@@ -89,6 +98,7 @@ extern "C" EXPORT unsigned int VcmpPluginInit(PluginFuncs * pluginFuncs, PluginC
8998 if (conf.GetAllValues (" scripts" , " script" , scripts) && scripts.size () > 0 ) {
9099 for (auto it = scripts.begin (); it != scripts.end (); it++) {
91100 auto result = Lua.safe_script_file (it->pItem , sol::script_pass_on_error);
101+ s_ScriptFiles.emplace_back (it->pItem );
92102 if (!result.valid ()) {
93103 sol::error e = result;
94104 spdlog::error (" Failed to load script: {}" , e.what ());
@@ -97,6 +107,34 @@ extern "C" EXPORT unsigned int VcmpPluginInit(PluginFuncs * pluginFuncs, PluginC
97107 }
98108 else spdlog::error (" No Lua scripts specified to load" );
99109 }
100-
110+
111+ if (experimental_mode) {
112+ spdlog::warn (" Experimental features may be really unstable, be very careful when using them." );
113+ Lua[" __reload_scripts" ] = &reload_scripts;
114+ }
115+
101116 return 1 ;
117+ }
118+
119+ void reload_scripts ()
120+ {
121+ spdlog::warn (" Reloading scripts..." );
122+
123+ // Re-trigger some crucial events which simulate a 'restart'
124+ EventManager::Trigger (" onServerShutdown" );
125+ // Reset the event handlers to avoid duplication
126+ EventManager::Reset ();
127+
128+ for (const auto & scriptFile : s_ScriptFiles)
129+ {
130+ spdlog::info (" Parsing script: {}" , scriptFile);
131+ auto result = Lua.safe_script_file (scriptFile, sol::script_pass_on_error);
132+ if (!result.valid ()) {
133+ sol::error e = result;
134+ spdlog::error (" Failed to load script: {}" , e.what ());
135+ }
136+ }
137+
138+ // Re-trigger some crucial events which simulate a 'restart'
139+ EventManager::Trigger (" onServerInit" );
102140}
0 commit comments