Пример #1
0
 public static void RemoveGlobal(BlockDefinition def) {
     GlobalDefinitions[def.BlockID] = null;
     foreach (Player p in Player.players) {
         if (p.HasCpeExt(CpeExt.BlockDefinitions))
             p.SendRaw(Opcode.CpeRemoveBlockDefinition, def.BlockID);
     }
     SaveGlobal("blocks.json");
 }
Пример #2
0
 public static void AddGlobal(BlockDefinition def) {
     GlobalDefinitions[def.BlockID] = def;
     foreach (Player pl in Player.players) {
         if (!pl.HasCpeExt(CpeExt.BlockDefinitions)) continue;
             
         if (pl.HasCpeExt(CpeExt.BlockDefinitionsExt) && def.Shape != 0)
             SendDefineBlockExt(pl, def);
         else
             SendDefineBlock(pl, def);
         pl.SendSetBlockPermission(def.BlockID, 1, 1);
     }
 }
Пример #3
0
 public static void LoadGlobal(string path) {
     try {
         if (File.Exists(path)) {
             string json = File.ReadAllText(path);
             GlobalDefinitions = JsonConvert.DeserializeObject<BlockDefinition[]>(json);
         }
     } catch (Exception ex) {
         Server.ErrorLog(ex);
         GlobalDefinitions = new BlockDefinition[256];
     }            
     for (int i = 0; i < 256; i++) {
         if (GlobalDefinitions[i] != null && GlobalDefinitions[i].Name == null)
             GlobalDefinitions[i] = null;
     }
     
     GlobalDefinitions[0] = new BlockDefinition();
     GlobalDefinitions[0].Name = "Air fallback";
     SaveGlobal("blocks.json");
 }
Пример #4
0
        bool SendRawMapCore(Level prev, Level level)
        {
            if (level.blocks == null)
            {
                return(false);
            }
            bool success = true;

            useCheckpointSpawn  = false;
            lastCheckpointIndex = -1;

            AFKCooldown = DateTime.UtcNow.AddSeconds(2);
            ZoneIn      = null;
            SendMapMotd();
            AllowBuild = level.BuildAccess.CheckAllowed(this);

            try {
                int volume = level.blocks.Length;
                if (Supports(CpeExt.FastMap))
                {
                    Send(Packet.LevelInitaliseExt(volume));
                }
                else
                {
                    Send(Packet.LevelInitalise());
                }

                if (hasBlockDefs)
                {
                    if (prev != null && prev != level)
                    {
                        RemoveOldLevelCustomBlocks(prev);
                    }
                    BlockDefinition.SendLevelCustomBlocks(this);

                    if (Supports(CpeExt.InventoryOrder))
                    {
                        BlockDefinition.SendLevelInventoryOrder(this);
                    }
                }

                using (LevelChunkStream dst = new LevelChunkStream(this))
                    using (Stream stream = LevelChunkStream.CompressMapHeader(this, volume, dst))
                    {
                        if (level.MightHaveCustomBlocks())
                        {
                            LevelChunkStream.CompressMap(this, stream, dst);
                        }
                        else
                        {
                            LevelChunkStream.CompressMapSimple(this, stream, dst);
                        }
                    }

                // Force players to read the MOTD (clamped to 3 seconds at most)
                if (level.Config.LoadDelay > 0)
                {
                    System.Threading.Thread.Sleep(level.Config.LoadDelay);
                }

                byte[] buffer = Packet.LevelFinalise(level.Width, level.Height, level.Length);
                Send(buffer);
                Loading = false;

                OnSentMapEvent.Call(this, prev, level);
            } catch (Exception ex) {
                success = false;
                PlayerActions.ChangeMap(this, Server.mainLevel);
                Message("&WThere was an error sending the map, you have been sent to the main level.");
                Logger.LogError(ex);
            } finally {
                Server.DoGC();
            }
            return(success);
        }
Пример #5
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);
        }
Пример #6
0
        internal static void SetDefaultNames()
        {
            Aliases.Clear();
            SetDefaultAliases();
            int start = 0;

            // Using a single const string reduces size by 2KB
            const string default_names =
                "Air@Stone@Grass@Dirt@Cobblestone@Wood@Sapling@Bedrock@" +
                "Active_Water@Water@Active_Lava@Lava@Sand@Gravel@Gold_Ore@Iron_Ore@" +
                "Coal@Log@Leaves@Sponge@Glass@Red@Orange@Yellow@" +
                "Lime@Green@Teal@Aqua@Cyan@Blue@Indigo@Violet@" +
                "Magenta@Pink@Black@Gray@White@Dandelion@Rose@Brown_Shroom@" +
                "Red_Shroom@Gold@Iron@DoubleSlab@Slab@Brick@TNT@BookShelf@" +
                "MossyRocks@Obsidian@CobblestoneSlab@Rope@SandStone@Snow@Fire@LightPink@" +
                "ForestGreen@Brown@DeepBlue@Turquoise@Ice@CeramicTile@MagmaBlock@Pillar@" +
                "Crate@StoneBrick@@@@@FlagBase@@" +
                "@Fast_Hot_Lava@C4@C4_Det@@@@@" +
                "Door_Cobblestone@@@Door_Red@@Door_Orange@Door_Yellow@Door_LightGreen@" +
                "@Door_AquaGreen@Door_Cyan@Door_LightBlue@Door_Purple@Door_LightPurple@Door_Pink@Door_DarkPink@" +
                "Door_DarkGrey@Door_LightGrey@Door_White@@Op_Glass@Opsidian@Op_Brick@Op_Stone@" +
                "Op_Cobblestone@Op_Air@Op_Water@Op_Lava@@Lava_Sponge@Wood_Float@Door@" +
                "Lava_Fast@Door_Obsidian@Door_Glass@Door_Stone@Door_Leaves@Door_Sand@Door_Wood@Door_Green@" +
                "Door_TNT@Door_Stair@tDoor@tDoor_Obsidian@tDoor_Glass@tDoor_Stone@tDoor_Leaves@tDoor_Sand@" +
                "tDoor_Wood@tDoor_Green@White_Message@Black_Message@Air_Message@Water_Message@Lava_Message@tDoor_TNT@" +
                "tDoor_Stair@tDoor_Air@tDoor_Water@tDoor_lava@Waterfall@Lavafall@@Water_Faucet@" +
                "Lava_Faucet@Finite_Water@Finite_Lava@Finite_Faucet@oDoor@oDoor_Obsidian@oDoor_Glass@oDoor_Stone@" +
                "oDoor_Leaves@oDoor_Sand@oDoor_Wood@oDoor_Green@oDoor_TNT@oDoor_Stair@oDoor_Lava@oDoor_Water@" +
                "Air_Portal@Water_Portal@Lava_Portal@Custom_Block@Air_Door@Air_Switch@Door_Water@Door_Lava@" +
                "oDoor_Air@oDoor_Obsidian_Air@oDoor_Glass_Air@oDoor_Stone_Air@oDoor_Leaves_Air@oDoor_Sand_Air@oDoor_Wood_Air@Blue_Portal@" +
                "Orange_Portal@oDoor_Red@oDoor_TNT_Air@oDoor_Stair_Air@oDoor_Lava_Air@oDoor_Water_Air@Small_TNT@Big_TNT@" +
                "TNT_Explosion@Lava_Fire@Nuke_TNT@RocketStart@RocketHead@Firework@Hot_Lava@Cold_Water@" +
                "Nerve_Gas@Active_Cold_Water@Active_Hot_Lava@Magma@Geyser@Checkpoint@@@" +
                "Air_Flood@Door_Air@Air_Flood_Layer@Air_Flood_Down@Air_Flood_Up@@@@" +
                "@@@Door8_Air@Door9_Air@@@@" +
                "@@@@Door_Iron@Door_Dirt@Door_Grass@Door_Blue@" +
                "Door_Book@@@@@@Train@Creeper@" +
                "Zombie@Zombie_Head@@Dove@Pidgeon@Duck@Phoenix@Red_Robin@" +
                "Blue_Bird@@Killer_Phoenix@@@GoldFish@Sea_Sponge@Shark@" +
                "Salmon@Betta_Fish@Lava_Shark@Snake@Snake_Tail@Door_Gold@@@";

            for (int b = 0; b < Block.Count; b++)
            {
                int    end  = default_names.IndexOf('@', start);
                string name = start == end ? "unknown" : default_names.Substring(start, end - start);
                start = end + 1;

                if (b > 0 && b < Block.CpeCount)
                {
                    BlockDefinition def = BlockDefinition.GlobalDefs[b];
                    if (def != null)
                    {
                        name = def.Name;
                    }
                }
                coreNames[b] = name;

                name = name.ToLower();
                if (name != "unknown")
                {
                    Aliases[name] = (byte)b;
                }
                if (name.IndexOf('_') >= 0)
                {
                    Aliases[name.Replace("_", "")] = (byte)b;
                }
            }
        }
Пример #7
0
        public static Level Load(string name, byte phys)
        {
            if (LevelLoad != null)
            {
                LevelLoad(name);
            }
            OnLevelLoadEvent.Call(name);
            if (cancelload)
            {
                cancelload = false; return(null);
            }

            string path = LevelInfo.LevelPath(name);

            if (!File.Exists(path))
            {
                Server.s.Log("Attempted to load " + name + ", but the level file does not exist.");
                return(null);
            }

            try {
                Level level = IMapImporter.Formats[0].Read(path, name, true);
                level.setPhysics(phys);
                level.backedup = true;

                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();

                try {
                    string propsPath = LevelInfo.FindPropertiesFile(level.name);
                    if (propsPath != null)
                    {
                        LvlProperties.Load(level, propsPath);
                    }
                    else
                    {
                        Server.s.Log(".properties file for level " + level.name + " was not found.");
                    }
                    // Backwards compatibility for older levels which had .env files.
                    LvlProperties.LoadEnv(level);
                } catch (Exception e) {
                    Server.ErrorLog(e);
                }
                level.BlockDB.Used = level.UseBlockDB;

                BlockDefinition[] defs = BlockDefinition.Load(false, level);
                for (int i = 0; i < defs.Length; i++)
                {
                    if (defs[i] == null)
                    {
                        continue;
                    }
                    level.CustomBlockDefs[i]  = defs[i];
                    level.CustomBlockProps[i] = new BlockProps((byte)i);
                }
                BlockProps.Load("lvl_" + level.name, level.CustomBlockProps);
                Bots.BotsFile.LoadBots(level);

                object locker = ThreadSafeCache.DBCache.Get(name);
                lock (locker) {
                    LevelDB.LoadZones(level, name);
                    LevelDB.LoadPortals(level, name);
                    LevelDB.LoadMessages(level, name);
                }

                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);
            }
        }
Пример #8
0
        bool SendRawMapCore(Level oldLevel, Level level)
        {
            if (level.blocks == null)
            {
                return(false);
            }
            bool success = true;

            useCheckpointSpawn  = false;
            lastCheckpointIndex = -1;

            LevelAccess access = level.BuildAccess.Check(this);

            AllowBuild = access == LevelAccess.Whitelisted || access == LevelAccess.Allowed;

            try {
                if (hasBlockDefs)
                {
                    if (oldLevel != null && oldLevel != level)
                    {
                        RemoveOldLevelCustomBlocks(oldLevel);
                    }
                    BlockDefinition.SendLevelCustomBlocks(this);
                }

                SendRaw(Opcode.LevelInitialise);
                using (LevelChunkStream s = new LevelChunkStream(this))
                    LevelChunkStream.CompressMap(this, s);

                byte[] buffer = new byte[7];
                buffer[0] = Opcode.LevelFinalise;
                NetUtils.WriteI16((short)level.Width, buffer, 1);
                NetUtils.WriteI16((short)level.Height, buffer, 3);
                NetUtils.WriteI16((short)level.Length, buffer, 5);
                Send(buffer);
                AFKCooldown = DateTime.UtcNow.AddSeconds(2);
                Loading     = false;

                if (HasCpeExt(CpeExt.EnvWeatherType))
                {
                    Send(Packet.EnvWeatherType((byte)level.Weather));
                }
                if (HasCpeExt(CpeExt.EnvColors))
                {
                    SendCurrentEnvColors();
                }
                SendCurrentMapAppearance();
                if (HasCpeExt(CpeExt.BlockPermissions))
                {
                    SendCurrentBlockPermissions();
                }

                if (OnSendMap != null)
                {
                    OnSendMap(this, buffer);
                }
                if (!level.guns && aiming)
                {
                    aiming = false;
                    ClearBlockchange();
                }
            } catch (Exception ex) {
                success = false;
                PlayerActions.ChangeMap(this, Server.mainLevel);
                SendMessage("There was an error sending the map data, you have been sent to the main level.");
                Server.ErrorLog(ex);
            } finally {
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            return(success);
        }
Пример #9
0
 static void SendDefineBlockExt(Player p, BlockDefinition def) {
     byte[] buffer = new byte[85];
     buffer[0] = Opcode.CpeDefineBlockExt;
     MakeDefineBlockStart(def, buffer);
     buffer[74] = def.MinX;
     buffer[75] = def.MinZ;
     buffer[76] = def.MinY;
     buffer[77] = def.MaxX;
     buffer[78] = def.MaxZ;
     buffer[79] = def.MaxY;
     MakeDefineBlockEnd(def, 80, buffer);
     p.SendRaw(buffer);
 }
Пример #10
0
        internal unsafe static void SendLevelInventoryOrder(Player pl)
        {
            BlockDefinition[] defs = pl.level.CustomBlockDefs;

            int  count           = pl.MaxRawBlock + 1;
            int *order_to_blocks = stackalloc int[Block.ExtendedCount];
            int *block_to_orders = stackalloc int[Block.ExtendedCount];

            for (int b = 0; b < Block.ExtendedCount; b++)
            {
                order_to_blocks[b] = -1;
                block_to_orders[b] = -1;
            }

            // Fill slots with explicit order
            for (int i = 0; i < defs.Length; i++)
            {
                BlockDefinition def = defs[i];
                if (def == null || def.RawID > pl.MaxRawBlock)
                {
                    continue;
                }
                if (def.InventoryOrder == -1)
                {
                    continue;
                }

                if (def.InventoryOrder != 0)
                {
                    if (order_to_blocks[def.InventoryOrder] != -1)
                    {
                        continue;
                    }
                    order_to_blocks[def.InventoryOrder] = def.RawID;
                }
                block_to_orders[def.RawID] = def.InventoryOrder;
            }

            // Put blocks into their default slot if slot is unused
            for (int i = 0; i < defs.Length; i++)
            {
                BlockDefinition def = defs[i];
                int             raw = def != null ? def.RawID : i;
                if (raw > pl.MaxRawBlock || (def == null && raw >= Block.CPE_COUNT))
                {
                    continue;
                }

                if (def != null && def.InventoryOrder >= 0)
                {
                    continue;
                }
                if (order_to_blocks[raw] == -1)
                {
                    order_to_blocks[raw] = raw;
                    block_to_orders[raw] = raw;
                }
            }

            // Push blocks whose slots conflict with other blocks into free slots at end
            for (int i = defs.Length - 1; i >= 0; i--)
            {
                BlockDefinition def = defs[i];
                int             raw = def != null ? def.RawID : i;
                if (raw > pl.MaxRawBlock || (def == null && raw >= Block.CPE_COUNT))
                {
                    continue;
                }

                if (block_to_orders[raw] != -1)
                {
                    continue;
                }
                for (int slot = count - 1; slot >= 1; slot--)
                {
                    if (order_to_blocks[slot] != -1)
                    {
                        continue;
                    }

                    block_to_orders[raw]  = slot;
                    order_to_blocks[slot] = raw;
                    break;
                }
            }

            for (int raw = 0; raw < count; raw++)
            {
                int order = block_to_orders[raw];
                if (order == -1)
                {
                    order = 0;
                }

                BlockDefinition def = defs[Block.FromRaw((BlockID)raw)];
                if (def == null && raw >= Block.CPE_COUNT)
                {
                    continue;
                }
                // Special case, don't want 255 getting hidden by default
                if (raw == 255 && def.InventoryOrder == -1)
                {
                    continue;
                }

                pl.Send(Packet.SetInventoryOrder((BlockID)raw, (BlockID)order, pl.hasExtBlocks));
            }
        }
Пример #11
0
        internal static void SetDefaultNames()
        {
            string[] names = new string[] { "Air", "Stone", "Grass", "Dirt", "Cobblestone",
                                            "Wood", "Sapling", "Bedrock", "Active_Water", "Water", "Active_Lava", "Lava",
                                            "Sand", "Gravel", "Gold_Ore", "Iron_Ore", "Coal", "Log", "Leaves", "Sponge",
                                            "Glass", "Red", "Orange", "Yellow", "Lime", "Green", "Teal", "Aqua", "Cyan",
                                            "Blue", "Indigo", "Violet", "Magenta", "Pink", "Black", "Gray", "White",
                                            "Dandelion", "Rose", "Brown_Shroom", "Red_Shroom", "Gold", "Iron",
                                            "DoubleSlab", "Slab", "Brick", "TNT", "BookShelf", "MossyRocks",
                                            "Obsidian", "CobblestoneSlab", "Rope", "SandStone", "Snow", "Fire", "LightPink",
                                            "ForestGreen", "Brown", "DeepBlue", "Turquoise", "Ice", "CeramicTile", "MagmaBlock",
                                            "Pillar", "Crate", "StoneBrick", null, null,
                                            null, null, "FlagBase", null, null,
                                            "Fast_Hot_Lava", "C4", "C4_Det", null, null, null, null,
                                            "Door_Cobblestone", null, null, "Door_Red", null,
                                            "Door_Orange", "Door_Yellow", "Door_LightGreen", null, "Door_AquaGreen",
                                            "Door_Cyan", "Door_LightBlue", "Door_Purple", "Door_LightPurple", "Door_Pink",
                                            "Door_DarkPink", "Door_DarkGrey", "Door_LightGrey", "Door_White", null,
                                            "Op_Glass", "Opsidian", "Op_Brick", "Op_Stone", "Op_Cobblestone", "Op_Air",
                                            "Op_Water", "Op_Lava", null, "Lava_Sponge", "Wood_Float", "Door",
                                            "Lava_Fast", "Door_Obsidian", "Door_Glass", "Door_Stone", "Door_Leaves", "Door_Sand",
                                            "Door_Wood", "Door_Green", "Door_TNT", "Door_Stair", "tDoor", "tDoor_Obsidian",
                                            "tDoor_Glass", "tDoor_Stone", "tDoor_Leaves", "tDoor_Sand", "tDoor_Wood",
                                            "tDoor_Green", "White_Message", "Black_Message", "Air_Message", "Water_Message",
                                            "Lava_Message", "tDoor_TNT", "tDoor_Stair", "tDoor_Air", "tDoor_Water", "tDoor_lava",
                                            "Waterfall", "Lavafall", null, "Water_Faucet", "Lava_Faucet", "Finite_Water",
                                            "Finite_Lava", "Finite_Faucet", "oDoor", "oDoor_Obsidian", "oDoor_Glass",
                                            "oDoor_Stone", "oDoor_Leaves", "oDoor_Sand", "oDoor_Wood", "oDoor_Green",
                                            "oDoor_TNT", "oDoor_Stair", "oDoor_Lava", "oDoor_Water", "Air_Portal", "Water_Portal",
                                            "Lava_Portal", "Custom_Block", "Air_Door", "Air_Switch", "Door_Water", "Door_Lava",
                                            "oDoor_Air", "oDoor_Obsidian_Air", "oDoor_Glass_Air", "oDoor_Stone_Air",
                                            "oDoor_Leaves_Air", "oDoor_Sand_Air", "oDoor_Wood_Air", "Blue_Portal", "Orange_Portal",
                                            "oDoor_Red", "oDoor_TNT_Air", "oDoor_Stair_Air", "oDoor_Lava_Air", "oDoor_Water_Air",
                                            "Small_TNT", "Big_TNT", "TNT_Explosion", "Lava_Fire", "Nuke_TNT", "RocketStart",
                                            "RocketHead", "Firework", "Hot_Lava", "Cold_Water", "Nerve_Gas", "Active_Cold_Water",
                                            "Active_Hot_Lava", "Magma", "Geyser", "Checkpoint", null, null, "Air_Flood",
                                            "Door_Air", "Air_Flood_Layer", "Air_Flood_Down", "Air_Flood_Up", null,
                                            null, null, null, null, null, "Door8_Air",
                                            "Door9_Air", null, null, null, null, null,
                                            null, null, "Door_Iron", "Door_Dirt", "Door_Grass", "Door_Blue", "Door_Book",
                                            null, null, null, null, null,
                                            "Train", "Creeper", "Zombie", "Zombie_Head", null, "Dove", "Pidgeon", "Duck",
                                            "Phoenix", "Red_Robin", "Blue_Bird", null, "Killer_Phoenix", null, null,
                                            "GoldFish", "Sea_Sponge", "Shark", "Salmon", "Betta_Fish", "Lava_Shark", "Snake",
                                            "Snake_Tail", "Door_Gold", null, null };

            Aliases.Clear();
            SetDefaultAliases();
            for (int i = 0; i < names.Length; i++)
            {
                string name = names[i];
                if (name == null)
                {
                    name = "unknown";
                }
                if (i > 0 && i < Block.CpeCount)
                {
                    BlockDefinition def = BlockDefinition.GlobalDefs[i];
                    if (def != null)
                    {
                        name = def.Name;
                    }
                }
                coreNames[i] = name;

                name = name.ToLower();
                if (name != "unknown")
                {
                    Aliases[name] = (byte)i;
                }
                if (name.IndexOf('_') >= 0)
                {
                    Aliases[name.Replace("_", "")] = (byte)i;
                }
            }
        }
Пример #12
0
 static void MakeDefineBlockEnd(BlockDefinition def, int offset, byte[] buffer) {
     buffer[offset + 0] = def.BlockDraw;
     buffer[offset + 1] = def.FogDensity;
     buffer[offset + 2] = def.FogR;
     buffer[offset + 3] = def.FogG;
     buffer[offset + 4] = def.FogB;
 }
Пример #13
0
 static void MakeDefineBlockStart(BlockDefinition def, byte[] buffer) {
     // speed = 2^((raw - 128) / 64);
     // therefore raw = 64log2(speed) + 128
     byte rawSpeed = (byte)(64 * Math.Log(def.Speed, 2) + 128);
     
     buffer[1] = def.BlockID;
     Encoding.ASCII.GetBytes(def.Name.PadRight(64), 0, 64, buffer, 2);
     buffer[66] = def.CollideType;
     buffer[67] = rawSpeed;
     buffer[68] = def.TopTex;
     buffer[69] = def.SideTex;
     buffer[70] = def.BottomTex;
     buffer[71] = (byte)(def.BlocksLight ? 0 : 1);
     buffer[72] = def.WalkSound;
     buffer[73] = (byte)(def.FullBright ? 1 : 0);
 }
Пример #14
0
        public bool SendRawMap(Level oldLevel, Level level)
        {
            if (level.blocks == null)
            {
                return(false);
            }
            bool success = true;

            useCheckpointSpawn  = false;
            lastCheckpointIndex = -1;

            try {
                int    usedLength = 0;
                byte[] buffer     = CompressRawMap(out usedLength);

                if (hasBlockDefs)
                {
                    if (oldLevel != null && oldLevel != level)
                    {
                        RemoveOldLevelCustomBlocks(oldLevel);
                    }
                    BlockDefinition.SendLevelCustomBlocks(this);
                }

                SendRaw(Opcode.LevelInitialise);
                int totalRead = 0;
                while (totalRead < usedLength)
                {
                    byte[] packet = new byte[1028]; // need each packet separate for Mono
                    packet[0] = Opcode.LevelDataChunk;
                    short length = (short)Math.Min(buffer.Length - totalRead, 1024);
                    NetUtils.WriteI16(length, packet, 1);
                    Buffer.BlockCopy(buffer, totalRead, packet, 3, length);
                    packet[1027] = (byte)(100 * (float)totalRead / buffer.Length);

                    SendRaw(packet);
                    if (ip != "127.0.0.1")
                    {
                        Thread.Sleep(Server.updateTimer.Interval > 1000 ? 100 : 10);
                    }
                    totalRead += length;
                }

                buffer    = new byte[7];
                buffer[0] = Opcode.LevelFinalise;
                NetUtils.WriteI16((short)level.Width, buffer, 1);
                NetUtils.WriteI16((short)level.Height, buffer, 3);
                NetUtils.WriteI16((short)level.Length, buffer, 5);
                SendRaw(buffer);
                Loading = false;

                if (HasCpeExt(CpeExt.EnvWeatherType))
                {
                    SendSetMapWeather(level.weather);
                }
                if (HasCpeExt(CpeExt.EnvColors))
                {
                    SendCurrentEnvColors();
                }
                if (HasCpeExt(CpeExt.EnvMapAppearance) || HasCpeExt(CpeExt.EnvMapAppearance, 2))
                {
                    SendCurrentMapAppearance();
                }

                if (OnSendMap != null)
                {
                    OnSendMap(this, buffer);
                }
                if (!level.guns)
                {
                    aiming = false;
                }
            } catch (Exception ex) {
                success = false;
                Command.all.Find("goto").Use(this, Server.mainLevel.name);
                SendMessage("There was an error sending the map data, you have been sent to the main level.");
                Server.ErrorLog(ex);
            } finally {
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }

            if (HasCpeExt(CpeExt.BlockPermissions))
            {
                SendCurrentBlockPermissions();
            }
            return(success);
        }
Пример #15
0
        internal static void SetDefaultNames()
        {
            string[] names = { "air",              "stone",              "grass",           "dirt",             "cobblestone",     "wood",              "sapling",
                               "bedrock",          "active_water",       "water",           "active_lava",      "lava",            "sand",              "gravel",
                               "gold_ore",         "iron_ore",           "coal",            "log",              "leaves",          "sponge",            "glass",     "red",
                               "orange",           "yellow",             "lime",            "green",            "teal",            "aqua",              "cyan",
                               "blue",             "indigo",             "violet",          "magenta",          "pink",            "black",             "gray",      "white",
                               "dandelion",        "rose",               "brown_shroom",    "red_shroom",       "gold",            "iron",
                               "doubleslab",       "slab",               "brick",           "tnt",              "bookshelf",       "mossyrocks",
                               "obsidian",         "cobblestoneslab",    "rope",            "sandstone",        "snow",            "fire",              "lightpink",
                               "forestgreen",      "brown",              "deepblue",        "turquoise",        "ice",             "ceramictile",       "magmablock",
                               "pillar",           "crate",              "stonebrick",      null,               null,
                               null,               null,                 "flagbase",        null,               null,
                               "fast_hot_lava",    "c4",                 "c4_det",          null,               null,              null,                null,
                               "door_cobblestone", null,                 null,              "door_red",         null,
                               "door_orange",      "door_yellow",        "door_lightgreen", null,               "door_aquagreen",
                               "door_cyan",        "door_lightblue",     "door_purple",     "door_lightpurple", "door_pink",
                               "door_darkpink",    "door_darkgrey",      "door_lightgrey",  "door_white",       null,
                               "op_glass",         "opsidian",           "op_brick",        "op_stone",         "op_cobblestone",  "op_air",
                               "op_water",         "op_lava",            null,              "lava_sponge",      "wood_float",      "door",
                               "lava_fast",        "door_obsidian",      "door_glass",      "door_stone",       "door_leaves",     "door_sand",
                               "door_wood",        "door_green",         "door_tnt",        "door_stair",       "tdoor",           "tdoor_obsidian",
                               "tdoor_glass",      "tdoor_stone",        "tdoor_leaves",    "tdoor_sand",       "tdoor_wood",
                               "tdoor_green",      "white_message",      "black_message",   "air_message",      "water_message",
                               "lava_message",     "tdoor_tnt",          "tdoor_stair",     "tdoor_air",        "tdoor_water",     "tdoor_lava",
                               "waterfall",        "lavafall",           null,              "water_faucet",     "lava_faucet",     "finite_water",
                               "finite_lava",      "finite_faucet",      "odoor",           "odoor_obsidian",   "odoor_glass",
                               "odoor_stone",      "odoor_leaves",       "odoor_sand",      "odoor_wood",       "odoor_green",
                               "odoor_tnt",        "odoor_stair",        "odoor_lava",      "odoor_water",      "air_portal",      "water_portal",
                               "lava_portal",      "custom_block",       "air_door",        "air_switch",       "door_water",      "door_lava",
                               "odoor_wood_air",   "odoor_obsidian_air", "odoor_glass_air", "odoor_stone_air",
                               "odoor_leaves_air", "odoor_sand_air",     "odoor_wood_air",  "blue_portal",      "orange_portal",
                               "odoor_red",        "odoor_tnt_air",      "odoor_stair_air", "odoor_lava_air",   "odoor_water_air",
                               "small_tnt",        "big_tnt",            "tnt_explosion",   "lava_fire",        "nuke_tnt",        "rocketstart",
                               "rockethead",       "firework",           "hot_lava",        "cold_water",       "nerve_gas",       "active_cold_water",
                               "active_hot_lava",  "magma",              "geyser",          "checkpoint",       null,              null,                "air_flood",
                               "door_air",         "air_flood_layer",    "air_flood_down",  "air_flood_up",     null,
                               null,               null,                 null,              null,               null,              "door8_air",
                               "door9_air",        null,                 null,              null,               null,              null,
                               null,               null,                 "door_iron",       "door_dirt",        "door_grass",      "door_blue",         "door_book",
                               null,               null,                 null,              null,               null,
                               "train",            "creeper",            "zombie",          "zombie_head",      null,              "dove",              "pidgeon",   "duck",
                               "phoenix",          "red_robin",          "blue_bird",       null,               "killer_phoenix",  null,                null,
                               "goldfish",         "sea_sponge",         "shark",           "salmon",           "betta_fish",      "lava_shark",        "snake",
                               "snake_tail",       "door_gold",          null,              null };

            Aliases.Clear();
            SetDefaultAliases();
            for (int i = 0; i < names.Length; i++)
            {
                string name = names[i];
                if (name == null)
                {
                    name = "unknown";
                }
                if (i > 0 && i < Block.CpeCount)
                {
                    BlockDefinition def = BlockDefinition.GlobalDefs[i];
                    if (def != null)
                    {
                        name = def.Name;
                    }
                }

                Props[i].Name = name;
                if (name != "unknown")
                {
                    Aliases[name] = (byte)i;
                }
                if (name.IndexOf('_') >= 0)
                {
                    Aliases[name.Replace("_", "")] = (byte)i;
                }
            }
        }
Пример #16
0
        public static BlockDefinition[] Load(string path)
        {
            BlockDefinition[] defs = new BlockDefinition[Block.ExtendedCount];
            if (!File.Exists(path))
            {
                return(defs);
            }
            if (elems == null)
            {
                elems = ConfigElement.GetAll(typeof(BlockDefinition));
            }

            try {
                string json = File.ReadAllText(path);

                JsonReader reader = new JsonReader(json);
                reader.OnMember = (obj, key, value) => {
                    if (obj.Meta == null)
                    {
                        obj.Meta = new BlockDefinition();
                    }
                    ConfigElement.Parse(elems, obj.Meta, key, (string)value);
                };

                JsonArray array = (JsonArray)reader.Parse();
                if (array == null)
                {
                    return(defs);
                }

                foreach (object raw in array)
                {
                    JsonObject obj = (JsonObject)raw;
                    if (obj == null || obj.Meta == null)
                    {
                        continue;
                    }

                    BlockDefinition def = (BlockDefinition)obj.Meta;
                    if (String.IsNullOrEmpty(def.Name))
                    {
                        continue;
                    }

                    BlockID block = def.GetBlock();
                    if (block >= defs.Length)
                    {
                        Logger.Log(LogType.Warning, "Invalid block ID: " + def.RawID);
                    }
                    else
                    {
                        defs[block] = def;
                    }

                    // In case user manually edited fallback in the json file
                    def.FallBack = Math.Min(def.FallBack, Block.CPE_MAX_BLOCK);
                }
            } catch (Exception ex) {
                Logger.LogError("Error Loading block defs from " + path, ex);
            }
            return(defs);
        }
Пример #17
0
        public byte GetFallback(byte extType)
        {
            BlockDefinition def = CustomBlockDefs[extType];

            return(def == null ? Block.air : def.FallBack);
        }
Пример #18
0
 public void UpdateCustomBlock(BlockID block, BlockDefinition def)
 {
     CustomBlockDefs[block] = def;
     UpdateBlockHandlers(block);
     blockAABBs[block] = Block.BlockAABB(block, this);
 }
Пример #19
0
 static void SendDefineBlock(Player p, BlockDefinition def) {
     byte[] buffer = new byte[80];
     buffer[0] = Opcode.CpeDefineBlock;
     MakeDefineBlockStart(def, buffer);
     buffer[74] = def.Shape;
     MakeDefineBlockEnd(def, 75, buffer);
     p.SendRaw(buffer);
 }