Skip to content

Commit

Permalink
reworked server side command for checking new releases
Browse files Browse the repository at this point in the history
  • Loading branch information
derkalle4 committed Nov 19, 2024
1 parent b88578d commit 29c1232
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 9 deletions.
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,25 @@ Simply overwrite all plugin files and they will be reloaded automatically or jus

## Commands

There is currently one server-side command available for this plugin:
There is currently one server-side command available to use via the command line for this plugin:

### update_plugin
### um [check/update] [all/<plugin_name>]

This command triggers the update process for all installed plugins.
This command triggers the update mechanism for all or one specific plugin. Examples:

```bash
# check all plugins for updates (but do not update)
um check all

# update all plugins (including "check all")
um update all

# check specific plugin e.g. UpdateManager itself
um check UpdateManager

# update specific plugin e.g. UpdateManager itself
um update UpdateManager
```

## Configuration

Expand Down
43 changes: 39 additions & 4 deletions src/UpdateManager+Commands.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,54 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Admin;
using CounterStrikeSharp.API.Modules.Commands;

namespace UpdateManager
{
public partial class UpdateManager : BasePlugin
{
[ConsoleCommand("update_plugins", "Updates all supported plugins")]
[CommandHelper(whoCanExecute: CommandUsage.SERVER_ONLY)]
[ConsoleCommand("um", "CS2 Update Manager")]
[RequiresPermissions("@updatemanager/admin")]
[CommandHelper(whoCanExecute: CommandUsage.SERVER_ONLY, minArgs: 2, usage: "[check/update] [all/<plugin_name>]")]
public void CommandUpdatePlugins(CCSPlayerController player, CommandInfo command)
{
// arguments
var commandType = command.GetArg(1);
var pluginName = command.GetArg(2);
bool applyUpdate;
// check action
switch (commandType.ToLower())
{
case "check":
applyUpdate = false;
break;
case "update":
applyUpdate = true;
break;
default:
command.ReplyToCommand("Invalid command. Usage: [check/update] [all/<plugin_name>]");
return;
}
// update plugin list
getPluginList();
// check for updates
UpdateAllPlugins(true).GetAwaiter().GetResult();
// check pluginName
if (pluginName == "all")
{
if (applyUpdate) command.ReplyToCommand(Localizer["command.update_all"]);
else command.ReplyToCommand(Localizer["command.check_all"]);
UpdateAllPlugins(applyUpdate).GetAwaiter().GetResult();
return;
}
else if (_plugins.FirstOrDefault(x => x.Item1 == pluginName) != null)
{
if (applyUpdate) command.ReplyToCommand(Localizer["command.update"].Value.Replace("{plugin}", pluginName));
else command.ReplyToCommand(Localizer["command.check"].Value.Replace("{plugin}", pluginName));
UpdatePlugin(pluginName, applyUpdate).GetAwaiter().GetResult();
}
else
{
command.ReplyToCommand(Localizer["command.plugin_not_found"].Value.Replace("{plugin}", pluginName));
}
}
}
}
8 changes: 7 additions & 1 deletion src/lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,11 @@
"update.error": "[UpdateManager] Fehler beim Aktualisieren des Plugins {pluginName}: {error}",
"update.available": "[UpdateManager] Neue Version verfügbar: {pluginName} v{latestVersion} (aktuell: v{pluginVersion})",
"update.notfound": "[UpdateManager] {pluginName} v{pluginVersion} ist bereits die neueste Version",
"update.success": "[UpdateManager] Plugin {pluginName} aktualisiert von v{pluginVersion} auf v{latestVersion}"
"update.success": "[UpdateManager] Plugin {pluginName} aktualisiert von v{pluginVersion} auf v{latestVersion}",
"command.invalid": "[UpdateManager] Ungültiger Befehl. Verwendung: [check/update] [all/<plugin_name>]",
"command.check_all": "[UpdateManager] Überprüfe {plugin} auf Aktualisierungen...",
"command.check": "[UpdateManager] Überprüfe {plugin} auf Aktualisierungen...",
"command.update_all": "[UpdateManager] Aktualisiere alle Plugins...",
"command.update": "[UpdateManager] Aktualisiere {plugin}...",
"command.plugin_not_found": "[UpdateManager] Plugin {plugin} nicht gefunden"
}
8 changes: 7 additions & 1 deletion src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@
"update.error": "[UpdateManager] Error while updating plugin {pluginName}: {error}",
"update.available": "[UpdateManager] New version available: {pluginName} v{latestVersion} (current: v{pluginVersion})",
"update.notfound": "[UpdateManager] {pluginName} v{pluginVersion} is already the newest version",
"update.success": "[UpdateManager] Plugin {pluginName} updated from v{pluginVersion} to v{latestVersion}"
"update.success": "[UpdateManager] Plugin {pluginName} updated from v{pluginVersion} to v{latestVersion}",
"command.invalid": "[UpdateManager] Invalid command. Usage: [check/update] [all/<plugin_name>]",
"command.check_all": "[UpdateManager] Checking {plugin} for updates...",
"command.check": "[UpdateManager] Checking {plugin} for updates...",
"command.update_all": "[UpdateManager] Updating all plugins...",
"command.update": "[UpdateManager] Updating {plugin}...",
"command.plugin_not_found": "[UpdateManager] Plugin {plugin} not found"
}

0 comments on commit 29c1232

Please sign in to comment.