static DateTime ReadDate([NotNull] BinaryReader reader) { if (reader.ReadBoolean()) { return(DateTimeUtil.ToDateTime(reader.ReadUInt32())); } else { return(DateTime.MinValue); } }
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("worldOnlyChat")) != null) { bool worldOnlyChat; if (Boolean.TryParse(tempAttr.Value, out worldOnlyChat)) { world.WorldOnlyChat = worldOnlyChat; } else { Logger.Log(LogType.Warning, "WorldManager: Could not parse \"worldOnlyChat\" attribute of world \"{0}\", assuming NO world only chat.", worldName); } } if ((tempAttr = el.Attribute("realm")) != null) { if (tempAttr.Value == "yes") { world.IsRealm = true; } else { Logger.Log(LogType.Warning, "WorldManager: Could not parse \"realm\" attribute of world \"{0}\", assuming NOT a realm.", worldName); } } 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 ((tempAttr = el.Attribute("visitCount")) != null) { int vCount; if (Int32.TryParse(tempAttr.Value, out vCount)) { world.VisitCount = vCount; } else { Logger.Log(LogType.Warning, "WorldManager: Could not parse \"VisitCount\" attribute of world \"{0}\", assuming NO Visits.", worldName); } } if (firstWorld == null) { firstWorld = world; } XElement tempEl; 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); } if ((tempAttr = el.Attribute("backup")) != null) { TimeSpan backupInterval; if (tempAttr.Value.ToTimeSpan(out backupInterval)) { world.BackupInterval = backupInterval; } else { world.BackupInterval = World.DefaultBackupInterval; Logger.Log(LogType.Warning, "WorldManager: Could not parse \"backup\" attribute of world \"{0}\", assuming default({1}).", worldName, world.BackupInterval.ToMiniString()); } } else { world.BackupInterval = World.DefaultBackupInterval; } if ((tempEl = el.Element("Locked")) != null) { bool locked; if (Boolean.TryParse(tempEl.Value, out locked)) { world.IsLocked = locked; } else { Logger.Log(LogType.Warning, "WorldManager: Could not parse \"Locked\" attribute of world \"{0}\", assuming NOT locked.", worldName); } } if ((tempEl = el.Element("LockedBy")) != null) { world.LockedBy = tempEl.Value; } if ((tempEl = el.Element("LockedOn")) != null) { DateTime lockedOn = DateTime.UtcNow; if (DateTimeUtil.ToDateTime(tempEl.Value, ref lockedOn)) { world.LockedDate = lockedOn; } else { Logger.Log(LogType.Warning, "WorldManager: Could not parse \"LockedOn\" attribute of world \"{0}\", assuming NO lock time.", worldName); } } if ((tempEl = el.Element("UnlockedBy")) != null) { world.UnlockedBy = tempEl.Value; } if ((tempEl = el.Element("UnlockedOn")) != null) { DateTime unlockedOn = DateTime.UtcNow; if (DateTimeUtil.ToDateTime(tempEl.Value, ref unlockedOn)) { world.UnlockedDate = unlockedOn; } else { Logger.Log(LogType.Warning, "WorldManager: Could not parse \"UnlockedOn\" attribute of world \"{0}\", assuming NO unlock time.", worldName); } } XElement blockEl = el.Element(BlockDB.XmlRootName); if (blockEl != null) { world.BlockDB.LoadSettings(blockEl); } 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("terrain")) != null) { world.Terrain = envEl.Attribute("terrain").Value; } 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 = Map.GetBlockByName(tempAttr.Value); if (block == Block.Undefined) { world.EdgeBlock = Block.Water; Logger.Log(LogType.Warning, "WorldManager: Could not parse \"edge\" attribute of Environment settings for world \"{0}\", assuming default(Water).", worldName); } else { world.EdgeBlock = block; } } if ((tempAttr = envEl.Attribute("side")) != null) { Block block = Map.GetBlockByName(tempAttr.Value); if (block == Block.Undefined) { world.EdgeBlock = Block.Admincrete; Logger.Log(LogType.Warning, "WorldManager: Could not parse \"side\" attribute of Environment settings for world \"{0}\", assuming default(Admincrete).", worldName); } else { world.SideBlock = block; } } if ((tempAttr = envEl.Attribute("cloudCC")) != null) { world.CloudColor = System.Drawing.ColorTranslator.FromHtml(tempAttr.Value).ToArgb(); } if ((tempAttr = envEl.Attribute("fogCC")) != null) { world.FogColor = System.Drawing.ColorTranslator.FromHtml(tempAttr.Value).ToArgb(); } if ((tempAttr = envEl.Attribute("skyCC")) != null) { world.SkyColor = System.Drawing.ColorTranslator.FromHtml(tempAttr.Value).ToArgb(); } if ((tempAttr = envEl.Attribute("levelCC")) != null) { world.EdgeLevel = Convert.ToInt16(tempAttr.Value); } if ((tempAttr = envEl.Attribute("edgeCC")) != null) { world.EdgeBlock = (Block)Byte.Parse(tempAttr.Value); } if ((tempAttr = envEl.Attribute("sideCC")) != null) { world.SideBlock = (Block)Byte.Parse(tempAttr.Value); } if ((tempAttr = envEl.Attribute("textureCC")) != null) { world.textureURL = tempAttr.Value; } if ((tempAttr = envEl.Attribute("hacks")) != null) { world.Hax = Convert.ToBoolean(tempAttr.Value); } } 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); }
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.ToDateTime(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.ToDateTime(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.ToDateTime(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.ToDateTime(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); }
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.ToDateTime(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); } }
PlayerInfo LoadBinaryFormat0([NotNull] BinaryReader reader) { if (reader == null) { throw new ArgumentNullException("reader"); } int id = Read7BitEncodedInt(reader); // ReSharper disable UseObjectOrCollectionInitializer PlayerInfo info = new PlayerInfo(id); // ReSharper restore UseObjectOrCollectionInitializer // General info.Name = reader.ReadString(); info.DisplayedName = ReadString(reader); info.LastSeen = DateTimeUtil.ToDateTime(reader.ReadUInt32()); // Rank int rankIndex = Read7BitEncodedInt(reader); info.Rank = GetRankByIndex(rankIndex); { bool hasPrevRank = reader.ReadBoolean(); if (hasPrevRank) { int prevRankIndex = Read7BitEncodedInt(reader); info.PreviousRank = GetRankByIndex(prevRankIndex); } } info.RankChangeType = (RankChangeType)reader.ReadByte(); if (info.RankChangeType != RankChangeType.Default) { info.RankChangeDate = ReadDate(reader); info.RankChangedBy = ReadString(reader); info.RankChangeReason = ReadString(reader); } // Bans info.BanStatus = (BanStatus)reader.ReadByte(); info.BanDate = ReadDate(reader); info.BannedBy = ReadString(reader); info.BanReason = ReadString(reader); if (info.BanStatus == BanStatus.Banned) { info.BannedUntil = ReadDate(reader); info.LastFailedLoginDate = ReadDate(reader); info.LastFailedLoginIP = ReadIPAddress(reader); } else { info.UnbanDate = ReadDate(reader); info.UnbannedBy = ReadString(reader); info.UnbanReason = ReadString(reader); } // Stats info.FirstLoginDate = ReadDate(reader); info.LastLoginDate = ReadDate(reader); info.TotalTime = ReadTimeSpan(reader); info.BlocksBuilt = Read7BitEncodedInt(reader); info.BlocksDeleted = Read7BitEncodedInt(reader); if (reader.ReadBoolean()) { info.BlocksDrawn = reader.ReadInt64(); } info.TimesVisited = Read7BitEncodedInt(reader); info.MessagesWritten = Read7BitEncodedInt(reader); info.TimesKickedOthers = Read7BitEncodedInt(reader); info.TimesBannedOthers = Read7BitEncodedInt(reader); // Kicks info.TimesKicked = Read7BitEncodedInt(reader); if (info.TimesKicked > 0) { info.LastKickDate = ReadDate(reader); info.LastKickBy = ReadString(reader); info.LastKickReason = ReadString(reader); } // Freeze/Mute info.IsFrozen = reader.ReadBoolean(); if (info.IsFrozen) { info.FrozenOn = ReadDate(reader); info.FrozenBy = ReadString(reader); } info.MutedUntil = ReadDate(reader); if (info.MutedUntil != DateTime.MinValue) { info.MutedBy = ReadString(reader); } // Misc info.Password = ReadString(reader); info.LastModified = ReadDate(reader); reader.ReadBoolean(); // info.IsOnline - skip info.IsHidden = reader.ReadBoolean(); info.LastIP = ReadIPAddress(reader); info.LeaveReason = (LeaveReason)reader.ReadByte(); info.BandwidthUseMode = (BandwidthUseMode)reader.ReadByte(); return(info); }