feat: Add player position tracking endpoints for updates and retrieval

This commit is contained in:
MayaTheShy
2026-02-20 00:18:57 -05:00
parent a1d2b62d5f
commit bc4f87f178

View File

@@ -760,6 +760,56 @@ app.post('/api/groups/:groupId/command', (req, res) => {
}
});
// Player position endpoints
app.post('/api/player/update', (req, res) => {
try {
const { playerID, position, timestamp } = req.body;
if (!playerID || !position) {
return res.status(400).json({ error: 'Missing playerID or position' });
}
db.savePlayerPosition(playerID, position);
// Broadcast to WebSocket clients
broadcastToClients({
type: 'player_update',
playerID,
position,
timestamp: timestamp || Date.now()
});
res.json({ success: true, playerID, position });
} catch (error) {
console.error('Error updating player position:', error);
res.status(500).json({ error: error.message });
}
});
app.get('/api/players', (req, res) => {
try {
const players = db.getAllPlayerPositions();
res.json(players);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
app.get('/api/player/:id', (req, res) => {
try {
const playerId = parseInt(req.params.id);
const player = db.getPlayerPosition(playerId);
if (!player) {
return res.status(404).json({ error: 'Player not found' });
}
res.json(player);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
// Graceful shutdown
process.on('SIGINT', () => {
console.log('\n🛑 Shutting down server...');