1022 lines
46 KiB
HTML
1022 lines
46 KiB
HTML
<!doctype html>
|
|
<html lang="es">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
|
<title>realconn · conexiones en vivo</title>
|
|
<style>
|
|
:root {
|
|
--bg: #04060d;
|
|
--hud: #e8f1ff;
|
|
--dim: #6c7a99;
|
|
--accent: #ff4d6a;
|
|
--ok: #4dff88;
|
|
}
|
|
* { box-sizing: border-box; }
|
|
html, body {
|
|
margin: 0; height: 100%; width: 100%;
|
|
overflow: hidden; background: var(--bg);
|
|
color: var(--hud);
|
|
font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Courier New", monospace;
|
|
-webkit-user-select: none; user-select: none;
|
|
}
|
|
#stage { position: fixed; inset: 0; }
|
|
#stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
|
|
#hud {
|
|
position: fixed; top: 0; left: 0; right: 0;
|
|
display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 22px;
|
|
padding: 10px 16px; pointer-events: none;
|
|
text-shadow: 0 0 6px rgba(0,0,0,.9);
|
|
font-size: clamp(11px, 1.6vw, 14px); letter-spacing: .06em;
|
|
}
|
|
#hud .item { white-space: nowrap; }
|
|
#hud .label { color: var(--dim); margin-right: 6px; }
|
|
#score { font-size: clamp(18px, 3.2vw, 30px); font-weight: 700; color: #fff; }
|
|
#cycle { color: var(--ok); }
|
|
#cycle.bump { animation: bump .6s ease-out; }
|
|
@keyframes bump { 0% { transform: scale(1.6); color: #fff; } 100% { transform: scale(1); } }
|
|
#hud .item.cycle { display: inline-block; }
|
|
#status .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--dim); vertical-align: middle; }
|
|
#status.on .dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
|
|
#status.off .dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
|
|
#status.demo .dot { background: #ffd34d; box-shadow: 0 0 8px #ffd34d; }
|
|
#legend {
|
|
position: fixed; right: 16px; bottom: 8px; pointer-events: none;
|
|
font-size: 11px; color: var(--dim); display: flex; gap: 12px;
|
|
text-shadow: 0 0 4px #000;
|
|
}
|
|
#legend i { display: inline-block; width: 10px; height: 2px; margin-right: 5px; vertical-align: middle; }
|
|
.hide-hud #hud, .hide-hud #legend { display: none; }
|
|
@media (max-width: 480px) { #legend { display: none; } }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="stage">
|
|
<canvas id="bg"></canvas>
|
|
<canvas id="game"></canvas>
|
|
<canvas id="fx"></canvas>
|
|
</div>
|
|
|
|
<div id="hud">
|
|
<div class="item"><span class="label">SCORE</span><span id="score">0</span></div>
|
|
<div class="item cycle"><span class="label">CICLO</span><span id="cycle">+0</span></div>
|
|
<div class="item"><span class="label">EN VUELO</span><span id="flying">0</span></div>
|
|
<div class="item"><span class="label">IMPACTOS</span><span id="hits">0</span></div>
|
|
<div class="item"><span class="label">DESCARTADAS</span><span id="dropped">0</span></div>
|
|
<div class="item" id="status"><span class="dot"></span><span id="statusText">conectando…</span></div>
|
|
</div>
|
|
<div id="legend">
|
|
<span><i style="background:#4dff88"></i>2xx</span>
|
|
<span><i style="background:#4dd2ff"></i>3xx</span>
|
|
<span><i style="background:#ffd34d"></i>4xx</span>
|
|
<span><i style="background:#ff4d6a"></i>5xx</span>
|
|
</div>
|
|
|
|
<script>
|
|
/* =====================================================================
|
|
* CONFIGURACIÓN
|
|
* API_URL: dirección de la API de realconn que este cliente consulta.
|
|
* Se puede sobrescribir por URL: index.html?api=http://host:8080/api/connections
|
|
* ===================================================================== */
|
|
const CONFIG = {
|
|
API_URL: "api/connections", // <<< URL DE LA API
|
|
POLL_INTERVAL_MS: 2000, // cada cuánto se consulta la API
|
|
MAX_ACTIVE_MISSILES: 350, // misiles simultáneos en pantalla
|
|
MAX_QUEUE: 3000, // conexiones en espera de lanzarse
|
|
MISSILE_TIME_S: [2.4, 4.2], // duración de la caída (min, max)
|
|
SHOW_LABELS: true, // mostrar la IP bajo cada misil
|
|
SHOW_UA: true, // mostrar navegador y sistema operativo bajo la IP
|
|
MAP_IMAGE_URL: "", // imagen opcional para el mapa (si vacío se dibuja uno vectorial)
|
|
SERVER_IMAGE_URL: "", // imagen opcional para el servidor (si vacío se dibuja uno detallado)
|
|
DEMO: false, // genera conexiones falsas (sin API)
|
|
};
|
|
|
|
/* --- Parámetros por URL (útil al incrustar en un iframe) ---------------- */
|
|
(() => {
|
|
const q = new URLSearchParams(location.search);
|
|
if (q.has("api")) CONFIG.API_URL = q.get("api");
|
|
if (q.has("interval")) CONFIG.POLL_INTERVAL_MS = Math.max(250, +q.get("interval") || CONFIG.POLL_INTERVAL_MS);
|
|
if (q.has("labels")) CONFIG.SHOW_LABELS = q.get("labels") !== "0";
|
|
if (q.has("ua")) CONFIG.SHOW_UA = q.get("ua") !== "0";
|
|
if (q.has("map")) CONFIG.MAP_IMAGE_URL = q.get("map");
|
|
if (q.has("server")) CONFIG.SERVER_IMAGE_URL = q.get("server");
|
|
if (q.has("demo")) CONFIG.DEMO = q.get("demo") !== "0";
|
|
if (q.get("hud") === "0") document.body.classList.add("hide-hud");
|
|
})();
|
|
|
|
/* --- Utilidades ---------------------------------------------------------- */
|
|
const $ = (id) => document.getElementById(id);
|
|
const rand = (a, b) => a + Math.random() * (b - a);
|
|
const clamp = (v, a, b) => Math.max(a, Math.min(b, v));
|
|
function hashStr(s) { // FNV-1a
|
|
let h = 2166136261;
|
|
for (let i = 0; i < s.length; i++) { h ^= s.charCodeAt(i); h = Math.imul(h, 16777619); }
|
|
return h >>> 0;
|
|
}
|
|
function statusColor(st) {
|
|
if (st >= 500) return [255, 77, 106];
|
|
if (st >= 400) return [255, 211, 77];
|
|
if (st >= 300) return [77, 210, 255];
|
|
if (st >= 200) return [77, 255, 136];
|
|
return [197, 140, 255];
|
|
}
|
|
const rgb = (c, a = 1) => `rgba(${c[0]},${c[1]},${c[2]},${a})`;
|
|
const MONO = "ui-monospace, Menlo, Consolas, monospace";
|
|
function rr(ctx, x, y, w, h, r) { // rectángulo redondeado
|
|
r = Math.min(r, w / 2, h / 2);
|
|
ctx.beginPath();
|
|
ctx.moveTo(x + r, y);
|
|
ctx.arcTo(x + w, y, x + w, y + h, r); ctx.arcTo(x + w, y + h, x, y + h, r);
|
|
ctx.arcTo(x, y + h, x, y, r); ctx.arcTo(x, y, x + w, y, r);
|
|
ctx.closePath();
|
|
}
|
|
|
|
/* --- User-Agent → "Navegador versión · Sistema operativo" --------------- */
|
|
function parseUA(ua) {
|
|
const v = (re) => { const r = ua.match(re); return r ? r[1] : null; };
|
|
const bot = ua.match(/\b(Googlebot|bingbot|YandexBot|Baiduspider|DuckDuckBot|AhrefsBot|SemrushBot|Applebot|facebookexternalhit|Twitterbot|GPTBot|ClaudeBot|PetalBot|MJ12bot|DotBot|Bytespider|UptimeRobot|DataForSeoBot)\b/i);
|
|
if (bot) return bot[1] + " · bot";
|
|
const tool = ua.match(/^(curl|Wget|python-requests|Python-urllib|aiohttp|Go-http-client|PostmanRuntime|okhttp|axios|node-fetch|undici|Java|libwww-perl|HTTPie|Apache-HttpClient|Scrapy|Dalvik)\/?(\d*)/i);
|
|
if (tool) return tool[1] + (tool[2] ? " " + tool[2] : "") + (/Dalvik/i.test(tool[1]) ? " · Android" : " · script");
|
|
|
|
let os = "";
|
|
let w;
|
|
if ((w = v(/Windows NT (\d+\.\d+)/))) os = ({ "10.0": "Windows 10/11", "6.3": "Windows 8.1", "6.2": "Windows 8", "6.1": "Windows 7", "6.0": "Windows Vista", "5.1": "Windows XP" })[w] || "Windows";
|
|
else if (/Windows/.test(ua)) os = "Windows";
|
|
else if ((w = ua.match(/(iPhone|iPad|iPod).*? OS (\d+)[_.](\d+)/))) os = (w[1] === "iPad" ? "iPadOS " : "iOS ") + w[2] + "." + w[3];
|
|
else if ((w = v(/Android (\d+(?:\.\d+)?)/))) os = "Android " + w;
|
|
else if (/Android/.test(ua)) os = "Android";
|
|
else if (/CrOS/.test(ua)) os = "ChromeOS";
|
|
else if (/Mac OS X|Macintosh/.test(ua)) os = "macOS";
|
|
else if (/Ubuntu/.test(ua)) os = "Ubuntu";
|
|
else if (/Fedora/.test(ua)) os = "Fedora";
|
|
else if (/Linux/.test(ua)) os = "Linux";
|
|
else if (/FreeBSD/.test(ua)) os = "FreeBSD";
|
|
|
|
let br = "";
|
|
if ((w = v(/Edg(?:e|A|iOS)?\/(\d+)/))) br = "Edge " + w;
|
|
else if ((w = v(/(?:OPR|OPX|Opera)\/(\d+)/))) br = "Opera " + w;
|
|
else if ((w = v(/SamsungBrowser\/(\d+)/))) br = "Samsung " + w;
|
|
else if ((w = v(/YaBrowser\/(\d+)/))) br = "Yandex " + w;
|
|
else if ((w = v(/Vivaldi\/(\d+)/))) br = "Vivaldi " + w;
|
|
else if ((w = v(/(?:Firefox|FxiOS)\/(\d+)/))) br = "Firefox " + w;
|
|
else if ((w = v(/CriOS\/(\d+)/))) br = "Chrome " + w;
|
|
else if ((w = v(/Chrome\/(\d+)/))) br = "Chrome " + w;
|
|
else if ((w = v(/Version\/(\d+(?:\.\d+)?).*Safari/))) br = "Safari " + w;
|
|
else if ((w = v(/(?:MSIE |Trident\/.*rv:)(\d+)/))) br = "IE " + w;
|
|
else if (/bot|crawl|spider|slurp/i.test(ua)) br = (ua.match(/[\w.-]*(?:bot|crawl|spider|slurp)[\w.-]*/i) || ["bot"])[0];
|
|
|
|
const out = [br, os].filter(Boolean).join(" · ");
|
|
return out || ua.split(/[\s(;]/)[0].slice(0, 24) || "desconocido";
|
|
}
|
|
const uaCache = new Map();
|
|
function describeUA(ua) {
|
|
if (!ua) return "sin user-agent";
|
|
let d = uaCache.get(ua);
|
|
if (d === undefined) {
|
|
d = parseUA(ua);
|
|
if (uaCache.size > 1000) uaCache.clear();
|
|
uaCache.set(ua, d);
|
|
}
|
|
return d;
|
|
}
|
|
function loadImage(src) {
|
|
return new Promise((res) => {
|
|
if (!src) return res(null);
|
|
const im = new Image();
|
|
im.crossOrigin = "anonymous";
|
|
im.onload = () => res(im);
|
|
im.onerror = () => res(null);
|
|
im.src = src;
|
|
});
|
|
}
|
|
|
|
/* --- Mapa del mundo simplificado (lon, lat) ----------------------------- */
|
|
const LAND = [
|
|
// Norteamérica
|
|
[[-168,66],[-162,70],[-156,71],[-140,70],[-128,70],[-115,68],[-95,72],[-82,73],[-78,63],[-90,57],[-82,52],[-78,55],[-65,60],[-60,55],[-56,52],[-66,45],[-70,42],[-76,38],[-76,35],[-81,31],[-80,25],[-83,29],[-90,30],[-97,27],[-97,22],[-92,18],[-87,21],[-88,16],[-83,10],[-79,9],[-78,7],[-81,8],[-86,12],[-92,14],[-96,16],[-105,20],[-110,24],[-112,31],[-115,30],[-110,23],[-117,32],[-121,35],[-124,40],[-124,47],[-130,55],[-138,59],[-148,60],[-153,57],[-162,55],[-158,59],[-165,62]],
|
|
// Groenlandia
|
|
[[-73,78],[-60,82],[-30,83],[-20,80],[-20,72],[-30,68],[-42,60],[-50,62],[-55,68],[-60,75]],
|
|
// Islandia
|
|
[[-24,64],[-22,66],[-15,66],[-13,65],[-18,63]],
|
|
// Cuba
|
|
[[-85,22],[-80,23],[-74,20],[-78,20],[-82,22]],
|
|
// Sudamérica
|
|
[[-80,9],[-75,11],[-70,12],[-62,11],[-52,5],[-50,0],[-44,-2],[-35,-6],[-35,-9],[-39,-15],[-41,-22],[-48,-26],[-53,-34],[-58,-38],[-62,-40],[-65,-45],[-68,-50],[-69,-55],[-74,-52],[-75,-45],[-73,-37],[-71,-30],[-70,-18],[-76,-14],[-81,-6],[-80,-2],[-80,1],[-77,4],[-78,8]],
|
|
// Eurasia
|
|
[[-10,36],[-9,43],[-2,44],[-5,48],[2,51],[8,54],[8,57],[11,55],[14,55],[20,55],[22,58],[24,60],[22,64],[18,63],[12,57],[6,58],[5,62],[14,68],[22,71],[30,70],[40,67],[44,68],[55,70],[68,72],[75,73],[80,73],[90,76],[105,78],[115,74],[130,72],[140,73],[150,71],[160,70],[170,70],[180,68],[180,65],[175,64],[170,60],[163,58],[160,52],[156,51],[156,57],[143,59],[137,54],[141,52],[140,47],[135,43],[130,42],[127,39],[129,35],[126,35],[125,38],[122,40],[118,39],[121,37],[119,34],[122,30],[120,26],[116,23],[110,21],[108,22],[106,19],[109,15],[109,11],[105,9],[105,11],[101,13],[100,7],[103,2],[104,1],[100,3],[98,8],[98,16],[94,18],[92,22],[90,22],[86,20],[80,16],[80,10],[77,8],[73,16],[72,21],[67,24],[61,25],[57,26],[56,27],[52,28],[48,30],[50,26],[52,24],[56,24],[59,22],[56,18],[52,16],[45,13],[43,13],[39,21],[35,28],[34,31],[35,36],[30,36],[27,37],[26,40],[29,41],[35,42],[41,41],[39,44],[37,47],[31,46],[29,45],[28,41],[23,40],[24,38],[22,37],[20,40],[19,42],[14,45],[13,44],[16,41],[18,40],[16,38],[15,40],[11,42],[9,44],[6,43],[3,43],[3,42],[0,39],[-1,37],[-5,36]],
|
|
// Gran Bretaña e Irlanda
|
|
[[-5,50],[1,51],[2,53],[-1,55],[-2,58],[-5,59],[-6,57],[-5,55],[-3,54],[-4,52]],
|
|
[[-10,52],[-6,52],[-6,55],[-8,55],[-10,54]],
|
|
// África y Madagascar
|
|
[[-17,21],[-17,15],[-12,8],[-8,4],[-3,5],[3,6],[7,4],[9,4],[10,0],[13,-5],[12,-14],[15,-27],[18,-34],[22,-34],[27,-33],[32,-28],[35,-24],[35,-20],[40,-15],[40,-10],[39,-5],[42,0],[48,5],[51,11],[44,11],[43,13],[39,18],[37,22],[35,27],[33,31],[30,31],[20,32],[20,30],[15,32],[10,34],[10,37],[3,37],[-2,35],[-6,36],[-10,30],[-13,27],[-16,24]],
|
|
[[44,-25],[47,-25],[50,-16],[49,-12],[44,-16]],
|
|
// Japón
|
|
[[130,31],[135,34],[140,35],[142,39],[141,42],[145,44],[142,45],[140,42],[139,38],[136,36],[132,34]],
|
|
// Sudeste asiático y Oceanía
|
|
[[95,5],[98,4],[104,-2],[106,-6],[102,-4],[95,3]],
|
|
[[109,1],[111,3],[117,7],[119,1],[116,-4],[110,-3]],
|
|
[[105,-6],[114,-7],[114,-8],[106,-7]],
|
|
[[131,-1],[138,-2],[147,-6],[150,-10],[143,-9],[138,-8],[132,-4]],
|
|
[[114,-22],[114,-34],[118,-35],[124,-33],[131,-31],[138,-35],[141,-38],[147,-38],[150,-37],[153,-31],[153,-25],[146,-19],[142,-11],[141,-17],[136,-15],[137,-12],[132,-11],[129,-15],[125,-14],[122,-17],[118,-20]],
|
|
[[172,-34],[175,-37],[178,-38],[175,-41],[171,-44],[167,-46],[169,-46],[174,-41],[173,-39]],
|
|
];
|
|
const LAT_TOP = 82, LAT_BOT = -56;
|
|
function pointInPoly(x, y, poly) {
|
|
let inside = false;
|
|
for (let i = 0, j = poly.length - 1; i < poly.length; j = i++) {
|
|
const [xi, yi] = poly[i], [xj, yj] = poly[j];
|
|
if ((yi > y) !== (yj > y) && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi) inside = !inside;
|
|
}
|
|
return inside;
|
|
}
|
|
const isLand = (lon, lat) => LAND.some((p) => pointInPoly(lon, lat, p));
|
|
|
|
/* --- Estado global -------------------------------------------------------- */
|
|
const stage = { W: 0, H: 0, dpr: 1, mapTop: 0, mapBot: 0, groundY: 0 };
|
|
const bgCanvas = $("bg"), gameCanvas = $("game"), fxCanvas = $("fx");
|
|
const bg = bgCanvas.getContext("2d");
|
|
const g = gameCanvas.getContext("2d");
|
|
let landDots = []; // puntos del mapa de donde salen los misiles
|
|
let srv = null; // el servidor que recibe las conexiones
|
|
let srvStatic = null; // partes fijas del servidor, prerenderizadas
|
|
let missiles = [];
|
|
let rings = []; // ondas expansivas (2D)
|
|
let queue = []; // conexiones pendientes de lanzar
|
|
let mapImg = null, serverImg = null;
|
|
const stats = { score: 0, shownScore: 0, hits: 0, dropped: 0 };
|
|
let shake = 0;
|
|
|
|
/* =========================================================================
|
|
* PARTÍCULAS EN GPU (WebGL)
|
|
* Cada partícula se sube una sola vez; la trayectoria (velocidad, gravedad,
|
|
* rozamiento y desvanecido) se calcula en el vertex shader.
|
|
* ========================================================================= */
|
|
const Particles = (() => {
|
|
const MAX = 40000, STRIDE = 10; // ox, oy, vx, vy, t0, life, r, g, b, size
|
|
const gl = fxCanvas.getContext("webgl", { alpha: true, premultipliedAlpha: false, antialias: false });
|
|
if (!gl) return null;
|
|
|
|
const vs = `
|
|
attribute vec2 a_o; attribute vec2 a_v; attribute float a_t0; attribute float a_life;
|
|
attribute vec3 a_c; attribute float a_s;
|
|
uniform float u_t; uniform vec2 u_res; uniform float u_dpr; uniform vec2 u_shake;
|
|
varying vec3 v_c; varying float v_a;
|
|
const float K = 2.2; // rozamiento
|
|
const float G = 520.0; // gravedad (px/s^2)
|
|
void main() {
|
|
float age = u_t - a_t0;
|
|
if (age < 0.0 || age > a_life) { gl_Position = vec4(2.0, 2.0, 0.0, 1.0); gl_PointSize = 0.0; return; }
|
|
float e = (1.0 - exp(-K * age)) / K;
|
|
vec2 p = a_o + a_v * e + vec2(0.0, G) * (age - e) / K + u_shake;
|
|
vec2 clip = (p / u_res) * 2.0 - 1.0;
|
|
gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);
|
|
float f = age / a_life;
|
|
v_a = 1.0 - f * f;
|
|
v_c = mix(vec3(1.0, 0.97, 0.85), a_c, smoothstep(0.0, 0.35, f));
|
|
gl_PointSize = a_s * u_dpr * (1.0 - 0.6 * f);
|
|
}`;
|
|
const fs = `
|
|
precision mediump float;
|
|
varying vec3 v_c; varying float v_a;
|
|
void main() {
|
|
float d = length(gl_PointCoord - 0.5);
|
|
float a = smoothstep(0.5, 0.05, d);
|
|
float core = smoothstep(0.22, 0.0, d);
|
|
gl_FragColor = vec4(v_c * (0.8 + core), clamp(a * v_a * 1.3, 0.0, 1.0));
|
|
}`;
|
|
function sh(type, src) {
|
|
const s = gl.createShader(type); gl.shaderSource(s, src); gl.compileShader(s);
|
|
if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) throw new Error(gl.getShaderInfoLog(s));
|
|
return s;
|
|
}
|
|
const prog = gl.createProgram();
|
|
gl.attachShader(prog, sh(gl.VERTEX_SHADER, vs));
|
|
gl.attachShader(prog, sh(gl.FRAGMENT_SHADER, fs));
|
|
gl.linkProgram(prog);
|
|
if (!gl.getProgramParameter(prog, gl.LINK_STATUS)) return null;
|
|
gl.useProgram(prog);
|
|
|
|
const data = new Float32Array(MAX * STRIDE);
|
|
for (let i = 0; i < MAX; i++) data[i * STRIDE + 4] = -1e6; // vacías (edad > vida)
|
|
const buf = gl.createBuffer();
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buf);
|
|
gl.bufferData(gl.ARRAY_BUFFER, data, gl.DYNAMIC_DRAW);
|
|
const B = 4 * STRIDE;
|
|
const attr = (name, size, off) => {
|
|
const loc = gl.getAttribLocation(prog, name);
|
|
gl.enableVertexAttribArray(loc);
|
|
gl.vertexAttribPointer(loc, size, gl.FLOAT, false, B, off * 4);
|
|
};
|
|
attr("a_o", 2, 0); attr("a_v", 2, 2); attr("a_t0", 1, 4); attr("a_life", 1, 5); attr("a_c", 3, 6); attr("a_s", 1, 9);
|
|
const U = (n) => gl.getUniformLocation(prog, n);
|
|
const uT = U("u_t"), uRes = U("u_res"), uDpr = U("u_dpr"), uShake = U("u_shake");
|
|
gl.enable(gl.BLEND);
|
|
gl.blendFunc(gl.SRC_ALPHA, gl.ONE); // aditivo: brillo tipo explosión
|
|
gl.clearColor(0, 0, 0, 0);
|
|
|
|
let cursor = 0, dirtyFrom = MAX, dirtyTo = 0;
|
|
return {
|
|
burst(x, y, color, count, power, t) {
|
|
for (let n = 0; n < count; n++) {
|
|
const i = cursor, o = i * STRIDE;
|
|
cursor = (cursor + 1) % MAX;
|
|
const ang = Math.random() * Math.PI * 2;
|
|
const sp = power * (0.25 + Math.pow(Math.random(), 0.6));
|
|
data[o] = x; data[o + 1] = y;
|
|
data[o + 2] = Math.cos(ang) * sp; data[o + 3] = Math.sin(ang) * sp - power * 0.55;
|
|
data[o + 4] = t; data[o + 5] = rand(0.6, 1.7);
|
|
const hot = Math.random() < 0.3;
|
|
data[o + 6] = hot ? 1 : color[0] / 255; data[o + 7] = hot ? 0.6 : color[1] / 255; data[o + 8] = hot ? 0.2 : color[2] / 255;
|
|
// la mayoría son chispas; unas pocas, resplandores grandes y suaves
|
|
data[o + 9] = Math.random() < 0.06 ? rand(16, 30) : rand(3, 8);
|
|
if (data[o + 9] > 12) { data[o + 2] *= 0.25; data[o + 3] *= 0.25; data[o + 5] *= 0.5; }
|
|
if (i < dirtyFrom) dirtyFrom = i;
|
|
if (i + 1 > dirtyTo) dirtyTo = i + 1;
|
|
}
|
|
},
|
|
resize(w, h, dpr) {
|
|
fxCanvas.width = Math.round(w * dpr); fxCanvas.height = Math.round(h * dpr);
|
|
gl.viewport(0, 0, fxCanvas.width, fxCanvas.height);
|
|
gl.uniform2f(uRes, w, h); gl.uniform1f(uDpr, dpr);
|
|
},
|
|
draw(t, sx, sy) {
|
|
if (dirtyTo > dirtyFrom) {
|
|
gl.bufferSubData(gl.ARRAY_BUFFER, dirtyFrom * B, data.subarray(dirtyFrom * STRIDE, dirtyTo * STRIDE));
|
|
dirtyFrom = MAX; dirtyTo = 0;
|
|
}
|
|
gl.uniform1f(uT, t); gl.uniform2f(uShake, sx, sy);
|
|
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
gl.drawArrays(gl.POINTS, 0, MAX);
|
|
},
|
|
};
|
|
})();
|
|
|
|
/* Alternativa en CPU si el navegador no tiene WebGL */
|
|
const CpuParticles = (() => {
|
|
if (Particles) return null;
|
|
const ps = [];
|
|
return {
|
|
burst(x, y, color, count, power) {
|
|
for (let n = 0; n < Math.min(count, 40); n++) {
|
|
const a = Math.random() * Math.PI * 2, sp = power * (0.25 + Math.random());
|
|
ps.push({ x, y, vx: Math.cos(a) * sp, vy: Math.sin(a) * sp - power * 0.55, life: rand(0.6, 1.4), age: 0, color });
|
|
}
|
|
if (ps.length > 3000) ps.splice(0, ps.length - 3000);
|
|
},
|
|
update(dt, ctx) {
|
|
ctx.globalCompositeOperation = "lighter";
|
|
for (let i = ps.length - 1; i >= 0; i--) {
|
|
const p = ps[i];
|
|
p.age += dt;
|
|
if (p.age > p.life) { ps.splice(i, 1); continue; }
|
|
p.vx *= 1 - 2.2 * dt; p.vy = p.vy * (1 - 2.2 * dt) + 520 * dt;
|
|
p.x += p.vx * dt; p.y += p.vy * dt;
|
|
ctx.fillStyle = rgb(p.color, 1 - p.age / p.life);
|
|
ctx.fillRect(p.x - 1.5, p.y - 1.5, 3, 3);
|
|
}
|
|
ctx.globalCompositeOperation = "source-over";
|
|
},
|
|
};
|
|
})();
|
|
|
|
/* =========================================================================
|
|
* ESCENARIO: mapa, suelo y servidor
|
|
* ========================================================================= */
|
|
function layout() {
|
|
const W = window.innerWidth, H = window.innerHeight;
|
|
const dpr = Math.min(window.devicePixelRatio || 1, 2);
|
|
Object.assign(stage, { W, H, dpr });
|
|
stage.mapTop = Math.max(40, H * 0.07);
|
|
stage.groundY = H - clamp(H * 0.05, 14, 36);
|
|
for (const c of [bgCanvas, gameCanvas]) { c.width = Math.round(W * dpr); c.height = Math.round(H * dpr); }
|
|
bg.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
g.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
if (Particles) Particles.resize(W, H, dpr);
|
|
|
|
buildServer();
|
|
renderServerStatic();
|
|
stage.mapBot = stage.mapTop + (srv.y - stage.mapTop) * 0.6;
|
|
drawBackground();
|
|
}
|
|
|
|
function drawBackground() {
|
|
const { W, H, mapTop, mapBot, groundY } = stage;
|
|
bg.clearRect(0, 0, W, H);
|
|
|
|
// cielo
|
|
const sky = bg.createLinearGradient(0, 0, 0, H);
|
|
sky.addColorStop(0, "#070b1d"); sky.addColorStop(0.6, "#05070f"); sky.addColorStop(1, "#0b0612");
|
|
bg.fillStyle = sky; bg.fillRect(0, 0, W, H);
|
|
|
|
// estrellas
|
|
const r = mulberry(7);
|
|
for (let i = 0; i < (W * H) / 5000; i++) {
|
|
bg.fillStyle = `rgba(200,220,255,${0.15 + r() * 0.4})`;
|
|
bg.fillRect(r() * W, r() * groundY, r() < 0.1 ? 1.6 : 1, r() < 0.1 ? 1.6 : 1);
|
|
}
|
|
|
|
landDots = [];
|
|
const mh = mapBot - mapTop;
|
|
if (mapImg) {
|
|
bg.globalAlpha = 0.55;
|
|
bg.drawImage(mapImg, 0, mapTop, W, mh);
|
|
bg.globalAlpha = 1;
|
|
for (let i = 0; i < 400; i++) landDots.push([r() * W, mapTop + r() * mh]);
|
|
} else {
|
|
// mapa de puntos
|
|
const step = clamp(Math.min(W / 130, mh / 50), 4, 12);
|
|
const rad = step * 0.28;
|
|
for (let y = mapTop + step / 2; y < mapBot; y += step) {
|
|
const lat = LAT_TOP - ((y - mapTop) / mh) * (LAT_TOP - LAT_BOT);
|
|
for (let x = step / 2; x < W; x += step) {
|
|
const lon = -180 + (x / W) * 360;
|
|
if (isLand(lon, lat)) {
|
|
landDots.push([x, y]);
|
|
bg.fillStyle = "rgba(70,140,255,0.38)";
|
|
bg.beginPath(); bg.arc(x, y, rad, 0, Math.PI * 2); bg.fill();
|
|
} else if (((x / step) | 0) % 6 === 0 && ((y / step) | 0) % 6 === 0) {
|
|
bg.fillStyle = "rgba(70,140,255,0.07)";
|
|
bg.fillRect(x - 0.5, y - 0.5, 1, 1);
|
|
}
|
|
}
|
|
}
|
|
if (!landDots.length) landDots.push([W / 2, mapTop]);
|
|
}
|
|
|
|
// suelo / horizonte
|
|
const gr = bg.createLinearGradient(0, groundY, 0, H);
|
|
gr.addColorStop(0, "#1a0f2e"); gr.addColorStop(1, "#07040c");
|
|
bg.fillStyle = gr;
|
|
bg.beginPath();
|
|
bg.moveTo(0, H);
|
|
for (let x = 0; x <= W; x += 8) bg.lineTo(x, groundY + Math.sin(x * 0.03) * 3 + Math.sin(x * 0.011) * 4);
|
|
bg.lineTo(W, H); bg.closePath(); bg.fill();
|
|
bg.strokeStyle = "rgba(255,77,106,.55)"; bg.lineWidth = 1.5;
|
|
bg.beginPath();
|
|
for (let x = 0; x <= W; x += 8) bg.lineTo(x, groundY + Math.sin(x * 0.03) * 3 + Math.sin(x * 0.011) * 4);
|
|
bg.stroke();
|
|
}
|
|
|
|
function mulberry(a) {
|
|
return () => { a |= 0; a = (a + 0x6d2b79f5) | 0; let t = Math.imul(a ^ (a >>> 15), 1 | a);
|
|
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t; return ((t ^ (t >>> 14)) >>> 0) / 4294967296; };
|
|
}
|
|
|
|
/* =========================================================================
|
|
* SERVIDOR: un único equipo rack detallado
|
|
* Panel superior: encendido, LEDs de estado, pantalla LCD y logotipo.
|
|
* Centro: bahías de discos con LED de actividad y de fallo.
|
|
* Abajo: ventiladores (giran según la carga), puertos de red y USB.
|
|
* ========================================================================= */
|
|
const C_BLUE = [77, 170, 255], C_GREEN = [77, 255, 136], C_AMBER = [255, 176, 46], C_RED = [255, 60, 90];
|
|
|
|
function buildServer() {
|
|
const { W, H, groundY } = stage;
|
|
let h = clamp(H * 0.32, 110, 300);
|
|
const w = Math.min(W - 24, clamp(Math.max(h * 2.5, W * 0.5), 260, 860));
|
|
h = Math.min(h, w / 1.75);
|
|
const x = (W - w) / 2, y = groundY - h;
|
|
const ear = clamp(w * 0.03, 8, 20);
|
|
const cx = x + ear, cw = w - ear * 2;
|
|
const th = h * 0.26, bh = h * 0.46, fh = h - th - bh;
|
|
const pad = Math.max(3, h * 0.025);
|
|
const S = {
|
|
x, y, w, h, ear, cx, cw, th, bh, fh, pad,
|
|
flash: 0, load: 0, fanA: 0, hot: [], recent: [],
|
|
led: { pwr: 1, net: 0, hdd: 0, err: 0 }, bays: [], ports: [], usb: [], fans: [],
|
|
};
|
|
|
|
// panel superior
|
|
const midY = y + th / 2;
|
|
S.power = { x: cx + pad * 2 + th * 0.24, y: midY, r: th * 0.2 };
|
|
const ls = clamp(th * 0.42, 13, 30);
|
|
S.ledR = clamp(th * 0.065, 1.8, 4);
|
|
S.leds = ["pwr", "net", "hdd", "err"].map((k, i) => ({ k, x: S.power.x + th * 0.42 + ls * (i + 0.5), y: midY - th * 0.1 }));
|
|
S.ledLabelY = midY + th * 0.24;
|
|
const logoW = clamp(cw * 0.16, 54, 150);
|
|
const lcdX = S.leds[3].x + ls * 0.5 + pad * 2;
|
|
S.lcd = { x: lcdX, y: y + th * 0.15, w: Math.max(0, cx + cw - logoW - pad * 4 - lcdX), h: th * 0.7 };
|
|
S.logo = { x: cx + cw - pad * 2, y: midY, size: clamp(Math.min(th * 0.24, logoW / 5.4), 7, 18) };
|
|
|
|
// bahías de discos
|
|
const rows = h >= 160 ? 2 : 1;
|
|
const cols = clamp(Math.round(cw / (rows === 2 ? 62 : 54)), 4, 14);
|
|
const bx0 = cx + pad, by0 = y + th + pad * 0.6;
|
|
const bw = (cw - pad * 2) / cols, bhh = (bh - pad * 1.2) / rows;
|
|
for (let r = 0; r < rows; r++)
|
|
for (let c = 0; c < cols; c++) {
|
|
const b = { x: bx0 + c * bw + 1.5, y: by0 + r * bhh + 1.5, w: bw - 3, h: bhh - 3, n: r * cols + c, act: 0, warn: 0, fault: 0 };
|
|
const lr = clamp(b.h * 0.045, 1.5, 3);
|
|
b.l1 = { x: b.x + b.w - lr * 3, y: b.y + b.h * 0.11 };
|
|
b.l2 = { x: b.x + b.w - lr * 7, y: b.y + b.h * 0.11 };
|
|
b.lr = lr;
|
|
S.bays.push(b);
|
|
}
|
|
Object.assign(S, { rows, cols, bx0, bw });
|
|
|
|
// parte inferior: ventiladores, red y USB
|
|
const fy = y + th + bh;
|
|
S.vent = { x: cx + pad, y: fy + pad, w: cw * 0.5, h: fh - pad * 2 };
|
|
const nf = clamp(Math.floor(S.vent.w / (fh * 1.05)), 1, 5);
|
|
const fr = Math.min(S.vent.h * 0.46, (S.vent.w / nf) * 0.44);
|
|
for (let i = 0; i < nf; i++) S.fans.push({ x: S.vent.x + (S.vent.w * (i + 0.5)) / nf, y: S.vent.y + S.vent.h / 2, r: fr });
|
|
const pw = clamp(fh * 0.4, 10, 28), ph = pw * 0.82, gap = pw * 0.35;
|
|
let px = S.vent.x + S.vent.w + pad * 3;
|
|
const py = fy + (fh - ph) / 2 - fh * 0.06;
|
|
const right = cx + cw - pad * 2;
|
|
for (let i = 0; i < 4 && px + pw <= right; i++, px += pw + gap) S.ports.push({ x: px, y: py, w: pw, h: ph, act: 0 });
|
|
px += gap;
|
|
const uw = pw * 0.75, uh = pw * 0.32;
|
|
for (let i = 0; i < 2 && px + uw <= right; i++) S.usb.push({ x: px, y: fy + fh / 2 - uh / 2 + (i - 0.5) * uh * 1.8, w: uw, h: uh });
|
|
srv = S;
|
|
}
|
|
|
|
/* Partes que no cambian: se dibujan una vez en un canvas aparte */
|
|
function renderServerStatic() {
|
|
const S = srv, dpr = stage.dpr, m = 4;
|
|
const c = srvStatic || (srvStatic = document.createElement("canvas"));
|
|
c.width = Math.ceil((S.w + m * 2) * dpr); c.height = Math.ceil((S.h + m * 2) * dpr);
|
|
const o = c.getContext("2d");
|
|
o.setTransform(dpr, 0, 0, dpr, (m - S.x) * dpr, (m - S.y) * dpr);
|
|
o.clearRect(S.x - m, S.y - m, S.w + m * 2, S.h + m * 2);
|
|
S.sm = m;
|
|
if (serverImg) { o.drawImage(serverImg, S.x, S.y, S.w, S.h); return; }
|
|
const { x, y, w, h, ear, cx, cw, th, bh, fh } = S;
|
|
|
|
// orejas del rack con tornillos
|
|
for (const ex of [x, x + w - ear]) {
|
|
rr(o, ex, y + 1, ear, h - 2, 2);
|
|
o.fillStyle = "#151c2e"; o.fill();
|
|
o.strokeStyle = "#2c3a5c"; o.lineWidth = 1; o.stroke();
|
|
for (const sy of [y + h * 0.14, y + h * 0.86]) {
|
|
const r = ear * 0.24;
|
|
o.fillStyle = "#0a0e18"; o.beginPath(); o.arc(ex + ear / 2, sy, r, 0, Math.PI * 2); o.fill();
|
|
o.strokeStyle = "#45578a"; o.stroke();
|
|
o.beginPath(); o.moveTo(ex + ear / 2 - r * 0.6, sy); o.lineTo(ex + ear / 2 + r * 0.6, sy); o.stroke();
|
|
}
|
|
}
|
|
|
|
// chasis
|
|
const body = o.createLinearGradient(0, y, 0, y + h);
|
|
body.addColorStop(0, "#232d48"); body.addColorStop(0.5, "#141b2e"); body.addColorStop(1, "#0d1222");
|
|
rr(o, cx, y, cw, h, 3);
|
|
o.fillStyle = body; o.fill();
|
|
o.strokeStyle = "rgba(120,170,255,.5)"; o.lineWidth = 1.2; o.stroke();
|
|
o.fillStyle = "rgba(255,255,255,.12)"; o.fillRect(cx + 3, y + 1, cw - 6, 1);
|
|
for (const yy of [y + th, y + th + bh]) {
|
|
o.fillStyle = "#060912"; o.fillRect(cx + 1, yy - 1, cw - 2, 2);
|
|
o.fillStyle = "rgba(255,255,255,.05)"; o.fillRect(cx + 1, yy + 1, cw - 2, 1);
|
|
}
|
|
// acabado cepillado del panel superior
|
|
o.fillStyle = "rgba(255,255,255,.022)";
|
|
for (let yy = y + 3; yy < y + th - 2; yy += 2) o.fillRect(cx + 2, yy, cw - 4, 1);
|
|
|
|
// botón de encendido
|
|
const P = S.power;
|
|
o.fillStyle = "#0a0e18"; o.beginPath(); o.arc(P.x, P.y, P.r * 1.25, 0, Math.PI * 2); o.fill();
|
|
o.strokeStyle = "#3a4a74"; o.lineWidth = 1.5; o.stroke();
|
|
|
|
// zócalos y etiquetas de los LEDs de estado
|
|
const lf = clamp(th * 0.15, 6, 10);
|
|
o.font = `${lf}px ${MONO}`; o.textAlign = "center"; o.textBaseline = "middle";
|
|
for (const L of S.leds) {
|
|
o.fillStyle = "#05070d"; o.beginPath(); o.arc(L.x, L.y, S.ledR + 1.2, 0, Math.PI * 2); o.fill();
|
|
o.fillStyle = "#6c7a99"; o.fillText(L.k.toUpperCase(), L.x, S.ledLabelY);
|
|
}
|
|
|
|
// marco de la pantalla LCD
|
|
const L = S.lcd;
|
|
if (L.w > 40) {
|
|
rr(o, L.x - 3, L.y - 3, L.w + 6, L.h + 6, 3); o.fillStyle = "#05070d"; o.fill();
|
|
rr(o, L.x, L.y, L.w, L.h, 2); o.fillStyle = "#021309"; o.fill();
|
|
o.strokeStyle = "rgba(77,255,136,.28)"; o.lineWidth = 1; o.stroke();
|
|
}
|
|
|
|
// logotipo
|
|
o.textAlign = "right";
|
|
o.font = `700 ${S.logo.size}px ${MONO}`; o.fillStyle = "#cfdbf7";
|
|
o.fillText("REALCONN", S.logo.x, S.logo.y - S.logo.size * 0.3);
|
|
o.font = `${Math.max(6, S.logo.size * 0.55)}px ${MONO}`; o.fillStyle = "#6c7a99";
|
|
o.fillText(`RC-9000 · ${S.bays.length} BAYS`, S.logo.x, S.logo.y + S.logo.size * 0.55);
|
|
|
|
// bahías de discos
|
|
const nf = clamp(S.bays[0].h * 0.13, 6, 10);
|
|
for (const b of S.bays) {
|
|
rr(o, b.x, b.y, b.w, b.h, 2);
|
|
const cg = o.createLinearGradient(0, b.y, 0, b.y + b.h);
|
|
cg.addColorStop(0, "#1a2340"); cg.addColorStop(1, "#0e1426");
|
|
o.fillStyle = cg; o.fill();
|
|
o.strokeStyle = "#2c3b60"; o.lineWidth = 1; o.stroke();
|
|
// número y zócalos de LED
|
|
o.textAlign = "left"; o.font = `${nf}px ${MONO}`; o.fillStyle = "#56658a";
|
|
if (b.w > 30) o.fillText(String(b.n).padStart(2, "0"), b.x + 3, b.l1.y);
|
|
for (const l of [b.l1, b.l2]) { o.fillStyle = "#05070d"; o.beginPath(); o.arc(l.x, l.y, b.lr + 1, 0, Math.PI * 2); o.fill(); }
|
|
// rejilla de ventilación
|
|
const gx = b.x + b.w * 0.1, gw = b.w * 0.8, gy0 = b.y + b.h * 0.24, gy1 = b.y + b.h * 0.6;
|
|
const st = Math.max(3, b.h * 0.07);
|
|
o.fillStyle = "#060912";
|
|
for (let yy = gy0; yy < gy1; yy += st) o.fillRect(gx, yy, gw, Math.max(1, st * 0.45));
|
|
// asa
|
|
rr(o, b.x + b.w * 0.08, b.y + b.h * 0.66, b.w * 0.84, b.h * 0.24, 2);
|
|
o.fillStyle = "#222e4d"; o.fill(); o.strokeStyle = "#3f5284"; o.stroke();
|
|
o.fillStyle = "#0a0f1c"; o.fillRect(b.x + b.w * 0.2, b.y + b.h * 0.76, b.w * 0.6, Math.max(1, b.h * 0.04));
|
|
}
|
|
|
|
// zona de ventilación
|
|
const V = S.vent;
|
|
rr(o, V.x, V.y, V.w, V.h, 2); o.fillStyle = "#05070d"; o.fill();
|
|
o.strokeStyle = "#26324f"; o.stroke();
|
|
|
|
// puertos RJ45
|
|
o.textAlign = "center"; o.font = `${clamp(fh * 0.13, 6, 9)}px ${MONO}`;
|
|
S.ports.forEach((p, i) => {
|
|
o.fillStyle = "#04060b"; o.fillRect(p.x, p.y, p.w, p.h);
|
|
o.strokeStyle = "#4a5c8c"; o.lineWidth = 1; o.strokeRect(p.x + 0.5, p.y + 0.5, p.w - 1, p.h - 1);
|
|
o.fillStyle = "#0c111e"; o.fillRect(p.x + p.w * 0.3, p.y + p.h * 0.72, p.w * 0.4, p.h * 0.28); // muesca
|
|
o.fillStyle = "#b89a45";
|
|
for (let k = 0; k < 8; k++) o.fillRect(p.x + p.w * 0.14 + k * (p.w * 0.72 / 8), p.y + p.h * 0.32, Math.max(0.6, p.w * 0.04), p.h * 0.2);
|
|
o.fillStyle = "#56658a"; o.fillText("ETH" + i, p.x + p.w / 2, p.y + p.h + clamp(fh * 0.13, 6, 9));
|
|
});
|
|
// USB
|
|
for (const u of S.usb) {
|
|
o.fillStyle = "#04060b"; o.fillRect(u.x, u.y, u.w, u.h);
|
|
o.strokeStyle = "#4a5c8c"; o.strokeRect(u.x + 0.5, u.y + 0.5, u.w - 1, u.h - 1);
|
|
o.fillStyle = "#2b62c9"; o.fillRect(u.x + u.w * 0.12, u.y + u.h * 0.25, u.w * 0.76, u.h * 0.3);
|
|
}
|
|
}
|
|
|
|
function led(x, y, r, c, a) {
|
|
if (a > 0.05) {
|
|
g.fillStyle = rgb(c, 0.2 * a);
|
|
g.beginPath(); g.arc(x, y, r * 3.2, 0, Math.PI * 2); g.fill();
|
|
}
|
|
g.fillStyle = a > 0.05 ? rgb([c[0] + (255 - c[0]) * a * 0.4, c[1] + (255 - c[1]) * a * 0.4, c[2] + (255 - c[2]) * a * 0.4].map(Math.round), 0.35 + 0.65 * a) : rgb(c, 0.12);
|
|
g.beginPath(); g.arc(x, y, r, 0, Math.PI * 2); g.fill();
|
|
}
|
|
|
|
function drawServer(t, dt) {
|
|
const S = srv;
|
|
const dec = (v, k) => Math.max(0, v - dt * k);
|
|
S.load *= Math.exp(-dt / 3);
|
|
S.flash = dec(S.flash, 2.5);
|
|
S.fanA += dt * (3 + Math.min(S.load, 40) * 0.7);
|
|
S.led.net = dec(S.led.net, 3); S.led.hdd = dec(S.led.hdd, 4); S.led.err = dec(S.led.err, 0.5);
|
|
const blink = (rate) => ((t * rate) | 0) % 2 ? 1 : 0.25;
|
|
|
|
g.drawImage(srvStatic, S.x - S.sm, S.y - S.sm, srvStatic.width / stage.dpr, srvStatic.height / stage.dpr);
|
|
|
|
if (!serverImg) {
|
|
// ventiladores tras la rejilla
|
|
for (const f of S.fans) {
|
|
g.save();
|
|
g.beginPath(); g.arc(f.x, f.y, f.r, 0, Math.PI * 2);
|
|
g.fillStyle = "#03050a"; g.fill(); g.clip();
|
|
g.translate(f.x, f.y); g.rotate(S.fanA + f.x * 0.1);
|
|
g.fillStyle = "#26324f";
|
|
for (let k = 0; k < 7; k++) {
|
|
g.rotate((Math.PI * 2) / 7);
|
|
g.beginPath(); g.ellipse(f.r * 0.5, 0, f.r * 0.44, f.r * 0.17, 0.55, 0, Math.PI * 2); g.fill();
|
|
}
|
|
g.fillStyle = "#364468"; g.beginPath(); g.arc(0, 0, f.r * 0.22, 0, Math.PI * 2); g.fill();
|
|
g.restore();
|
|
g.strokeStyle = "rgba(130,160,210,.38)"; g.lineWidth = 1;
|
|
for (const k of [0.98, 0.72, 0.46]) { g.beginPath(); g.arc(f.x, f.y, f.r * k, 0, Math.PI * 2); g.stroke(); }
|
|
g.beginPath(); g.moveTo(f.x - f.r, f.y); g.lineTo(f.x + f.r, f.y); g.moveTo(f.x, f.y - f.r); g.lineTo(f.x, f.y + f.r); g.stroke();
|
|
}
|
|
|
|
// botón de encendido
|
|
const P = S.power;
|
|
g.strokeStyle = rgb(C_BLUE, 0.7 + 0.3 * Math.sin(t * 2)); g.lineWidth = Math.max(1.5, P.r * 0.2); g.lineCap = "round";
|
|
g.beginPath(); g.arc(P.x, P.y, P.r * 0.7, -Math.PI / 2 + 0.7, Math.PI * 1.5 - 0.7); g.stroke();
|
|
g.beginPath(); g.moveTo(P.x, P.y - P.r * 0.9); g.lineTo(P.x, P.y - P.r * 0.2); g.stroke();
|
|
g.strokeStyle = rgb(C_BLUE, 0.25); g.lineWidth = 2;
|
|
g.beginPath(); g.arc(P.x, P.y, P.r * 1.25, 0, Math.PI * 2); g.stroke();
|
|
|
|
// LEDs de estado
|
|
const st = {
|
|
pwr: [C_BLUE, 1],
|
|
net: [C_GREEN, S.led.net > 0.02 ? blink(22) : 0.35],
|
|
hdd: [C_AMBER, S.led.hdd > 0.02 ? blink(30) : 0],
|
|
err: [C_RED, S.led.err > 0.02 ? blink(4) : 0],
|
|
};
|
|
for (const L of S.leds) led(L.x, L.y, S.ledR, st[L.k][0], st[L.k][1]);
|
|
|
|
// actividad de fondo de los discos
|
|
if (Math.random() < dt * (1.5 + S.load * 2)) {
|
|
const b = S.bays[(Math.random() * S.bays.length) | 0];
|
|
b.act = Math.max(b.act, 0.5);
|
|
}
|
|
for (const b of S.bays) {
|
|
b.act = dec(b.act, 3); b.warn = dec(b.warn, 0.8); b.fault = dec(b.fault, 0.35);
|
|
if (b.act > 0.05) { g.fillStyle = rgb(C_GREEN, 0.07 * b.act); g.fillRect(b.x, b.y, b.w, b.h); }
|
|
led(b.l1.x, b.l1.y, b.lr, C_GREEN, b.act > 0.05 ? blink(26) * b.act : 0.3);
|
|
if (b.fault > 0.02) led(b.l2.x, b.l2.y, b.lr, C_RED, blink(3));
|
|
else if (b.warn > 0.02) led(b.l2.x, b.l2.y, b.lr, C_AMBER, b.warn);
|
|
else led(b.l2.x, b.l2.y, b.lr, C_BLUE, 0);
|
|
}
|
|
|
|
// LEDs de los puertos de red: enlace (verde) y actividad (ámbar)
|
|
for (const p of S.ports) {
|
|
p.act = dec(p.act, 2.5);
|
|
const r = clamp(p.w * 0.07, 1.2, 2.2);
|
|
led(p.x + r * 2, p.y + r * 2, r, C_GREEN, 0.9);
|
|
led(p.x + p.w - r * 2, p.y + r * 2, r, C_AMBER, p.act > 0.02 ? blink(28) : 0);
|
|
}
|
|
|
|
// pantalla LCD: carga y últimas conexiones
|
|
const L = S.lcd;
|
|
if (L.w > 40) {
|
|
g.save();
|
|
g.beginPath(); g.rect(L.x, L.y, L.w, L.h); g.clip();
|
|
g.fillStyle = "rgba(77,255,136,0.05)"; g.fillRect(L.x, L.y, L.w, L.h);
|
|
const fs = clamp(L.h / 4.3, 7, 12), lh = fs * 1.22;
|
|
g.font = `${fs}px ${MONO}`; g.textAlign = "left"; g.textBaseline = "top";
|
|
const lines = Math.max(1, Math.floor((L.h - 4) / lh));
|
|
g.fillStyle = "#9dffc4";
|
|
g.fillText(`${(S.load / 3).toFixed(1)} conn/s · ${stats.hits.toLocaleString("es")} recibidas`, L.x + 4, L.y + 3);
|
|
if (!S.recent.length) {
|
|
g.fillStyle = "rgba(125,255,176,.6)";
|
|
if (lines > 1) g.fillText("esperando conexiones" + ((t * 2 | 0) % 2 ? "_" : ""), L.x + 4, L.y + 3 + lh);
|
|
}
|
|
for (let i = 0; i < lines - 1 && i < S.recent.length; i++) {
|
|
const e = S.recent[i];
|
|
g.fillStyle = rgb(e.color, Math.max(0.35, 1 - i * 0.18));
|
|
g.fillText(e.text, L.x + 4, L.y + 3 + lh * (i + 1));
|
|
}
|
|
g.fillStyle = "rgba(0,0,0,.28)";
|
|
for (let yy = L.y; yy < L.y + L.h; yy += 2) g.fillRect(L.x, yy, L.w, 1);
|
|
g.restore();
|
|
g.textBaseline = "alphabetic";
|
|
}
|
|
}
|
|
|
|
// puntos calientes en la cubierta donde impactan los misiles
|
|
for (let i = S.hot.length - 1; i >= 0; i--) {
|
|
const hs = S.hot[i];
|
|
hs.life -= dt * 1.2;
|
|
if (hs.life <= 0) { S.hot.splice(i, 1); continue; }
|
|
const r = 10 + 26 * hs.life;
|
|
const gr = g.createRadialGradient(hs.x, S.y, 0, hs.x, S.y, r);
|
|
gr.addColorStop(0, rgb([255, 240, 200], 0.55 * hs.life));
|
|
gr.addColorStop(0.4, rgb(hs.color, 0.35 * hs.life));
|
|
gr.addColorStop(1, rgb(hs.color, 0));
|
|
g.fillStyle = gr; g.fillRect(hs.x - r, S.y - r, r * 2, r * 2);
|
|
}
|
|
if (S.flash > 0) { g.fillStyle = `rgba(200,220,255,${S.flash * 0.07})`; g.fillRect(S.cx, S.y, S.cw, S.h); }
|
|
}
|
|
|
|
function serverHit(m) {
|
|
const S = srv;
|
|
S.load += 1;
|
|
S.flash = Math.min(1, S.flash + 0.3);
|
|
S.led.net = 1; S.led.hdd = 1;
|
|
if (m.status >= 500) S.led.err = 1;
|
|
const col = clamp(Math.floor((m.tx - S.bx0) / S.bw), 0, S.cols - 1);
|
|
const b = S.bays[((m.hash >>> 3) % S.rows) * S.cols + col];
|
|
b.act = 1;
|
|
if (m.status >= 500) b.fault = 1; else if (m.status >= 400) b.warn = 1;
|
|
if (S.ports.length) S.ports[(m.hash >>> 5) % S.ports.length].act = 1;
|
|
S.hot.push({ x: m.tx, life: 1, color: m.color });
|
|
if (S.hot.length > 40) S.hot.shift();
|
|
S.recent.unshift({ text: `${m.ip} ${m.status || "---"} ${m.uaText}`, color: m.color });
|
|
if (S.recent.length > 10) S.recent.length = 10;
|
|
}
|
|
|
|
/* =========================================================================
|
|
* MISILES
|
|
* ========================================================================= */
|
|
function launch(c) {
|
|
const h = hashStr(c.ip || "?");
|
|
const [sx, sy] = landDots[h % landDots.length];
|
|
// punto de impacto sobre la cubierta del servidor (fracción del ancho, estable por IP)
|
|
const u = 0.04 + (((h >>> 8) % 1000) / 1000) * 0.92;
|
|
// con mucha cola caen más rápido
|
|
const press = clamp(queue.length / 400, 0, 1);
|
|
const dur = rand(CONFIG.MISSILE_TIME_S[0], CONFIG.MISSILE_TIME_S[1]) * (1 - press * 0.55);
|
|
missiles.push({
|
|
ip: c.ip || "?", status: c.status | 0, color: statusColor(c.status | 0), hash: h,
|
|
uaText: describeUA(c.ua), method: c.method || "", path: c.path || "",
|
|
sx, sy: sy + rand(-3, 3), u, tx: 0, ty: 0,
|
|
t: 0, dur, done: false, fade: 1,
|
|
});
|
|
}
|
|
|
|
function impact(m, now) {
|
|
serverHit(m);
|
|
stats.hits++;
|
|
const big = m.status >= 500 ? 1.4 : m.status >= 400 ? 1.15 : 1;
|
|
const count = Math.round((missiles.length > 150 ? 50 : 110) * big);
|
|
if (Particles) Particles.burst(m.tx, m.ty, m.color, count, 230 * big, now);
|
|
else CpuParticles.burst(m.tx, m.ty, m.color, count, 230 * big);
|
|
rings.push({ x: m.tx, y: m.ty, r: 0, max: 26 * big + Math.random() * 10, life: 1, color: m.color });
|
|
shake = Math.min(6, shake + 1.2 * big);
|
|
}
|
|
|
|
/* =========================================================================
|
|
* BUCLE DE ANIMACIÓN
|
|
* ========================================================================= */
|
|
let last = performance.now();
|
|
let spawnAcc = 0;
|
|
|
|
function frame(nowMs) {
|
|
const now = nowMs / 1000;
|
|
const dt = Math.min(0.05, (nowMs - last) / 1000);
|
|
last = nowMs;
|
|
const { W, H } = stage;
|
|
|
|
// lanzar conexiones de la cola de forma repartida en el intervalo de sondeo
|
|
const rate = queue.length / Math.max(0.25, CONFIG.POLL_INTERVAL_MS / 1000) + 1;
|
|
spawnAcc += rate * dt;
|
|
while (spawnAcc >= 1 && queue.length && missiles.length < CONFIG.MAX_ACTIVE_MISSILES) {
|
|
launch(queue.shift()); spawnAcc -= 1;
|
|
}
|
|
if (!queue.length) spawnAcc = Math.min(spawnAcc, 1);
|
|
|
|
shake *= 0.88;
|
|
const sx = (Math.random() - 0.5) * shake, sy = (Math.random() - 0.5) * shake;
|
|
|
|
g.setTransform(stage.dpr, 0, 0, stage.dpr, sx * stage.dpr, sy * stage.dpr);
|
|
g.clearRect(-10, -10, W + 20, H + 20);
|
|
|
|
drawServer(now, dt);
|
|
|
|
// misiles
|
|
const labels = CONFIG.SHOW_LABELS && missiles.length < 220;
|
|
const tags = [];
|
|
g.lineCap = "round";
|
|
for (let i = missiles.length - 1; i >= 0; i--) {
|
|
const m = missiles[i];
|
|
m.tx = srv.cx + srv.cw * m.u; m.ty = srv.y;
|
|
if (!m.done) {
|
|
m.t += dt / m.dur;
|
|
if (m.t >= 1) { m.t = 1; m.done = true; impact(m, now); }
|
|
} else {
|
|
m.fade -= dt * 1.6;
|
|
if (m.fade <= 0) { missiles.splice(i, 1); continue; }
|
|
}
|
|
const k = m.t * m.t * (1.4 - 0.4 * m.t); // ligera aceleración
|
|
const hx = m.sx + (m.tx - m.sx) * k, hy = m.sy + (m.ty - m.sy) * k;
|
|
|
|
// estela
|
|
const grad = g.createLinearGradient(m.sx, m.sy, hx, hy);
|
|
grad.addColorStop(0, rgb(m.color, 0));
|
|
grad.addColorStop(1, rgb(m.color, 0.9 * m.fade));
|
|
g.strokeStyle = grad;
|
|
g.lineWidth = 1.6;
|
|
g.beginPath(); g.moveTo(m.sx, m.sy); g.lineTo(hx, hy); g.stroke();
|
|
|
|
if (!m.done) {
|
|
// cabeza
|
|
g.fillStyle = rgb(m.color, 0.25);
|
|
g.beginPath(); g.arc(hx, hy, 5, 0, Math.PI * 2); g.fill();
|
|
g.fillStyle = "#fff";
|
|
g.fillRect(hx - 1.5, hy - 1.5, 3, 3);
|
|
if (labels) tags.push([m, hx, hy]);
|
|
}
|
|
}
|
|
|
|
// bajo cada misil: IP y, debajo, navegador · sistema operativo
|
|
if (tags.length) {
|
|
const fIP = clamp(W / 110, 9, 12), fUA = Math.max(8, fIP - 2);
|
|
g.textAlign = "center";
|
|
g.font = `${fIP}px ${MONO}`;
|
|
for (const [m, x, y] of tags) {
|
|
g.fillStyle = rgb(m.color, 0.95);
|
|
g.fillText(m.ip, x, y + 16);
|
|
}
|
|
if (CONFIG.SHOW_UA) {
|
|
g.font = `${fUA}px ${MONO}`;
|
|
g.fillStyle = "rgba(205,218,245,.72)";
|
|
for (const [m, x, y] of tags) g.fillText(m.uaText, x, y + 16 + fUA + 3);
|
|
}
|
|
}
|
|
|
|
// ondas expansivas estilo arcade
|
|
for (let i = rings.length - 1; i >= 0; i--) {
|
|
const r = rings[i];
|
|
r.life -= dt * 1.8;
|
|
if (r.life <= 0) { rings.splice(i, 1); continue; }
|
|
r.r = r.max * (1 - r.life * r.life);
|
|
const flick = (now * 20 | 0) % 2 ? "#ffffff" : rgb(r.color);
|
|
g.globalAlpha = r.life;
|
|
g.fillStyle = rgb(r.color, 0.18);
|
|
g.beginPath(); g.arc(r.x, r.y, r.r, 0, Math.PI * 2); g.fill();
|
|
g.strokeStyle = flick; g.lineWidth = 2;
|
|
g.stroke();
|
|
g.globalAlpha = 1;
|
|
}
|
|
|
|
if (CpuParticles) CpuParticles.update(dt, g);
|
|
if (Particles) Particles.draw(now, sx, sy);
|
|
|
|
// marcador animado
|
|
if (stats.shownScore < stats.score) {
|
|
stats.shownScore = Math.min(stats.score, stats.shownScore + Math.max(1, Math.ceil((stats.score - stats.shownScore) * 0.12)));
|
|
$("score").textContent = stats.shownScore.toLocaleString("es");
|
|
}
|
|
$("flying").textContent = missiles.filter((m) => !m.done).length + (queue.length ? ` (+${queue.length})` : "");
|
|
$("hits").textContent = stats.hits.toLocaleString("es");
|
|
|
|
requestAnimationFrame(frame);
|
|
}
|
|
|
|
/* =========================================================================
|
|
* API
|
|
* ========================================================================= */
|
|
function setStatus(kind, text) {
|
|
$("status").className = "item " + kind;
|
|
$("statusText").textContent = text;
|
|
}
|
|
|
|
function receive(list, dropped) {
|
|
stats.score += list.length;
|
|
stats.dropped += dropped;
|
|
const cyc = $("cycle");
|
|
cyc.textContent = "+" + list.length;
|
|
cyc.classList.remove("bump"); void cyc.offsetWidth; cyc.classList.add("bump");
|
|
$("dropped").textContent = stats.dropped.toLocaleString("es");
|
|
for (const c of list) queue.push(c);
|
|
if (queue.length > CONFIG.MAX_QUEUE) {
|
|
const extra = queue.length - CONFIG.MAX_QUEUE;
|
|
queue.splice(0, extra); // se cuentan en el score pero no se dibujan
|
|
stats.dropped += extra;
|
|
$("dropped").textContent = stats.dropped.toLocaleString("es");
|
|
}
|
|
}
|
|
|
|
/* Cada pestaña tiene su propio ID y su propia posición (cursor) en la API,
|
|
* así varios navegadores ven todas las conexiones sin robárselas. */
|
|
const CLIENT_ID = (crypto.randomUUID ? crypto.randomUUID()
|
|
: Date.now().toString(36) + Math.random().toString(36).slice(2)).slice(0, 64);
|
|
let cursor = null; // null = empezar en vivo
|
|
|
|
function apiURL() {
|
|
const u = new URL(CONFIG.API_URL, location.href);
|
|
u.searchParams.set("client", CLIENT_ID);
|
|
if (cursor !== null) u.searchParams.set("since", String(cursor));
|
|
return u.toString();
|
|
}
|
|
|
|
async function poll() {
|
|
if (CONFIG.DEMO) {
|
|
receive(fakeConnections(), 0);
|
|
setStatus("demo", "demo");
|
|
} else {
|
|
const ctl = new AbortController();
|
|
const to = setTimeout(() => ctl.abort(), Math.max(5000, CONFIG.POLL_INTERVAL_MS * 2));
|
|
try {
|
|
const res = await fetch(apiURL(), { cache: "no-store", signal: ctl.signal });
|
|
if (!res.ok) throw new Error("HTTP " + res.status);
|
|
const j = await res.json();
|
|
if (typeof j.next === "number") cursor = j.next;
|
|
receive(Array.isArray(j.connections) ? j.connections : [], j.dropped | 0);
|
|
setStatus("on", j.pending ? `en línea · ${j.pending} pendientes` : "en línea");
|
|
} catch (e) {
|
|
setStatus("off", "sin conexión con la API");
|
|
} finally {
|
|
clearTimeout(to);
|
|
}
|
|
}
|
|
setTimeout(poll, CONFIG.POLL_INTERVAL_MS);
|
|
}
|
|
|
|
function fakeConnections() {
|
|
const n = Math.random() < 0.15 ? (Math.random() * 40) | 0 : (Math.random() * 8) | 0;
|
|
const st = [200, 200, 200, 200, 304, 301, 404, 403, 500, 502];
|
|
const uas = [
|
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36",
|
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0",
|
|
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.1 Safari/605.1.15",
|
|
"Mozilla/5.0 (iPhone; CPU iPhone OS 18_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.1 Mobile/15E148 Safari/604.1",
|
|
"Mozilla/5.0 (Linux; Android 14; SM-S918B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Mobile Safari/537.36",
|
|
"Mozilla/5.0 (Linux; Android 13; SM-A536B) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/26.0 Chrome/122.0.0.0 Mobile Safari/537.36",
|
|
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:132.0) Gecko/20100101 Firefox/132.0",
|
|
"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
|
|
"curl/8.5.0",
|
|
"python-requests/2.32.3",
|
|
];
|
|
return Array.from({ length: n }, () => ({
|
|
ua: uas[(Math.random() * uas.length) | 0],
|
|
ip: Math.random() < 0.85
|
|
? [1 + (Math.random() * 222) | 0, (Math.random() * 255) | 0, (Math.random() * 255) | 0, (Math.random() * 254 + 1) | 0].join(".")
|
|
: "2001:db8::" + ((Math.random() * 65535) | 0).toString(16),
|
|
status: st[(Math.random() * st.length) | 0],
|
|
}));
|
|
}
|
|
|
|
/* =========================================================================
|
|
* ARRANQUE
|
|
* ========================================================================= */
|
|
(async () => {
|
|
[mapImg, serverImg] = await Promise.all([loadImage(CONFIG.MAP_IMAGE_URL), loadImage(CONFIG.SERVER_IMAGE_URL)]);
|
|
layout();
|
|
let rt;
|
|
window.addEventListener("resize", () => { clearTimeout(rt); rt = setTimeout(layout, 120); });
|
|
requestAnimationFrame((t) => { last = t; frame(t); });
|
|
poll();
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|