release/v1.3.1 #8

Merged
nvrl merged 3 commits from release/v1.3.1 into main 2026-02-21 04:25:16 +01:00
Showing only changes of commit 83dbfce8b2 - Show all commits

View File

@@ -40,6 +40,7 @@ interface Account {
cooldownExpiresAt?: string; cooldownExpiresAt?: string;
authError?: boolean; authError?: boolean;
notes?: string; notes?: string;
sharedWith?: any[];
} }
interface ServerConfig { interface ServerConfig {
@@ -48,6 +49,7 @@ interface ServerConfig {
serverSteamId?: string; serverSteamId?: string;
enabled: boolean; enabled: boolean;
theme?: string; theme?: string;
isAdmin?: boolean;
} }
// --- App State --- // --- App State ---
@@ -94,44 +96,24 @@ const createTray = () => {
const assetsDir = path.join(__dirname, '..', 'assets-build'); const assetsDir = path.join(__dirname, '..', 'assets-build');
const possibleIcons = ['icon.svg', 'icon.png']; const possibleIcons = ['icon.svg', 'icon.png'];
let iconPath = ''; let iconPath = '';
for (const name of possibleIcons) { for (const name of possibleIcons) {
const fullPath = path.join(assetsDir, name); const fullPath = path.join(assetsDir, name);
if (fs.existsSync(fullPath)) { if (fs.existsSync(fullPath)) { iconPath = fullPath; break; }
iconPath = fullPath;
break;
} }
} if (!iconPath) return;
console.log(`[Tray] Attempting to initialize with icon: ${iconPath || 'NONE FOUND'}`);
if (!iconPath) {
console.warn(`[Tray] FAILED: No valid icon found in ${assetsDir}`);
return;
}
try { try {
const icon = nativeImage.createFromPath(iconPath).resize({ width: 16, height: 16 }); const icon = nativeImage.createFromPath(iconPath).resize({ width: 16, height: 16 });
tray = new Tray(icon); tray = new Tray(icon);
tray.setToolTip('Ultimate Ban Tracker'); tray.setToolTip('Ultimate Ban Tracker');
tray.on('click', () => { tray.on('click', () => { if (mainWindow) { mainWindow.show(); mainWindow.focus(); } });
if (mainWindow) {
mainWindow.show();
mainWindow.focus();
}
});
updateTrayMenu(); updateTrayMenu();
console.log(`[Tray] Successfully initialized`); } catch (e) { }
} catch (e: any) {
console.error(`[Tray] Critical error during initialization: ${e.message}`);
}
}; };
const updateTrayMenu = () => { const updateTrayMenu = () => {
if (!tray) return; if (!tray) return;
const accounts = store.get('accounts') as Account[]; const accounts = store.get('accounts') as Account[];
const config = store.get('serverConfig'); const config = store.get('serverConfig');
const contextMenu = Menu.buildFromTemplate([ const contextMenu = Menu.buildFromTemplate([
{ label: `Ultimate Ban Tracker v${app.getVersion()}`, enabled: false }, { label: `Ultimate Ban Tracker v${app.getVersion()}`, enabled: false },
{ type: 'separator' }, { type: 'separator' },
@@ -143,16 +125,11 @@ const updateTrayMenu = () => {
click: () => handleSwitchAccount(acc.loginName) click: () => handleSwitchAccount(acc.loginName)
})) : [{ label: 'No accounts found', enabled: false }] })) : [{ label: 'No accounts found', enabled: false }]
}, },
{ { label: 'Sync Now', enabled: !!config?.enabled, click: () => syncAccounts(true) },
label: 'Sync Now',
enabled: !!config?.enabled,
click: () => syncAccounts()
},
{ type: 'separator' }, { type: 'separator' },
{ label: 'Show Dashboard', click: () => { if (mainWindow) mainWindow.show(); } }, { label: 'Show Dashboard', click: () => { if (mainWindow) mainWindow.show(); } },
{ label: 'Quit', click: () => { (app as any).isQuitting = true; app.quit(); } } { label: 'Quit', click: () => { (app as any).isQuitting = true; app.quit(); } }
]); ]);
tray.setContextMenu(contextMenu); tray.setContextMenu(contextMenu);
}; };
@@ -192,29 +169,21 @@ const handleSwitchAccount = async (loginName: string) => {
const scrapeAccountData = async (account: Account) => { const scrapeAccountData = async (account: Account) => {
const now = new Date(); const now = new Date();
try { try {
// 1. Refresh Basic Profile & Bans
const profile = await fetchProfileData(account.steamId, account.steamLoginSecure); const profile = await fetchProfileData(account.steamId, account.steamLoginSecure);
const bans = await scrapeBanStatus(profile.profileUrl, account.steamLoginSecure); const bans = await scrapeBanStatus(profile.profileUrl, account.steamLoginSecure);
account.personaName = profile.personaName; account.profileUrl = profile.profileUrl;
account.personaName = profile.personaName; account.vacBanned = bans.vacBanned; account.gameBans = bans.gameBans;
account.profileUrl = profile.profileUrl;
account.vacBanned = bans.vacBanned;
account.gameBans = bans.gameBans;
account.status = (bans.vacBanned || bans.gameBans > 0) ? 'banned' : 'none'; account.status = (bans.vacBanned || bans.gameBans > 0) ? 'banned' : 'none';
account.lastBanCheck = now.toISOString(); account.lastBanCheck = now.toISOString();
if (profile.avatar && (!account.localAvatar || profile.avatar !== account.avatar)) { if (profile.avatar && (!account.localAvatar || profile.avatar !== account.avatar)) {
account.avatar = profile.avatar; account.avatar = profile.avatar;
const localPath = await downloadAvatar(account.steamId, profile.avatar); const localPath = await downloadAvatar(account.steamId, profile.avatar);
if (localPath) account.localAvatar = localPath; if (localPath) account.localAvatar = localPath;
} }
// 2. Refresh Cooldowns if session is active
if (account.steamLoginSecure) { if (account.steamLoginSecure) {
try { try {
const result = await scrapeCooldown(account.steamId, account.steamLoginSecure); const result = await scrapeCooldown(account.steamId, account.steamLoginSecure);
account.authError = false; account.authError = false; account.lastScrapeTime = now.toISOString();
account.lastScrapeTime = now.toISOString();
if (result.isActive) { if (result.isActive) {
account.cooldownExpiresAt = result.expiresAt ? result.expiresAt.toISOString() : new Date(Date.now() + 86400000).toISOString(); account.cooldownExpiresAt = result.expiresAt ? result.expiresAt.toISOString() : new Date(Date.now() + 86400000).toISOString();
if (backend) await backend.pushCooldown(account.steamId, account.cooldownExpiresAt); if (backend) await backend.pushCooldown(account.steamId, account.cooldownExpiresAt);
@@ -226,12 +195,9 @@ const scrapeAccountData = async (account: Account) => {
if (e.message.includes('cookie') || e.message.includes('Sign In')) account.authError = true; if (e.message.includes('cookie') || e.message.includes('Sign In')) account.authError = true;
} }
} }
// 3. Share updated state with backend
if (backend && !account._id.startsWith('shared_')) { if (backend && !account._id.startsWith('shared_')) {
await backend.shareAccount(account); await backend.shareAccount(account);
} }
return true; return true;
} catch (e) { } catch (e) {
console.error(`[Scraper] Failed to scrape ${account.personaName}:`, e); console.error(`[Scraper] Failed to scrape ${account.personaName}:`, e);
@@ -240,7 +206,8 @@ const scrapeAccountData = async (account: Account) => {
}; };
// --- Sync Worker --- // --- Sync Worker ---
const syncAccounts = async () => { const syncAccounts = async (isManual = false) => {
console.log(`[Sync] Phase 1: Pulling from server...`);
initBackend(); initBackend();
let accounts = store.get('accounts') as Account[]; let accounts = store.get('accounts') as Account[];
let hasChanges = false; let hasChanges = false;
@@ -252,12 +219,13 @@ const syncAccounts = async () => {
const exists = accounts.find(a => a.steamId === s.steamId); const exists = accounts.find(a => a.steamId === s.steamId);
if (!exists) { if (!exists) {
accounts.push({ accounts.push({
_id: `shared_${s.steamId}`, _id: `shared_${s.steamId}`, steamId: s.steamId, personaName: s.personaName,
steamId: s.steamId, personaName: s.personaName, avatar: s.avatar, profileUrl: s.profileUrl, avatar: s.avatar, profileUrl: s.profileUrl, vacBanned: s.vacBanned,
vacBanned: s.vacBanned, gameBans: s.gameBans, cooldownExpiresAt: s.cooldownExpiresAt, gameBans: s.gameBans, cooldownExpiresAt: s.cooldownExpiresAt,
loginName: s.loginName || '', steamLoginSecure: s.steamLoginSecure, loginConfig: s.loginConfig, loginName: s.loginName || '', steamLoginSecure: s.steamLoginSecure,
sessionUpdatedAt: s.sessionUpdatedAt, autoCheckCooldown: !!s.steamLoginSecure, loginConfig: s.loginConfig, sessionUpdatedAt: s.sessionUpdatedAt,
status: (s.vacBanned || s.gameBans > 0) ? 'banned' : 'none', lastBanCheck: new Date().toISOString() autoCheckCooldown: !!s.steamLoginSecure, status: (s.vacBanned || s.gameBans > 0) ? 'banned' : 'none',
lastBanCheck: new Date().toISOString(), sharedWith: s.sharedWith
}); });
hasChanges = true; hasChanges = true;
} else { } else {
@@ -274,6 +242,10 @@ const syncAccounts = async () => {
exists.cooldownExpiresAt = s.cooldownExpiresAt; exists.cooldownExpiresAt = s.cooldownExpiresAt;
hasChanges = true; hasChanges = true;
} }
if (JSON.stringify(exists.sharedWith) !== JSON.stringify(s.sharedWith)) {
exists.sharedWith = s.sharedWith;
hasChanges = true;
}
} }
} }
} catch (e) { } } catch (e) { }
@@ -285,47 +257,39 @@ const syncAccounts = async () => {
updateTrayMenu(); updateTrayMenu();
} }
if (accounts.length === 0) return; // Phase 2: Background Scrapes
const runScrapes = async () => {
const updatedAccounts = [...accounts]; console.log(`[Sync] Phase 2: Starting background checks for ${accounts.length} accounts...`);
const currentAccounts = [...store.get('accounts') as Account[]];
let scrapeChanges = false; let scrapeChanges = false;
for (const account of currentAccounts) {
for (const account of updatedAccounts) {
try { try {
const now = new Date(); const now = new Date();
if (backend && !account._id.startsWith('shared_')) await backend.shareAccount(account);
// OPTIMIZATION: Ensure ALL authenticated accounts are shared with the server on every sync cycle
if (backend && !account._id.startsWith('shared_')) {
await backend.shareAccount(account);
}
const lastCheck = account.lastBanCheck ? new Date(account.lastBanCheck) : new Date(0); const lastCheck = account.lastBanCheck ? new Date(account.lastBanCheck) : new Date(0);
if ((now.getTime() - lastCheck.getTime()) / 3600000 > 6 || !account.personaName) {
await scrapeAccountData(account);
scrapeChanges = true;
}
if (account.autoCheckCooldown && account.steamLoginSecure) {
if (account.cooldownExpiresAt && new Date(account.cooldownExpiresAt) > now) continue;
const lastScrape = account.lastScrapeTime ? new Date(account.lastScrapeTime) : new Date(0); const lastScrape = account.lastScrapeTime ? new Date(account.lastScrapeTime) : new Date(0);
if ((now.getTime() - lastScrape.getTime()) / 3600000 > 8) { const needsMetadata = (now.getTime() - lastCheck.getTime()) / 3600000 > 6 || !account.personaName;
await new Promise(r => setTimeout(r, Math.floor(Math.random() * 60000) + 5000)); const needsCooldown = account.autoCheckCooldown && account.steamLoginSecure && (now.getTime() - lastScrape.getTime()) / 3600000 > 8;
await scrapeAccountData(account);
scrapeChanges = true; if (needsMetadata || needsCooldown || isManual) {
} if (!isManual && needsCooldown) await new Promise(r => setTimeout(r, Math.floor(Math.random() * 30000) + 5000));
if (await scrapeAccountData(account)) scrapeChanges = true;
} }
} catch (error) { } } catch (error) { }
} }
if (scrapeChanges) { if (scrapeChanges) {
store.set('accounts', updatedAccounts); store.set('accounts', currentAccounts);
if (mainWindow) mainWindow.webContents.send('accounts-updated', updatedAccounts); if (mainWindow) mainWindow.webContents.send('accounts-updated', currentAccounts);
updateTrayMenu(); updateTrayMenu();
} }
console.log('[Sync] Sync cycle finished.');
};
if (isManual) await runScrapes(); else runScrapes();
}; };
const scheduleNextSync = () => { const scheduleNextSync = () => {
setTimeout(async () => { await syncAccounts(); scheduleNextSync(); }, isDev ? 120000 : 1800000); setTimeout(async () => { await syncAccounts(false); scheduleNextSync(); }, isDev ? 300000 : 1800000);
}; };
// --- Discovery --- // --- Discovery ---
@@ -364,28 +328,21 @@ const handleLocalAccountsFound = async (localAccounts: LocalSteamAccount[]) => {
} }
}; };
// --- Main Window Creation --- // --- Main Window ---
function createWindow() { function createWindow() {
mainWindow = new BrowserWindow({ mainWindow = new BrowserWindow({
width: 1280, height: 800, title: "Ultimate Ban Tracker", backgroundColor: '#171a21', autoHideMenuBar: true, width: 1280, height: 800, title: "Ultimate Ban Tracker", backgroundColor: '#171a21', autoHideMenuBar: true,
webPreferences: { preload: path.join(__dirname, 'preload.js'), nodeIntegration: false, contextIsolation: true } webPreferences: { preload: path.join(__dirname, 'preload.js'), nodeIntegration: false, contextIsolation: true }
}); });
mainWindow.setMenu(null); mainWindow.setMenu(null);
mainWindow.on('close', (event) => { mainWindow.on('close', (event) => {
if (!(app as any).isQuitting) { if (!(app as any).isQuitting) { event.preventDefault(); mainWindow?.hide(); }
event.preventDefault();
mainWindow?.hide();
}
return false; return false;
}); });
if (isDev) mainWindow.loadURL('http://localhost:5173'); if (isDev) mainWindow.loadURL('http://localhost:5173');
else mainWindow.loadFile(path.join(__dirname, '..', 'dist', 'index.html')); else mainWindow.loadFile(path.join(__dirname, '..', 'dist', 'index.html'));
} }
// --- App Lifecycle ---
app.whenReady().then(() => { app.whenReady().then(() => {
protocol.handle('steam-resource', (request) => { protocol.handle('steam-resource', (request) => {
let rawPath = decodeURIComponent(request.url.replace('steam-resource://', '')); let rawPath = decodeURIComponent(request.url.replace('steam-resource://', ''));
@@ -394,11 +351,10 @@ app.whenReady().then(() => {
if (!fs.existsSync(absolutePath)) return new Response('Not Found', { status: 404 }); if (!fs.existsSync(absolutePath)) return new Response('Not Found', { status: 404 });
try { return net.fetch(pathToFileURL(absolutePath).toString()); } catch (e) { return new Response('Error', { status: 500 }); } try { return net.fetch(pathToFileURL(absolutePath).toString()); } catch (e) { return new Response('Error', { status: 500 }); }
}); });
createWindow(); createWindow();
createTray(); createTray();
initBackend(); initBackend();
setTimeout(syncAccounts, 5000); setTimeout(() => syncAccounts(false), 5000);
scheduleNextSync(); scheduleNextSync();
steamClient.startWatching(handleLocalAccountsFound); steamClient.startWatching(handleLocalAccountsFound);
}); });
@@ -423,19 +379,17 @@ ipcMain.handle('login-to-server', async () => {
if (!config.url) return false; if (!config.url) return false;
return new Promise<boolean>((resolve) => { return new Promise<boolean>((resolve) => {
const authWindow = new BrowserWindow({ const authWindow = new BrowserWindow({
width: 800, height: 700, parent: mainWindow || undefined, modal: true, title: 'Login to Ban Tracker Server', width: 800, height: 700, parent: mainWindow || undefined, modal: true, title: 'Login to Server',
webPreferences: { nodeIntegration: false, contextIsolation: true } webPreferences: { nodeIntegration: false, contextIsolation: true }
}); });
authWindow.loadURL(`${config.url}/auth/steam`); authWindow.loadURL(`${config.url}/auth/steam`);
let captured = false; let captured = false;
const saveServerAuth = (token: string) => { const saveServerAuth = (token: string) => {
if (captured) return; captured = true; if (captured) return; captured = true;
let serverSteamId = undefined; let serverSteamId = undefined; let isAdmin = false;
let isAdmin = false;
try { try {
const payload = JSON.parse(Buffer.from(token.split('.')[1]!, 'base64').toString()); const payload = JSON.parse(Buffer.from(token.split('.')[1]!, 'base64').toString());
serverSteamId = payload.steamId; serverSteamId = payload.steamId; isAdmin = !!payload.isAdmin;
isAdmin = !!payload.isAdmin;
} catch (e) {} } catch (e) {}
const current = store.get('serverConfig'); const current = store.get('serverConfig');
store.set('serverConfig', { ...current, token, serverSteamId, isAdmin, enabled: true }); store.set('serverConfig', { ...current, token, serverSteamId, isAdmin, enabled: true });
@@ -458,14 +412,12 @@ ipcMain.handle('login-to-server', async () => {
}); });
ipcMain.handle('get-server-user-info', () => ({ steamId: store.get('serverConfig').serverSteamId })); ipcMain.handle('get-server-user-info', () => ({ steamId: store.get('serverConfig').serverSteamId }));
ipcMain.handle('sync-now', async () => { await syncAccounts(); return true; }); ipcMain.handle('sync-now', async () => { await syncAccounts(true); return true; });
ipcMain.handle('scrape-account', async (event, steamId: string) => { ipcMain.handle('scrape-account', async (event, steamId: string) => {
const accounts = store.get('accounts') as Account[]; const accounts = store.get('accounts') as Account[];
const account = accounts.find(a => a.steamId === steamId); const account = accounts.find(a => a.steamId === steamId);
if (!account) return false; if (!account) return false;
console.log(`[Main] Manually triggering scrape for ${account.personaName}...`);
const success = await scrapeAccountData(account); const success = await scrapeAccountData(account);
if (success) { if (success) {
store.set('accounts', accounts); store.set('accounts', accounts);
@@ -491,7 +443,7 @@ ipcMain.handle('add-account', async (event, { identifier }) => {
loginName: existing.loginName || '', steamLoginSecure: existing.steamLoginSecure, loginName: existing.loginName || '', steamLoginSecure: existing.steamLoginSecure,
loginConfig: existing.loginConfig, sessionUpdatedAt: existing.sessionUpdatedAt, loginConfig: existing.loginConfig, sessionUpdatedAt: existing.sessionUpdatedAt,
autoCheckCooldown: !!existing.steamLoginSecure, status: (existing.vacBanned || existing.gameBans > 0) ? 'banned' : 'none', autoCheckCooldown: !!existing.steamLoginSecure, status: (existing.vacBanned || existing.gameBans > 0) ? 'banned' : 'none',
lastBanCheck: new Date().toISOString() lastBanCheck: new Date().toISOString(), sharedWith: existing.sharedWith
}; };
store.set('accounts', [...accounts, newAccount]); store.set('accounts', [...accounts, newAccount]);
updateTrayMenu(); updateTrayMenu();
@@ -565,60 +517,35 @@ ipcMain.handle('switch-account', async (event, loginName: string) => await handl
ipcMain.handle('open-external', (event, url: string) => shell.openExternal(url)); ipcMain.handle('open-external', (event, url: string) => shell.openExternal(url));
ipcMain.handle('open-steam-app-login', async () => { ipcMain.handle('open-steam-app-login', async () => {
console.log('[SteamClient] Preparing for fresh login...');
await killSteam(); await killSteam();
if (process.platform === 'win32') { if (process.platform === 'win32') {
// Clear auto-login registry
const clearReg = 'reg add "HKCU\\Software\\Valve\\Steam" /v AutoLoginUser /t REG_SZ /d "" /f'; const clearReg = 'reg add "HKCU\\Software\\Valve\\Steam" /v AutoLoginUser /t REG_SZ /d "" /f';
await new Promise<void>((res) => exec(clearReg, () => res())); await new Promise<void>((res) => exec(clearReg, () => res()));
} else if (process.platform === 'linux') { } else if (process.platform === 'linux') {
// On Linux we can use the steamClient helper to set an empty user
await steamClient.setAutoLoginUser("", undefined, ""); await steamClient.setAutoLoginUser("", undefined, "");
} }
const command = process.platform === 'win32' ? 'start steam://open/login' : 'xdg-open steam://open/login'; const command = process.platform === 'win32' ? 'start steam://open/login' : 'xdg-open steam://open/login';
exec(command); exec(command);
return true; return true;
}); });
ipcMain.handle('open-steam-login', async (event, expectedSteamId: string) => { ipcMain.handle('open-steam-login', async (event, expectedSteamId: string) => {
// Use a unique partition per account to prevent session bleeding
const partitionId = expectedSteamId ? `persist:steam-login-${expectedSteamId}` : 'persist:steam-login-new'; const partitionId = expectedSteamId ? `persist:steam-login-${expectedSteamId}` : 'persist:steam-login-new';
const loginSession = session.fromPartition(partitionId); const loginSession = session.fromPartition(partitionId);
if (!expectedSteamId) await loginSession.clearStorageData({ storages: ['cookies', 'localstorage', 'indexdb'] });
// If adding a brand new account, explicitly clear previous trash
if (!expectedSteamId) {
console.log('[Auth] Clearing session for new account login...');
await loginSession.clearStorageData({ storages: ['cookies', 'localstorage', 'indexdb'] });
}
// If we have an existing cookie string for this account, pre-inject it
if (expectedSteamId) { if (expectedSteamId) {
const accounts = store.get('accounts') as Account[]; const accounts = store.get('accounts') as Account[];
const account = accounts.find(a => a.steamId === expectedSteamId); const account = accounts.find(a => a.steamId === expectedSteamId);
if (account?.steamLoginSecure) { if (account?.steamLoginSecure) {
console.log(`[Auth] Pre-injecting existing cookies for ${account.personaName}...`);
const cookiePairs = account.steamLoginSecure.split(';').map(c => c.trim()); const cookiePairs = account.steamLoginSecure.split(';').map(c => c.trim());
for (const pair of cookiePairs) { for (const pair of cookiePairs) {
const [name, value] = pair.split('='); const [name, value] = pair.split('=');
if (name && value) { if (name && value) {
try { try { await loginSession.cookies.set({ url: 'https://steamcommunity.com', domain: 'steamcommunity.com', name, value, path: '/', secure: true, httpOnly: name.includes('Secure') }); } catch (e) {}
await loginSession.cookies.set({
url: 'https://steamcommunity.com',
domain: 'steamcommunity.com',
name: name,
value: value,
path: '/',
secure: true,
httpOnly: name.includes('Secure')
});
} catch (e) {}
} }
} }
} }
} }
return new Promise<boolean>((resolve) => { return new Promise<boolean>((resolve) => {
const loginWindow = new BrowserWindow({ const loginWindow = new BrowserWindow({
width: 800, height: 700, parent: mainWindow || undefined, modal: true, title: 'Login to Steam', width: 800, height: 700, parent: mainWindow || undefined, modal: true, title: 'Login to Steam',