Example #1
0
        public static void Save(World world, Guid id)
        {
            var saveData = new ClientSaveData()
            {
                Objects = world.Objects.ToArray(),
            };

            Trace.TraceInformation("Saving client data");
            var watch = Stopwatch.StartNew();

            string data;

            using (var stream = new System.IO.MemoryStream())
            {
                using (var serializer = new Dwarrowdelf.SaveGameSerializer(stream, new[] { new ClientObjectRefResolver(world) }))
                {
                    serializer.Serialize(saveData);

                    stream.Position = 0;

                    using (StreamReader reader = new StreamReader(stream))
                        data = reader.ReadToEnd();
                }
            }

            watch.Stop();
            Trace.TraceInformation("Saving client data took {0}", watch.Elapsed);

            var msg = new Messages.SaveClientDataReplyMessage() { ID = id, Data = data };
            GameData.Data.User.Send(msg);

            if (SaveEvent != null)
                SaveEvent();
        }
Example #2
0
        public static string SerializeClientObjects(World world)
        {
            var saveData = new ClientSaveData()
            {
                Objects = world.Objects.ToArray(),
            };

            Trace.TraceInformation("Saving client data");
            var watch = Stopwatch.StartNew();

            string data;

            using (var stream = new System.IO.MemoryStream())
            {
                using (var serializer = new Dwarrowdelf.SaveGameSerializer(stream, new[] { new ClientObjectRefResolver(world) }))
                {
                    serializer.Serialize(saveData);

                    stream.Position = 0;

                    using (StreamReader reader = new StreamReader(stream))
                        data = reader.ReadToEnd();
                }
            }

            watch.Stop();
            Trace.TraceInformation("Saving client data took {0}", watch.Elapsed);

            return(data);
        }
Example #3
0
        public static string SerializeClientObjects(World world)
        {
            var saveData = new ClientSaveData()
            {
                Objects = world.Objects.ToArray(),
            };

            Trace.TraceInformation("Saving client data");
            var watch = Stopwatch.StartNew();

            string data;

            using (var stream = new System.IO.MemoryStream())
            {
                using (var serializer = new Dwarrowdelf.SaveGameSerializer(stream, new[] { new ClientObjectRefResolver(world) }))
                {
                    serializer.Serialize(saveData);

                    stream.Position = 0;

                    using (StreamReader reader = new StreamReader(stream))
                        data = reader.ReadToEnd();
                }
            }

            watch.Stop();
            Trace.TraceInformation("Saving client data took {0}", watch.Elapsed);

            return data;
        }
Example #4
0
        public void Save()
        {
            //var id = Guid.NewGuid();
            // XXX use fixed guid to help testing
            var id = new Guid(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);

            var msg = new Dwarrowdelf.Messages.SaveClientDataRequestMessage()
            {
                ID = id
            };

            foreach (var p in m_players.Where(p => p.IsConnected))
            {
                p.Send(msg);
            }

            if (ServerConfig.DisableSaving)
            {
                Trace.TraceError("Warning: Saving is disabled");
                return;
            }

            this.LastSaveID = id;

            var saveDir = Path.Combine(m_gameDir, id.ToString());

            Directory.CreateDirectory(saveDir);


            /* Save game intro */
            var saveEntry = new SaveEntry()
            {
                ID       = id,
                DateTime = DateTime.Now,
                GameMode = this.GameMode,
                Tick     = this.World.TickNumber,
            };

            using (var stream = File.Create(Path.Combine(saveDir, "intro.json")))
                using (var serializer = new Dwarrowdelf.SaveGameSerializer(stream))
                    serializer.Serialize(saveEntry);


            /* Save game */

            var savePath = Path.Combine(saveDir, "server.json");

            Trace.TraceInformation("Saving game {0}", savePath);
            var watch = Stopwatch.StartNew();

            using (var stream = File.Create(savePath))
                using (var serializer = new Dwarrowdelf.SaveGameSerializer(stream))
                    serializer.Serialize(this);

            watch.Stop();
            Trace.TraceInformation("Saving game took {0}", watch.Elapsed);
        }
Example #5
0
		public void Save()
		{
			//var id = Guid.NewGuid();
			// XXX use fixed guid to help testing
			var id = new Guid(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);

			var msg = new Dwarrowdelf.Messages.SaveClientDataRequestMessage() { ID = id };
			foreach (var p in m_players.Where(p => p.IsConnected))
				p.Send(msg);

			if (ServerConfig.DisableSaving)
			{
				Trace.TraceError("Warning: Saving is disabled");
				return;
			}

			this.LastSaveID = id;

			var saveDir = Path.Combine(m_gameDir, id.ToString());

			Directory.CreateDirectory(saveDir);


			/* Save game intro */
			var saveEntry = new SaveEntry()
			{
				ID = id,
				DateTime = DateTime.Now,
				GameMode = this.GameMode,
				Tick = this.World.TickNumber,
			};

			using (var stream = File.Create(Path.Combine(saveDir, "intro.json")))
			using (var serializer = new Dwarrowdelf.SaveGameSerializer(stream))
				serializer.Serialize(saveEntry);


			/* Save game */

			var savePath = Path.Combine(saveDir, "server.json");

			Trace.TraceInformation("Saving game {0}", savePath);
			var watch = Stopwatch.StartNew();

			using (var stream = File.Create(savePath))
			using (var serializer = new Dwarrowdelf.SaveGameSerializer(stream))
				serializer.Serialize(this);

			watch.Stop();
			Trace.TraceInformation("Saving game took {0}", watch.Elapsed);
		}