Answer the question
In order to leave comments, you need to log in
How to implement certain functions in the clicker?
There is a clicker. In which there are 2 functions:
1) Accumulation of currency for manual clicking
2) Automatic calculation of currency (for example, once every 1 second)
All these actions must be coordinated with the server. With a click, I decided how. When I click, I send a request to the server, what I clicked. Also, on the client side, using JS, I simply add 1 more click to the amount of clicks (so that there are no delays, because the request to the server and the response do not come instantly).
But there is also automatic currency accrual. Every second, the server sends me the final balance, on which my amount + automatically calculated click. And here we get a disagreement:
I very quickly clicked 20 times
The server managed to accept only 5 and counted them.
Automatic currency accrual credited me clicks to the total amount for THESE 5 clicks.
And then the client will have the following:
First, 20 clicks will be displayed. Then the number 5 will appear (since the automatic currency accrual worked at the 5th request). cry).
Now the question is. How can I implement this clicker without such delays? I can’t do everything on the client, since desynchronization in the currency can occur.
Answer the question
In order to leave comments, you need to log in
What for in general the data from the server to display on the client? Count everything locally - both clicks and additions by timer. The only reason I can think of why you might need this is to fight cheaters.
To do this, send all user actions to the server once a second (clicks, pressing bonus purchase buttons). The server should repeat all the logic (add clicks, automatic timers, enable all sorts of bonuses if there are enough points) and send back the resulting user points to that second. When sending, the client must remember how many points he had and, when receiving a response, compare it with what he received from the server. If there is a discrepancy, then the difference is added to the current number of points.
Those. all logic is on the client, but it is duplicated and checked on the server (for example, checking that there are no 10 ^ 20 clicks per second, that there were enough points to buy an upgrade).
If the client does not cheat, then everything will always converge and there will be no problems. If he cheats, then you can stop working or update the state to what the server says (the user will see some bonuses or a bunch of points for a second).
Records in the database about the record of points, about achievements or whatever you want to protect there, the server makes only according to its vision of the state of the game. The player can draw anything for himself, and here you will not interfere with him in any way.
If you want to hide some formula or logic exclusively on the server, then nothing can be done here without delay.
Check out the section about server reconciliation here in this series of articles - https://www.gabrielgambetta.com/client-side-predic... - and for general education, read it in its entirety, there is quite a bit and everything is written in very simple language .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question