diff --git a/src/ARKServerManager/Globalization/en-US/en-US.xaml b/src/ARKServerManager/Globalization/en-US/en-US.xaml
index 9c35aa98..97418250 100644
--- a/src/ARKServerManager/Globalization/en-US/en-US.xaml
+++ b/src/ARKServerManager/Globalization/en-US/en-US.xaml
@@ -1214,6 +1214,8 @@
Discord Bot Details
Channel Id:
The id of the discord server channel this profile will listen to.
+ Alias:
+ A unique name to identify your server when using the discord commands, can be used instead of the profile id.
Allow Backup
If enabled, the profile will listen for backup commands from discord.
Allow Restart
@@ -5604,8 +5606,9 @@
Another command '{0}' is currently running against profile '{1}'.
Command '{0}' has been disabled for profile '{1}'.
- The '{0}' command requires a profile id.
+ The '{0}' command requires a profile id or alias.
Profile '{0}' was not found or is not associated with the channel.
+ Multiple profiles with '{0}' were found in the channel, command aborted.
Profile '{0}' is in a state '{1}' that cannot run this command.
Profile '{0}' is currently being updated.
diff --git a/src/ARKServerManager/Lib/ServerProfile.cs b/src/ARKServerManager/Lib/ServerProfile.cs
index 62a4f416..09dc1038 100644
--- a/src/ARKServerManager/Lib/ServerProfile.cs
+++ b/src/ARKServerManager/Lib/ServerProfile.cs
@@ -968,6 +968,14 @@ namespace ServerManagerTool.Lib
set { SetValue(DiscordChannelIdProperty, value); }
}
+ public static readonly DependencyProperty DiscordAliasProperty = DependencyProperty.Register(nameof(DiscordAlias), typeof(string), typeof(ServerProfile), new PropertyMetadata(String.Empty));
+ [DataMember]
+ public string DiscordAlias
+ {
+ get { return (string)GetValue(DiscordAliasProperty); }
+ set { SetValue(DiscordAliasProperty, value); }
+ }
+
public static readonly DependencyProperty AllowDiscordBackupProperty = DependencyProperty.Register(nameof(AllowDiscordBackup), typeof(bool), typeof(ServerProfile), new PropertyMetadata(true));
[DataMember]
public bool AllowDiscordBackup
diff --git a/src/ARKServerManager/UserControls/ServerSettingsControl.xaml b/src/ARKServerManager/UserControls/ServerSettingsControl.xaml
index f499a088..c55acc17 100644
--- a/src/ARKServerManager/UserControls/ServerSettingsControl.xaml
+++ b/src/ARKServerManager/UserControls/ServerSettingsControl.xaml
@@ -1618,6 +1618,9 @@
+
+
+
diff --git a/src/ARKServerManager/Utils/DiscordBotHelper.cs b/src/ARKServerManager/Utils/DiscordBotHelper.cs
index 8a33fe87..dace86c7 100644
--- a/src/ARKServerManager/Utils/DiscordBotHelper.cs
+++ b/src/ARKServerManager/Utils/DiscordBotHelper.cs
@@ -5,7 +5,6 @@ using ServerManagerTool.Enums;
using ServerManagerTool.Lib;
using System;
using System.Collections.Generic;
-using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Threading;
@@ -23,7 +22,7 @@ namespace ServerManagerTool.Utils
public static bool HasRunningCommands => _currentProfileCommands.Count > 0;
- public static IList HandleDiscordCommand(CommandType commandType, string serverId, string channelId, string profileId, CancellationToken token)
+ public static IList HandleDiscordCommand(CommandType commandType, string serverId, string channelId, string profileIdOrAlias, CancellationToken token)
{
// check if incoming values are valid
if (string.IsNullOrWhiteSpace(serverId) || string.IsNullOrWhiteSpace(channelId))
@@ -42,35 +41,35 @@ namespace ServerManagerTool.Utils
switch (commandType)
{
case CommandType.Info:
- return GetServerInfo(channelId, profileId);
+ return GetServerInfo(channelId, profileIdOrAlias);
case CommandType.List:
return GetServerList(channelId);
case CommandType.Status:
- return GetServerStatus(channelId, profileId);
+ return GetServerStatus(channelId, profileIdOrAlias);
case CommandType.Backup:
if (Config.Default.AllowDiscordBackup)
- return BackupServer(channelId, profileId, token);
+ return BackupServer(channelId, profileIdOrAlias, token);
return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandNotEnabled"), commandType) };
case CommandType.Restart:
if (Config.Default.AllowDiscordRestart)
- return RestartServer(channelId, profileId, token);
+ return RestartServer(channelId, profileIdOrAlias, token);
return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandNotEnabled"), commandType) };
case CommandType.Shutdown:
if (Config.Default.AllowDiscordShutdown)
- return ShutdownServer(channelId, profileId, token);
+ return ShutdownServer(channelId, profileIdOrAlias, token);
return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandNotEnabled"), commandType) };
case CommandType.Stop:
if (Config.Default.AllowDiscordStop)
- return StopServer(channelId, profileId, token);
+ return StopServer(channelId, profileIdOrAlias, token);
return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandNotEnabled"), commandType) };
case CommandType.Start:
if (Config.Default.AllowDiscordStart)
- return StartServer(channelId, profileId, token);
+ return StartServer(channelId, profileIdOrAlias, token);
return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandNotEnabled"), commandType) };
case CommandType.Update:
if (Config.Default.AllowDiscordUpdate)
- return UpdateServer(channelId, profileId, token);
+ return UpdateServer(channelId, profileIdOrAlias, token);
return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandNotEnabled"), commandType) };
default:
@@ -93,19 +92,14 @@ namespace ServerManagerTool.Utils
return string.IsNullOrWhiteSpace(translationKey) ? string.Empty : _globalizer.GetResourceString(translationKey) ?? translationKey;
}
- private static IList GetServerInfo(string channelId, string profileId)
+ private static IList GetServerInfo(string channelId, string profileIdOrAlias)
{
- if (string.IsNullOrWhiteSpace(profileId))
+ if (string.IsNullOrWhiteSpace(profileIdOrAlias))
{
return new List { string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMissing"), CommandType.Info) };
}
- // check if another command is being run against the profile
- if (_currentProfileCommands.ContainsKey(profileId))
- {
- return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[profileId], profileId) };
- }
- _currentProfileCommands.Add(profileId, CommandType.Info);
+ var key = string.Empty;
try
{
@@ -115,12 +109,28 @@ namespace ServerManagerTool.Utils
TaskUtils.RunOnUIThreadAsync(() =>
{
- var server = ServerManager.Instance.Servers.FirstOrDefault(s => Equals(channelId, s.Profile.DiscordChannelId) && Equals(profileId, s.Profile.ProfileID));
+ var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId)
+ && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias)));
- if (server is null)
+ if (!serverList.Any())
{
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileIdOrAlias));
}
+ if (serverList.Count() > 1)
+ {
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMultiples"), profileIdOrAlias));
+ }
+
+ var server = serverList.First();
+
+ // check if another command is being run against the profile
+ if (_currentProfileCommands.ContainsKey(server.Profile.ProfileID))
+ {
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[server.Profile.ProfileID], server.Profile.ProfileName));
+ }
+
+ key = server.Profile.ProfileID;
+ _currentProfileCommands.Add(key, CommandType.Info);
switch (server.Runtime.Status)
{
@@ -130,7 +140,7 @@ namespace ServerManagerTool.Utils
case ServerStatus.Uninstalled:
case ServerStatus.Unknown:
case ServerStatus.Updating:
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), profileId, server.Runtime.StatusString));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
}
serverName = server.Profile.ServerName;
@@ -168,7 +178,7 @@ namespace ServerManagerTool.Utils
}
finally
{
- _currentProfileCommands.Remove(profileId);
+ _currentProfileCommands.Remove(key);
}
}
@@ -183,20 +193,21 @@ namespace ServerManagerTool.Utils
response.Add($"**{_globalizer.GetResourceString("DiscordBot_CountLabel")}** {serverList.Count()}");
foreach (var server in serverList)
{
- response.Add($"```{_globalizer.GetResourceString("ServerSettings_ProfileIdLabel")} {server.Profile.ProfileID}\n{_globalizer.GetResourceString("ServerSettings_ProfileLabel")} {server.Profile.ProfileName}\n{_globalizer.GetResourceString("ServerSettings_ServerNameLabel")} {server.Profile.ServerName}```");
+ response.Add($"```{_globalizer.GetResourceString("ServerSettings_ProfileIdLabel")} {server.Profile.ProfileID}\n{_globalizer.GetResourceString("ServerSettings_DiscordAliasLabel")} {server.Profile.DiscordAlias}\n{_globalizer.GetResourceString("ServerSettings_ProfileLabel")} {server.Profile.ProfileName}\n{_globalizer.GetResourceString("ServerSettings_ServerNameLabel")} {server.Profile.ServerName}```");
}
}).Wait();
return response;
}
- private static IList GetServerStatus(string channelId, string profileId)
+ private static IList GetServerStatus(string channelId, string profileIdOrAlias)
{
List response = new List();
TaskUtils.RunOnUIThreadAsync(() =>
{
- var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId) && (string.IsNullOrWhiteSpace(profileId) || Equals(profileId, s.Profile.ProfileID)));
+ var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId)
+ && (string.IsNullOrWhiteSpace(profileIdOrAlias) || Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias)));
response.Add($"**{_globalizer.GetResourceString("DiscordBot_CountLabel")}** {serverList.Count()}");
foreach (var server in serverList)
@@ -208,19 +219,14 @@ namespace ServerManagerTool.Utils
return response;
}
- private static IList BackupServer(string channelId, string profileId, CancellationToken token)
+ private static IList BackupServer(string channelId, string profileIdOrAlias, CancellationToken token)
{
- if (string.IsNullOrWhiteSpace(profileId))
+ if (string.IsNullOrWhiteSpace(profileIdOrAlias))
{
return new List { string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMissing"), CommandType.Backup) };
}
- // check if another command is being run against the profile
- if (_currentProfileCommands.ContainsKey(profileId))
- {
- return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[profileId], profileId) };
- }
- _currentProfileCommands.Add(profileId, CommandType.Backup);
+ var key = string.Empty;
ServerProfileSnapshot profile = null;
Task task = null;
@@ -229,18 +235,34 @@ namespace ServerManagerTool.Utils
{
TaskUtils.RunOnUIThreadAsync(() =>
{
- var server = ServerManager.Instance.Servers.FirstOrDefault(s => Equals(channelId, s.Profile.DiscordChannelId) && Equals(profileId, s.Profile.ProfileID));
+ var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId)
+ && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias)));
- if (server is null)
+ if (!serverList.Any())
{
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileIdOrAlias));
}
+ if (serverList.Count() > 1)
+ {
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMultiples"), profileIdOrAlias));
+ }
+
+ var server = serverList.First();
if (!server.Profile.AllowDiscordBackup)
{
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Backup, profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Backup, server.Profile.ProfileName));
}
+ // check if another command is being run against the profile
+ if (_currentProfileCommands.ContainsKey(server.Profile.ProfileID))
+ {
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[server.Profile.ProfileID], server.Profile.ProfileName));
+ }
+
+ key = server.Profile.ProfileID;
+ _currentProfileCommands.Add(key, CommandType.Backup);
+
switch (server.Runtime.Status)
{
case ServerStatus.Initializing:
@@ -248,7 +270,7 @@ namespace ServerManagerTool.Utils
case ServerStatus.Uninstalled:
case ServerStatus.Unknown:
case ServerStatus.Updating:
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), profileId, server.Runtime.StatusString));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
}
profile = ServerProfileSnapshot.Create(server.Profile);
@@ -267,7 +289,8 @@ namespace ServerManagerTool.Utils
{
TaskUtils.RunOnUIThreadAsync(() =>
{
- var server = ServerManager.Instance.Servers.FirstOrDefault(s => Equals(channelId, s.Profile.DiscordChannelId) && Equals(profileId, s.Profile.ProfileID));
+ var server = ServerManager.Instance.Servers.First(s => Equals(channelId, s.Profile.DiscordChannelId)
+ && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias)));
server.Runtime.UpdateServerStatus(serverStatus, true);
}).Wait();
}
@@ -276,7 +299,7 @@ namespace ServerManagerTool.Utils
task = Task.Run(() =>
{
app.PerformProfileBackup(profile, token);
- _currentProfileCommands.Remove(profileId);
+ _currentProfileCommands.Remove(key);
});
response.Add(string.Format(_globalizer.GetResourceString("DiscordBot_BackupRequested"), profile.ServerName));
@@ -287,24 +310,19 @@ namespace ServerManagerTool.Utils
{
if (task is null)
{
- _currentProfileCommands.Remove(profileId);
+ _currentProfileCommands.Remove(key);
}
}
}
- private static IList RestartServer(string channelId, string profileId, CancellationToken token)
+ private static IList RestartServer(string channelId, string profileIdOrAlias, CancellationToken token)
{
- if (string.IsNullOrWhiteSpace(profileId))
+ if (string.IsNullOrWhiteSpace(profileIdOrAlias))
{
return new List { string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMissing"), CommandType.Restart) };
}
- // check if another command is being run against the profile
- if (_currentProfileCommands.ContainsKey(profileId))
- {
- return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[profileId], profileId) };
- }
- _currentProfileCommands.Add(profileId, CommandType.Restart);
+ var key = string.Empty;
ServerProfileSnapshot profile = null;
Task task = null;
@@ -313,28 +331,44 @@ namespace ServerManagerTool.Utils
{
TaskUtils.RunOnUIThreadAsync(() =>
{
- var server = ServerManager.Instance.Servers.FirstOrDefault(s => Equals(channelId, s.Profile.DiscordChannelId) && Equals(profileId, s.Profile.ProfileID));
+ var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId)
+ && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias)));
- if (server is null)
+ if (!serverList.Any())
{
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileIdOrAlias));
}
+ if (serverList.Count() > 1)
+ {
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMultiples"), profileIdOrAlias));
+ }
+
+ var server = serverList.First();
if (!server.Profile.AllowDiscordRestart)
{
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Restart, profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Restart, server.Profile.ProfileName));
}
+ // check if another command is being run against the profile
+ if (_currentProfileCommands.ContainsKey(server.Profile.ProfileID))
+ {
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[server.Profile.ProfileID], server.Profile.ProfileName));
+ }
+
+ key = server.Profile.ProfileID;
+ _currentProfileCommands.Add(key, CommandType.Restart);
+
switch (server.Runtime.Status)
{
case ServerStatus.Initializing:
case ServerStatus.Stopping:
case ServerStatus.Uninstalled:
case ServerStatus.Unknown:
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), profileId, server.Runtime.StatusString));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
case ServerStatus.Updating:
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), server.Profile.ProfileName));
}
profile = ServerProfileSnapshot.Create(server.Profile);
@@ -354,7 +388,8 @@ namespace ServerManagerTool.Utils
{
TaskUtils.RunOnUIThreadAsync(() =>
{
- var server = ServerManager.Instance.Servers.FirstOrDefault(s => Equals(channelId, s.Profile.DiscordChannelId) && Equals(profileId, s.Profile.ProfileID));
+ var server = ServerManager.Instance.Servers.First(s => Equals(channelId, s.Profile.DiscordChannelId)
+ && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias)));
server.Runtime.UpdateServerStatus(serverStatus, true);
}).Wait();
}
@@ -363,7 +398,7 @@ namespace ServerManagerTool.Utils
task = Task.Run(() =>
{
app.PerformProfileShutdown(profile, true, false, false, token);
- _currentProfileCommands.Remove(profileId);
+ _currentProfileCommands.Remove(key);
});
response.Add(string.Format(_globalizer.GetResourceString("DiscordBot_RestartRequested"), profile.ServerName));
@@ -374,24 +409,19 @@ namespace ServerManagerTool.Utils
{
if (task is null)
{
- _currentProfileCommands.Remove(profileId);
+ _currentProfileCommands.Remove(key);
}
}
}
- private static IList ShutdownServer(string channelId, string profileId, CancellationToken token)
+ private static IList ShutdownServer(string channelId, string profileIdOrAlias, CancellationToken token)
{
- if (string.IsNullOrWhiteSpace(profileId))
+ if (string.IsNullOrWhiteSpace(profileIdOrAlias))
{
return new List { string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMissing"), CommandType.Shutdown) };
}
- // check if another command is being run against the profile
- if (_currentProfileCommands.ContainsKey(profileId))
- {
- return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[profileId], profileId) };
- }
- _currentProfileCommands.Add(profileId, CommandType.Shutdown);
+ var key = string.Empty;
ServerProfileSnapshot profile = null;
Task task = null;
@@ -400,18 +430,34 @@ namespace ServerManagerTool.Utils
{
TaskUtils.RunOnUIThreadAsync(() =>
{
- var server = ServerManager.Instance.Servers.FirstOrDefault(s => Equals(channelId, s.Profile.DiscordChannelId) && Equals(profileId, s.Profile.ProfileID));
+ var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId)
+ && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias)));
- if (server is null)
+ if (!serverList.Any())
{
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileIdOrAlias));
}
+ if (serverList.Count() > 1)
+ {
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMultiples"), profileIdOrAlias));
+ }
+
+ var server = serverList.First();
if (!server.Profile.AllowDiscordShutdown)
{
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Shutdown, profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Shutdown, server.Profile.ProfileName));
}
+ // check if another command is being run against the profile
+ if (_currentProfileCommands.ContainsKey(server.Profile.ProfileID))
+ {
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[server.Profile.ProfileID], server.Profile.ProfileName));
+ }
+
+ key = server.Profile.ProfileID;
+ _currentProfileCommands.Add(key, CommandType.Shutdown);
+
switch (server.Runtime.Status)
{
case ServerStatus.Initializing:
@@ -419,10 +465,10 @@ namespace ServerManagerTool.Utils
case ServerStatus.Stopped:
case ServerStatus.Uninstalled:
case ServerStatus.Unknown:
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), profileId, server.Runtime.StatusString));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
case ServerStatus.Updating:
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), server.Profile.ProfileName));
}
profile = ServerProfileSnapshot.Create(server.Profile);
@@ -441,7 +487,8 @@ namespace ServerManagerTool.Utils
{
TaskUtils.RunOnUIThreadAsync(() =>
{
- var server = ServerManager.Instance.Servers.FirstOrDefault(s => Equals(channelId, s.Profile.DiscordChannelId) && Equals(profileId, s.Profile.ProfileID));
+ var server = ServerManager.Instance.Servers.First(s => Equals(channelId, s.Profile.DiscordChannelId)
+ && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias)));
server.Runtime.UpdateServerStatus(serverStatus, true);
}).Wait();
}
@@ -450,7 +497,7 @@ namespace ServerManagerTool.Utils
task = Task.Run(() =>
{
app.PerformProfileShutdown(profile, false, false, false, token);
- _currentProfileCommands.Remove(profileId);
+ _currentProfileCommands.Remove(key);
});
response.Add(string.Format(_globalizer.GetResourceString("DiscordBot_ShutdownRequested"), profile.ServerName));
@@ -461,24 +508,19 @@ namespace ServerManagerTool.Utils
{
if (task is null)
{
- _currentProfileCommands.Remove(profileId);
+ _currentProfileCommands.Remove(key);
}
}
}
- private static IList StopServer(string channelId, string profileId, CancellationToken token)
+ private static IList StopServer(string channelId, string profileIdOrAlias, CancellationToken token)
{
- if (string.IsNullOrWhiteSpace(profileId))
+ if (string.IsNullOrWhiteSpace(profileIdOrAlias))
{
return new List { string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMissing"), CommandType.Stop) };
}
- // check if another command is being run against the profile
- if (_currentProfileCommands.ContainsKey(profileId))
- {
- return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[profileId], profileId) };
- }
- _currentProfileCommands.Add(profileId, CommandType.Stop);
+ var key = string.Empty;
ServerProfileSnapshot profile = null;
Task task = null;
@@ -487,18 +529,34 @@ namespace ServerManagerTool.Utils
{
TaskUtils.RunOnUIThreadAsync(() =>
{
- var server = ServerManager.Instance.Servers.FirstOrDefault(s => Equals(channelId, s.Profile.DiscordChannelId) && Equals(profileId, s.Profile.ProfileID));
+ var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId)
+ && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias)));
- if (server is null)
+ if (!serverList.Any())
{
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileIdOrAlias));
}
+ if (serverList.Count() > 1)
+ {
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMultiples"), profileIdOrAlias));
+ }
+
+ var server = serverList.First();
if (!server.Profile.AllowDiscordStop)
{
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Stop, profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Stop, server.Profile.ProfileName));
}
+ // check if another command is being run against the profile
+ if (_currentProfileCommands.ContainsKey(server.Profile.ProfileID))
+ {
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[server.Profile.ProfileID], server.Profile.ProfileName));
+ }
+
+ key = server.Profile.ProfileID;
+ _currentProfileCommands.Add(key, CommandType.Stop);
+
switch (server.Runtime.Status)
{
case ServerStatus.Initializing:
@@ -506,10 +564,10 @@ namespace ServerManagerTool.Utils
case ServerStatus.Stopped:
case ServerStatus.Uninstalled:
case ServerStatus.Unknown:
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), profileId, server.Runtime.StatusString));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
case ServerStatus.Updating:
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), server.Profile.ProfileName));
}
profile = ServerProfileSnapshot.Create(server.Profile);
@@ -529,7 +587,8 @@ namespace ServerManagerTool.Utils
{
TaskUtils.RunOnUIThreadAsync(() =>
{
- var server = ServerManager.Instance.Servers.FirstOrDefault(s => Equals(channelId, s.Profile.DiscordChannelId) && Equals(profileId, s.Profile.ProfileID));
+ var server = ServerManager.Instance.Servers.First(s => Equals(channelId, s.Profile.DiscordChannelId)
+ && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias)));
server.Runtime.UpdateServerStatus(serverStatus, true);
}).Wait();
}
@@ -538,7 +597,7 @@ namespace ServerManagerTool.Utils
task = Task.Run(() =>
{
app.PerformProfileShutdown(profile, false, false, false, token);
- _currentProfileCommands.Remove(profileId);
+ _currentProfileCommands.Remove(key);
});
response.Add(string.Format(_globalizer.GetResourceString("DiscordBot_StopRequested"), profile.ServerName));
@@ -549,24 +608,19 @@ namespace ServerManagerTool.Utils
{
if (task is null)
{
- _currentProfileCommands.Remove(profileId);
+ _currentProfileCommands.Remove(key);
}
}
}
- private static IList StartServer(string channelId, string profileId, CancellationToken token)
+ private static IList StartServer(string channelId, string profileIdOrAlias, CancellationToken token)
{
- if (string.IsNullOrWhiteSpace(profileId))
+ if (string.IsNullOrWhiteSpace(profileIdOrAlias))
{
return new List { string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMissing"), CommandType.Start) };
}
- // check if another command is being run against the profile
- if (_currentProfileCommands.ContainsKey(profileId))
- {
- return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[profileId], profileId) };
- }
- _currentProfileCommands.Add(profileId, CommandType.Start);
+ var key = string.Empty;
ServerProfileSnapshot profile = null;
Task task = null;
@@ -575,18 +629,34 @@ namespace ServerManagerTool.Utils
{
TaskUtils.RunOnUIThreadAsync(() =>
{
- var server = ServerManager.Instance.Servers.FirstOrDefault(s => Equals(channelId, s.Profile.DiscordChannelId) && Equals(profileId, s.Profile.ProfileID));
+ var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId)
+ && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias)));
- if (server is null)
+ if (!serverList.Any())
{
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileIdOrAlias));
}
+ if (serverList.Count() > 1)
+ {
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMultiples"), profileIdOrAlias));
+ }
+
+ var server = serverList.First();
if (!server.Profile.AllowDiscordStart)
{
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Start, profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Start, server.Profile.ProfileName));
}
+ // check if another command is being run against the profile
+ if (_currentProfileCommands.ContainsKey(server.Profile.ProfileID))
+ {
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[server.Profile.ProfileID], server.Profile.ProfileName));
+ }
+
+ key = server.Profile.ProfileID;
+ _currentProfileCommands.Add(key, CommandType.Start);
+
switch (server.Runtime.Status)
{
case ServerStatus.Initializing:
@@ -594,10 +664,10 @@ namespace ServerManagerTool.Utils
case ServerStatus.Running:
case ServerStatus.Uninstalled:
case ServerStatus.Unknown:
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), profileId, server.Runtime.StatusString));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
case ServerStatus.Updating:
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), server.Profile.ProfileName));
}
profile = ServerProfileSnapshot.Create(server.Profile);
@@ -617,7 +687,8 @@ namespace ServerManagerTool.Utils
{
TaskUtils.RunOnUIThreadAsync(() =>
{
- var server = ServerManager.Instance.Servers.FirstOrDefault(s => Equals(channelId, s.Profile.DiscordChannelId) && Equals(profileId, s.Profile.ProfileID));
+ var server = ServerManager.Instance.Servers.First(s => Equals(channelId, s.Profile.DiscordChannelId)
+ && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias)));
server.Runtime.UpdateServerStatus(serverStatus, true);
}).Wait();
}
@@ -626,7 +697,7 @@ namespace ServerManagerTool.Utils
task = Task.Run(() =>
{
app.PerformProfileShutdown(profile, true, false, false, token);
- _currentProfileCommands.Remove(profileId);
+ _currentProfileCommands.Remove(key);
});
response.Add(string.Format(_globalizer.GetResourceString("DiscordBot_StartRequested"), profile.ServerName));
@@ -637,24 +708,19 @@ namespace ServerManagerTool.Utils
{
if (task is null)
{
- _currentProfileCommands.Remove(profileId);
+ _currentProfileCommands.Remove(key);
}
}
}
- private static IList UpdateServer(string channelId, string profileId, CancellationToken token)
+ private static IList UpdateServer(string channelId, string profileIdOrAlias, CancellationToken token)
{
- if (string.IsNullOrWhiteSpace(profileId))
+ if (string.IsNullOrWhiteSpace(profileIdOrAlias))
{
return new List { string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMissing"), CommandType.Update) };
}
- // check if another command is being run against the profile
- if (_currentProfileCommands.ContainsKey(profileId))
- {
- return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[profileId], profileId) };
- }
- _currentProfileCommands.Add(profileId, CommandType.Update);
+ var key = string.Empty;
ServerProfileSnapshot profile = null;
bool performRestart = false;
@@ -664,31 +730,47 @@ namespace ServerManagerTool.Utils
{
TaskUtils.RunOnUIThreadAsync(() =>
{
- var server = ServerManager.Instance.Servers.FirstOrDefault(s => Equals(channelId, s.Profile.DiscordChannelId) && Equals(profileId, s.Profile.ProfileID));
+ var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId)
+ && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias)));
- if (server is null)
+ if (!serverList.Any())
{
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileIdOrAlias));
}
+ if (serverList.Count() > 1)
+ {
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMultiples"), profileIdOrAlias));
+ }
+
+ var server = serverList.First();
if (!server.Profile.AllowDiscordUpdate)
{
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Update, profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Update, server.Profile.ProfileName));
}
+ // check if another command is being run against the profile
+ if (_currentProfileCommands.ContainsKey(server.Profile.ProfileID))
+ {
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[server.Profile.ProfileID], server.Profile.ProfileName));
+ }
+
+ key = server.Profile.ProfileID;
+ _currentProfileCommands.Add(key, CommandType.Update);
+
switch (server.Runtime.Status)
{
case ServerStatus.Initializing:
case ServerStatus.Stopping:
case ServerStatus.Unknown:
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), profileId, server.Runtime.StatusString));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
case ServerStatus.Running:
performRestart = true;
break;
case ServerStatus.Updating:
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), server.Profile.ProfileName));
}
profile = ServerProfileSnapshot.Create(server.Profile);
@@ -707,7 +789,8 @@ namespace ServerManagerTool.Utils
{
TaskUtils.RunOnUIThreadAsync(() =>
{
- var server = ServerManager.Instance.Servers.FirstOrDefault(s => Equals(channelId, s.Profile.DiscordChannelId) && Equals(profileId, s.Profile.ProfileID));
+ var server = ServerManager.Instance.Servers.First(s => Equals(channelId, s.Profile.DiscordChannelId)
+ && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias)));
server.Runtime.UpdateServerStatus(serverStatus, true);
}).Wait();
}
@@ -716,7 +799,7 @@ namespace ServerManagerTool.Utils
task = Task.Run(() =>
{
app.PerformProfileShutdown(profile, performRestart, true, false, token);
- _currentProfileCommands.Remove(profileId);
+ _currentProfileCommands.Remove(key);
});
response.Add(string.Format(_globalizer.GetResourceString("DiscordBot_UpdateRequested"), profile.ServerName));
@@ -727,7 +810,7 @@ namespace ServerManagerTool.Utils
{
if (task is null)
{
- _currentProfileCommands.Remove(profileId);
+ _currentProfileCommands.Remove(key);
}
}
}
diff --git a/src/ARKServerManager/VersionFeed.xml b/src/ARKServerManager/VersionFeed.xml
index 1edb9430..3ddde9e2 100644
--- a/src/ARKServerManager/VersionFeed.xml
+++ b/src/ARKServerManager/VersionFeed.xml
@@ -20,6 +20,7 @@
- Global Settings - Discord Bot section - Added a whitelist to allow bots to send commands to the server manager.
+ - Server Settings - Discord Bot section - Added an alias that can be used with the discord command instead of the profile id.
CHANGE
diff --git a/src/ARKServerManager/VersionFeedBeta.xml b/src/ARKServerManager/VersionFeedBeta.xml
index 0df1dce2..305b1186 100644
--- a/src/ARKServerManager/VersionFeedBeta.xml
+++ b/src/ARKServerManager/VersionFeedBeta.xml
@@ -16,6 +16,11 @@
+ NEW
+
+
+ - Server Settings - Discord Bot section - Added an alias that can be used with the discord command instead of the profile id.
+
CHANGE
diff --git a/src/ConanServerManager/Globalization/en-US/en-US.xaml b/src/ConanServerManager/Globalization/en-US/en-US.xaml
index 92e1de83..486b8e37 100644
--- a/src/ConanServerManager/Globalization/en-US/en-US.xaml
+++ b/src/ConanServerManager/Globalization/en-US/en-US.xaml
@@ -1154,6 +1154,8 @@
Discord Bot Details
Channel Id:
The id of the discord server channel this profile will listen to.
+ Alias:
+ A unique name to identify your server when using the discord commands, can be used instead of the profile id.
Allow Backup
If enabled, the profile will listen for backup commands from discord.
Allow Restart
@@ -1251,8 +1253,9 @@
Another command '{0}' is currently running against profile '{1}'.
Command '{0}' has been disabled for profile '{1}'.
- The '{0}' command requires a profile id.
+ The '{0}' command requires a profile id or alias.
Profile '{0}' was not found or is not associated with the channel.
+ Multiple profiles with '{0}' were found in the channel, command aborted.
Profile '{0}' is in a state '{1}' that cannot run this command.
Profile '{0}' is currently being updated.
diff --git a/src/ConanServerManager/Lib/ServerProfile.cs b/src/ConanServerManager/Lib/ServerProfile.cs
index 428bad2d..cc62450c 100644
--- a/src/ConanServerManager/Lib/ServerProfile.cs
+++ b/src/ConanServerManager/Lib/ServerProfile.cs
@@ -576,6 +576,14 @@ namespace ServerManagerTool.Lib
set { SetValue(DiscordChannelIdProperty, value); }
}
+ public static readonly DependencyProperty DiscordAliasProperty = DependencyProperty.Register(nameof(DiscordAlias), typeof(string), typeof(ServerProfile), new PropertyMetadata(String.Empty));
+ [DataMember]
+ public string DiscordAlias
+ {
+ get { return (string)GetValue(DiscordAliasProperty); }
+ set { SetValue(DiscordAliasProperty, value); }
+ }
+
public static readonly DependencyProperty AllowDiscordBackupProperty = DependencyProperty.Register(nameof(AllowDiscordBackup), typeof(bool), typeof(ServerProfile), new PropertyMetadata(true));
[DataMember]
public bool AllowDiscordBackup
diff --git a/src/ConanServerManager/UserControls/ServerSettingsControl.xaml b/src/ConanServerManager/UserControls/ServerSettingsControl.xaml
index bfa7cb8f..1538ee97 100644
--- a/src/ConanServerManager/UserControls/ServerSettingsControl.xaml
+++ b/src/ConanServerManager/UserControls/ServerSettingsControl.xaml
@@ -1093,6 +1093,9 @@
+
+
+
diff --git a/src/ConanServerManager/Utils/DiscordBotHelper.cs b/src/ConanServerManager/Utils/DiscordBotHelper.cs
index 29ebce75..aa82a14c 100644
--- a/src/ConanServerManager/Utils/DiscordBotHelper.cs
+++ b/src/ConanServerManager/Utils/DiscordBotHelper.cs
@@ -5,7 +5,6 @@ using ServerManagerTool.Enums;
using ServerManagerTool.Lib;
using System;
using System.Collections.Generic;
-using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Threading;
@@ -23,7 +22,7 @@ namespace ServerManagerTool.Utils
public static bool HasRunningCommands => _currentProfileCommands.Count > 0;
- public static IList HandleDiscordCommand(CommandType commandType, string serverId, string channelId, string profileId, CancellationToken token)
+ public static IList HandleDiscordCommand(CommandType commandType, string serverId, string channelId, string profileIdOrAlias, CancellationToken token)
{
// check if incoming values are valid
if (string.IsNullOrWhiteSpace(serverId) || string.IsNullOrWhiteSpace(channelId))
@@ -42,35 +41,35 @@ namespace ServerManagerTool.Utils
switch (commandType)
{
case CommandType.Info:
- return GetServerInfo(channelId, profileId);
+ return GetServerInfo(channelId, profileIdOrAlias);
case CommandType.List:
return GetServerList(channelId);
case CommandType.Status:
- return GetServerStatus(channelId, profileId);
+ return GetServerStatus(channelId, profileIdOrAlias);
case CommandType.Backup:
if (Config.Default.AllowDiscordBackup)
- return BackupServer(channelId, profileId, token);
+ return BackupServer(channelId, profileIdOrAlias, token);
return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandNotEnabled"), commandType) };
case CommandType.Restart:
if (Config.Default.AllowDiscordRestart)
- return RestartServer(channelId, profileId, token);
+ return RestartServer(channelId, profileIdOrAlias, token);
return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandNotEnabled"), commandType) };
case CommandType.Shutdown:
if (Config.Default.AllowDiscordShutdown)
- return ShutdownServer(channelId, profileId, token);
+ return ShutdownServer(channelId, profileIdOrAlias, token);
return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandNotEnabled"), commandType) };
case CommandType.Stop:
if (Config.Default.AllowDiscordStop)
- return StopServer(channelId, profileId, token);
+ return StopServer(channelId, profileIdOrAlias, token);
return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandNotEnabled"), commandType) };
case CommandType.Start:
if (Config.Default.AllowDiscordStart)
- return StartServer(channelId, profileId, token);
+ return StartServer(channelId, profileIdOrAlias, token);
return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandNotEnabled"), commandType) };
case CommandType.Update:
if (Config.Default.AllowDiscordUpdate)
- return UpdateServer(channelId, profileId, token);
+ return UpdateServer(channelId, profileIdOrAlias, token);
return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandNotEnabled"), commandType) };
default:
@@ -93,19 +92,14 @@ namespace ServerManagerTool.Utils
return string.IsNullOrWhiteSpace(translationKey) ? string.Empty : _globalizer.GetResourceString(translationKey) ?? translationKey;
}
- private static IList GetServerInfo(string channelId, string profileId)
+ private static IList GetServerInfo(string channelId, string profileIdOrAlias)
{
- if (string.IsNullOrWhiteSpace(profileId))
+ if (string.IsNullOrWhiteSpace(profileIdOrAlias))
{
return new List { string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMissing"), CommandType.Info) };
}
- // check if another command is being run against the profile
- if (_currentProfileCommands.ContainsKey(profileId))
- {
- return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[profileId], profileId) };
- }
- _currentProfileCommands.Add(profileId, CommandType.Info);
+ var key = string.Empty;
try
{
@@ -115,12 +109,28 @@ namespace ServerManagerTool.Utils
TaskUtils.RunOnUIThreadAsync(() =>
{
- var server = ServerManager.Instance.Servers.FirstOrDefault(s => Equals(channelId, s.Profile.DiscordChannelId) && Equals(profileId, s.Profile.ProfileID));
+ var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId)
+ && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias)));
- if (server is null)
+ if (!serverList.Any())
{
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileIdOrAlias));
}
+ if (serverList.Count() > 1)
+ {
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMultiples"), profileIdOrAlias));
+ }
+
+ var server = serverList.First();
+
+ // check if another command is being run against the profile
+ if (_currentProfileCommands.ContainsKey(server.Profile.ProfileID))
+ {
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[server.Profile.ProfileID], server.Profile.ProfileName));
+ }
+
+ key = server.Profile.ProfileID;
+ _currentProfileCommands.Add(key, CommandType.Info);
switch (server.Runtime.Status)
{
@@ -130,7 +140,7 @@ namespace ServerManagerTool.Utils
case ServerStatus.Uninstalled:
case ServerStatus.Unknown:
case ServerStatus.Updating:
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), profileId, server.Runtime.StatusString));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
}
serverName = server.Profile.ServerName;
@@ -168,7 +178,7 @@ namespace ServerManagerTool.Utils
}
finally
{
- _currentProfileCommands.Remove(profileId);
+ _currentProfileCommands.Remove(key);
}
}
@@ -183,20 +193,21 @@ namespace ServerManagerTool.Utils
response.Add($"**{_globalizer.GetResourceString("DiscordBot_CountLabel")}** {serverList.Count()}");
foreach (var server in serverList)
{
- response.Add($"```{_globalizer.GetResourceString("ServerSettings_ProfileIdLabel")} {server.Profile.ProfileID}\n{_globalizer.GetResourceString("ServerSettings_ProfileLabel")} {server.Profile.ProfileName}\n{_globalizer.GetResourceString("ServerSettings_ServerNameLabel")} {server.Profile.ServerName}```");
+ response.Add($"```{_globalizer.GetResourceString("ServerSettings_ProfileIdLabel")} {server.Profile.ProfileID}\n{_globalizer.GetResourceString("ServerSettings_DiscordAliasLabel")} {server.Profile.DiscordAlias}\n{_globalizer.GetResourceString("ServerSettings_ProfileLabel")} {server.Profile.ProfileName}\n{_globalizer.GetResourceString("ServerSettings_ServerNameLabel")} {server.Profile.ServerName}```");
}
}).Wait();
return response;
}
- private static IList GetServerStatus(string channelId, string profileId)
+ private static IList GetServerStatus(string channelId, string profileIdOrAlias)
{
List response = new List();
TaskUtils.RunOnUIThreadAsync(() =>
{
- var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId) && (string.IsNullOrWhiteSpace(profileId) || Equals(profileId, s.Profile.ProfileID)));
+ var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId)
+ && (string.IsNullOrWhiteSpace(profileIdOrAlias) || Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias)));
response.Add($"**{_globalizer.GetResourceString("DiscordBot_CountLabel")}** {serverList.Count()}");
foreach (var server in serverList)
@@ -208,19 +219,14 @@ namespace ServerManagerTool.Utils
return response;
}
- private static IList BackupServer(string channelId, string profileId, CancellationToken token)
+ private static IList BackupServer(string channelId, string profileIdOrAlias, CancellationToken token)
{
- if (string.IsNullOrWhiteSpace(profileId))
+ if (string.IsNullOrWhiteSpace(profileIdOrAlias))
{
return new List { string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMissing"), CommandType.Backup) };
}
- // check if another command is being run against the profile
- if (_currentProfileCommands.ContainsKey(profileId))
- {
- return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[profileId], profileId) };
- }
- _currentProfileCommands.Add(profileId, CommandType.Backup);
+ var key = string.Empty;
ServerProfileSnapshot profile = null;
Task task = null;
@@ -229,18 +235,34 @@ namespace ServerManagerTool.Utils
{
TaskUtils.RunOnUIThreadAsync(() =>
{
- var server = ServerManager.Instance.Servers.FirstOrDefault(s => Equals(channelId, s.Profile.DiscordChannelId) && Equals(profileId, s.Profile.ProfileID));
+ var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId)
+ && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias)));
- if (server is null)
+ if (!serverList.Any())
{
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileIdOrAlias));
}
+ if (serverList.Count() > 1)
+ {
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMultiples"), profileIdOrAlias));
+ }
+
+ var server = serverList.First();
if (!server.Profile.AllowDiscordBackup)
{
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Backup, profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Backup, server.Profile.ProfileName));
}
+ // check if another command is being run against the profile
+ if (_currentProfileCommands.ContainsKey(server.Profile.ProfileID))
+ {
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[server.Profile.ProfileID], server.Profile.ProfileName));
+ }
+
+ key = server.Profile.ProfileID;
+ _currentProfileCommands.Add(key, CommandType.Backup);
+
switch (server.Runtime.Status)
{
case ServerStatus.Initializing:
@@ -248,7 +270,7 @@ namespace ServerManagerTool.Utils
case ServerStatus.Uninstalled:
case ServerStatus.Unknown:
case ServerStatus.Updating:
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), profileId, server.Runtime.StatusString));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
}
profile = ServerProfileSnapshot.Create(server.Profile);
@@ -267,7 +289,8 @@ namespace ServerManagerTool.Utils
{
TaskUtils.RunOnUIThreadAsync(() =>
{
- var server = ServerManager.Instance.Servers.FirstOrDefault(s => Equals(channelId, s.Profile.DiscordChannelId) && Equals(profileId, s.Profile.ProfileID));
+ var server = ServerManager.Instance.Servers.First(s => Equals(channelId, s.Profile.DiscordChannelId)
+ && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias)));
server.Runtime.UpdateServerStatus(serverStatus, true);
}).Wait();
}
@@ -276,7 +299,7 @@ namespace ServerManagerTool.Utils
task = Task.Run(() =>
{
app.PerformProfileBackup(profile, token);
- _currentProfileCommands.Remove(profileId);
+ _currentProfileCommands.Remove(key);
});
response.Add(string.Format(_globalizer.GetResourceString("DiscordBot_BackupRequested"), profile.ServerName));
@@ -287,24 +310,19 @@ namespace ServerManagerTool.Utils
{
if (task is null)
{
- _currentProfileCommands.Remove(profileId);
+ _currentProfileCommands.Remove(key);
}
}
}
- private static IList RestartServer(string channelId, string profileId, CancellationToken token)
+ private static IList RestartServer(string channelId, string profileIdOrAlias, CancellationToken token)
{
- if (string.IsNullOrWhiteSpace(profileId))
+ if (string.IsNullOrWhiteSpace(profileIdOrAlias))
{
return new List { string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMissing"), CommandType.Restart) };
}
- // check if another command is being run against the profile
- if (_currentProfileCommands.ContainsKey(profileId))
- {
- return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[profileId], profileId) };
- }
- _currentProfileCommands.Add(profileId, CommandType.Restart);
+ var key = string.Empty;
ServerProfileSnapshot profile = null;
Task task = null;
@@ -313,28 +331,44 @@ namespace ServerManagerTool.Utils
{
TaskUtils.RunOnUIThreadAsync(() =>
{
- var server = ServerManager.Instance.Servers.FirstOrDefault(s => Equals(channelId, s.Profile.DiscordChannelId) && Equals(profileId, s.Profile.ProfileID));
+ var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId)
+ && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias)));
- if (server is null)
+ if (!serverList.Any())
{
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileIdOrAlias));
}
+ if (serverList.Count() > 1)
+ {
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMultiples"), profileIdOrAlias));
+ }
+
+ var server = serverList.First();
if (!server.Profile.AllowDiscordRestart)
{
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Restart, profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Restart, server.Profile.ProfileName));
}
+ // check if another command is being run against the profile
+ if (_currentProfileCommands.ContainsKey(server.Profile.ProfileID))
+ {
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[server.Profile.ProfileID], server.Profile.ProfileName));
+ }
+
+ key = server.Profile.ProfileID;
+ _currentProfileCommands.Add(key, CommandType.Restart);
+
switch (server.Runtime.Status)
{
case ServerStatus.Initializing:
case ServerStatus.Stopping:
case ServerStatus.Uninstalled:
case ServerStatus.Unknown:
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), profileId, server.Runtime.StatusString));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
case ServerStatus.Updating:
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), server.Profile.ProfileName));
}
profile = ServerProfileSnapshot.Create(server.Profile);
@@ -354,7 +388,8 @@ namespace ServerManagerTool.Utils
{
TaskUtils.RunOnUIThreadAsync(() =>
{
- var server = ServerManager.Instance.Servers.FirstOrDefault(s => Equals(channelId, s.Profile.DiscordChannelId) && Equals(profileId, s.Profile.ProfileID));
+ var server = ServerManager.Instance.Servers.First(s => Equals(channelId, s.Profile.DiscordChannelId)
+ && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias)));
server.Runtime.UpdateServerStatus(serverStatus, true);
}).Wait();
}
@@ -363,7 +398,7 @@ namespace ServerManagerTool.Utils
task = Task.Run(() =>
{
app.PerformProfileShutdown(profile, true, false, false, false, token);
- _currentProfileCommands.Remove(profileId);
+ _currentProfileCommands.Remove(key);
});
response.Add(string.Format(_globalizer.GetResourceString("DiscordBot_RestartRequested"), profile.ServerName));
@@ -374,24 +409,19 @@ namespace ServerManagerTool.Utils
{
if (task is null)
{
- _currentProfileCommands.Remove(profileId);
+ _currentProfileCommands.Remove(key);
}
}
}
- private static IList ShutdownServer(string channelId, string profileId, CancellationToken token)
+ private static IList ShutdownServer(string channelId, string profileIdOrAlias, CancellationToken token)
{
- if (string.IsNullOrWhiteSpace(profileId))
+ if (string.IsNullOrWhiteSpace(profileIdOrAlias))
{
return new List { string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMissing"), CommandType.Shutdown) };
}
- // check if another command is being run against the profile
- if (_currentProfileCommands.ContainsKey(profileId))
- {
- return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[profileId], profileId) };
- }
- _currentProfileCommands.Add(profileId, CommandType.Shutdown);
+ var key = string.Empty;
ServerProfileSnapshot profile = null;
Task task = null;
@@ -400,18 +430,34 @@ namespace ServerManagerTool.Utils
{
TaskUtils.RunOnUIThreadAsync(() =>
{
- var server = ServerManager.Instance.Servers.FirstOrDefault(s => Equals(channelId, s.Profile.DiscordChannelId) && Equals(profileId, s.Profile.ProfileID));
+ var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId)
+ && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias)));
- if (server is null)
+ if (!serverList.Any())
{
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileIdOrAlias));
}
+ if (serverList.Count() > 1)
+ {
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMultiples"), profileIdOrAlias));
+ }
+
+ var server = serverList.First();
if (!server.Profile.AllowDiscordShutdown)
{
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Shutdown, profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Shutdown, server.Profile.ProfileName));
}
+ // check if another command is being run against the profile
+ if (_currentProfileCommands.ContainsKey(server.Profile.ProfileID))
+ {
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[server.Profile.ProfileID], server.Profile.ProfileName));
+ }
+
+ key = server.Profile.ProfileID;
+ _currentProfileCommands.Add(key, CommandType.Shutdown);
+
switch (server.Runtime.Status)
{
case ServerStatus.Initializing:
@@ -419,10 +465,10 @@ namespace ServerManagerTool.Utils
case ServerStatus.Stopped:
case ServerStatus.Uninstalled:
case ServerStatus.Unknown:
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), profileId, server.Runtime.StatusString));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
case ServerStatus.Updating:
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), server.Profile.ProfileName));
}
profile = ServerProfileSnapshot.Create(server.Profile);
@@ -441,7 +487,8 @@ namespace ServerManagerTool.Utils
{
TaskUtils.RunOnUIThreadAsync(() =>
{
- var server = ServerManager.Instance.Servers.FirstOrDefault(s => Equals(channelId, s.Profile.DiscordChannelId) && Equals(profileId, s.Profile.ProfileID));
+ var server = ServerManager.Instance.Servers.First(s => Equals(channelId, s.Profile.DiscordChannelId)
+ && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias)));
server.Runtime.UpdateServerStatus(serverStatus, true);
}).Wait();
}
@@ -450,7 +497,7 @@ namespace ServerManagerTool.Utils
task = Task.Run(() =>
{
app.PerformProfileShutdown(profile, false, false, false, false, token);
- _currentProfileCommands.Remove(profileId);
+ _currentProfileCommands.Remove(key);
});
response.Add(string.Format(_globalizer.GetResourceString("DiscordBot_ShutdownRequested"), profile.ServerName));
@@ -461,24 +508,19 @@ namespace ServerManagerTool.Utils
{
if (task is null)
{
- _currentProfileCommands.Remove(profileId);
+ _currentProfileCommands.Remove(key);
}
}
}
- private static IList StopServer(string channelId, string profileId, CancellationToken token)
+ private static IList StopServer(string channelId, string profileIdOrAlias, CancellationToken token)
{
- if (string.IsNullOrWhiteSpace(profileId))
+ if (string.IsNullOrWhiteSpace(profileIdOrAlias))
{
return new List { string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMissing"), CommandType.Stop) };
}
- // check if another command is being run against the profile
- if (_currentProfileCommands.ContainsKey(profileId))
- {
- return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[profileId], profileId) };
- }
- _currentProfileCommands.Add(profileId, CommandType.Stop);
+ var key = string.Empty;
ServerProfileSnapshot profile = null;
Task task = null;
@@ -487,18 +529,34 @@ namespace ServerManagerTool.Utils
{
TaskUtils.RunOnUIThreadAsync(() =>
{
- var server = ServerManager.Instance.Servers.FirstOrDefault(s => Equals(channelId, s.Profile.DiscordChannelId) && Equals(profileId, s.Profile.ProfileID));
+ var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId)
+ && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias)));
- if (server is null)
+ if (!serverList.Any())
{
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileIdOrAlias));
}
+ if (serverList.Count() > 1)
+ {
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMultiples"), profileIdOrAlias));
+ }
+
+ var server = serverList.First();
if (!server.Profile.AllowDiscordStop)
{
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Stop, profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Stop, server.Profile.ProfileName));
}
+ // check if another command is being run against the profile
+ if (_currentProfileCommands.ContainsKey(server.Profile.ProfileID))
+ {
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[server.Profile.ProfileID], server.Profile.ProfileName));
+ }
+
+ key = server.Profile.ProfileID;
+ _currentProfileCommands.Add(key, CommandType.Stop);
+
switch (server.Runtime.Status)
{
case ServerStatus.Initializing:
@@ -506,10 +564,10 @@ namespace ServerManagerTool.Utils
case ServerStatus.Stopped:
case ServerStatus.Uninstalled:
case ServerStatus.Unknown:
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), profileId, server.Runtime.StatusString));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
case ServerStatus.Updating:
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), server.Profile.ProfileName));
}
profile = ServerProfileSnapshot.Create(server.Profile);
@@ -529,7 +587,8 @@ namespace ServerManagerTool.Utils
{
TaskUtils.RunOnUIThreadAsync(() =>
{
- var server = ServerManager.Instance.Servers.FirstOrDefault(s => Equals(channelId, s.Profile.DiscordChannelId) && Equals(profileId, s.Profile.ProfileID));
+ var server = ServerManager.Instance.Servers.First(s => Equals(channelId, s.Profile.DiscordChannelId)
+ && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias)));
server.Runtime.UpdateServerStatus(serverStatus, true);
}).Wait();
}
@@ -538,7 +597,7 @@ namespace ServerManagerTool.Utils
task = Task.Run(() =>
{
app.PerformProfileShutdown(profile, false, false, false, false, token);
- _currentProfileCommands.Remove(profileId);
+ _currentProfileCommands.Remove(key);
});
response.Add(string.Format(_globalizer.GetResourceString("DiscordBot_StopRequested"), profile.ServerName));
@@ -549,24 +608,19 @@ namespace ServerManagerTool.Utils
{
if (task is null)
{
- _currentProfileCommands.Remove(profileId);
+ _currentProfileCommands.Remove(key);
}
}
}
- private static IList StartServer(string channelId, string profileId, CancellationToken token)
+ private static IList StartServer(string channelId, string profileIdOrAlias, CancellationToken token)
{
- if (string.IsNullOrWhiteSpace(profileId))
+ if (string.IsNullOrWhiteSpace(profileIdOrAlias))
{
return new List { string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMissing"), CommandType.Start) };
}
- // check if another command is being run against the profile
- if (_currentProfileCommands.ContainsKey(profileId))
- {
- return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[profileId], profileId) };
- }
- _currentProfileCommands.Add(profileId, CommandType.Start);
+ var key = string.Empty;
ServerProfileSnapshot profile = null;
Task task = null;
@@ -575,18 +629,34 @@ namespace ServerManagerTool.Utils
{
TaskUtils.RunOnUIThreadAsync(() =>
{
- var server = ServerManager.Instance.Servers.FirstOrDefault(s => Equals(channelId, s.Profile.DiscordChannelId) && Equals(profileId, s.Profile.ProfileID));
+ var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId)
+ && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias)));
- if (server is null)
+ if (!serverList.Any())
{
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileIdOrAlias));
}
+ if (serverList.Count() > 1)
+ {
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMultiples"), profileIdOrAlias));
+ }
+
+ var server = serverList.First();
if (!server.Profile.AllowDiscordStart)
{
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Start, profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Start, server.Profile.ProfileName));
}
+ // check if another command is being run against the profile
+ if (_currentProfileCommands.ContainsKey(server.Profile.ProfileID))
+ {
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[server.Profile.ProfileID], server.Profile.ProfileName));
+ }
+
+ key = server.Profile.ProfileID;
+ _currentProfileCommands.Add(key, CommandType.Start);
+
switch (server.Runtime.Status)
{
case ServerStatus.Initializing:
@@ -594,10 +664,10 @@ namespace ServerManagerTool.Utils
case ServerStatus.Running:
case ServerStatus.Uninstalled:
case ServerStatus.Unknown:
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), profileId, server.Runtime.StatusString));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
case ServerStatus.Updating:
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), server.Profile.ProfileName));
}
profile = ServerProfileSnapshot.Create(server.Profile);
@@ -617,7 +687,8 @@ namespace ServerManagerTool.Utils
{
TaskUtils.RunOnUIThreadAsync(() =>
{
- var server = ServerManager.Instance.Servers.FirstOrDefault(s => Equals(channelId, s.Profile.DiscordChannelId) && Equals(profileId, s.Profile.ProfileID));
+ var server = ServerManager.Instance.Servers.First(s => Equals(channelId, s.Profile.DiscordChannelId)
+ && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias)));
server.Runtime.UpdateServerStatus(serverStatus, true);
}).Wait();
}
@@ -626,7 +697,7 @@ namespace ServerManagerTool.Utils
task = Task.Run(() =>
{
app.PerformProfileShutdown(profile, true, false, false, false, token);
- _currentProfileCommands.Remove(profileId);
+ _currentProfileCommands.Remove(key);
});
response.Add(string.Format(_globalizer.GetResourceString("DiscordBot_StartRequested"), profile.ServerName));
@@ -637,24 +708,19 @@ namespace ServerManagerTool.Utils
{
if (task is null)
{
- _currentProfileCommands.Remove(profileId);
+ _currentProfileCommands.Remove(key);
}
}
}
- private static IList UpdateServer(string channelId, string profileId, CancellationToken token)
+ private static IList UpdateServer(string channelId, string profileIdOrAlias, CancellationToken token)
{
- if (string.IsNullOrWhiteSpace(profileId))
+ if (string.IsNullOrWhiteSpace(profileIdOrAlias))
{
return new List { string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMissing"), CommandType.Update) };
}
- // check if another command is being run against the profile
- if (_currentProfileCommands.ContainsKey(profileId))
- {
- return new List { string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[profileId], profileId) };
- }
- _currentProfileCommands.Add(profileId, CommandType.Update);
+ var key = string.Empty;
ServerProfileSnapshot profile = null;
bool performRestart = false;
@@ -664,31 +730,47 @@ namespace ServerManagerTool.Utils
{
TaskUtils.RunOnUIThreadAsync(() =>
{
- var server = ServerManager.Instance.Servers.FirstOrDefault(s => Equals(channelId, s.Profile.DiscordChannelId) && Equals(profileId, s.Profile.ProfileID));
+ var serverList = ServerManager.Instance.Servers.Where(s => Equals(channelId, s.Profile.DiscordChannelId)
+ && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias)));
- if (server is null)
+ if (!serverList.Any())
{
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileNotFound"), profileIdOrAlias));
}
+ if (serverList.Count() > 1)
+ {
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileMultiples"), profileIdOrAlias));
+ }
+
+ var server = serverList.First();
if (!server.Profile.AllowDiscordUpdate)
{
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Update, profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandDisabledProfile"), CommandType.Update, server.Profile.ProfileName));
}
+ // check if another command is being run against the profile
+ if (_currentProfileCommands.ContainsKey(server.Profile.ProfileID))
+ {
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[server.Profile.ProfileID], server.Profile.ProfileName));
+ }
+
+ key = server.Profile.ProfileID;
+ _currentProfileCommands.Add(key, CommandType.Update);
+
switch (server.Runtime.Status)
{
case ServerStatus.Initializing:
case ServerStatus.Stopping:
case ServerStatus.Unknown:
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), profileId, server.Runtime.StatusString));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
case ServerStatus.Running:
performRestart = true;
break;
case ServerStatus.Updating:
- throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), profileId));
+ throw new Exception(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), server.Profile.ProfileName));
}
profile = ServerProfileSnapshot.Create(server.Profile);
@@ -707,7 +789,8 @@ namespace ServerManagerTool.Utils
{
TaskUtils.RunOnUIThreadAsync(() =>
{
- var server = ServerManager.Instance.Servers.FirstOrDefault(s => Equals(channelId, s.Profile.DiscordChannelId) && Equals(profileId, s.Profile.ProfileID));
+ var server = ServerManager.Instance.Servers.First(s => Equals(channelId, s.Profile.DiscordChannelId)
+ && (Equals(profileIdOrAlias, s.Profile.ProfileID) || !string.IsNullOrWhiteSpace(s.Profile.DiscordAlias) && Equals(profileIdOrAlias, s.Profile.DiscordAlias)));
server.Runtime.UpdateServerStatus(serverStatus, true);
}).Wait();
}
@@ -716,7 +799,7 @@ namespace ServerManagerTool.Utils
task = Task.Run(() =>
{
app.PerformProfileShutdown(profile, performRestart, true, false, false, token);
- _currentProfileCommands.Remove(profileId);
+ _currentProfileCommands.Remove(key);
});
response.Add(string.Format(_globalizer.GetResourceString("DiscordBot_UpdateRequested"), profile.ServerName));
@@ -727,7 +810,7 @@ namespace ServerManagerTool.Utils
{
if (task is null)
{
- _currentProfileCommands.Remove(profileId);
+ _currentProfileCommands.Remove(key);
}
}
}
diff --git a/src/ConanServerManager/VersionFeed.xml b/src/ConanServerManager/VersionFeed.xml
index d84ed2ad..af4d270c 100644
--- a/src/ConanServerManager/VersionFeed.xml
+++ b/src/ConanServerManager/VersionFeed.xml
@@ -9,8 +9,8 @@
urn:uuid:19B09A66-43F2-4D5F-AF33-5C77D7EA9A6B
- 1.1.58 (1.1.58.2)
- 1.1.58.2
+ 1.1.58 (1.1.58.3)
+ 1.1.58.3
2021-12-16T00:00:00Z
@@ -20,6 +20,7 @@
- Global Settings - Discord Bot section - Added a whitelist to allow bots to send commands to the server manager.
+ - Server Settings - Discord Bot section - Added an alias that can be used with the discord command instead of the profile id.
CHANGE
diff --git a/src/ConanServerManager/VersionFeedBeta.xml b/src/ConanServerManager/VersionFeedBeta.xml
index 1cd4d40f..a5a6a1db 100644
--- a/src/ConanServerManager/VersionFeedBeta.xml
+++ b/src/ConanServerManager/VersionFeedBeta.xml
@@ -7,6 +7,29 @@
2021-12-16T00:00:00Z
+
+ urn:uuid:F3C22842-A089-46F7-AB1A-5D3DED105412
+ 1.1.58 (1.1.58.3)
+ 1.1.58.3
+
+ 2021-12-16T00:00:00Z
+
+
+
+ NEW
+
+
+ - Server Settings - Discord Bot section - Added an alias that can be used with the discord command instead of the profile id.
+
+
+
+
+
+ bletch
+ bletch1971@hotmail.com
+
+
+
urn:uuid:C566D9D2-3566-46DF-8AD4-39F5FC0FFEF2
1.1.58 (1.1.58.2)
diff --git a/src/ServerManager.Discord/Delegates/HandleCommandDelegate.cs b/src/ServerManager.Discord/Delegates/HandleCommandDelegate.cs
index e4301ce4..ef626b53 100644
--- a/src/ServerManager.Discord/Delegates/HandleCommandDelegate.cs
+++ b/src/ServerManager.Discord/Delegates/HandleCommandDelegate.cs
@@ -4,5 +4,5 @@ using System.Threading;
namespace ServerManagerTool.DiscordBot.Delegates
{
- public delegate IList HandleCommandDelegate(CommandType commandType, string serverId, string channelId, string profileId, CancellationToken token);
+ public delegate IList HandleCommandDelegate(CommandType commandType, string serverId, string channelId, string profileIdOrAlias, CancellationToken token);
}
diff --git a/src/ServerManager.Discord/Modules/ServerCommandModule.cs b/src/ServerManager.Discord/Modules/ServerCommandModule.cs
index ea993166..b2bd5461 100644
--- a/src/ServerManager.Discord/Modules/ServerCommandModule.cs
+++ b/src/ServerManager.Discord/Modules/ServerCommandModule.cs
@@ -29,16 +29,16 @@ namespace ServerManagerTool.DiscordBot.Modules
[Command("backup", RunMode = RunMode.Async)]
[Summary("Backup the server")]
- [Remarks("backup profileId")]
+ [Remarks("backup profileId|alias")]
[RequireBotPermission(ChannelPermission.ViewChannel | ChannelPermission.SendMessages)]
- public async Task BackupServerAsync(string profileId)
+ public async Task BackupServerAsync(string profileIdOrAlias)
{
try
{
var serverId = Context?.Guild?.Id.ToString() ?? string.Empty;
var channelId = Context?.Channel?.Id.ToString() ?? string.Empty;
- var response = _handleCommandCallback?.Invoke(CommandType.Backup, serverId, channelId, profileId, _serverManagerBot.Token);
+ var response = _handleCommandCallback?.Invoke(CommandType.Backup, serverId, channelId, profileIdOrAlias, _serverManagerBot.Token);
if (response is null)
{
await ReplyAsync("No servers associated with this channel.");
@@ -60,16 +60,16 @@ namespace ServerManagerTool.DiscordBot.Modules
[Command("restart", RunMode = RunMode.Async)]
[Summary("Restart the server")]
- [Remarks("restart profileId")]
+ [Remarks("restart profileId|alias")]
[RequireBotPermission(ChannelPermission.ViewChannel | ChannelPermission.SendMessages)]
- public async Task RestartServerAsync(string profileId)
+ public async Task RestartServerAsync(string profileIdOrAlias)
{
try
{
var serverId = Context?.Guild?.Id.ToString() ?? string.Empty;
var channelId = Context?.Channel?.Id.ToString() ?? string.Empty;
- var response = _handleCommandCallback?.Invoke(CommandType.Restart, serverId, channelId, profileId, _serverManagerBot.Token);
+ var response = _handleCommandCallback?.Invoke(CommandType.Restart, serverId, channelId, profileIdOrAlias, _serverManagerBot.Token);
if (response is null)
{
await ReplyAsync("No servers associated with this channel.");
@@ -91,16 +91,16 @@ namespace ServerManagerTool.DiscordBot.Modules
[Command("shutdown", RunMode = RunMode.Async)]
[Summary("Shuts down the server properly")]
- [Remarks("shutdown profileId")]
+ [Remarks("shutdown profileId|alias")]
[RequireBotPermission(ChannelPermission.ViewChannel | ChannelPermission.SendMessages)]
- public async Task ShutdownServerAsync(string profileId)
+ public async Task ShutdownServerAsync(string profileIdOrAlias)
{
try
{
var serverId = Context?.Guild?.Id.ToString() ?? string.Empty;
var channelId = Context?.Channel?.Id.ToString() ?? string.Empty;
- var response = _handleCommandCallback?.Invoke(CommandType.Shutdown, serverId, channelId, profileId, _serverManagerBot.Token);
+ var response = _handleCommandCallback?.Invoke(CommandType.Shutdown, serverId, channelId, profileIdOrAlias, _serverManagerBot.Token);
if (response is null)
{
await ReplyAsync("No servers associated with this channel.");
@@ -122,16 +122,16 @@ namespace ServerManagerTool.DiscordBot.Modules
[Command("start", RunMode = RunMode.Async)]
[Summary("Starts the server")]
- [Remarks("start profileId")]
+ [Remarks("start profileId|alias")]
[RequireBotPermission(ChannelPermission.ViewChannel | ChannelPermission.SendMessages)]
- public async Task StartServerAsync(string profileId)
+ public async Task StartServerAsync(string profileIdOrAlias)
{
try
{
var serverId = Context?.Guild?.Id.ToString() ?? string.Empty;
var channelId = Context?.Channel?.Id.ToString() ?? string.Empty;
- var response = _handleCommandCallback?.Invoke(CommandType.Start, serverId, channelId, profileId, _serverManagerBot.Token);
+ var response = _handleCommandCallback?.Invoke(CommandType.Start, serverId, channelId, profileIdOrAlias, _serverManagerBot.Token);
if (response is null)
{
await ReplyAsync("No servers associated with this channel.");
@@ -153,16 +153,16 @@ namespace ServerManagerTool.DiscordBot.Modules
[Command("stop", RunMode = RunMode.Async)]
[Summary("Forcibly stops the server")]
- [Remarks("stop profileId")]
+ [Remarks("stop profileId|alias")]
[RequireBotPermission(ChannelPermission.ViewChannel | ChannelPermission.SendMessages)]
- public async Task StopServerAsync(string profileId)
+ public async Task StopServerAsync(string profileIdOrAlias)
{
try
{
var serverId = Context?.Guild?.Id.ToString() ?? string.Empty;
var channelId = Context?.Channel?.Id.ToString() ?? string.Empty;
- var response = _handleCommandCallback?.Invoke(CommandType.Stop, serverId, channelId, profileId, _serverManagerBot.Token);
+ var response = _handleCommandCallback?.Invoke(CommandType.Stop, serverId, channelId, profileIdOrAlias, _serverManagerBot.Token);
if (response is null)
{
await ReplyAsync("No servers associated with this channel.");
@@ -184,16 +184,16 @@ namespace ServerManagerTool.DiscordBot.Modules
[Command("update", RunMode = RunMode.Async)]
[Summary("Updates the server")]
- [Remarks("update profileId")]
+ [Remarks("update profileId|alias")]
[RequireBotPermission(ChannelPermission.ViewChannel | ChannelPermission.SendMessages)]
- public async Task UpdateServerAsync(string profileId)
+ public async Task UpdateServerAsync(string profileIdOrAlias)
{
try
{
var serverId = Context?.Guild?.Id.ToString() ?? string.Empty;
var channelId = Context?.Channel?.Id.ToString() ?? string.Empty;
- var response = _handleCommandCallback?.Invoke(CommandType.Update, serverId, channelId, profileId, _serverManagerBot.Token);
+ var response = _handleCommandCallback?.Invoke(CommandType.Update, serverId, channelId, profileIdOrAlias, _serverManagerBot.Token);
if (response is null)
{
await ReplyAsync("No servers associated with this channel.");
diff --git a/src/ServerManager.Discord/Modules/ServerQueryModule.cs b/src/ServerManager.Discord/Modules/ServerQueryModule.cs
index a793c3b7..407486c3 100644
--- a/src/ServerManager.Discord/Modules/ServerQueryModule.cs
+++ b/src/ServerManager.Discord/Modules/ServerQueryModule.cs
@@ -38,16 +38,16 @@ namespace ServerManagerTool.DiscordBot.Modules
[Command("info", RunMode = RunMode.Async)]
[Summary("Poll server for information")]
- [Remarks("info profileId")]
+ [Remarks("info profileId|alias")]
[RequireBotPermission(ChannelPermission.ViewChannel | ChannelPermission.SendMessages)]
- public async Task ServerInfoAsync(string profileId)
+ public async Task ServerInfoAsync(string profileIdOrAlias)
{
try
{
var serverId = Context?.Guild?.Id.ToString() ?? string.Empty;
var channelId = Context?.Channel?.Id.ToString() ?? string.Empty;
- var response = _handleCommandCallback?.Invoke(CommandType.Info, serverId, channelId, profileId, _serverManagerBot.Token);
+ var response = _handleCommandCallback?.Invoke(CommandType.Info, serverId, channelId, profileIdOrAlias, _serverManagerBot.Token);
if (response is null)
{
await ReplyAsync("No servers associated with this channel.");
@@ -109,16 +109,16 @@ namespace ServerManagerTool.DiscordBot.Modules
[Command("status", RunMode = RunMode.Async)]
[Summary("Poll server for status")]
- [Remarks("status profileId")]
+ [Remarks("status profileId|alias")]
[RequireBotPermission(ChannelPermission.ViewChannel | ChannelPermission.SendMessages)]
- public async Task ServerStatusAsync(string profileId)
+ public async Task ServerStatusAsync(string profileIdOrAlias)
{
try
{
var serverId = Context?.Guild?.Id.ToString() ?? string.Empty;
var channelId = Context?.Channel?.Id.ToString() ?? string.Empty;
- var response = _handleCommandCallback?.Invoke(CommandType.Status, serverId, channelId, profileId, _serverManagerBot.Token);
+ var response = _handleCommandCallback?.Invoke(CommandType.Status, serverId, channelId, profileIdOrAlias, _serverManagerBot.Token);
if (response is null)
{
await ReplyAsync("No servers associated with this channel.");