mirror of
https://github.com/Such-Software/wownerogue.git
synced 2026-10-17 22:31:26 +02:00
refactor: remove dead move handler + stale test scratch files
4.2 (partial): Delete the dead handlePlayerMove socket handler and its orphaned playerMoveTimestamps map + cleanup. It was never registered (the live move path is MovementManager.handleMove) but, if ever wired, it double-stepped the monster and bypassed the escape/collision event handling — a loaded footgun. No behaviour change. 4.5: Delete 14 stale non-jest files from test/ (5 scratch .js scripts + 9 .html debug pages) — they contain no jest constructs and are referenced nowhere. test/ is now exclusively the 21 real jest suites. Full suite: 21 suites / 155 tests.
This commit is contained in:
@@ -187,8 +187,7 @@ class SocketHandlers {
|
||||
cleanupTimeoutMs: 300000 // 5 minutes to reconnect before game is lost
|
||||
});
|
||||
|
||||
// Movement manager abstraction with memory cleanup
|
||||
this.playerMoveTimestamps = new Map();
|
||||
// Movement manager abstraction (owns its own move-cooldown state)
|
||||
this.movementManager = new MovementManager({
|
||||
activeGames: this.activeGames,
|
||||
io: this.io,
|
||||
@@ -206,32 +205,6 @@ class SocketHandlers {
|
||||
* Register memory cleanup functions to prevent memory leaks
|
||||
*/
|
||||
_registerMemoryCleanups() {
|
||||
// Cleanup player move timestamps (keep for 5 minutes)
|
||||
this.memoryManager.registerCleanup(
|
||||
'playerMoveTimestamps',
|
||||
() => {
|
||||
const now = Date.now();
|
||||
const maxAge = 300000; // 5 minutes
|
||||
let cleaned = 0;
|
||||
const toDelete = [];
|
||||
|
||||
for (const [socketId, timestamp] of this.playerMoveTimestamps.entries()) {
|
||||
if (now - timestamp > maxAge) {
|
||||
toDelete.push(socketId);
|
||||
}
|
||||
}
|
||||
|
||||
for (const socketId of toDelete) {
|
||||
if (this.playerMoveTimestamps.delete(socketId)) {
|
||||
cleaned++;
|
||||
}
|
||||
}
|
||||
|
||||
return cleaned;
|
||||
},
|
||||
300000
|
||||
);
|
||||
|
||||
// (mempool-notification dedup + TTL eviction lives in PaymentHandlers, which owns
|
||||
// the actual dedup set; the old SocketHandlers copy here was unused and is removed.)
|
||||
|
||||
@@ -245,69 +218,6 @@ class SocketHandlers {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle player movement input from client.
|
||||
* Expects moveData: { direction: 'up'|'down'|'left'|'right' }
|
||||
*/
|
||||
handlePlayerMove(socket, moveData) {
|
||||
try {
|
||||
if (!moveData || typeof moveData.direction !== 'string') return;
|
||||
const now = Date.now();
|
||||
const last = this.playerMoveTimestamps.get(socket.id) || 0;
|
||||
if (now - last < this.MOVE_COOLDOWN) return; // rate limit moves
|
||||
this.playerMoveTimestamps.set(socket.id, now);
|
||||
|
||||
const game = this.activeGames.get(socket.id);
|
||||
if (!game) return; // not in a game
|
||||
|
||||
// Translate direction to delta
|
||||
const dir = moveData.direction;
|
||||
let dx = 0, dy = 0;
|
||||
switch (dir) {
|
||||
case 'up': dy = -1; break;
|
||||
case 'down': dy = 1; break;
|
||||
case 'left': dx = -1; break;
|
||||
case 'right': dx = 1; break;
|
||||
default: return; // ignore unknown
|
||||
}
|
||||
|
||||
// Attempt move via game API (assuming game has movePlayer(dx,dy))
|
||||
if (typeof game.movePlayer === 'function') {
|
||||
game.movePlayer(dx, dy);
|
||||
} else if (game.player) {
|
||||
// Fallback direct mutation (legacy) with simple bounds check
|
||||
const newX = game.player.x + dx;
|
||||
const newY = game.player.y + dy;
|
||||
if (newX >= 0 && newY >= 0) {
|
||||
game.player.x = newX;
|
||||
game.player.y = newY;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof game.moveMonster === 'function') {
|
||||
game.moveMonster();
|
||||
}
|
||||
|
||||
// Build updated state
|
||||
let state;
|
||||
if (typeof game.getState === 'function') {
|
||||
state = game.getState();
|
||||
} else {
|
||||
state = { player: game.player };
|
||||
}
|
||||
|
||||
// Add block height context
|
||||
if (this.debugManager && typeof this.debugManager.getCurrentBlockHeight === 'function') {
|
||||
state.blockHeight = this.debugManager.getCurrentBlockHeight();
|
||||
}
|
||||
|
||||
this.io.to(socket.id).emit('game_update', state);
|
||||
|
||||
} catch (err) {
|
||||
console.error('handlePlayerMove error:', err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after a successful player move (before update is emitted) via MovementManager postMoveHook.
|
||||
* Handles monster chasing logic and immediate game over if monster catches player.
|
||||
@@ -816,9 +726,6 @@ class SocketHandlers {
|
||||
// addressToUser entries must persist so checkPaymentStatus() can query the wallet
|
||||
// RPC after session resumption. They get cleaned up when payments are confirmed or expired.
|
||||
|
||||
// Clean up movement timestamps
|
||||
this.playerMoveTimestamps.delete(socketId);
|
||||
|
||||
// Preserve queue entry for users with session/payment
|
||||
// The queue entry's socketId will be updated on reconnection
|
||||
if (this.queueManager && typeof this.queueManager.removePlayer === 'function') {
|
||||
@@ -1211,7 +1118,6 @@ class SocketHandlers {
|
||||
|
||||
// Clear remaining data structures
|
||||
this.activeGames.clear();
|
||||
this.playerMoveTimestamps.clear();
|
||||
|
||||
if (this.debugManager.CONSOLE_LOGGING) {
|
||||
console.log('✅ SocketHandlers shutdown complete');
|
||||
|
||||
Reference in New Issue
Block a user