MahjongRepository / mahjong_soul_api

Python wrapper for the Mahjong Soul (Majsoul) Protobuf objects. It allows to use their API.
72 stars 10 forks source link

How to get notify messages from server? How do I connect to a match? #16

Closed shinkuan closed 1 year ago

shinkuan commented 1 year ago

The examples in this repo shows how to send requests and get response, but I can't find how to get notify messages from server. I tried something like:

async def NotifyRoomGameStart(data):
    logging.info("NotifyRoomGameStart hook")
    nonlocal game_url
    nonlocal connect_token
    nonlocal game_uuid
    nonlocal location
    nonlocal gotNotifyRoomGameStart
    game_url = data.game_url
    connect_token = data.connect_token
    game_uuid = data.game_uuid
    location = data.location
    gotNotifyRoomGameStart = True
    pass
channel.add_hook(1, NotifyRoomGameStart)

But it doesn't work.

The second question is how do I connect to a match after I created a room? After sending startRoom request, the server sends a notify message contains: game_url, connect_token, game_uuid, location. Below are captured log using majsoul_warpper:

-----------------------------------------------------------------
{'id': 46, 'type': <MsgType.Req: 2>, 'method': '.lq.Lobby.startRoom', 'data': {}}
-----------------------------------------------------------------
{'id': 95, 'type': <MsgType.Notify: 1>, 'method': '.lq.NotifyRoomGameStart', 'data': {'gameUrl': '172.30.16.106:4022', 'connectToken': 'd33aad81-5ee3-42ba-9577-5e0f03d954d7', 'gameUuid': '230822-ea721146-7a8d-46b3-b1f7-b66292f8f269', 'location': 'local'}}
-----------------------------------------------------------------
{'id': 46, 'type': <MsgType.Res: 3>, 'method': '.lq.Lobby.startRoom', 'data': {}}
-----------------------------------------------------------------