Skip to content

Commit

Permalink
tries load multiple times if failed
Browse files Browse the repository at this point in the history
  • Loading branch information
Monera committed Sep 16, 2023
1 parent 038153e commit 808fc6b
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions scripting/ez/load.sp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define LOAD_MAX_TRIES (4)

static Regex pluginExtensionRegex;

void Init_Load()
Expand All @@ -19,30 +21,40 @@ public Action SvrCmd_EZLoad(int args)
GetCmdArg(1, substring, sizeof(substring));

ArrayList list = ListPlugins(substring);
int length = list.Length;
int failure = 0;
for(int i = 0; i < length; i++)
int success = 0;

for(int i = 0; i < LOAD_MAX_TRIES && list.Length != 0; i++)
{
char path[PLATFORM_MAX_PATH];
char err[256];
bool wasloaded;
int j = 0;
while(j < list.Length)
{
char path[PLATFORM_MAX_PATH];
char err[256];
bool wasloaded;

list.GetString(i, path, sizeof(path));
Handle plugin = LoadPluginEx(path, err, sizeof(err), wasloaded);
list.GetString(j, path, sizeof(path));
Handle plugin = LoadPluginEx(path, err, sizeof(err), wasloaded);

if(plugin == null)
{
PrintToServer("[EZ] Plugin %s failed to load: %s", path, err);
failure += 1;
}
else if(wasloaded)
{
failure += 1;
if(plugin)
{
if(!wasloaded)
{
success += 1;
}

list.Erase(j);
}
else
{
PrintToServer("[EZ] Plugin %s failed to load: %s", path, err);
j += 1;
}
}
}

delete list;

PrintToServer("[EZ] %d plugins are loaded", length - failure);
PrintToServer("[EZ] %d plugins are loaded", success);

return Plugin_Handled;
}
Expand Down

0 comments on commit 808fc6b

Please sign in to comment.