internal static void executeCommand(IRocketCommand command,Steamworks.CSteamID caller, string commandString) { if (!command.AllowFromConsole && !IsPlayer(caller)) { Logger.Log("This command can't be called from console"); return; } string[] collection = Regex.Matches(commandString, @"[\""](.+?)[\""]|([^ ]+)", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture).Cast<Match>().Select(m => m.Value.Trim('"').Trim()).ToArray(); try { IRocketPlayer p = UnturnedPlayer.FromCSteamID(caller); if (p == null) { p = new ConsolePlayer(); } command.Execute(p, collection); } catch (Exception ex) { Logger.LogError("An error occured while executing command /" + command.Name + " " + commandString + ": " + ex.ToString()); } }
public bool Execute(IRocketPlayer player, string command) { string[] commandParts = Regex.Matches(command, @"[\""](.+?)[\""]|([^ ]+)", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture).Cast<Match>().Select(m => m.Value.Trim('"').Trim()).ToArray(); if (commandParts.Length != 0) { name = commandParts[0]; string[] parameters = commandParts.Skip(1).ToArray(); if (player == null) player = new ConsolePlayer(); IRocketCommand rocketCommand = GetCommand(name); if (rocketCommand != null) { if (rocketCommand.AllowedCaller == AllowedCaller.Player && player is ConsolePlayer) { Logger.Log("This command can't be called from console"); return false; } if (rocketCommand.AllowedCaller == AllowedCaller.Console && !(player is ConsolePlayer)) { Logger.Log("This command can only be called from console"); return false; } try { rocketCommand.Execute(player, parameters); } catch (Exception ex) { Logger.LogError("An error occured while executing " + rocketCommand.Name + " [" + String.Join(", ", parameters) + "]: " + ex.ToString()); } return true; } } return false; }