Improve networking

This commit is contained in:
2026-09-25 00:08:01 -03:00
parent 6458bc0440
commit 2a2ccae9ce
18 changed files with 600 additions and 162 deletions
+11 -1
View File
@@ -20,15 +20,25 @@ export interface ModData {
ores: OreJson[];
}
// a mod as the server lists it to clients, in load order. paths are relative to the site root
// a mod as the server lists it to clients, in load order. paths are relative to the server's root
export interface ModListing {
id: string;
name: string;
version: string;
// short hash of everything public, the folder it's served from
hash: string;
data: string;
client?: string;
worldgen?: string;
// sha-256 in hex of each file, clients check these before using them
sha256: { data: string; client?: string; worldgen?: string };
}
// the texture atlas with every mod's textures, built by the server
export interface AtlasListing {
png: string;
json: string;
sha256: { png: string; json: string };
}
export class RecipeBook {
+20 -5
View File
@@ -1,10 +1,14 @@
// messages sent between the client and the server, as json over a websocket
import type { Faces } from "./constants.ts";
import type { ItemData } from "./inventory.ts";
import type { ModListing } from "./mod_loader.ts";
import type { AtlasListing, ModListing } from "./mod_loader.ts";
export const AIR_ID = "bworld:air";
// bump when a client and server of different versions can't play together.
// the server rejects a different version before the client downloads anything
export const PROTOCOL_VERSION = 1;
export interface PlayerInfo {
id: string;
name: string;
@@ -44,7 +48,9 @@ export interface ScreenLayout {
// clients send what the player is trying to do, the server decides what happens
export type ClientMessage =
| { type: "hello"; name: string }
| { type: "hello"; name: string; protocol: number }
// sent once the client has downloaded, checked and loaded everything in welcome
| { type: "ready" }
| { type: "move"; x: number; y: number; z: number; yaw: number; pitch: number }
| { type: "break_block"; x: number; y: number; z: number }
// right click on a block: interact with it, or place the held block against `face`
@@ -56,14 +62,23 @@ export type ClientMessage =
| { type: "chat"; text: string };
export type ServerMessage =
// what to download before joining, see "Delivery to clients" in MODS.md
| {
type: "welcome";
protocol: number;
seed: string;
atlas: AtlasListing;
// in load order, the client loads them before joining the world
mods: ModListing[];
}
// the connection is closed right after
| { type: "rejected"; reason: string }
// answers ready, the player is in the world from here
| {
type: "join";
id: string;
// the server may change the name asked for, like alice to alice2
name: string;
seed: string;
// in load order, the client loads them before joining the world
mods: ModListing[];
players: PlayerInfo[];
changes: BlockChange[];
spawn: { x: number; y: number; z: number; yaw: number; pitch: number };