From 972c200cd0692fffe981d2aa76c0c0f2b0675f14 Mon Sep 17 00:00:00 2001 From: shenlei Date: Fri, 16 Oct 2026 20:35:08 +0900 Subject: [PATCH] Switchbot gate: find the mt mark anywhere in the client timestamp Every locale.cfg client build is LOCALE_SERVICE_EUROPE and sends CG_CLIENT_VERSION2, and 203 compares that timestamp with atoi against 1215955205. The client now sends "1215955205 mt20261016", so the gate looks for "mt" instead of requiring it at the start. Found on channel5. Co-Authored-By: Claude Opus 5.5 --- docs/FEATURE-SWITCHBOT.md | 4 ++-- src/server/game/src/port_switchbot.cpp | 9 +++++---- tests/features/test_switchbot.py | 4 +++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/docs/FEATURE-SWITCHBOT.md b/docs/FEATURE-SWITCHBOT.md index 67036114..c8d01a7d 100644 --- a/docs/FEATURE-SWITCHBOT.md +++ b/docs/FEATURE-SWITCHBOT.md @@ -50,7 +50,7 @@ Header numbers, subheaders and field order are AVA2's. The structs are `pack(1)` CG is registered in `packet_info.cpp` with `Set(..., true)` and GG with `Set(..., false)`. The 40250 base packets are unchanged. -**Version gate.** The new client sends `mt20261016` as the `CG_CLIENT_VERSION` timestamp, in place of `__TIMESTAMP__`. Before `EnterGame` sends anything, it checks `SwitchbotHelper::IsClientSupported`, which requires `mt` with date >= `PORT_SWITCHBOT_CLIENT_VERSION`. An older client gets no GC_SWITCHBOT packet. It can't fill the window either. The EU-branch client timestamp (`1215955205`) doesn't pass the gate. +**Version gate.** The client is built with `LOCALE_SERVICE_EUROPE`, so every locale sends `CG_CLIENT_VERSION2`. The new client's timestamp is `1215955205 mt20261016`. 203 is a europe locale and checks the version with `atoi`, which still reads 1215955205. Before `EnterGame` sends anything, it checks `SwitchbotHelper::IsClientSupported`, which looks for `mt` in the timestamp with date >= `PORT_SWITCHBOT_CLIENT_VERSION`. An older client sends `1215955205` only and gets no GC_SWITCHBOT packet. It can't fill the window either. (The non-EU branch sends `mt20261016`.) ## Verification @@ -60,4 +60,4 @@ CG is registered in `packet_info.cpp` with `Set(..., true)` and GG with `Set(... - the version gate; - that `/mt_switchbot` is gone. - Client: `metin2-client/tests/wiki/test_switchbot.py` checks that the window script is AVA2 `uiswitchbot.py` verbatim, plus its glue. -- Not yet compiled on 203 and not deployed. The live 203 still runs v1, so the server and client must be deployed together. +- Compiled on 203 (dev tree) and run on channel5. Not deployed. The live 203 still runs v1, so the server and client must be deployed together. diff --git a/src/server/game/src/port_switchbot.cpp b/src/server/game/src/port_switchbot.cpp index d360af1c..ca109814 100644 --- a/src/server/game/src/port_switchbot.cpp +++ b/src/server/game/src/port_switchbot.cpp @@ -12,8 +12,9 @@ // "switchbot_stop ") for localeInfo text, instead of AVA2's numeric locale ids 864 / 865. // - Leaving the core deletes the table after it is sent (AVA2 leaked it), and a logout that unregisters the last // active slot stops the roll event. -// - Version gate: EnterGame sends nothing unless the CG_CLIENT_VERSION timestamp is "mt" with -// date >= PORT_SWITCHBOT_CLIENT_VERSION (older clients send __TIMESTAMP__ or "1215955205"). +// - Version gate: EnterGame sends nothing unless the CG_CLIENT_VERSION(2) timestamp carries "mt" with +// date >= PORT_SWITCHBOT_CLIENT_VERSION. The EU client sends "1215955205 mt": the europe version +// check reads the timestamp with atoi, so it still sees 1215955205. Older clients send "1215955205" only. // - The attribute list has two pseudo sets after ATTRIBUTE_SET_MAX_NUM: 8 = rings (port_rings.cpp) and // 9 = talismans (port_pendant.cpp), whose pools are not in item_attr. #include "stdafx.h" @@ -742,8 +743,8 @@ void CSwitchbotManager::SendSwitchbotUpdate(DWORD player_id) bool SwitchbotHelper::IsClientSupported(LPCHARACTER ch) { LPDESC d = ch ? ch->GetDesc() : NULL; - const char* c_pszVersion = d ? d->GetClientVersion() : ""; - return c_pszVersion[0] == 'm' && c_pszVersion[1] == 't' && atoi(c_pszVersion + 2) >= PORT_SWITCHBOT_CLIENT_VERSION; + const char* c_pszMark = d ? strstr(d->GetClientVersion(), "mt") : NULL; + return c_pszMark && atoi(c_pszMark + 2) >= PORT_SWITCHBOT_CLIENT_VERSION; } void CSwitchbotManager::EnterGame(LPCHARACTER ch) diff --git a/tests/features/test_switchbot.py b/tests/features/test_switchbot.py index d578f6ae..4e14d4e3 100644 --- a/tests/features/test_switchbot.py +++ b/tests/features/test_switchbot.py @@ -82,7 +82,7 @@ assert 'CSwitchbotManager::Instance().EnterGame(ch);' in source('game/src/input_ assert 'enum { PORT_SWITCHBOT_CLIENT_VERSION = 20261016 };' in source('game/src/port_switchbot.h') enter=port[port.index('void CSwitchbotManager::EnterGame'):];enter=enter[:enter.index('\n}\n')] assert enter.index('if (!SwitchbotHelper::IsClientSupported(ch))\n\t\treturn;')= PORT_SWITCHBOT_CLIENT_VERSION" in port +assert 'strstr(d->GetClientVersion(), "mt")' in port and 'atoi(c_pszMark + 2) >= PORT_SWITCHBOT_CLIENT_VERSION' in port assert 'case SWITCHBOT:' in source('game/src/input_db.cpp') main=source('game/src/main.cpp') assert 'CSwitchbotManager switchbotManager;' in main and 'PortSwitchbotBoot();' in main @@ -102,6 +102,8 @@ if cpacket.is_file(): assert 'static_assert(sizeof(TSwitchbotUpdateItem) == 40,' in client assert 'static_assert(sizeof(TPacketCGSwitchbot) == 7 && sizeof(TPacketGCSwitchbot) == 7,' in client stream=(CLIENT/'PythonNetworkStreamPhaseGame.cpp').read_bytes().decode('latin1') + # the EU branch (the one every locale.cfg build takes) keeps 1215955205 first for the atoi version check + assert 'strncpy(kVersionPacket.timestamp, "1215955205 mt20261016", sizeof(kVersionPacket.timestamp)-1);' in stream assert 'strncpy(kVersionPacket.timestamp, "mt20261016", sizeof(kVersionPacket.timestamp)-1);' in stream pyswitch=(CLIENT/'PythonSwitchbot.h').read_bytes().decode('latin1') ctable=pyswitch[pyswitch.index('struct TSwitchbotTable'):];ctable=ctable[:ctable.index('};')]