Backend: - New Flask 3 app with service-layer architecture - Pydantic v2 models and unified API response format - psycopg3 connection pool with stored procedure support - 14 services: DB, SSH, K8s, BGD, RMQ (admin + game), realtime, player, economy, guild, world, progression, character, audit, chat - 30+ API endpoints covering players, guilds, economy, world, admin, server, files, director, chat - SSE real-time events for battlegroup, chat, metrics, connection status - SocketIO remote shell (xterm.js compatible) - Settings CRUD, moderation (ban/kick/unban), audit logging - Security: CSRF, rate limiting, CSP, HSTS, read-only SQL enforcement Frontend: - Vite + React 18 + TypeScript + Tailwind CSS - 14 Dune house themes via CSS custom properties - SWR for server state, Axios API client with interceptors - 14 pages: Overview, Player Explorer + Detail, Guild Manager, Vehicles, Buildings, Map Viewer, Accounts, Server Control, Admin Tools (7 tabs), Chat Monitor, Remote Shell, File Browser, Director, Settings - Player Detail with 6 tabs: overview, inventory, vehicles, buildings, progression, actions - Admin Tools: broadcast, economy, world, character, functions, raw query, audit log - Interactive canvas map viewer with zoom/pan/filter - Toast notifications, connection badges, theme switcher Other: - Updated .gitignore for frontend/backend structure - Updated README with new architecture, development guide, and project structure - Legacy app/ templates/ static/ remain untouched
53 lines
1.2 KiB
TypeScript
53 lines
1.2 KiB
TypeScript
import { useEffect, useRef } from 'react'
|
|
import { useApp } from '../stores/AppContext'
|
|
|
|
export function useRealtime() {
|
|
const { dispatch } = useApp()
|
|
const evtSource = useRef<EventSource | null>(null)
|
|
|
|
useEffect(() => {
|
|
const es = new EventSource('/api/events/stream')
|
|
evtSource.current = es
|
|
|
|
es.onopen = () => {
|
|
console.log('[SSE] Connected')
|
|
}
|
|
|
|
es.addEventListener('battlegroup_update', (e) => {
|
|
try {
|
|
const data = JSON.parse(e.data)
|
|
console.log('[SSE] battlegroup_update', data)
|
|
} catch {}
|
|
})
|
|
|
|
es.addEventListener('rmq_health', (e) => {
|
|
try {
|
|
const data = JSON.parse(e.data)
|
|
console.log('[SSE] rmq_health', data)
|
|
} catch {}
|
|
})
|
|
|
|
es.addEventListener('connection_status', (e) => {
|
|
try {
|
|
const data = JSON.parse(e.data)
|
|
dispatch({ type: 'SET_CONNECTION', payload: data })
|
|
} catch {}
|
|
})
|
|
|
|
es.addEventListener('chat_message', (e) => {
|
|
try {
|
|
const data = JSON.parse(e.data)
|
|
console.log('[SSE] chat_message', data)
|
|
} catch {}
|
|
})
|
|
|
|
es.onerror = () => {
|
|
console.warn('[SSE] Connection error')
|
|
}
|
|
|
|
return () => {
|
|
es.close()
|
|
}
|
|
}, [dispatch])
|
|
}
|