Request Details
we need a way to disconnect clients from the server side. ideally both through, ctx.disconnect_identity(identity: Identity) and ctx.disconnect_connection_id(connection_id: ConnectionId).
this is required to be able to build ban systems as custom clients can just not react to any "server says disconnect" setups.
a timeout system also requires this but can be worked around with the "server says disconnect" setups but it isn't nice and can be ignored on the client side as mentioned.
the disconnect_connection_id alternative is needed when multiple clients can connect to the same identity at the same time and we don't want to disconnect all connections or something like that. (it's mostly to have the option)
doing a direct ctx.disconnect_sender() is not as useful as it doesn't work with scheduled reducers/procedures.
Requested by @xDovos via the SpacetimeDB site.
Activity
View on GitHub#5266I have the same requirement for a multiplayer game: when a player logs in on a new device with the same Identity, the server should disconnect the previous connection while keeping the new one active.
Tracking the latest ConnectionId and rejecting reducers from older connections only prevents gameplay actions that perform that check. It does not close the old WebSocket or stop its subscription updates. Asking the old client to disconnect is also insufficient because it can ignore the notification.
The session_id-based reconnect mechanism addresses replacement within the same logical session, but different devices can use different session IDs, so it does not enforce one active connection per account.
A module-accessible API to disconnect a specific ConnectionId would let us implement this policy in the server-side client_connected/login logic. Disconnecting by Identity would also be useful for bans, but targeted disconnection is particularly important here so the newly accepted connection is preserved.
