diff --git a/src/ARKServerManager/App.config b/src/ARKServerManager/App.config index f75a4ea4..446c2530 100644 --- a/src/ARKServerManager/App.config +++ b/src/ARKServerManager/App.config @@ -825,6 +825,24 @@ False + + True + + + True + + + True + + + True + + + True + + + True + diff --git a/src/ARKServerManager/Config.Designer.cs b/src/ARKServerManager/Config.Designer.cs index f3913c05..7eed5ed1 100644 --- a/src/ARKServerManager/Config.Designer.cs +++ b/src/ARKServerManager/Config.Designer.cs @@ -2890,5 +2890,77 @@ namespace ServerManagerTool { this["SectionDiscordBotIsExpanded"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool AllowDiscordBackup { + get { + return ((bool)(this["AllowDiscordBackup"])); + } + set { + this["AllowDiscordBackup"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool AllowDiscordUpdate { + get { + return ((bool)(this["AllowDiscordUpdate"])); + } + set { + this["AllowDiscordUpdate"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool AllowDiscordStart { + get { + return ((bool)(this["AllowDiscordStart"])); + } + set { + this["AllowDiscordStart"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool AllowDiscordRestart { + get { + return ((bool)(this["AllowDiscordRestart"])); + } + set { + this["AllowDiscordRestart"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool AllowDiscordShutdown { + get { + return ((bool)(this["AllowDiscordShutdown"])); + } + set { + this["AllowDiscordShutdown"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool AllowDiscordStop { + get { + return ((bool)(this["AllowDiscordStop"])); + } + set { + this["AllowDiscordStop"] = value; + } + } } } diff --git a/src/ARKServerManager/Config.settings b/src/ARKServerManager/Config.settings index 8aa116c6..9ee1d712 100644 --- a/src/ARKServerManager/Config.settings +++ b/src/ARKServerManager/Config.settings @@ -800,5 +800,23 @@ False + + True + + + True + + + True + + + True + + + True + + + True + \ No newline at end of file diff --git a/src/ARKServerManager/Globalization/en-US/en-US.xaml b/src/ARKServerManager/Globalization/en-US/en-US.xaml index 1496eb1e..ff889d9f 100644 --- a/src/ARKServerManager/Globalization/en-US/en-US.xaml +++ b/src/ARKServerManager/Globalization/en-US/en-US.xaml @@ -621,6 +621,12 @@ The prefix that must be used when sending a command via discord. Get Token... Help... + If enabled, the backup command can be sent from discord. + If enabled, the restart command can be sent from discord. + If enabled, the shutdown command can be sent from discord. + If enabled, the start command can be sent from discord. + If enabled, the stop command can be sent from discord. + If enabled, the update command can be sent from discord. SMTP Email Settings Host: @@ -1196,7 +1202,19 @@ Discord Bot Details Channel Id: - The id of the discord server channel the bot will listen to. + The id of the discord server channel this profile will listen to. + Allow Backup + If enabled, the profile will listen for backup commands from discord. + Allow Restart + If enabled, the profile will listen for restart commands from discord. + Allow Shutdown + If enabled, the profile will listen for shutdown commands from discord. + Allow Start + If enabled, the profile will listen for start commands from discord. + Allow Stop + If enabled, the profile will listen for stop commands from discord. + Allow Update + If enabled, the profile will listen for update commands from discord. @@ -5548,10 +5566,11 @@ The discord bot requires a valid token so it can log into the discord server\r\nThis can be set in the global settings. The discord bot prefix contains invalid characters. Only letters and numbers are allowed. - Command '{0}' has not been implemented. + Command '{0}' has not been enabled. Unknown command '{0}'. Another command is currently being processed. Another command '{0}' is currently running against profile '{1}'. + Command '{0}' has been disabled for profile '{1}'. The '{0}' command requires a profile id. Profile '{0}' was not found or is not associated with the channel. diff --git a/src/ARKServerManager/Lib/ServerProfile.cs b/src/ARKServerManager/Lib/ServerProfile.cs index d517acb4..d8dc7a6d 100644 --- a/src/ARKServerManager/Lib/ServerProfile.cs +++ b/src/ARKServerManager/Lib/ServerProfile.cs @@ -965,6 +965,54 @@ namespace ServerManagerTool.Lib get { return (string)GetValue(DiscordChannelIdProperty); } set { SetValue(DiscordChannelIdProperty, value); } } + + public static readonly DependencyProperty AllowDiscordBackupProperty = DependencyProperty.Register(nameof(AllowDiscordBackup), typeof(bool), typeof(ServerProfile), new PropertyMetadata(true)); + [DataMember] + public bool AllowDiscordBackup + { + get { return (bool)GetValue(AllowDiscordBackupProperty); } + set { SetValue(AllowDiscordBackupProperty, value); } + } + + public static readonly DependencyProperty AllowDiscordRestartProperty = DependencyProperty.Register(nameof(AllowDiscordRestart), typeof(bool), typeof(ServerProfile), new PropertyMetadata(true)); + [DataMember] + public bool AllowDiscordRestart + { + get { return (bool)GetValue(AllowDiscordRestartProperty); } + set { SetValue(AllowDiscordRestartProperty, value); } + } + + public static readonly DependencyProperty AllowDiscordShutdownProperty = DependencyProperty.Register(nameof(AllowDiscordShutdown), typeof(bool), typeof(ServerProfile), new PropertyMetadata(true)); + [DataMember] + public bool AllowDiscordShutdown + { + get { return (bool)GetValue(AllowDiscordShutdownProperty); } + set { SetValue(AllowDiscordShutdownProperty, value); } + } + + public static readonly DependencyProperty AllowDiscordStartProperty = DependencyProperty.Register(nameof(AllowDiscordStart), typeof(bool), typeof(ServerProfile), new PropertyMetadata(true)); + [DataMember] + public bool AllowDiscordStart + { + get { return (bool)GetValue(AllowDiscordStartProperty); } + set { SetValue(AllowDiscordStartProperty, value); } + } + + public static readonly DependencyProperty AllowDiscordStopProperty = DependencyProperty.Register(nameof(AllowDiscordStop), typeof(bool), typeof(ServerProfile), new PropertyMetadata(true)); + [DataMember] + public bool AllowDiscordStop + { + get { return (bool)GetValue(AllowDiscordStopProperty); } + set { SetValue(AllowDiscordStopProperty, value); } + } + + public static readonly DependencyProperty AllowDiscordUpdateProperty = DependencyProperty.Register(nameof(AllowDiscordUpdate), typeof(bool), typeof(ServerProfile), new PropertyMetadata(true)); + [DataMember] + public bool AllowDiscordUpdate + { + get { return (bool)GetValue(AllowDiscordUpdateProperty); } + set { SetValue(AllowDiscordUpdateProperty, value); } + } #endregion #region Rules diff --git a/src/ARKServerManager/Utils/DiscordBotHelper.cs b/src/ARKServerManager/Utils/DiscordBotHelper.cs index 648bd133..97abbec7 100644 --- a/src/ARKServerManager/Utils/DiscordBotHelper.cs +++ b/src/ARKServerManager/Utils/DiscordBotHelper.cs @@ -49,17 +49,29 @@ namespace ServerManagerTool.Utils return GetServerStatus(channelId, profileId); case CommandType.Backup: - return BackupServer(channelId, profileId, token); + if (Config.Default.AllowDiscordBackup) + return BackupServer(channelId, profileId, token); + return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandNotEnabled"), commandType) }; case CommandType.Restart: - return RestartServer(channelId, profileId, token); + if (Config.Default.AllowDiscordRestart) + return RestartServer(channelId, profileId, token); + return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandNotEnabled"), commandType) }; case CommandType.Shutdown: - return ShutdownServer(channelId, profileId, token); + if (Config.Default.AllowDiscordShutdown) + return ShutdownServer(channelId, profileId, token); + return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandNotEnabled"), commandType) }; case CommandType.Stop: - return StopServer(channelId, profileId, token); + if (Config.Default.AllowDiscordStop) + return StopServer(channelId, profileId, token); + return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandNotEnabled"), commandType) }; case CommandType.Start: - return StartServer(channelId, profileId, token); + if (Config.Default.AllowDiscordStart) + return StartServer(channelId, profileId, token); + return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandNotEnabled"), commandType) }; case CommandType.Update: - return UpdateServer(channelId, profileId, token); + if (Config.Default.AllowDiscordUpdate) + return UpdateServer(channelId, profileId, token); + return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandNotEnabled"), commandType) }; default: return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandUnknown"), commandType) }; @@ -224,6 +236,11 @@ namespace ServerManagerTool.Utils throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileId)); } + if (!server.Profile.AllowDiscordBackup) + { + throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Backup, profileId)); + } + switch (server.Runtime.Status) { case ServerStatus.Initializing: @@ -303,6 +320,11 @@ namespace ServerManagerTool.Utils throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileId)); } + if (!server.Profile.AllowDiscordRestart) + { + throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Restart, profileId)); + } + switch (server.Runtime.Status) { case ServerStatus.Initializing: @@ -385,6 +407,11 @@ namespace ServerManagerTool.Utils throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileId)); } + if (!server.Profile.AllowDiscordShutdown) + { + throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Shutdown, profileId)); + } + switch (server.Runtime.Status) { case ServerStatus.Initializing: @@ -443,7 +470,7 @@ namespace ServerManagerTool.Utils { if (string.IsNullOrWhiteSpace(profileId)) { - return new List { string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMissing"), CommandType.Shutdown) }; + return new List { string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMissing"), CommandType.Stop) }; } // check if another command is being run against the profile @@ -451,7 +478,7 @@ namespace ServerManagerTool.Utils { return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[profileId], profileId) }; } - _currentProfileCommands.Add(profileId, CommandType.Shutdown); + _currentProfileCommands.Add(profileId, CommandType.Stop); ServerProfileSnapshot profile = null; Task task = null; @@ -467,6 +494,11 @@ namespace ServerManagerTool.Utils throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileId)); } + if (!server.Profile.AllowDiscordStop) + { + throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Stop, profileId)); + } + switch (server.Runtime.Status) { case ServerStatus.Initializing: @@ -550,6 +582,11 @@ namespace ServerManagerTool.Utils throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileId)); } + if (!server.Profile.AllowDiscordStart) + { + throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Start, profileId)); + } + switch (server.Runtime.Status) { case ServerStatus.Initializing: @@ -634,6 +671,11 @@ namespace ServerManagerTool.Utils throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileId)); } + if (!server.Profile.AllowDiscordUpdate) + { + throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Update, profileId)); + } + switch (server.Runtime.Status) { case ServerStatus.Initializing: diff --git a/src/ARKServerManager/Windows/GlobalSettingsControl.xaml b/src/ARKServerManager/Windows/GlobalSettingsControl.xaml index b5a3622b..9685a6fd 100644 --- a/src/ARKServerManager/Windows/GlobalSettingsControl.xaml +++ b/src/ARKServerManager/Windows/GlobalSettingsControl.xaml @@ -589,29 +589,41 @@ + - + - + + + + - - - +