Multiplayer game architecture in node.js - State management and synchronization with Redux
Asked Answered
R

1

6

I'm implementing an online TCG game (think Hearthstone/Magic) as a pet project and I've decided to go React/Redux for the client UI. This led me to think about the possibility of using Redux on the server as well to maintain the global state for each client/game.

The way it would work, is players in a game would send events (via socket.io) to the server which would be validated according to the game state+rules, which would then trigger a change in the server state and propagate it to the respective clients.

The thing is, I feel like I'm gonna have to jump through a lot of hoops to get all the game rules/logic to conform to the more functional/immutable approach of Redux instead of modeling all my game entities as classes. Also, since each player has limited information about their opponents (you can't see the other player's hand for example), I'll have to have some custom logic for filtering the state information depending on which player is receiving the data.

On the other hand, I like the idea of having a centralized state split across different handlers for each domain, predictable data flow, and possibility to regress to prior states. Also the actions in Redux fit neatly into the command pattern which is useful for these kinds of games.

Should I just implement a custom Redux like state manager but drop the immutability part? Is there a more "tried and true" approach for these kinds of situations?

Romie answered 28/5, 2017 at 16:26 Comment(0)
T
0

Look at event-sourcing.

Events from UI will affect different read-models - that is case you are talking about. You even can use some simple event sourcing framework for backend, since the main logic is based on events.

I always suggest reimagined/resolve framework as very simle and compact one to understand cqrs+es main concepts in examples.

Teresa answered 2/3, 2019 at 15:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.