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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Connection made → Direct peer-to-peer, Nostr disconnected

If Nostr becomes unavailable, players can fall back to manual connection code exchange. The game continues to function regardless of external infrastructure.

**Implementation:** `src/engine/network/p2p/NostrMatchmaking.ts`, `ConnectionCode.ts`
**Implementation:** `src/hooks/useMultiplayer.ts`, `src/store/multiplayerStore.ts`

---

Expand Down
2 changes: 0 additions & 2 deletions src/components/game/WebGPUGameCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ export function WebGPUGameCanvas() {
eventBusRef,
isGameInitialized: isWorkerInitialized,
placementPreviewRef: refs.placementPreview,
wallPlacementPreviewRef: refs.wallPlacementPreview,
overlayManagerRef: refs.overlayManager,
lastControlGroupTap,
});
Expand All @@ -160,7 +159,6 @@ export function WebGPUGameCanvas() {
cameraRef: refs.camera,
environmentRef: refs.environment,
lightPoolRef: refs.lightPool,
fogOfWarRef: refs.fogOfWar,
containerRef,
map: CURRENT_MAP,
});
Expand Down
3 changes: 0 additions & 3 deletions src/components/game/hooks/useGameInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import type { IWorldProvider } from '@/engine/ecs/IWorldProvider';
import type { EventBus } from '@/engine/core/EventBus';
import { RTSCamera } from '@/rendering/Camera';
import { BuildingPlacementPreview } from '@/rendering/BuildingPlacementPreview';
import { WallPlacementPreview } from '@/rendering/WallPlacementPreview';
import { TSLGameOverlayManager } from '@/rendering/tsl';
import { getLocalPlayerId } from '@/store/gameSetupStore';
import {
Expand All @@ -44,8 +43,6 @@ export interface UseGameInputProps {
/** Signal that game is initialized - triggers InputManager dependency update */
isGameInitialized?: boolean;
placementPreviewRef: MutableRefObject<BuildingPlacementPreview | null>;
/** @deprecated No longer used - wall placement handled by BuildingInputHandler */
wallPlacementPreviewRef?: MutableRefObject<WallPlacementPreview | null>;
overlayManagerRef: MutableRefObject<TSLGameOverlayManager | null>;
lastControlGroupTap: MutableRefObject<{ group: number; time: number } | null>;
}
Expand Down
5 changes: 1 addition & 4 deletions src/components/game/hooks/usePostProcessing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import type { MutableRefObject, RefObject } from 'react';
import { useEffect, useRef } from 'react';
import * as THREE from 'three';
import { RenderContext, RenderPipeline, TSLFogOfWar } from '@/rendering/tsl';
import { RenderContext, RenderPipeline } from '@/rendering/tsl';
import { EnvironmentManager } from '@/rendering/EnvironmentManager';
import { LightPool } from '@/rendering/LightPool';
import { RTSCamera } from '@/rendering/Camera';
Expand All @@ -24,8 +24,6 @@ export interface UsePostProcessingProps {
cameraRef: MutableRefObject<RTSCamera | null>;
environmentRef: MutableRefObject<EnvironmentManager | null>;
lightPoolRef: MutableRefObject<LightPool | null>;
/** @deprecated Fog of war is now handled via RenderPipeline */
fogOfWarRef?: MutableRefObject<TSLFogOfWar | null>;
containerRef: RefObject<HTMLDivElement | null>;
map: MapData;
}
Expand All @@ -37,7 +35,6 @@ export function usePostProcessing({
cameraRef,
environmentRef,
lightPoolRef,
fogOfWarRef: _fogOfWarRef,
containerRef,
map,
}: UsePostProcessingProps): void {
Expand Down
39 changes: 11 additions & 28 deletions src/engine/core/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
getDesyncState,
useMultiplayerStore,
getAdaptiveCommandDelay,
getSlotIdForPeer,
getAllRemoteSlotIds,
setOnReconnectedCallback,
} from '@/store/multiplayerStore';
Expand Down Expand Up @@ -180,22 +179,17 @@ export class Game extends GameCore {
// Commands use slot IDs (e.g., "player1", "player2"), not peer IDs
const validRemoteSlotIds = getAllRemoteSlotIds();
if (!validRemoteSlotIds.includes(command.playerId)) {
// Also check legacy single-peer mode
const legacyPeerId = useMultiplayerStore.getState().remotePeerId;
const legacySlotId = legacyPeerId ? getSlotIdForPeer(legacyPeerId) : null;
if (command.playerId !== legacySlotId) {
console.error(
`[Game] SECURITY: Rejected command with invalid playerId. ` +
`Valid slot IDs: [${validRemoteSlotIds.join(', ')}], Got: ${command.playerId}`
);
this.eventBus.emit('security:spoofedPlayerId', {
expectedPlayerId: validRemoteSlotIds.join(', '),
spoofedPlayerId: command.playerId,
commandType: command.type,
tick: command.tick,
});
return;
}
console.error(
`[Game] SECURITY: Rejected command with invalid playerId. ` +
`Valid slot IDs: [${validRemoteSlotIds.join(', ')}], Got: ${command.playerId}`
);
this.eventBus.emit('security:spoofedPlayerId', {
expectedPlayerId: validRemoteSlotIds.join(', '),
spoofedPlayerId: command.playerId,
commandType: command.type,
tick: command.tick,
});
return;
}

// SECURITY: Validate command tick is within acceptable range
Expand Down Expand Up @@ -611,17 +605,6 @@ export class Game extends GameCore {
}
}

// Fallback for legacy single-peer mode: try to get slot ID from peer ID mapping
if (remoteSlotIds.length === 0) {
const remotePeerId = useMultiplayerStore.getState().remotePeerId;
if (remotePeerId) {
const slotId = getSlotIdForPeer(remotePeerId);
if (slotId && !players.includes(slotId)) {
players.push(slotId);
}
}
}

return players;
}

Expand Down
12 changes: 4 additions & 8 deletions src/hooks/useLobbySync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ export function useLobbySync({ playerName, isPublicLobby }: UseLobbyOptions): Lo
setMultiplayer,
setConnected,
setHost,
setDataChannel,
} = useMultiplayerStore();

// Derived state
Expand All @@ -124,27 +123,24 @@ export function useLobbySync({ playerName, isPublicLobby }: UseLobbyOptions): Lo
const isGuestMode = lobbyStatus === 'connected' && !isHost;

// When connected as guest, set up multiplayer store
// Note: Data channel is set up via addPeer() in useMultiplayer.ts
useEffect(() => {
if (lobbyStatus === 'connected' && hostConnection) {
setMultiplayer(true);
setConnected(true);
setHost(false);
setDataChannel(hostConnection);
}
}, [lobbyStatus, hostConnection, setMultiplayer, setConnected, setHost, setDataChannel]);
}, [lobbyStatus, hostConnection, setMultiplayer, setConnected, setHost]);

// When hosting with connected guests, set up multiplayer
// Note: Data channels are set up via addPeer() in useMultiplayer.ts
useEffect(() => {
if (isHost && guests.some(g => g.dataChannel)) {
setMultiplayer(true);
setConnected(true);
setHost(true);
const firstConnectedGuest = guests.find(g => g.dataChannel);
if (firstConnectedGuest?.dataChannel) {
setDataChannel(firstConnectedGuest.dataChannel);
}
}
}, [isHost, guests, setMultiplayer, setConnected, setHost, setDataChannel]);
}, [isHost, guests, setMultiplayer, setConnected, setHost]);

// Send lobby state to guests whenever it changes (host only)
useEffect(() => {
Expand Down
Loading