AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugins (https://forums.alliedmods.net/forumdisplay.php?f=108)
-   -   [DEV] Autoreload plugins (https://forums.alliedmods.net/showthread.php?t=322045)

Dragokas 03-13-2020 12:46

[DEV] Autoreload plugins
 
1 Attachment(s)
Description:
By default, SourceMod reloads plugin on map change only (in case its file modification time is changed).
This plugin does the same every 2 seconds (adjustable).
*New features:
- Notify in chat about reloading, loading, unloading.
- Show plugin load status in chat
- Can load newly added plugins (you must set it in ConVars!!!)
- Can reload plugin even if the previous time it is failed
- Can reload translation files cache (when some plugin is changed)
- Scan in subfolders (recursively)
- Ensure plugin is really loaded in case it was fault due to attempt to reload it in middle-time of file uploading
- ConVars allowing to select delay (shorter, to track changes faster - for dev., or vice versa, longer delay to decrease CPU load - for production server)
- Ability to show part of error log in chat when plugin failed to load
- More optimized.
Commands:
PHP Code:

// Forcibly check plugin files for newly updated and reload if any
sm_pluginsreload 

Settings (ConVars):
Located at: cfg/sourcemod/sm_autoreload.cfg
PHP Code:

// Enable this plugin? (1 - Yes, 0 - No)
sm_autoreload_enable "1"

// * Delay between updates (in sec.). Set 0 to disable timer at all.
sm_autoreload_delay "2.0"

// ** Do we need to check for new plugin files appearing? (1 - Yes, 0 - No).
sm_autoreload_track_new "0"

// Where to show info about the reloaded plugin? (0 - Nowhere, 1 - Server, 2 - Chat, 4 - Console. Sum them to combine several options)
sm_autoreload_show_info "3"

// How many lines of error log to display when the plugin is failed to load? (0 - to disable)
sm_autoreload_error_lines "4"

// Display chat message to admins only defined by these admin flags (leave empty - to display for all users)
sm_autoreload_msg_flag "" 

*Notice 1: I would suggest setting like 5.0 - 10.0 sec. delay for production server where you don't need so quick plugin check.
**Notice 2: track new files cause more disk operations since the entire folder has re-read each time. Leave disabled to improve performance.
Forwards:
Spoiler


Using:
Place smx in "plugins" folder.
Credits:
- Timiditas - author of idea and original plugin
- SilverShot - testing, give me some ideas and forcing me find solutions ^^
- Marttt - reload translation cache suggestion
Full changelog:


// TODO:
- Integrity check.
- Adding dynamically loaded/unloaded plugins to tracking list. Also, need help in issue #1482.


Donate
Donates are very appreciated and welcomed for further inspiration, make me happy, and make next updates came out more often:
- Patreon (Paypal)
- BitCoin
- Ю.Money

lugui 03-13-2020 20:46

Re: [DEV] Plugin reload
 
good, that will save me one or two seconds on each reaload when I testing my plugins... I gess it will add up to a few minutes =P

Silvers 03-14-2020 01:41

Re: [DEV] Plugin reload
 
At last can add new plugins without having to refresh the plugins list (albeit I use sm_refresh but still typing in console when Im not in-game using the keybind I set).

Thanks!

Alienmario 03-16-2020 11:27

Re: [DEV] Plugin reload
 
Thanks!

Dragokas 03-16-2020 19:50

Re: [DEV] Plugin reload
 
Updated.

Quote:

1.6 (17-Mar-2020)
- Code is simplified, changed timing logic.
- Plugin load status is now always displayed (it's checked with 0.5 sec. delay after actual re-loading).
- Status description is simplified.
- Plugin change is now detected by file size as well.
- "sm_autoreload_delay" ConVar safe minimum is defined as 1.0 sec.
- Disabled load/reload selection logic based on plugin status, since FindPluginByFile returns 0 even if plugin is loaded but disabled. Now, reload + load is always executed together.
- Added ability to display in chat part of error log when plugin is failed to load (you can disable or adjust number of lines in "sm_autoreload_error_lines" ConVar).
- Added an option to display info in console only, see "sm_autoreload_show_info" description.

1.5 (16-Mar-2020)
- Better file uploading finish detection, so no more twice spam in error log (thanks to SilverShot).
- Some message misprints corrected.

Marttt 03-21-2020 13:39

Re: [DEV] Plugin reload
 
I don't know if it will be a good addition, but I'm used to run the "sm_reload_translations" together with the "sm plugins refresh", to reload the translations file (because some times I have to update both .smx and .phrases file),

So maybe you can include that in the plugin and make a cvar (maybe not necessary) allowing it to reload the translations file (at the end) if some plugin is updated.

IMO is just a suggestion to improve it.

Thanks for you effort. Nice plugin as always.

Dragokas 03-22-2020 06:42

Re: [DEV] Plugin reload
 
Thanks for suggestion, Marttt! Very useful.

Updated.

Quote:

1.8 (22-Mar-2020)
- Attempt to indirectly recognize <Disabled> plugins to prevent both load / reload commands executing for each modified plugin (affected rcon double-msg only).
- Added reloading of translation files cache; can be triggered by any of plugins reload (Marttt suggestion).
- Added ability to display reload message to admins only: new ConVar "sm_autoreload_msg_flag" (e.g., useful to not distract the players).
- Added ability to disable reloader: new ConVar "sm_autoreload_enable" (e.g. useful when some plugin can surely crash the server due to "hot" reload).

1.7 (18-Mar-2020)
- Some non-essential message cleaning

CrazyGhostRider 03-31-2020 16:21

Re: [DEV] Plugin reload
 
You have a mistake. Instead of reloading the updated plugin, the "Loading" of the plugin occurs.

Dragokas 03-31-2020 17:26

Re: [DEV] Plugin reload
 
Can you show server logs?

CrazyGhostRider 04-01-2020 05:41

Re: [DEV] Plugin reload
 
I replace the file speclist.smx

[AutoReload] test/speclist.smx has changed timestamp. Reloading...
[SM] Plugin test\speclist.smx is already loaded.
sm plugins reload test/speclist
[SM] Plugin Spectator List reloaded successfully.


sm_autoreload_delay = 2.0
sm_autoreload_track_new = 1
sm_autoreload_error_lines = 4



P.S. Another error with chat messages if you delete a file. And then add the file again
test/speclist2.smx plugin is deleted. Unloading...
test/speclist2.smx plugin reloaded. Status: NOT Loaded

But in the server console it writes like this:
[AutoReload] test/speclist2.smx plugin is deleted. Unloading...
[SM] Plugin Spectator List unloaded successfully.
[AutoReload] test/speclist2.smx has changed timestamp. Reloading...
[SM] Loaded plugin test\speclist2.smx successfully.

Dragokas 04-01-2020 10:30

Re: [DEV] Plugin reload
 
1 Attachment(s)
There is nothing wrong with functionality. Plugin executes both operations "load" and "reload" for plugins with unrecognized statuses.
To beautify server output and prevent one additional superfluous operation, please make the same log using this v.1.8d. You may receive msg like this:
Quote:

Plugin status code before reload: X

CrazyGhostRider 04-01-2020 16:17

Re: [DEV] Plugin reload
 
Nothing changed.

Let me show you the example plugin "speclist.smx"
The plugin is already loaded on the server. I am throwing a new plugin (with the new sm_test command)
Server console:
[AutoReload] test/speclist.smx has changed timestamp. Reloading...
[SM] Plugin test\speclist.smx is already loaded.

In game chat :
test/speclist.smx plugin reloaded. Status: NOT Loaded


I check the performance:
Unknown command "sm_test"

I manually restart the plugin:
Server console:
sm plugins reload test/speclist
[SM] Plugin Spectator List reloaded successfully.

And only after that the plugin rebooted and the sm_test command started working.



And the second error is this:
The server is on. Delete the plugin:
Server console:
[AutoReload] test/speclist.smx plugin is deleted. Unloading...
[SM] Plugin Spectator List unloaded successfully.

I am returning the plugin
Server console:
[AutoReload] test/speclist.smx has changed timestamp. Reloading...
[SM] Loaded plugin test\speclist.smx successfully.

In game chat :
test/speclist.smx plugin reloaded. Status: NOT Loaded

Dragokas 04-01-2020 17:28

Re: [DEV] Plugin reload
 
Windows?

Is everything OK when you do same tests using root folder "plugins" (without "test" subfolder) ?

CrazyGhostRider 04-01-2020 17:40

Re: [DEV] Plugin reload
 
Windows

Without without the "test" subfolder, everything works.
The game chat also shows the status correctly.

Dragokas 04-01-2020 18:35

Re: [DEV] Plugin reload
 
Updated.

Quote:

1.9 (02-Apr-2020)
- Fixed Windows support. Reloader incorrectly selected load action type, because FindPluginByFile() can't normalize linux path separator (thanks to CrazyGhostRider for report).
- Plugin list is being updated now with newly added plugins on each map start (even if sm_autoreload_track_new == 0).
- Plugin reloading is blocked between map end and map start (for safe).

Dragokas 10-04-2020 18:55

Re: [DEV] Plugin reload
 
Cosmetic change.
Quote:

1.10 (05-Oct-2020)
- Fixed: not hooked dynamic change of "sm_autoreload_error_lines" ConVar.

Dragokas 04-16-2021 14:15

Re: [DEV] Autoreload plugins
 
Updated.

Quote:

1.11 (16-Apr-2021)
- Added TIMER_FLAG_NO_MAPCHANGE to prevent accidentally plugin double reload on map change.
- Added forwards (thanks to Silvers for request):

* AP_OnPluginUpdate - called when plugin list update sequence is about to start (or ended) - see the "pre" argument to determine.
> This happens when 1 or more plugins are to be planned for loading/reloading/unloading.
> Example: when 10 plugins are changed simultaneously, this forward is called 2 times: 1 - very first before all other forward, then 2 - it is called as last, after all other forwards.
* AP_OnPluginLoad - called before and after plugin is loaded (no matter successfully or not - see the "pre" and "status" arguments for details).
> This happens when plugin wasn't loaded yet, or its previous loading failed.
* AP_OnPluginReload - called before and after plugin is reloaded (no matter successfully or not - see the "pre" and "status" arguments for details).
> This happens when plugin is already loaded at the moment.
* AP_OnPluginUnload
> This happens when plugin is removed, moved or renamed from its initial location.
* Notice 1: You can prevent plugins from load/reload/unload by returning Plugin_Stop in forward (it is only applicable for actions done directly by this plugin).
* Notice 2: these forwards doesn't report about actions made by other plugins including sourcemod itself, like:
> when you manually load/reload/unload plugin via console;
> when SM load/reload/unload plugin between OnMapEnd and OnMapStart events.

About forwards:

- See details in scripting/include/autoreload.inc
- See examples in scripting/include/test_forwards.sp

Dragokas 06-30-2021 22:01

Re: [DEV] Autoreload plugins
 
Updated.

Quote:

1.13 (01-July-2021)
- Added command "sm_pluginsreload" - to force checking plugin files for newly updated (by SilverShot request).
- Added new allowed value "0" for "sm_autoreload_delay" ConVar - to disable checking plugins update by timer at all.

1.12 (09-May-2021)
- Little safe check to prevent error if < 4 character length filename for some reason is located at plugins folder.
Note: To update from the old version and be able to use new features, a server reboot is required.

ChrisP 11-02-2021 16:49

Re: [DEV] Autoreload plugins
 
This plugin saves me so much time. Thank you Timiditas and Dragokas!

Dragokas 11-27-2021 03:17

Re: [DEV] Autoreload plugins
 
Updated.

Quote:

1.14 (27-Nov-2021)
- Potential fix for rare crash, caused by file system error.
- Improved DEBUG version in attempt to track the rare case with server crash caused by false positive time stamp change detection for all plugins at once.

Tonblader 05-06-2022 12:31

Re: [DEV] Autoreload plugins
 
Is it possible you can add a custom route of where you want plugins to be detected in a cvar maybe with multiple paths where the plugin can reload other plugins?
example:
sm_cvar sm_autoreload_paths "plugins\disabled\boost\c2m1" "plugins\all\"

Dragokas 05-06-2022 13:43

Re: [DEV] Autoreload plugins
 
Plugins are detected by Autoreloader anywhere in /plugins/ (recursively) same as SourceMod do; an exception is /plugins/disabled/ and all its subfolders which aren't loaded. This is default behaviour of SourceMod and I'm going to follow it.

Dragokas 05-06-2022 14:07

Re: [DEV] Autoreload plugins
 
As about tracking dynamically loaded plugins made by 3rd-party side call (via "sm plugins load"), it's impossible to do until new forward been implemented according to issue #1482. I'm not going to inject low-level hooks directly in sm engine just for such a rarely used feature.

PS. Ahh, well, it is still possible to track them by calculating delta between cached and current plugin list in memory. This will cause consuming more CPU cycles. Maybe I will think about that as an optional feature. Surely, not soon, cos I'm too busy for nearest months.

Dragokas 10-06-2022 12:40

Re: [DEV] Autoreload plugins
 
Updated.
Quote:

1.15 (06-Oct-2022)
- Walkaround rare SM bug #1839, when SM reports incorrect plugin state, causing incorrect decision about "load" or "reload".
- Updated against warnings in SM 1.11, and futute 1.12, 1.13.


All times are GMT -4. The time now is 22:16.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.