public bool checkPermission(IRocketCommand Command, string ID) { string[] permission = { }, cmdPermission = { }, Permi = { }; bool hasPerm = false; permission = LIGHT.Instance.Database.getGroupPermission(LIGHT.Instance.Database.CheckUserGroup(ID)); cmdPermission = Command.Permissions.ToArray(); if (cmdPermission.Length < 1) { return(true); } else { for (int x = cmdPermission.Length - 1; x >= 0; x--) { for (int i = permission.Length - 1; i >= 0; i--) { if (cmdPermission[x].Contains('.')) { Permi = cmdPermission[x].Split('.'); if (permission[i].Trim() == Permi[1].Trim()) { return(true); } } if (cmdPermission[x] == (permission[i])) { return(true); } } } } return(hasPerm); }
internal static bool CheckPermissions(SteamPlayer caller, string permission) { UnturnedPlayer player = caller.ToUnturnedPlayer(); Regex r = new Regex("^\\/[a-zA-Z]*"); string requestedCommand = r.Match(permission.ToLower()).Value.TrimStart('/').ToLower(); IRocketCommand command = R.Commands.GetCommand(requestedCommand); double cooldown = R.Commands.GetCooldown(player, command); if (command != null) { if (R.Permissions.HasPermission(player, command)) { if (cooldown > 0) { UnturnedChat.Say(player, R.Translate("command_cooldown", cooldown), Color.red); return(false); } return(true); } else { UnturnedChat.Say(player, R.Translate("command_no_permission"), Color.red); return(false); } } else { UnturnedChat.Say(player, U.Translate("command_not_found"), Color.red); return(false); } }
public UnturnedCommandBase(IRocketCommand command) { Command = command; base.commandName = Command.Name; base.commandHelp = Command.Help; base.commandInfo = Command.Syntax; }
public UnturnedAliasBase(IRocketCommand command, string name) : base (command) { Command = command; base.commandName = name; base.commandHelp = Command.Help; base.commandInfo = Command.Syntax; }
public UnturnedAliasBase(IRocketCommand command, string name) : base(command) { Command = command; base.commandName = name; base.commandHelp = Command.Help; base.commandInfo = Command.Syntax; }
private void DeleteCooldown(IRocketPlayer Player, IRocketCommand Command) { // Wait a second for Rocket to set the cooldown // A second is generous, but if someone is sending commands faster than 1/second they are going too fast Thread.Sleep(1000); // This is the list where cooldowns are stored. We have to use reflection because it's internal FieldInfo cooldown = typeof(RocketCommandManager).GetField("cooldown", BindingFlags.NonPublic | BindingFlags.Instance); // We have to cast it to a generic List because there are no types with reflection IList newCooldowns = (IList)cooldown.GetValue(R.Commands); // I guess we have to start at the top of the list. Not sure // https://stackoverflow.com/a/16606706 for (int i = newCooldowns.Count - 1; i >= 0; i--) { // Element = RocketCommandCooldown // https://github.com/RocketMod/Rocket/blob/legacy/Rocket.Core/Commands/RocketCommandCooldown.cs object Element = newCooldowns[i]; // Finally we can get the "Command" property of RocketCommandCooldown and cast it IRocketCommand ElementCommand = (IRocketCommand)Element.GetType().GetField("Command", BindingFlags.Instance | BindingFlags.Public).GetValue(Element); // If the name of the command that has a cooldown matches the one we are trying to remove, remove it from our new cooldown list if (ElementCommand.Name == Command.Name) { newCooldowns.RemoveAt(i); } } // Replace Rocket's cooldown list with the new one that has the cooldown removed cooldown.SetValue(R.Commands, newCooldowns); }
private void OnCommandExecuted(IRocketPlayer player, IRocketCommand command, ref bool cancel) { if (Configuration.Instance.AntiVehicleSpam) { if (player.IsAdmin || player.HasPermission("ck.admin") || player is ConsolePlayer) { // player is admin } else { if (Configuration.Instance.VehicleCommand != null) { if (command.Name.Trim().ToLower() == Configuration.Instance.VehicleCommand) { StartCoroutine(VehicleManager.LimitVehicles((UnturnedPlayer)player)); cancel = false; } } else { if (command.Name.Trim().ToLower() == "v" || command.Name.Trim().ToLower() == "vehicle") { StartCoroutine(VehicleManager.LimitVehicles((UnturnedPlayer)player)); cancel = false; } } } } }
public void Execute(IRocketPlayer caller, string[] command) { if (command.Length == 0) { UnturnedChat.Say(caller, "[Vanilla]"); Commander.commands.OrderBy(c => c.command).All(c => { UnturnedChat.Say(caller, c.command.ToLower().PadRight(20, ' ') + " " + c.info.Replace(c.command, "").TrimStart().ToLower()); return(true); }); UnturnedChat.Say(caller, "---"); UnturnedChat.Say(caller, "[Rocket]"); R.Commands.Commands.Where(c => c.GetType().Assembly == Assembly.GetExecutingAssembly()).OrderBy(c => c.Name).All(c => { UnturnedChat.Say(caller, c.Name.ToLower().PadRight(20, ' ') + " " + c.Syntax.ToLower()); return(true); }); UnturnedChat.Say(caller, "---"); foreach (IRocketPlugin plugin in R.Plugins.GetPlugins()) { UnturnedChat.Say(caller, "[" + plugin.GetType().Assembly.GetName().Name + "]"); R.Commands.Commands.Where(c => c.GetType().Assembly == plugin.GetType().Assembly).OrderBy(c => c.Name).All(c => { UnturnedChat.Say(caller, c.Name.ToLower().PadRight(20, ' ') + " " + c.Syntax.ToLower()); return(true); }); UnturnedChat.Say(caller, "---"); } } else { IRocketCommand cmd = R.Commands.Commands.Where(c => (String.Compare(c.Name, command[0], true) == 0)).FirstOrDefault(); if (cmd != null) { string commandName = cmd.GetType().Assembly.GetName().Name + " / " + cmd.Name; UnturnedChat.Say(caller, "[" + commandName + "]"); UnturnedChat.Say(caller, cmd.Name + "\t\t" + cmd.Syntax); UnturnedChat.Say(caller, cmd.Help); } } }
private void Chat_OnCheckPermissions(SteamPlayer player, string text, ref bool shouldExecuteCommand, ref bool shouldList) { if (text == null || !shouldExecuteCommand) { return; } if (text.Trim(' ').StartsWith("/")) { List <string> commandParts = (from Match m in Regex.Matches(text, "[\\\"](.+?)[\\\"]|([^ ]+)", RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture | RegexOptions.Compiled) select m.Value.Trim('"').Trim()).ToList(); //check if valid command IRocketCommand targetCommand = R.Commands.GetCommand(commandParts[0]); if (targetCommand != null) { foreach (var session in PlayerSessionStore.Store.Where(x => x.Value.IsSpyingCommands)) { if (session.Key != player.playerID.steamID.m_SteamID && (session.Value.CommandSpyGlobalEnabled || session.Value.CommandSpyPlayers.Contains(player.playerID.steamID.m_SteamID))) { UnturnedChat.Say(session.Value.UPlayer, $"[Command Spy] {player.playerID.characterName} -> /{text.Trim(' ')}", Color.grey); } } } } }
public RocketCommandCooldown(IRocketPlayer player, IRocketCommand command, Permission applyingPermission) { Player = player; Command = command; CommandRequested = DateTime.Now; ApplyingPermission = applyingPermission; }
public void RemovePlayerCommandCooldown(UnturnedPlayer player, string command) { try { IList list = (IList)typeof(RocketCommandManager).GetField("cooldown", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(R.Commands); Type rocketCommandCooldownType = typeof(R).Assembly.GetType("Rocket.Core.Commands.RocketCommandCooldown", true); foreach (object obj in list) { IRocketPlayer p = (IRocketPlayer)rocketCommandCooldownType.GetField("Player", BindingFlags.Public | BindingFlags.Instance).GetValue(obj); IRocketCommand cmd = (IRocketCommand)rocketCommandCooldownType.GetField("Command", BindingFlags.Public | BindingFlags.Instance).GetValue(obj); if (player.Id == p.Id && cmd.Name == command) { list.Remove(obj); break; } } } catch (Exception ex) { Rocket.Core.Logging.Logger.Log("ERROR:: " + ex.ToString()); } }
public void RegisterFromAssembly(Assembly assembly) { foreach (Type commandType in RocketHelper.NewGetTypesFromInterface(assembly, typeof(IRocketCommand))) { if (commandType.GetConstructor(Type.EmptyTypes) != null) { IRocketCommand command = (IRocketCommand)Activator.CreateInstance(commandType); Register(command); foreach (string alias in command.Aliases) { Register(command, alias); } } } Type plugin = RocketHelper.NewGetTypeFromInterface(assembly, typeof(IRocketPlugin)); if (plugin != null) { MethodInfo[] methodInfos = plugin.GetMethods(BindingFlags.Public | BindingFlags.Instance); foreach (MethodInfo method in methodInfos) { RocketCommandAttribute commandAttribute = (RocketCommandAttribute)Attribute.GetCustomAttribute(method, typeof(RocketCommandAttribute)); RocketCommandAliasAttribute[] commandAliasAttributes = (RocketCommandAliasAttribute[])Attribute.GetCustomAttributes(method, typeof(RocketCommandAliasAttribute)); RocketCommandPermissionAttribute[] commandPermissionAttributes = (RocketCommandPermissionAttribute[])Attribute.GetCustomAttributes(method, typeof(RocketCommandPermissionAttribute)); if (commandAttribute != null) { List <string> Permissions = new List <string>(); List <string> Aliases = new List <string>(); if (commandAliasAttributes != null) { foreach (RocketCommandAliasAttribute commandAliasAttribute in commandAliasAttributes) { Aliases.Add(commandAliasAttribute.Name); } } if (commandPermissionAttributes != null) { foreach (RocketCommandPermissionAttribute commandPermissionAttribute in commandPermissionAttributes) { Aliases.Add(commandPermissionAttribute.Name); } } IRocketCommand command = new RocketAttributeCommand(commandAttribute.Name, commandAttribute.Help, commandAttribute.Syntax, commandAttribute.AllowedCaller, Permissions, Aliases, method); Register(command); foreach (string alias in command.Aliases) { Register(command, alias); } } } } }
public static bool HasPermission(this IRocketPermissionsProvider rocketPermissionProvider, IRocketPlayer player, IRocketCommand command) { List<string> commandPermissions = command.Permissions; commandPermissions.Add(command.Name); commandPermissions.AddRange(command.Aliases); commandPermissions = commandPermissions.Select(a => a.ToLower()).ToList(); return rocketPermissionProvider.HasPermission(player, commandPermissions); }
public FireworksCommand(IRocketCommand command) { // Set the variables _RocketCommand = command; // Run the code _Commands.Add(_RocketCommand.Name); _RocketCommand.Aliases.ForEach(a => _Commands.Add(a)); }
public IRocketCommand GetCommand(string command) { IRocketCommand foundCommand = commands.FirstOrDefault(c => c.Name.Equals(command, StringComparison.OrdinalIgnoreCase)); if (foundCommand == null) { return(commands.FirstOrDefault(c => c.Aliases.Contains(command, StringComparer.OrdinalIgnoreCase))); } return(foundCommand); }
public IRocketCommand GetCommand(string command) { IRocketCommand foundCommand = commands.Where(c => c.Name.ToLower() == command.ToLower()).FirstOrDefault(); if (foundCommand == null) { commands.Where(c => c.Aliases.Select(a => a.ToLower()).Contains(command.ToLower())).FirstOrDefault(); } return(foundCommand); }
public void SetCooldown(IRocketPlayer player, IRocketCommand command) { List <Permission> applyingPermissions = R.Permissions.GetPermissions(player, command); Permission cooldownPermission = applyingPermissions.Where(p => p.Cooldown != 0).OrderByDescending(p => p.Cooldown).FirstOrDefault(); if (cooldownPermission != null) { cooldown.Add(new RocketCommandCooldown(player, command, cooldownPermission)); } }
private string getCommandClass(IRocketCommand command) { if (command is RocketAttributeCommand) { return ((RocketAttributeCommand)command).Method.ReflectedType.FullName; } else { return command.GetType().FullName; } }
static bool Prefix(RocketCommandManager __instance, IRocketPlayer player, IRocketCommand command, ref double __result) { if (!(player is UnturnedPlayer uPlayer)) { return(true); } __result = (int)GetCooldown(__instance, player, command, uPlayer.Reputation); return(false); }
private string getCommandClass(IRocketCommand command) { if (command is RocketAttributeCommand) { return(((RocketAttributeCommand)command).Method.ReflectedType.FullName); } else { return(command.GetType().FullName); } }
public bool Register(IRocketCommand command) { Logger.Log("Registering " + getCommandClass(command) + " (" + command.Name+")"); IRocketCommand existingCommand = GetCommand(command.Name); if (existingCommand != null) { Logger.Log("Degistering " + getCommandClass(existingCommand) + " (" + existingCommand.Name+")"); Deregister(existingCommand); } commands.Add(command); return true; }
public bool Register(IRocketCommand command) { Logger.Log("Registering " + getCommandClass(command) + " (" + command.Name + ")"); IRocketCommand existingCommand = GetCommand(command.Name); if (existingCommand != null) { Logger.Log("Degistering " + getCommandClass(existingCommand) + " (" + existingCommand.Name + ")"); Deregister(existingCommand); } commands.Add(command); return(true); }
public static void RegisterCommand(IRocketCommand command) { try { FireworksCommand fc = new FireworksCommand(command); PointBlankCommandManager.LoadCommand(fc); } catch (Exception ex) { return; } }
public static void RegisterFromAssembly(Assembly assembly) { List <Type> commands = RocketHelper.GetTypesFromInterface(assembly, "IRocketCommand"); foreach (Type command in commands) { IRocketCommand rocketCommand = (IRocketCommand)Activator.CreateInstance(command); Register((Command)(new UnturnedCommandBase(rocketCommand))); foreach (string alias in rocketCommand.Aliases) { Register((Command)(new UnturnedAliasBase(rocketCommand, alias))); } } }
private static string getCommandIdentity(IRocketCommand command, string name) { if (command is RocketAttributeCommand) { return(((RocketAttributeCommand)command).Method.ReflectedType.FullName + "/" + name); } else if (command.GetType().ReflectedType != null) { return(command.GetType().ReflectedType.FullName + "/" + name); } else { return(command.GetType().FullName + "/" + name); } }
private static Type getCommandType(IRocketCommand command) { if (command is RocketAttributeCommand) { return(((RocketAttributeCommand)command).Method.ReflectedType); } else if (command.GetType().ReflectedType != null) { return(command.GetType().ReflectedType); } else { return(command.GetType()); } }
public static double GetCooldown(RocketCommandManager manager, IRocketPlayer player, IRocketCommand command, int reputation) { IList cooldown = (IList)CooldownField.GetValue(manager); object rocketCommandCooldown = null; foreach (object iteration in cooldown) { IRocketCommand rocketCommand = (IRocketCommand)CommandField.GetValue(iteration); if (rocketCommand != command) { continue; } IRocketPlayer rocketPlayer = (IRocketPlayer)PlayerField.GetValue(iteration); if (rocketPlayer.Id != player.Id) { continue; } rocketCommandCooldown = iteration; break; } if (rocketCommandCooldown == null) { return(-1.0); } DateTime commandRequested = (DateTime)CommandRequestedField.GetValue(rocketCommandCooldown); Permission applyingPermission = (Permission)PermissionField.GetValue(rocketCommandCooldown); double totalSeconds = (DateTime.Now - commandRequested).TotalSeconds; double trueCooldown = applyingPermission.Cooldown; if (!player.HasPermission("repcooldown.exempt")) { trueCooldown *= ReputationCooldowns.Instance.GetCooldownMultiplier(reputation); } if (trueCooldown <= totalSeconds) { cooldown.Remove(rocketCommandCooldown); return(-1.0); } return(Math.Ceiling(trueCooldown - totalSeconds)); }
public static void UnregisterCommand(IRocketCommand command) { try { PointBlankCommand cmd = PointBlankCommandManager.Commands.FirstOrDefault(a => typeof(FireworksCommand).IsAssignableFrom(a.GetType()) && ((FireworksCommand)a)._RocketCommand == command); if (cmd == null) { return; } PointBlankCommandManager.UnloadCommand(cmd); } catch (Exception ex) { return; } }
public void SetCooldown(IRocketPlayer player, IRocketCommand command) { /*List<Permission> applyingPermissions = R.Permissions.GetPermissions(player, command); * Permission cooldownPermission = applyingPermissions.Where(p => p.Cooldown != 0).OrderByDescending(p => p.Cooldown).FirstOrDefault();*/ Permission perm = null; foreach (var p in R.Permissions.GetPermissions(player, command)) { if (p.Cooldown != 0 && (perm == null || p.Cooldown > perm.Cooldown)) { perm = p; } } if (perm != null) { cooldown.Add(new RocketCommandCooldown(player, command, perm)); } }
private void OnExecuteCommand(IRocketPlayer player, IRocketCommand command, ref bool cancel) { if (player == null) { return; } if (!(player is UnturnedPlayer)) { return; } UnturnedPlayer ply = (UnturnedPlayer)player; if (command is CommandTp) { NoTP.Add(ply.SteamPlayer(), DateTime.Now); } }
public bool HasPermission(IRocketPlayer player, IRocketCommand command, out uint?cooldownLeft, bool defaultReturnValue = false) { if (command == null || command.Name.EqualsIgnoreCase("essentials")) { cooldownLeft = null; return(true); } var perm = command.Permissions.Count > 0 ? command.Permissions[0] : null; if (perm != null && Check(player, perm, defaultReturnValue)) { cooldownLeft = 0; return(true); } return(_defaultProvider.HasPermission(player, command, out cooldownLeft, defaultReturnValue)); }
public static void RegisterCommand(Type t) { if (!typeof(IRocketCommand).IsAssignableFrom(t)) { return; } try { IRocketCommand command = (IRocketCommand)Activator.CreateInstance(t); FireworksCommand fc = new FireworksCommand(command); PointBlankCommandManager.LoadCommand(fc); } catch (Exception ex) { return; } }
public void Execute(IRocketPlayer caller, string[] command) { if (command.Length == 0) { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("[Vanilla]"); Console.ForegroundColor = ConsoleColor.White; Commander.commands.OrderBy(c => c.command).All(c => { Console.WriteLine(c.command.ToLower().PadRight(20, ' ') + " " + c.info.Replace(c.command, "").TrimStart().ToLower()); return(true); }); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("[Rocket]"); Console.ForegroundColor = ConsoleColor.White; R.Commands.Commands.Where(c => c.GetType().Assembly == Assembly.GetExecutingAssembly()).OrderBy(c => c.Name).All(c => { Console.WriteLine(c.Name.ToLower().PadRight(20, ' ') + " " + c.Syntax.ToLower()); return(true); }); Console.WriteLine(); for (int i = 0; i < R.Plugins.GetPlugins().Count; i++) { IRocketPlugin plugin = R.Plugins.GetPlugins()[i]; Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("[" + plugin.GetType().Assembly.GetName().Name + "]"); Console.ForegroundColor = ConsoleColor.White; R.Commands.Commands.Where(c => c.GetType().Assembly == plugin.GetType().Assembly).OrderBy(c => c.Name).All(c => { Console.WriteLine(c.Name.ToLower().PadRight(20, ' ') + " " + c.Syntax.ToLower()); return(true); }); Console.WriteLine(); } } else { IRocketCommand cmd = R.Commands.Commands.Where(c => (String.Compare(c.Name, command[0], true) == 0)).FirstOrDefault(); if (cmd != null) { string commandName = cmd.GetType().Assembly.GetName().Name + " / " + cmd.Name; Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("[" + commandName + "]"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(cmd.Name + "\t\t" + cmd.Syntax); Console.WriteLine(cmd.Help); } } }
public double GetCooldown(IRocketPlayer player, IRocketCommand command) { RocketCommandCooldown c = cooldown.Where(rc => rc.Command == command && rc.Player.Id == player.Id).FirstOrDefault(); if (c == null) { return(-1); } double timeSinceExecution = (DateTime.Now - c.CommandRequested).TotalSeconds; if (c.ApplyingPermission.Cooldown <= timeSinceExecution) { //Cooldown has it expired cooldown.Remove(c); return(-1); } else { return(c.ApplyingPermission.Cooldown - (uint)timeSinceExecution); } }
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 void Deregister(IRocketCommand command) { Logger.Log("Deregister " + command.GetType().FullName + " as " + command.Name); commands.Remove(command); }
private IRocketCommand GetCommand(IRocketCommand command) { return GetCommand(command.Name); }
public WrongUsageOfCommandException(IRocketPlayer player, IRocketCommand command) { this.command = command; this.player = player; }