Fix server management issues and improve overall stability

Major server management fixes:
- Replace Flatpak-specific pkill with universal process tree termination using pstree + process.kill()
- Fix signal format errors (SIGTERM/SIGKILL instead of TERM/KILL strings)
- Add 5-second cooldown after server stop to prevent race conditions with external detection
- Enable Stop Server button for external servers in UI
- Implement proper timeout handling with process tree killing

ContentDB improvements:
- Fix download retry logic and "closed" error by preventing concurrent zip extraction
- Implement smart root directory detection and stripping during package extraction
- Add game-specific timeout handling (8s for VoxeLibre vs 3s for simple games)

World creation fixes:
- Make world creation asynchronous to prevent browser hangs
- Add WebSocket notifications for world creation completion status

Other improvements:
- Remove excessive debug logging
- Improve error handling and user feedback throughout the application
- Clean up temporary files and unnecessary logging

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Nathan Schneider
2025-08-24 19:17:38 -06:00
parent 3aed09b60f
commit 2d3b1166fe
15 changed files with 851 additions and 536 deletions

View File

@@ -6,6 +6,7 @@ const { promisify } = require('util');
const paths = require('../utils/paths');
const ConfigParser = require('../utils/config-parser');
const serverManager = require('../utils/shared-server-manager');
const router = express.Router();
@@ -39,11 +40,15 @@ router.get('/', async (req, res) => {
db.close();
} catch (dbError) {}
const gameid = config.gameid || 'minetest_game';
const gameTitle = await paths.getGameDisplayName(gameid);
worlds.push({
name: worldDir,
displayName: config.server_name || worldDir,
description: config.server_description || '',
gameid: config.gameid || 'minetest_game',
gameid: gameid,
gameTitle: gameTitle,
creativeMode: config.creative_mode || false,
enableDamage: config.enable_damage !== false,
enablePvp: config.enable_pvp !== false,
@@ -128,131 +133,42 @@ router.post('/create', async (req, res) => {
console.log('Starting world creation for:', name, 'with gameid:', gameid);
// Create the world directory - Luanti will initialize it when the server starts
await fs.mkdir(worldPath, { recursive: true });
console.log('Created world directory:', worldPath);
// Create a basic world.mt file with the correct game ID
const worldConfig = `enable_damage = true
creative_mode = false
mod_storage_backend = sqlite3
auth_backend = sqlite3
player_backend = sqlite3
backend = sqlite3
gameid = ${gameid || 'minetest_game'}
world_name = ${name}
`;
const worldConfigPath = path.join(worldPath, 'world.mt');
await fs.writeFile(worldConfigPath, worldConfig, 'utf8');
console.log('Created world.mt with gameid:', gameid || 'minetest_game');
// Create essential database files with proper schema
const sqlite3 = require('sqlite3');
// Create players database with correct schema
const playersDbPath = path.join(worldPath, 'players.sqlite');
await new Promise((resolve, reject) => {
const playersDb = new sqlite3.Database(playersDbPath, (err) => {
if (err) reject(err);
else {
playersDb.serialize(() => {
playersDb.exec(`CREATE TABLE IF NOT EXISTS player (
name TEXT PRIMARY KEY,
pitch REAL,
yaw REAL,
posX REAL,
posY REAL,
posZ REAL,
hp INTEGER,
breath INTEGER,
creation_date INTEGER,
modification_date INTEGER,
privs TEXT
)`, (err) => {
if (err) {
console.error('Error creating player table:', err);
reject(err);
} else {
console.log('Created player table in players.sqlite');
playersDb.close((closeErr) => {
if (closeErr) reject(closeErr);
else resolve();
});
}
});
// Start world creation asynchronously and respond immediately
serverManager.createWorld(name, gameid || 'minetest_game')
.then(() => {
console.log('Successfully created world using Luanti:', name);
// Notify clients via WebSocket
const io = req.app.get('socketio');
if (io) {
io.emit('worldCreated', {
worldName: name,
gameId: gameid || 'minetest_game',
success: true
});
}
})
.catch((error) => {
console.error('Error creating world:', error);
// Notify clients via WebSocket about the error
const io = req.app.get('socketio');
if (io) {
io.emit('worldCreated', {
worldName: name,
gameId: gameid || 'minetest_game',
success: false,
error: error.message
});
}
});
});
// Create other essential databases
const mapDbPath = path.join(worldPath, 'map.sqlite');
await new Promise((resolve, reject) => {
const mapDb = new sqlite3.Database(mapDbPath, (err) => {
if (err) reject(err);
else {
mapDb.serialize(() => {
mapDb.exec(`CREATE TABLE IF NOT EXISTS blocks (
x INTEGER,
y INTEGER,
z INTEGER,
data BLOB NOT NULL,
PRIMARY KEY (x, z, y)
)`, (err) => {
if (err) {
console.error('Error creating blocks table:', err);
reject(err);
} else {
console.log('Created blocks table in map.sqlite');
mapDb.close((closeErr) => {
if (closeErr) reject(closeErr);
else resolve();
});
}
});
});
}
});
});
const modStorageDbPath = path.join(worldPath, 'mod_storage.sqlite');
await new Promise((resolve, reject) => {
const modDb = new sqlite3.Database(modStorageDbPath, (err) => {
if (err) reject(err);
else {
modDb.serialize(() => {
modDb.exec(`CREATE TABLE IF NOT EXISTS entries (
modname TEXT NOT NULL,
key BLOB NOT NULL,
value BLOB NOT NULL,
PRIMARY KEY (modname, key)
)`, (err) => {
if (err) {
console.error('Error creating entries table:', err);
reject(err);
} else {
console.log('Created entries table in mod_storage.sqlite');
modDb.close((closeErr) => {
if (closeErr) reject(closeErr);
else resolve();
});
}
});
});
}
});
});
console.log('Created essential database files with proper schema');
res.redirect('/worlds?created=' + encodeURIComponent(name));
// Respond immediately with a "creating" status
res.redirect('/worlds?creating=' + encodeURIComponent(name));
} catch (error) {
console.error('Error creating world:', error);
console.error('Error starting world creation:', error);
res.status(500).render('worlds/new', {
title: 'Create World',
currentPage: 'worlds',
error: 'Failed to create world: ' + error.message,
error: 'Failed to start world creation: ' + error.message,
formData: req.body
});
}