feat(rust): Dynamic PVP's zones on the feed and the map (PLAN_REDESIGNS §14.3.3)
Stage 4 of the §14.3 integration plan, on protocol 14 (docs rust-link/PROTOCOL.md §20.7). - pvp.zone.created is a public kind, pvp.zone.deleted a staff kind. Each row is read per viewer by the new dynamicPvp.js: grid for everyone, the event's name only for Dynamic PVP's own vanilla events, position and zone id for staff only. - The feed's world filter carries the opening: "A PvP zone opened around the downed patrol helicopter · G7 · for 10 min". It names nobody. - The map gains a fifth layer, `pvp` (PvP zones), public by default with its own audience in Admin → Rust visibility, drawn as a red ring with its event's name. - Server settings' plugin line names Dynamic PVP; the swagger schemas and route descriptions carry the layer and the integration (fragment regenerated); ci/bundle.json ships dynamicPvp.js; README lists it. Tests: server 611/611 (dynamicPvp.test.js new, catalogue and map extended) and every check; client 89/89 (feed and map tooltip), build and externals. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E14m6SuuY6i1vASFeGDBeY
This commit is contained in:
@@ -153,6 +153,10 @@ test('the classification covers exactly the event kinds the protocol defines, th
|
||||
// Protocol 14 (§20.5): Rust's own world events, one kind told apart by
|
||||
// `event`. Public as a kind; `worldEvents.js` filters per type and per viewer.
|
||||
'world.event',
|
||||
// Protocol 14 (§20.7): Dynamic PVP's zones. The opening is public and names
|
||||
// nobody; the closing is a staff line (PLAN_REDESIGNS §14.3.3).
|
||||
'pvp.zone.created',
|
||||
'pvp.zone.deleted',
|
||||
]
|
||||
|
||||
assert.deepEqual([...catalogue.ALL_KINDS].sort(), [...PROTOCOL_4].sort())
|
||||
@@ -172,6 +176,9 @@ test('the classification covers exactly the event kinds the protocol defines, th
|
||||
// audience — the names come off per viewer, so the kind is not a presence kind.
|
||||
assert.equal(catalogue.isPublic('world.event'), true)
|
||||
assert.equal(catalogue.isPresence('world.event'), false)
|
||||
assert.equal(catalogue.isPublic('pvp.zone.created'), true)
|
||||
assert.equal(catalogue.isPresence('pvp.zone.created'), false)
|
||||
assert.equal(catalogue.isPublic('pvp.zone.deleted'), false, 'a zone closing is a staff line')
|
||||
})
|
||||
|
||||
test('every kind that names a player who was on is behind the presence setting', () => {
|
||||
@@ -196,5 +203,6 @@ test('every kind that names a player who was on is behind the presence setting',
|
||||
|
||||
// And what is left names nobody — a world event included, once `worldEvents.shapeFor`
|
||||
// has taken its names off for a viewer below the presence audience (D376).
|
||||
assert.deepEqual(catalogue.kindsFor({}).sort(), ['npc.boss.spawned', 'server.initialized', 'server.shutdown', 'server.wipe', 'world.event'])
|
||||
// Dynamic PVP's opening names nobody at all.
|
||||
assert.deepEqual(catalogue.kindsFor({}).sort(), ['npc.boss.spawned', 'pvp.zone.created', 'server.initialized', 'server.shutdown', 'server.wipe', 'world.event'])
|
||||
})
|
||||
|
||||
102
server/test/dynamicPvp.test.js
Normal file
102
server/test/dynamicPvp.test.js
Normal file
@@ -0,0 +1,102 @@
|
||||
// ── Dynamic PVP's zones (PLAN_REDESIGNS §14.3.3, protocol 14) ──────────────
|
||||
//
|
||||
// Each test is one way the feature could look right and be wrong:
|
||||
//
|
||||
// a zone's position reaches a viewer below staff through the feed, round the
|
||||
// map's own audience (D111)
|
||||
// an operator's own event name, typed into Dynamic PVP's config, reaches a
|
||||
// public page
|
||||
// the feed shapes a zone line without its grid
|
||||
// a frame of another kind is changed by the zone reader
|
||||
|
||||
const test = require('node:test')
|
||||
const assert = require('node:assert')
|
||||
|
||||
const { fakeCtx } = require('./_fakes')
|
||||
|
||||
/** Installs a core whose `db.query` answers `rows`. */
|
||||
function withRows(rows = []) {
|
||||
const ctx = fakeCtx({
|
||||
db: { query: (sql, params = []) => Promise.resolve(typeof rows === 'function' ? rows(sql, params) : rows), pool: {} },
|
||||
})
|
||||
require('../core')._reset()
|
||||
require('../core').init(ctx)
|
||||
}
|
||||
|
||||
withRows()
|
||||
|
||||
const dynamicPvp = require('../dynamicPvp')
|
||||
const { gridOf } = require('../worldEvents')
|
||||
|
||||
const NOW = Date.now()
|
||||
const GEOMETRY = { worldSize: 6000, gridCells: 41, gridCellSize: 146.34146341463415 }
|
||||
|
||||
const created = (over = {}) => ({
|
||||
kind: 'pvp.zone.created',
|
||||
type: 'event',
|
||||
t: NOW,
|
||||
serverId: 'main',
|
||||
wipeId: 'w1',
|
||||
zoneId: '1412203045',
|
||||
event: 'Helicopter',
|
||||
x: 812,
|
||||
z: -340.5,
|
||||
radius: 100,
|
||||
shape: 'sphere',
|
||||
durationSec: 600,
|
||||
...over,
|
||||
})
|
||||
|
||||
test('the public read the zone, its grid and how long it lasts, and never where it is', () => {
|
||||
const out = dynamicPvp.shapeFor(created(), { staff: false, geometry: GEOMETRY })
|
||||
assert.strictEqual(out.event, 'Helicopter')
|
||||
assert.strictEqual(out.grid, gridOf(GEOMETRY, 812, -340.5))
|
||||
assert.strictEqual(out.radius, 100)
|
||||
assert.strictEqual(out.durationSec, 600)
|
||||
for (const hidden of ['x', 'z', 'zoneId']) assert.strictEqual(hidden in out, false, `${hidden} is staff's`)
|
||||
})
|
||||
|
||||
test('staff read the position and the zone id too', () => {
|
||||
const out = dynamicPvp.shapeFor(created(), { staff: true, geometry: GEOMETRY })
|
||||
assert.strictEqual(out.x, 812)
|
||||
assert.strictEqual(out.z, -340.5)
|
||||
assert.strictEqual(out.zoneId, '1412203045')
|
||||
})
|
||||
|
||||
test("a monument's or an operator's own event name is staff's alone", () => {
|
||||
for (const event of ['Airfield', 'My secret arena']) {
|
||||
assert.strictEqual('event' in dynamicPvp.shapeFor(created({ event }), { staff: false, geometry: GEOMETRY }), false)
|
||||
assert.strictEqual(dynamicPvp.shapeFor(created({ event }), { staff: true, geometry: GEOMETRY }).event, event)
|
||||
}
|
||||
for (const event of dynamicPvp.GENERAL_EVENTS) assert.ok(dynamicPvp.isGeneral(event))
|
||||
})
|
||||
|
||||
test('without a map geometry a line has no grid, and off the map neither', () => {
|
||||
assert.strictEqual('grid' in dynamicPvp.shapeFor(created(), { geometry: null }), false)
|
||||
assert.strictEqual('grid' in dynamicPvp.shapeFor(created({ x: 9000 }), { geometry: GEOMETRY }), false)
|
||||
})
|
||||
|
||||
test('a frame of another kind is passed back untouched', () => {
|
||||
const other = { kind: 'world.event', event: 'heli.downed', x: 1, z: 2 }
|
||||
assert.strictEqual(dynamicPvp.shapeFor(other, { staff: false }), other)
|
||||
})
|
||||
|
||||
test('the feed reads a zone line for its viewer, with the map’s grid', async () => {
|
||||
const stored = created({ event: 'Airfield' })
|
||||
withRows((sql) => {
|
||||
if (sql.includes('FROM rust_events')) return [{ id: 11, kind: 'pvp.zone.created', t: NOW, wipeId: 'w1', steamId: null, raw: JSON.stringify(stored) }]
|
||||
if (sql.includes('FROM rust_servers')) return [{ id: 'main', name: 'Main', enabled: 1 }]
|
||||
if (sql.includes('FROM rust_map_images')) return [{ serverId: 'main', ...GEOMETRY }]
|
||||
return []
|
||||
})
|
||||
const events = require('../model/events/events.model')
|
||||
|
||||
const [signedOut] = await events.recent({ serverId: 'main' })
|
||||
assert.strictEqual(signedOut.frame.grid, gridOf(GEOMETRY, 812, -340.5))
|
||||
assert.strictEqual('x' in signedOut.frame, false)
|
||||
assert.strictEqual('event' in signedOut.frame, false)
|
||||
|
||||
const [staff] = await events.recent({ serverId: 'main', staff: true })
|
||||
assert.strictEqual(staff.frame.x, 812)
|
||||
assert.strictEqual(staff.frame.event, 'Airfield')
|
||||
})
|
||||
@@ -84,17 +84,19 @@ const LIVE = {
|
||||
{ steamId: '7005', name: 'My alt, asleep', x: 5, z: 5, sleeping: true, online: false },
|
||||
],
|
||||
bases: [{ kind: 'tc', x: 9, z: 9 }],
|
||||
pvp: [{ zoneId: '1412203045', event: 'Helicopter', x: 30, z: 40, radius: 100, shape: 'sphere' }],
|
||||
}
|
||||
|
||||
test('a fresh install shows the world and events to anybody, and positions to staff only', async (t) => {
|
||||
settings(t)
|
||||
assert.deepStrictEqual(await map.fleet(), { world: 'public', events: 'public', players: 'staff', bases: 'staff', mates: true, markers: {} })
|
||||
assert.deepStrictEqual(await map.fleet(), { world: 'public', events: 'public', players: 'staff', bases: 'staff', pvp: 'public', mates: true, markers: {} })
|
||||
|
||||
const acc = await map.access({}, 'main')
|
||||
assert.equal(acc.layers.world.visible, true)
|
||||
assert.equal(acc.layers.events.visible, true)
|
||||
assert.equal(acc.layers.players.visible, false)
|
||||
assert.equal(acc.layers.bases.visible, false)
|
||||
assert.equal(acc.layers.pvp.visible, true, 'Dynamic PVP zones name nobody (§14.3.3)')
|
||||
assert.equal(acc.mates.visible, false, 'an anonymous viewer has no accounts to be shown')
|
||||
})
|
||||
|
||||
@@ -158,6 +160,19 @@ test('a hidden layer is absent from the answer, not an empty array', async (t) =
|
||||
}
|
||||
})
|
||||
|
||||
test('§14.3.3: the pvp layer passes Dynamic PVP zones through, is empty from an older plugin, and can be hidden', async (t) => {
|
||||
settings(t)
|
||||
assert.deepStrictEqual(map.project(LIVE, await map.access({}, 'main')).pvp, LIVE.pvp)
|
||||
const { pvp, ...older } = LIVE
|
||||
assert.deepStrictEqual(map.project(older, await map.access({}, 'main')).pvp, [])
|
||||
})
|
||||
|
||||
test('§14.3.3: a pvp layer set to staff is absent for the public', async (t) => {
|
||||
settings(t, { stored: { 'map.layer.pvp.audience': 'staff' } })
|
||||
const out = map.project(LIVE, await map.access({}, 'main'))
|
||||
assert.equal(Object.prototype.hasOwnProperty.call(out, 'pvp'), false)
|
||||
})
|
||||
|
||||
test('staff get every layer', async (t) => {
|
||||
settings(t, { viewer: { level: 'staff', userId: 1 } })
|
||||
const out = map.project({ ...LIVE, basesTruncated: true }, await map.access({}, 'main'))
|
||||
|
||||
Reference in New Issue
Block a user