public async Task <bool> BanAsync(IUser user, IUser bannedBy = null, string reason = null, TimeSpan?duration = null)
        {
            UserBanEvent @event = new UserBanEvent(user, bannedBy, reason, duration, true);

            eventManager.Emit(host, @event);
            if (@event.IsCancelled)
            {
                return(false);
            }

            var callerId = (bannedBy is UnturnedUser up) ? up.CSteamID : CSteamID.Nil;

            //if (user.IsOnline)
            //{
            //    SteamBlacklist.ban(player.CSteamID, 0, callerId, reason, (uint)(duration?.TotalSeconds ?? uint.MaxValue));
            //    return true;
            //}

            var steamId = new CSteamID(ulong.Parse(user.Id));

            SteamBlacklist.ban(steamId, 0, callerId, reason, (uint)(duration?.TotalSeconds ?? uint.MaxValue));

            var target = ((UnturnedUser)user).Player;

            if (target.IsOnline)
            {
                Provider.kick(steamId, reason);
            }

            return(true);
        }
示例#2
0
        /// <inheritdoc />
        public bool Ban(IUserInfo player, IUser caller, string reason, TimeSpan?timeSpan = null)
        {
            if (player == null)
            {
                throw new ArgumentNullException(nameof(player));
            }

            if (string.IsNullOrWhiteSpace(player.Id))
            {
                throw new ArgumentException("The argument has invalid members.", nameof(player));
            }

            if (reason == null)
            {
                reason = string.Empty;
            }

            UserBanEvent e = new UserBanEvent(player, caller, reason, null);

            container.Resolve <IEventBus>().Emit(container.Resolve <IHost>(), e);

            if (e.IsCancelled)
            {
                return(false);
            }

            if (player is EcoPlayerUser ecoUser)
            {
                bool bothSucceed = false;

                if (ecoUser.Player.UserIdType == UserIdType.Both)
                {
                    bothSucceed = AddBanBlacklist(ecoUser.Player.InternalEcoUser.SteamId);
                }

                if (!AddBanBlacklist(ecoUser.Id) && !bothSucceed)
                {
                    return(false);
                }

                UserManager.Obj.SaveConfig();

                if (ecoUser.IsOnline)
                {
                    ecoUser.Player.InternalEcoUser.Client.Disconnect("You have been banned.", reason);
                }
            }
            else
            {
                if (!AddBanBlacklist(player.Id))
                {
                    return(false);
                }

                UserManager.Obj.SaveConfig();
            }

            return(true);
        }