Ejemplo n.º 1
0
        void SaveBlocks()
        {
            if (!BlocksChanged())
            {
                LoadBlocks(); return;
            }

            for (int b = 0; b < blockPropsChanged.Length; b++)
            {
                if (blockPropsChanged[b].ChangedScope == 0)
                {
                    continue;
                }
                Block.Props[b] = blockPropsChanged[b];
            }

            foreach (BlockPerms changed in blockPermsChanged)
            {
                BlockPerms.Set(changed.ID, changed.MinRank,
                               changed.Allowed, changed.Disallowed);
            }
            BlockPerms.ResendAllBlockPermissions();

            BlockProps.Save("default", Block.Props, 1);
            BlockPerms.Save();
            Block.SetBlocks();
            LoadBlocks();
        }
Ejemplo n.º 2
0
        void blk_list_SelectedIndexChanged(object sender, EventArgs e)
        {
            blockID        = Block.Byte(blk_list.SelectedItem.ToString());
            blockPermsOrig = BlockPerms.List[blockID];
            blockPerms     = blockPermsChanged.Find(p => p.BlockID == blockID);
            BlockInitSpecificArrays();
            blockSupressEvents = true;

            BlockProps props = blockPropsChanged[blockID];

            blk_cbMsgBlock.Checked = props.IsMessageBlock;
            blk_cbPortal.Checked   = props.IsPortal;
            blk_cbDeath.Checked    = props.KillerBlock;
            blk_txtDeath.Text      = props.DeathMessage;
            blk_txtDeath.Enabled   = blk_cbDeath.Checked;

            blk_cbDoor.Checked  = props.IsDoor;
            blk_cbTdoor.Checked = props.IsTDoor;
            blk_cbRails.Checked = props.IsRails;
            blk_cbLava.Checked  = props.LavaKills;
            blk_cbWater.Checked = props.WaterKills;

            BlockPerms perms = blockPerms != null ? blockPerms : blockPermsOrig;

            GuiPerms.SetDefaultIndex(blk_cmbMin, perms.MinRank);
            GuiPerms.SetSpecificPerms(perms.Allowed, blockAllowBoxes);
            GuiPerms.SetSpecificPerms(perms.Disallowed, blockDisallowBoxes);
            blockSupressEvents = false;
        }
Ejemplo n.º 3
0
        void blk_list_SelectedIndexChanged(object sender, EventArgs e)
        {
            curBlock       = blockIDMap[blk_list.SelectedIndex];
            blockPermsOrig = BlockPerms.Find(curBlock);
            blockPermsCopy = blockPermsChanged.Find(p => p.ID == curBlock);
            BlockInitSpecificArrays();
            blockItems.SupressEvents = true;

            BlockProps props = blockPropsChanged[curBlock];

            blk_cbMsgBlock.Checked = props.IsMessageBlock;
            blk_cbPortal.Checked   = props.IsPortal;
            blk_cbDeath.Checked    = props.KillerBlock;
            blk_txtDeath.Text      = props.DeathMessage;
            blk_txtDeath.Enabled   = blk_cbDeath.Checked;

            blk_cbDoor.Checked  = props.IsDoor;
            blk_cbTdoor.Checked = props.IsTDoor;
            blk_cbRails.Checked = props.IsRails;
            blk_cbLava.Checked  = props.LavaKills;
            blk_cbWater.Checked = props.WaterKills;

            BlockPerms perms = blockPermsCopy != null ? blockPermsCopy : blockPermsOrig;

            blockItems.Update(perms);
        }
Ejemplo n.º 4
0
        public static void SetBlocks()
        {
            BlockProps[] props = Props;
            for (int b = 0; b < props.Length; b++)
            {
                props[b] = MakeDefaultProps((BlockID)b);
            }

            SetDefaultNames();
            string propsPath = Paths.BlockPropsPath("default");

            // backwards compatibility with older versions
            if (!File.Exists(propsPath))
            {
                BlockProps.Load("core", Props, 1, false);
                BlockProps.Load("global", Props, 1, true);
            }
            else
            {
                BlockProps.Load("default", Props, 1, false);
            }

            BlockPerms.Load();
            UpdateLoadedLevels();
        }
Ejemplo n.º 5
0
 public void SetUsableBlocks()
 {
     for (int i = 0; i < Blocks.Length; i++)
     {
         Blocks[i] = BlockPerms.UsableBy(Permission, (byte)i);
     }
 }
Ejemplo n.º 6
0
 public static byte[] UserType(Player p)
 {
     byte[] buffer = new byte[2];
     buffer[0] = Opcode.SetPermission;
     buffer[1] = BlockPerms.UsableBy(p, Block.Bedrock) ? (byte)100 : (byte)0;
     return(buffer);
 }
Ejemplo n.º 7
0
        void SaveBlocks()
        {
            if (!BlocksChanged())
            {
                LoadBlocks(); return;
            }

            for (int i = 0; i < blockPropsChanged.Length; i++)
            {
                if (!blockPropsChanged[i].Changed)
                {
                    continue;
                }
                Block.Props[i] = blockPropsChanged[i];
            }
            foreach (BlockPerms perms in blockPermsChanged)
            {
                BlockPerms.List[perms.BlockID] = perms;
                if (perms.BlockID < Block.CpeCount)
                {
                    BlockPerms.ResendAllBlockPermissions();
                }
            }

            BlockProps.Save("core", Block.Props, Block.CorePropsLock, null);
            BlockPerms.Save();
            Block.SetBlocks();
            LoadBlocks();
        }
Ejemplo n.º 8
0
 public static void SetBlocks()
 {
     SetCoreProperties();
     BlockProps.Load("core", Props, CorePropsLock, false);
     BlockDefinition.UpdateGlobalBlockProps();
     BlockPerms.Load();
     UpdateLoadedLevels();
 }
Ejemplo n.º 9
0
 /// <summary> Returns whether the player is allowed to place/modify/delete the given block. </summary>
 /// <remarks> Outputs information of which ranks can modify the block if not. </remarks>
 public static bool IsBlockAllowed(Player p, string action, ExtBlock block)
 {
     if (p == null || BlockPerms.UsableBy(p, block.BlockID))
     {
         return(true);
     }
     BlockPerms.List[block.BlockID].MessageCannotUse(p, action);
     return(false);
 }
Ejemplo n.º 10
0
 /// <summary> Returns whether the player is allowed to place/modify/delete the given block. </summary>
 /// <remarks> Outputs information of which ranks can modify the block if not. </remarks>
 public static bool IsBlockAllowed(Player p, string action, BlockID block)
 {
     if (p.group.Blocks[block])
     {
         return(true);
     }
     BlockPerms.Find(block).MessageCannotUse(p, action);
     return(false);
 }
Ejemplo n.º 11
0
 internal bool CheckManualChange(ExtBlock old, ExtBlock block, bool deleteMode)
 {
     if (!BlockPerms.UsableBy(this, old.BlockID) && !Block.BuildIn(old.BlockID) && !Block.AllowBreak(old.BlockID))
     {
         string action = deleteMode ? "delete" : "replace";
         BlockPerms.List[old.BlockID].MessageCannotUse(this, action);
         return(false);
     }
     return(CommandParser.IsBlockAllowed(this, "place", block));
 }
Ejemplo n.º 12
0
 internal bool CheckManualChange(BlockID old, BlockID block, bool deleteMode)
 {
     if (!group.Blocks[old] && !level.BuildIn(old) && !Block.AllowBreak(old))
     {
         string action = deleteMode ? "delete" : "replace";
         BlockPerms.Find(old).MessageCannotUse(this, action);
         return(false);
     }
     return(CommandParser.IsBlockAllowed(this, "place", block));
 }
Ejemplo n.º 13
0
        static void UpdatePermissions(byte block, Player p, string message)
        {
            BlockPerms.Save();
            BlockPerms.Load();
            if (block < Block.CpeCount)
            {
                BlockPerms.ResendAllBlockPermissions();
            }

            Chat.MessageGlobal("&d{0}%S{1}", Block.Name(block), message);
            if (Player.IsSuper(p))
            {
                Player.Message(p, Block.Name(block) + message);
            }
        }
Ejemplo n.º 14
0
        protected override void UpdatePerms(ItemPerms perms, Player p, string msg)
        {
            BlockPerms.Save();
            BlockPerms.ApplyChanges();

            BlockID block = ((BlockPerms)perms).ID;

            if (!Block.IsPhysicsType(block))
            {
                BlockPerms.ResendAllBlockPermissions();
            }

            string name = Block.GetName(p, block);

            Announce(p, name + msg);
        }
Ejemplo n.º 15
0
        bool ParseBlock(Player p, string message)
        {
            BlockID block = Block.Parse(p, message);

            if (block == Block.Invalid)
            {
                return(false);
            }

            p.Message("Block \"{0}\" appears as &b{1}",
                      message, Block.GetName(p, Block.Convert(block)));
            BlockPerms.Find(block).MessageCannotUse(p, "use");

            DescribePhysics(p, message, block);
            return(true);
        }
Ejemplo n.º 16
0
        static List <string> RankBlocks(LevelPermission perm)
        {
            List <string> items = new List <string>(Block.Count);

            foreach (BlockPerms perms in BlockPerms.List)
            {
                if (!BlockPerms.UsableBy(perm, perms.BlockID))
                {
                    continue;
                }
                if (Block.Name(perms.BlockID).CaselessEq("unknown"))
                {
                    continue;
                }
                items.Add(Block.Name(perms.BlockID));
            }
            return(items);
        }
Ejemplo n.º 17
0
        public override void Use(Player p, string message, CommandData data)
        {
            string[] args = message.SplitSpaces(2);
            if (args.Length < 2)
            {
                Help(p); return;
            }

            BlockID block;

            if (!CommandParser.GetBlockIfAllowed(p, args[0], "change permissions of", out block))
            {
                return;
            }

            BlockPerms perms = BlockPerms.Find(block);

            SetPerms(p, args, data, perms, "block");
        }
Ejemplo n.º 18
0
        public static byte[] Motd(Player p, string motd)
        {
            byte[] buffer = new byte[131];
            buffer[0] = Opcode.Handshake;
            buffer[1] = Server.version;

            if (motd.Length > NetUtils.StringSize)
            {
                NetUtils.Write(motd, buffer, 2, p.hasCP437);
                NetUtils.Write(motd.Substring(NetUtils.StringSize), buffer, 66, p.hasCP437);
            }
            else
            {
                NetUtils.Write(ServerConfig.Name, buffer, 2, p.hasCP437);
                NetUtils.Write(motd, buffer, 66, p.hasCP437);
            }

            buffer[130] = BlockPerms.UsableBy(p, Block.Bedrock) ? (byte)100 : (byte)0;
            return(buffer);
        }
Ejemplo n.º 19
0
        void WriteBlockPermissions(byte[] bulk)
        {
            int coreCount = hasCustomBlocks ? Block.CpeCount : Block.OriginalCount;

            for (byte i = 0; i < coreCount; i++)
            {
                bool place  = BlockPerms.UsableBy(this, i) && level.CanPlace;
                bool delete = BlockPerms.UsableBy(this, i) && level.CanDelete;
                Packet.WriteBlockPermission(i, place, delete, bulk, i * 4);
            }

            if (!hasBlockDefs)
            {
                return;
            }
            int j = coreCount * 4;

            for (int i = Block.CpeCount; i < Block.Count; i++)
            {
                Packet.WriteBlockPermission((byte)i, level.CanPlace, level.CanDelete, bulk, j);
                j += 4;
            }
        }
Ejemplo n.º 20
0
        internal static string FormatBlockName(string block)
        {
            BlockPerms perms = BlockPerms.List[Block.Byte(block)];

            return(Group.GetColor(perms.MinRank) + block);
        }
Ejemplo n.º 21
0
        public override void Use(Player p, string message)
        {
            string[] args = message.SplitSpaces();
            if (args.Length == 1)
            {
                Help(p); return;
            }

            byte block = Block.Byte(args[0]);

            if (block == Block.Invalid)
            {
                Player.Message(p, "Could not find block entered"); return;
            }
            if (!CommandParser.IsBlockAllowed(p, "change permissions of", (ExtBlock)block))
            {
                return;
            }

            if (args.Length == 2 && args[1][0] == '+')
            {
                Group grp = GetGroup(p, args[1].Substring(1));
                if (grp == null)
                {
                    return;
                }
                BlockPerms perms = BlockPerms.List[block];

                if (perms.Disallowed.Contains(grp.Permission))
                {
                    perms.Disallowed.Remove(grp.Permission);
                }
                else if (!perms.Allowed.Contains(grp.Permission))
                {
                    perms.Allowed.Add(grp.Permission);
                }

                UpdatePermissions(block, p, " can now be used by " + grp.ColoredName);
            }
            else if (args.Length == 2 && args[1][0] == '-')
            {
                Group grp = GetGroup(p, args[1].Substring(1));
                if (grp == null)
                {
                    return;
                }
                BlockPerms perms = BlockPerms.List[block];

                if (p != null && p.Rank == grp.Permission)
                {
                    Player.Message(p, "You cannot disallow your own rank from using a block."); return;
                }

                if (perms.Allowed.Contains(grp.Permission))
                {
                    perms.Allowed.Remove(grp.Permission);
                }
                else if (!perms.Disallowed.Contains(grp.Permission))
                {
                    perms.Disallowed.Add(grp.Permission);
                }

                UpdatePermissions(block, p, " is no longer usable by " + grp.ColoredName);
            }
            else if (args.Length == 2)
            {
                Group grp = GetGroup(p, args[1]);
                if (grp == null)
                {
                    return;
                }
                BlockPerms perms = BlockPerms.List[block];

                perms.MinRank = grp.Permission;
                UpdatePermissions(block, p, "'s permission was set to " + grp.ColoredName);
            }
        }
Ejemplo n.º 22
0
        internal static string FormatBlockName(Player p, BlockID block)
        {
            BlockPerms perms = BlockPerms.Find(block);

            return(Group.GetColor(perms.MinRank) + Block.GetName(p, block));
        }