PHP System to cure user x in x minutes

0

Good morning everyone! I'm creating a rpg game and I'm not figuring out how to get it to cure the user of x in x minutes. I was able to do it via ajax, but it is not safe right? Easily the user can circumvent and heal his whole life if he wants ... Is there any way to do this without ajax? In the database I already have all the values, life, maximum life etc ... Give me a force! Thanks.

@EDIT with ajax even though it worked, the user had to be logged in, it would also be something that he did not have to log in ... that the system would work even if he turned it off.

    
asked by anonymous 11.06.2016 / 13:37

1 answer

1

You can have an event in the database that every time x and x do some action for you, for example:

Character table, with id, name and life.

CREATE TABLE IF NOT EXISTS personagem (
    id INT PRIMARY KEY AUTO_INCREMENT,
    nome VARCHAR(40) NOT NULL,
    vida INT NOT NULL DEFAULT 50
)

Event, every 2 minutes adds +10 to the character's life, if it is better than 100 (you have to have control if in case life is at 92, do not go to 102, because in the example the maximum life is 100, mad I will not do that)

DELIMITER $$
--
-- Eventos
--
CREATE EVENT 'realizaCura' 
ON SCHEDULE EVERY 2 MINUTE
STARTS '2016-05-12 15:11:10' ON COMPLETION NOT PRESERVE ENABLE 
DO UPDATE personagem SET personagem.vida = (personagem.vida + 10) WHERE personagem.vida < 100$$
DELIMITER ;

Sorry if I had a syntax error, I did it over the phone.

    
11.06.2016 / 16:18