|
8 | 8 | #include "../../Plugins/inc/Plugin.h" |
9 | 9 | #include "../../../files/Files.h" |
10 | 10 | #include "../../../http/HTTPManager.h" |
| 11 | +#include "../../Plugins/inc/plugins/CPPPlugin.h" |
| 12 | +#include "../../Plugins/inc/plugins/LuaPlugin.h" |
11 | 13 |
|
12 | 14 | typedef const char *(*GetPlugin)(); |
13 | 15 |
|
@@ -272,47 +274,73 @@ void SwiftlyPluginManagerReload(CPlayerSlot *slot, CCommandContext context, std: |
272 | 274 | PrintToClientOrConsole(slot, "Plugin Reload", "Plugin '%s' has been reloaded.\n", plugin_name.c_str()); |
273 | 275 | } |
274 | 276 |
|
| 277 | +void LoadPlugin(std::string plugin_name) |
| 278 | +{ |
| 279 | + Plugin *plugin = nullptr; |
| 280 | + |
| 281 | + std::vector<std::string> files = Files::FetchFileNames("addons/swiftly/plugins/" + plugin_name); |
| 282 | + |
| 283 | + for (const std::string &file : files) |
| 284 | + { |
| 285 | + if (ends_with(file, WIN_LINUX(".dll", ".so"))) |
| 286 | + { |
| 287 | + plugin = new CPPPlugin(file, plugin_name, PluginType_t::PLUGIN_CPP); |
| 288 | + break; |
| 289 | + } |
| 290 | + else if (ends_with(file, ".lua")) |
| 291 | + { |
| 292 | + plugin = new LuaPlugin(std::string(std::filesystem::current_path().string() + "/addons/swiftly/plugins/" + plugin_name), plugin_name, PluginType_t::PLUGIN_LUA); |
| 293 | + break; |
| 294 | + } |
| 295 | + } |
| 296 | + |
| 297 | + if (plugin) |
| 298 | + AddPluginInMap(plugin); |
| 299 | +} |
| 300 | + |
275 | 301 | void SwiftlyPluginManagerRefresh(CPlayerSlot *slot, CCommandContext context) |
276 | 302 | { |
277 | 303 | if (slot->Get() != -1) |
278 | 304 | return; |
279 | 305 |
|
280 | | - PrintToClientOrConsole(slot, "Plugin Refresh", "This feature has been temporarely removed until support for multi language scripting is finished.\n"); |
281 | | - |
282 | | - // std::vector<std::string> pluginNames; |
283 | | - |
284 | | - // std::vector<std::string> files = Files::FetchFileNames("addons/swiftly/plugins"); |
285 | | - // for (const std::string &file : files) |
286 | | - // { |
287 | | - // if (!ends_with(file, WIN_LINUX(".dll", ".so"))) |
288 | | - // continue; |
289 | | - // if (starts_with(file, WIN_LINUX("disabled\\", "disabled/"))) |
290 | | - // continue; |
291 | | - |
292 | | - // pluginNames.push_back(file); |
293 | | - // } |
294 | | - |
295 | | - // uint32 newPlugins = 0; |
296 | | - |
297 | | - // for (const std::string plugin_name : pluginNames) |
298 | | - // { |
299 | | - // if (!ExistsPluginInMap(plugin_name)) |
300 | | - // { |
301 | | - // std::vector<std::string> exploded = explode(plugin_name, WIN_LINUX("\\", "/")); |
302 | | - // std::string name = exploded[exploded.size() - 2]; |
303 | | - // if (name == "plugins") |
304 | | - // { |
305 | | - // PrintToClientOrConsole(slot, "Plugin Refresh", "Skipped '%s' because it needs to be in it's own folder.\n", plugin_name); |
306 | | - // continue; |
307 | | - // } |
308 | | - |
309 | | - // Plugin *plugin = new Plugin(plugin_name, name); |
310 | | - // AddPluginInMap(plugin); |
311 | | - // ++newPlugins; |
312 | | - // } |
313 | | - // } |
314 | | - |
315 | | - // PrintToClientOrConsole(slot, "Plugin Refresh", "%02d plugins have been added.\n", newPlugins); |
| 306 | + std::vector<std::string> pluginNames; |
| 307 | + |
| 308 | + std::vector<std::string> directories = Files::FetchDirectories("addons/swiftly/plugins"); |
| 309 | + for (std::string directory : directories) |
| 310 | + { |
| 311 | + if (directory.find("disabled") != std::string::npos) |
| 312 | + continue; |
| 313 | + |
| 314 | + directory = replace(directory, "addons/swiftly/plugins", ""); |
| 315 | + directory = replace(directory, WIN_LINUX("\\", "/"), ""); |
| 316 | + |
| 317 | + pluginNames.push_back(directory); |
| 318 | + } |
| 319 | + |
| 320 | + uint32 newPlugins = 0; |
| 321 | + |
| 322 | + for (const std::string plugin_name : pluginNames) |
| 323 | + { |
| 324 | + if (!ExistsPluginInMap(plugin_name)) |
| 325 | + { |
| 326 | + // std::vector<std::string> exploded = explode(plugin_name, WIN_LINUX("\\", "/")); |
| 327 | + // std::string name = exploded[exploded.size() - 2]; |
| 328 | + // if (name == "plugins") |
| 329 | + // { |
| 330 | + // PrintToClientOrConsole(slot, "Plugin Refresh", "Skipped '%s' because it needs to be in it's own folder.\n", plugin_name); |
| 331 | + // continue; |
| 332 | + // } |
| 333 | + |
| 334 | + // Plugin *plugin = new Plugin(plugin_name, name); |
| 335 | + |
| 336 | + // AddPluginInMap(new LuaPlugin(plugin_name, "", PluginType_t::PLUGIN_LUA)); |
| 337 | + |
| 338 | + LoadPlugin(plugin_name); |
| 339 | + ++newPlugins; |
| 340 | + } |
| 341 | + } |
| 342 | + |
| 343 | + PrintToClientOrConsole(slot, "Plugin Refresh", "%02d plugins have been added.\n", newPlugins); |
316 | 344 | } |
317 | 345 |
|
318 | 346 | void SwiftlyPluginManager(CPlayerSlot *slot, CCommandContext context, const char *subcmd, const char *plugin_name) |
|
0 commit comments