public static bool HasMorePerm(NetworkUser sender, NetworkUser target, ConCommandArgs args)
        {
            var senderElevationLevel = sender ? sender.GetPermissionLevel() : PermissionLevel.Admin + 1; // +1 for server console
            var targetElevationLevel = target.GetPermissionLevel();

            if (senderElevationLevel < targetElevationLevel)
            {
                Log.MessageNetworked(string.Format(Lang.PS_ARGUSER_HAS_MORE_PERM, target.userName), args, Log.LogLevel.Error);
                return(false);
            }

            if (senderElevationLevel == targetElevationLevel)
            {
                Log.MessageNetworked(string.Format(Lang.PS_ARGUSER_HAS_SAME_PERM, target.userName), args, Log.LogLevel.Error);
                return(false);
            }

            return(true);
        }
Example #2
0
        public static bool CanUserExecute(NetworkUser networkUser, string conCommandName, List <string> userArgs)
        {
            if (AdminCommands.TryGetValue(conCommandName, out var requiredLevel))
            {
                var userLevel = networkUser.GetPermissionLevel();

                if (userLevel >= requiredLevel.Value)
                {
                    return(true);
                }

                var conCommandArgs = new ConCommandArgs
                {
                    commandName = conCommandName,
                    sender      = networkUser,
                    userArgs    = userArgs
                };

                Log.MessageNetworked(string.Format(Lang.PS_NO_REQUIRED_LEVEL, requiredLevel.Value.ToString()), conCommandArgs);
                return(false);
            }

            return(true);
        }