internal static void Load() { if (File.Exists(Paths.IPBanListFileName)) { string headerText; using (StreamReader reader = File.OpenText(Paths.IPBanListFileName)) { headerText = reader.ReadLine(); // header if (headerText == null) { Logger.Log("IPBanList.Load: IP ban file is empty.", LogType.Warning); } int version = ParseHeader(headerText); while (!reader.EndOfStream) { string[] fields = reader.ReadLine().Split(','); if (fields.Length == IPBanInfo.FieldCount) { try { IPBanInfo ban; if (version == 0) { ban = IPBanInfo.LoadOldFormat(fields, true); } else { ban = IPBanInfo.Load(fields); } if (ban.Address.Equals(IPAddress.Any) || ban.Address.Equals(IPAddress.None)) { Logger.Log("IPBanList.Load: Invalid IP address skipped.", LogType.Warning); } else { Bans.Add(ban.Address.ToString(), ban); } } catch (IOException ex) { Logger.Log("IPBanList.Load: Error while trying to read from file: {0}", LogType.Error, ex.Message); } catch (Exception ex) { Logger.Log("IPBanList.Load: Could not parse a record: {0}", LogType.Error, ex.Message); } } else { Logger.Log("IPBanList.Load: Corrupt record skipped ({0} fields instead of {1}): {2}", LogType.Error, fields.Length, IPBanInfo.FieldCount, String.Join(",", fields)); } } if (version == 0) { Logger.Log("IPBanList.Load: Attempting to recover IP bans...", LogType.SystemActivity); int oldBanCount = Bans.Count; PlayerDB.RecoverIPBans(); Logger.Log("IPBanList.Load: {0} IP bans recovered.", LogType.SystemActivity, Bans.Count - oldBanCount); } } Logger.Log("IPBanList.Load: Done loading IP ban list ({0} records).", LogType.Debug, Bans.Count); } else { Logger.Log("IPBanList.Load: No IP ban file found.", LogType.Warning); } IsLoaded = true; }