Ejemplo n.º 1
0
        protected override void SaveUndoData(List <Player.UndoPos> buffer, string path)
        {
            UndoCacheNode node           = new UndoCacheNode();
            string        lastLoggedName = "";

            using (FileStream fs = File.Create(path)) {
                BinaryWriter w          = new BinaryWriter(fs);
                long         entriesPos = 0;
                ChunkHeader  last       = default(ChunkHeader);

                foreach (Player.UndoPos uP in buffer)
                {
                    DateTime time     = Server.StartTime.AddSeconds(uP.timeDelta);
                    int      timeDiff = (int)(time - last.BaseTime).TotalSeconds;
                    if (last.LevelName != uP.mapName || timeDiff > (65535 >> 2) || last.Entries == ushort.MaxValue)
                    {
                        if (!LevelInfo.ExistsOffline(uP.mapName))
                        {
                            if (uP.mapName != lastLoggedName)
                            {
                                lastLoggedName = uP.mapName;
                                Server.s.Log("Missing map file \"" + lastLoggedName + "\", skipping undo entries");
                            }
                            continue;
                        }

                        ushort width, height, length;
                        LvlFile.LoadDimensions(LevelInfo.LevelPath(uP.mapName), out width, out height, out length);
                        node.Width = width; node.Height = height; node.Length = length;
                        WriteChunkEntries(w, last.Entries, entriesPos);
                        node.MapName = uP.mapName;
                        last         = WriteEmptyChunk(w, node, time, ref entriesPos);
                    }

                    UndoCacheItem item  = UndoCacheItem.Make(node, 0, uP);
                    int           flags = (item.Flags & 0xC000) | timeDiff;
                    w.Write((ushort)flags); w.Write(item.Index);
                    w.Write(item.Type); w.Write(item.NewType);
                    last.Entries++;
                }
                if (last.Entries > 0)
                {
                    WriteChunkEntries(w, last.Entries, entriesPos);
                }
            }
        }
Ejemplo n.º 2
0
            public void FromOfflineLevel(string name)
            {
                this.name = name;
                LvlFile.LoadDimensions(LevelInfo.LevelPath(name),
                                       out Width, out Height, out Length);
                string path = LevelInfo.GetPropertiesPath(name);

                Server.s.Log(path);
                if (path != null)
                {
                    PropertiesFile.Read(path, ParseProperty, '=');
                }

                path = "levels/level properties/" + name + ".env";
                Server.s.Log(path);
                if (File.Exists(path))
                {
                    PropertiesFile.Read(path, ParseEnv, '=');
                }
            }