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.


All times are GMT -4. The time now is 00:10.

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