public static TryParseDateTime ( long timestamp ) : System.DateTime | ||
timestamp | long | |
return | System.DateTime |
internal static IPBanInfo LoadFormat2([NotNull] string[] fields) { 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.Unescape(fields[1]) }; DateTimeUtil.TryParseDateTime(fields[2], ref info.BanDate); if (fields[3].Length > 0) { info.BanReason = PlayerDB.Unescape(fields[3]); } if (fields[4].Length > 0) { info.PlayerName = PlayerDB.Unescape(fields[4]); } Int32.TryParse(fields[5], out info.Attempts); info.LastAttemptName = PlayerDB.Unescape(fields[6]); if (info.LastAttemptName.Length == 0) { info.LastAttemptName = null; } DateTimeUtil.TryParseDateTime(fields[7], ref info.LastAttemptDate); return(info); }
public Zone(NbtCompound tag) { NbtCompound boundsTag = tag.Get <NbtCompound>("Bounds"); if (boundsTag == null) { throw new SerializationException("Bounds missing from zone definition tag."); } Bounds = new BoundingBox(boundsTag); NbtCompound controllerTag = tag.Get <NbtCompound>("Controller"); if (controllerTag == null) { throw new SerializationException("Controller missing from zone definition tag."); } Controller = new SecurityController(controllerTag); var createdByTag = tag.Get <NbtString>("CreatedBy"); var createdDateTag = tag.Get <NbtLong>("CreatedDate"); if (createdByTag != null && createdDateTag != null) { CreatedBy = createdByTag.Value; CreatedDate = DateTimeUtil.TryParseDateTime(createdDateTag.Value); } var editedByTag = tag.Get <NbtString>("EditedBy"); var editedDateTag = tag.Get <NbtLong>("EditedDate"); if (editedByTag != null && editedDateTag != null) { EditedBy = editedByTag.Value; EditedDate = DateTimeUtil.TryParseDateTime(editedDateTag.Value); } }
static void LoadWorldListEntry([NotNull] XElement el) { if (el == null) { throw new ArgumentNullException("el"); } XAttribute tempAttr; if ((tempAttr = el.Attribute("name")) == null) { Logger.Log(LogType.Error, "WorldManager: World tag with no name skipped."); return; } string worldName = tempAttr.Value; bool neverUnload = (el.Attribute("noUnload") != null); World world; try { world = AddWorld(null, worldName, null, neverUnload); } catch (WorldOpException ex) { Logger.Log(LogType.Error, "WorldManager: Error adding world \"{0}\": {1}", worldName, ex.Message); return; } if ((tempAttr = el.Attribute("hidden")) != null) { bool isHidden; if (Boolean.TryParse(tempAttr.Value, out isHidden)) { world.IsHidden = isHidden; } else { Logger.Log(LogType.Warning, "WorldManager: Could not parse \"hidden\" attribute of world \"{0}\", assuming NOT hidden.", worldName); } } if (firstWorld == null) { firstWorld = world; } XElement tempEl = el.Element("Greeting"); if (tempEl != null && !String.IsNullOrEmpty(tempEl.Value)) { world.Greeting = tempEl.Value; } if ((tempEl = el.Element(AccessSecurityXmlTagName)) != null) { world.AccessSecurity = new SecurityController(tempEl, true); } else if ((tempEl = el.Element("accessSecurity")) != null) { world.AccessSecurity = new SecurityController(tempEl, true); } if ((tempEl = el.Element(BuildSecurityXmlTagName)) != null) { world.BuildSecurity = new SecurityController(tempEl, true); } else if ((tempEl = el.Element("buildSecurity")) != null) { world.BuildSecurity = new SecurityController(tempEl, true); } // load backup settings if ((tempAttr = el.Attribute("backup")) != null) { TimeSpan backupInterval; if (DateTimeUtil.TryParseTimeSpan(tempAttr.Value, out backupInterval)) { if (backupInterval <= TimeSpan.Zero) { world.BackupEnabledState = YesNoAuto.No; } else { world.BackupInterval = backupInterval; } } else { world.BackupEnabledState = YesNoAuto.Auto; Logger.Log(LogType.Warning, "WorldManager: Could not parse \"backup\" attribute of world \"{0}\", assuming default ({1}).", worldName, world.BackupInterval.ToMiniString()); } } else { world.BackupEnabledState = YesNoAuto.Auto; } // load BlockDB settings XElement blockEl = el.Element(BlockDB.XmlRootName); if (blockEl != null) { world.BlockDB.LoadSettings(blockEl); } // load environment settings XElement envEl = el.Element(EnvironmentXmlTagName); if (envEl != null) { if ((tempAttr = envEl.Attribute("cloud")) != null) { if (!Int32.TryParse(tempAttr.Value, out world.CloudColor)) { world.CloudColor = -1; Logger.Log(LogType.Warning, "WorldManager: Could not parse \"cloud\" attribute of Environment settings for world \"{0}\", assuming default (normal).", worldName); } } if ((tempAttr = envEl.Attribute("fog")) != null) { if (!Int32.TryParse(tempAttr.Value, out world.FogColor)) { world.FogColor = -1; Logger.Log(LogType.Warning, "WorldManager: Could not parse \"fog\" attribute of Environment settings for world \"{0}\", assuming default (normal).", worldName); } } if ((tempAttr = envEl.Attribute("sky")) != null) { if (!Int32.TryParse(tempAttr.Value, out world.SkyColor)) { world.SkyColor = -1; Logger.Log(LogType.Warning, "WorldManager: Could not parse \"sky\" attribute of Environment settings for world \"{0}\", assuming default (normal).", worldName); } } if ((tempAttr = envEl.Attribute("level")) != null) { if (!Int32.TryParse(tempAttr.Value, out world.EdgeLevel)) { world.EdgeLevel = -1; Logger.Log(LogType.Warning, "WorldManager: Could not parse \"level\" attribute of Environment settings for world \"{0}\", assuming default (normal).", worldName); } } if ((tempAttr = envEl.Attribute("edge")) != null) { Block block; if (Map.GetBlockByName(tempAttr.Value, false, out block)) { if (Map.GetEdgeTexture(block) == null) { world.EdgeBlock = Block.Water; Logger.Log(LogType.Warning, "WorldManager: Unacceptable blocktype given for \"edge\" attribute of Environment settings for world \"{0}\", assuming default (Water).", worldName); } else { world.EdgeBlock = block; } } else { world.EdgeBlock = Block.Water; Logger.Log(LogType.Warning, "WorldManager: Could not parse \"edge\" attribute of Environment settings for world \"{0}\", assuming default (Water).", worldName); } } } // load loaded/map-changed information long timestamp; tempEl = el.Element("LoadedBy"); if (tempEl != null) { world.LoadedBy = tempEl.Value; } tempEl = el.Element("LoadedOn"); if (tempEl != null && Int64.TryParse(tempEl.Value, out timestamp)) { world.LoadedOn = DateTimeUtil.TryParseDateTime(timestamp); } tempEl = el.Element("MapChangedBy"); if (tempEl != null) { world.MapChangedBy = tempEl.Value; } tempEl = el.Element("MapChangedOn"); if (tempEl != null && Int64.TryParse(tempEl.Value, out timestamp)) { world.MapChangedOn = DateTimeUtil.TryParseDateTime(timestamp); } // load lock information if ((tempAttr = el.Attribute("locked")) != null) { bool isLocked; if (Boolean.TryParse(tempAttr.Value, out isLocked)) { world.IsLocked = isLocked; } tempEl = el.Element("LockedBy"); if (tempEl != null) { world.LockedBy = tempEl.Value; } tempEl = el.Element("LockedOn"); if (tempEl != null && Int64.TryParse(tempEl.Value, out timestamp)) { world.LockedOn = DateTimeUtil.TryParseDateTime(timestamp); } } else { tempEl = el.Element("UnlockedBy"); if (tempEl != null) { world.UnlockedBy = tempEl.Value; } tempEl = el.Element("UnlockedOn"); if (tempEl != null && Int64.TryParse(tempEl.Value, out timestamp)) { world.UnlockedOn = DateTimeUtil.TryParseDateTime(timestamp); } } foreach (XElement mainedRankEl in el.Elements(RankMainXmlTagName)) { Rank rank = Rank.Parse(mainedRankEl.Value); if (rank != null) { if (rank < world.AccessSecurity.MinRank) { world.AccessSecurity.MinRank = rank; Logger.Log(LogType.Warning, "WorldManager: Lowered access MinRank of world {0} to allow it to be the main world for that rank.", rank.Name); } rank.MainWorld = world; } } CheckMapFile(world); }
/// <summary> Checks fCraft.net for updated versions of fCraft. </summary> public static UpdaterResult CheckForUpdates() { UpdaterMode mode = ConfigKey.UpdaterMode.GetEnum <UpdaterMode>(); if (mode == UpdaterMode.Disabled) { return(UpdaterResult.NoUpdate); } string url = String.Format(UpdateUri, CurrentRelease.Revision); if (RaiseCheckingForUpdatesEvent(ref url)) { return(UpdaterResult.NoUpdate); } Logger.Log(LogType.SystemActivity, "Checking for fCraft updates..."); try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.CachePolicy = Server.CachePolicy; request.Method = "GET"; request.ReadWriteTimeout = (int)UpdateCheckTimeout.TotalMilliseconds; request.ServicePoint.BindIPEndPointDelegate = Server.BindIPEndPointCallback; request.Timeout = (int)UpdateCheckTimeout.TotalMilliseconds; request.UserAgent = UserAgent; using (WebResponse response = request.GetResponse()) { // ReSharper disable AssignNullToNotNullAttribute using (XmlTextReader reader = new XmlTextReader(response.GetResponseStream())) { // ReSharper restore AssignNullToNotNullAttribute XDocument doc = XDocument.Load(reader); XElement root = doc.Root; // ReSharper disable PossibleNullReferenceException if (root.Attribute("result").Value == "update") { string downloadUrl = root.Attribute("url").Value; var releases = new List <ReleaseInfo>(); foreach (XElement el in root.Elements("Release")) { releases.Add( new ReleaseInfo( Int32.Parse(el.Attribute("v").Value), Int32.Parse(el.Attribute("r").Value), DateTimeUtil.TryParseDateTime(Int64.Parse(el.Attribute("date").Value)), el.Element("Summary").Value, el.Element("ChangeLog").Value, ReleaseInfo.StringToReleaseFlags(el.Attribute("flags").Value) ) ); } // ReSharper restore PossibleNullReferenceException UpdaterResult result = new UpdaterResult((releases.Count > 0), new Uri(downloadUrl), releases.ToArray()); RaiseCheckedForUpdatesEvent(UpdateUri, result); return(result); } else { return(UpdaterResult.NoUpdate); } } } } catch (Exception ex) { Logger.Log(LogType.Error, "An error occurred while trying to check for updates: {0}: {1}", ex.GetType(), ex.Message); return(UpdaterResult.NoUpdate); } }
internal static PlayerInfo LoadFormat2(string[] fields) { if (fields.Length < 44) { throw new FormatException("PlayerInfo record did not contain all the expected information. " + "This record, or maybe the whole file, may be corrupted."); } 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.TryParseDateTime(fields[3], ref info.RankChangeDate); if (fields[4].Length > 0) { info.RankChangedBy = PlayerDB.Unescape(fields[4]); } 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.TryParseDateTime(fields[6], ref info.BanDate)) { if (fields[7].Length > 0) { info.BannedBy = PlayerDB.Unescape(fields[7]); } if (fields[10].Length > 0) { info.BanReason = PlayerDB.Unescape(fields[10]); } } // unban information if (DateTimeUtil.TryParseDateTime(fields[8], ref info.UnbanDate)) { if (fields[9].Length > 0) { info.UnbannedBy = PlayerDB.Unescape(fields[9]); } if (fields[11].Length > 0) { info.UnbanReason = PlayerDB.Unescape(fields[11]); } } // failed logins DateTimeUtil.TryParseDateTime(fields[12], ref info.LastFailedLoginDate); if (fields[13].Length > 1 || !IPAddress.TryParse(fields[13], out info.LastFailedLoginIP)) { // LEGACY info.LastFailedLoginIP = IPAddress.None; } // skip 14 DateTimeUtil.TryParseDateTime(fields[15], ref info.FirstLoginDate); // login/logout times DateTimeUtil.TryParseDateTime(fields[16], ref info.LastLoginDate); DateTimeUtil.TryParseTimeSpan(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[24].Length > 0) { info.PreviousRank = Rank.Parse(fields[24]); } if (fields[25].Length > 0) { info.RankChangeReason = PlayerDB.Unescape(fields[25]); } Int32.TryParse(fields[26], out info.TimesKicked); Int32.TryParse(fields[27], out info.TimesKickedOthers); Int32.TryParse(fields[28], out info.TimesBannedOthers); 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.TryParseDateTime(fields[31], ref info.LastKickDate); if (!DateTimeUtil.TryParseDateTime(fields[32], ref 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.Unescape(fields[34]); } if (fields[35].Length > 0) { info.LastKickReason = PlayerDB.Unescape(fields[35]); } DateTimeUtil.TryParseDateTime(fields[36], ref info.BannedUntil); info.IsFrozen = (fields[37] == "f"); if (fields[38].Length > 0) { info.FrozenBy = PlayerDB.Unescape(fields[38]); } DateTimeUtil.TryParseDateTime(fields[39], ref info.FrozenOn); DateTimeUtil.TryParseDateTime(fields[40], ref info.MutedUntil); if (fields[41].Length > 0) { info.MutedBy = PlayerDB.Unescape(fields[41]); } info.Password = PlayerDB.Unescape(fields[42]); // fields[43] is "online", and is ignored byte bandwidthUseModeCode; if (Byte.TryParse(fields[44], out bandwidthUseModeCode)) { info.BandwidthUseMode = (BandwidthUseMode)bandwidthUseModeCode; if (!Enum.IsDefined(typeof(BandwidthUseMode), bandwidthUseModeCode)) { info.BandwidthUseMode = BandwidthUseMode.Default; } } else { info.BandwidthUseMode = BandwidthUseMode.Default; } if (fields.Length > 45) { if (fields[45].Length == 0) { info.IsHidden = false; } else { info.IsHidden = info.Rank.Can(Permission.Hide); } } if (fields.Length > 46) { DateTimeUtil.TryParseDateTime(fields[46], ref info.LastModified); } if (fields.Length > 47 && fields[47].Length > 0) { info.DisplayedName = PlayerDB.Unescape(fields[47]); } if (fields.Length > 48) { byte accountTypeCode; if (Byte.TryParse(fields[48], out accountTypeCode)) { info.AccountType = (AccountType)accountTypeCode; if (!Enum.IsDefined(typeof(AccountType), accountTypeCode)) { info.AccountType = AccountType.Unknown; } } } if (fields.Length > 49) { if (fields[49].Length > 0) { info.Email = PlayerDB.Unescape(fields[49]); } } // date consistency checks if (info.LastSeen < info.FirstLoginDate) { info.LastSeen = info.FirstLoginDate; } if (info.LastLoginDate < info.FirstLoginDate) { info.LastLoginDate = info.FirstLoginDate; } return(info); }