Frameworks for multi-player games

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.

3 Likes

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 :slight_smile: ).

4 Likes

For an example of Colyseus, you can check out the demo from @DarraghBurke.

3 Likes

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.

You can find the source for my Colyseus demo here: darraghjburke/IslandPainter (github.com)

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.

Feel free to ask if you have any questions!

3 Likes

@DarraghBurke wow how did I miss this?! Nice work. I see you used the hex tile stuff from Red Blob Games - cool! That’s such an amazing resource.

1 Like

Yep, though I only half-implemented the math because I was lazy, which is why the map is a diamond instead of a hex :smiley:

I didn’t post it on the forum, so a lot of folks here might not have seen it

1 Like

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.

3 Likes

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.

2 Likes

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.

I guess I hit a nerve. It was just a suggestion. I made no comparison to Firebase nor any disparaging remarks. Each to his own.

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.

We are working on something like this @jeremy-coleman , exposing a lot of the multi user functionality we use in our Frame product in a simple api.

This was great! Thank you everyone.

I have Colyseus and Nengi open in the other tab.

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. :wink: 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.

Thanks again for the excellent responses!!

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.

I would guess every card game has already been implemented in pixi and is on github.

@TheLeftover did you end up settling on a framework?

I’ve also had the same needs as you and wrote a framework myself: GitHub - hpx7/rtag: Real-time app generator. Check it out and let me know if it seems useful to you

1 Like

@hpx7 thanks for mentioning it. I took a look at the repo; it is certainly on-point. Thank you for posting the link.

I am buried in something else but I will look closer later. If I have thoughts or questions, I will come back to you here.

2 Likes