示例#1
0
        private static void LoadRegions(BinaryFileReader reader,
                                        RegionEntry[] entries)
        {
            for (int i = 0; i < entries.Length; ++i)
            {
                RegionEntry entry  = entries[i];
                Region      region = (Region)entry.Object;
                if (region == null)
                {
                    continue;
                }

                reader.Seek(entry.Position, SeekOrigin.Begin);

                try {
                    region.Deserialize(reader);
                } catch (Exception e) {
                    log.Error(String.Format("failed to load region", region),
                              e);
                    ++m_LoadErrors;
                    continue;
                }

                if (reader.Position != entry.Position + entry.Length)
                {
                    log.ErrorFormat("Bad deserialize on region {0}, type {1}: position={2}, should be {3}",
                                    region.UId, region.GetType(),
                                    reader.Position, entry.Position + entry.Length);
                    ++m_LoadErrors;
                }
            }
        }
示例#2
0
        public ConfigForm()
        {
            InitializeComponent();

            AcceptButton = okBtn;
            CancelButton = cancelBtn;

            //Populate target fields
            List <string> targets = TargetFactory.GetTargetNames();

            foreach (string target in targets)
            {
                targetList.Items.Add(target);
            }

            targetList.SelectedIndex = 0;

            //Populate resolution fields
            foreach (Tuple <int, int> resolution in MainForm.kValidResolutions)
            {
                ResolutionEntry entry = new ResolutionEntry();
                entry.Width  = resolution.Item1;
                entry.Height = resolution.Item2;
                entry.Text   = String.Format("{0} x {1}", entry.Width, entry.Height);
                emuResolution.Items.Add(entry);
            }

            emuResolution.SelectedIndex = MainForm.kDefaultResolutionEntry;

            //Populate region fields
            foreach (Tuple <char, string> region in MainForm.kRegions)
            {
                RegionEntry entry = new RegionEntry();
                entry.RegionCode = region.Item1;
                entry.Text       = region.Item2;
                emuRegion.Items.Add(entry);
            }

            emuRegion.SelectedIndex = MainForm.kDefaultRegion;

            //Populate keycode fields
            foreach (SDL_Keycode.Keycode keycode in Enum.GetValues(typeof(SDL_Keycode.Keycode)))
            {
                KeycodeEntry entry = new KeycodeEntry();
                entry.Keycode = keycode;

                inputUp.Items.Add(entry);
                inputDown.Items.Add(entry);
                inputLeft.Items.Add(entry);
                inputRight.Items.Add(entry);
                inputA.Items.Add(entry);
                inputB.Items.Add(entry);
                inputC.Items.Add(entry);
                inputStart.Items.Add(entry);
            }
        }
示例#3
0
 public override void GetPacketDataString(TextWriter text, bool flagsDescription)
 {
     for (int i = 0; i < regions.Length; i++)
     {
         RegionEntry region = (RegionEntry)regions[i];
         if (region.regionIndex == 0)
         {
             continue;
         }
         text.Write("\n\tregionIndex:{0,-3} regionId:{1,-3} name:{2} fromPort:{3} toPort:{4} ip:{5,-15}",
                    region.regionIndex, region.region, region.name, region.fromPort, region.toPort, region.ip);
     }
 }
示例#4
0
        private void TestGetOp(IRegion <object, object> region, int num)
        {
            DoNput(region, num);

            ICollection <object> cKeys = region.GetLocalView().Keys;
            object cVal;

            Assert.AreEqual(num, cKeys.Count, "Number of keys does not match.");
            foreach (object cKey in cKeys)
            {
                RegionEntry <object, object> entry = region.GetEntry(cKey);
                cVal = entry.Value;
                if (IsOverflowed(cVal))
                {
                    cVal = region[cKey];
                    Assert.IsFalse(IsOverflowed(cVal), "Overflow token even after a Region.Get");
                }
            }
        }
        /// <summary>
        /// Initializes the packet. All data parsing must be done here.
        /// </summary>
        public override void Init()
        {
            regions = new RegionEntry[4] ;

            Position = 0;

            for (int i = 0; i < 4; i++)
            {
                RegionEntry reg = new RegionEntry();

                reg.regionIndex = ReadByte(); // 0x00
                reg.region = ReadByte();      // 0x01
                reg.name = ReadString(20);    // 0x02
                reg.fromPort = ReadString(5); // 0x22
                reg.toPort = ReadString(5);   // 0x27
                reg.ip = ReadString(20);      // 0x2C

                regions[i] = reg;
            }
        }
示例#6
0
        /// <summary>
        /// Initializes the packet. All data parsing must be done here.
        /// </summary>
        public override void Init()
        {
            regions = new RegionEntry[4];

            Position = 0;

            for (int i = 0; i < 4; i++)
            {
                RegionEntry reg = new RegionEntry();

                reg.regionIndex = ReadByte();                 // 0x00
                reg.region      = ReadByte();                 // 0x01
                reg.name        = ReadString(20);             // 0x02
                reg.fromPort    = ReadString(5);              // 0x22
                reg.toPort      = ReadString(5);              // 0x27
                reg.ip          = ReadString(20);             // 0x2C

                regions[i] = reg;
            }
        }
示例#7
0
        private void CheckOverflowToken(IRegion <object, object> region, int num, int lruLimit)
        {
            //IGeodeSerializable cVal;
            //ICacheableKey[] cKeys = region.GetKeys();

            object cVal;
            ICollection <object> cKeys = region.GetLocalView().Keys;

            Assert.AreEqual(num, cKeys.Count, "Number of keys does not match.");
            int count = 0;

            foreach (object cKey in cKeys)
            {
                RegionEntry <object, object> entry = region.GetEntry(cKey);
                cVal = entry.Value;
                if (IsOverflowed(cVal))
                {
                    count++;
                }
            }
            Assert.AreEqual(0, count, "Number of overflowed entries should be zero");
        }
示例#8
0
        private static RegionEntry[] LoadRegionIndex(BinaryReader idxReader)
        {
            int count = idxReader.ReadInt32(), skipped = 0;

            RegionEntry[] entries = new RegionEntry[count];

            for (int i = 0; i < count; ++i)
            {
                idxReader.ReadInt32();                //no typeid for regions
                int  serial = idxReader.ReadInt32();
                long pos    = idxReader.ReadInt64();
                int  length = idxReader.ReadInt32();

                if (serial == Serial.MinusOne)
                {
                    ++skipped;
                    continue;
                }

                Region region = Region.FindByUId(serial);
                if (region == null)
                {
                    ++skipped;
                    continue;
                }

                entries[i] = new RegionEntry(region, pos, length);
                Region.AddRegion(region);
            }

            if (skipped > 0)
            {
                log.WarnFormat("{0} regions were skipped", skipped);
                m_LoadErrors += skipped;
            }

            return(entries);
        }
示例#9
0
        private static void LoadRegions(string path,
										RegionEntry[] entries)
        {
            using (FileStream bin = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                using (BinaryReader binReader = new BinaryReader(bin)) {
                    BinaryFileReader reader = new BinaryFileReader(binReader);
                    try {
                        LoadRegions(reader, entries);
                    } finally {
                        reader.Close();
                    }
                }
            }
        }
示例#10
0
        private static void LoadRegions(BinaryFileReader reader,
										RegionEntry[] entries)
        {
            for (int i = 0; i < entries.Length; ++i) {
                RegionEntry entry = entries[i];
                Region region = (Region)entry.Object;
                if (region == null)
                    continue;

                reader.Seek(entry.Position, SeekOrigin.Begin);

                try {
                    region.Deserialize(reader);
                } catch (Exception e) {
                    log.Error(String.Format("failed to load region", region),
                              e);
                    ++m_LoadErrors;
                    continue;
                }

                if (reader.Position != entry.Position + entry.Length) {
                    log.ErrorFormat("Bad deserialize on region {0}, type {1}: position={2}, should be {3}",
                                    region.UId, region.GetType(),
                                    reader.Position, entry.Position + entry.Length);
                    ++m_LoadErrors;
                }
            }
        }
示例#11
0
        private static RegionEntry[] LoadRegionIndex(BinaryReader idxReader)
        {
            int count = idxReader.ReadInt32(), skipped = 0;

            RegionEntry[] entries = new RegionEntry[count];

            for (int i = 0; i < count; ++i) {
                idxReader.ReadInt32();//no typeid for regions
                int serial = idxReader.ReadInt32();
                long pos = idxReader.ReadInt64();
                int length = idxReader.ReadInt32();

                if (serial == Serial.MinusOne) {
                    ++skipped;
                    continue;
                }

                Region region = Region.FindByUId(serial);
                if (region == null) {
                    ++skipped;
                    continue;
                }

                entries[i] = new RegionEntry(region, pos, length);
                Region.AddRegion(region);
            }

            if (skipped > 0) {
                log.WarnFormat("{0} regions were skipped", skipped);
                m_LoadErrors += skipped;
            }

            return entries;
        }
示例#12
0
        public void DoGetsVerify()
        {
            Util.Log("DoGetsVerify: m_cKeys " + m_cKeys.Length);
            Assert.IsNotNull(m_cKeys, "DoGetsVerify: null keys array.");
            Assert.IsNotNull(m_cValues, "DoGetsVerify: null values array.");
            Assert.IsNotNull(m_region, "DoGetsVerify: null region.");

            for (int keyIndex = 0; keyIndex < m_cKeys.Length; keyIndex++)
            {
                Util.Log("DoGetsVerify key type " + m_cKeys[keyIndex].CacheableKey.GetType());
                Object actualValue = m_region[m_cKeys[keyIndex].CacheableKey];

                if (actualValue == null)
                {
                    Util.Log("DoGetsVerify value is null");
                }
                else
                {
                    Util.Log("DoGetsVerify value is not null ");
                }
                uint cksum = m_cKeys[keyIndex].GetChecksum();
                //Util.Log("DoGetsVerify  key clasid " + m_region[(KeyChecksumPrefix + keyIndex).ClassId]);
                //Util.Log("DoGetsVerify  key clasid " + m_region[(KeyChecksumPrefix + keyIndex).ClassId]);
                //Util.Log("DoGetsVerify  key type " + m_region.Get(KeyChecksumPrefix + keyIndex).GetType().ToString());
                //CacheableInt32 putCksum = m_region[KeyChecksumPrefix + keyIndex] as CacheableInt32;
                Util.Log("DoGetsVerify  key type " + m_region[KeyChecksumPrefix + keyIndex].GetType().ToString());
                int putCksum = (int)m_region[KeyChecksumPrefix + keyIndex];
                Assert.IsNotNull(putCksum,
                                 "DoGetsVerify: Could not find checksum for key at index {0}.",
                                 keyIndex);
                Assert.AreEqual(cksum, (uint)putCksum,
                                "DoGetsVerify: Checksums of the keys at index {0} differ.",
                                keyIndex);
                Util.Log("actualValue Type = {0}", actualValue.GetType());
                cksum    = m_cValues[keyIndex].GetChecksum((object)actualValue);
                putCksum = (int)m_region[ValChecksumPrefix + keyIndex];
                Assert.IsNotNull(putCksum, "DoGetsVerify: Could not find checksum for value at index {0}.", keyIndex);
                Assert.AreEqual(cksum, (uint)putCksum, "DoGetsVerify: Checksums of the values at index {0} differ.", keyIndex);

                // Also check in local cache using GetEntry
                Util.Log("DoGetsVerify() key hashcode " + m_cKeys[keyIndex].CacheableKey.GetHashCode());
                RegionEntry <object, object> entry = m_region.GetEntry(m_cKeys[keyIndex].CacheableKey);

                if (entry != null)
                {
                    try
                    {
                        cksum = m_cValues[keyIndex].GetChecksum(entry.Value);
                    }
                    catch (Exception ex)
                    {
                        Util.Log("DoGetsVerify()  got exception " + ex.Message);
                        Util.Log("DoGetsVerify()  get stacktrace " + ex.StackTrace);
                        throw ex;
                    }
                }
                else
                {
                    cksum = 0;
                }
                Assert.AreEqual(cksum, (uint)putCksum, "DoGetsVerify: " +
                                "Checksums of the values at index {0} differ using GetEntry.",
                                keyIndex);
            }
            Util.Log("DoGetsVerify completed for keyType [{0}], valType [{1}].",
                     m_cKeys[0].CacheableKey.GetType(), GetValueType());
        }
示例#13
0
        public static void Load()
        {
            if (m_Loaded)
            {
                return;
            }

            m_Loaded      = true;
            m_LoadingType = null;

            Console.Write("World: Loading...");

            DateTime start = DateTime.Now;

            m_Loading    = true;
            m_DeleteList = new ArrayList();

            int mobileCount = 0, itemCount = 0, guildCount = 0, regionCount = 0;

            object[] ctorArgs  = new object[1];
            Type[]   ctorTypes = new Type[1] {
                typeof(Serial)
            };

            ArrayList items   = new ArrayList();
            ArrayList mobiles = new ArrayList();
            ArrayList guilds  = new ArrayList();
            ArrayList regions = new ArrayList();

            if (File.Exists(mobIdxPath) && File.Exists(mobTdbPath))
            {
                using (FileStream idx = new FileStream(mobIdxPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryReader idxReader = new BinaryReader(idx);

                    using (FileStream tdb = new FileStream(mobTdbPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        BinaryReader tdbReader = new BinaryReader(tdb);

                        int count = tdbReader.ReadInt32();

                        ArrayList types = new ArrayList(count);

                        for (int i = 0; i < count; ++i)
                        {
                            string typeName = tdbReader.ReadString();

                            Type t = ScriptCompiler.FindTypeByFullName(typeName);

                            if (t == null)
                            {
                                Console.WriteLine("failed");
                                Console.WriteLine("Error: Type '{0}' was not found. Delete all of those types? (y/n)", typeName);

                                if (Console.ReadLine() == "y")
                                {
                                    types.Add(null);
                                    Console.Write("World: Loading...");
                                    continue;
                                }

                                Console.WriteLine("Types will not be deleted. An exception will be thrown when you press return");

                                throw new Exception(String.Format("Bad type '{0}'", typeName));
                            }

                            ConstructorInfo ctor = t.GetConstructor(ctorTypes);

                            if (ctor != null)
                            {
                                types.Add(new object[] { ctor, null });
                            }
                            else
                            {
                                throw new Exception(String.Format("Type '{0}' does not have a serialization constructor", t));
                            }
                        }

                        mobileCount = idxReader.ReadInt32();

                        m_Mobiles = new Hashtable(mobileCount);

                        for (int i = 0; i < mobileCount; ++i)
                        {
                            int  typeID = idxReader.ReadInt32();
                            int  serial = idxReader.ReadInt32();
                            long pos    = idxReader.ReadInt64();
                            int  length = idxReader.ReadInt32();

                            object[] objs = (object[])types[typeID];

                            if (objs == null)
                            {
                                continue;
                            }

                            Mobile          m        = null;
                            ConstructorInfo ctor     = (ConstructorInfo)objs[0];
                            string          typeName = (string)objs[1];

                            try
                            {
                                ctorArgs[0] = (Serial)serial;
                                m           = (Mobile)(ctor.Invoke(ctorArgs));
                            }
                            catch
                            {
                            }

                            if (m != null)
                            {
                                mobiles.Add(new MobileEntry(m, typeID, typeName, pos, length));
                                AddMobile(m);
                            }
                        }

                        tdbReader.Close();
                    }

                    idxReader.Close();
                }
            }
            else
            {
                m_Mobiles = new Hashtable();
            }

            if (File.Exists(itemIdxPath) && File.Exists(itemTdbPath))
            {
                using (FileStream idx = new FileStream(itemIdxPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryReader idxReader = new BinaryReader(idx);

                    using (FileStream tdb = new FileStream(itemTdbPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        BinaryReader tdbReader = new BinaryReader(tdb);

                        int count = tdbReader.ReadInt32();

                        ArrayList types = new ArrayList(count);

                        for (int i = 0; i < count; ++i)
                        {
                            string typeName = tdbReader.ReadString();

                            Type t = ScriptCompiler.FindTypeByFullName(typeName);

                            if (t == null)
                            {
                                Console.WriteLine("failed");
                                Console.WriteLine("Error: Type '{0}' was not found. Delete all of those types? (y/n)", typeName);

                                if (Console.ReadLine() == "y")
                                {
                                    types.Add(null);
                                    Console.Write("World: Loading...");
                                    continue;
                                }

                                Console.WriteLine("Types will not be deleted. An exception will be thrown when you press return");

                                throw new Exception(String.Format("Bad type '{0}'", typeName));
                            }

                            ConstructorInfo ctor = t.GetConstructor(ctorTypes);

                            if (ctor != null)
                            {
                                types.Add(new object[] { ctor, typeName });
                            }
                            else
                            {
                                throw new Exception(String.Format("Type '{0}' does not have a serialization constructor", t));
                            }
                        }

                        itemCount = idxReader.ReadInt32();

                        m_Items = new Hashtable(itemCount);

                        for (int i = 0; i < itemCount; ++i)
                        {
                            int  typeID = idxReader.ReadInt32();
                            int  serial = idxReader.ReadInt32();
                            long pos    = idxReader.ReadInt64();
                            int  length = idxReader.ReadInt32();

                            object[] objs = (object[])types[typeID];

                            if (objs == null)
                            {
                                continue;
                            }

                            Item            item     = null;
                            ConstructorInfo ctor     = (ConstructorInfo)objs[0];
                            string          typeName = (string)objs[1];

                            try
                            {
                                ctorArgs[0] = (Serial)serial;
                                item        = (Item)(ctor.Invoke(ctorArgs));
                            }
                            catch
                            {
                            }

                            if (item != null)
                            {
                                items.Add(new ItemEntry(item, typeID, typeName, pos, length));
                                AddItem(item);
                            }
                        }

                        tdbReader.Close();
                    }

                    idxReader.Close();
                }
            }
            else
            {
                m_Items = new Hashtable();
            }

            if (File.Exists(guildIdxPath))
            {
                using (FileStream idx = new FileStream(guildIdxPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryReader idxReader = new BinaryReader(idx);

                    guildCount = idxReader.ReadInt32();

                    CreateGuildEventArgs createEventArgs = new CreateGuildEventArgs(-1);
                    for (int i = 0; i < guildCount; ++i)
                    {
                        idxReader.ReadInt32();                        //no typeid for guilds
                        int  id     = idxReader.ReadInt32();
                        long pos    = idxReader.ReadInt64();
                        int  length = idxReader.ReadInt32();

                        createEventArgs.Id = id;
                        BaseGuild guild = EventSink.InvokeCreateGuild(createEventArgs);                          //new Guild( id );
                        if (guild != null)
                        {
                            guilds.Add(new GuildEntry(guild, pos, length));
                        }
                    }

                    idxReader.Close();
                }
            }

            if (File.Exists(regionIdxPath))
            {
                using (FileStream idx = new FileStream(regionIdxPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryReader idxReader = new BinaryReader(idx);

                    regionCount = idxReader.ReadInt32();

                    for (int i = 0; i < regionCount; ++i)
                    {
                        int  typeID = idxReader.ReadInt32();
                        int  serial = idxReader.ReadInt32();
                        long pos    = idxReader.ReadInt64();
                        int  length = idxReader.ReadInt32();

                        Region r = Region.FindByUId(serial);

                        if (r != null)
                        {
                            regions.Add(new RegionEntry(r, pos, length));
                            Region.AddRegion(r);
                            regionCount++;
                        }
                    }

                    idxReader.Close();
                }
            }

            bool      failedMobiles = false, failedItems = false, failedGuilds = false, failedRegions = false;
            Type      failedType   = null;
            Serial    failedSerial = Serial.Zero;
            Exception failed       = null;
            int       failedTypeID = 0;

            if (File.Exists(mobBinPath))
            {
                using (FileStream bin = new FileStream(mobBinPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin));

                    for (int i = 0; i < mobiles.Count; ++i)
                    {
                        MobileEntry entry = (MobileEntry)mobiles[i];
                        Mobile      m     = (Mobile)entry.Object;

                        if (m != null)
                        {
                            reader.Seek(entry.Position, SeekOrigin.Begin);

                            try
                            {
                                m_LoadingType = entry.TypeName;
                                m.Deserialize(reader);

                                if (reader.Position != (entry.Position + entry.Length))
                                {
                                    throw new Exception(String.Format("***** Bad serialize on {0} *****", m.GetType()));
                                }
                            }
                            catch (Exception e)
                            {
                                mobiles.RemoveAt(i);

                                failed        = e;
                                failedMobiles = true;
                                failedType    = m.GetType();
                                failedTypeID  = entry.TypeID;
                                failedSerial  = m.Serial;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }
            }

            if (!failedMobiles && File.Exists(itemBinPath))
            {
                using (FileStream bin = new FileStream(itemBinPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin));

                    for (int i = 0; i < items.Count; ++i)
                    {
                        ItemEntry entry = (ItemEntry)items[i];
                        Item      item  = (Item)entry.Object;

                        if (item != null)
                        {
                            reader.Seek(entry.Position, SeekOrigin.Begin);

                            try
                            {
                                m_LoadingType = entry.TypeName;
                                item.Deserialize(reader);

                                if (reader.Position != (entry.Position + entry.Length))
                                {
                                    throw new Exception(String.Format("***** Bad serialize on {0} *****", item.GetType()));
                                }
                            }
                            catch (Exception e)
                            {
                                items.RemoveAt(i);

                                failed       = e;
                                failedItems  = true;
                                failedType   = item.GetType();
                                failedTypeID = entry.TypeID;
                                failedSerial = item.Serial;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }
            }

            m_LoadingType = null;

            if (!failedMobiles && !failedItems && File.Exists(guildBinPath))
            {
                using (FileStream bin = new FileStream(guildBinPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin));

                    for (int i = 0; i < guilds.Count; ++i)
                    {
                        GuildEntry entry = (GuildEntry)guilds[i];
                        BaseGuild  g     = (BaseGuild)entry.Object;

                        if (g != null)
                        {
                            reader.Seek(entry.Position, SeekOrigin.Begin);

                            try
                            {
                                g.Deserialize(reader);

                                if (reader.Position != (entry.Position + entry.Length))
                                {
                                    throw new Exception(String.Format("***** Bad serialize on Guild {0} *****", g.Id));
                                }
                            }
                            catch (Exception e)
                            {
                                guilds.RemoveAt(i);

                                failed       = e;
                                failedGuilds = true;
                                failedType   = typeof(BaseGuild);
                                failedTypeID = g.Id;
                                failedSerial = g.Id;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }
            }

            if (!failedMobiles && !failedItems && File.Exists(regionBinPath))
            {
                using (FileStream bin = new FileStream(regionBinPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin));

                    for (int i = 0; i < regions.Count; ++i)
                    {
                        RegionEntry entry = (RegionEntry)regions[i];
                        Region      r     = (Region)entry.Object;

                        if (r != null)
                        {
                            reader.Seek(entry.Position, SeekOrigin.Begin);

                            try
                            {
                                r.Deserialize(reader);

                                if (reader.Position != (entry.Position + entry.Length))
                                {
                                    throw new Exception(String.Format("***** Bad serialize on {0} *****", r.GetType()));
                                }
                            }
                            catch (Exception e)
                            {
                                regions.RemoveAt(i);

                                failed        = e;
                                failedRegions = true;
                                failedType    = r.GetType();
                                failedTypeID  = entry.TypeID;
                                failedSerial  = r.UId;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }
            }

            if (failedItems || failedMobiles || failedGuilds || failedRegions)
            {
                Console.WriteLine("An error was encountered while loading a saved object");

                Console.WriteLine(" - Type: {0}", failedType);
                Console.WriteLine(" - Serial: {0}", failedSerial);

                Console.WriteLine("Delete the object? (y/n)");

                if (Console.ReadLine() == "y")
                {
                    if (failedType != typeof(BaseGuild) && !failedType.IsSubclassOf(typeof(Region)))
                    {
                        Console.WriteLine("Delete all objects of that type? (y/n)");

                        if (Console.ReadLine() == "y")
                        {
                            if (failedMobiles)
                            {
                                for (int i = 0; i < mobiles.Count;)
                                {
                                    if (((MobileEntry)mobiles[i]).TypeID == failedTypeID)
                                    {
                                        mobiles.RemoveAt(i);
                                    }
                                    else
                                    {
                                        ++i;
                                    }
                                }
                            }
                            else if (failedItems)
                            {
                                for (int i = 0; i < items.Count;)
                                {
                                    if (((ItemEntry)items[i]).TypeID == failedTypeID)
                                    {
                                        items.RemoveAt(i);
                                    }
                                    else
                                    {
                                        ++i;
                                    }
                                }
                            }
                        }
                    }

                    SaveIndex(mobiles, mobIdxPath);
                    SaveIndex(items, itemIdxPath);
                    SaveIndex(guilds, guildIdxPath);
                    SaveIndex(regions, regionIdxPath);
                }

                Console.WriteLine("After pressing return an exception will be thrown and the server will terminate");
                Console.ReadLine();

                throw new Exception(String.Format("Load failed (items={0}, mobiles={1}, guilds={2}, regions={3}, type={4}, serial={5})", failedItems, failedMobiles, failedGuilds, failedRegions, failedType, failedSerial), failed);
            }

            EventSink.InvokeWorldLoad();

            m_Loading = false;

            for (int i = 0; i < m_DeleteList.Count; ++i)
            {
                object o = m_DeleteList[i];

                if (o is Item)
                {
                    ((Item)o).Delete();
                }
                else if (o is Mobile)
                {
                    ((Mobile)o).Delete();
                }
            }

            m_DeleteList.Clear();

            foreach (Item item in m_Items.Values)
            {
                if (item.Parent == null)
                {
                    item.UpdateTotals();
                }

                item.ClearProperties();
            }

            ArrayList list = new ArrayList(m_Mobiles.Values);

            foreach (Mobile m in list)
            {
                m.ForceRegionReEnter(true);
                m.UpdateTotals();

                m.ClearProperties();
            }

            Console.WriteLine("done ({1} items, {2} mobiles) ({0:F1} seconds)", (DateTime.Now - start).TotalSeconds, m_Items.Count, m_Mobiles.Count);
        }
示例#14
0
        private static void LoadEntities()
        {
            ItemEntry[]   itemEntries   = null;
            MobileEntry[] mobileEntries = null;
            GuildEntry[]  guildEntries  = null;
            RegionEntry[] regionEntries = null;

            if (File.Exists(mobIdxPath) && File.Exists(mobTdbPath))
            {
                log.Debug("loading mobile index");
                EntityType[] types = LoadTypes(mobTdbPath);
                mobileEntries = LoadMobileIndex(mobIdxPath, types);
            }
            else
            {
                m_Mobiles = new Hashtable();
            }

            if (File.Exists(itemIdxPath) && File.Exists(itemTdbPath))
            {
                log.Debug("loading item index");
                EntityType[] types = LoadTypes(itemTdbPath);
                itemEntries = LoadItemIndex(itemIdxPath, types);
            }
            else
            {
                m_Items = new Hashtable();
            }

            if (File.Exists(guildIdxPath))
            {
                log.Debug("loading guild index");

                using (FileStream idx = new FileStream(guildIdxPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryReader idxReader = new BinaryReader(idx);

                    int count = idxReader.ReadInt32();
                    guildEntries = new GuildEntry[count];

                    CreateGuildEventArgs createEventArgs = new CreateGuildEventArgs(-1);
                    for (int i = 0; i < count; ++i)
                    {
                        idxReader.ReadInt32();                        //no typeid for guilds
                        int  id     = idxReader.ReadInt32();
                        long pos    = idxReader.ReadInt64();
                        int  length = idxReader.ReadInt32();

                        createEventArgs.Id = id;
                        BaseGuild guild = EventSink.InvokeCreateGuild(createEventArgs);                          //new Guild( id );
                        if (guild != null)
                        {
                            guildEntries[i] = new GuildEntry(guild, pos, length);
                        }
                    }

                    idxReader.Close();
                }
            }

            if (File.Exists(regionIdxPath))
            {
                log.Debug("loading region index");

                using (FileStream idx = new FileStream(regionIdxPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryReader idxReader = new BinaryReader(idx);

                    int count = idxReader.ReadInt32();
                    regionEntries = new RegionEntry[count];

                    for (int i = 0; i < count; ++i)
                    {
                        idxReader.ReadInt32();                         /* typeID */
                        int  serial = idxReader.ReadInt32();
                        long pos    = idxReader.ReadInt64();
                        int  length = idxReader.ReadInt32();

                        Region r = Region.FindByUId(serial);

                        if (r != null)
                        {
                            regionEntries[i] = new RegionEntry(r, pos, length);
                            Region.AddRegion(r);
                        }
                    }

                    idxReader.Close();
                }
            }

            bool      failedMobiles = false, failedItems = false, failedGuilds = false, failedRegions = false;
            Type      failedType   = null;
            Serial    failedSerial = Serial.Zero;
            Exception failed       = null;
            int       failedTypeID = 0;

            if (File.Exists(mobBinPath))
            {
                log.Debug("loading mobiles");

                using (FileStream bin = new FileStream(mobBinPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin));

                    for (int i = 0; i < mobileEntries.Length; ++i)
                    {
                        MobileEntry entry = mobileEntries[i];
                        Mobile      m     = (Mobile)entry.Object;

                        if (m != null)
                        {
                            reader.Seek(entry.Position, SeekOrigin.Begin);

                            try
                            {
                                m_LoadingType = entry.TypeName;
                                m.Deserialize(reader);

                                if (reader.Position != (entry.Position + entry.Length))
                                {
                                    throw new Exception(String.Format("***** Bad serialize on {0} *****", m.GetType()));
                                }
                            }
                            catch (Exception e)
                            {
                                log.Error("failed to load mobile", e);
                                mobileEntries[i].Clear();

                                failed        = e;
                                failedMobiles = true;
                                failedType    = m.GetType();
                                failedTypeID  = entry.TypeID;
                                failedSerial  = m.Serial;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }

                if (!failedMobiles)
                {
                    mobileEntries = null;
                }
            }

            if (!failedMobiles && File.Exists(itemBinPath))
            {
                log.Debug("loading items");

                using (FileStream bin = new FileStream(itemBinPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin));

                    for (int i = 0; i < itemEntries.Length; ++i)
                    {
                        ItemEntry entry = itemEntries[i];
                        Item      item  = (Item)entry.Object;

                        if (item != null)
                        {
                            reader.Seek(entry.Position, SeekOrigin.Begin);

                            try
                            {
                                m_LoadingType = entry.TypeName;
                                item.Deserialize(reader);

                                if (reader.Position != (entry.Position + entry.Length))
                                {
                                    throw new Exception(String.Format("***** Bad serialize on {0} *****", item.GetType()));
                                }
                            }
                            catch (Exception e)
                            {
                                log.Fatal("failed to load item", e);
                                itemEntries[i].Clear();

                                failed       = e;
                                failedItems  = true;
                                failedType   = item.GetType();
                                failedTypeID = entry.TypeID;
                                failedSerial = item.Serial;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }

                if (!failedItems)
                {
                    itemEntries = null;
                }
            }

            if (!failedMobiles && !failedItems && File.Exists(guildBinPath))
            {
                log.Debug("loading guilds");

                using (FileStream bin = new FileStream(guildBinPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin));

                    for (int i = 0; i < guildEntries.Length; ++i)
                    {
                        GuildEntry entry = guildEntries[i];
                        BaseGuild  g     = (BaseGuild)entry.Object;

                        if (g != null)
                        {
                            reader.Seek(entry.Position, SeekOrigin.Begin);

                            try
                            {
                                g.Deserialize(reader);

                                if (reader.Position != (entry.Position + entry.Length))
                                {
                                    throw new Exception(String.Format("***** Bad serialize on Guild {0} *****", g.Id));
                                }
                            }
                            catch (Exception e)
                            {
                                log.Fatal("failed to load guild", e);
                                guildEntries[i].Clear();

                                failed       = e;
                                failedGuilds = true;
                                failedType   = typeof(BaseGuild);
                                failedTypeID = g.Id;
                                failedSerial = g.Id;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }

                if (!failedGuilds)
                {
                    guildEntries = null;
                }
            }

            if (!failedMobiles && !failedItems && File.Exists(regionBinPath))
            {
                log.Debug("loading regions");

                using (FileStream bin = new FileStream(regionBinPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin));

                    for (int i = 0; i < regionEntries.Length; ++i)
                    {
                        RegionEntry entry = regionEntries[i];
                        Region      r     = (Region)entry.Object;

                        if (r != null)
                        {
                            reader.Seek(entry.Position, SeekOrigin.Begin);

                            try
                            {
                                r.Deserialize(reader);

                                if (reader.Position != (entry.Position + entry.Length))
                                {
                                    throw new Exception(String.Format("***** Bad serialize on {0} *****", r.GetType()));
                                }
                            }
                            catch (Exception e)
                            {
                                log.Fatal("failed to load region", e);
                                regionEntries[i].Clear();

                                failed        = e;
                                failedRegions = true;
                                failedType    = r.GetType();
                                failedTypeID  = entry.TypeID;
                                failedSerial  = r.UId;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }

                if (!failedRegions)
                {
                    regionEntries = null;
                }
            }

            if (failedItems || failedMobiles || failedGuilds || failedRegions)
            {
                Console.WriteLine("An error was encountered while loading a saved object");

                Console.WriteLine(" - Type: {0}", failedType);
                Console.WriteLine(" - Serial: {0}", failedSerial);

                Console.WriteLine("Delete the object? (y/n)");

                if (Console.ReadLine() == "y")
                {
                    if (failedType != typeof(BaseGuild) && !failedType.IsSubclassOf(typeof(Region)))
                    {
                        Console.WriteLine("Delete all objects of that type? (y/n)");

                        if (Console.ReadLine() == "y")
                        {
                            if (failedMobiles)
                            {
                                for (int i = 0; i < mobileEntries.Length; ++i)
                                {
                                    if (mobileEntries[i].TypeID == failedTypeID)
                                    {
                                        mobileEntries[i].Clear();
                                    }
                                }
                            }
                            else if (failedItems)
                            {
                                for (int i = 0; i < itemEntries.Length; ++i)
                                {
                                    if (itemEntries[i].TypeID == failedTypeID)
                                    {
                                        itemEntries[i].Clear();
                                    }
                                }
                            }
                        }
                    }

                    if (mobileEntries != null)
                    {
                        SaveIndex(mobileEntries, mobIdxPath);
                    }
                    if (itemEntries != null)
                    {
                        SaveIndex(itemEntries, itemIdxPath);
                    }
                    if (guildEntries != null)
                    {
                        SaveIndex(guildEntries, guildIdxPath);
                    }
                    if (regionEntries != null)
                    {
                        SaveIndex(regionEntries, regionIdxPath);
                    }
                }

                Console.WriteLine("After pressing return an exception will be thrown and the server will terminate");
                Console.ReadLine();

                throw new Exception(String.Format("Load failed (items={0}, mobiles={1}, guilds={2}, regions={3}, type={4}, serial={5})", failedItems, failedMobiles, failedGuilds, failedRegions, failedType, failedSerial), failed);
            }
        }
示例#15
0
        private static void LoadEntities()
        {
            ItemEntry[] itemEntries = null;
            MobileEntry[] mobileEntries = null;
            GuildEntry[] guildEntries = null;
            RegionEntry[] regionEntries = null;

            if ( File.Exists( mobIdxPath ) && File.Exists( mobTdbPath ) )
            {
                log.Debug("loading mobile index");
                EntityType[] types = LoadTypes(mobTdbPath);
                mobileEntries = LoadMobileIndex(mobIdxPath, types);
            }
            else
            {
                m_Mobiles = new Hashtable();
            }

            if ( File.Exists( itemIdxPath ) && File.Exists( itemTdbPath ) )
            {
                log.Debug("loading item index");
                EntityType[] types = LoadTypes(itemTdbPath);
                itemEntries = LoadItemIndex(itemIdxPath, types);
            }
            else
            {
                m_Items = new Hashtable();
            }

            if ( File.Exists( guildIdxPath ) )
            {
                log.Debug("loading guild index");

                using ( FileStream idx = new FileStream( guildIdxPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
                {
                    BinaryReader idxReader = new BinaryReader( idx );

                    int count = idxReader.ReadInt32();
                    guildEntries = new GuildEntry[count];

                    CreateGuildEventArgs createEventArgs = new CreateGuildEventArgs( -1 );
                    for ( int i = 0; i < count; ++i )
                    {
                        idxReader.ReadInt32();//no typeid for guilds
                        int id = idxReader.ReadInt32();
                        long pos = idxReader.ReadInt64();
                        int length = idxReader.ReadInt32();

                        createEventArgs.Id = id;
                        BaseGuild guild = EventSink.InvokeCreateGuild( createEventArgs );//new Guild( id );
                        if ( guild != null )
                            guildEntries[i] = new GuildEntry( guild, pos, length );
                    }

                    idxReader.Close();
                }
            }

            if ( File.Exists( regionIdxPath ) )
            {
                log.Debug("loading region index");

                using ( FileStream idx = new FileStream( regionIdxPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
                {
                    BinaryReader idxReader = new BinaryReader( idx );

                    int count = idxReader.ReadInt32();
                    regionEntries = new RegionEntry[count];

                    for ( int i = 0; i < count; ++i )
                    {
                        idxReader.ReadInt32(); /* typeID */
                        int serial = idxReader.ReadInt32();
                        long pos = idxReader.ReadInt64();
                        int length = idxReader.ReadInt32();

                        Region r = Region.FindByUId( serial );

                        if ( r != null )
                        {
                            regionEntries[i] = new RegionEntry( r, pos, length );
                            Region.AddRegion( r );
                        }
                    }

                    idxReader.Close();
                }
            }

            bool failedMobiles = false, failedItems = false, failedGuilds = false, failedRegions = false;
            Type failedType = null;
            Serial failedSerial = Serial.Zero;
            Exception failed = null;
            int failedTypeID = 0;

            if ( File.Exists( mobBinPath ) )
            {
                log.Debug("loading mobiles");

                using ( FileStream bin = new FileStream( mobBinPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
                {
                    BinaryFileReader reader = new BinaryFileReader( new BinaryReader( bin ) );

                    for ( int i = 0; i < mobileEntries.Length; ++i )
                    {
                        MobileEntry entry = mobileEntries[i];
                        Mobile m = (Mobile)entry.Object;

                        if ( m != null )
                        {
                            reader.Seek( entry.Position, SeekOrigin.Begin );

                            try
                            {
                                m_LoadingType = entry.TypeName;
                                m.Deserialize( reader );

                                if ( reader.Position != (entry.Position + entry.Length) )
                                    throw new Exception( String.Format( "***** Bad serialize on {0} *****", m.GetType() ) );
                            }
                            catch ( Exception e )
                            {
                                log.Error("failed to load mobile", e);
                                mobileEntries[i].Clear();

                                failed = e;
                                failedMobiles = true;
                                failedType = m.GetType();
                                failedTypeID = entry.TypeID;
                                failedSerial = m.Serial;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }

                if (!failedMobiles)
                    mobileEntries = null;
            }

            if ( !failedMobiles && File.Exists( itemBinPath ) )
            {
                log.Debug("loading items");

                using ( FileStream bin = new FileStream( itemBinPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
                {
                    BinaryFileReader reader = new BinaryFileReader( new BinaryReader( bin ) );

                    for ( int i = 0; i < itemEntries.Length; ++i )
                    {
                        ItemEntry entry = itemEntries[i];
                        Item item = (Item)entry.Object;

                        if ( item != null )
                        {
                            reader.Seek( entry.Position, SeekOrigin.Begin );

                            try
                            {
                                m_LoadingType = entry.TypeName;
                                item.Deserialize( reader );

                                if ( reader.Position != (entry.Position + entry.Length) )
                                    throw new Exception( String.Format( "***** Bad serialize on {0} *****", item.GetType() ) );
                            }
                            catch ( Exception e )
                            {
                                log.Fatal("failed to load item", e);
                                itemEntries[i].Clear();

                                failed = e;
                                failedItems = true;
                                failedType = item.GetType();
                                failedTypeID = entry.TypeID;
                                failedSerial = item.Serial;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }

                if (!failedItems)
                    itemEntries = null;
            }

            if ( !failedMobiles && !failedItems && File.Exists( guildBinPath ) )
            {
                log.Debug("loading guilds");

                using ( FileStream bin = new FileStream( guildBinPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
                {
                    BinaryFileReader reader = new BinaryFileReader( new BinaryReader( bin ) );

                    for ( int i = 0; i < guildEntries.Length; ++i )
                    {
                        GuildEntry entry = guildEntries[i];
                        BaseGuild g = (BaseGuild)entry.Object;

                        if ( g != null )
                        {
                            reader.Seek( entry.Position, SeekOrigin.Begin );

                            try
                            {
                                g.Deserialize( reader );

                                if ( reader.Position != (entry.Position + entry.Length) )
                                    throw new Exception( String.Format( "***** Bad serialize on Guild {0} *****", g.Id ) );
                            }
                            catch ( Exception e )
                            {
                                log.Fatal("failed to load guild", e);
                                guildEntries[i].Clear();

                                failed = e;
                                failedGuilds = true;
                                failedType = typeof( BaseGuild );
                                failedTypeID = g.Id;
                                failedSerial = g.Id;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }

                if (!failedGuilds)
                    guildEntries = null;
            }

            if ( !failedMobiles && !failedItems && File.Exists( regionBinPath ) )
            {
                log.Debug("loading regions");

                using ( FileStream bin = new FileStream( regionBinPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
                {
                    BinaryFileReader reader = new BinaryFileReader( new BinaryReader( bin ) );

                    for ( int i = 0; i < regionEntries.Length; ++i )
                    {
                        RegionEntry entry = regionEntries[i];
                        Region r = (Region)entry.Object;

                        if ( r != null )
                        {
                            reader.Seek( entry.Position, SeekOrigin.Begin );

                            try
                            {
                                r.Deserialize( reader );

                                if ( reader.Position != (entry.Position + entry.Length) )
                                    throw new Exception( String.Format( "***** Bad serialize on {0} *****", r.GetType() ) );
                            }
                            catch ( Exception e )
                            {
                                log.Fatal("failed to load region", e);
                                regionEntries[i].Clear();

                                failed = e;
                                failedRegions = true;
                                failedType = r.GetType();
                                failedTypeID = entry.TypeID;
                                failedSerial = r.UId;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }

                if (!failedRegions)
                    regionEntries = null;
            }

            if ( failedItems || failedMobiles || failedGuilds || failedRegions )
            {
                Console.WriteLine( "An error was encountered while loading a saved object" );

                Console.WriteLine( " - Type: {0}", failedType );
                Console.WriteLine( " - Serial: {0}", failedSerial );

                Console.WriteLine( "Delete the object? (y/n)" );

                if ( Console.ReadLine() == "y" )
                {
                    if ( failedType != typeof( BaseGuild ) && !failedType.IsSubclassOf( typeof( Region ) ) )
                    {
                        Console.WriteLine( "Delete all objects of that type? (y/n)" );

                        if ( Console.ReadLine() == "y" )
                        {
                            if ( failedMobiles )
                            {
                                for ( int i = 0; i < mobileEntries.Length; ++i)
                                {
                                    if (mobileEntries[i].TypeID == failedTypeID)
                                        mobileEntries[i].Clear();
                                }
                            }
                            else if ( failedItems )
                            {
                                for ( int i = 0; i < itemEntries.Length; ++i)
                                {
                                    if (itemEntries[i].TypeID == failedTypeID)
                                        itemEntries[i].Clear();
                                }
                            }
                        }
                    }

                    if (mobileEntries != null)
                        SaveIndex( mobileEntries, mobIdxPath );
                    if (itemEntries != null)
                        SaveIndex( itemEntries, itemIdxPath );
                    if (guildEntries != null)
                        SaveIndex( guildEntries, guildIdxPath );
                    if (regionEntries != null)
                        SaveIndex( regionEntries, regionIdxPath );
                }

                Console.WriteLine( "After pressing return an exception will be thrown and the server will terminate" );
                Console.ReadLine();

                throw new Exception( String.Format( "Load failed (items={0}, mobiles={1}, guilds={2}, regions={3}, type={4}, serial={5})", failedItems, failedMobiles, failedGuilds, failedRegions, failedType, failedSerial ), failed );
            }
        }