void UpdateDatabase(Player p, MBArgs args, ushort x, ushort y, ushort z)
        {
            args.Message = args.Message.Replace("'", "\\'");
            args.Message = Colors.Escape(args.Message);
            args.Message = args.Message.UnicodeToCp437();

            string map    = p.level.name;
            object locker = ThreadSafeCache.DBCache.GetLocker(map);

            lock (locker) {
                Database.Backend.CreateTable("Messages" + map, LevelDB.createMessages);
                p.level.hasMessageBlocks = true;

                int count = Database.CountRows("Messages" + map,
                                               "WHERE X=@0 AND Y=@1 AND Z=@2", x, y, z);
                if (count == 0)
                {
                    Database.Backend.AddRow("Messages" + map, "X, Y, Z, Message", x, y, z, args.Message);
                }
                else
                {
                    Database.Backend.UpdateRows("Messages" + map, "Message=@3",
                                                "WHERE X=@0 AND Y=@1 AND Z=@2", x, y, z, args.Message);
                }
            }
        }
        void UpdateDatabase(Player p, MBArgs args, ushort x, ushort y, ushort z)
        {
            string map    = p.level.name;
            object locker = ThreadSafeCache.DBCache.GetLocker(map);

            lock (locker) {
                MessageBlock.Set(map, x, y, z, args.Message);
            }
        }
Exemple #3
0
        public override void Use(Player p, string message, CommandData data)
        {
            if (message.Length == 0)
            {
                Help(p); return;
            }

            bool   allMessage = false;
            MBArgs mbArgs     = new MBArgs();

            string[] args  = message.SplitSpaces(2);
            string   block = args[0].ToLower();

            mbArgs.Block = GetBlock(p, block, ref allMessage);
            if (mbArgs.Block == Block.Invalid)
            {
                return;
            }
            if (!CommandParser.IsBlockAllowed(p, "place a message block of", mbArgs.Block))
            {
                return;
            }

            if (allMessage)
            {
                mbArgs.Message = message;
            }
            else if (args.Length == 1)
            {
                p.Message("You need to provide text to put in the messageblock."); return;
            }
            else
            {
                mbArgs.Message = args[1];
            }

            bool allCmds = HasExtraPerm(p, data.Rank, 1);

            if (!MessageBlock.Validate(p, mbArgs.Message, allCmds))
            {
                return;
            }

            if (!p.Ignores.DrawOutput || !p.Supports(CpeExt.MessageTypes))
            {
                p.Message("Place where you wish the message block to go.");
            }
            p.MakeSelection(1, "Selecting location for &Smessage block.", mbArgs, PlacedMark);
        }
Exemple #4
0
        public override void Use(Player p, string message)
        {
            if (message.Length == 0)
            {
                Help(p); return;
            }

            bool   allMessage = false;
            MBArgs data       = new MBArgs();

            string[] args  = message.SplitSpaces(2);
            string   block = args[0].ToLower();

            data.Block = GetBlock(p, block, ref allMessage);
            if (data.Block.IsInvalid)
            {
                return;
            }
            if (!CommandParser.IsBlockAllowed(p, "place a message block of", data.Block))
            {
                return;
            }

            if (allMessage)
            {
                data.Message = message;
            }
            else if (args.Length == 1)
            {
                Player.Message(p, "You need to provide text to put in the messageblock."); return;
            }
            else
            {
                data.Message = args[1];
            }

            bool allCmds = HasExtraPerm(p, 1);

            if (!MessageBlock.Validate(p, data.Message, allCmds))
            {
                return;
            }

            Player.Message(p, "Place where you wish the message block to go.");
            p.MakeSelection(1, data, PlacedMark);
        }
        bool PlacedMark(Player p, Vec3S32[] marks, object state, BlockID block)
        {
            ushort x = (ushort)marks[0].X, y = (ushort)marks[0].Y, z = (ushort)marks[0].Z;
            MBArgs args = (MBArgs)state;

            BlockID old = p.level.GetBlock(x, y, z);

            if (p.level.CheckAffect(p, x, y, z, old, args.Block))
            {
                p.level.UpdateBlock(p, x, y, z, args.Block);
                UpdateDatabase(p, args, x, y, z);
                p.Message("Message block created.");
            }
            else
            {
                p.Message("Failed to create a message block.");
            }
            return(true);
        }