beamable / BeamableProduct

The beamable product suite including com.beamable, com.beamable.server, microservice base image, portal, the installer, and build scripts
Other
5 stars 0 forks source link

Beam 2083 - Session locking #3271

Open cdhanna opened 5 months ago

cdhanna commented 5 months ago

https://disruptorbeam.atlassian.net/browse/BEAM-2083

As a Game Maker using concurrency-unsafe features, In order to prevent each player from playing on multiple devices simultaneously, I want a convenient way to invalidate all sessions but one when players run the game.

Certain Beamable features such as Cloud Saving can have serious problems when one player is trying to use them from multiple devices at the same time (basically, ping-ponging between two states). In addition, Game Makers may want to create gameplay without worrying about concurrency issues. To that end, it should be possible for Game Makers to declare their game “single session” and make it so that any older sessions get invalidated when a new session is created.

From the Game Maker’s C# code perspective, the feature must be able to:

answer “Is my current session valid?” in a lightweight way (such as in an Update method)

have a globally available callback for when the current session becomes invalid, something named OnSessionTerminated or the like.

manually issue an “invalidate all other sessions” command.

configure the game to automatically issue “invalidate all other sessions” upon startup.


Possible solution, is to use the autogen API, ISessionApi.GetClientHistory function to see if the current session is the latest session, and from that, derive if the current session is "valid" or "invalid".

The big part that solution is missing is the notification aspect. However, we could solve/work-around by adding a polling approach.

cdhanna commented 3 months ago

Maybe instead of the wording, "valid" vs "invalid" ; we could adopt "latest" vs "not-latest"


Beamable should emit a notification to every connected client when a session starts, saying, "new session started!"

Beamable should emit a notification to every connected client when a session ends, saying, "existing session has stopped!" (best effort)

These should be realm-configurable.


This is a backend notification update that we need to talk to Justin about.


This could be a Microservice feature, but this feels "core" enough that it should just attach onto our presence stuff