Skip to content

Commit

Permalink
check steam auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Armaldio committed Jan 9, 2025
1 parent 95dacd3 commit 61cf648
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 23 deletions.
61 changes: 38 additions & 23 deletions src/shared/libs/plugin-steam/upload-to-steam.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createAction, createActionRunner, runWithLiveLogs } from '@pipelab/plugin-core'
import { checkSteamAuth } from './utils'

// https://github.com/ztgasdf/steampkg?tab=readme-ov-file#account-management

Expand Down Expand Up @@ -85,6 +86,8 @@ export const uploadToSteamRunner = createActionRunner<typeof uploadToSteam>(
const { join, dirname } = await import('path')
const { platform } = await import('os')
const { chmod, mkdir, writeFile } = await import('fs/promises')
// for esm
const { execa } = await import('execa')

log('uploading to steam')
const { folder, appId, sdk, depotId, username, description } = inputs
Expand Down Expand Up @@ -180,6 +183,37 @@ export const uploadToSteamRunner = createActionRunner<typeof uploadToSteam>(
await chmod(steamcmdPath, 0o755)
}

// check for steam authentication
const isAuthenticated = await checkSteamAuth({
context: {
log
},
scriptPath,
steamcmdPath,
username
})

console.log('isAuthenticated', isAuthenticated)

if (isAuthenticated.success === false) {
await execa({
detached: true,
stdio: 'inherit'
})`echo Enter your password && read password`
// console.log('isAuthenticated.error', isAuthenticated.error)
// if (error === 'LOGGED_OUT') {
// options.context.log('You are not logged in to Steam')
// options.context.log('To log in, run command below:')
// options.context.log(`"${options.steamcmdPath}" +login ${options.username} +quit`)
// throw new Error(
// 'You are not logged in to Steam\nTo log in, run command below:\n' +
// `"${options.steamcmdPath}" +login ${options.username} +quit`
// )
// } else {
// throw new Error('Unknown error: ' + isAuthenticated.error)
// }
}

log('Writing script')
await writeFile(scriptPath, script, 'utf8')

Expand Down Expand Up @@ -207,33 +241,14 @@ export const uploadToSteamRunner = createActionRunner<typeof uploadToSteam>(
}
)
} catch (e) {
console.error(e)
if (!error) {
error = 'UNKNOWN'
}
}

console.warn('error', error)

if (error) {
if (error === 'LOGGED_OUT') {
log('You are not logged in to Steam')
log('To log in, run command below:')
log(`"${steamcmdPath}" +login ${username} +quit`)
throw new Error(
'You are not logged in to Steam\nTo log in, run command below:\n' +
`"${steamcmdPath}" +login ${username} +quit`
)
if (e instanceof Error) {
console.error(e)
throw new Error('Error:' + e.message)
} else {
throw new Error('Unknown error')
throw new Error('unknwon error')
}
}

// // must keep that to not be interactive
// await execa(steamcmdPath, ['+login', username, '+run_app_build', scriptPath, '+quit'], {
// stdout: 'inherit',
// stderr: 'inherit'
// })
log('Done uploading')
}
)
53 changes: 53 additions & 0 deletions src/shared/libs/plugin-steam/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { runWithLiveLogs } from '../plugin-core'

export type Options = {
steamcmdPath: string
username: string
scriptPath: string
context: {
log: typeof console.log
}
}

export const checkSteamAuth = async (options: Options) => {
let error: 'LOGGED_OUT' | 'UNKNOWN' | undefined = undefined

try {
await runWithLiveLogs(
options.steamcmdPath,
['+login', options.username, '+quit'],
{},
options.context.log,
{
onStdout: (data, subprocess) => {
options.context.log('data stdout', data)

// TODO: handle password input dynamically
if (data.includes('Cached credentials not found')) {
error = 'LOGGED_OUT'

subprocess.kill()
}
}
}
)
} catch (e) {
console.error('e', e)
if (!error) {
error = 'UNKNOWN'
}
}

console.warn('error', error)

if (error) {
return {
success: false,
error
}
}

return {
success: true
}
}

0 comments on commit 61cf648

Please sign in to comment.