示例#1
0
        internal static IPBanInfo LoadFormat0([NotNull] string[] fields, bool convertDatesToUtc)
        {
            if (fields == null)
            {
                throw new ArgumentNullException("fields");
            }
            if (fields.Length != 8)
            {
                throw new ArgumentException("Unexpected field count", "fields");
            }
            IPBanInfo info = new IPBanInfo {
                Address  = IPAddress.Parse(fields[0]),
                BannedBy = PlayerDB.UnescapeOldFormat(fields[1])
            };

            DateTimeUtil.TryParseLocalDate(fields[2], out info.BanDate);
            info.BanReason = PlayerDB.UnescapeOldFormat(fields[3]);
            if (fields[4].Length > 1)
            {
                info.PlayerName = PlayerDB.UnescapeOldFormat(fields[4]);
            }

            info.Attempts        = Int32.Parse(fields[5]);
            info.LastAttemptName = PlayerDB.UnescapeOldFormat(fields[6]);
            if (info.LastAttemptName.Length == 0)
            {
                info.LastAttemptName = null;
            }
            DateTimeUtil.TryParseLocalDate(fields[7], out info.LastAttemptDate);

            if (convertDatesToUtc)
            {
                if (info.BanDate != DateTime.MinValue)
                {
                    info.BanDate = info.BanDate.ToUniversalTime();
                }
                if (info.LastAttemptDate != DateTime.MinValue)
                {
                    info.LastAttemptDate = info.LastAttemptDate.ToUniversalTime();
                }
            }

            return(info);
        }
示例#2
0
        internal static PlayerInfo LoadFormat0(string[] fields, bool convertDatesToUtc)
        {
            PlayerInfo info = new PlayerInfo {
                Name = fields[0]
            };

            if (fields[1].Length == 0 || !IPAddress.TryParse(fields[1], out info.LastIP))
            {
                info.LastIP = IPAddress.None;
            }

            info.Rank = Rank.Parse(fields[2]) ?? RankManager.DefaultRank;
            DateTimeUtil.TryParseLocalDate(fields[3], out info.RankChangeDate);
            if (fields[4].Length > 0)
            {
                info.RankChangedBy = fields[4];
                if (info.RankChangedBy == "-")
                {
                    info.RankChangedBy = null;
                }
            }

            switch (fields[5])
            {
            case "b":
                info.BanStatus = BanStatus.Banned;
                break;

            case "x":
                info.BanStatus = BanStatus.IPBanExempt;
                break;

            default:
                info.BanStatus = BanStatus.NotBanned;
                break;
            }

            // ban information
            if (DateTimeUtil.TryParseLocalDate(fields[6], out info.BanDate))
            {
                if (fields[7].Length > 0)
                {
                    info.BannedBy = fields[7];
                }
                if (fields[10].Length > 0)
                {
                    info.BanReason = PlayerDB.UnescapeOldFormat(fields[10]);
                    if (info.BanReason == "-")
                    {
                        info.BanReason = null;
                    }
                }
            }

            // unban information
            if (DateTimeUtil.TryParseLocalDate(fields[8], out info.UnbanDate))
            {
                if (fields[9].Length > 0)
                {
                    info.UnbannedBy = fields[9];
                }
                if (fields[11].Length > 0)
                {
                    info.UnbanReason = PlayerDB.UnescapeOldFormat(fields[11]);
                    if (info.UnbanReason == "-")
                    {
                        info.UnbanReason = null;
                    }
                }
            }

            // failed logins
            if (fields[12].Length > 1)
            {
                DateTimeUtil.TryParseLocalDate(fields[12], out info.LastFailedLoginDate);
            }
            if (fields[13].Length > 1 || !IPAddress.TryParse(fields[13], out info.LastFailedLoginIP))      // LEGACY
            {
                info.LastFailedLoginIP = IPAddress.None;
            }
            // skip 14

            // login/logout times
            DateTimeUtil.TryParseLocalDate(fields[15], out info.FirstLoginDate);
            DateTimeUtil.TryParseLocalDate(fields[16], out info.LastLoginDate);
            TimeSpan.TryParse(fields[17], out info.TotalTime);

            // stats
            if (fields[18].Length > 0)
            {
                Int32.TryParse(fields[18], out info.BlocksBuilt);
            }
            if (fields[19].Length > 0)
            {
                Int32.TryParse(fields[19], out info.BlocksDeleted);
            }
            Int32.TryParse(fields[20], out info.TimesVisited);
            if (fields[20].Length > 0)
            {
                Int32.TryParse(fields[21], out info.MessagesWritten);
            }
            // fields 22-23 are no longer in use

            if (fields.Length > MinFieldCount)
            {
                if (fields[24].Length > 0)
                {
                    info.PreviousRank = Rank.Parse(fields[24]);
                }
                if (fields[25].Length > 0)
                {
                    info.RankChangeReason = PlayerDB.UnescapeOldFormat(fields[25]);
                }
                Int32.TryParse(fields[26], out info.TimesKicked);
                Int32.TryParse(fields[27], out info.TimesKickedOthers);
                Int32.TryParse(fields[28], out info.TimesBannedOthers);
                if (fields.Length > 29)
                {
                    info.ID = Int32.Parse(fields[29]);
                    if (info.ID < 256)
                    {
                        info.ID = PlayerDB.GetNextID();
                    }
                    byte rankChangeTypeCode;
                    if (Byte.TryParse(fields[30], out rankChangeTypeCode))
                    {
                        info.RankChangeType = (RankChangeType)rankChangeTypeCode;
                        if (!Enum.IsDefined(typeof(RankChangeType), rankChangeTypeCode))
                        {
                            info.GuessRankChangeType();
                        }
                    }
                    else
                    {
                        info.GuessRankChangeType();
                    }
                    DateTimeUtil.TryParseLocalDate(fields[31], out info.LastKickDate);
                    if (!DateTimeUtil.TryParseLocalDate(fields[32], out info.LastSeen) || info.LastSeen < info.LastLoginDate)
                    {
                        info.LastSeen = info.LastLoginDate;
                    }
                    Int64.TryParse(fields[33], out info.BlocksDrawn);

                    if (fields[34].Length > 0)
                    {
                        info.LastKickBy = PlayerDB.UnescapeOldFormat(fields[34]);
                    }
                    if (fields[35].Length > 0)
                    {
                        info.LastKickReason = PlayerDB.UnescapeOldFormat(fields[35]);
                    }
                }
                else
                {
                    info.ID = PlayerDB.GetNextID();
                    info.GuessRankChangeType();
                    info.LastSeen = info.LastLoginDate;
                }

                if (fields.Length > 36)
                {
                    DateTimeUtil.TryParseLocalDate(fields[36], out info.BannedUntil);
                    info.IsFrozen = (fields[37] == "f");
                    if (fields[38].Length > 0)
                    {
                        info.FrozenBy = PlayerDB.UnescapeOldFormat(fields[38]);
                    }
                    DateTimeUtil.TryParseLocalDate(fields[39], out info.FrozenOn);
                    DateTimeUtil.TryParseLocalDate(fields[40], out info.MutedUntil);
                    if (fields[41].Length > 0)
                    {
                        info.MutedBy = PlayerDB.UnescapeOldFormat(fields[41]);
                    }
                    info.Password = PlayerDB.UnescapeOldFormat(fields[42]);
                    // fields[43] is "online", and is ignored
                }

                if (fields.Length > 44)
                {
                    if (fields[44].Length != 0)
                    {
                        info.BandwidthUseMode = (BandwidthUseMode)Int32.Parse(fields[44]);
                    }
                }
            }

            if (info.LastSeen < info.FirstLoginDate)
            {
                info.LastSeen = info.FirstLoginDate;
            }
            if (info.LastLoginDate < info.FirstLoginDate)
            {
                info.LastLoginDate = info.FirstLoginDate;
            }

            if (convertDatesToUtc)
            {
                if (info.RankChangeDate != DateTime.MinValue)
                {
                    info.RankChangeDate = info.RankChangeDate.ToUniversalTime();
                }
                if (info.BanDate != DateTime.MinValue)
                {
                    info.BanDate = info.BanDate.ToUniversalTime();
                }
                if (info.UnbanDate != DateTime.MinValue)
                {
                    info.UnbanDate = info.UnbanDate.ToUniversalTime();
                }
                if (info.LastFailedLoginDate != DateTime.MinValue)
                {
                    info.LastFailedLoginDate = info.LastFailedLoginDate.ToUniversalTime();
                }
                if (info.FirstLoginDate != DateTime.MinValue)
                {
                    info.FirstLoginDate = info.FirstLoginDate.ToUniversalTime();
                }
                if (info.LastLoginDate != DateTime.MinValue)
                {
                    info.LastLoginDate = info.LastLoginDate.ToUniversalTime();
                }
                if (info.LastKickDate != DateTime.MinValue)
                {
                    info.LastKickDate = info.LastKickDate.ToUniversalTime();
                }
                if (info.LastSeen != DateTime.MinValue)
                {
                    info.LastSeen = info.LastSeen.ToUniversalTime();
                }
                if (info.BannedUntil != DateTime.MinValue)
                {
                    info.BannedUntil = info.BannedUntil.ToUniversalTime();
                }
                if (info.FrozenOn != DateTime.MinValue)
                {
                    info.FrozenOn = info.FrozenOn.ToUniversalTime();
                }
                if (info.MutedUntil != DateTime.MinValue)
                {
                    info.MutedUntil = info.MutedUntil.ToUniversalTime();
                }
            }

            return(info);
        }