feat(server)!: websocket lobby, server-run matches, server economy, new schema (P1-2, P1-4, P2-1, P2-1b, P2-5)
Replaces the Firebase-style /db facade (rtdb, rules, nodes tree) with explicit REST endpoints and a WebSocket hub. Login by name or optional e-mail, seed accounts via npm run db:reset. BREAKING CHANGE: old clients (lobby/netfight over /db) no longer work against this server; database is new.
This commit is contained in:
46
server/db/migrations/001_init.sql
Normal file
46
server/db/migrations/001_init.sql
Normal file
@@ -0,0 +1,46 @@
|
||||
-- Robot Clash schema v1. Online saves are one JSON document per player; the server changes their economy
|
||||
-- fields only through game/eco.js (same rules as the client), so a document stays consistent.
|
||||
CREATE TABLE users (
|
||||
uid TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL, -- display name
|
||||
uname TEXT UNIQUE, -- login name, lower case (NULL for guests)
|
||||
email TEXT UNIQUE, -- optional
|
||||
pass TEXT, -- bcrypt hash (NULL for guests)
|
||||
role TEXT NOT NULL DEFAULT 'player',-- player | admin
|
||||
guest INTEGER NOT NULL DEFAULT 0,
|
||||
created INTEGER NOT NULL,
|
||||
seen INTEGER NOT NULL
|
||||
);
|
||||
CREATE TABLE refresh_tokens (
|
||||
token TEXT PRIMARY KEY,
|
||||
uid TEXT NOT NULL REFERENCES users(uid) ON DELETE CASCADE,
|
||||
exp INTEGER NOT NULL
|
||||
);
|
||||
CREATE INDEX refresh_tokens_uid ON refresh_tokens(uid);
|
||||
CREATE TABLE online_saves (
|
||||
uid TEXT PRIMARY KEY REFERENCES users(uid) ON DELETE CASCADE,
|
||||
data TEXT NOT NULL,
|
||||
fame INTEGER NOT NULL DEFAULT 0, -- copy of data.fame for the ranking
|
||||
updated INTEGER NOT NULL
|
||||
);
|
||||
CREATE INDEX online_saves_fame ON online_saves(fame DESC);
|
||||
CREATE TABLE campaign_saves ( -- offline campaign mirrored for registered accounts (client-trusted)
|
||||
uid TEXT PRIMARY KEY REFERENCES users(uid) ON DELETE CASCADE,
|
||||
data TEXT NOT NULL,
|
||||
updated INTEGER NOT NULL
|
||||
);
|
||||
CREATE TABLE matches (
|
||||
id TEXT PRIMARY KEY,
|
||||
seed INTEGER NOT NULL,
|
||||
arena TEXT NOT NULL,
|
||||
uid0 TEXT NOT NULL,
|
||||
uid1 TEXT NOT NULL,
|
||||
winner INTEGER, -- seat 0 / 1, -1 draw, NULL running
|
||||
reason TEXT,
|
||||
started INTEGER NOT NULL,
|
||||
ended INTEGER
|
||||
);
|
||||
CREATE TABLE kv ( -- small settings, e.g. 'live' (admin live control)
|
||||
key TEXT PRIMARY KEY,
|
||||
value TEXT NOT NULL
|
||||
);
|
||||
Reference in New Issue
Block a user