D
D
Danbka2020-01-29 23:00:23
PHP
Danbka, 2020-01-29 23:00:23

How to save the result of a browser-based single player game to a database on the server?

There is a browser game (single-player, like a puzzle) that is implemented using vuejs.

What is the best way to send the result of the game (number of moves spent by the user) to the server in order to be able to display the top players in the future, for example?

Just sending the result at the end of the game is not an option - it's easy to fake the request and send any value as the result.

Means some interaction with the server is necessary. So far I see 2 options:

1) in my opinion, it is inefficient, but it can work: when you click the "New Game" button, send an ajax request to the server, using which to create a record about a new game in the database. Then, for each player's move, send requests to the server and increase the number of moves in the database. The result of each move is calculated on the server to avoid "faking" the results.

2) web sockets. I didn't work with them. Are they suitable for this task?

3) anything else I don't know?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
fix0_o, 2020-02-07
@fix0_o

For single user 1 option is acceptable. Sockets are preferred, but only possible on a lunex system. On Win, there is also a socket option, but it has a number of problems, the main one being the inability to control the daemon from the inside.
According to 1 option. , this is a min js library based on jquery, the bottom line is that if you understand the implementation a little, then you will understand how best to implement option 1.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question