'use client' import { useEffect, useMemo, useState } from 'react'; import { useSession } from 'next-auth/react'; import GameSocket from './GameSocket'; import TeamSidebar from './TeamSidebar'; import StaticEffects from './StaticEffects'; import RadarHeader from './RadarHeader'; import RadarCanvas from './RadarCanvas'; import { useAvatarDirectoryStore } from '@/app/lib/useAvatarDirectoryStore'; import { useTelemetryStore } from '@/app/lib/useTelemetryStore'; import { useBombBeep } from './hooks/useBombBeep'; import { useOverview } from './hooks/useOverview'; import { useRadarState } from './hooks/useRadarState'; import { Grenade } from './lib/types'; import { UI } from './lib/ui'; import { teamOfGrenade } from './lib/grenades'; import { BombState } from './lib/types'; const teamIdT = undefined as string | undefined; const teamIdCT = undefined as string | undefined; function makeWsUrl(host?: string, port?: string, path?: string, scheme?: string) { const h = (host ?? '').trim() || '127.0.0.1'; const p = (port ?? '').trim() || '8081'; const pa = (path ?? '').trim() || '/telemetry'; const sch = (scheme ?? '').toLowerCase(); const pageHttps = typeof window !== 'undefined' && window.location.protocol === 'https:'; const useWss = sch === 'wss' || (sch !== 'ws' && (p === '443' || pageHttps)); const proto = useWss ? 'wss' : 'ws'; const portPart = (p === '80' || p === '443') ? '' : `:${p}`; return `${proto}://${h}${portPart}${pa}`; } const gameUrl = makeWsUrl( process.env.NEXT_PUBLIC_CS2_GAME_WS_HOST, process.env.NEXT_PUBLIC_CS2_GAME_WS_PORT, process.env.NEXT_PUBLIC_CS2_GAME_WS_PATH, process.env.NEXT_PUBLIC_CS2_GAME_WS_SCHEME ); export default function LiveRadar() { // Session / User const { data: session, status } = useSession(); const isAuthed = status === 'authenticated'; const mySteamId: string | null = useMemo(() => { const u: any = session?.user; const cands = [u?.steamId, u?.steamid, u?.steam_id, u?.id]; const first = cands.find(Boolean); return first ? String(first) : null; }, [session?.user]); // Avatar store const ensureTeamsLoaded = useAvatarDirectoryStore(s => s.ensureTeamsLoaded); const avatarVersion = useAvatarDirectoryStore(s => s.version); const avatarById = useAvatarDirectoryStore(s => s.byId); // Radar state (alles zentrale Zeug) const { radarWsStatus, setGameWsStatus, activeMapKey, setActiveMapKey, players, playersRef, hoveredPlayerId, setHoveredPlayerId, grenades, trails, deathMarkers, bomb, roundPhase, roundEndsAtRef, bombEndsAtRef, defuseRef, score, myTeam, upsertPlayer, handlePlayersAll, handleGrenades, handleBomb, clearRoundArtifacts, scheduleFlush, } = useRadarState(mySteamId); // Avatare toggle (persist) const [useAvatars, setUseAvatars] = useState(false); useEffect(() => { try { setUseAvatars(localStorage.getItem('radar.useAvatars') === '1'); } catch {} }, []); useEffect(() => { try { localStorage.setItem('radar.useAvatars', useAvatars ? '1' : '0'); } catch {} }, [useAvatars]); // Teams preload useEffect(() => { const ids = [teamIdT, teamIdCT].filter(Boolean) as string[]; if (ids.length) ensureTeamsLoaded(ids); }, [ensureTeamsLoaded]); // Map-Key aus Telemetry übernehmen const mapKeyFromTelemetry = useTelemetryStore(s => s.mapKey); useEffect(() => { if (mapKeyFromTelemetry) setActiveMapKey(mapKeyFromTelemetry); }, [mapKeyFromTelemetry, setActiveMapKey]); // overview + mapping const { overview, imgSize, setImgSize, currentSrc, srcIdx, setSrcIdx, worldToPx, unitsToPx } = useOverview(activeMapKey, players.map(p=>({x:p.x,y:p.y}))); void overview; void srcIdx; // kept if you want to expose choice UI later // Bomb beep state const { beepState } = useBombBeep(bomb); const bombSecLeft = bombEndsAtRef.current == null ? null : Math.max(0, Math.ceil((bombEndsAtRef.current - Date.now())/1000)); const bombFinal10 = bombSecLeft != null && bombSecLeft <= 10; // helper: grenade filter by team const teamOfPlayer = (sid?: string | null): 'T' | 'CT' | string | null => { if (!sid) return null; return playersRef.current.get(sid)?.team ?? null; }; const shouldShowGrenade = (g: Grenade): boolean => { if (myTeam !== 'T' && myTeam !== 'CT') return true; const gt = teamOfGrenade(g, teamOfPlayer); return gt === myTeam; }; if (!isAuthed) { return (
Bitte einloggen, um das Live-Radar zu sehen.