AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugins (https://forums.alliedmods.net/forumdisplay.php?f=108)
-   -   Updater (https://forums.alliedmods.net/showthread.php?t=169095)

GoD-Tony 10-08-2011 14:03

Updater
 
1 Attachment(s)
Updater

Allows developers to automatically update their plugins and files. Updates will be checked on server startup and then once every 24 hours. All updates will be logged to Updater.log in your SourceMod log directory.

Installation:
  1. Your server must be running at least one of the following extensions:
  2. Add updater.smx to your plugins directory.
Cvars:
  • sm_updater <1|2|3> - Determines update functionality.
    • 1 = Only notify in the log file when an update is available.
    • 2 = Automatically download and install available updates. *Default
    • 3 = Include the source code with updates.
Commands:
  • sm_updater_check - Forces Updater to check all plugins for updates. Can only be run once per hour.
  • sm_updater_status - View the status of Updater.

Source code: Mercurial | zip | bz2 | gz

GoD-Tony 10-08-2011 14:04

Re: Updater
 
Information for Developers
Code:
/**  * Adds your plugin to the updater. The URL will be updated if  * your plugin was previously added.  *  * @param url      URL to your plugin's update file.  * @noreturn  */ native Updater_AddPlugin(const String:url[]); /**  * Removes your plugin from the updater. This does not need to  * be called during OnPluginEnd.  *  * @noreturn  */ native Updater_RemovePlugin(); /**  * Forces your plugin to be checked for updates. The behaviour  * of the update is dependant on the server's configuration.  *  * @return    True if an update was triggered. False otherwise.  * @error      Plugin not found in updater.  */ native bool:Updater_ForceUpdate(); /**  * Called when your plugin is about to be checked for updates.  *  * @return    Plugin_Handled to prevent checking, Plugin_Continue to allow it.  */ forward Action:Updater_OnPluginChecking(); /**  * Called when your plugin is about to begin downloading an available update.  *  * @return    Plugin_Handled to prevent downloading, Plugin_Continue to allow it.  */ forward Action:Updater_OnPluginDownloading(); /**  * Called when your plugin's update files have been fully downloaded  * and are about to write to their proper location. This should be used  * to free read-only resources that require write access for your update.  *  * @note OnPluginUpdated will be called later during the same frame.  *  * @noreturn  */ forward Updater_OnPluginUpdating(); /**  * Called when your plugin's update has been completed. It is safe  * to reload your plugin at this time.  *  * @noreturn  */ forward Updater_OnPluginUpdated(); /**  * @brief Reloads a plugin.  *  * @param plugin    Plugin Handle (INVALID_HANDLE uses the calling plugin).  * @noreturn  */ stock ReloadPlugin(Handle:plugin=INVALID_HANDLE);

When testing an update with your plugin, I recommend that you test it against a debug version of Updater. It will log detailed download information to Updater_Debug.log in case you accidentally used malformed URLs or paths.
Code:
/* Line 25: updater.sp */ #define DEBUG   // This will enable verbose logging. Useful for developers testing their updates.

Example Plugin
Code:
#include <sourcemod> #undef REQUIRE_PLUGIN #include <updater> #define UPDATE_URL    "http://website.com/myplugin/updatefile.txt" public OnPluginStart() {     if (LibraryExists("updater"))     {         Updater_AddPlugin(UPDATE_URL)     } } public OnLibraryAdded(const String:name[]) {     if (StrEqual(name, "updater"))     {         Updater_AddPlugin(UPDATE_URL)     } }
Now let's take a look at what UPDATE_URL is pointing to ...

Update File Format

Simple Update - Majority of plugins will use this.
Code:

"Updater"
{
        "Information"
        {
                "Version"
                {
                        "Latest"        "1.0.1"
                }
               
                "Notes"        "More info @ www.sourcemod.net. Changes in 1.0.1:"
                "Notes"        "Added new Batman model"
                "Notes"        "Minor code changes"
        }
       
        "Files"
        {
                "Plugin"        "Path_SM/plugins/myplugin.smx"
                "Plugin"        "Path_SM/translations/myplugin.phrases.txt"
                "Plugin"        "Path_SM/translations/ru/myplugin.phrases.txt"
                "Plugin"        "Path_Mod/models/characters/batman.mdl"
                "Plugin"        "Path_Mod/materials/models/characters/batman.vmt"
               
                "Source"        "Path_SM/scripting/myplugin.sp"
        }
}

Patch Update - Useful on large plugins to avoid downloading all files when only a few have changed. Patch files will be used if the "Previous" version matches the server's currently running version.
Code:

"Updater"
{
        "Information"
        {
                "Version"
                {
                        "Latest"        "1.0.1"
                        "Previous"        "1.0.0"
                }
               
                "Notes"        "More info @ www.sourcemod.net. Changes in 1.0.1:"
                "Notes"        "Added Russian phrases"
                "Notes"        "Minor code changes"
        }
       
        "Files"
        {
                "Patch"
                {
                        "Plugin"        "Path_SM/plugins/myplugin.smx"
                        "Plugin"        "Path_SM/translations/ru/myplugin.phrases.txt"

                        "Source"        "Path_SM/scripting/myplugin.sp"
                }
               
                "Plugin"        "Path_SM/plugins/myplugin.smx"
                "Plugin"        "Path_SM/translations/myplugin.phrases.txt"
                "Plugin"        "Path_SM/translations/ru/myplugin.phrases.txt"
                "Plugin"        "Path_Mod/models/characters/batman.mdl"
                "Plugin"        "Path_Mod/materials/models/characters/batman.vmt"
               
                "Source"        "Path_SM/scripting/myplugin.sp"
        }
}

All web paths are relative to your plugin's update file (UPDATE_URL in this case). Using the above example, the URLs for this update would look like this:

Code:

UPDATE_URL = http://website.com/myplugin/updatefile.txt

http://website.com/myplugin/plugins/myplugin.smx
http://website.com/myplugin/translations/myplugin.phrases.txt
http://website.com/myplugin/translations/ru/myplugin.phrases.txt
http://website.com/myplugin/models/characters/batman.mdl
http://website.com/myplugin/materials/models/characters/batman.vmt
http://website.com/myplugin/scripting/myplugin.sp

Final Notes
  • You should only reload your plugin manually if your plugin can handle late load situations. Otherwise letting it reload automatically during the next mapchange is safest.
  • If you have released a plugin that uses Updater, post a link to it in this thread. I'd like to take a look at it!
  • If you're looking for somewhere to host your update files for free: Updater Integration Using Bitbucket

KyleS 10-08-2011 16:54

Re: Updater
 
Holy smokes nice job!

McFlurry 10-08-2011 17:26

Re: Updater
 
This is pretty awesome, have some bacon. :bacon!:

GoD-Tony 10-12-2011 10:05

Re: Updater
 
Changelog
Quote:

Updater 1.2.2
- Added support for downloading updates using the SteamWorks extension.

Quote:

Updater 1.2.1
- Added support for SourceMod 1.7.
- Minor fixes for http-redirects.

Quote:

Updater 1.2.0
- Changed from KV to SMC for parsing updater manifests.
--- This fixes plugin versions sometimes being converted to float values.
- Removed 10 second startup delay.
- Fixed plugins without an info enum logging garbage data.
- Fixed SSL URLs being incorrectly prefixed.
- Fixed error handling when failing to create files.
- Fixed error log ordering potentially affecting downloads.
- Improved Socket extension support.
--- Added support for HTTP redirects.
--- Improved HTTP error logging.
--- SSL download attempts will now properly throw an error.
- Improved debug error logs.

Quote:

Updater 1.1.5
- Fixed multiple HTTP parsing issues with Sockets.

Quote:

Updater 1.1.4
- Added support for nesting plugins in plugin directory.

Quote:

Updater 1.1.3
- Added command to check Updater status: sm_updater_status
- Disabled HTTP download caching on all extensions.
- Improved error logging.
- Updated documentation.

Quote:

Updater 1.1.1
- Auto-fix urls for SteamTools if missing http prefix.

Quote:

Updater 1.1.0
- Added support for downloading updates using the SteamTools extension.
- Added a command to force all plugins to be checked for updates: sm_updater_check
- Improved logging on unsuccessful updates.

Quote:

Updater 1.0.2
- Added a log message when a plugin was successfully updated.
- Added a log message when Updater restarts itself after being updated.

Quote:

Updater 1.0.1
- Prevent parsing of corrupt KV files
- Added more descriptive update logging
- Updated some documentation
- Minor code changes


Powerlord 10-12-2011 10:37

Re: Updater
 
What's the advantage of using this over Plugin Autoupdater?

GoD-Tony 10-12-2011 10:52

Re: Updater
 
Quote:

Originally Posted by Powerlord (Post 1573485)
What's the advantage of using this over Plugin Autoupdater?

I made this because that plugin had bugs piling up and it wasn't being maintained. I originally made this for SMAC early in the year, but decided to release it as a separate plugin so that anyone could use it in other projects, including my own.

I incorporated this quick list of ideas to start:
Quote:

Originally Posted by GoD-Tony (Post 1562013)
  • Bug fixes.
  • Path_SM support instead of having to hardcode the SourceMod folder (none of my servers used the original name).
  • KeyValue files instead of XML.
  • More features for developers, and less confusing for users.
  • The auto-updating plugin should update itself, so that other plugins can always rely on the latest features/fixes.

In addition, XML wasn't very pawn friendly, and there was a bug that scattered files if the URL or local path was too long. This plugin also lets the user to choose which extension they want to use (some had crashing issues with Sockets).

Despirator 10-12-2011 13:02

Re: Updater
 
thank you GoD-Tony. I really appreciate it

Steell 10-12-2011 14:14

Re: Updater
 
If I may request a feature: can we have an option that makes a backup of a certain file, rather than just replacing it?

GoD-Tony 10-12-2011 15:17

Re: Updater
 
Quote:

Originally Posted by Steell (Post 1573602)
can we have an option that makes a backup of a certain file, rather than just replacing it?

I thought about this before but couldn't decide on a proper way to implement it.

How would you like the backups to work? Should all of the replaced files be grouped into the same folder, or should they keep their directory structure intact but move to /data/updater/backups?

The main problem I see with backups is that they're rendered useless if a plugin is updated twice within a close time-frame. Basically your backups would only be as good as the second newest version.


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

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