Having a timer (setInterval) on server side for control, and display it on client side
Unanswered
Podenco Canario posted this in #help-forum
Podenco CanarioOP
Hello,
I'm in a weird spot I've never been before : I'm creating a webapp game.
To do so I need to evaluate a timer on the server side (to prevent any kind of cheat), and display it on front so my players knows the remaining time to answer the question.
The thing is I don't really know how to handle this situation on both sides.
Right now I'm using a
I think I'm not on the right path, but I really don't have any idea how to implement this or where I should start really.
I should add that on my client side I'm using Zustand to store the timer (but that's not really relevant I guess), also my backend is Supabase.
I'm thinking maybe I should use some kind of Websockets eventually (right now I'm testing with only one player), but it still doesn't tell how I should handle this "server side timer" I'm trying to create.
Do you guys have any idea on which direction to take ?
I'm in a weird spot I've never been before : I'm creating a webapp game.
To do so I need to evaluate a timer on the server side (to prevent any kind of cheat), and display it on front so my players knows the remaining time to answer the question.
The thing is I don't really know how to handle this situation on both sides.
Right now I'm using a
setInterval inside a export const runtime = 'edge' Next API Route to handle the timer, and I'm trying to display it on the front using fetch inside some useEffect, useMemo, or useCallback (sorry I'm still struggling to understand when to use which... and this is another topic)I think I'm not on the right path, but I really don't have any idea how to implement this or where I should start really.
I should add that on my client side I'm using Zustand to store the timer (but that's not really relevant I guess), also my backend is Supabase.
I'm thinking maybe I should use some kind of Websockets eventually (right now I'm testing with only one player), but it still doesn't tell how I should handle this "server side timer" I'm trying to create.
Do you guys have any idea on which direction to take ?
3 Replies
I think you could store an expiration time in your db and when the client side timer runs out check if it's been tampered with or if it completed as expected. That's if you're worried that it might be artificially shortened by players. For the other way around I'm not sure how you could do it but I'll think of something.
Podenco CanarioOP
Oh yeah, like using a datetime instead of a number to decrement. I like the idea. Thx for the input 🙂
Np, let me know if it works. ✌ðŸ»