diff --git a/src/DiIiS-NA/BGS-Server/AccountsSystem/Account.cs b/src/DiIiS-NA/BGS-Server/AccountsSystem/Account.cs index a86e689..9c299ed 100644 --- a/src/DiIiS-NA/BGS-Server/AccountsSystem/Account.cs +++ b/src/DiIiS-NA/BGS-Server/AccountsSystem/Account.cs @@ -464,5 +464,29 @@ namespace DiIiS_NA.LoginServer.AccountsSystem Admin, Owner } + + public static class UserLevelsExtensions + { + public static UserLevels? FromString(string str) + { + if (string.IsNullOrWhiteSpace(str)) + return null; + switch (str.ToLower()) + { + case "user": + return UserLevels.User; + case "tester": + return UserLevels.Tester; + case "gm": + return UserLevels.GM; + case "admin": + return UserLevels.Admin; + case "owner": + return UserLevels.Owner; + default: + return null; + } + } + } } } diff --git a/src/DiIiS-NA/Blizzless.csproj b/src/DiIiS-NA/Blizzless.csproj index e0dd412..fc13cc4 100644 --- a/src/DiIiS-NA/Blizzless.csproj +++ b/src/DiIiS-NA/Blizzless.csproj @@ -124,6 +124,9 @@ GameAttribute.cs + + CommandException.cs + diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/CommandGroup.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/CommandGroup.cs index 28c3367..ea1c8ec 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/CommandGroup.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/CommandGroup.cs @@ -66,12 +66,12 @@ namespace DiIiS_NA.GameServer.CommandManager #if DEBUG return $"You don't have enough privileges to invoke that command (Min. level: {Attributes.MinUserLevel})."; #else - return "You don't have enough privileges to invoke that command."; + return "Unknown command."; #endif - if (invokerClient?.InGameClient == null && Attributes.InGameOnly) + if (invokerClient?.InGameClient?.Player == null && Attributes.InGameOnly) return "You can only use this command in-game."; string[] @params = null; - CommandAttribute target = null; + CommandAttribute target; if (parameters == string.Empty) target = GetDefaultSubcommand(); @@ -89,9 +89,9 @@ namespace DiIiS_NA.GameServer.CommandManager #if DEBUG return $"You don't have enough privileges to invoke that command (Min. level: {Attributes.MinUserLevel})."; #else - return "You don't have enough privileges to invoke that command."; + return "Unknown command."; #endif - if (invokerClient?.InGameClient == null && target.InGameOnly) + if (invokerClient?.InGameClient?.Player == null && target.InGameOnly) return "This command can only be invoked in-game."; try @@ -124,7 +124,7 @@ namespace DiIiS_NA.GameServer.CommandManager { var output = _commands .Where(pair => pair.Key.Name.Trim() != string.Empty) - .Where(pair => invokerClient == null || pair.Key.MinUserLevel <= invokerClient.Account.UserLevel) + .Where(pair => (invokerClient == null && pair.Key.InGameOnly) || (invokerClient != null && pair.Key.MinUserLevel <= invokerClient.Account.UserLevel)) .Aggregate("Available subcommands: ", (current, pair) => current + (pair.Key.Name + ", ")); return output.Substring(0, output.Length - 2) + "."; diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/CommandManager.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/CommandManager.cs index dc61af7..4f04e2f 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/CommandManager.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/CommandManager.cs @@ -28,13 +28,18 @@ namespace DiIiS_NA.GameServer.CommandManager if (attributes.Length == 0) continue; var groupAttribute = attributes[0]; if (groupAttribute.Name == null) continue; + if (groupAttribute.Name.Contains(" ")) + { + Logger.Warn($"Command group name '{groupAttribute.Name}' contains spaces (which is $[red]$not$[/]$ allowed). Command group will be ignored."); + } + if (CommandsConfig.Instance.DisabledGroupsData.Contains(groupAttribute.Name)) { - Logger.Trace($"Command group {groupAttribute.Name} is disabled."); + Logger.Warn($"Command group name '{groupAttribute.Name}' is disabled."); continue; } if (CommandGroups.ContainsKey(groupAttribute)) - Logger.Warn("There exists an already registered command group named '{0}'.", groupAttribute.Name); + Logger.Warn($"There exists an already registered command group named '{groupAttribute.Name}'."); var commandGroup = (CommandGroup)Activator.CreateInstance(type); if (commandGroup != null) @@ -44,7 +49,7 @@ namespace DiIiS_NA.GameServer.CommandManager } else { - Logger.Warn("Failed to create an instance of command group '{0}'.", groupAttribute.Name); + Logger.Warn($"Failed to create an instance of command group '{groupAttribute.Name}'."); } } } @@ -63,8 +68,8 @@ namespace DiIiS_NA.GameServer.CommandManager if (!ExtractCommandAndParameters(line, out var command, out var parameters)) { - output = "Unknown command: " + line; - Logger.Error(output); + output = "Unknown command."; + Logger.Warn(output); return; } @@ -77,11 +82,11 @@ namespace DiIiS_NA.GameServer.CommandManager if (found == false) { - Logger.Error("Unknown command: " + command.SafeAnsi()); + Logger.Warn("Unknown command."); return; } - Logger.Success(output != string.Empty ? output : "Command executed successfully."); + Logger.Success(output != string.Empty ? "\n-----------------------------------------------------\n" + output + "\n-----------------------------------------------------\n" : "Command executed successfully."); } @@ -110,8 +115,12 @@ namespace DiIiS_NA.GameServer.CommandManager } if (found == false) +#if DEBUG output = $"Unknown command: {command} {parameters}"; - +#else + output = $"Unknown command."; +#endif + if (output == string.Empty) return true; @@ -151,23 +160,23 @@ namespace DiIiS_NA.GameServer.CommandManager { public override string Fallback(string[] parameters = null, BattleClient invokerClient = null) { - var output = "Available commands: "; + var output = "Available commands:\n"; output = invokerClient != null ? CommandGroups.Where(pair => pair.Key.MinUserLevel > invokerClient?.Account.UserLevel) .Aggregate(output, (current, pair) => current + ($"{CommandsConfig.Instance.CommandPrefix}{pair.Key.Name}: {pair.Key.Help}\n\n")) : CommandGroups .Where(s=>!s.Key.InGameOnly) - .Aggregate(output, (current, pair) => current + (($"$[underline green]${CommandsConfig.Instance.CommandPrefix}{pair.Key.Name}$[/]$: {pair.Key.Help}\n\n"))); + .Aggregate(output, (current, pair) => current + (($"$[underline green]${CommandsConfig.Instance.CommandPrefix}{pair.Key.Name}$[/]$: $[white]${pair.Key.Help}$[/]$\n"))); - return output + "Type 'help ' to get help about a specific command."; + return output + $"Type '{CommandsConfig.Instance.CommandPrefix}help ' to get help about a specific command."; } } [CommandGroup("help", "usage: help \nType 'commands' to get a list of available commands.")] public class HelpCommandGroup : CommandGroup { - public override string Fallback(string[] parameters = null, BattleClient invokerClient = null) => "usage: help \nType 'commands' to get a list of available commands."; + public override string Fallback(string[] parameters = null, BattleClient invokerClient = null) => $"usage: {CommandsConfig.Instance.CommandPrefix}help \nType 'commands' to get a list of available commands."; public override string Handle(string parameters, BattleClient invokerClient = null) { @@ -180,7 +189,7 @@ namespace DiIiS_NA.GameServer.CommandManager var group = @params[0]; var command = @params.Length > 1 ? @params[1] : string.Empty; - foreach (var pair in CommandGroups.Where(pair => group == pair.Key.Name)) + foreach (var pair in CommandGroups.Where(pair => group == pair.Key.Name && ((invokerClient == null && !pair.Key.InGameOnly) || (invokerClient != null && pair.Key.MinUserLevel <= invokerClient.Account.UserLevel)))) { if (command == string.Empty) return pair.Key.Help; diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/AccountCommands.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/AccountCommands.cs index 2b8a346..1b52b8c 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/AccountCommands.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/AccountCommands.cs @@ -38,27 +38,10 @@ public class AccountCommands : CommandGroup if (@params.Length == 4) { - var level = @params[3].ToLower(); - switch (level) - { - case "owner": - userLevel = Account.UserLevels.Owner; - break; - case "admin": - userLevel = Account.UserLevels.Admin; - break; - case "gm": - userLevel = Account.UserLevels.GM; - break; - case "tester": - userLevel = Account.UserLevels.Tester; - break; - case "user": - userLevel = Account.UserLevels.User; - break; - default: - return level + " is not a valid user level."; - } + var level = Account.UserLevelsExtensions.FromString(@params[3]); + if (level == null) + return "Invalid user level."; + userLevel = level.Value; } if (!email.Contains('@')) @@ -131,34 +114,16 @@ public class AccountCommands : CommandGroup return "Invalid arguments. Type 'help account setuserlevel' to get help."; var email = @params[0]; - var level = @params[1].ToLower(); - Account.UserLevels userLevel; var account = AccountManager.GetAccountByEmail(email); if (account == null) return $"No account with email '{email}' exists."; - switch (level) - { - case "owner": - userLevel = Account.UserLevels.Owner; - break; - case "admin": - userLevel = Account.UserLevels.Admin; - break; - case "gm": - userLevel = Account.UserLevels.GM; - break; - case "tester": - userLevel = Account.UserLevels.Tester; - break; - case "user": - userLevel = Account.UserLevels.User; - break; - default: - return level + " is not a valid user level."; - } + var level = Account.UserLevelsExtensions.FromString(@params[1]); + if (level == null) + return "Invalid user level."; + Account.UserLevels userLevel = level.Value; account.UpdateUserLevel(userLevel); return $"Updated user level for account {email} [user-level: {userLevel}]."; diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/ActorsCommand.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/ActorsCommand.cs index b438afa..ffd7d83 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/ActorsCommand.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/ActorsCommand.cs @@ -8,15 +8,13 @@ namespace DiIiS_NA.GameServer.CommandManager; [CommandGroup("actors", "Actors info (does not include Players, Minions and Monsters). This is useful for testing purposes.", - Account.UserLevels.Tester)] + Account.UserLevels.Tester, inGameOnly: true)] public class ActorsCommand : CommandGroup { - [Command("all", "Lists all actors in world sorted by distance to you.", Account.UserLevels.Tester)] + [Command("all", "Lists all actors in world sorted by distance to you.", Account.UserLevels.Tester, inGameOnly: true)] public string All(string[] @params, BattleClient invokerClient) { - if (invokerClient?.InGameClient?.Player is not {} player) - return "You are not in game."; - + var player = invokerClient.InGameClient.Player; return $"World [{player.World.SNO}]\nAll actors:" + string.Join("\n", player.World.Actors .OrderBy(a => { @@ -32,12 +30,10 @@ public class ActorsCommand : CommandGroup })); } - [Command("revealed", "Lists all revealed actors sorted by distance to you.", Account.UserLevels.Tester)] + [Command("revealed", "Lists all revealed actors sorted by distance to you.", Account.UserLevels.Tester, inGameOnly: true)] public string Revealed(string[] @params, BattleClient invokerClient) { - if (invokerClient?.InGameClient?.Player is not {} player) - return "You are not in game."; - + var player = invokerClient.InGameClient.Player; return $"World [{player.World.SNO}]\nVisible actors:" + string.Join("\n", player.World.Actors .Where(a => a.Value.IsRevealedToPlayer(player)) .OrderBy(a => @@ -54,12 +50,10 @@ public class ActorsCommand : CommandGroup })); } - [Command("all-usable", "Sets all actors operable in world sorted by distance to you.e (not the wisest invention).", Account.UserLevels.Tester)] + [Command("all-usable", "Sets all actors operable in world sorted by distance to you.e (not the wisest invention).", Account.UserLevels.Tester, inGameOnly: true)] public string Usable(string[] @params, BattleClient invokerClient) { - if (invokerClient?.InGameClient?.Player is not {} player) - return "You are not in game."; - + var player = invokerClient.InGameClient.Player; if (@params is { Length: > 0 }) { if (!Enum.TryParse(@params[0].AsSpan(), out var actorSno)) diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/ConversationCommand.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/ConversationCommand.cs index 4e3d2e9..a140a9a 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/ConversationCommand.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/ConversationCommand.cs @@ -5,18 +5,12 @@ using DiIiS_NA.LoginServer.Battle; namespace DiIiS_NA.GameServer.CommandManager; -[CommandGroup("conversation", "Starts a conversation. \n Usage: conversation snoConversation")] +[CommandGroup("conversation", "Starts a conversation. \n Usage: conversation snoConversation", inGameOnly: true)] public class ConversationCommand : CommandGroup { - [DefaultCommand] + [DefaultCommand(inGameOnly: true)] public string Conversation(string[] @params, BattleClient invokerClient) { - if (invokerClient == null) - return "You cannot invoke this command from console."; - - if (invokerClient.InGameClient == null) - return "You can only invoke this command while in-game."; - if (@params.Length != 1) return "Invalid arguments. Type 'help conversation' to get help."; diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/DifficultyCommand.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/DifficultyCommand.cs index a25b46c..1aca111 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/DifficultyCommand.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/DifficultyCommand.cs @@ -3,10 +3,10 @@ using DiIiS_NA.LoginServer.Battle; namespace DiIiS_NA.GameServer.CommandManager; -[CommandGroup("difficulty", "Changes difficulty of the game", Account.UserLevels.GM)] +[CommandGroup("difficulty", "Changes difficulty of the game", Account.UserLevels.GM, inGameOnly: true)] public class DifficultyCommand : CommandGroup { - [Command("max", "Sets difficulty to max", Account.UserLevels.GM)] + [Command("max", "Sets difficulty to max", Account.UserLevels.GM, inGameOnly: true)] public string Max(string[] @params, BattleClient invokerClient) { if (invokerClient?.InGameClient is null) @@ -17,7 +17,7 @@ public class DifficultyCommand : CommandGroup return $"Difficulty set to max - {invokerClient.InGameClient.Player.World.Game.Difficulty}"; } - [Command("min", "Sets difficulty to min", Account.UserLevels.GM)] + [Command("min", "Sets difficulty to min", Account.UserLevels.GM, inGameOnly: true)] public string Min(string[] @params, BattleClient invokerClient) { if (invokerClient?.InGameClient is null) @@ -28,7 +28,7 @@ public class DifficultyCommand : CommandGroup return $"Difficulty set to min - {invokerClient.InGameClient.Player.World.Game.Difficulty}"; } - [Command("up", "Increases difficulty of the game", Account.UserLevels.GM)] + [Command("up", "Increases difficulty of the game", Account.UserLevels.GM, inGameOnly: true)] public string Up(string[] @params, BattleClient invokerClient) { if (invokerClient?.InGameClient is null) @@ -39,7 +39,7 @@ public class DifficultyCommand : CommandGroup return $"Difficulty increased - set to {invokerClient.InGameClient.Player.World.Game.Difficulty}"; } - [Command("down", "Decreases difficulty of the game", Account.UserLevels.GM)] + [Command("down", "Decreases difficulty of the game", Account.UserLevels.GM, inGameOnly: true)] public string Down(string[] @params, BattleClient invokerClient) { if (invokerClient?.InGameClient is null) @@ -50,7 +50,7 @@ public class DifficultyCommand : CommandGroup return $"Difficulty decreased - set to {invokerClient.InGameClient.Player.World.Game.Difficulty}"; } - [Command("set", "Sets difficulty of the game", Account.UserLevels.GM)] + [Command("set", "Sets difficulty of the game", Account.UserLevels.GM, inGameOnly: true)] public string Set(string[] @params, BattleClient invokerClient) { if (invokerClient?.InGameClient is null) @@ -61,7 +61,7 @@ public class DifficultyCommand : CommandGroup return $"Difficulty set to {invokerClient.InGameClient.Player.World.Game.Difficulty}"; } - [DefaultCommand] + [DefaultCommand(inGameOnly: true)] public string Default(string[] @params, BattleClient invokerClient) { if (invokerClient?.InGameClient is null) diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/DoorsCommand.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/DoorsCommand.cs index e6bbce9..e4bcbe1 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/DoorsCommand.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/DoorsCommand.cs @@ -5,10 +5,10 @@ using DiIiS_NA.LoginServer.AccountsSystem; namespace DiIiS_NA.GameServer.CommandManager; -[CommandGroup("doors", "Information about all doors in the vicinity. This is useful for testing purposes.", Account.UserLevels.Tester)] +[CommandGroup("doors", "Information about all doors in the vicinity. This is useful for testing purposes.", Account.UserLevels.Tester, inGameOnly: true)] public class DoorsCommand : CommandGroup { - [Command("all", "Activate all doors. This is useful for testing purposes.\nUsage: !open all", Account.UserLevels.Tester)] + [Command("all", "Activate all doors. This is useful for testing purposes.\nUsage: !open all", Account.UserLevels.Tester, inGameOnly: true)] public string OpenAllDoors(string[] @params, BattleClient invokerClient) { if (invokerClient?.InGameClient?.Player is not { } player) @@ -20,7 +20,7 @@ public class DoorsCommand : CommandGroup return $"Opened {openedDoors.Length} doors: {string.Join(", ", openedDoors.Select(d => (int)d.SNO + " - " + d.SNO))}"; } - [Command("near", "Activate all nearby doors in the vicinity. This is useful for testing purposes.\nUsage: !open near [distance:50]", Account.UserLevels.Tester)] + [Command("near", "Activate all nearby doors in the vicinity. This is useful for testing purposes.\nUsage: !open near [distance:50]", Account.UserLevels.Tester, inGameOnly: true)] public string OpenAllDoorsNear(string[] @params, BattleClient invokerClient) { if (invokerClient?.InGameClient?.Player is not { } player) @@ -41,7 +41,7 @@ public class DoorsCommand : CommandGroup return $"Opened {openedDoors.Count()} in a distance of {distance:0.0000} doors: {string.Join(", ", openedDoors)}"; } - [Command("info", "Retrieve all world doors in proximity, sorted in descending order.\nUsage: !open info [distance:50]", Account.UserLevels.Tester)] + [Command("info", "Retrieve all world doors in proximity, sorted in descending order.\nUsage: !open info [distance:50]", Account.UserLevels.Tester, inGameOnly: true)] public string InfoDoorsNear(string[] @params, BattleClient invokerClient) { if (invokerClient?.InGameClient?.Player is not { } player) @@ -65,7 +65,7 @@ public class DoorsCommand : CommandGroup }))}"; } - [DefaultCommand()] + [DefaultCommand(inGameOnly: true)] public string DefaultCommand(string[] @params, BattleClient invokerClient) { return "!doors all - Activate all doors. This is useful for testing purposes.\n" + diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/DropCommand.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/DropCommand.cs index 832c046..c29d37c 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/DropCommand.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/DropCommand.cs @@ -4,10 +4,10 @@ using DiIiS_NA.LoginServer.Battle; namespace DiIiS_NA.GameServer.CommandManager; -[CommandGroup("drop", "Drops an epic item for your class.\nOptionally specify the number of items: !drop [1-20]", Account.UserLevels.Owner)] +[CommandGroup("drop", "Drops an epic item for your class.\nOptionally specify the number of items: !drop [1-20]", Account.UserLevels.Owner, inGameOnly: true)] public class DropCommand : CommandGroup { - [DefaultCommand] + [DefaultCommand(inGameOnly: true)] public string Drop(string[] @params, BattleClient invokerClient) { if (invokerClient?.InGameClient?.Player is not { } player) diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/FollowersCommand.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/FollowersCommand.cs index 3f60eee..d75a63b 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/FollowersCommand.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/FollowersCommand.cs @@ -5,10 +5,10 @@ using DiIiS_NA.LoginServer.Battle; namespace DiIiS_NA.GameServer.CommandManager; -[CommandGroup("followers", "Manage your followers.", Account.UserLevels.Tester)] +[CommandGroup("followers", "Manage your followers.", Account.UserLevels.Tester, inGameOnly: true)] public class FollowersCommand : CommandGroup { - [Command("list", "List all followers.")] + [Command("list", "List all followers.", inGameOnly: true)] public string List(string[] @params, BattleClient invokerClient) { if (invokerClient?.InGameClient?.Player is not { } player) @@ -21,7 +21,7 @@ public class FollowersCommand : CommandGroup return string.Join('\n', followers); } - [Command("dismiss", "Dismisses all followers.")] + [Command("dismiss", "Dismisses all followers.", inGameOnly: true)] public string DismissAllCommand(string[] @params, BattleClient invokerClient) { if (invokerClient?.InGameClient?.Player is not { } player) diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/GoldCommand.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/GoldCommand.cs index 9267464..aa23e47 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/GoldCommand.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/GoldCommand.cs @@ -4,18 +4,12 @@ using DiIiS_NA.LoginServer.Battle; namespace DiIiS_NA.GameServer.CommandManager; [CommandGroup("gold", "Gold for your character.\nOptionally specify the number of gold: !gold [count]", - Account.UserLevels.GM)] + Account.UserLevels.GM, inGameOnly: true)] public class GoldCommand : CommandGroup { - [DefaultCommand] + [DefaultCommand(inGameOnly: true)] public string Gold(string[] @params, BattleClient invokerClient) { - if (invokerClient == null) - return "You cannot invoke this command from console."; - - if (invokerClient.InGameClient == null) - return "You can only invoke this command while in-game."; - var player = invokerClient.InGameClient.Player; var amount = 1; diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/HealCommand.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/HealCommand.cs index 8c4e199..2f23542 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/HealCommand.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/HealCommand.cs @@ -3,16 +3,13 @@ using DiIiS_NA.LoginServer.Battle; namespace DiIiS_NA.GameServer.CommandManager; -[CommandGroup("heal", "Heals yourself", Account.UserLevels.Tester)] +[CommandGroup("heal", "Heals yourself", Account.UserLevels.Tester, inGameOnly: true)] public class HealCommand : CommandGroup { - [DefaultCommand] + [DefaultCommand(inGameOnly: true)] public string Heal(string[] @params, BattleClient invokerClient) { - if (invokerClient?.InGameClient?.Player is not { } player) - return "You are not in game"; - - player.Heal(); + invokerClient.InGameClient.Player.Heal(); return "You have been healed"; } } \ No newline at end of file diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/IdentifyCommand.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/IdentifyCommand.cs index 6c1ac6f..1b2163d 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/IdentifyCommand.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/IdentifyCommand.cs @@ -5,15 +5,13 @@ using DiIiS_NA.LoginServer.Battle; namespace DiIiS_NA.GameServer.CommandManager; -[CommandGroup("identify", "Identifies all items in your inventory.", Account.UserLevels.Tester)] +[CommandGroup("identify", "Identifies all items in your inventory.", Account.UserLevels.Tester, inGameOnly: true)] public class IdentifyCommand { - [DefaultCommand()] + [DefaultCommand(inGameOnly: true)] public string Identify(string[] @params, BattleClient invokerClient) { - if (invokerClient?.InGameClient?.Player is not { } player) - return "You must be in game to use this command."; - + var player = invokerClient.InGameClient.Player; var unidentified = player.Inventory.GetBackPackItems().Where(i => i.Unidentified).ToArray(); var count = unidentified.Length; player.StartCasting(60 * 2, new Action(() => diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/InfoCommand.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/InfoCommand.cs index ec6baad..a4ee0d4 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/InfoCommand.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/InfoCommand.cs @@ -8,10 +8,10 @@ using DiIiS_NA.LoginServer.Battle; namespace DiIiS_NA.GameServer.CommandManager; -[CommandGroup("info", "Get current game information.")] +[CommandGroup("info", "Get current game information.", inGameOnly: true)] public class InfoCommand : CommandGroup { - [DefaultCommand] + [DefaultCommand(inGameOnly: true)] public string Info(string[] @params, BattleClient invokerClient) { if (invokerClient?.InGameClient?.Game is not { } game || invokerClient.InGameClient.Player is not { } player || diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/InvulnerableCommand.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/InvulnerableCommand.cs index fdcba31..5ca5bcb 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/InvulnerableCommand.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/InvulnerableCommand.cs @@ -5,14 +5,13 @@ using DiIiS_NA.LoginServer.Battle; namespace DiIiS_NA.GameServer.CommandManager; -[CommandGroup("invulnerable", "Makes you invulnerable", Account.UserLevels.GM)] +[CommandGroup("invulnerable", "Makes you invulnerable", Account.UserLevels.GM, inGameOnly: true)] public class InvulnerableCommand : CommandGroup { [DefaultCommand] public string Invulnerable(string[] @params, BattleClient invokerClient) { - if (invokerClient?.InGameClient?.Player is not { } player) - return "You cannot invoke this command from console."; + var player = invokerClient.InGameClient.Player; if (player.Attributes.FixedMap.Contains(FixedAttribute.Invulnerable)) { diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/ItemCommand.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/ItemCommand.cs index cb69759..511092b 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/ItemCommand.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/ItemCommand.cs @@ -9,10 +9,10 @@ using DiIiS_NA.LoginServer.Battle; namespace DiIiS_NA.GameServer.CommandManager; [CommandGroup("item", "Spawns an item (with a name or type).\nUsage: item [type |] [amount]", - Account.UserLevels.GM)] + Account.UserLevels.GM, inGameOnly: true)] public class ItemCommand : CommandGroup { - [DefaultCommand] + [DefaultCommand(inGameOnly: true)] public string Spawn(string[] @params, BattleClient invokerClient) { if (invokerClient == null) diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/LevelUpCommand.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/LevelUpCommand.cs index f8de9de..17e07c2 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/LevelUpCommand.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/LevelUpCommand.cs @@ -6,10 +6,10 @@ using DiIiS_NA.LoginServer.Battle; namespace DiIiS_NA.GameServer.CommandManager; [CommandGroup("levelup", "Levels your character.\nOptionally specify the number of levels: !levelup [count]", - Account.UserLevels.GM)] + Account.UserLevels.GM, inGameOnly: true)] public class LevelUpCommand : CommandGroup { - [DefaultCommand] + [DefaultCommand(inGameOnly: true)] public string LevelUp(string[] @params, BattleClient invokerClient) { if (invokerClient == null) diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/PlatinumAchiCommand.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/PlatinumAchiCommand.cs index c6632d4..f4c0852 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/PlatinumAchiCommand.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/PlatinumAchiCommand.cs @@ -5,18 +5,12 @@ using DiIiS_NA.LoginServer.Battle; namespace DiIiS_NA.GameServer.CommandManager; [CommandGroup("achiplatinum", - "Platinum for your character.\nOptionally specify the number of levels: !platinum [count]", Account.UserLevels.GM)] + "Platinum for your character.\nOptionally specify the number of levels: !platinum [count]", Account.UserLevels.GM, inGameOnly: true)] public class PlatinumAchiCommand : CommandGroup { - [DefaultCommand] + [DefaultCommand(inGameOnly: true)] public string Platinum(string[] @params, BattleClient invokerClient) { - if (invokerClient == null) - return "You cannot invoke this command from console."; - - if (invokerClient.InGameClient == null) - return "You can only invoke this command while in-game."; - var player = invokerClient.InGameClient.Player; var amount = 1; var achiid = 74987243307074; diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/PlatinumCommand.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/PlatinumCommand.cs index 07ec0ae..5f85ac3 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/PlatinumCommand.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/PlatinumCommand.cs @@ -6,18 +6,12 @@ namespace DiIiS_NA.GameServer.CommandManager; [CommandGroup("platinum", "Platinum for your character.\nOptionally specify the number of levels: !platinum [count]", - Account.UserLevels.Tester)] + Account.UserLevels.Tester, inGameOnly: true)] public class PlatinumCommand : CommandGroup { - [DefaultCommand] + [DefaultCommand(inGameOnly: true)] public string Platinum(string[] @params, BattleClient invokerClient) { - if (invokerClient == null) - return "You cannot invoke this command from console."; - - if (invokerClient.InGameClient == null) - return "You can only invoke this command while in-game."; - var player = invokerClient.InGameClient.Player; var amount = 1; diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/PlayEffectGroup.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/PlayEffectGroup.cs index c3ee86c..8514f70 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/PlayEffectGroup.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/PlayEffectGroup.cs @@ -4,18 +4,12 @@ using DiIiS_NA.LoginServer.Battle; namespace DiIiS_NA.GameServer.CommandManager; [CommandGroup("eff", "Platinum for your character.\nOptionally specify the number of levels: !eff [count]", - Account.UserLevels.GM)] + Account.UserLevels.GM, inGameOnly: true)] public class PlayEffectGroup : CommandGroup { - [DefaultCommand] + [DefaultCommand(inGameOnly: true)] public string PlayEffectCommand(string[] @params, BattleClient invokerClient) { - if (invokerClient == null) - return "You cannot invoke this command from console."; - - if (invokerClient.InGameClient == null) - return "You can only invoke this command while in-game."; - var player = invokerClient.InGameClient.Player; var id = 1; diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/PowerfulCommand.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/PowerfulCommand.cs index 69b67ce..60c30a8 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/PowerfulCommand.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/PowerfulCommand.cs @@ -6,15 +6,13 @@ using DiIiS_NA.LoginServer.Battle; namespace DiIiS_NA.GameServer.CommandManager; [CommandGroup("powerful", "Makes your character with absurd amount of damage. Useful for testing.", - Account.UserLevels.Tester)] + Account.UserLevels.Tester, inGameOnly: true)] public class PowerfulCommand : CommandGroup { - [DefaultCommand] + [DefaultCommand(inGameOnly: true)] public string Powerful(string[] @params, BattleClient invokerClient) { - if (invokerClient?.InGameClient?.Player is not { } player) - return "You must be in game to use this command."; - + var player = invokerClient.InGameClient.Player; if (player.Attributes.FixedMap.Contains(FixedAttribute.Powerful)) { player.Attributes.FixedMap.Remove(FixedAttribute.Powerful); diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/QuestCommand.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/QuestCommand.cs index 5dec561..e791304 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/QuestCommand.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/QuestCommand.cs @@ -39,7 +39,7 @@ public class QuestCommand : CommandGroup } } - [Command("event", "Launches chosen side-quest by snoID\n Usage: event snoId")] + [Command("event", "Launches chosen side-quest by snoID\n Usage: event snoId", inGameOnly: true)] public string Event(string[] @params, BattleClient invokerClient) { if (@params == null) @@ -61,7 +61,7 @@ public class QuestCommand : CommandGroup } } - [Command("timer", "Send broadcast text message.\n Usage: public 'message'")] + [Command("timer", "Send broadcast text message.\n Usage: public 'message'", inGameOnly: true)] public string Timer(string[] @params, BattleClient invokerClient) { if (@params == null) @@ -78,7 +78,7 @@ public class QuestCommand : CommandGroup return "Message sent."; } - [Command("set", "Advance to a specific quest step.\n Usage: quest to [questId] [step]")] + [Command("set", "Advance to a specific quest step.\n Usage: quest to [questId] [step]", inGameOnly: true)] public string Set(string[] @params, BattleClient invokerClient) { if (@params == null) diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/ResourcefulCommand.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/ResourcefulCommand.cs index 54a3961..e078f15 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/ResourcefulCommand.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/ResourcefulCommand.cs @@ -6,10 +6,10 @@ using DiIiS_NA.LoginServer.Battle; namespace DiIiS_NA.GameServer.CommandManager; [CommandGroup("resourceful", "Makes your character with full resource. Useful for testing.", - Account.UserLevels.Tester)] + Account.UserLevels.Tester, inGameOnly: true)] public class ResourcefulCommand : CommandGroup { - [DefaultCommand] + [DefaultCommand(inGameOnly: true)] public string Resourceful(string[] @params, BattleClient invokerClient) { if (invokerClient?.InGameClient?.Player is not { } player) diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/SpawnCommand.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/SpawnCommand.cs index cbaff81..c93b62e 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/SpawnCommand.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/SpawnCommand.cs @@ -9,7 +9,7 @@ namespace DiIiS_NA.GameServer.CommandManager; [CommandGroup("spawn", "Spawns a mob.\nUsage: spawn [actorSNO] [amount]", Account.UserLevels.GM)] public class SpawnCommand : CommandGroup { - [DefaultCommand] + [DefaultCommand(inGameOnly: true)] public string Spawn(string[] @params, BattleClient invokerClient) { if (invokerClient == null) diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/SpeedCommand.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/SpeedCommand.cs index 5f64e3d..49ee918 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/SpeedCommand.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/SpeedCommand.cs @@ -5,15 +5,12 @@ using DiIiS_NA.LoginServer.Battle; namespace DiIiS_NA.GameServer.CommandManager; -[CommandGroup("speed", "Modify speed walk of you character.\nUsage: !speed \nReset: !speed")] +[CommandGroup("speed", "Modify speed walk of you character.\nUsage: !speed \nReset: !speed", inGameOnly: true)] public class SpeedCommand : CommandGroup { - [DefaultCommand] + [DefaultCommand(inGameOnly: true)] public string ModifySpeed(string[] @params, BattleClient invokerClient) { - if (invokerClient?.InGameClient == null) - return "This command can only be used in-game."; - if (@params == null) return "Change the movement speed. Min 0 (Base), Max 2.\n You can use decimal values like 1.3 for example."; diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/StashUpCommand.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/StashUpCommand.cs index ed723fd..6ab4b60 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/StashUpCommand.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/StashUpCommand.cs @@ -3,18 +3,12 @@ using DiIiS_NA.LoginServer.Battle; namespace DiIiS_NA.GameServer.CommandManager; -[CommandGroup("stashup", "Upgrade Stash.", Account.UserLevels.Tester)] +[CommandGroup("stashup", "Upgrade Stash.", Account.UserLevels.Tester, inGameOnly: true)] public class StashUpCommand : CommandGroup { [DefaultCommand] public string Stashup(string[] @params, BattleClient invokerClient) { - if (invokerClient == null) - return "You cannot invoke this command from console."; - - if (invokerClient.InGameClient == null) - return "You can only invoke this command while in-game."; - var player = invokerClient.InGameClient.Player; player.Inventory.OnBuySharedStashSlots(null); diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/TagCommand.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/TagCommand.cs index 5d3b060..87a7fe5 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/TagCommand.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/TagCommand.cs @@ -3,10 +3,10 @@ using DiIiS_NA.LoginServer.Battle; namespace DiIiS_NA.GameServer.CommandManager; -[CommandGroup("tag", "Switch private Tag for connect")] +[CommandGroup("tag", "Switch private Tag for connect", inGameOnly: true)] class TagCommand : CommandGroup { - [DefaultCommand(Account.UserLevels.User)] + [DefaultCommand(Account.UserLevels.User, inGameOnly: true)] public string Tag(string[] @params, BattleClient invokerClient) { if(@params == null) diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/TeleportCommand.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/TeleportCommand.cs index 6bf2f4e..389061c 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/TeleportCommand.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/TeleportCommand.cs @@ -7,18 +7,12 @@ using DiIiS_NA.LoginServer.Battle; namespace DiIiS_NA.GameServer.CommandManager; -[CommandGroup("tp", "Transfers your character to another world.")] +[CommandGroup("tp", "Transfers your character to another world.", inGameOnly: true)] public class TeleportCommand : CommandGroup { - [DefaultCommand] + [DefaultCommand(inGameOnly: true)] public string Portal(string[] @params, BattleClient invokerClient) { - if (invokerClient == null) - return "You cannot invoke this command from console."; - - if (invokerClient.InGameClient == null) - return "You can only invoke this command while in-game."; - if (@params != null && @params.Any()) { int.TryParse(@params[0], out var worldId); diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/UnlockArtCommand.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/UnlockArtCommand.cs index e55797e..a24cd2a 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/UnlockArtCommand.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/UnlockArtCommand.cs @@ -4,18 +4,12 @@ using DiIiS_NA.LoginServer.Battle; namespace DiIiS_NA.GameServer.CommandManager; -[CommandGroup("unlockart", "Unlock all artisans: !unlockart", Account.UserLevels.Tester)] +[CommandGroup("unlockart", "Unlock all artisans: !unlockart", Account.UserLevels.Tester, inGameOnly: true)] public class UnlockArtCommand : CommandGroup { - [DefaultCommand] + [DefaultCommand(inGameOnly: true)] public string UnlockArt(string[] @params, BattleClient invokerClient) { - if (invokerClient == null) - return "You cannot invoke this command from console."; - - if (invokerClient.InGameClient == null) - return "You can only invoke this command while in-game."; - var player = invokerClient.InGameClient.Player; player.BlacksmithUnlocked = true; diff --git a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/WorldCommand.cs b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/WorldCommand.cs index 0e41a30..26f2bba 100644 --- a/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/WorldCommand.cs +++ b/src/DiIiS-NA/D3-GameServer/CommandManager/Commands/WorldCommand.cs @@ -6,10 +6,10 @@ using DiIiS_NA.LoginServer.Battle; namespace DiIiS_NA.GameServer.CommandManager; -[CommandGroup("world", "World commands", Account.UserLevels.Tester)] +[CommandGroup("world", "World commands", Account.UserLevels.Tester, inGameOnly: true)] public class WorldCommand : CommandGroup { - [Command("info", "Current World Info")] + [Command("info", "Current World Info", inGameOnly: true)] public string Info(string[] @params, BattleClient invokerClient) { if (invokerClient?.InGameClient?.Player is not {} player)