Add read-only public table export for client encyclopedia
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
# 公开模板资料导出
|
||||
|
||||
本工具供 metin2-client 百科生成器使用,只读取四张公开配置表和 refine_proto 的配方字段。
|
||||
不读取账号、角色、物品实例或运行 CONFIG,不启动/停止服务,不修改数据库。
|
||||
|
||||
在服务器上使用现有 MySQL 客户端凭据(如 root 的 socket/option file):
|
||||
|
||||
```sh
|
||||
python3 tools/wiki/export_public_tables.py /tmp/wiki-export-NEW
|
||||
```
|
||||
|
||||
目标目录必须不存在。将导出目录通过 SSH 复制到客户端忽略的 build/wiki-source/,再运行客户端的 tools/wiki/build_catalogue.py。
|
||||
本工具与客户端生成器分别保留输入哈希。运行中的数据库和磁盘配置可能存在未重载差异,导出时应确认 DB/game 已加载该版本;此静态资料不能声明服务器实时掉落或最终精炼概率。
|
||||
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Read-only export of public template tables; run on the FreeBSD game host.
|
||||
Usage: python3 tools/wiki/export_public_tables.py /tmp/wiki-export
|
||||
mysql uses the operator's existing option file/socket credentials; no password is printed/stored.
|
||||
"""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def export(server, output, database, mysql):
|
||||
if not re.fullmatch(r'[A-Za-z0-9_]+', database):
|
||||
raise ValueError('invalid database identifier')
|
||||
if output.exists():
|
||||
raise ValueError('choose a fresh output directory')
|
||||
conf=server/'share/conf'
|
||||
output.mkdir(parents=True,mode=0o700)
|
||||
try:
|
||||
for name in ('item_proto.txt','item_names.txt','mob_proto.txt','mob_names.txt'):
|
||||
shutil.copyfile(conf/name,output/name)
|
||||
query=('SELECT id,cost,prob,vnum0,count0,vnum1,count1,vnum2,count2,'
|
||||
'vnum3,count3,vnum4,count4 FROM refine_proto ORDER BY id')
|
||||
with (output/'refine.tsv').open('wb') as stream:
|
||||
subprocess.run([mysql,'-N','-B',database,'-e',query],stdout=stream,check=True)
|
||||
report={p.name:hashlib.sha256(p.read_bytes()).hexdigest() for p in output.iterdir()}
|
||||
(output/'source-manifest.json').write_text(json.dumps(report,indent=2)+'\n')
|
||||
except Exception:
|
||||
shutil.rmtree(output)
|
||||
raise
|
||||
return report
|
||||
|
||||
|
||||
if __name__=='__main__':
|
||||
parser=argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('output',type=Path)
|
||||
parser.add_argument('--server',type=Path,default=Path('/usr/metin2/server'))
|
||||
parser.add_argument('--database',default='player')
|
||||
parser.add_argument('--mysql',default='mysql')
|
||||
args=parser.parse_args()
|
||||
print(json.dumps(export(args.server,args.output,args.database,args.mysql),indent=2))
|
||||
Reference in New Issue
Block a user