Files
mtgodot-poc/project/channel_status_test.gd
T
shenandClaude Sonnet 5 47baf6c0c6 Metin2 game client (P0–P11) + mobile asset pipeline
Networked client on the existing Godot 4.7 + libgr2 renderer:
- net: m2dev wire protocol (libsodium KX + XChaCha20), auth/select/game
  phases, EntityStore world model, ~all GC/CG headers. char create/delete,
  private shop / mall / cube, SHOP_GC_START_EX, guild, party (+ CG_PARTY_SET_STATE),
  quests, dragon soul, refine, safebox, exchange.
- UI: in-game windows migrated 1:1 from the reference uiscript/root .py —
  char status (/stat), inventory+equipment, select-item ([SELECT_ITEM] quest
  token), system-option + game-option + ESC system menu, private-shop 39-grid,
  party info board, shop tabs, atlas, minimap, quickbar, chat, …
- EterGrnLib polish: GR2 material blend/two-sided, LOD crossfade, motion-event
  dispatch, contact shadow, ray-AABB picking, weapon grip pre-transform.

Portable asset IO (A1) — all extension/libgr2/formats/mtproto reads routed
through godot::FileAccess (res:// PCK works on iOS/Android); standalone-lib
*_path() kept for the non-Godot CTests. AssetResolver + PropertyRegistry
switched to a baked index (bake_asset_index.gd) instead of std::filesystem.

Mobile builds: build-{android,ios}.sh, export-android.sh, pack-assets.sh,
gen-debug-keystore.sh. Assets ship as a zip mounted at runtime by
project/asset_pack.gd (adb push now; HTTP download is a drop-in later).

ctest 10/10, 34 GDScript suites, macOS/iOS/Android all build.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013EJxkHiNKS4kybHS3XKyAJ
2026-08-31 20:02:12 +09:00

90 lines
2.8 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# channel_status_test —— 频道负载查询(ChannelStatusheadless 自检。
# godot --headless --path project --script channel_status_test.gd
# 起一个进程内 TCP mock 状态服务器,验证请求字节 + 响应解析。
extends SceneTree
const ChannelStatus = preload("res://net/channel_status.gd")
var _fail := 0
func _ck(c: bool, m: String) -> void:
if not c:
_fail += 1
printerr("FAIL: " + m)
func _init() -> void:
await _run()
if _fail == 0:
print("PASS: channel_status_test")
quit(0)
else:
printerr("%d check(s) failed" % _fail)
quit(1)
func _run() -> void:
var srv := TCPServer.new()
var port := 0
for p in range(52000, 52050):
if srv.listen(p) == OK:
port = p
break
_ck(port != 0, "mock server listening")
var got_req := [PackedByteArray()]
var host_node := Node.new()
get_root().add_child(host_node)
var cs: Node = ChannelStatus.new()
get_root().add_child(cs)
var result := [{}]
cs.done.connect(func(m): result[0] = m)
cs.query("127.0.0.1", port, Callable(), 3.0)
# mock 服务器:等连接 → 收请求 → 回 RESPOND_CHANNELSTATUS
var conn: StreamPeerTCP = null
var replied := false
for i in 300:
if srv.is_connection_available() and conn == null:
conn = srv.take_connection()
if conn:
conn.poll()
if conn and conn.get_status() == StreamPeerTCP.STATUS_CONNECTED:
if conn.get_available_bytes() >= 4 and got_req[0].is_empty():
got_req[0] = conn.get_data(4)[1]
if not got_req[0].is_empty() and not replied:
# 先塞一个无关包(header 0x0007 len 6)测试跳过逻辑
var noise := PackedByteArray(); noise.resize(6)
noise.encode_u16(0, 0x0007); noise.encode_u16(2, 6)
conn.put_data(noise)
# 再回 RESPOND_CHANNELSTATUS: [0x0010][len=4][int32 count=2][{i16 port,u8 st}×2]
var body := PackedByteArray(); body.resize(4 + 4 + 3 + 3)
body.encode_u16(0, 0x0010); body.encode_u16(2, 4)
body.encode_s32(4, 2)
body.encode_s16(8, 13011); body.encode_u8(10, 1) # CH1 正常
body.encode_s16(11, 13021); body.encode_u8(13, 3) # CH2 爆满
conn.put_data(body)
replied = true
if not result[0].is_empty():
break
await process_frame
_ck(got_req[0].size() == 4, "请求 4 字节")
if got_req[0].size() == 4:
_ck(got_req[0].decode_u16(0) == 0x000F and got_req[0].decode_u16(2) == 4,
"请求 = CG_STATE_CHECKER(0x000F) len 4")
_ck(result[0].get(13011, -1) == 1, "CH1 (13011) -> status 1")
_ck(result[0].get(13021, -1) == 3, "CH2 (13021) -> status 3")
_ck(cs.text_for(3) == "爆满" and cs.text_for(1) == "正常", "状态文案")
# 连不上的端口 -> 空 map,不卡死
var cs2: Node = ChannelStatus.new()
get_root().add_child(cs2)
var r2 := [{"x": 1}]
cs2.query("127.0.0.1", 1, func(m): r2[0] = m, 1.0)
for i in 120:
if not cs2.is_processing():
break
await process_frame
_ck(r2[0].is_empty(), "不可达 -> 空 map")
srv.stop()