Skip to content

Commit

Permalink
Update protocol to 0.8.41 version and minor project structure changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nihisil committed Jun 28, 2020
1 parent d750887 commit 225d9fd
Show file tree
Hide file tree
Showing 10 changed files with 12,159 additions and 8,943 deletions.
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ It is the fork of https://github.com/chaserhkj/PyMajSoul/ package with different

`example.py` is working only with **Python3.7+**.

# How to update protocol files to the newest version
## Requirements

1. Download the new liqi.json file (find it in the network tab of your browser) and put it to data/liqi.json. For example https://mahjongsoul.game.yo-star.com/v0.6.58.w/res/proto/liqi.json
2. `cd ms`
3. `python generate_proto_file.py`
1. Install python packages from `requerements.txt`
1. Install protobuf compiler `sudo apt install protobuf-compiler`

# Hot to update RPC wrapper
## How to update protocol files to the new version

1. Install protobuf compiler first `sudo apt install protobuf-compiler`
2. `cd ms`
3. `chmod +x ms-plugin.py`
4. `sudo cp ms-plugin.py /usr/bin/ms-plugin.py`
5. `protoc --custom_out=. --plugin=protoc-gen-custom=ms-plugin.py ./data/protocol.proto`
It was tested on Ubuntu.

1. Download the new `liqi.json` file (find it in the network tab of your browser) and put it to `ms/liqi.json`
1. `python generate_proto_file.py`
1. `protoc --python_out=plugins=grpc:. protocol.proto`
1. `chmod +x ms-plugin.py`
1. `sudo cp ms-plugin.py /usr/bin/ms-plugin.py`
1. `protoc --custom_out=. --plugin=protoc-gen-custom=ms-plugin.py ./protocol.proto`
8 changes: 6 additions & 2 deletions ms/example.py → example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s: %(message)s', datefmt='%Y-%m-%d %H:%M:%S')

MS_HOST = 'https://www.majsoul.com'
MS_HOST = 'https://game.maj-soul.com'


async def main():
Expand Down Expand Up @@ -47,14 +47,17 @@ async def connect():
async with aiohttp.ClientSession() as session:
async with session.get('{}/1/version.json'.format(MS_HOST)) as res:
version = await res.json()
print(version)
version = version['version']

async with session.get('{}/1/v{}/config.json'.format(MS_HOST, version)) as res:
config = await res.json()
url = config['ip'][0]['region_urls']['mainland']
print(config)
url = config['ip'][0]['region_urls'][1]

async with session.get(url + '?service=ws-gateway&protocol=ws&ssl=true') as res:
servers = await res.json()
print(servers)
servers = servers['servers']
server = random.choice(servers)
endpoint = 'wss://{}/'.format(server)
Expand Down Expand Up @@ -107,6 +110,7 @@ async def load_game_logs(lobby):
req.count = step
res = await lobby.fetch_game_record_list(req)
records.extend([r.uuid for r in res.record_list])

return records


Expand Down
1 change: 0 additions & 1 deletion ms/data/liqi.json

This file was deleted.

4 changes: 2 additions & 2 deletions ms/generate_proto_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from io import StringIO
from pprint import pprint

filename = 'data/liqi.json'
filename = 'liqi.json'
data = json.load(open(filename), object_pairs_hook=OrderedDict)
buf = StringIO()
buf.write('syntax = "proto3";\n\n')
Expand Down Expand Up @@ -73,5 +73,5 @@ def parse_item(name, item):
for name in data:
parse_item(name, data[name])

with open('data/protocol.proto', 'w') as f:
with open('protocol.proto', 'w') as f:
f.write(buf.getvalue())
1 change: 1 addition & 0 deletions ms/liqi.json

Large diffs are not rendered by default.

Loading

0 comments on commit 225d9fd

Please sign in to comment.