Esempio n. 1
0
 static string TokenWorlds(Player p)
 {
     return(LevelInfo.AllMapFiles().Length.ToString());
 }
Esempio n. 2
0
        public void Save(bool Override = false, bool clearPhysics = false)
        {
            if (blocks == null)
            {
                return;
            }
            string path = LevelInfo.LevelPath(name);

            if (LevelSave != null)
            {
                LevelSave(this);
            }
            OnLevelSaveEvent.Call(this);
            if (cancelsave1)
            {
                cancelsave1 = false; return;
            }
            if (cancelsave)
            {
                cancelsave = false; return;
            }

            try
            {
                if (!Directory.Exists("levels"))
                {
                    Directory.CreateDirectory("levels");
                }
                if (!Directory.Exists("levels/level properties"))
                {
                    Directory.CreateDirectory("levels/level properties");
                }

                if (changed || !File.Exists(path) || Override || (physicschanged && clearPhysics))
                {
                    if (clearPhysics)
                    {
                        ClearPhysics();
                    }

                    if (File.Exists(path))
                    {
                        if (File.Exists(path + ".prev"))
                        {
                            File.Delete(path + ".prev");
                        }
                        File.Copy(path, path + ".prev");
                        File.Delete(path);
                    }
                    LvlFile.Save(this, path + ".backup");
                    File.Copy(path + ".backup", path);
                    SaveSettings(this);

                    Server.s.Log(string.Format("SAVED: Level \"{0}\". ({1}/{2}/{3})", name, players.Count,
                                               PlayerInfo.Online.Count, Server.players));
                    changed = false;
                }
                else
                {
                    Server.s.Log("Skipping level save for " + name + ".");
                }
            }
            catch (OutOfMemoryException e)
            {
                Server.ErrorLog(e);
                if (Server.mono)
                {
                    Process[] prs = Process.GetProcesses();
                    foreach (Process pr in prs)
                    {
                        if (pr.ProcessName == "MCGalaxy")
                        {
                            pr.Kill();
                        }
                    }
                }
                else
                {
                    Command.all.Find("restart").Use(null, "");
                }
            } catch (Exception e) {
                Server.s.Log("FAILED TO SAVE :" + name);
                Player.GlobalMessage("FAILED TO SAVE :" + name);
                Server.ErrorLog(e);
            }
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
Esempio n. 3
0
        //givenName is safe against SQL injections, it gets checked in CmdLoad.cs
        public static Level Load(string givenName, byte phys)
        {
            if (LevelLoad != null)
            {
                LevelLoad(givenName);
            }
            OnLevelLoadEvent.Call(givenName);
            if (cancelload)
            {
                cancelload = false;
                return(null);
            }
            CreateLeveldb(givenName);

            string path = LevelInfo.LevelPath(givenName);

            if (File.Exists(path))
            {
                try
                {
                    Level level = LvlFile.Load(givenName, path);
                    level.setPhysics(phys);
                    level.backedup = true;

                    using (DataTable ZoneDB = Database.fillData("SELECT * FROM `Zone" + givenName + "`"))
                    {
                        Zone Zn;
                        for (int i = 0; i < ZoneDB.Rows.Count; ++i)
                        {
                            DataRow row = ZoneDB.Rows[i];
                            Zn.smallX = ushort.Parse(row["SmallX"].ToString());
                            Zn.smallY = ushort.Parse(row["SmallY"].ToString());
                            Zn.smallZ = ushort.Parse(row["SmallZ"].ToString());
                            Zn.bigX   = ushort.Parse(row["BigX"].ToString());
                            Zn.bigY   = ushort.Parse(row["BigY"].ToString());
                            Zn.bigZ   = ushort.Parse(row["BigZ"].ToString());
                            Zn.Owner  = row["Owner"].ToString();
                            level.ZoneList.Add(Zn);
                        }
                    }

                    level.jailx    = (ushort)(level.spawnx * 32);
                    level.jaily    = (ushort)(level.spawny * 32);
                    level.jailz    = (ushort)(level.spawnz * 32);
                    level.jailrotx = level.rotx;
                    level.jailroty = level.roty;
                    level.StartPhysics();
                    //level.physChecker.Elapsed += delegate
                    //{
                    //    if (!level.physicssate && level.physics > 0)
                    //        level.StartPhysics();
                    //};
                    //level.physChecker.Start();

                    try
                    {
                        DataTable foundDB = Database.fillData("SELECT * FROM `Portals" + givenName + "`");

                        for (int i = 0; i < foundDB.Rows.Count; ++i)
                        {
                            DataRow row = foundDB.Rows[i];
                            if (
                                !Block.portal(level.GetTile(ushort.Parse(row["EntryX"].ToString()),
                                                            ushort.Parse(row["EntryY"].ToString()),
                                                            ushort.Parse(row["EntryZ"].ToString()))))
                            {
                                Database.executeQuery("DELETE FROM `Portals" + givenName + "` WHERE EntryX=" +
                                                      row["EntryX"] + " AND EntryY=" +
                                                      row["EntryY"] + " AND EntryZ=" +
                                                      row["EntryZ"]);
                            }
                        }
                        foundDB = Database.fillData("SELECT * FROM `Messages" + givenName + "`");

                        for (int i = 0; i < foundDB.Rows.Count; ++i)
                        {
                            DataRow row = foundDB.Rows[i];
                            if (
                                !Block.mb(level.GetTile(ushort.Parse(row["X"].ToString()),
                                                        ushort.Parse(row["Y"].ToString()),
                                                        ushort.Parse(row["Z"].ToString()))))
                            {
                                //givenName is safe against SQL injections, it gets checked in CmdLoad.cs
                                Database.executeQuery("DELETE FROM `Messages" + givenName + "` WHERE X=" +
                                                      row["X"] + " AND Y=" + row["Y"] +
                                                      " AND Z=" + row["Z"]);
                            }
                        }
                        foundDB.Dispose();
                    } catch (Exception e) {
                        Server.ErrorLog(e);
                    }

                    try {
                        string propsPath = LevelInfo.GetPropertiesPath(level.name);
                        if (propsPath != null)
                        {
                            LvlProperties.Load(level, propsPath);
                        }
                        else
                        {
                            Server.s.Log(".properties file for level " + level.name + " was not found.");
                        }
                        LvlProperties.LoadEnv(level, level.name);
                    } catch (Exception e) {
                        Server.ErrorLog(e);
                    }

                    BlockDefinition[] defs = BlockDefinition.Load(false, level);
                    for (int i = 0; i < defs.Length; i++)
                    {
                        if (defs[i] == null)
                        {
                            continue;
                        }
                        level.CustomBlockDefs[i] = defs[i];
                    }

                    Server.s.Log(string.Format("Level \"{0}\" loaded.", level.name));
                    if (LevelLoaded != null)
                    {
                        LevelLoaded(level);
                    }
                    OnLevelLoadedEvent.Call(level);
                    return(level);
                } catch (Exception ex) {
                    Server.ErrorLog(ex);
                    return(null);
                }
            }
            Server.s.Log("ERROR loading level.");
            return(null);
        }
Esempio n. 4
0
 public static Level FindExact(string name)
 {
     return(LevelInfo.FindExact(name));
 }
Esempio n. 5
0
 public void SaveFor(string map)
 {
     Save(LevelInfo.PropsPath(map), map);
 }
Esempio n. 6
0
        public static void Resize(ref Level lvl, int width, int height, int length)
        {
            Level res = new Level(lvl.name, (ushort)width, (ushort)height, (ushort)length);

            res.hasPortals       = lvl.hasPortals;
            res.hasMessageBlocks = lvl.hasMessageBlocks;
            byte[] src = lvl.blocks, dst = res.blocks;

            // Copy blocks in bulk
            width  = Math.Min(lvl.Width, res.Width);
            height = Math.Min(lvl.Height, res.Height);
            length = Math.Min(lvl.Length, res.Length);
            for (int y = 0; y < height; y++)
            {
                for (int z = 0; z < length; z++)
                {
                    int srcI = lvl.Width * (z + y * lvl.Length);
                    int dstI = res.Width * (z + y * res.Length);
                    Buffer.BlockCopy(src, srcI, dst, dstI, width);
                }
            }

            // Copy extended blocks in bulk
            width  = Math.Min(lvl.ChunksX, res.ChunksX);
            height = Math.Min(lvl.ChunksY, res.ChunksY);
            length = Math.Min(lvl.ChunksZ, res.ChunksZ);
            for (int cy = 0; cy < height; cy++)
            {
                for (int cz = 0; cz < length; cz++)
                {
                    for (int cx = 0; cx < width; cx++)
                    {
                        src = lvl.CustomBlocks[(cy * lvl.ChunksZ + cz) * lvl.ChunksX + cx];
                        if (src == null)
                        {
                            continue;
                        }

                        dst = new byte[16 * 16 * 16];
                        res.CustomBlocks[(cy * res.ChunksZ + cz) * res.ChunksX + cx] = dst;
                        Buffer.BlockCopy(src, 0, dst, 0, 16 * 16 * 16);
                    }
                }
            }

            // TODO: This copying is really ugly and probably not 100% right
            res.spawnx = lvl.spawnx; res.spawny = lvl.spawny; res.spawnz = lvl.spawnz;
            res.rotx   = lvl.rotx; res.roty = lvl.roty;

            lock (lvl.saveLock) {
                lvl.Backup(true);

                // Make sure zones are kept
                res.Zones = lvl.Zones;
                lvl.Zones = new VolatileArray <Zone>(false);

                IMapExporter.Formats[0].Write(LevelInfo.MapPath(lvl.name), res);
                lvl.SaveChanges = false;
            }

            res.ChangedSinceBackup = false;
            Level.LoadMetadata(res);
            BotsFile.Load(res);

            LevelActions.Replace(lvl, res);
            lvl = res;
        }
Esempio n. 7
0
 public static Level Load(string name)
 {
     return(Load(name, LevelInfo.MapPath(name)));
 }
Esempio n. 8
0
 public static void CopyLevel(string src, string dst)
 {
     File.Copy(LevelInfo.MapPath(src), LevelInfo.MapPath(dst));
     DoAll(src, dst, action_copy);
     CopyDatabaseTables(src, dst);
 }