public void UnbanAll( [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, Permission.BanAll ) ) {
PlayerOpException.ThrowPermissionMissing( player, this, "unban-all",
Permission.Ban, Permission.BanIP, Permission.BanAll );
}
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, "unban-all" );
}
// 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 );
}
PlayerOpException.CheckBanReason( reason, player, this, true );
bool somethingGotUnbanned = false;
// Unban the IP
if ( IPBanList.Contains( address ) ) {
if ( IPBanList.Remove( address, raiseEvents ) ) {
Logger.Log( LogType.UserActivity,
"{0} unbanned {1} (UnbanAll {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 );
}
somethingGotUnbanned = true;
}
}
// Unban individual players
PlayerInfo[] allPlayersOnIP = PlayerDB.FindPlayers( address );
foreach ( PlayerInfo targetAlt in allPlayersOnIP ) {
if ( targetAlt.BanStatus != BanStatus.Banned )
continue;
// Raise PlayerInfo.BanChanging event
PlayerInfoBanChangingEventArgs e = new PlayerInfoBanChangingEventArgs( targetAlt, player, true, reason, announce );
if ( raiseEvents ) {
RaiseBanChangingEvent( e );
if ( e.Cancel )
continue;
reason = e.Reason;
}
// Do the ban
if ( targetAlt.ProcessUnban( player.Name, reason ) ) {
if ( raiseEvents ) {
RaiseBanChangedEvent( e );
}
// Log and announce ban
Logger.Log( LogType.UserActivity,
"{0} unbanned {1} (UnbanAll {2}). Reason: {3}",
player.Name, targetAlt.Name, Name, reason ?? "" );
if ( announce ) {
if ( targetAlt == this ) {
Server.Message( "&WPlayer {0}&W was unbanned by {1}&W (UnbanAll)",
targetAlt.ClassyName, player.ClassyName );
} else {
Server.Message( "&WPlayer {0}&W was unbanned by {1}&W by association with {2}",
targetAlt.ClassyName, player.ClassyName, ClassyName );
}
}
somethingGotUnbanned = true;
}
}
// If no one ended up getting unbanned, quit here
if ( !somethingGotUnbanned ) {
PlayerOpException.ThrowNoOneToUnban( player, this, address );
}
// Announce UnbanAll reason towards the end of all unbans
if ( announce && ConfigKey.AnnounceKickAndBanReasons.Enabled() && reason != null ) {
Server.Message( "&WUnbanAll reason: {0}", reason );
}
}
}