internal static void BanInfoHandler( Player player, Command cmd )
{
string name = cmd.Next();
if ( cmd.HasNext ) {
CdBanInfo.PrintUsage( player );
return;
}
IPAddress address;
PlayerInfo info = null;
if ( name == null ) {
name = player.Name;
} else if ( !player.Can( Permission.ViewOthersInfo ) ) {
player.MessageNoAccess( Permission.ViewOthersInfo );
return;
}
if ( Server.IsIP( name ) && IPAddress.TryParse( name, out address ) ) {
IPBanInfo banInfo = IPBanList.Get( address );
if ( banInfo != null ) {
player.Message( "{0} was banned by {1}&S on {2:dd MMM yyyy} ({3} ago)",
banInfo.Address,
banInfo.BannedByClassy,
banInfo.BanDate,
banInfo.TimeSinceLastAttempt );
if ( !String.IsNullOrEmpty( banInfo.PlayerName ) ) {
player.Message( " Banned by association with {0}",
banInfo.PlayerNameClassy );
}
if ( banInfo.Attempts > 0 ) {
player.Message( " There have been {0} attempts to log in, most recently {1} ago by {2}",
banInfo.Attempts,
banInfo.TimeSinceLastAttempt.ToMiniString(),
banInfo.LastAttemptNameClassy );
}
if ( banInfo.BanReason != null ) {
player.Message( " Ban reason: {0}", banInfo.BanReason );
}
} else {
player.Message( "{0} is currently NOT banned.", address );
}
} else {
info = PlayerDB.FindPlayerInfoOrPrintMatches( player, name );
if ( info == null )
return;
address = info.LastIP;
IPBanInfo ipBan = IPBanList.Get( info.LastIP );
switch ( info.BanStatus ) {
case BanStatus.Banned:
if ( ipBan != null ) {
player.Message( "Player {0}&S and their IP are &CBANNED", info.ClassyName );
} else {
player.Message( "Player {0}&S is &CBANNED&S (but their IP is not).", info.ClassyName );
}
break;
case BanStatus.IPBanExempt:
if ( ipBan != null ) {
player.Message( "Player {0}&S is exempt from an existing IP ban.", info.ClassyName );
} else {
player.Message( "Player {0}&S is exempt from IP bans.", info.ClassyName );
}
break;
case BanStatus.NotBanned:
if ( ipBan != null ) {
player.Message( "Player {0}&s is not banned, but their IP is.", info.ClassyName );
} else {
player.Message( "Player {0}&s is not banned.", info.ClassyName );
}
break;
}
if ( info.BanDate != DateTime.MinValue ) {
player.Message( " Last ban by {0}&S on {1:dd MMM yyyy} ({2} ago).",
info.BannedByClassy,
info.BanDate,
info.TimeSinceBan.ToMiniString() );
if ( info.BanReason != null ) {
player.Message( " Last ban reason: {0}", info.BanReason );
}
} else {
player.Message( "No past bans on record." );
}
if ( info.UnbanDate != DateTime.MinValue && !info.IsBanned ) {
player.Message( " Unbanned by {0}&S on {1:dd MMM yyyy} ({2} ago).",
info.UnbannedByClassy,
info.UnbanDate,
info.TimeSinceUnban.ToMiniString() );
if ( info.UnbanReason != null ) {
player.Message( " Last unban reason: {0}", info.UnbanReason );
}
}
if ( info.BanDate != DateTime.MinValue ) {
TimeSpan banDuration;
if ( info.IsBanned ) {
banDuration = info.TimeSinceBan;
player.Message( " Ban duration: {0} so far",
banDuration.ToMiniString() );
} else {
banDuration = info.UnbanDate.Subtract( info.BanDate );
player.Message( " Previous ban's duration: {0}",
banDuration.ToMiniString() );
}
}
}
// Show alts
List<PlayerInfo> altNames = new List<PlayerInfo>();
int bannedAltCount = 0;
foreach ( PlayerInfo playerFromSameIP in PlayerDB.FindPlayers( address ) ) {
if ( playerFromSameIP == info )
continue;
altNames.Add( playerFromSameIP );
if ( playerFromSameIP.IsBanned ) {
bannedAltCount++;
}
}
if ( altNames.Count > 0 ) {
altNames.Sort( new PlayerInfoComparer( player ) );
if ( altNames.Count > MaxAltsToPrint ) {
if ( bannedAltCount > 0 ) {
player.MessagePrefixed( "&S ",
"&S Over {0} accounts ({1} banned) on IP: {2} &Setc",
MaxAltsToPrint,
bannedAltCount,
altNames.Take( 15 ).ToArray().JoinToClassyString() );
} else {
player.MessagePrefixed( "&S ",
"&S Over {0} accounts on IP: {1} &Setc",
MaxAltsToPrint,
altNames.Take( 15 ).ToArray().JoinToClassyString() );
}
} else {
if ( bannedAltCount > 0 ) {
player.MessagePrefixed( "&S ",
"&S {0} accounts ({1} banned) on IP: {2}",
altNames.Count,
bannedAltCount,
altNames.ToArray().JoinToClassyString() );
} else {
player.MessagePrefixed( "&S ",
"&S {0} accounts on IP: {1}",
altNames.Count,
altNames.ToArray().JoinToClassyString() );
}
}
}
}