PlayerInfo LoadFormat2( [NotNull] string[] fields ) {
if( fields == null ) throw new ArgumentNullException( "fields" );
int id = Int32.Parse( fields[29] );
if( id < 256 ) id = GetNextID();
PlayerInfo info = new PlayerInfo( id ) {
Name = fields[0]
};
if( fields[1].Length > 0 ) {
IPAddress lastIP;
IPAddress.TryParse( fields[1], out lastIP );
info.LastIP = lastIP;
}
info.Rank = Rank.Parse( fields[2] ) ?? RankManager.DefaultRank;
DateTime tempDate;
fields[3].ToDateTime( out tempDate );
info.RankChangeDate = tempDate;
if( fields[4].Length > 0 ) info.RankChangedBy = fields[4];
switch( fields[5] ) {
case "b":
info.BanStatus = BanStatus.Banned;
break;
case "x":
info.BanStatus = BanStatus.BanExempt;
break;
default:
info.BanStatus = BanStatus.NotBanned;
break;
}
// ban information
if( fields[6].ToDateTime( out tempDate ) ) {
if( fields[7].Length > 0 ) info.BannedBy = Unescape( fields[7] );
if( fields[10].Length > 0 ) info.BanReason = Unescape( fields[10] );
}
info.BanDate = tempDate;
// unban information
if( fields[8].ToDateTime( out tempDate ) ) {
if( fields[9].Length > 0 ) info.UnbannedBy = Unescape( fields[9] );
if( fields[11].Length > 0 ) info.UnbanReason = Unescape( fields[11] );
}
info.UnbanDate = tempDate;
// failed logins
DateTime lastFailedLoginDate;
fields[12].ToDateTime( out lastFailedLoginDate );
info.LastFailedLoginDate = lastFailedLoginDate;
if( fields[13].Length > 1 ) {
IPAddress lastFailedLoginIP;
if (IPAddress.TryParse(fields[13], out lastFailedLoginIP)) {
info.LastFailedLoginIP = lastFailedLoginIP;
}
}
// skip 14
// login/logout dates
TimeSpan totalTime;
fields[15].ToDateTime( out tempDate );
info.FirstLoginDate = tempDate;
fields[16].ToDateTime( out tempDate );
info.LastLoginDate = tempDate;
fields[17].ToTimeSpan( out totalTime );
info.TotalTime = totalTime;
// stats
int tempInt;
if( fields[18].Length > 0 ) {
Int32.TryParse( fields[18], out tempInt );
info.BlocksBuilt = tempInt;
}
if( fields[19].Length > 0 ) {
Int32.TryParse( fields[19], out tempInt );
info.BlocksDeleted = tempInt;
}
Int32.TryParse( fields[20], out tempInt );
info.TimesVisited = tempInt;
if( fields[20].Length > 0 ) {
Int32.TryParse( fields[21], out tempInt );
info.MessagesWritten = tempInt;
}
// fields 22-23 are no longer in use
if( fields[24].Length > 0 ) info.PreviousRank = Rank.Parse( fields[24] );
if( fields[25].Length > 0 ) info.RankChangeReason = Unescape( fields[25] );
Int32.TryParse( fields[26], out tempInt );
info.TimesKicked = tempInt;
Int32.TryParse( fields[27], out tempInt );
info.TimesKickedOthers = tempInt;
Int32.TryParse( fields[28], out tempInt );
info.TimesBannedOthers = tempInt;
// fields[29] is ID, read above
byte rankChangeTypeCode;
if( Byte.TryParse( fields[30], out rankChangeTypeCode ) ) {
info.RankChangeType = (RankChangeType)rankChangeTypeCode;
if( !Enum.IsDefined( typeof( RankChangeType ), rankChangeTypeCode ) ) {
GuessRankChangeType( info );
}
} else {
GuessRankChangeType( info );
}
fields[31].ToDateTime( out tempDate );
info.LastKickDate = tempDate;
if( !fields[32].ToDateTime( out tempDate ) ) {
tempDate = info.LastLoginDate;
}
info.LastSeen = tempDate;
long blocksDrawn;
Int64.TryParse( fields[33], out blocksDrawn );
info.BlocksDrawn = blocksDrawn;
if( fields[34].Length > 0 ) info.LastKickBy = Unescape( fields[34] );
if( fields[35].Length > 0 ) info.LastKickReason = Unescape( fields[35] );
fields[36].ToDateTime( out tempDate );
info.BannedUntil = tempDate;
info.IsFrozen = (fields[37] == "f");
if( fields[38].Length > 0 ) info.FrozenBy = Unescape( fields[38] );
fields[39].ToDateTime( out tempDate );
info.FrozenOn = tempDate;
fields[40].ToDateTime( out tempDate );
info.MutedUntil = tempDate;
if( fields[41].Length > 0 ) info.MutedBy = Unescape( fields[41] );
info.Password = Unescape( fields[42] );
// fields[43] is "online", and is ignored
ParseBandwidthUseMode( info, fields[44] );
if( fields.Length > 45 ) {
if( fields[45].Length == 0 ) {
info.IsHidden = false;
} else {
info.IsHidden = info.Rank.Can( Permission.Hide );
}
}
if( fields.Length > 46 ) {
DateTime tempLastModified;
fields[46].ToDateTime( out tempLastModified );
info.LastModified = tempLastModified;
}
if( fields.Length > 47 && fields[47].Length > 0 ) {
info.DisplayedName = Unescape( fields[47] );
}
if( info.LastLoginDate < info.FirstLoginDate ) {
info.LastLoginDate = info.FirstLoginDate;
}
if( info.LastSeen < info.LastLoginDate ) {
info.LastSeen = info.LastLoginDate;
}
return info;
}