Improve networking
This commit is contained in:
@@ -5,6 +5,7 @@ import { block_from_json, block_to_json, item_from_json, item_to_json } from "$/
|
||||
import { generate_raw_chunk } from "$/common/generation.ts";
|
||||
import { load_worldgen } from "$/common/worldgen_loader.ts";
|
||||
import { create_mod } from "$/tools/new_mod.ts";
|
||||
import { PROTOCOL_VERSION } from "$/common/protocol.ts";
|
||||
import { copy_dir, test_game } from "./helpers.ts";
|
||||
|
||||
// mods/bworld plus a mod made from the template, in a temp folder
|
||||
@@ -59,9 +60,10 @@ Deno.test("a mod made from the template loads and runs", async () => {
|
||||
);
|
||||
|
||||
game.on_connect(1);
|
||||
send(1, { type: "hello", name: "alice" });
|
||||
send(1, { type: "hello", name: "alice", protocol: PROTOCOL_VERSION });
|
||||
const welcome = take(1)[0];
|
||||
assertEquals(welcome.mods.map((m: Msg) => m.id), ["bworld", "copper_tools"]);
|
||||
send(1, { type: "ready" });
|
||||
|
||||
// the command, by name and by namespaced name
|
||||
send(1, { type: "chat", text: "/hello" });
|
||||
@@ -180,9 +182,8 @@ export function setup(ctx: ServerContext) {
|
||||
}
|
||||
`,
|
||||
);
|
||||
let { game, send, take } = await test_game(dir);
|
||||
game.on_connect(1);
|
||||
send(1, { type: "hello", name: "bob" });
|
||||
let { game, send, take, join } = await test_game(dir);
|
||||
join(1, "bob");
|
||||
for (let i = 0; i < 5; i++) game.tick();
|
||||
game.set_block(0, 100, 0, "copper_tools:example_block");
|
||||
send(1, { type: "move", x: 0.5, y: 100, z: 1.5, yaw: 0, pitch: 0 });
|
||||
@@ -190,9 +191,8 @@ export function setup(ctx: ServerContext) {
|
||||
assert(take(1).some((m) => m.text === "clicks 1, placed at 5"));
|
||||
|
||||
const saved = game.save();
|
||||
({ game, send, take } = await test_game(dir, saved));
|
||||
game.on_connect(1);
|
||||
send(1, { type: "hello", name: "bob" });
|
||||
({ game, send, take, join } = await test_game(dir, saved));
|
||||
join(1, "bob");
|
||||
send(1, { type: "use_block", x: 0, y: 100, z: 0, face: "top" });
|
||||
assert(take(1).some((m) => m.text === "clicks 2, placed at 5"));
|
||||
Deno.removeSync(dir, { recursive: true });
|
||||
|
||||
Reference in New Issue
Block a user