Exemple #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)
        {
            var todelUserLevel = _users.GetUserLevel(Helpers.GetArgVal(c, 1));
            var result         = _users.DeleteUserFromDb(Helpers.GetArgVal(c, 1), c.FromUser,
                                                         _users.GetUserLevel(c.FromUser));

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

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

                // de-op
                if (!_sst.IsMonitoringServer)
                {
                    return(true);
                }
                if (!_sst.ServerInfo.CurrentPlayers.ContainsKey(Helpers.GetArgVal(c, 1)))
                {
                    return(true);
                }
                var id = _sst.ServerEventProcessor.GetPlayerId(Helpers.GetArgVal(c, 1));
                if (id != -1)
                {
                    // doesn't matter if not opped, since QL shows no error message
                    await _sst.QlCommands.SendToQlAsync(string.Format("deop {0}", id), false);
                }

                return(true);
            }

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

            return(false);
        }