import { useCallback, useEffect, useState } from "react"; import { Check, Loader2, Minus } from "lucide-react"; import { api, asUiError, type FriendsMode, type FriendsStatus, type InternetCheck, type UiError } from "@/lib/api"; import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { useHuman, useT, type Key } from "@/i18n"; /** Convenience only; Rust validates again before applying or saving. */ function validLanIpv4(value: string): boolean { if (!/^(0|[1-9]\d{0,2})(\.(0|[1-9]\d{0,2})){3}$/.test(value)) return false; const octets = value.split(".").map(Number); const [a, b] = octets; return octets.every((n) => n <= 255) && a > 0 && a < 224 && a !== 127 && !(a === 169 && b === 254) && !(a === 100 && b >= 64 && b <= 127); } function Line({ ok, children, warn }: { ok: boolean; warn?: boolean; children: React.ReactNode }) { const t = useT(); return (
{line}
{error ? human(error.human).message : t("fr.looking")}
; const cur = st.settings; const exposed = st.exposure.filter((e) => (e.what === "database" || e.what === "server console") && e.reachable_from_network); const connection = cur.mode === "local" ? null : `set realmlist ${cur.host}`; const selectedLan = lanOverride ?? st.lan_ip; const lanUnavailable = lanOverride !== null && lanValid && !st.lan_addresses.some((a) => a.address === lanOverride); return ({t("q.friends")}
{exposed.length > 0 && ({t("fr.exposedTitle")}
{t("fr.exposedText", { what: exposed.map((e) => t(e.what === "database" ? "fr.what.database" : "fr.what.console")).join(t("fr.and")) })}
{t("realm.secondPort", { port: st.secondary_world_port })}
}{t(m.text)}
{m.id === "lan" && ( <> {lanChoice === "custom" && <> setCustomLan(e.target.value)} /> >} {!lanValid &&{t("fr.lan.invalid")}
} {lanUnavailable &&{t("fr.lan.unavailable")} {t("fr.lan.unavailableText")}
} {selectedLan && lanValid &&{t("fr.cgnat")}
)} {net?.public_ip && net.reachability !== "cgnat" && ({t("fr.publicAddr")} {net.public_ip}{!net.router_found && {t("fr.noRouter")}}
)} {net?.public_ip && net.reachability !== "cgnat" && cur.mode !== m.id &&{t("fr.noInternet")}
}{!st.tailscale.installed && {t("fr.tsMissing")}} {st.tailscale.installed && !st.tailscale.connected && {t("fr.tsOff")}} {st.tailscale.connected && <>{t("fr.privateAddr")} {st.tailscale.ip}>}
)} {m.id === "private" && !st.tailscale.installed && ({t("fr.giveText")}
{connection}
{note}
} {needsRestart && st.server_running && ( )} {error &&{error.human.code === "unknown" ? error.technical : human(error.human).message}
}