loomnetwork / gamechain

BSD 3-Clause "New" or "Revised" License
3 stars 6 forks source link

Create FindMatch Method #125

Closed phoorichet closed 6 years ago

phoorichet commented 6 years ago

When the user clicks Battle in the game, it's expecting the server to do a match making for PvP. However, the server itself has to keep track on the user how is online and ready to play the game.

Calling just one method to get the PVP on the backend isn't enough because the transaction has to be broadcasted to the all the nodes, to update the user status first. If we also do the look up in this function, the transaction will be blocked and the user won't get updated status -- needed when the server looking up.

We can archive this using websocket subevent.

  1. Create FindMatch endpoint: Basically, this endpoint will create a transaction to the blockchain saying that the user is online. And just return. What this endpoint returns is the topic name.
  2. The client subscribes to the topic name returned from the server, listening for event message from the server.
  3. Another user calls RegisterPVP endpoint, the server looks up and found the first player and emits the events to both users with the topic name in 1.

ref:

Tasks:

phoorichet commented 6 years ago

closed #140