fCraft.PlayerInfo.UnbanIP C# (CSharp) Метод

UnbanIP() публичный Метод

Unbans given player and their IP address. Throws PlayerOpException on problems.
public UnbanIP ( [ player, [ reason, bool announce, bool raiseEvents ) : void
player [ Player who is unbanning.
reason [ Reason for unban. May be empty, if permitted by server configuration.
announce bool Whether unban should be publicly announced on the server.
raiseEvents bool Whether RemovingIPBan, RemovedIPBan, /// BanChanging, and BanChanged events should be raised.
Результат void
        public void UnbanIP( [NotNull] Player player, [CanBeNull] string reason, bool announce, bool raiseEvents )
        {
            if ( player == null )
                throw new ArgumentNullException( "player" );
            if ( reason != null && reason.Trim().Length == 0 )
                reason = null;
            lock ( actionLock ) {
                if ( !player.Can( Permission.Ban, Permission.BanIP ) ) {
                    PlayerOpException.ThrowPermissionMissing( player, this, "IP-unban", Permission.Ban, Permission.BanIP );
                }

                IPAddress address = LastIP;

                // Check if player is trying to unban self
                if ( player.Info == this || address.Equals( player.IP ) && !player.IsSuper ) {
                    PlayerOpException.ThrowCannotTargetSelf( player, this, "IP-unban" );
                }

                // Check if a non-bannable address was given (0.0.0.0 or 255.255.255.255)
                if ( address.Equals( IPAddress.None ) || address.Equals( IPAddress.Any ) ) {
                    PlayerOpException.ThrowInvalidIP( player, this, address );
                }

                // Check existing unban statuses
                bool needNameUnban = IsBanned;
                bool needIPUnban = ( IPBanList.Get( address ) != null );
                if ( !needIPUnban && !needNameUnban ) {
                    PlayerOpException.ThrowPlayerAndIPNotBanned( player, this, address );
                }

                PlayerOpException.CheckBanReason( reason, player, this, true );

                // Unban the name
                if ( needNameUnban ) {
                    Unban( player, reason, announce, raiseEvents );
                }

                // Unban the IP
                if ( needIPUnban ) {
                    if ( IPBanList.Remove( address, raiseEvents ) ) {
                        Logger.Log( LogType.UserActivity,
                                    "{0} unbanned {1} (UnbanIP {2}). Reason: {3}",
                                    player.Name, address, Name, reason ?? "" );

                        // Announce unban on the server
                        if ( announce ) {
                            var can = Server.Players.Can( Permission.ViewPlayerIPs );
                            can.Message( "&WPlayer {0}&W was IP-unbanned ({1}) by {2}",
                                         ClassyName, address, player.ClassyName );
                            var cant = Server.Players.Cant( Permission.ViewPlayerIPs );
                            cant.Message( "&WPlayer {0}&W was IP-unbanned by {1}",
                                          ClassyName, player.ClassyName );
                            if ( ConfigKey.AnnounceKickAndBanReasons.Enabled() && reason != null ) {
                                Server.Message( "&WUnbanIP reason: {0}", reason );
                            }
                        }
                    } else {
                        PlayerOpException.ThrowPlayerAndIPNotBanned( player, this, address );
                    }
                }
            }
        }