示例#1
0
        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);
        }
示例#2
0
        static void LoadWorldListEntry([NotNull] XElement el, FileInfo[] allMapFiles)
        {
            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, allMapFiles);
        }
示例#3
0
        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.");
            }

            if (!Player.IsValidPlayerName(fields[0]))
            {
                throw new FormatException("Unacceptable player name");
            }
            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], NumberStyles.Integer, NumberFormatter, out info.BlocksBuilt);
            }
            if (fields[19].Length > 0)
            {
                Int32.TryParse(fields[19], NumberStyles.Integer, NumberFormatter, out info.BlocksDeleted);
            }
            if (fields[20].Length > 0)
            {
                Int32.TryParse(fields[20], NumberStyles.Integer, NumberFormatter, out info.TimesVisited);
            }
            if (fields[21].Length > 0)
            {
                Int32.TryParse(fields[21], NumberStyles.Integer, NumberFormatter, 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], NumberStyles.Integer, NumberFormatter, out info.TimesKicked);
            Int32.TryParse(fields[27], NumberStyles.Integer, NumberFormatter, out info.TimesKickedOthers);
            Int32.TryParse(fields[28], NumberStyles.Integer, NumberFormatter, 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;
                switch (info.RankChangeType)
                {
                case RankChangeType.AutoDemoted:
                case RankChangeType.AutoPromoted:
                case RankChangeType.Default:
                case RankChangeType.Demoted:
                case RankChangeType.Promoted:
                    break;

                default:
                    info.GuessRankChangeType();
                    break;
                }
            }
            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], NumberStyles.Integer, NumberFormatter, 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], NumberStyles.Integer, NumberFormatter, out bandwidthUseModeCode))
            {
                info.BandwidthUseMode = (BandwidthUseMode)bandwidthUseModeCode;
                switch (info.BandwidthUseMode)
                {
                case BandwidthUseMode.High:
                case BandwidthUseMode.Low:
                case BandwidthUseMode.Normal:
                case BandwidthUseMode.VeryHigh:
                case BandwidthUseMode.VeryLow:
                    break;

                default:
                    info.BandwidthUseMode = BandwidthUseMode.Default;
                    break;
                }
            }
            else
            {
                info.BandwidthUseMode = BandwidthUseMode.Default;
            }

            if (fields.Length > 45 && fields[45] == "h")
            {
                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], NumberStyles.Integer, NumberFormatter, out accountTypeCode))
                {
                    info.AccountType = (AccountType)accountTypeCode;
                    if (!Enum.IsDefined(typeof(AccountType), accountTypeCode))
                    {
                        info.AccountType = AccountType.Unknown;
                    }
                }
            }
            if (fields.Length > 49 && 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);
        }
示例#4
0
        internal static PlayerInfo LoadFormat1(string[] fields)
        {
            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;
            fields[3].ToDateTimeLegacy(ref info.RankChangeDate);
            if (fields[4].Length > 0)
            {
                info.RankChangedBy = 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 (fields[6].ToDateTimeLegacy(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 (fields[8].ToDateTimeLegacy(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
            fields[12].ToDateTimeLegacy(ref info.LastFailedLoginDate);

            if (fields[13].Length > 1 || !IPAddress.TryParse(fields[13], out info.LastFailedLoginIP))      // LEGACY
            {
                info.LastFailedLoginIP = IPAddress.None;
            }
            // skip 14
            fields[15].ToDateTimeLegacy(ref info.FirstLoginDate);

            // login/logout times
            fields[16].ToDateTimeLegacy(ref info.LastLoginDate);
            fields[17].ToTimeSpanLegacy(ref 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();
            }

            fields[31].ToDateTimeLegacy(ref info.LastKickDate);
            if (!fields[32].ToDateTimeLegacy(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[34].Length > 0)
            {
                info.LastKickReason = PlayerDB.Unescape(fields[35]);
            }

            fields[36].ToDateTimeLegacy(ref info.BannedUntil);
            info.IsFrozen = (fields[37] == "f");
            if (fields[38].Length > 0)
            {
                info.FrozenBy = PlayerDB.Unescape(fields[38]);
            }
            fields[39].ToDateTimeLegacy(ref info.FrozenOn);
            fields[40].ToDateTimeLegacy(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);
                }
            }

            // date consistency checks
            if (info.LastSeen < info.FirstLoginDate)
            {
                info.LastSeen = info.FirstLoginDate;
            }
            if (info.LastLoginDate < info.FirstLoginDate)
            {
                info.LastLoginDate = info.FirstLoginDate;
            }

            return(info);
        }
示例#5
0
        /// <summary> Loads configuration from file. </summary>
        /// <param name="skipRankList"> If true, skips over rank definitions. </param>
        /// <param name="raiseReloadedEvent"> Whether ConfigReloaded event should be raised. </param>
        public static void Load(bool skipRankList, bool raiseReloadedEvent)
        {
            bool fromFile = false;

            // try to load config file (XML)
            XDocument file;

            if (File.Exists(Paths.ConfigFileName))
            {
                file = XDocument.Load(Paths.ConfigFileName);
                if (file.Root == null || file.Root.Name != ConfigXmlRootName)
                {
                    Logger.Log(LogType.Warning,
                               "Config.Load: Malformed or incompatible config file {0}. Loading defaults.",
                               Paths.ConfigFileName);
                    file = new XDocument();
                    file.Add(new XElement(ConfigXmlRootName));
                }
                else
                {
                    Logger.Log(LogType.Debug,
                               "Config.Load: Config file {0} loaded successfully.",
                               Paths.ConfigFileName);
                    fromFile = true;
                }
            }
            else
            {
                // create a new one (with defaults) if no file exists
                file = new XDocument();
                file.Add(new XElement(ConfigXmlRootName));
            }

            XElement config = file.Root;

            if (config == null)
            {
                throw new Exception("Config.xml has no root. Never happens.");
            }

            int version = 0;

            if (fromFile)
            {
                XAttribute attr = config.Attribute("version");
                if (attr != null && Int32.TryParse(attr.Value, out version))
                {
                    if (version < LowestSupportedVersion)
                    {
                        Logger.Log(LogType.Warning,
                                   "Config.Load: Your copy of config.xml is too old (v{0}) to be loaded properly. " +
                                   "Some settings will be lost or replaced with defaults. " +
                                   "Please run ConfigGUI to make sure that everything is in order.",
                                   version);
                    }
                    else if (version != CurrentVersion)
                    {
                        Logger.Log(LogType.Warning,
                                   "Config.Load: Your config.xml was made for a different version of fCraft. " +
                                   "Some obsolete settings might be ignored, and some recently-added settings will be set to defaults. " +
                                   "It is recommended that you run ConfigGUI to make sure that everything is in order. (v{0} -> v{1})",
                                   version, CurrentVersion);
                    }
                }
                else
                {
                    Logger.Log(LogType.Warning,
                               "Config.Load: Unknown version of config.xml found. It might be corrupted. " +
                               "Please run ConfigGUI to make sure that everything is in order.");
                }
            }

            // read rank definitions
            if (!skipRankList)
            {
                LoadRankList(config, fromFile);
            }

            ResetLogOptions();

            // read log options for console
            XElement consoleOptions = config.Element("ConsoleOptions");

            if (consoleOptions != null)
            {
                LoadLogOptions(consoleOptions, Logger.ConsoleOptions);
            }
            else if (fromFile)
            {
                Logger.Log(LogType.Warning, "Config.Load: using default console options.");
            }

            // read log options for log files
            XElement logFileOptions = config.Element("LogFileOptions");

            if (logFileOptions != null)
            {
                LoadLogOptions(logFileOptions, Logger.LogFileOptions);
            }
            else if (fromFile)
            {
                Logger.Log(LogType.Warning, "Config.Load: using default log file options.");
            }


            // read the rest of the keys
            if (version < FirstVersionWithSectionTags)
            {
                foreach (XElement element in config.Elements())
                {
                    ParseKeyElementPreSettings(element);
                }
            }
            else if (version < FirstVersionWithSettingsTag)
            {
                foreach (XElement section in config.Elements("Section"))
                {
                    foreach (XElement keyElement in section.Elements())
                    {
                        ParseKeyElementPreSettings(keyElement);
                    }
                }
            }
            else
            {
                XElement settings = config.Element("Settings");
                if (settings != null)
                {
                    foreach (XElement pair in settings.Elements("ConfigKey"))
                    {
                        ParseKeyElement(pair);
                    }
                }
                else
                {
                    Logger.Log(LogType.Warning,
                               "Config.Load: No <Settings> tag present. Using default for everything.");
                }
            }

            if (!skipRankList)
            {
                RankManager.DefaultRank           = Rank.Parse(ConfigKey.DefaultRank.GetString());
                RankManager.DefaultBuildRank      = Rank.Parse(ConfigKey.DefaultBuildRank.GetString());
                RankManager.PatrolledRank         = Rank.Parse(ConfigKey.PatrolledRank.GetString());
                RankManager.BlockDBAutoEnableRank = Rank.Parse(ConfigKey.BlockDBAutoEnableRank.GetString());
            }

            // key relation validation
            if (version < FirstVersionWithMaxPlayersKey)
            {
                ConfigKey.MaxPlayersPerWorld.TrySetValue(ConfigKey.MaxPlayers.GetInt());
            }
            if (ConfigKey.MaxPlayersPerWorld.GetInt() > ConfigKey.MaxPlayers.GetInt())
            {
                Logger.Log(LogType.Warning,
                           "Value of MaxPlayersPerWorld ({0}) was lowered to match MaxPlayers ({1}).",
                           ConfigKey.MaxPlayersPerWorld.GetInt(),
                           ConfigKey.MaxPlayers.GetInt());
                ConfigKey.MaxPlayersPerWorld.TrySetValue(ConfigKey.MaxPlayers.GetInt());
            }

            if (raiseReloadedEvent)
            {
                RaiseReloadedEvent();
            }
        }
示例#6
0
        static void ApplyKeyChange(ConfigKey key)
        {
            switch (key)
            {
            case ConfigKey.AnnouncementColor:
                Color.Announcement = Color.Parse(key.GetString());
                break;

            case ConfigKey.AntispamInterval:
                Player.AntispamInterval = key.GetInt();
                break;

            case ConfigKey.AntispamMessageCount:
                Player.AntispamMessageCount = key.GetInt();
                break;

            case ConfigKey.DefaultBuildRank:
                RankManager.DefaultBuildRank = Rank.Parse(key.GetString());
                break;

            case ConfigKey.DefaultRank:
                RankManager.DefaultRank = Rank.Parse(key.GetString());
                break;

            case ConfigKey.BandwidthUseMode:
                Player[] playerListCache = Server.Players;
                if (playerListCache != null)
                {
                    foreach (Player p in playerListCache)
                    {
                        if (p.BandwidthUseMode == BandwidthUseMode.Default)
                        {
                            // resets the use tweaks
                            p.BandwidthUseMode = BandwidthUseMode.Default;
                        }
                    }
                }
                break;

            case ConfigKey.BlockDBAutoEnableRank:
                RankManager.BlockDBAutoEnableRank = Rank.Parse(key.GetString());
                if (BlockDB.IsEnabledGlobally)
                {
                    World[] worldListCache = WorldManager.Worlds;
                    foreach (World world in worldListCache)
                    {
                        if (world.BlockDB.AutoToggleIfNeeded())
                        {
                            if (world.BlockDB.IsEnabled)
                            {
                                Logger.Log(LogType.SystemActivity,
                                           "BlockDB is now auto-enabled on world {0}", world.Name);
                            }
                            else
                            {
                                Logger.Log(LogType.SystemActivity,
                                           "BlockDB is now auto-disabled on world {0}", world.Name);
                            }
                        }
                    }
                }
                break;

            case ConfigKey.BlockUpdateThrottling:
                Server.BlockUpdateThrottling = key.GetInt();
                break;

            case ConfigKey.BypassHttpsCertificateValidation:
                if (key.Enabled())
                {
                    ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
                }
                else
                {
                    ServicePointManager.ServerCertificateValidationCallback = null;
                }
                break;

            case ConfigKey.ConsoleName:
                if (Player.Console != null)
                {
                    Player.Console.Info.Name = key.GetString();
                }
                break;

            case ConfigKey.DefaultBackupInterval:
                World.DefaultBackupInterval = new TimeSpan(TimeSpan.TicksPerMinute * key.GetInt());
                break;

            case ConfigKey.HeartbeatUrl:
                Heartbeat.MinecraftNetUri = new Uri(key.GetString());
                break;

            case ConfigKey.HelpColor:
                Color.Help = Color.Parse(key.GetString());
                break;

            case ConfigKey.IRCDelay:
                IRC.SendDelay = TimeSpan.FromMilliseconds(key.GetInt());
                break;

            case ConfigKey.IRCMessageColor:
                Color.IRC = Color.Parse(key.GetString());
                break;

            case ConfigKey.LogMode:
                Logger.SplittingType = key.GetEnum <LogSplittingType>();
                break;

            case ConfigKey.MapPath:
                if (!Paths.IgnoreMapPathConfigKey && GetString(ConfigKey.MapPath).Length > 0)
                {
                    if (Paths.TestDirectory("MapPath", GetString(ConfigKey.MapPath), true))
                    {
                        Paths.MapPath = Path.GetFullPath(GetString(ConfigKey.MapPath));
                    }
                }
                break;

            case ConfigKey.MaxUndo:
                BuildingCommands.MaxUndoCount = key.GetInt();
                break;

            case ConfigKey.MeColor:
                Color.Me = Color.Parse(key.GetString());
                break;

            case ConfigKey.NoPartialPositionUpdates:
                if (key.Enabled())
                {
                    Player.FullPositionUpdateInterval = 0;
                }
                else
                {
                    Player.FullPositionUpdateInterval = Player.FullPositionUpdateIntervalDefault;
                }
                break;

            case ConfigKey.PatrolledRank:
                RankManager.PatrolledRank = Rank.Parse(key.GetString());
                break;

            case ConfigKey.PrivateMessageColor:
                Color.PM = Color.Parse(key.GetString());
                break;

            case ConfigKey.RelayAllBlockUpdates:
                Player.RelayAllUpdates = key.Enabled();
                break;

            case ConfigKey.SayColor:
                Color.Say = Color.Parse(key.GetString());
                break;

            case ConfigKey.SystemMessageColor:
                Color.Sys = Color.Parse(key.GetString());
                break;

            case ConfigKey.TickInterval:
                Server.TicksPerSecond = 1000 / (float)key.GetInt();
                break;

            case ConfigKey.UploadBandwidth:
                Server.MaxUploadSpeed = key.GetInt();
                break;

            case ConfigKey.WarningColor:
                Color.Warning = Color.Parse(key.GetString());
                break;
            }
        }
示例#7
0
        internal PlayerInfo LoadFormat0([NotNull] string[] fields)
        {
            if (fields == null)
            {
                throw new ArgumentNullException("fields");
            }
            DateTime tempDate;

            // get ID
            int id;

            if (fields.Length > 29)
            {
                if (!Int32.TryParse(fields[29], out id) || id < 256)
                {
                    id = GetNextID();
                }
            }
            else
            {
                id = GetNextID();
            }

            PlayerInfo info = new PlayerInfo(id)
            {
                Name = fields[0]
            };

            if (fields[1].Length > 1)
            {
                IPAddress lastIP;
                IPAddress.TryParse(fields[1], out lastIP);
                info.LastIP = lastIP;
            }

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

            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 (TryParseLocalDate(fields[6], out tempDate))
            {
                if (fields[7].Length > 0)
                {
                    info.BannedBy = fields[7];
                }
                if (fields[10].Length > 0)
                {
                    info.BanReason = UnescapeOldFormat(fields[10]);
                    if (info.BanReason == "-")
                    {
                        info.BanReason = null;
                    }
                }
            }
            info.BanDate = tempDate;

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

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

            // login/logout times
            TryParseLocalDate(fields[15], out tempDate);
            info.FirstLoginDate = tempDate;
            TryParseLocalDate(fields[16], out tempDate);
            info.LastLoginDate = tempDate;
            TimeSpan totalTime;

            TimeSpan.TryParse(fields[17], 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.Length > MinFieldCount)
            {
                if (fields[24].Length > 0)
                {
                    info.PreviousRank = Rank.Parse(fields[24]);
                }
                if (fields[25].Length > 0)
                {
                    info.RankChangeReason = UnescapeOldFormat(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] (id) already read/assigned by this point
                if (fields.Length > 29)
                {
                    byte rankChangeTypeCode;
                    if (Byte.TryParse(fields[30], out rankChangeTypeCode))
                    {
                        info.RankChangeType = (RankChangeType)rankChangeTypeCode;
                        if (!Enum.IsDefined(typeof(RankChangeType), rankChangeTypeCode))
                        {
                            GuessRankChangeType(info);
                        }
                    }
                    else
                    {
                        GuessRankChangeType(info);
                    }
                    TryParseLocalDate(fields[31], out tempDate);
                    info.LastKickDate = tempDate;
                    if (!TryParseLocalDate(fields[32], 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 = UnescapeOldFormat(fields[34]);
                    }
                    if (fields[35].Length > 0)
                    {
                        info.LastKickReason = UnescapeOldFormat(fields[35]);
                    }
                }
                else
                {
                    GuessRankChangeType(info);
                    info.LastSeen = info.LastLoginDate;
                }

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

                if (fields.Length > 44)
                {
                    ParseBandwidthUseMode(info, fields[44]);
                }
            }

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

            return(info);
        }
示例#8
0
        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);
        }
示例#9
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 = 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 = 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 = 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 = UnescapeOldFormat(fields[34]);
                    }
                    if (fields[35].Length > 0)
                    {
                        info.LastKickReason = 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 = UnescapeOldFormat(fields[38]);
                    }
                    DateTimeUtil.TryParseLocalDate(fields[39], out info.FrozenOn);
                    DateTimeUtil.TryParseLocalDate(fields[40], out info.MutedUntil);
                    if (fields[41].Length > 0)
                    {
                        info.MutedBy = UnescapeOldFormat(fields[41]);
                    }
                    info.Password = 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);
        }
示例#10
0
        public Zone([NotNull] string raw, [CanBeNull] World world)
            : this()
        {
            if (raw == null)
            {
                throw new ArgumentNullException("raw");
            }
            string[] parts = raw.Split(',');

            string[] header = parts[0].Split(' ');
            Name   = header[0];
            Bounds = new BoundingBox(Int32.Parse(header[1]), Int32.Parse(header[2]), Int32.Parse(header[3]),
                                     Int32.Parse(header[4]), Int32.Parse(header[5]), Int32.Parse(header[6]));

            Rank buildRank = Rank.Parse(header[7]);


            if (header.Length > 8)
            {
                // Part 5: Zone color
                try {
                    bool zoneShow;
                    if (bool.TryParse(header[8], out zoneShow))
                    {
                        ShowZone = zoneShow;
                    }
                    Color = header[9];
                    short zoneAlpha;
                    if (short.TryParse(header[10], out zoneAlpha))
                    {
                        Alpha = zoneAlpha;
                    }
                } catch (Exception ex) {
                    Logger.Log(LogType.Error, "Could not load Zone Colors for {0}", Name);
                    Logger.Log(LogType.Error, ex.StackTrace);
                }
            }

            if (header[0].Contains(SpecialZone.Door))
            {
                buildRank = RankManager.DefaultRank;
            }
            // if all else fails, fall back to lowest class... ignore door instances
            if (buildRank == null && !header[0].Contains(SpecialZone.Door))
            {
                if (world != null)
                {
                    Controller.MinRank = world.BuildSecurity.MinRank;
                }
                else
                {
                    Controller.ResetMinRank();
                }
                Logger.Log(LogType.Error,
                           "Zone: Error parsing zone definition: unknown rank \"{0}\". Permission reset to default ({1}). Ignore this message if you have recently changed rank permissions.",
                           header[7], Controller.MinRank.Name);
            }
            else
            {
                Controller.MinRank = buildRank;
            }

            if (PlayerDB.IsLoaded)
            {
                // Part 2:
                if (parts[1].Length > 0)
                {
                    foreach (string playerName in parts[1].Split(' '))
                    {
                        if (!Player.IsValidPlayerName(playerName))
                        {
                            Logger.Log(LogType.Warning,
                                       "Invalid entry in zone \"{0}\" whitelist: {1}", Name, playerName);
                            continue;
                        }
                        PlayerInfo info = PlayerDB.FindPlayerInfoExact(playerName);
                        if (info == null)
                        {
                            Logger.Log(LogType.Warning,
                                       "Unrecognized player in zone \"{0}\" whitelist: {1}", Name, playerName);
                            continue; // player name not found in the DB (discarded)
                        }
                        Controller.Include(info);
                    }
                }

                // Part 3: excluded list
                if (parts[2].Length > 0)
                {
                    foreach (string playerName in parts[2].Split(' '))
                    {
                        if (!Player.IsValidPlayerName(playerName))
                        {
                            Logger.Log(LogType.Warning,
                                       "Invalid entry in zone \"{0}\" blacklist: {1}", Name, playerName);
                            continue;
                        }
                        PlayerInfo info = PlayerDB.FindPlayerInfoExact(playerName);
                        if (info == null)
                        {
                            Logger.Log(LogType.Warning,
                                       "Unrecognized player in zone \"{0}\" whitelist: {1}", Name, playerName);
                            continue; // player name not found in the DB (discarded)
                        }
                        Controller.Exclude(info);
                    }
                }
            }
            else
            {
                RawWhitelist = parts[1];
                RawBlacklist = parts[2];
            }

            // Part 4: extended header
            if (parts.Length > 3)
            {
                string[] xheader = parts[3].Split(' ');
                if (xheader[0] == "-")
                {
                    CreatedBy   = null;
                    CreatedDate = DateTime.MinValue;
                }
                else
                {
                    CreatedBy   = xheader[0];
                    CreatedDate = DateTime.Parse(xheader[1]);
                }

                if (xheader[2] == "-")
                {
                    EditedBy   = null;
                    EditedDate = DateTime.MinValue;
                }
                else
                {
                    EditedBy   = xheader[2];
                    EditedDate = DateTime.Parse(xheader[3]);
                }
            }
        }
示例#11
0
        public Zone([NotNull] string raw, [CanBeNull] World world)
            : this()
        {
            if (raw == null)
            {
                throw new ArgumentNullException("raw");
            }
            string[] parts = raw.Split(',');

            string[] header = parts[0].Split(' ');
            Name   = header[0];
            Bounds = new BoundingBox(Int32.Parse(header[1]), Int32.Parse(header[2]), Int32.Parse(header[3]),
                                     Int32.Parse(header[4]), Int32.Parse(header[5]), Int32.Parse(header[6]));

            // If no ranks are loaded (e.g. MapConverter/MapRenderer)(
            if (RankManager.Ranks.Count > 0)
            {
                Rank buildRank = Rank.Parse(header[7]);
                // if all else fails, fall back to lowest class
                if (buildRank == null)
                {
                    if (world != null)
                    {
                        Controller.MinRank = world.BuildSecurity.MinRank;
                    }
                    else
                    {
                        Controller.ResetMinRank();
                    }
                    Logger.Log(LogType.Error,
                               "Zone: Error parsing zone definition: unknown rank \"{0}\". Permission reset to default ({1}).",
                               header[7], Controller.MinRank.Name);
                }
                else
                {
                    Controller.MinRank = buildRank;
                }
            }

            // If PlayerDB is not loaded (e.g. ConfigGUI)
            if (PlayerDB.IsLoaded)
            {
                // Part 2:
                if (parts[1].Length > 0)
                {
                    foreach (string playerName in parts[1].Split(' '))
                    {
                        if (!Player.IsValidPlayerName(playerName))
                        {
                            Logger.Log(LogType.Warning,
                                       "Invalid entry in zone \"{0}\" whitelist: {1}", Name, playerName);
                            continue;
                        }
                        PlayerInfo info = PlayerDB.FindPlayerInfoExact(playerName);
                        if (info == null)
                        {
                            Logger.Log(LogType.Warning,
                                       "Unrecognized player in zone \"{0}\" whitelist: {1}", Name, playerName);
                            continue; // player name not found in the DB (discarded)
                        }
                        Controller.Include(info);
                    }
                }

                // Part 3: excluded list
                if (parts[2].Length > 0)
                {
                    foreach (string playerName in parts[2].Split(' '))
                    {
                        if (!Player.IsValidPlayerName(playerName))
                        {
                            Logger.Log(LogType.Warning,
                                       "Invalid entry in zone \"{0}\" blacklist: {1}", Name, playerName);
                            continue;
                        }
                        PlayerInfo info = PlayerDB.FindPlayerInfoExact(playerName);
                        if (info == null)
                        {
                            Logger.Log(LogType.Warning,
                                       "Unrecognized player in zone \"{0}\" whitelist: {1}", Name, playerName);
                            continue; // player name not found in the DB (discarded)
                        }
                        Controller.Exclude(info);
                    }
                }
            }
            else
            {
                RawWhitelist = parts[1];
                RawBlacklist = parts[2];
            }

            // Part 4: extended header
            if (parts.Length > 3)
            {
                string[] xheader = parts[3].Split(' ');
                if (xheader[0] == "-")
                {
                    CreatedBy   = null;
                    CreatedDate = DateTime.MinValue;
                }
                else
                {
                    CreatedBy   = xheader[0];
                    CreatedDate = DateTime.Parse(xheader[1]);
                }

                if (xheader[2] == "-")
                {
                    EditedBy   = null;
                    EditedDate = DateTime.MinValue;
                }
                else
                {
                    EditedBy   = xheader[2];
                    EditedDate = DateTime.Parse(xheader[3]);
                }
            }
        }