diff --git a/packages/local-service/src/matching/cluster-list.ts b/packages/local-service/src/matching/cluster-list.ts new file mode 100644 index 0000000..cda65e1 --- /dev/null +++ b/packages/local-service/src/matching/cluster-list.ts @@ -0,0 +1,19 @@ +/** + * wtmm_static.fetch_clusters_list: the list of server regions ("clusters") the player can + * pick for matchmaking. + * + * The stock UI script asks for it right after the matching sign-in + * (gui.vromfs.bin scripts/onlineInfo/clustersManagement.nut, updateClustersList): the answer + * must carry a non-empty array "clusters" of cluster names, otherwise the script retries and, + * after MAX_FETCH_RETRIES (5), signs the player out — the endless re-login loop seen in lab + * run 6. The names are the ones the stock scripts know (scripts/onlineInfo/defaultClusters.nut + * maps every country to one of them and preselects it; the UI shows loc "cluster/"). + * + * Everything runs on the player's machine, so the region has no effect on where anything + * connects; the list only has to be valid for the stock UI. + */ +import type { MatchingRequestHandler } from './matching-requests.ts'; + +const CLUSTERS = ['EU', 'NA', 'CIS', 'SA'] as const; + +export const fetchClustersList: MatchingRequestHandler = () => ({ clusters: [...CLUSTERS] }); diff --git a/packages/local-service/src/matching/matching-message.ts b/packages/local-service/src/matching/matching-message.ts index 715f3ee..ac4f184 100644 --- a/packages/local-service/src/matching/matching-message.ts +++ b/packages/local-service/src/matching/matching-message.ts @@ -7,7 +7,8 @@ * 0x44e9bc0, kind passed to the sender at 0x44ea3b9). * - The client sorts what it receives by kind (matching::ClientImpl::handleServerPacket, * 0x44e7540): kind 0x1b goes to the answer queue, handled at 0x44ec4b0, which finds the - * pending request by "id", treats a missing or zero "error" as success and passes "data" on; + * pending request by "id", treats a missing or zero "error" as success and passes "data" on + * (the result itself is inside it, see answerTo); * every other kind is a server notification (0x44eab40). Every message needs a "type", * otherwise the client drops it ("bad message. type not set"). */ @@ -62,6 +63,15 @@ export function asRequest(message: MatchingMessage): MatchingRequest | undefined }; } -export function answerTo(request: MatchingRequest, data: Record): MatchingMessage { - return { kind: MessageKind.Answer, json: { id: request.id, type: request.type, data } }; +/** + * The answer's result sits one level deeper than "data", mirroring the request envelope: + * {"id", "type", "data": {"data": }}. The answer handler (0x44ec4b0) passes the + * message's "data" to the request's completion wrapper (0x44f1c00, set by the request sender + * 0x44e9bc0), which logs "got response on …" and hands that object's own "data" to the + * caller; for script requests (matching_call, 0x46e1e70) that is the table the UI script + * receives, with "error" added (0x46e5ee0). local verification: a result placed directly in "data" + * reached the script as an empty table. + */ +export function answerTo(request: MatchingRequest, result: Record): MatchingMessage { + return { kind: MessageKind.Answer, json: { id: request.id, type: request.type, data: { data: result } } }; } diff --git a/packages/local-service/src/matching/matching-requests.ts b/packages/local-service/src/matching/matching-requests.ts index 4576f6b..01b3531 100644 --- a/packages/local-service/src/matching/matching-requests.ts +++ b/packages/local-service/src/matching/matching-requests.ts @@ -8,6 +8,7 @@ * Nothing local checks the credentials (single-player machine); the session key is needed * because the client encrypts everything after this request. */ +import { fetchClustersList } from './cluster-list.ts'; import type { MatchingRequest } from './matching-message.ts'; import { jwtDecryptsWith, unwrapSessionKey } from './session-crypto/session-key.ts'; @@ -23,6 +24,7 @@ export type MatchingRequestHandler = (request: MatchingRequest, session: Matchin export const MATCHING_REQUESTS: ReadonlyMap = new Map([ ['mlogin.login', signIn], + ['wtmm_static.fetch_clusters_list', fetchClustersList], ]); function signIn(request: MatchingRequest, session: MatchingSessionControl): Record {