public void SendPermissionChange(ulong steamId, CommandStruct commandStruct)
        {
            var message = new MessageCommandPermission()
            {
                Commands = new List<CommandStruct>(),
                CommandAction = CommandActions.Level
            };
            message.Commands.Add(commandStruct);

            ConnectionHelper.SendMessageToPlayer(steamId, message);
        }
        public void UpdateCommandSecurity(CommandStruct command, ulong sender)
        {
            var commandStruct = Permissions.Commands.FirstOrDefault(c => c.Name.Equals(command.Name, StringComparison.InvariantCultureIgnoreCase));

            int index;
            if (CommandCache.ContainsKey(sender) && command.Name.Substring(0, 1) == "#" && Int32.TryParse(command.Name.Substring(1), out index) && index > 0 && index <= CommandCache[sender].Count)
                commandStruct = Permissions.Commands.FirstOrDefault(c => c.Name.Equals(CommandCache[sender][index - 1].Name, StringComparison.InvariantCultureIgnoreCase));

            if (string.IsNullOrEmpty(commandStruct.Name))
            {
                ConnectionHelper.SendChatMessage(sender, string.Format("Command {0} could not be found.", command.Name));
                return;
            }

            command.Name = commandStruct.Name;

            //update security first
            var i = Permissions.Commands.IndexOf(commandStruct);
            commandStruct.NeededLevel = command.NeededLevel;
            Permissions.Commands[i] = commandStruct;

            //then send changes
            List<IMyPlayer> players = new List<IMyPlayer>();
            MyAPIGateway.Players.GetPlayers(players, p => p != null);
            foreach (IMyPlayer player in players)
            {
                var playerPermission = Permissions.Players.FirstOrDefault(p => p.Player.SteamId == player.SteamUserId);

                if (playerPermission.Player.SteamId == 0)
                {
                    //no player found -> send changes
                    SendPermissionChange(player.SteamUserId, commandStruct);
                    continue;
                }

                //don't send changes to players with exeptional permissions
                if (playerPermission.Extensions.Any(s => s.Equals(commandStruct.Name)) || playerPermission.Restrictions.Any(s => s.Equals(commandStruct.Name)))
                    continue;

                SendPermissionChange(player.SteamUserId, commandStruct);
            }

            ConnectionHelper.SendChatMessage(sender, string.Format("The level of command {0} was set to {1}.", commandStruct.Name, commandStruct.NeededLevel));

            SavePermissionFile();
        }
 public void SendPermissionChange(ulong steamId, CommandStruct commandStruct)
 {
     ConnectionHelper.SendMessageToPlayer(steamId, ConnectionHelper.ConnectionKeys.CommandLevel, string.Format("{0}:{1}", commandStruct.Name, commandStruct.NeededLevel));
 }