/// <summary> /// Returns true if character has the Moderator role or it's null and we're on the server /// (it means the command is invoked from the server system console directly). /// </summary> public static bool ServerIsModeratorOrSystemConsole(ICharacter character) => ServerModeratorSystem.SharedIsModerator(character) || character == null && Api.IsServer;
/// <summary> /// Returns true if character has the Moderator role or it's null and we're on the server /// (it means the command is invoked from the server system console directly). /// </summary> public static bool ServerIsModeratorOrSystemConsole(ICharacter character) { return(ServerModeratorSystem.SharedIsModerator(character) || character is null && Api.IsServer); }
public string Execute( [CustomSuggestions(nameof(GetCommandNameSuggestions))] string searchCommand = null) { var allCommands = ConsoleCommandsSystem.AllCommands.ToList(); if (Api.IsServer) { allCommands.RemoveAll( // exclude client commands on Server-side c => (c.Kind ^ ConsoleCommandKinds.Client) == default); } var currentCharacter = this.ExecutionContextCurrentCharacter; if (currentCharacter is not null) { var isOperator = ServerOperatorSystem.SharedIsOperator(currentCharacter); var isModerator = ServerModeratorSystem.SharedIsModerator(currentCharacter); ConsoleCommandsSystem.SharedFilterAvailableCommands(allCommands, isOperator, isModerator); } var sb = new StringBuilder(capacity: 2047); sb.AppendLine().AppendLine(); if (!string.IsNullOrEmpty(searchCommand)) { var foundCommandsList = allCommands.Where( c => c.Name.StartsWith(searchCommand, StringComparison.OrdinalIgnoreCase) || c.Alias is not null && c.Alias.StartsWith(searchCommand, StringComparison.OrdinalIgnoreCase)) .ToList(); if (foundCommandsList.Count == 0) { sb.Append("No commands found."); return(sb.ToString()); } allCommands = foundCommandsList; } //AppendLegend(sb); //sb.AppendLine(); sb.AppendLine("Commands: "); foreach (var consoleCommand in allCommands) { string prefix; switch (consoleCommand.Kind) { // add server suffix for server commands case ConsoleCommandKinds.ServerEveryone: case ConsoleCommandKinds.ServerOperator: case ConsoleCommandKinds.ServerModerator: prefix = "/"; break; case ConsoleCommandKinds.ClientAndServerEveryone: case ConsoleCommandKinds.ClientAndServerOperatorOnly: prefix = "(/)"; break; default: prefix = string.Empty; break; } AppendCommandInfo(sb, consoleCommand, prefix); } return(sb.ToString()); }