diff --git a/server/database.js b/server/database.js index 050acf3..14db339 100644 --- a/server/database.js +++ b/server/database.js @@ -133,6 +133,17 @@ export function initializeDatabase() { ) `); + // Player positions table (for tracking pocket computer users) + db.exec(` + CREATE TABLE IF NOT EXISTS player_positions ( + player_id INTEGER PRIMARY KEY, + x INTEGER NOT NULL, + y INTEGER NOT NULL, + z INTEGER NOT NULL, + updated_at INTEGER NOT NULL + ) + `); + // Create indexes for better performance db.exec(` CREATE INDEX IF NOT EXISTS idx_world_blocks_discovered @@ -455,6 +466,25 @@ export function getSessionStats(turtleId, limit = 10) { return stmt.all(turtleId, limit); } +// Player Positions +export function savePlayerPosition(playerId, position) { + const stmt = db.prepare(` + INSERT OR REPLACE INTO player_positions (player_id, x, y, z, updated_at) + VALUES (?, ?, ?, ?, ?) + `); + stmt.run(playerId, position.x, position.y, position.z, Date.now()); +} + +export function getPlayerPosition(playerId) { + const stmt = db.prepare('SELECT x, y, z, updated_at FROM player_positions WHERE player_id = ?'); + return stmt.get(playerId); +} + +export function getAllPlayerPositions() { + const stmt = db.prepare('SELECT player_id, x, y, z, updated_at FROM player_positions'); + return stmt.all(); +} + // Cleanup function export function closeDatabase() { db.close();