コード例 #1
0
        public override void Use(Player p, string message)
        {
            string[] args = message.Split(' ');
            string   path = args.Length == 1 ? LevelInfo.LevelPath(args[0]) :
                            LevelInfo.BackupPath(args[0], args[1]);

            Server.s.Log(path);

            if (!File.Exists(path))
            {
                Player.SendMessage(p, "Level or backup could not be found."); return;
            }

            Level lvl = LvlFile.Load(name, path);

            lvl.setPhysics(0);
            lvl.backedup        = true;
            lvl.permissionbuild = LevelPermission.Admin;

            lvl.jailx    = (ushort)(lvl.spawnx * 32);
            lvl.jaily    = (ushort)(lvl.spawny * 32);
            lvl.jailz    = (ushort)(lvl.spawnz * 32);
            lvl.jailrotx = lvl.rotx; lvl.jailroty = lvl.roty;

            p.Loading = true;
            CmdReveal.DespawnEntities(p);
            Level oldLevel = p.level;

            p.level = lvl;
            p.SendMotd();
            if (!p.SendRawMap(oldLevel, lvl))
            {
                return;
            }

            ushort x = (ushort)((0.5 + lvl.spawnx) * 32);
            ushort y = (ushort)((1 + lvl.spawny) * 32);
            ushort z = (ushort)((0.5 + lvl.spawnz) * 32);

            p.aiming = false;
            Player.GlobalSpawn(p, x, y, z, lvl.rotx, lvl.roty, true);
            p.ClearBlockchange();
            p.Loading = false;

            if (args.Length == 1)
            {
                lvl.name = "&cMuseum " + Server.DefaultColor + "(" + args[0] + ")";
            }
            else
            {
                lvl.name = "&cMuseum " + Server.DefaultColor + "(" + args[0] + " " + args[1] + ")";
            }

            if (!p.hidden)
            {
                Player.GlobalMessage(p.ColoredName + " %Swent to the " + lvl.name);
            }
        }
コード例 #2
0
        void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType)
        {
            RevertAndClearState(p, x, y, z);
            CatchPos cpos = (CatchPos)p.blockchangeObject;
            string   path = LevelInfo.BackupPath(p.level.name, cpos.backup);

            try {
                using (Level other = LvlFile.Load("tempLevel", path)) {
                    if (!CopyBlocks(p, other, x, y, z, cpos))
                    {
                        return;
                    }
                }
                if (p.staticCommands)
                {
                    p.Blockchange += Blockchange1;
                }
            } catch (Exception ex) {
                Server.ErrorLog(ex);
                Server.s.Log("Restore selection failed");
            }
        }
コード例 #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);
        }