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 );
}
}
}
}