Beispiel #1
0
        /// <summary>
        /// Executes the specified command asynchronously.
        /// </summary>
        /// <param name="c">The command argument information.</param>
        /// <returns><c>true</c> if the command was successfully executed, otherwise <c>false</c>.</returns>
        public async Task <bool> ExecAsync(Cmd c)
        {
            if (!Helpers.GetArgVal(c, 2).Equals("1") && !Helpers.GetArgVal(c, 2).Equals("2") &&
                !Helpers.GetArgVal(c, 2).Equals("3"))
            {
                await DisplayArgLengthError(c);

                return(false);
            }
            if ((Helpers.GetArgVal(c, 2).Equals("3")))
            {
                var userLevel = IsIrcOwner(c) ? UserLevel.Owner : _users.GetUserLevel(c.FromUser);
                if (userLevel != UserLevel.Owner)
                {
                    StatusMessage = "^1[ERROR]^3 Only owners can add admins.";
                    await SendServerTell(c, StatusMessage);

                    Log.Write(string.Format("Non-owner {0} attempted to add an admin from {1} Ignoring.",
                                            c.FromUser, ((c.FromIrc) ? "IRC." : "in-game.")), _logClassType, _logPrefix);

                    return(false);
                }
            }
            var date   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            var result = _users.AddUserToDb(Helpers.GetArgVal(c, 1),
                                            (UserLevel)Convert.ToInt32(Helpers.GetArgVal(c, 2)), c.FromUser,
                                            date);

            if (result == UserDbResult.Success)
            {
                StatusMessage = string.Format("^2[SUCCESS]^7 Added user^2 {0} ^7to the ^2[{1}] ^7group.",
                                              Helpers.GetArgVal(c, 1), (UserLevel)Convert.ToInt32(Helpers.GetArgVal(c, 2)));
                await SendServerSay(c, StatusMessage);

                // UI: reflect changes
                _sst.UserInterface.RefreshCurrentSstUsersDataSource();

                // Auto-op if necessary
                if ((UserLevel)Convert.ToInt32(Helpers.GetArgVal(c, 2)) > UserLevel.SuperUser)
                {
                    await _sst.ServerEventProcessor.AutoOpActiveAdmin(Helpers.GetArgVal(c, 1));
                }

                return(true);
            }

            StatusMessage = string.Format(
                "^1[ERROR]^3 Unable to add user ^1{0}^3 to the ^1[{1}] ^3group. Code:^1 {2}",
                Helpers.GetArgVal(c, 1), (UserLevel)Convert.ToInt32(Helpers.GetArgVal(c, 2)), result);
            await SendServerTell(c, StatusMessage);

            return(false);
        }