mirror of
https://git.sanhost.net/sanasol/hytale-f2p
synced 2026-02-26 16:21:49 -03:00
fix: add game_running_marker to prevent duplicate launches
This commit is contained in:
@@ -396,6 +396,34 @@ exec "$REAL_JAVA" "\${ARGS[@]}"
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ==========================================================================
|
||||||
|
// STEP 4: Check if game is already running (prevent duplicate launches)
|
||||||
|
// ==========================================================================
|
||||||
|
const GAME_RUNNING_MARKER = path.join(userDataDir, '.game_running');
|
||||||
|
|
||||||
|
if (fs.existsSync(GAME_RUNNING_MARKER)) {
|
||||||
|
try {
|
||||||
|
const existingPid = fs.readFileSync(GAME_RUNNING_MARKER, 'utf8').trim();
|
||||||
|
const error = new Error(`Game is already running (PID: ${existingPid}). Please close it before launching again.`);
|
||||||
|
console.error('[Launcher]', error.message);
|
||||||
|
if (progressCallback) {
|
||||||
|
progressCallback(error.message, -1, null, null, null);
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
} catch (err) {
|
||||||
|
if (err.message.includes('already running')) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
// File is corrupted, clean it up and continue
|
||||||
|
console.log('Game running marker corrupted, cleaning up and continuing...');
|
||||||
|
try {
|
||||||
|
fs.unlinkSync(GAME_RUNNING_MARKER);
|
||||||
|
} catch (unlinkErr) {
|
||||||
|
// Ignore if file is already gone
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let spawnOptions = {
|
let spawnOptions = {
|
||||||
stdio: ['ignore', 'pipe', 'pipe'],
|
stdio: ['ignore', 'pipe', 'pipe'],
|
||||||
@@ -415,6 +443,15 @@ exec "$REAL_JAVA" "\${ARGS[@]}"
|
|||||||
// This works on all platforms (Windows, macOS, Linux)
|
// This works on all platforms (Windows, macOS, Linux)
|
||||||
child.unref();
|
child.unref();
|
||||||
|
|
||||||
|
// Write game running marker file to track process
|
||||||
|
try {
|
||||||
|
fs.writeFileSync(GAME_RUNNING_MARKER, child.pid.toString());
|
||||||
|
console.log(`Game running marker created: ${GAME_RUNNING_MARKER} (PID: ${child.pid})`);
|
||||||
|
} catch (markerErr) {
|
||||||
|
console.warn('Failed to create game running marker:', markerErr.message);
|
||||||
|
// Continue anyway - not critical if marker fails
|
||||||
|
}
|
||||||
|
|
||||||
console.log(`Game process started with PID: ${child.pid}`);
|
console.log(`Game process started with PID: ${child.pid}`);
|
||||||
|
|
||||||
let hasExited = false;
|
let hasExited = false;
|
||||||
@@ -447,6 +484,17 @@ exec "$REAL_JAVA" "\${ARGS[@]}"
|
|||||||
child.on('exit', (code, signal) => {
|
child.on('exit', (code, signal) => {
|
||||||
hasExited = true;
|
hasExited = true;
|
||||||
clearTimeout(launchCheckTimeout);
|
clearTimeout(launchCheckTimeout);
|
||||||
|
|
||||||
|
// Clean up game running marker file
|
||||||
|
try {
|
||||||
|
if (fs.existsSync(GAME_RUNNING_MARKER)) {
|
||||||
|
fs.unlinkSync(GAME_RUNNING_MARKER);
|
||||||
|
console.log('Game running marker removed');
|
||||||
|
}
|
||||||
|
} catch (markerCleanupErr) {
|
||||||
|
console.warn('Failed to remove game running marker:', markerCleanupErr.message);
|
||||||
|
}
|
||||||
|
|
||||||
if (code !== null) {
|
if (code !== null) {
|
||||||
console.log(`Game process exited with code ${code}`);
|
console.log(`Game process exited with code ${code}`);
|
||||||
if (code !== 0 && progressCallback) {
|
if (code !== 0 && progressCallback) {
|
||||||
|
|||||||
Reference in New Issue
Block a user