protected void HandleBlockchange(byte[] message)
        {
            if (!isLoggedIn) return;

            ushort x = packet.NTHO(message, 0);
            ushort y = packet.NTHO(message, 2);
            ushort z = packet.NTHO(message, 4);
            byte action = message[6];
            byte newType = message[7];

            if (newType > 49 || (newType == 7 && !isAdmin))
            {
                Kick("HACKED CLIENT!");
                //TODO Send message to op's for adminium hack
                return;
            }

            byte currentType = level.GetBlock(x, z, y);
            if (currentType == (byte)Blocks.Types.zero)
            {
                Kick("HACKED CLIENT!");
                return;
            }

            //TODO Check for permissions to build and distance > max

            if (blockChange != null)
            {
                SendBlockChange(x, z, y, currentType);
                bool placing = false;
                if (action == 1) placing = true;
                ThreadPool.QueueUserWorkItem(delegate {
                    blockChange.Invoke(this, x, z, y, newType, placing, PassBackData);
                    blockChange = null;
                    PassBackData = null;
                });

                return;
            }

            if (action == 0) //Deleting
            {
                level.BlockChange(x, z, y, (byte)Blocks.Types.air);
            }
            else //Placing
            {
                level.BlockChange(x, z, y, newType);
            }
        }
 public void CatchNextChat(NextChatDelegate chat, object data)
 {
     PassBackData = data;
     blockChange = null;
     nextChat = chat;
 }
 public void CatchNextBlockchange(BlockChangeDelegate change, object data)
 {
     PassBackData = data;
     nextChat = null;
     blockChange = change;
 }
        /// <summary>
        /// This delegate is used for when a command wants to be activated the next time the player sends a message.
        /// </summary>
        /// <param name="chat">The NextChatDelegate that will be executed on the next chat.</param>
        /// <param name="data">A passback object that can be used for a command to send data back to itself for use</param>
        /*public void CatchNextChat(NextChatDelegate chat, object data)
        {
            PassBackData = data;
            blockChange = null;
            nextChat = chat;
        }*/
        /// <summary>
        /// Fakes a click by invoking a blockchange event.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="z"></param>
        /// <param name="y"></param>
        /// <param name="type"></param>
        public void Click(ushort x, ushort z, ushort y, byte type)
        {
            bool canceled = OnPlayerBlockChange.Call(x, y, z, ActionType.Place, this, type);
            if (canceled) // If any event canceled us
                return;
            if (blockChange != null) {
                bool placing = true;
                BlockChangeDelegate tempBlockChange = blockChange;
                if (!ExtraData.ContainsKey("PassBackData"))
                    ExtraData.Add("PassBackData", null);
                object tempPassBack = ExtraData["PassBackData"];

                blockChange = null;
                ExtraData["PassBackData"] = null;

                ThreadPool.QueueUserWorkItem(delegate { tempBlockChange.Invoke(this, x, z, y, type, placing, tempPassBack); });
                return;
            }
        }
 public void CatchNextBlockchange(BlockChangeDelegate change, object data)
 {
     if (!ExtraData.ContainsKey("PassBackData"))
         ExtraData.Add("PassBackData", null);
     ExtraData["PassBackData"] = data;
     nextChat = null;
     blockChange = change;
 }
Exemple #6
0
        public void click(ushort x, ushort z, ushort y, byte type)
        {
            if (blockChange != null)
            {
                bool placing = true;
                BlockChangeDelegate tempBlockChange = blockChange;
                object tempPassBack = PassBackData;

                blockChange = null;
                PassBackData = null;

                ThreadPool.QueueUserWorkItem(delegate { tempBlockChange.Invoke(this, x, z, y, type, placing, tempPassBack); });
                return;
            }
        }