コード例 #1
0
		public static void SerializeMessages()
		{
			if( !Directory.Exists( SavePath ) )
				Directory.CreateDirectory( SavePath );

			BinaryFileWriter writer = new BinaryFileWriter( SaveFile, true );

			writer.Write( (int)_messageTable.Count );

			if( _messageTable.Count > 0 )
			{
				foreach( KeyValuePair<Mobile, List<ChatMessage>> kvp in _messageTable )
				{
					if( kvp.Key == null || kvp.Key.Deleted || kvp.Value == null )
					{
						writer.Write( (int)-1 );
					}
					else
					{
						writer.Write( (int)kvp.Key.Serial );

						writer.Write( (int)kvp.Value.Count );
						kvp.Value.ForEach(
							delegate( ChatMessage message )
							{
								message.Serialize( writer );
							} );
					}
				}
			}

			writer.Close();
		}
コード例 #2
0
ファイル: Persistence.cs プロジェクト: Crome696/ServUO
		public static void Serialize(FileInfo file, Action<GenericWriter> serializer)
		{
			file.Refresh();

			if (file.Directory != null && !file.Directory.Exists)
			{
				file.Directory.Create();
			}

			if (!file.Exists)
			{
				file.Create().Close();
			}
				
			file.Refresh();

			using (var fs = file.OpenWrite())
			{
				var writer = new BinaryFileWriter(fs, true);

				try
				{
					serializer(writer);
				}
				finally
				{
					writer.Flush();
					writer.Close();
				}
			}
		}
コード例 #3
0
        public static void CustomSeperateSave(SeperateSaveData data)
        {
            GenericWriter writer = new BinaryFileWriter(Path.Combine(data.SaveLocation, data.SaveName + ".bin"), true);
            DirectoryCheck(data.SaveLocation);

            data.SaveMethod(writer);
            writer.Write(writer.Position);
            writer.Close();
        }
コード例 #4
0
ファイル: GumpInfo.cs プロジェクト: Jascen/UOSmart
		public static void Save()
		{
            try
            {
                if (!Directory.Exists(General.SavePath))
                    Directory.CreateDirectory(General.SavePath);

                GenericWriter writer = new BinaryFileWriter(Path.Combine(General.SavePath, "Gumps.bin"), true);

                writer.Write(0); // version

                writer.Write(s_ForceMenu);
                writer.Write(s_ForceInfos.Count);
                foreach (GumpInfo ginfo in s_ForceInfos.Values)
                    ginfo.Save(writer);

                ArrayList list = new ArrayList();
                GumpInfo info;

                foreach (object o in new ArrayList(s_Infos.Values))
                {
                    if (!(o is Hashtable))
                        continue;

                    foreach (object ob in new ArrayList(((Hashtable)o).Values))
                    {
                        if (!(ob is GumpInfo))
                            continue;

                        info = (GumpInfo)ob;

                        if (info.Mobile != null
                        && info.Mobile.Player
                        && !info.Mobile.Deleted
                        && info.Mobile.Account != null
                        && ((Account)info.Mobile.Account).LastLogin > DateTime.Now - TimeSpan.FromDays(30))
                            list.Add(ob);
                    }
                }

                writer.Write(list.Count);

                foreach (GumpInfo ginfo in list)
                    ginfo.Save(writer);

                writer.Close();
            }
            catch (Exception e)
            {
                Errors.Report(General.Local(199));
                Console.WriteLine(e.Message);
                Console.WriteLine(e.Source);
                Console.WriteLine(e.StackTrace);
            }
		}
コード例 #5
0
ファイル: StandardSaveStrategy.cs プロジェクト: rokann/JustUO
		protected void SaveMobiles(SaveMetrics metrics)
		{
			Dictionary<Serial, Mobile> mobiles = World.Mobiles;

			GenericWriter idx;
			GenericWriter tdb;
			GenericWriter bin;

			if (UseSequentialWriters)
			{
				idx = new BinaryFileWriter(World.MobileIndexPath, false);
				tdb = new BinaryFileWriter(World.MobileTypesPath, false);
				bin = new BinaryFileWriter(World.MobileDataPath, true);
			}
			else
			{
				idx = new AsyncWriter(World.MobileIndexPath, false);
				tdb = new AsyncWriter(World.MobileTypesPath, false);
				bin = new AsyncWriter(World.MobileDataPath, true);
			}

			idx.Write(mobiles.Count);

			foreach (Mobile m in mobiles.Values)
			{
				long start = bin.Position;

				idx.Write(m._TypeRef);
				idx.Write(m.Serial);
				idx.Write(start);

				m.Serialize(bin);

				if (metrics != null)
				{
					metrics.OnMobileSaved((int)(bin.Position - start));
				}

				idx.Write((int)(bin.Position - start));

				m.FreeCache();
			}

			tdb.Write(World.m_MobileTypes.Count);

			foreach (Type t in World.m_MobileTypes)
			{
				tdb.Write(t.FullName);
			}

			idx.Close();
			tdb.Close();
			bin.Close();
		}
コード例 #6
0
		protected void SaveMobiles( SaveMetrics metrics ) {
			Dictionary<Serial, Mobile> mobiles = World.Mobiles;

			GenericWriter idx;
			GenericWriter tdb;
			GenericWriter bin;

			if ( World.SaveType == World.SaveOption.Normal ) {
				idx = new BinaryFileWriter( World.MobileIndexPath, false );
				tdb = new BinaryFileWriter( World.MobileTypesPath, false );
				bin = new BinaryFileWriter( World.MobileDataPath, true );
			} else {
				idx = new AsyncWriter( World.MobileIndexPath, false );
				tdb = new AsyncWriter( World.MobileTypesPath, false );
				bin = new AsyncWriter( World.MobileDataPath, true );
			}

			idx.Write( ( int ) mobiles.Count );
			foreach ( Mobile m in mobiles.Values ) {
				long start = bin.Position;

				idx.Write( ( int ) m.m_TypeRef );
				idx.Write( ( int ) m.Serial );
				idx.Write( ( long ) start );

				m.Serialize( bin );

				if ( metrics != null ) {
					metrics.OnMobileSaved( ( int ) ( bin.Position - start ) );
				}

				idx.Write( ( int ) ( bin.Position - start ) );

				m.FreeCache();
			}

			tdb.Write( ( int ) World.m_MobileTypes.Count );

			for ( int i = 0; i < World.m_MobileTypes.Count; ++i )
				tdb.Write( World.m_MobileTypes[i].FullName );

			idx.Close();
			tdb.Close();
			bin.Close();
		}
コード例 #7
0
		private static void OnSave( WorldSaveEventArgs e )
		{try{

			if ( !Directory.Exists( "Saves/Gumps/" ) )
				Directory.CreateDirectory( "Saves/Gumps/" );

			GenericWriter writer = new BinaryFileWriter( Path.Combine( "Saves/Gumps/", "Gumps.bin" ), true );

			writer.Write( 0 ); // version

			ArrayList list = new ArrayList();

			GumpInfo gumpi;
			foreach( object obj in new ArrayList( s_Infos.Values ) )
			{
				if ( !(obj is Hashtable) )
					continue;

				foreach( object obje in new ArrayList( ((Hashtable)obj).Values ) )
				{
					if ( !(obje is GumpInfo ) )
						continue;

					gumpi = (GumpInfo)obje;

					if ( gumpi.Mobile != null
					&& gumpi.Mobile.Player
					&& !gumpi.Mobile.Deleted
					&& gumpi.Mobile.Account != null
					&& ((Account)gumpi.Mobile.Account).LastLogin > DateTime.Now - TimeSpan.FromDays( 30 ) )
						list.Add( obje );
				}
			}

			writer.Write( list.Count );

			foreach( GumpInfo info in list )
				info.Save( writer );

			writer.Close();

		}catch{ Errors.Report( "GumpInfo-> OnSave" ); } }
コード例 #8
0
        private static void SaveGuilds(string guildBase)
        {
            string guildIdxPath = Path.Combine(guildBase, "Guilds.idx");
            string guildBinPath = Path.Combine(guildBase, "Guilds.bin");

            GenericWriter idx;
            GenericWriter bin;

            if (!Directory.Exists(guildBase))
            {
                Directory.CreateDirectory(guildBase);
            }

            if (SaveType == SaveOption.Normal)
            {
                idx = new BinaryFileWriter(guildIdxPath, false);
                bin = new BinaryFileWriter(guildBinPath, true);
            }
            else
            {
                idx = new AsyncWriter(guildIdxPath, false);
                bin = new AsyncWriter(guildBinPath, true);
            }

            idx.Write((int)BaseGuild.List.Count);
            foreach (BaseGuild guild in BaseGuild.List.Values)
            {
                long start = bin.Position;

                idx.Write((int)0);                  //guilds have no typeid
                idx.Write((int)guild.Id);
                idx.Write((long)start);

                guild.Serialize(bin);

                idx.Write((int)(bin.Position - start));
            }

            idx.Close();
            bin.Close();
        }
コード例 #9
0
        protected void SaveData()
        {
            Dictionary <CustomSerial, SaveData> data = World.Data;

            GenericWriter indexWriter;
            GenericWriter typeWriter;
            GenericWriter dataWriter;

            indexWriter = new BinaryFileWriter(World.DataIndexPath, false);
            typeWriter  = new BinaryFileWriter(World.DataTypesPath, false);
            dataWriter  = new BinaryFileWriter(World.DataBinaryPath, true);


            indexWriter.Write(data.Count);

            foreach (SaveData saveData in data.Values)
            {
                long start = dataWriter.Position;

                indexWriter.Write(saveData._TypeID);
                indexWriter.Write((int)saveData.Serial);
                indexWriter.Write(start);

                saveData.Serialize(dataWriter);



                indexWriter.Write((int)(dataWriter.Position - start));
            }

            typeWriter.Write(World._DataTypes.Count);

            for (int i = 0; i < World._DataTypes.Count; ++i)
            {
                typeWriter.Write(World._DataTypes[i].FullName);
            }

            indexWriter.Close();
            typeWriter.Close();
            dataWriter.Close();
        }
コード例 #10
0
ファイル: SQL.cs プロジェクト: keninishna/ServUO-master
        protected void SaveDataSQL()
        {
            Dictionary <CustomSerial, SaveData> data = World.Data;
            List <Database.SaveData>            s    = new List <Database.SaveData>();
            List <Database.SaveDataIndex>       si   = new List <Database.SaveDataIndex>();

            foreach (SaveData saveData in World.BuffSaveData)
            {
                MemoryStream  stream = new MemoryStream();
                GenericWriter bin    = new BinaryFileWriter(stream, true);

                Database.SaveData sd = new Database.SaveData();
                sd.TypeID = saveData._TypeID;
                sd.Serial = (int)saveData.Serial;
                sd.Id     = (int)saveData.Serial;
                saveData.Serialize(sd);
                saveData.Serialize(bin);
                bin.Close();
                sd.Serialized = Convert.ToBase64String(stream.ToArray());
                s.Add(sd);
                stream.Close();
            }

            for (int i = 0; i < World._DataTypes.Count; ++i)
            {
                Database.SaveDataIndex sdi = new Database.SaveDataIndex();
                sdi.DataTypes = World._DataTypes[i].FullName;
                sdi.Id        = i;
                si.Add(sdi);
            }

            using (Database.UODataContext writedb = new Database.UODataContext(Core.SQLConnect))
            {
                Database.LinqExtension.Truncate(writedb.SaveDataIndexes); //drop items table
                Database.LinqExtension.Truncate(writedb.SaveDatas);       //drop items table
                writedb.BulkInsertAll(si);                                //bulk insert items
                writedb.BulkInsertAll(s);                                 //bulk insert items
            }
        }
コード例 #11
0
ファイル: StandardSaveStrategy.cs プロジェクト: jaedan/runuo
        protected void SaveGuilds(SaveMetrics metrics)
        {
            GenericWriter idx;
            GenericWriter bin;

            if (UseSequentialWriters)
            {
                idx = new BinaryFileWriter(World.GuildIndexPath, false);
                bin = new BinaryFileWriter(World.GuildDataPath, true);
            }
            else
            {
                idx = new AsyncWriter(World.GuildIndexPath, false);
                bin = new AsyncWriter(World.GuildDataPath, true);
            }

            idx.Write((int)BaseGuild.List.Count);
            foreach (BaseGuild guild in BaseGuild.List.Values)
            {
                long start = bin.Position;

                idx.Write((int)0);//guilds have no typeid
                idx.Write((int)guild.Id);
                idx.Write((long)start);

                guild.Serialize(bin);

                if (metrics != null)
                {
                    metrics.OnGuildSaved((int)(bin.Position - start));
                }

                idx.Write((int)(bin.Position - start));
            }

            idx.Close();
            bin.Close();
        }
コード例 #12
0
        protected void SaveItems(SaveMetrics metrics)
        {
            Dictionary <Serial, Item> items = World.Items;
            List <Item> decaying            = new List <Item>();

            GenericWriter idx;
            GenericWriter tdb;
            GenericWriter bin;

            if (World.SaveType == World.SaveOption.Normal)
            {
                idx = new BinaryFileWriter(World.ItemIndexPath, false);
                tdb = new BinaryFileWriter(World.ItemTypesPath, false);
                bin = new BinaryFileWriter(World.ItemDataPath, true);
            }
            else
            {
                idx = new AsyncWriter(World.ItemIndexPath, false);
                tdb = new AsyncWriter(World.ItemTypesPath, false);
                bin = new AsyncWriter(World.ItemDataPath, true);
            }

            idx.Write(( int )items.Count);
            foreach (Item item in items.Values)
            {
                if (item.Decays && item.Parent == null && item.Map != Map.Internal && (item.LastMoved + item.DecayTime) <= DateTime.Now)
                {
                    decaying.Add(item);
                }

                long start = bin.Position;

                idx.Write(( int )item.m_TypeRef);
                idx.Write(( int )item.Serial);
                idx.Write(( long )start);

                item.Serialize(bin);

                if (metrics != null)
                {
                    metrics.OnItemSaved(( int )(bin.Position - start));
                }

                idx.Write(( int )(bin.Position - start));

                item.FreeCache();
            }

            tdb.Write(( int )World.m_ItemTypes.Count);
            for (int i = 0; i < World.m_ItemTypes.Count; ++i)
            {
                tdb.Write(World.m_ItemTypes[i].FullName);
            }

            idx.Close();
            tdb.Close();
            bin.Close();

            for (int i = 0; i < decaying.Count; ++i)
            {
                Item item = decaying[i];

                if (item.OnDecay())
                {
                    item.Delete();
                }
            }
        }
コード例 #13
0
        private static void CustomSave()
        {
            DirectoryCheck(m_FilePath);

            GenericWriter idx = new BinaryFileWriter(m_FullPath + ".idx", true);
            GenericWriter bin = new BinaryFileWriter(m_FullPath + ".bin", true);

            idx.Write(m_DataDictionary.Count);
            foreach (KeyValuePair<string, SaveData> kv in m_DataDictionary)
            {
                idx.Write(kv.Key);
                idx.Write(bin.Position);
                kv.Value.SaveMethod(bin);
                idx.Write(bin.Position);
            }

            idx.Close();
            bin.Close();
        }
コード例 #14
0
ファイル: World.cs プロジェクト: BackupTheBerlios/sunuo-svn
        private static void SaveMobiles(string mobileBase)
        {
            ArrayList restock = new ArrayList();

            GenericWriter idx;
            GenericWriter tdb;
            GenericWriter bin;

            if (!Directory.Exists(mobileBase))
            {
                Directory.CreateDirectory(mobileBase);
            }

            string mobIdxPath = Path.Combine(mobileBase, "Mobiles.idx");
            string mobTdbPath = Path.Combine(mobileBase, "Mobiles.tdb");
            string mobBinPath = Path.Combine(mobileBase, "Mobiles.bin");

            if (SaveType == SaveOption.Normal)
            {
                idx = new BinaryFileWriter(mobIdxPath, false);
                tdb = new BinaryFileWriter(mobTdbPath, false);
                bin = new BinaryFileWriter(mobBinPath, true);
            }
            else
            {
                idx = new AsyncWriter(mobIdxPath, false);
                tdb = new AsyncWriter(mobTdbPath, false);
                bin = new AsyncWriter(mobBinPath, true);
            }

            idx.Write((int)m_Mobiles.Count);
            foreach (Mobile m in m_Mobiles.Values)
            {
                long start = bin.Position;

                idx.Write((int)m.m_TypeRef);
                idx.Write((int)m.Serial);
                idx.Write((long)start);

                m.Serialize(bin);

                idx.Write((int)(bin.Position - start));

                if (m is IVendor)
                {
                    if (((IVendor)m).LastRestock + ((IVendor)m).RestockDelay < Core.Now)
                    {
                        restock.Add(m);
                    }
                }

                m.FreeCache();
            }

            tdb.Write((int)m_MobileTypes.Count);
            for (int i = 0; i < m_MobileTypes.Count; ++i)
            {
                tdb.Write(((Type)m_MobileTypes[i]).FullName);
            }

            for (int i = 0; i < restock.Count; i++)
            {
                IVendor vend = (IVendor)restock[i];
                vend.Restock();
                vend.LastRestock = Core.Now;
            }

            idx.Close();
            tdb.Close();
            bin.Close();
        }
コード例 #15
0
ファイル: Alliances.cs プロジェクト: greeduomacro/hubroot
        public static void Serialize(BinaryFileWriter writer)
        {
            writer.Write((int)0); //Version

            writer.Write((int)AllianceLimit);
            writer.Write((bool)useXML);
            writer.Write((int)Alliances.Count);

            foreach (BaseAlliance a in Alliances)
            {
                a.Serialize(writer);
            }

            writer.Close();
        }
コード例 #16
0
ファイル: ACC.cs プロジェクト: greeduomacro/cov-shard-svn-1
		public static void Save( WorldSaveEventArgs args )
		{
			if( !Directory.Exists( "Saves/ACC" ) )
				Directory.CreateDirectory( "Saves/ACC" );

			string filename = "acc.sav";
			string path =@"Saves/ACC/";
			string pathNfile = path+filename;
			DateTime start = DateTime.Now;

			Console.WriteLine();
			Console.WriteLine();
			Console.WriteLine( "----------" );
			Console.WriteLine( "Saving ACC..." );

			try
			{
				using( FileStream m_FileStream = new FileStream( pathNfile, FileMode.OpenOrCreate, FileAccess.Write ) )
				{
					BinaryFileWriter writer = new BinaryFileWriter( m_FileStream, true );

					writer.Write( (int) m_RegSystems.Count );
					foreach( DictionaryEntry de in m_RegSystems )
					{
						Type t = ScriptCompiler.FindTypeByFullName( (string)de.Key );
						if( t != null )
						{
							writer.Write( (string)de.Key );
							writer.Write( (bool)de.Value );

							if( (bool)m_RegSystems[(string)de.Key] )
							{
								ACCSystem system = (ACCSystem)Activator.CreateInstance( t );
								if( system != null )
									system.StartSave( path );
							}
						}

					}

					writer.Close();
					m_FileStream.Close();
				}

				Console.WriteLine( "Done in {0:F1} seconds.", (DateTime.Now-start).TotalSeconds );
				Console.WriteLine( "----------" );
				Console.WriteLine();
			}
			catch( Exception err )
			{
				Console.WriteLine( "Failed. Exception: "+err );
			}
		}
コード例 #17
0
        public static void Save(WorldSaveEventArgs e)
        {
            if (!Directory.Exists("LokaiSaves/LokaiSkills"))
            {
                Directory.CreateDirectory("LokaiSaves/LokaiSkills");
            }
            string           filePath = Path.Combine("LokaiSaves/LokaiSkills", "LokaiSkills.bin");
            BinaryFileWriter writer   = null;

            try
            {
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                Console.WriteLine(".bin file successfully deleted.");
            }
            catch (Exception err)
            {
                Console.WriteLine("Unable to delete the BinaryFileWriter so exiting SAVE process.");
                Console.WriteLine(err.ToString());
                return;
            }
            try
            {
                writer = new BinaryFileWriter(filePath, true);
            }
            catch
            {
                Console.WriteLine("Unable to create new BinaryFileWriter so exiting SAVE process.");
                return;
            }
            writer.WriteEncodedInt((int)0); //version

            writer.WriteEncodedInt((int)m_LinguisticsLevel);
            writer.Write(m_CommerceEnabled);
            writer.Write(m_RidingChecksEnabled);
            writer.Write(m_SailingChecksEnabled);
            writer.Write(m_LinguisticsEnabled);

            writer.Write(ShowButchering);
            writer.Write(ShowSkinning);
            writer.Write(ShowAnimalRiding);
            writer.Write(ShowSailing);
            writer.Write(ShowDetectEvil);
            writer.Write(ShowCureDisease);
            writer.Write(ShowPickPocket);
            writer.Write(ShowPilfering);
            writer.Write(ShowFraming);
            writer.Write(ShowBrickLaying);
            writer.Write(ShowRoofing);
            writer.Write(ShowStoneMasonry);
            writer.Write(ShowVentriloquism);
            writer.Write(ShowHypnotism);
            writer.Write(ShowPreyTracking);
            writer.Write(ShowSpeakToAnimals);
            writer.Write(ShowWoodworking);
            writer.Write(ShowCooperage);
            writer.Write(ShowSpinning);
            writer.Write(ShowWeaving);
            writer.Write(ShowConstruction);
            writer.Write(ShowCommerce);
            writer.Write(ShowBrewing);
            writer.Write(ShowHerblore);
            writer.Write(ShowTreePicking);
            writer.Write(ShowTreeSapping);
            writer.Write(ShowTreeCarving);
            writer.Write(ShowTreeDigging);
            writer.Write(ShowTeaching);
            writer.Write(ShowLinguistics);
            writer.Close();
            Console.WriteLine("All LokaiSkill values successfully written to .bin file. File closed.");
        }
コード例 #18
0
        public static void Save()
        {
            log.Info("Saving...");
            log.Info(String.Format("idxPath: '{0}'", idxPath));
            log.Info(String.Format("binPath: '{0}'", binPath));

            if (!Directory.Exists(Path.Combine("Saves", "Donation")))
                Directory.CreateDirectory(Path.Combine("Saves", "Donation"));

            GenericWriter idx = new BinaryFileWriter(idxPath, false);
            GenericWriter bin = new BinaryFileWriter(binPath, true);

            log.Info(String.Format("m_ClaimedOrders.Count: '{0}'", m_ClaimedOrders.Count));
            idx.Write((int)m_ClaimedOrders.Count);
            foreach (ClaimedOrder claimed in m_ClaimedOrders)
            {
                long startPos = bin.Position;
                claimed.Serialize(bin);
                idx.Write((long)startPos);
                idx.Write((int)(bin.Position - startPos));
            }
            idx.Close();
            bin.Close();
            log.Info("Saving done.");
        }
コード例 #19
0
ファイル: StandardSaveStrategy.cs プロジェクト: Godkong/RunUO
        protected void SaveItems(SaveMetrics metrics)
        {
            Dictionary<Serial, Item> items = World.Items;

            GenericWriter idx;
            GenericWriter tdb;
            GenericWriter bin;

            if (UseSequentialWriters)
            {
                idx = new BinaryFileWriter( World.ItemIndexPath, false );
                tdb = new BinaryFileWriter( World.ItemTypesPath, false );
                bin = new BinaryFileWriter( World.ItemDataPath, true );
            } else {
                idx = new AsyncWriter( World.ItemIndexPath, false );
                tdb = new AsyncWriter( World.ItemTypesPath, false );
                bin = new AsyncWriter( World.ItemDataPath, true );
            }

            idx.Write( ( int ) items.Count );
            foreach ( Item item in items.Values ) {
                if ( item.Decays && item.Parent == null && item.Map != Map.Internal && ( item.LastMoved + item.DecayTime ) <= DateTime.Now ) {
                    _decayQueue.Enqueue( item );
                }

                long start = bin.Position;

                idx.Write( ( int ) item.m_TypeRef );
                idx.Write( ( int ) item.Serial );
                idx.Write( ( long ) start );

                item.Serialize( bin );

                if ( metrics != null ) {
                    metrics.OnItemSaved( ( int ) ( bin.Position - start ) );
                }

                idx.Write( ( int ) ( bin.Position - start ) );

                item.FreeCache();
            }

            tdb.Write( ( int ) World.m_ItemTypes.Count );
            for ( int i = 0; i < World.m_ItemTypes.Count; ++i )
                tdb.Write( World.m_ItemTypes[i].FullName );

            idx.Close();
            tdb.Close();
            bin.Close();
        }
コード例 #20
0
ファイル: ChatInfo.cs プロジェクト: greeduomacro/hubroot
		public virtual void Serialize( BinaryFileWriter writer )
		{
			writer.Write( (int)0 );

			//version 0
			writer.WriteMobileList<Mobile>( _buddyList, true );
			writer.Write( _client );
			writer.WriteMobileList<Mobile>( _ignoreList, true );
			writer.Write( _visible );
		}
コード例 #21
0
        private static void SaveItems()
        {
            GenericWriter writer1;
            GenericWriter writer2;
            GenericWriter writer3;
            Type          type1;
            int           num1;
            long          num2;
            int           num3;
            int           num4;
            Item          item2;
            ArrayList     list1 = new ArrayList();
            ArrayList     list2 = new ArrayList(Core.ScriptItems);

            if (World.SaveType == SaveOption.Normal)
            {
                writer1 = new BinaryFileWriter(World.itemIdxPath, false);
                writer2 = new BinaryFileWriter(World.itemTdbPath, false);
                writer3 = new BinaryFileWriter(World.itemBinPath, true);
            }
            else
            {
                writer1 = new AsyncWriter(World.itemIdxPath, false);
                writer2 = new AsyncWriter(World.itemTdbPath, false);
                writer3 = new AsyncWriter(World.itemBinPath, true);
            }
            writer1.Write(World.m_Items.Count);
            foreach (Item item1 in World.m_Items.Values)
            {
                if ((item1.Decays && (item1.Parent == null)) && ((item1.Map != Map.Internal) && ((item1.LastMoved + item1.DecayTime) <= DateTime.Now)))
                {
                    list1.Add(item1);
                }
                type1 = item1.GetType();
                num1  = list2.IndexOf(type1);
                if (num1 == -1)
                {
                    num1 = list2.Add(type1);
                }
                num2 = writer3.Position;
                writer1.Write(num1);
                writer1.Write(Serial.op_Implicit(item1.Serial));
                writer1.Write(num2);
                item1.Serialize(writer3);
                writer1.Write(((int)(writer3.Position - num2)));
                item1.FreeCache();
            }
            writer2.Write(list2.Count);
            for (num3 = 0; (num3 < list2.Count); ++num3)
            {
                writer2.Write(((Type)list2[num3]).FullName);
            }
            writer1.Close();
            writer2.Close();
            writer3.Close();
            for (num4 = 0; (num4 < list1.Count); ++num4)
            {
                item2 = ((Item)list1[num4]);
                if (item2.OnDecay())
                {
                    item2.Delete();
                }
            }
        }
コード例 #22
0
        public static void Register(
            string name,
            Action <IGenericWriter> serializer,
            Action <IGenericReader> deserializer,
            int priority = Persistence.DefaultPriority
            )
        {
            BufferWriter saveBuffer = null;

            void Serialize()
            {
                saveBuffer ??= new BufferWriter(true);
                saveBuffer.Seek(0, SeekOrigin.Begin);

                serializer(saveBuffer);
            }

            void WriterSnapshot(string savePath)
            {
                var path = Path.Combine(savePath, name);

                AssemblyHandler.EnsureDirectory(path);

                string binPath = Path.Combine(path, $"{name}.bin");

                using var bin = new BinaryFileWriter(binPath, true);

                saveBuffer !.Resize((int)saveBuffer.Position);
                bin.Write(saveBuffer.Buffer);
            }

            void Deserialize(string savePath)
            {
                var path = Path.Combine(savePath, name);

                AssemblyHandler.EnsureDirectory(path);

                string binPath = Path.Combine(path, $"{name}.bin");

                if (!File.Exists(binPath))
                {
                    return;
                }

                try
                {
                    using FileStream bin = new FileStream(binPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                    var buffer = GC.AllocateUninitializedArray <byte>((int)bin.Length);
                    bin.Read(buffer);
                    deserializer(new BufferReader(buffer));
                }
                catch (Exception e)
                {
                    Utility.PushColor(ConsoleColor.Red);
                    Console.WriteLine($"***** Bad deserialize of {name} *****");
                    Console.WriteLine(e.ToString());
                    Utility.PopColor();
                }
            }

            Persistence.Register(name, Serialize, WriterSnapshot, Deserialize, priority);
        }
コード例 #23
0
ファイル: World.cs プロジェクト: BackupTheBerlios/sunuo-svn
        private static void SaveRegions()
        {
            int count = 0;

            GenericWriter bin;

            if (SaveType == SaveOption.Normal)
            {
                bin = new BinaryFileWriter(regionBinPath, true);
            }
            else
            {
                bin = new AsyncWriter(regionBinPath, true);
            }

            MemoryStream mem    = new MemoryStream(4 + (20 * Region.Regions.Count));
            BinaryWriter memIdx = new BinaryWriter(mem);

            memIdx.Write((int)0);

            for (int i = 0; i < Region.Regions.Count; ++i)
            {
                Region region = (Region)Region.Regions[i];

                if (region.Saves)
                {
                    ++count;
                    long start = bin.Position;

                    memIdx.Write((int)0);                      //typeid
                    memIdx.Write((int)region.UId);
                    memIdx.Write((long)start);

                    region.Serialize(bin);

                    memIdx.Write((int)(bin.Position - start));
                }
            }

            bin.Close();

            memIdx.Seek(0, SeekOrigin.Begin);
            memIdx.Write((int)count);

            if (SaveType == SaveOption.Threaded)
            {
                AsyncWriter asyncIdx = new AsyncWriter(regionIdxPath, false);
                asyncIdx.MemStream = mem;
                asyncIdx.Close();
            }
            else
            {
                FileStream fs = new FileStream(regionIdxPath, FileMode.Create, FileAccess.Write, FileShare.None);
                mem.WriteTo(fs);
                fs.Close();
                mem.Close();
            }

            // mem is closed only in non threaded saves, as its reference is copied to asyncIdx.MemStream
            memIdx.Close();
        }
コード例 #24
0
ファイル: World.cs プロジェクト: BackupTheBerlios/sunuo-svn
        private static void SaveItems()
        {
            ArrayList decaying = new ArrayList();

            GenericWriter idx;
            GenericWriter tdb;
            GenericWriter bin;

            if (SaveType == SaveOption.Normal)
            {
                idx = new BinaryFileWriter(itemIdxPath, false);
                tdb = new BinaryFileWriter(itemTdbPath, false);
                bin = new BinaryFileWriter(itemBinPath, true);
            }
            else
            {
                idx = new AsyncWriter(itemIdxPath, false);
                tdb = new AsyncWriter(itemTdbPath, false);
                bin = new AsyncWriter(itemBinPath, true);
            }

            idx.Write((int)m_Items.Count);
            foreach (Item item in m_Items.Values)
            {
                if (item.Decays && item.Parent == null && item.Map != Map.Internal && (item.LastMoved + item.DecayTime) <= DateTime.Now)
                {
                    decaying.Add(item);
                }

                long start = bin.Position;

                idx.Write((int)item.m_TypeRef);
                idx.Write((int)item.Serial);
                idx.Write((long)start);

                item.Serialize(bin);

                idx.Write((int)(bin.Position - start));

                item.FreeCache();
            }

            tdb.Write((int)m_ItemTypes.Count);
            for (int i = 0; i < m_ItemTypes.Count; ++i)
            {
                tdb.Write(((Type)m_ItemTypes[i]).FullName);
            }

            idx.Close();
            tdb.Close();
            bin.Close();

            for (int i = 0; i < decaying.Count; ++i)
            {
                Item item = (Item)decaying[i];

                if (item.OnDecay())
                {
                    item.Delete();
                }
            }
        }
コード例 #25
0
ファイル: World.cs プロジェクト: BackupTheBerlios/sunuo-svn
        private static void SaveMobiles()
        {
            ArrayList restock = new ArrayList();

            GenericWriter idx;
            GenericWriter tdb;
            GenericWriter bin;

            if (SaveType == SaveOption.Normal)
            {
                idx = new BinaryFileWriter(mobIdxPath, false);
                tdb = new BinaryFileWriter(mobTdbPath, false);
                bin = new BinaryFileWriter(mobBinPath, true);
            }
            else
            {
                idx = new AsyncWriter(mobIdxPath, false);
                tdb = new AsyncWriter(mobTdbPath, false);
                bin = new AsyncWriter(mobBinPath, true);
            }

            idx.Write((int)m_Mobiles.Count);
            foreach (Mobile m in m_Mobiles.Values)
            {
                Type t = m.GetType();

                long start = bin.Position;

                idx.Write((int)m.m_TypeRef);
                idx.Write((int)m.Serial);
                idx.Write((long)start);

                m.Serialize(bin);

                idx.Write((int)(bin.Position - start));

                if (m is IVendor)
                {
                    if (((IVendor)m).LastRestock + ((IVendor)m).RestockDelay < DateTime.Now)
                    {
                        restock.Add(m);
                    }
                }

                m.FreeCache();
            }

            tdb.Write((int)m_MobileTypes.Count);
            for (int i = 0; i < m_MobileTypes.Count; ++i)
            {
                tdb.Write(((Type)m_MobileTypes[i]).FullName);
            }

            for (int i = 0; i < restock.Count; i++)
            {
                IVendor vend = (IVendor)restock[i];
                vend.Restock();
                vend.LastRestock = DateTime.Now;
            }

            idx.Close();
            tdb.Close();
            bin.Close();
        }
コード例 #26
0
ファイル: SQL.cs プロジェクト: keninishna/ServUO-master
        protected void SaveMobiles()
        {
            Stopwatch watch = Stopwatch.StartNew();
            Dictionary <Serial, Mobile> mobiles = World.Mobiles;
            List <Database.Mobile>      mobs    = new List <Database.Mobile>();
            List <Database.Skill>       vsk     = new List <Database.Skill>();
            List <Database.MobIndex>    mindex  = new List <Database.MobIndex>();
            int skillid = 0;

            foreach (Mobile m in World.BuffMobiles)
            {
                var typename = m.GetType();

                Database.Mobile v = new Database.Mobile();

                for (int i = 0; i < m.Skills.Length; i++)
                {
                    if (m.Skills[i] != null && m.Skills[i].Base != 0)
                    {
                        Database.Skill vskill = new Database.Skill();
                        skillid++;
                        vskill.Id     = skillid;
                        vskill.Base   = ((double)m.Skills[i].Base) * 10;
                        vskill.Cap    = (int)m.Skills[i].Cap;
                        vskill.Lock   = (byte)m.Skills[i].Lock;
                        vskill.Name   = m.Skills[i].Name;
                        vskill.Parent = m.Serial.Value;
                        vsk.Add(vskill);
                    }
                }


                foreach (Item mitem in m.Items)
                {
                    v.m_Items += mitem.Serial.Value + ";";
                }

                v.mType = typename.FullName;

                v.mTypeRef         = m.m_TypeRef;
                v.Id               = m.Serial.Value;
                v.Serial           = m.Serial.Value;
                v.m_IgnoreMobiles  = m.IgnoreMobiles;
                v.m_AccessLevel    = (byte)m.AccessLevel;
                v.m_AutoPageNotify = m.AutoPageNotify;
                v.m_BaseSoundID    = m.BaseSoundID;
                v.m_Blessed        = m.Blessed;
                v.m_Body           = m.Body;
                v.m_CanSwim        = m.CanSwim;
                v.m_CantWalk       = m.CantWalk;
                if (m.Corpse != null)
                {
                    v.m_Corpse = m.Corpse.Serial.Value;
                }
                v.m_CreationTime = m.CreationTime;
                v.m_Criminal     = m.Criminal;
                v.m_Dex          = m.Dex;
                v.m_Direction    = (byte)m.Direction;
                v.m_DisarmReady  = m.DisarmReady;
                v.m_EmoteHue     = m.EmoteHue;
                v.m_Fame         = m.Fame;
                v.m_Hidden       = m.Hidden;
                v.m_Hits         = m.Hits;
                if (m.Holding != null)
                {
                    v.m_Holding = m.Holding.Serial.Value;
                }
                v.m_Hue = m.Hue;
                v.m_Int = m.Int;

                v.m_Karma             = m.Karma;
                v.m_Language          = m.Language;
                v.m_Locationx         = m.Location.X;
                v.m_Locationy         = m.Location.Y;
                v.m_Locationz         = m.Location.Z;
                v.m_MagicDamageAbsorb = m.MagicDamageAbsorb;
                v.m_Mana = m.Mana;
                if (m.Map != null)
                {
                    v.m_Map = (byte)m.Map.MapIndex;
                }
                v.m_Name         = m.Name;
                v.m_NameHue      = m.NameHue;
                v.m_Player       = m.Player;
                v.m_SpeechHue    = m.SpeechHue;
                v.m_Squelched    = m.Squelched;
                v.m_Stam         = m.Stam;
                v.m_StatCap      = m.StatCap;
                v.m_Str          = m.Str;
                v.m_StunReady    = m.StunReady;
                v.m_VirtualArmor = m.VirtualArmor;
                v.m_Warmode      = m.Warmode;
                v.m_WhisperHue   = m.WhisperHue;
                v.m_YellHue      = m.YellHue;
                // v.Poison = (byte)m.Poison;

                //-------------------------
                if (m.Player)
                {
                    v.Account = m.Account.Username;
                }
                else
                {
                    v.Account = "NPC";
                }
                v.m_BAC         = m.BAC;
                v.m_BaseSoundID = m.BaseSoundID;
                v.m_Blessed     = m.Blessed;
                if (m.LastDexGain < DateTime.UtcNow)
                {
                    v.m_LastDexGain = DateTime.UtcNow;
                }
                else
                {
                    v.m_LastDexGain = m.LastDexGain;
                }
                if (m.LastStrGain < DateTime.UtcNow)
                {
                    v.m_LastStrGain = DateTime.UtcNow;
                }
                else
                {
                    v.m_LastStrGain = m.LastDexGain;
                }
                if (m.LastIntGain < DateTime.UtcNow)
                {
                    v.m_LastIntGain = DateTime.UtcNow;
                }
                else
                {
                    v.m_LastIntGain = m.LastDexGain;
                }
                v.m_Hair             = (byte)m.HairItemID;
                v.m_FacialHair       = (byte)m.FacialHairItemID;
                v.m_Race             = (byte)m.Race.RaceIndex;
                v.m_ShortTermMurders = m.ShortTermMurders;
                v.m_FollowersMax     = m.FollowersMax;
                if (m.GuildFealty != null)
                {
                    v.m_GuildFealty = m.GuildFealty.Serial.Value;
                }
                if (m.Guild != null)
                {
                    v.m_Guild = m.Guild.Id;
                }

                v.m_DisplayGuildTitle = m.DisplayGuildTitle;
                v.m_Hunger            = m.Hunger;
                v.m_Kills             = m.Kills;
                v.m_GuildTitle        = m.GuildTitle;
                v.m_Female            = m.Female;
                v.m_Player            = m.Player;
                v.m_Title             = m.Title;
                v.m_Profile           = m.Profile;
                v.m_ProfileLocked     = m.ProfileLocked;
                v.m_LogoutLocationx   = m.LogoutLocation.X;
                v.m_LogoutLocationy   = m.LogoutLocation.Y;
                v.m_LogoutLocationz   = m.LogoutLocation.Z;
                if (m.LogoutMap != null)
                {
                    v.m_LogoutMap = (byte)m.LogoutMap.MapIndex;
                }
                else
                {
                    v.m_LogoutMap = (byte)(0xFF);
                }
                v.m_StrLock = (byte)m.StrLock;
                v.m_DexLock = (byte)m.DexLock;
                v.m_IntLock = (byte)m.IntLock;
                v.m_Hidden  = m.Hidden;

                MemoryStream  strim = new MemoryStream();
                GenericWriter bin   = new BinaryFileWriter(strim, true);
                m.Serialize(bin);
                bin.Close();
                v.Data = Convert.ToBase64String(strim.ToArray());
                strim.Close();
                mobs.Add(v);
                m.FreeCache();
            }

            for (int i = 0; i < World.m_MobileTypes.Count; ++i)
            {
                Database.MobIndex a = new Database.MobIndex();

                a.MobTypes = (World.m_MobileTypes[i].FullName);
                a.Id       = i;
                mindex.Add(a);
            }

            using (Database.UODataContext writedb = new Database.UODataContext(Core.SQLConnect))
            {
                Database.LinqExtension.Truncate(writedb.Mobiles);    //drop mobiles table
                Database.LinqExtension.Truncate(writedb.Skills);     //drop skills table
                Database.LinqExtension.Truncate(writedb.MobIndexes); //drop mobile index table
                writedb.BulkInsertAll(mobs);                         //bulk insert mobs
                writedb.BulkInsertAll(vsk);                          //bulk insert skillz
                writedb.BulkInsertAll(mindex);
            }
            watch.Stop();
            Console.WriteLine("SQL mobile data created: " + watch.Elapsed.TotalSeconds);
        }
コード例 #27
0
ファイル: FDFile.cs プロジェクト: zerodowned/angelisland
			protected override void OnTarget(Mobile from, object targeted)
			{
				if (!(targeted is Container))
				{
					from.SendMessage("Only containers can be dumped.");
					return;
				}

				Container cont = (Container)targeted;

				try
				{
					using (FileStream idxfs = new FileStream(m_Filename + ".idx", FileMode.Create, FileAccess.Write, FileShare.None))
					{
						using (FileStream binfs = new FileStream(m_Filename + ".bin", FileMode.Create, FileAccess.Write, FileShare.None))
						{
							GenericWriter idx = new BinaryFileWriter(idxfs, true);
							GenericWriter bin = new BinaryFileWriter(binfs, true);

							ArrayList items = new ArrayList();
							items.Add(cont);
							items.AddRange(cont.GetDeepItems());

							idx.Write((int)items.Count);
							foreach (Item item in items)
							{
								long start = bin.Position;

								idx.Write(item.GetType().FullName); // <--- DIFFERENT FROM WORLD SAVE FORMAT!
								idx.Write((int)item.Serial);
								idx.Write((long)start);

								item.Serialize(bin);

								idx.Write((int)(bin.Position - start));
							}


							idx.Close();
							bin.Close();
						}
					}

					from.SendMessage("Container successfully dumped to {0}.", m_Filename);
				}
				catch (Exception e)
				{
					LogHelper.LogException(e);
					Console.WriteLine(e.ToString());
					from.SendMessage("Exception: {0}", e.Message);
				}
			}
コード例 #28
0
        private static void HandleError(Exception error, string name, object[] loadinfo)
        {
            bool sep = loadinfo == null;
            bool nerr = error == null;
            string type = sep ? "seperate savefile" : "save module";
            string placename = sep ? "the file can be found at" : "this module was indexed under the name";

            Console.WriteLine();
            if (nerr)
            {
                Console.WriteLine("The loading and saving methods of a {0} are inconsistent, {1} \"{2}\".", type, placename, name);
                if (!sep && (bool)loadinfo[3])
                    Console.WriteLine("More data was read than written.");
                else
                    Console.WriteLine("More data was written than read.");
            }
            else
            {
                Console.WriteLine("During the loading of a {0} an exception was caught, {1} \"{2}\".", type, placename, name);
                Console.WriteLine("The following error was caught:");
                Console.WriteLine(error.ToString());
            }

            Console.WriteLine("Please Review your Save/Load methods for this {0}", sep ? "file" : "module");

            if (!m_IgnoreErrors)
            {
                string str = sep ? "Do you wish to continue loading with faulty data(Y), or stop the program(N)?" : "Do you wish to remove this module and restart(Y), or continue loading with faulty data(N)?";
                Console.WriteLine(str);

                if (Console.ReadKey(true).Key == ConsoleKey.Y)
                {
                    if (!sep)
                    {
                        int oldcount = (int)loadinfo[0];
                        int location = (int)loadinfo[1];
                        BinaryFileReader idxreader = (BinaryFileReader)loadinfo[2];

                        int newcount = oldcount - 1;
                        string[] indexarray = new string[newcount];
                        long[] binposarray = new long[newcount];
                        long[] finposarray = new long[newcount];

                        idxreader.Seek(0, SeekOrigin.Begin);
                        idxreader.ReadInt();
                        int loc = 0;
                        for (int j = 0; j < oldcount; j++)
                        {
                            if (j != location)
                            {
                                indexarray[loc] = idxreader.ReadString();
                                binposarray[loc] = idxreader.ReadLong();
                                finposarray[loc] = idxreader.ReadLong();
                                loc++;
                            }
                            else
                            {
                                idxreader.ReadString();
                                idxreader.ReadLong();
                                idxreader.ReadLong();
                            }
                        }
                        idxreader.Close();
                        GenericWriter idxwriter = new BinaryFileWriter(m_FullPath + ".idx", true);

                        idxwriter.Write(newcount);
                        for (int j = 0; j < newcount; j++)
                        {
                            idxwriter.Write(indexarray[j]);
                            idxwriter.Write(binposarray[j]);
                            idxwriter.Write(finposarray[j]);
                        }
                        idxwriter.Close();

                        Process.Start(Core.ExePath, Core.Arguments);
                        Core.Process.Kill();
                    }
                }

                else if (sep)
                    Core.Process.Kill();
            }
        }
コード例 #29
0
        private static void SaveMobiles()
        {
            GenericWriter writer1;
            GenericWriter writer2;
            GenericWriter writer3;
            Type          type1;
            int           num1;
            long          num2;
            int           num3;
            int           num4;
            IVendor       vendor1;
            ArrayList     list1 = new ArrayList();
            ArrayList     list2 = new ArrayList(Core.ScriptMobiles);

            if (World.SaveType == SaveOption.Normal)
            {
                writer1 = new BinaryFileWriter(World.mobIdxPath, false);
                writer2 = new BinaryFileWriter(World.mobTdbPath, false);
                writer3 = new BinaryFileWriter(World.mobBinPath, true);
            }
            else
            {
                writer1 = new AsyncWriter(World.mobIdxPath, false);
                writer2 = new AsyncWriter(World.mobTdbPath, false);
                writer3 = new AsyncWriter(World.mobBinPath, true);
            }
            writer1.Write(World.m_Mobiles.Count);
            foreach (Mobile mobile1 in World.m_Mobiles.Values)
            {
                type1 = mobile1.GetType();
                num1  = list2.IndexOf(type1);
                if (num1 == -1)
                {
                    num1 = list2.Add(type1);
                }
                num2 = writer3.Position;
                writer1.Write(num1);
                writer1.Write(Serial.op_Implicit(mobile1.Serial));
                writer1.Write(num2);
                mobile1.Serialize(writer3);
                writer1.Write(((int)(writer3.Position - num2)));
                if ((mobile1 is IVendor) && ((((IVendor)mobile1).LastRestock + ((IVendor)mobile1).RestockDelay) < DateTime.Now))
                {
                    list1.Add(mobile1);
                }
                mobile1.FreeCache();
            }
            writer2.Write(list2.Count);
            for (num3 = 0; (num3 < list2.Count); ++num3)
            {
                writer2.Write(((Type)list2[num3]).FullName);
            }
            for (num4 = 0; (num4 < list1.Count); ++num4)
            {
                vendor1 = ((IVendor)list1[num4]);
                vendor1.Restock();
                vendor1.LastRestock = DateTime.Now;
            }
            writer1.Close();
            writer2.Close();
            writer3.Close();
        }
コード例 #30
0
        public static void SaveBackup( Mobile mobile, ArrayList ArgsList )
        {
            MC.SetProcess( Process.SaveBackup );

            if ( !Directory.Exists( MC.BackupDirectory ) )
                Directory.CreateDirectory( MC.BackupDirectory );

            string path = Path.Combine( MC.BackupDirectory, "Backup.mbk" );

            mobile.SendMessage( "Creating backup file..." );

            MC.CheckSpawners();

            ArrayList SpawnerList = CompileSpawnerList();

            GenericWriter writer;

            try
            {
                writer = new BinaryFileWriter( path, true );
            }
            catch(Exception ex)
            {
                MC.SetProcess( Process.None );

                ArgsList[2] = "Create Backup File";
                ArgsList[4] = String.Format( "Exception caught:\n{0}", ex );

                mobile.SendGump( new FileMenuGump( mobile, ArgsList ) );

                return;
            }

            writer.Write( SpawnerList.Count );

            try
            {
                foreach ( MegaSpawner megaSpawner in SpawnerList )
                    Serialize( megaSpawner, writer );
            }
            catch{}

            writer.Close();

            MC.SetProcess( Process.None );

            ArgsList[2] = "Create Backup File";
            ArgsList[4] = "All Mega Spawners have now been backed up to the backup file.";

            mobile.SendGump( new FileMenuGump( mobile, ArgsList ) );
        }
コード例 #31
0
		public void Serialize()
		{
			//Console.WriteLine("[Vote System]: Saving Config...");

			FileInfo info = new FileInfo("Data\\VoteSystem.cfg");

			if (!info.Exists)
				info.Create().Close();

			using(FileStream fs = info.Open(FileMode.Truncate, FileAccess.Write))
			{
				BinaryFileWriter bin = new BinaryFileWriter(fs, true);
				
				bin.Write((int)0);

				bin.Write((string)_DefaultName);
				bin.Write((string)_DefaultURL);
				bin.Write((TimeSpan)_DefaultCoolDown);

				bin.Close();
			}

			//Console.WriteLine("[Vote System]: Done.");
		}
コード例 #32
0
ファイル: World.cs プロジェクト: BackupTheBerlios/sunuo-svn
        private static void SaveMobiles(string mobileBase)
        {
            ArrayList restock = new ArrayList();

            GenericWriter idx;
            GenericWriter tdb;
            GenericWriter bin;

            if (!Directory.Exists(mobileBase))
                Directory.CreateDirectory(mobileBase);

            string mobIdxPath = Path.Combine(mobileBase, "Mobiles.idx");
            string mobTdbPath = Path.Combine(mobileBase, "Mobiles.tdb");
            string mobBinPath = Path.Combine(mobileBase, "Mobiles.bin");

            if ( SaveType == SaveOption.Normal )
            {
                idx = new BinaryFileWriter( mobIdxPath, false );
                tdb = new BinaryFileWriter( mobTdbPath, false );
                bin = new BinaryFileWriter( mobBinPath, true );
            }
            else
            {
                idx = new AsyncWriter( mobIdxPath, false );
                tdb = new AsyncWriter( mobTdbPath, false );
                bin = new AsyncWriter( mobBinPath, true );
            }

            idx.Write( (int) m_Mobiles.Count );
            foreach ( Mobile m in m_Mobiles.Values )
            {
                long start = bin.Position;

                idx.Write( (int) m.m_TypeRef );
                idx.Write( (int) m.Serial );
                idx.Write( (long) start );

                m.Serialize( bin );

                idx.Write( (int) (bin.Position - start) );

                if ( m is IVendor )
                {
                    if ( ((IVendor)m).LastRestock + ((IVendor)m).RestockDelay < DateTime.Now )
                        restock.Add( m );
                }

                m.FreeCache();
            }

            tdb.Write( (int) m_MobileTypes.Count );
            for ( int i = 0; i < m_MobileTypes.Count; ++i )
                tdb.Write( ((Type)m_MobileTypes[i]).FullName );

            for (int i=0;i<restock.Count;i++)
            {
                IVendor vend = (IVendor)restock[i];
                vend.Restock();
                vend.LastRestock = DateTime.Now;
            }

            idx.Close();
            tdb.Close();
            bin.Close();
        }
コード例 #33
0
ファイル: StandardSaveStrategy.cs プロジェクト: Godkong/RunUO
        protected void SaveGuilds(SaveMetrics metrics)
        {
            GenericWriter idx;
            GenericWriter bin;

            if (UseSequentialWriters)
            {
                idx = new BinaryFileWriter( World.GuildIndexPath, false );
                bin = new BinaryFileWriter( World.GuildDataPath, true );
            } else {
                idx = new AsyncWriter( World.GuildIndexPath, false );
                bin = new AsyncWriter( World.GuildDataPath, true );
            }

            idx.Write( ( int ) BaseGuild.List.Count );
            foreach ( BaseGuild guild in BaseGuild.List.Values ) {
                long start = bin.Position;

                idx.Write( ( int ) 0 );//guilds have no typeid
                idx.Write( ( int ) guild.Id );
                idx.Write( ( long ) start );

                guild.Serialize( bin );

                if ( metrics != null ) {
                    metrics.OnGuildSaved( ( int ) ( bin.Position - start ) );
                }

                idx.Write( ( int ) ( bin.Position - start ) );
            }

            idx.Close();
            bin.Close();
        }
コード例 #34
0
ファイル: World.cs プロジェクト: BackupTheBerlios/sunuo-svn
        private static void SaveGuilds(string guildBase)
        {
            string guildIdxPath = Path.Combine(guildBase, "Guilds.idx");
            string guildBinPath = Path.Combine(guildBase, "Guilds.bin");

            GenericWriter idx;
            GenericWriter bin;

            if (!Directory.Exists(guildBase))
                Directory.CreateDirectory(guildBase);

            if ( SaveType == SaveOption.Normal )
            {
                idx = new BinaryFileWriter( guildIdxPath, false );
                bin = new BinaryFileWriter( guildBinPath, true );
            }
            else
            {
                idx = new AsyncWriter( guildIdxPath, false );
                bin = new AsyncWriter( guildBinPath, true );
            }

            idx.Write( (int) BaseGuild.List.Count );
            foreach ( BaseGuild guild in BaseGuild.List.Values )
            {
                long start = bin.Position;

                idx.Write( (int)0 );//guilds have no typeid
                idx.Write( (int)guild.Id );
                idx.Write( (long)start );

                guild.Serialize( bin );

                idx.Write( (int) (bin.Position - start) );
            }

            idx.Close();
            bin.Close();
        }
コード例 #35
0
		private static void ExportSectorNodeNetwork(CommandEventArgs e)
		{
			try
			{
				Console.Write("Saving SectorNodes...");
				DateTime dt = DateTime.Now;
				if (!Directory.Exists("Data"))
					Directory.CreateDirectory("Data");

				using (FileStream fs = new FileStream("Data/SectorPathData.dat", FileMode.Create))
				{
					BinaryFileWriter writer = new BinaryFileWriter(fs, false);

					writer.Write(Map.Felucca.Width >> Map.SectorShift);
					writer.Write(Map.Felucca.Height >> Map.SectorShift);

					for (int y = 0; y < (Map.Felucca.Height >> Map.SectorShift); y++)
					{
						for (int x = 0; x < (Map.Felucca.Width >> Map.SectorShift); x++)
						{
							m_Nodes[x, y].Serialize(writer);
						}
					}

					writer.Close();
				}
				Console.WriteLine("done in {0}ms.", (DateTime.Now - dt).TotalMilliseconds);
			}
			catch (Exception ex)
			{
				LogHelper.LogException(ex);
				Console.WriteLine("error:");
				Console.WriteLine(ex);
			}
		}
コード例 #36
0
ファイル: Data.cs プロジェクト: guy489/runuot2a
        public static void SaveGlobalOptions()
        {
            CleanUpData();

            if (!Directory.Exists(General.SavePath))
                Directory.CreateDirectory(General.SavePath);

            GenericWriter writer = new BinaryFileWriter(Path.Combine(General.SavePath, "GlobalOptions.bin"), true);

            writer.Write(2); // version

            writer.Write(s_MultiPort);
            writer.Write(s_MultiServer);

            writer.Write(s_Notifications.Count);
            foreach (Notification not in s_Notifications)
                not.Save(writer);

            writer.Write(s_Filters.Count);
            foreach (string str in s_Filters)
                writer.Write(str);

            writer.Write((int)s_FilterPenalty);
            writer.Write((int)s_MacroPenalty);
            writer.Write(s_MaxMsgs);
            writer.Write(s_ChatSpam);
            writer.Write(s_MsgSpam);
            writer.Write(s_RequestSpam);
            writer.Write(s_FilterBanLength);
            writer.Write(s_FilterWarnings);
            writer.Write(s_AntiMacroDelay);
            writer.Write(s_IrcPort);
            writer.Write(s_IrcMaxAttempts);
            writer.Write(s_IrcEnabled);
            writer.Write(s_IrcAutoConnect);
            writer.Write(s_IrcAutoReconnect);
            writer.Write(s_FilterSpeech);
            writer.Write(s_FilterMsg);
            writer.Write(s_Debug);
            writer.Write(s_LogChat);
            writer.Write(s_LogPms);
            writer.Write((int)s_IrcStaffColor);
            writer.Write(s_IrcServer);
            writer.Write(s_IrcRoom);
            writer.Write(s_IrcNick);
            writer.Write(s_TotalChats+1);

            writer.Close();
        }
コード例 #37
0
ファイル: World.cs プロジェクト: BackupTheBerlios/sunuo-svn
        private static void SaveItems(string itemBase)
        {
            string itemIdxPath = Path.Combine( itemBase, "Items.idx" );
            string itemTdbPath = Path.Combine( itemBase, "Items.tdb" );
            string itemBinPath = Path.Combine( itemBase, "Items.bin" );

            ArrayList decaying = new ArrayList();

            GenericWriter idx;
            GenericWriter tdb;
            GenericWriter bin;

            if (!Directory.Exists(itemBase))
                Directory.CreateDirectory(itemBase);

            if ( SaveType == SaveOption.Normal )
            {
                idx = new BinaryFileWriter( itemIdxPath, false );
                tdb = new BinaryFileWriter( itemTdbPath, false );
                bin = new BinaryFileWriter( itemBinPath, true );
            }
            else
            {
                idx = new AsyncWriter( itemIdxPath, false );
                tdb = new AsyncWriter( itemTdbPath, false );
                bin = new AsyncWriter( itemBinPath, true );
            }

            idx.Write( (int) m_Items.Count );
            foreach ( Item item in m_Items.Values )
            {
                if ( item.Decays && item.Parent == null && item.Map != Map.Internal && (item.LastMoved + item.DecayTime) <= DateTime.Now )
                    decaying.Add( item );

                long start = bin.Position;

                idx.Write( (int) item.m_TypeRef );
                idx.Write( (int) item.Serial );
                idx.Write( (long) start );

                item.Serialize( bin );

                idx.Write( (int) (bin.Position - start) );

                item.FreeCache();
            }

            tdb.Write( (int) m_ItemTypes.Count );
            for ( int i = 0; i < m_ItemTypes.Count; ++i )
                tdb.Write( ((Type)m_ItemTypes[i]).FullName );

            idx.Close();
            tdb.Close();
            bin.Close();

            for ( int i = 0; i < decaying.Count; ++i )
            {
                Item item = (Item)decaying[i];

                if ( item.OnDecay() )
                    item.Delete();
            }
        }
コード例 #38
0
ファイル: XmlAttach.cs プロジェクト: greeduomacro/vivre-uo
        public static void Save(WorldSaveEventArgs e)
        {
            if (XmlAttach.MobileAttachments == null && XmlAttach.ItemAttachments == null) return;

            CleanUp();

            if (!Directory.Exists("Saves/Attachments"))
                Directory.CreateDirectory("Saves/Attachments");

            string filePath = Path.Combine("Saves/Attachments", "Attachments.bin");        // the attachment serializations
            string imaPath = Path.Combine("Saves/Attachments", "Attachments.ima");         // the item/mob attachment tables
            string fpiPath = Path.Combine("Saves/Attachments", "Attachments.fpi");        // the file position indices

            BinaryFileWriter writer = null;
            BinaryFileWriter imawriter = null;
            BinaryFileWriter fpiwriter = null;

            try
            {
                writer = new BinaryFileWriter(filePath, true);
                imawriter = new BinaryFileWriter(imaPath, true);
                fpiwriter = new BinaryFileWriter(fpiPath, true);

            }
            catch (Exception err)
            {
                ErrorReporter.GenerateErrorReport(err.ToString());
                return;
            }

            if (writer != null && imawriter != null && fpiwriter != null)
            {
                // save the current global attachment serial state
                ASerial.GlobalSerialize(writer);

                // remove all deleted attachments
                XmlAttach.FullDefrag();

                // save the attachments themselves
                if (XmlAttach.AllAttachments != null)
                {
                    writer.Write(XmlAttach.AllAttachments.Count);

                    object[] valuearray = new object[XmlAttach.AllAttachments.Count];
                    XmlAttach.AllAttachments.Values.CopyTo(valuearray, 0);

                    object[] keyarray = new object[XmlAttach.AllAttachments.Count];
                    XmlAttach.AllAttachments.Keys.CopyTo(keyarray, 0);

                    for (int i = 0; i < keyarray.Length; i++)
                    {
                        // write the key
                        writer.Write((int)keyarray[i]);

                        XmlAttachment a = valuearray[i] as XmlAttachment;

                        // write the value type
                        writer.Write((string)a.GetType().ToString());

                        // serialize the attachment itself
                        a.Serialize(writer);

                        // save the fileposition index
                        fpiwriter.Write((long)writer.Position);
                    }
                }
                else
                {
                    writer.Write((int)0);
                }

                writer.Close();

                // save the hash table info for items and mobiles
                // mobile attachments
                if (XmlAttach.MobileAttachments != null)
                {
                    imawriter.Write(XmlAttach.MobileAttachments.Count);

                    object[] valuearray = new object[XmlAttach.MobileAttachments.Count];
                    XmlAttach.MobileAttachments.Values.CopyTo(valuearray, 0);

                    object[] keyarray = new object[XmlAttach.MobileAttachments.Count];
                    XmlAttach.MobileAttachments.Keys.CopyTo(keyarray, 0);

                    for (int i = 0; i < keyarray.Length; i++)
                    {
                        // write the key
                        imawriter.Write((Mobile)keyarray[i]);

                        // write out the attachments
                        ArrayList alist = (ArrayList)valuearray[i];

                        imawriter.Write((int)alist.Count);
                        foreach (XmlAttachment a in alist)
                        {
                            // write the attachment serial
                            imawriter.Write((int)a.Serial.Value);

                            // write the value type
                            imawriter.Write((string)a.GetType().ToString());

                            // save the fileposition index
                            fpiwriter.Write((long)imawriter.Position);
                        }
                    }
                }
                else
                {
                    // no mobile attachments
                    imawriter.Write((int)0);
                }

                // item attachments
                if (XmlAttach.ItemAttachments != null)
                {
                    imawriter.Write(XmlAttach.ItemAttachments.Count);

                    object[] valuearray = new object[XmlAttach.ItemAttachments.Count];
                    XmlAttach.ItemAttachments.Values.CopyTo(valuearray, 0);

                    object[] keyarray = new object[XmlAttach.ItemAttachments.Count];
                    XmlAttach.ItemAttachments.Keys.CopyTo(keyarray, 0);

                    for (int i = 0; i < keyarray.Length; i++)
                    {
                        // write the key
                        imawriter.Write((Item)keyarray[i]);

                        // write out the attachments			             
                        ArrayList alist = (ArrayList)valuearray[i];

                        imawriter.Write((int)alist.Count);
                        foreach (XmlAttachment a in alist)
                        {
                            // write the attachment serial
                            imawriter.Write((int)a.Serial.Value);

                            // write the value type
                            imawriter.Write((string)a.GetType().ToString());

                            // save the fileposition index
                            fpiwriter.Write((long)imawriter.Position);
                        }
                    }
                }
                else
                {
                    // no item attachments
                    imawriter.Write((int)0);
                }

                imawriter.Close();
                fpiwriter.Close();
            }
        }
コード例 #39
0
ファイル: World.cs プロジェクト: BackupTheBerlios/sunuo-svn
        private static void SaveRegions(string regionBase)
        {
            string regionIdxPath = Path.Combine( regionBase, "Regions.idx" );
            string regionBinPath = Path.Combine( regionBase, "Regions.bin" );

            int count = 0;

            GenericWriter bin;

            if (!Directory.Exists(regionBase))
                Directory.CreateDirectory(regionBase);

            if ( SaveType == SaveOption.Normal )
                bin = new BinaryFileWriter( regionBinPath, true );
            else
                bin = new AsyncWriter( regionBinPath, true );

            MemoryStream mem = new MemoryStream( 4 + (20*Region.Regions.Count) );
            BinaryWriter memIdx = new BinaryWriter( mem );

            memIdx.Write( (int)0 );

            for ( int i = 0; i < Region.Regions.Count; ++i )
            {
                Region region = (Region)Region.Regions[i];

                if ( region.Saves )
                {
                    ++count;
                    long start = bin.Position;

                    memIdx.Write( (int)0 );//typeid
                    memIdx.Write( (int) region.UId );
                    memIdx.Write( (long) start );

                    region.Serialize( bin );

                    memIdx.Write( (int) (bin.Position - start) );
                }
            }

            bin.Close();

            memIdx.Seek( 0, SeekOrigin.Begin );
            memIdx.Write( (int)count );

            if ( SaveType == SaveOption.Threaded )
            {
                AsyncWriter asyncIdx = new AsyncWriter( regionIdxPath, false );
                asyncIdx.MemStream = mem;
                asyncIdx.Close();
            }
            else
            {
                FileStream fs = new FileStream( regionIdxPath, FileMode.Create, FileAccess.Write, FileShare.None );
                mem.WriteTo( fs );
                fs.Close();
                mem.Close();
            }

            // mem is closed only in non threaded saves, as its reference is copied to asyncIdx.MemStream
            memIdx.Close();
        }
コード例 #40
0
		public static void Save()
		{
			if (!Directory.Exists("Saves/CTFScore/"))
				Directory.CreateDirectory("Saves/CTFScore/");

			string idxPath = Path.Combine( "Saves/CTFScore", "CTFScore.idx" );
			string binPath = Path.Combine( "Saves/CTFScore", "CTFScore.bin" );

			GenericWriter idx = new BinaryFileWriter(idxPath, false);
			GenericWriter bin = new BinaryFileWriter(binPath, true);

			idx.Write( (int)Players.Values.Count );
			foreach ( CTFPlayer player in Players.Values )
			{
				long startPos = bin.Position;
				player.Serialize( bin );
				idx.Write( (long)startPos );
				idx.Write( (int)(bin.Position - startPos) );
			}
			idx.Close();
			bin.Close();
		}
コード例 #41
0
ファイル: Data.cs プロジェクト: guy489/runuot2a
        public static void SaveGlobalListens()
        {
            if (!Directory.Exists(General.SavePath))
                Directory.CreateDirectory(General.SavePath);

            GenericWriter writer = new BinaryFileWriter(Path.Combine(General.SavePath, "GlobalListens.bin"), true);

            writer.Write(0); // version

            writer.Write(s_Datas.Count);
            foreach (Data data in s_Datas.Values)
            {
                writer.Write(data.Mobile);
                data.SaveGlobalListens(writer);
            }

            writer.Close();
        }
コード例 #42
0
ファイル: Alliances.cs プロジェクト: greeduomacro/hubroot
        public void Serialize(BinaryFileWriter writer)
        {
            writer.Write((int)0); //Version

            writer.Write((string)serialString.ToString());
            writer.WriteMobile(allianceLeader);

            writer.Write((int)membersOf.Count);

            foreach (Mobile m in membersOf)
            {
                writer.WriteMobile(m);
            }

            writer.Write((int)childGuilds.Count);

            foreach (Guild g in childGuilds)
            {
                writer.WriteGuild(g);
            }

            writer.Write((string)allianceName);
            writer.Write((int)primaryHue);
            writer.Write((int)secondaryHue);
            writer.Write((int)mountBody);
            writer.Write((int)mountID);

        }
コード例 #43
0
		private void SaveTypeDatabase(string path, List<Type> types)
		{
			var bfw = new BinaryFileWriter(path, false);

			bfw.Write(types.Count);

			foreach (Type type in types)
			{
				bfw.Write(type.FullName);
			}

			bfw.Flush();
			bfw.Close();
		}
コード例 #44
0
ファイル: Alliances.cs プロジェクト: greeduomacro/hubroot
        private static void Event_WorldSave(WorldSaveEventArgs args)
        {
            try
            {
                if (!Directory.Exists(SavePath))
                    Directory.CreateDirectory(SavePath);

                BinaryFileWriter writer = new BinaryFileWriter(SaveFile, true);

                Serialize(writer);

                ConstructXML();
            }

            catch { Console.WriteLine("Error: Event_WorldSave Failed in Alliance Definition."); }
        }