M
M
mrdragon90002020-03-19 19:35:21
PHP
mrdragon9000, 2020-03-19 19:35:21

How to implement backend realtime games with a process "leading" the game?

It is necessary to make a realtime application similar to poker. There is a list of rooms, the server keeps a pool of rooms permanently created, users create some rooms themselves (with a password and individual settings).
When enough players enter the room, the game begins. The host first distributes cards to all players, after which he waits either for all players to make bets, or for the time of this stage to expire and go to the next step (puts some of the cards on the table and waits for the bet again, and at the end he credits the winning chips to the balance, and transfers the game to step 1, i.e. a new distribution).
How to implement it on the server side?
The back end is used to writing in laravel, nodejs is usually only for additional services.
I see two options:
1) Make a single process on nodejs both as a backend and as a host of rooms (+1 process as a socket server), and store the rooms in its operative. That is, this process listens to port 80 on http resp api requests and responds to them, and also contains the Rooms variable, which will contain all the rooms. It will ping the rooms to move to the next stage and do the related actions.
Likes: Very easy to manage rooms. When requesting information about them, we simply take it from a variable. It's easy to store the rates themselves and the members of the room, just as the properties of the room.
What I don't like: Can't expand. That is, I can’t put another room handler process on another server, and I don’t even know how good it is to process api and listen to rooms endlessly.
2) Make a laravel resp api + process (in the form of a php artisan command) that will process the rooms, and store the rooms themselves in some way in redis-e (+ socket server). What I don't like is a more confusing implementation, I'm not sure what type of data to store rooms in radish, how to store rates.
But it's not hard to expand.
Please tell me the best way to implement it

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xmoonlight, 2020-03-20
@xmoonlight

pthreads

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question