Server authority

This commit is contained in:
2026-09-24 19:34:07 -03:00
parent 1bef94ce0c
commit 79faa556de
75 changed files with 2247 additions and 1632 deletions
+10 -6
View File
@@ -15,18 +15,22 @@ export class Connection {
id: string;
seed: string;
initial_changes: BlockChange[];
spawn: { x: number; y: number; z: number; yaw: number; pitch: number };
selected_slot: number;
players = new Map<string, RemotePlayer>();
// handled by the network system inside the game loop, not whenever the socket feels like it
incoming: ServerMessage[] = [];
closed = false;
constructor(socket: WebSocket, id: string, seed: string, players: PlayerInfo[], changes: BlockChange[]) {
constructor(socket: WebSocket, welcome: Extract<ServerMessage, { type: "welcome" }>) {
this.socket = socket;
this.id = id;
this.seed = seed;
this.initial_changes = changes;
for (const player of players) {
this.id = welcome.id;
this.seed = welcome.seed;
this.initial_changes = welcome.changes;
this.spawn = welcome.spawn;
this.selected_slot = welcome.selected_slot;
for (const player of welcome.players) {
this.add_player(player);
}
@@ -77,7 +81,7 @@ export class Connection {
const message: ServerMessage = JSON.parse(event.data);
if (message.type === "welcome") {
clearTimeout(timeout);
resolve(new Connection(socket, message.id, message.seed, message.players, message.changes));
resolve(new Connection(socket, message));
}
}, { once: true });