fix: invalid generated token that caused hangs on exit [windows testing needed]

This commit is contained in:
Fazri Gading
2026-02-01 19:26:24 +08:00
parent ad34741627
commit ecaaa28866

View File

@@ -1,6 +1,5 @@
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const crypto = require('crypto');
const { exec } = require('child_process'); const { exec } = require('child_process');
const { promisify } = require('util'); const { promisify } = require('util');
const { spawn } = require('child_process'); const { spawn } = require('child_process');
@@ -69,53 +68,11 @@ async function fetchAuthTokens(uuid, name) {
}; };
} catch (error) { } catch (error) {
console.error('Failed to fetch auth tokens:', error.message); console.error('Failed to fetch auth tokens:', error.message);
// Fallback to local generation if server unavailable // Don't use invalid local tokens that cause the game to hang
return generateLocalTokens(uuid, name); throw new Error(`Authentication server unavailable: ${error.message}. Please check your internet connection or try again later.`);
} }
} }
// Fallback: Generate tokens locally (won't pass signature validation but allows offline testing)
function generateLocalTokens(uuid, name) {
console.log('Using locally generated tokens (fallback mode)');
const authServerUrl = getAuthServerUrl();
const now = Math.floor(Date.now() / 1000);
const exp = now + 36000;
const header = Buffer.from(JSON.stringify({
alg: 'EdDSA',
kid: '2025-10-01',
typ: 'JWT'
})).toString('base64url');
const identityPayload = Buffer.from(JSON.stringify({
sub: uuid,
name: name,
username: name,
entitlements: ['game.base'],
scope: 'hytale:server hytale:client',
iat: now,
exp: exp,
iss: authServerUrl,
jti: uuidv4()
})).toString('base64url');
const sessionPayload = Buffer.from(JSON.stringify({
sub: uuid,
scope: 'hytale:server',
iat: now,
exp: exp,
iss: authServerUrl,
jti: uuidv4()
})).toString('base64url');
const signature = crypto.randomBytes(64).toString('base64url');
return {
identityToken: `${header}.${identityPayload}.${signature}`,
sessionToken: `${header}.${sessionPayload}.${signature}`
};
}
async function launchGame(playerNameOverride = null, progressCallback, javaPathOverride, installPathOverride, gpuPreference = 'auto', branchOverride = null) { async function launchGame(playerNameOverride = null, progressCallback, javaPathOverride, installPathOverride, gpuPreference = 'auto', branchOverride = null) {
// ========================================================================== // ==========================================================================
// STEP 1: Validate player identity FIRST (before any other operations) // STEP 1: Validate player identity FIRST (before any other operations)