/** * LOCO Booking — connects to booking-loco.kakao.com:443 over TLS, * performs LOCO RSA handshake, sends GETCONF, and returns checkin server info. * * Flow (based on kiwitalk reference): * 1. TLS connect to booking-loco.kakao.com:443 * 2. LOCO RSA handshake (encrypt AES session key) * 3. Send GETCONF command → receive checkin server list * 4. Disconnect */ import { LocoSocket } from "./socket.js"; const BOOKING_HOST = "booking-loco.kakao.com"; const BOOKING_PORT = 443; /** * Connect to the booking server via TLS + LOCO protocol, * send GETCONF, and return checkin server information. */ export async function fetchBookingServer(serverPublicKey, req) { const config = { host: BOOKING_HOST, port: BOOKING_PORT, useTLS: true, serverPublicKey, }; const socket = new LocoSocket(config, { plaintext: true }); try { await socket.connect(); console.log("[Booking] Connected to booking-loco.kakao.com:443"); const resp = await socket.request("GETCONF", { MCCMNC: req.MCCMNC, os: req.os, model: req.model, }); console.log("[Booking] GETCONF response received"); if (process.env["LOCO_DEBUG"]) { console.log("[Booking] Full GETCONF body:", JSON.stringify(resp.body, null, 2)); } const body = resp.body; // Extract checkin hosts from ticket.lsl or ticket.v2sl const ticket = body["ticket"] ?? {}; const lsl = ticket["lsl"] ?? []; const v2sl = ticket["v2sl"] ?? []; // Extract ports from wifi config const wifi = body["wifi"] ?? {}; const ports = wifi["ports"] ?? [9282]; return { checkinHosts: v2sl, checkinHostsLsl: lsl, ports, raw: body, }; } finally { socket.disconnect(); } } /** * Convenience function: booking → pick first checkin host + port. * Returns { host, port } ready for checkin connection. */ export async function resolveCheckinServer(serverPublicKey, req, fallbackHost = "121.53.93.55", fallbackPort = 9282) { try { const conf = await fetchBookingServer(serverPublicKey, req); const hosts = conf.checkinHostsLsl.length > 0 ? conf.checkinHostsLsl : conf.checkinHosts; // Prefer an IP address over hostname for direct connection const host = hosts.find((h) => /^\d/.test(h)) ?? hosts[0] ?? fallbackHost; // Prefer port 9282 (standard LOCO raw TCP) if available const port = conf.ports.includes(9282) ? 9282 : (conf.ports[0] ?? fallbackPort); return { host, port }; } catch (err) { console.warn("[Booking] Failed:", err.message, "— using fallback"); return { host: fallbackHost, port: fallbackPort }; } } //# sourceMappingURL=booking.js.map