Files
metin2-client/tests/meshport/test_network_paths.py
T
shenandshen 507e687867 feat: add MeshPort overlay networking, item actions window, and AVA2 client enhancements
- add MeshPort peer-to-peer overlay networking SDK, C++ integration, and Python bindings
- add item actions quick use/split/delete/lock overlay window (mt_item_actions)
- add shop name range and NPC name visibility settings to system display options
- support battlepass ticket activation and month validation in mt_battlepass
- support boss tracking teleport destination button in mt_bosses
- support asynchronous account registration cancellation and pending login cancellation
- update AVA2 item conversion for attr lock scrolls and battlepass tickets
- update .gitignore for local build outputs and caches
2026-10-16 01:29:57 -07:00

80 lines
4.4 KiB
Python

"""Run the native integration executable against an isolated, real SDK gateway."""
import json
import os
import subprocess
import sys
import tempfile
from pathlib import Path
def check_client(root, temporary, profile, info):
result_path=Path(temporary)/'client-registration-result.txt'
source=r"""import ui, app, net
# Cancelling a pending login must not cancel the independent channel query or registration.
net.ConnectTCP('10.252.79.1', %d)
assert net.CancelPendingLogin()
assert not net.CancelPendingLogin()
class RegistrationProbe(ui.Window):
def __init__(self):
ui.Window.__init__(self)
self.phase = 0
self.trace = %r
open(self.trace, 'w').write('started\n')
self.started = app.GetTime()
net.RegisterAccount('10.252.79.1', %d, 'isolatedtest', 'unused', '1234567')
self.Show()
def OnUpdate(self):
if self.phase == 0 and app.GetTime() - self.started > .25:
net.CancelRegisterAccount()
self.phase = 1
open(self.trace, 'a').write('cancel requested\n')
result = net.GetRegisterAccountResult()
if self.phase == 1 and result:
open(self.trace, 'a').write('cancel result: ' + result + '\n')
assert result == 'ERR CANCELLED', result
net.RegisterAccount('10.253.79.1', %d, 'isolatedtest', 'unused', '1234567')
self.phase = 2
open(self.trace, 'a').write('remote registration started\n')
elif self.phase == 2 and result:
open(%r, 'w').write(result)
self.Hide()
_registration_probe = RegistrationProbe()
"""%(info['tcp_port'],str(result_path)+'.trace',info['tcp_port'],info['tcp_port'],str(result_path))
args=[str(root/'build/release/src/host/mt_native_render'),'--login-screen',
'--live-client',str(root/'build/zh-locale/Client'),
'--live-server','10.253.79.1:%d:%d'%(info['tcp_port'],info['tcp_port']),
'--frames','600','--py-exec',source]
with open(root/'build/meshport-registration-runtime.log','w') as output:
result=subprocess.run(args,env=dict(os.environ,MT_MESHPORT_CONFIG=str(profile),MT_MESHPORT_TRACE='1'),
stdout=output,stderr=subprocess.STDOUT,timeout=45)
assert result.returncode==0, 'native client launch failed'
if not result_path.exists() or result_path.read_text()!='OK':
trace=Path(str(result_path)+'.trace')
print('Client registration trace:',trace.read_text() if trace.exists() else 'no updates')
print('Client registration result:',result_path.read_text() if result_path.exists() else 'no result')
raise AssertionError('original HTTP registration/cancellation path failed')
print('Native Python 2.7 client: pre-login channel routing, actual HTTP registration and cancellation passed')
def main():
root=Path(__file__).resolve().parents[2]
fixture=root/'build/meshport-runtime/release/examples/gateway_fixture'
binary=Path(sys.argv[1]) if len(sys.argv)>1 else root/'build/native/src/meshport/meshport_network_paths_test'
with tempfile.TemporaryDirectory(prefix='metin2-mesh-') as temporary:
log=open(Path(temporary)/'gateway.log','w+')
gateway=subprocess.Popen([str(fixture)],stdout=subprocess.PIPE,stderr=log,text=True)
try:
import selectors
selector=selectors.DefaultSelector();selector.register(gateway.stdout,selectors.EVENT_READ)
if not selector.select(20):raise RuntimeError('gateway startup timed out')
info=json.loads(gateway.stdout.readline())
config=Path(temporary)/'profile.toml'
config.write_text("dhcp=true\nlisteners=[]\nstun_servers=[]\nstun_servers_v6=[]\n[[peer]]\nuri='tcp://127.0.0.1:%d'\n[network_identity]\nnetwork_name='%s'\nnetwork_secret='isolated-test-only'\n[flags]\nno_tun=true\nuse_smoltcp=true\nenable_encryption=true\n"%(info['mesh_port'],info['network_name']))
result=subprocess.run([str(binary),str(config),str(info['tcp_port']),str(info['udp_port'])],timeout=100,env=dict(os.environ,MT_MESHPORT_TRACE="1"))
if result.returncode:raise RuntimeError('native network paths failed (%s)'%result.returncode)
if '--client' in sys.argv:check_client(root,temporary,config,info)
finally:
gateway.terminate()
try:gateway.wait(timeout=5)
except subprocess.TimeoutExpired:gateway.kill();gateway.wait()
log.close()
if __name__=='__main__':main()