API to select "host" participant

Adversarial games such as GitHub - webxdc/ChessBoard: A webxdc chess game for two players and many observers :) need to decide who is playing which side. Currently in ChessBoard it is implemented by someone clicking “Start game” to send game offer and then someone else clicking “Join game”. This is not reliable because it is possible that multiple people click “Start game” at the same time.

To reduce this problem it would be nice to have an API which tells whether the game is started by original sender of .xdc file or someone else. Since there is only one such participant, they can be a “host” which gets join requests, accepts the first one arriving and confirming.

API can be as simple as a window.webxdc.isOriginalSender which is true for the device sending the app (not even another device of the same participant receiving the message via bcc-to-self) and false otherwise, or undefined in case of outdated messenger which does not support this API yet.

I solved it in the tic-tac-toe app by letting the host approve the join request (announce who actually joined):

  1. Host opens game
  2. multiple people send join requests
  3. Host confirms/starts the match with the first join request that was received.

Though this solution is mainly for “tournament” style games that can have multiple matches simultaneously.

How does host in tic-tac-toe knows that it is a host and should wait for join requests instead of sending own join request?

TBH this sounds like bloat. I think the problem you’re describing can be solved with cooperative conflict resolution.

  • Along with the “start game” message send a timestamp when the button was pressed.
  • Upon a conflict, just make the host the one who has the smallest alphabetic selfAddr (or the smallest hash of selfAddr)

In addition, I think webxdc.originalSenderAddr is better than webxdc.isOriginalSender

It sends the self address in the updates and does not answer to join request from the same address as the selfAddr. This could be improved when we have a unique userid that core would assign as metadata next to the payload.

1 Like