Skip to content

Commit ec25d46

Browse files
author
Simeon Kummer
committed
add access token for login
1 parent 826dd0e commit ec25d46

File tree

3 files changed

+51
-6
lines changed

3 files changed

+51
-6
lines changed

launch.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ def parse_arguments():
88
parser = argparse.ArgumentParser(description="Minecraft Launcher Script")
99
parser.add_argument('--uuid', type=str, required=True, help='MCID (UUID) der Person')
1010
parser.add_argument('--name', type=str, required=True, help='Name des Spielers')
11+
parser.add_argument('--token', type=str, required=False, help='Access Token für Online-Server')
1112
parser.add_argument('--launch-only', action='store_true', help='Nur Spiel starten, keine Installation')
1213
return parser.parse_args()
1314

14-
# Zufälliges Token generieren (kann auch immer 0 sein, wenn gewünscht)
15+
# Zufälliges Token generieren (nur als Fallback für Offline-Modus)
1516
def generate_token():
1617
return str(random.randint(0, 1000000)) # Beispiel für zufälliges Token, hier eine Zufallszahl
1718

@@ -32,9 +33,15 @@ def main():
3233
options = {
3334
"username": args.name,
3435
"uuid": args.uuid,
35-
"token": generate_token(), # Token generieren
36+
"token": args.token if args.token else generate_token(), # Verwende echten Token oder Fallback
3637
}
3738

39+
# Log token status for debugging
40+
if args.token:
41+
print(f"Using fresh Microsoft access token for online server support")
42+
else:
43+
print(f"No access token provided - using offline mode (cracked account)")
44+
3845
# Minecraft-Startbefehl holen
3946
minecraft_command = minecraft_launcher_lib.command.get_minecraft_command("fabric-loader-0.16.14-1.21.5", minecraft_directory, options)
4047
print(" ".join(minecraft_command)) # Kommando ausgeben

src/main.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ ipcMain.handle('login-microsoft', async () => {
101101
// Extract necessary data from the Minecraft profile
102102
const accountData = {
103103
uuid: minecraftProfile.profile.id,
104-
name: minecraftProfile.profile.name
104+
name: minecraftProfile.profile.name,
105+
refreshToken: xbox.save() // Save refresh token instead of access token
105106
};
106107

107108
// Save account data - ensure directory exists first
@@ -138,7 +139,11 @@ ipcMain.handle('login-cracked', async () => {
138139
const uuid = uuidv4();
139140
const name = "dev";
140141

141-
const accountData = { uuid, name };
142+
const accountData = {
143+
uuid,
144+
name,
145+
refreshToken: null // Cracked accounts don't have refresh tokens
146+
};
142147

143148
// Save account data - ensure directory exists first
144149
const accountsDirectory = path.dirname(INSTALL_DIR);
@@ -158,6 +163,33 @@ ipcMain.handle('launch-minecraft', async (event, { uuid, name }) => {
158163
try {
159164
const minecraftStarter = new MinecraftStarter();
160165

166+
// Get fresh access token if this is a Microsoft account
167+
let accessToken = null;
168+
const accountsPath = path.join(path.dirname(INSTALL_DIR), 'accounts.json');
169+
170+
if (fs.existsSync(accountsPath)) {
171+
try {
172+
const accountData = JSON.parse(fs.readFileSync(accountsPath, 'utf8'));
173+
174+
// Check if this is a Microsoft account with a refresh token
175+
if (accountData.refreshToken) {
176+
try {
177+
// Use refresh token to get fresh access token
178+
const authManager = new Auth("select_account");
179+
const xbox = await authManager.refresh(accountData.refreshToken);
180+
const minecraftProfile = await xbox.getMinecraft();
181+
accessToken = minecraftProfile.access_token;
182+
console.log('Got fresh access token using refresh token');
183+
} catch (error) {
184+
console.warn('Failed to refresh access token, launching in offline mode:', error);
185+
// Continue without token - will work for offline servers
186+
}
187+
}
188+
} catch (error) {
189+
console.warn('Could not load account data:', error);
190+
}
191+
}
192+
161193
// Check if BlitzClient directory exists
162194
const blitzClientPath = path.dirname(INSTALL_DIR);
163195
const minecraftPath = path.join(blitzClientPath, 'minecraft');
@@ -177,7 +209,7 @@ ipcMain.handle('launch-minecraft', async (event, { uuid, name }) => {
177209
}
178210

179211
// Launch Minecraft
180-
const minecraftProcess = minecraftStarter.run(uuid, name);
212+
const minecraftProcess = minecraftStarter.run(uuid, name, accessToken);
181213

182214
// If minecraft directory doesn't exist, download mods after startup
183215
if (!fs.existsSync(minecraftPath)) {

src/minecraftStarter.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ class MinecraftStarter {
300300
}
301301
}
302302

303-
async run(uuid, name) {
303+
async run(uuid, name, accessToken) {
304304
try {
305305
const installDir = path.resolve(this.INSTALL_DIR);
306306
const parentDir = path.dirname(installDir);
@@ -317,6 +317,12 @@ class MinecraftStarter {
317317
name ? name : 'Whyareyoureadingthis'
318318
];
319319

320+
// Add access token if available
321+
if (accessToken) {
322+
args.push('--token');
323+
args.push(accessToken);
324+
}
325+
320326
// If minecraft directory exists, append --launch-only
321327
if (fs.existsSync(minecraftDir)) {
322328
args.push('--launch-only');

0 commit comments

Comments
 (0)