Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _includes/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
{% include "header.html" %}
{{ content }}
{% include "footer.html" %}
<script type="module" src="/assets/space-egg/trigger.js?v=17"></script>
<script type="module" src="/assets/space-egg/trigger.js?v=18"></script>
</body>
</html>
6 changes: 3 additions & 3 deletions assets/space-egg/game.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createRenderer } from './rendering.js?v=14';
import { gameMarkup, gameTheme, waitForStyles, adaptControls } from './view.js?v=15';
import { gameMarkup, gameTheme, waitForStyles, adaptControls } from './view.js?v=18';
import { matchesWorld } from './protocol.js?v=14';
import { createOrdnance, ORDNANCE, blastTouches } from './ordnance.js?v=14';
import { targetStrength, damageEdge } from './targets.js?v=14';
Expand All @@ -9,7 +9,7 @@ import { POWERUPS, damageHull, expandedRect, effectSeconds, advanceScroll, shipC
import { hitsRect, firstHit } from './physics.js?v=14';
import { createSound } from './sound.js?v=17';
import { internalDestination } from './navigation.js?v=14';
import { createMultiplayer, MAX_PLAYERS, pilotName } from './multiplayer.js?v=15';
import { createMultiplayer, MAX_PLAYERS, pilotName } from './multiplayer.js?v=18';
import { invitationLink, invitationPeer } from './invitation.js?v=15';
import { hitReward, pageReward } from './scoring.js?v=14';

Expand Down Expand Up @@ -115,7 +115,7 @@ export async function openGame(onClose, invitedPeerId = null, signal) {
const { drawShip, drawPilotName, drawOrdnance } = createRenderer(context, reducedMotion);
const launchButton = find('.launch');
const scoreOutput = find('.score');
const colors = ['#ff6600', '#56dfff', '#ee91ff', '#b2ef5e'];
const colors = ['#ff6600', '#56dfff', '#ee91ff', '#b2ef5e', '#ffd65a', '#ff718d', '#a7a0ff', '#72f0cf'];
function playerColor(id = network?.playerId) {
const index = network?.playerIds.indexOf(id) ?? -1;
return colors[Math.max(0, index) % colors.length];
Expand Down
4 changes: 2 additions & 2 deletions assets/space-egg/multiplayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ function loadPeerLibrary() {
return libraryPromise;
}

export const MAX_PLAYERS = 4;
export const MAX_PLAYERS = 8;

export function pilotName(value) {
if (typeof value !== 'string') return '';
return Array.from(value.replace(/[\u0000-\u001f\u007f\u202a-\u202e\u2066-\u2069]/g, '').replace(/\s+/g, ' ').trim()).slice(0, 20).join('');
}
const protocol = 9;
const protocol = 10;

// Star topology: the host owns scoring and relays guests' visual updates.
export function createMultiplayer({ onMessage, onConnected, onStatus, onPlayers = () => {}, loadPeer = loadPeerLibrary }) {
Expand Down
2 changes: 1 addition & 1 deletion assets/space-egg/trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function reveal(invitedPeerId = null) {
const cancel = event => { if (event.key === 'Escape') controller.abort(); };
window.addEventListener('keydown', cancel);
try {
const { openGame } = await import('./game.js?v=17');
const { openGame } = await import('./game.js?v=18');
controller.signal.throwIfAborted();
await openGame(() => { active = false; }, invitedPeerId, controller.signal);
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion assets/space-egg/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function gameMarkup() {
<div class="tools-controls"></div><div class="tools-stats"></div>
</div></div>
<div class="lobby" hidden><div class="panel">
<span class="kicker">Besättning / upp till fyra</span><h2>Flyg tillsammans</h2>
<span class="kicker">Besättning / upp till åtta</span><h2>Flyg tillsammans</h2>
<p class="lobby-intro">Skapa ett rum och bjud in med en länk.</p>
<label class="name-label">Pilotnamn <span>(valfritt)</span><input class="pilot-name" maxlength="20" autocomplete="off" placeholder="Ditt anropsnamn"></label>
<section class="crew" hidden aria-label="Besättning"><h3>Besättning <span class="crew-count"></span></h3><ul class="crew-list" aria-live="polite"></ul></section>
Expand Down
2 changes: 1 addition & 1 deletion scripts/space-browser-multiplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def page():
g.locator('.pilot-name').fill('Mats')
g.locator('.join-game').click()
try:
g.locator('.connection-status').filter(has_text='2 / 4').wait_for(state='attached', timeout=35000)
g.locator('.connection-status').filter(has_text='2 / 8').wait_for(state='attached', timeout=35000)
except Exception:
print('HOST:', h.locator('.lobby-status').inner_text(), flush=True)
print('GUEST:', g.locator('.lobby-status').inner_text(), flush=True)
Expand Down
20 changes: 11 additions & 9 deletions scripts/space-transport.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,27 @@ function fakePeerLibrary() {
}
const flush = () => new Promise(resolve => setImmediate(resolve));

test('host admits four pilots, relays authenticated senders and rejects guest authority', async t => {
test('host admits eight pilots, relays authenticated senders and rejects guest authority', async t => {
const Peer = fakePeerLibrary();
const received = [[], [], [], [], []];
const received = Array.from({ length: 9 }, () => []);
const clients = received.map(messages => createMultiplayer({ loadPeer: async () => Peer,
onMessage: (message, sender) => messages.push({ message, sender }), onConnected() {}, onStatus() {} }));
t.after(() => clients.forEach(client => client.close()));
const id = await clients[0].host('Host');
for (let i = 1; i < 4; i++) await clients[i].join(id, `Guest ${i}`);
for (let i = 1; i < 8; i++) await clients[i].join(id, `Guest ${i}`);
await flush();
for (let i = 0; i < 4; i++) assert.equal(clients[i].playerIds.length, 4);
for (let i = 0; i < 8; i++) assert.equal(clients[i].playerIds.length, 8);
clients[1].send({ type: 'position', x: 0.5 });
clients[1].send({ type: 'state', score: 100000 });
await flush();
assert.equal(received[0].length, 1);
assert.equal(received[2].length, 1);
assert.equal(received[2][0].sender, clients[1].playerId);
await assert.rejects(clients[4].join(id), /fullt/);
clients[3].close(); await flush();
assert.equal(clients[0].playerIds.length, 3);
for (let i = 2; i < 8; i++) {
assert.equal(received[i].length, 1);
assert.equal(received[i][0].sender, clients[1].playerId);
}
await assert.rejects(clients[8].join(id), /fullt/);
clients[7].close(); await flush();
assert.equal(clients[0].playerIds.length, 7);
});

test('critical updates survive congestion; excessive backlog disconnects cleanly', async t => {
Expand Down
Loading