I have searched and searched but I see no open framework for turn-based multiplayer games. I am reluctantly about to create one. I am writing this because, honestly, I am surprised nothing exists.
What would be in the framework? Well this is what I forecast creating, for simple games like Poker, Hearts, MahJong, Scrabble, Backgammon and Chess.
A) Script for defining “pieces” or units (with links to artwork)
B) A websockets package for pipelining between clients and server
C) Conventions/rules for communicating game/board state
D) Ditto for communicating state changes (moves)
E) API between UI code and local client game code
Items A, B, C and D, if well designed, can make it much easier to write a new game, say Bridge, without writing a custom Bridge game from scratch. Item E makes such a system more modular agains different UI mechanisms (canvas v. html5). It also might provide a natural hook for AI players.
Those are -er- hypothetical elements. I am just spitballing at this point. Anyway, if something has been done in this area, I would love to hear about it.
For the multiplayer client/server and game state side of things you could look at Colyseus or Nengi
For UI API if you’re using Babylon.js GUI you don’t really need an API as such. If you’re using an HTML UI you could look at a reactive framework like React, Vue or Svelte (the latter being my favourite ).
Yes, Colyseus would be great for your case! Since these are turn-based games, the netcode should be really simple; you don’t need to worry about optimization too much.
As you can see, state management is pretty simple. You just define a schema (in your case this would probably involve structs like Player, Board, Card, etc.) and then a single state object is shared across clients and server. You can subscribe to any changes on the client side and update your scene/UI based on that.
I have tested most options, and firebase realtime is your best bet for turn based stuff. You won’t have to pay anything, unless you do, then congratulations. it also allows 200k real-time connections, which is very impressive. You’re not going to find anything else remotely close especially for free. Imagine building that yourself… you would have to have something like a redis cluster with 1 master fanning out to 4 slaves with 50k connections per slave that have to all sync on the mater. complicated af. You could do a p2p thing especially for turn based , but then user identities become a problem. Just use firebase, and if you want some self protection put an adapter-pattern style api between your application and the firebase data. Also the firebase semi-real time database (cloud firestore) allows 1 million concurrent real time connections, and its probably fast enough for chat and turn based stuff.
Playfab is really nice for managing game-related user data, but also really difficult to integrate it into another system. Cosmosdb v4 is good if all you want is a redis-like data store. They have 25ms latency SLA and a serverless option that significantly reduces cost. I’d recommend that over firebase if all you care about is real-time persisted data.
Also for hosting cloudflare pages has unlimited bandwidth so you can put your front-end and game assets on there for free and scale to the moon.
If we’re talking databases, and Firebase specifically, I’ve been really impressed with Supabase which is an open-source alternative to Firebase. Option to self-host, but given the hosted free tier and generous pricing model, it’s not worth the hassle self-hosting. They just raised $30m series A.
Supabase is a joke compared to firebase. Managed postgres for $25 a month with 8GB storage and 50gb transfer? lul no thanks. Its “real time” stuff is just an elixer socket on top of pg notify… Amazon Lightsail Pricing | Virtual Private Server (VPS) | AWS $3.50 a month for 20GB SSD and 1TB transfer. Neither option are good though for your use case of a turn-based online game. Consider the requirements… a game lobby, dynamic game creation, chat, login, profiles, leaderboard, maybe other idk. Do you know what it would take to get that working with 200k live connections? a million? Firebase will just do it for you, likely for free.
Idk, supabase making false claims that people will base their livelihood on, just pisses me off… And in the broader picture , they are just one of soo many that has humanity’s computer scientists wasting their time. I’m not a big fan of firebase either, but they do actually deliver a service thats impossible to build yourself for the same price , even when at 1m concurrent users.
Anyway, more relevant. I think it’d be really awesome if there was an @babylon/netcode that exposed a client side unordered udp socket in the simplest way possible. Teams/office went all in on webrtc so im sure there’s some brain share to be had on the msft side.
WRT databases and server timing: I am aiming for a certain configuration: The server is a wee box in the building.
Think of folks hanging out at a remote fishing cabin, or different folks packed on a tour bus for the Grand Tetons, or yet different folks on a multi-day dive boat. It might also include bored kids in a library where the Internet is pretty sucky.
In that setup, the need for a lobby or user registration - or client-server lag - are different. In any case, we will not rely on cloud-based services.
Oh yeah, the target use model affects one other technical thing: Most of the games should not drive large power draw. If I have a bunch of tourists in a bus playing Mah Jong, excellent 3D effects will be counter-productive.
I understand that sounds boring to most of the folks reading this but -ahem- y’all aren’t the ones I wish to entertain. (For the record, I did whizzy 3D visualizations using BABYLON a while back. Even using hexagons. Illuminated City - Demos and Projects - HTML5 Game Devs Forum)
My guess is that the smartest UI will be using BABYLON but being very smart about slowing down the animation loop when nothing is happening.
pouchdb might be something to look at for stable syncs both on the uplink and downlink. It’s probably fast enough and i think it’s designed for cases where if the handset goes offline, it will ensure the syncs get sent properly when it comes back online. Or you could do something like GitHub - peermaps/peermaps: peer to peer cartography
This might not be quite what you were suggesting but . . .
. . . I would like to have an engine that runs multiplayer card games of various types, where the difference between games boils down to:
~ script/config files,
~ graphics assets
~ some animation functions
~ high-level game play descriptor (of some sort)
It seems that tile-based games, Scrabble, Dominos and MahJong, should also be able to run off the same engine. Tiles and cards are really the same thing, almost.
Dice are different because they have six sides instead of two. Put another way, a die may change value, whereas a card/tile may not.
If you could sort out that difference, then you could incorporate Yahtzee and Liars Dice.
Pouch is really really good (esp if you have a shared couch to share between users versus P2P) UNLESS you need high volume/fast moving deltas (think physics updates, etc)… in which case you’re also need another “channel” for the super fast moving stuff…but for more static-ish stuff (couple of changes per minute) pouch/couch combo is stellar!