vice city online: the bare online core

This commit is contained in:
CRTkafa 2026-11-17 14:27:34 +07:00
commit 2f98475c19
256 changed files with 144219 additions and 0 deletions

22
server/bots.ts Normal file
View file

@ -0,0 +1,22 @@
// Test helper: connects N bots that walk in circles and prints what they see.
// Usage: VC_KEY=... bun server/bots.ts [url] [count]
const url = process.argv[2] ?? "ws://127.0.0.1:8791/ws";
const count = Number(process.argv[3] ?? 2);
const key = process.env.VC_KEY!;
const seen: Record<number, number> = {};
for (let i = 0; i < count; i++) {
const ws = new WebSocket(`${url}?key=${key}`);
let id = 0, t = 0;
ws.onmessage = (e) => {
const m = JSON.parse(String(e.data));
if (m.t === "welcome") {
id = m.id;
ws.send(JSON.stringify({ t: "hello", name: `bot${i}` }));
setInterval(() => {
t += 0.05;
ws.send(JSON.stringify({ t: "s", pos: [600 + Math.cos(t) * 5, -1257 + Math.sin(t) * 5, 7], vel: [0, 0, 0], heading: t, model: 0, anim: 1, hp: 100 }));
}, 50);
} else if (m.t === "snap") seen[id] = m.p.length;
};
}
setTimeout(() => { console.log("each bot sees others:", seen); process.exit(Object.values(seen).every((n) => n === count - 1) ? 0 : 1); }, 2500);