Updating to use new SteamCmd class

This commit is contained in:
ilumos 2017-09-03 20:36:02 +01:00
parent 3228d709ad
commit 22d9553070
2 changed files with 46 additions and 58 deletions

View file

@ -3,8 +3,8 @@
namespace Zeropingheroes\LancacheAutofill\Commands\Steam;
use Illuminate\Console\Command;
use Symfony\Component\Process\Process;
use Zeropingheroes\LancacheAutofill\Models\SteamAccount;
use Zeropingheroes\LancacheAutofill\Services\SteamCmd\SteamCmd;
class AuthoriseAccount extends Command
{
@ -31,28 +31,24 @@ class AuthoriseAccount extends Command
{
$account = $this->argument('account');
if( ! $account ){
if (!$account) {
$account = $this->ask('Please enter your Steam username');
}
$this->info('Authorising account '.$account);
$password = $this->secret('Please enter your password');
$steamGuardCode = $this->ask('Please enter your Steam Guard code', false);
$guard = $this->ask('Please enter your Steam Guard code (optional)', false);
// Start SteamCMD with the arguments, using "unbuffer"
// as SteamCMD buffers output when it is not run in a
// tty, which prevents us showing output line by line
$process = new Process('unbuffer '.getenv('STEAMCMD_PATH').' +login '.$account.' '.$password.' '.$steamGuardCode.' +quit');
// Set a short timeout for this interactive login prompt
$process->setTimeout(120);
$steamCmd = (new SteamCmd(getenv('STEAMCMD_PATH')))
->login($account, $password, $guard)
->run();
// Show SteamCMD output line by line
$process->run(function ($type, $buffer) {
$steamCmd->run(function ($type, $buffer) {
$this->line(str_replace(["\r", "\n"], '', $buffer));
});
if (!$process->isSuccessful()) {
if (!$steamCmd->isSuccessful()) {
$this->error('Failed to authorise Steam account '.$account);
die();
}

View file

@ -5,7 +5,7 @@ namespace Zeropingheroes\LancacheAutofill\Commands\Steam;
use Illuminate\Console\Command;
use Illuminate\Database\Capsule\Manager as Capsule;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
use Zeropingheroes\LancacheAutofill\Services\SteamCmd\SteamCmd;
class StartDownloading extends Command
{
@ -36,23 +36,7 @@ class StartDownloading extends Command
die();
}
// Check all Steam accounts specified in the accounts table are authorised
$this->info('Checking all Steam accounts are authorised');
foreach ($this->steamAccounts() as $account) {
$process = new Process('unbuffer '.getenv('STEAMCMD_PATH').' +@NoPromptForPassword 1 +login '.$account.' +quit');
// Show SteamCMD output line by line
$process->run(function ($type, $buffer) {
$this->line(str_replace(["\r", "\n"], '', $buffer));
});
if (!$process->isSuccessful()) {
$this->error('Steam account '.$account.' is not authorised');
$this->comment('Please re-run "./lancache-autofill steam:authorise-account '.$account.'"');
die();
}
$this->info('Steam account '.$account.' is authorised and will be used to download apps');
}
$this->checkSteamAccountsAreAuthorised();
// Loop through all apps in the queue
while ($item = $this->nextApp()) {
@ -139,44 +123,52 @@ class StartDownloading extends Command
* Start a Steam download
*
* @param $appId
* @param $account
* @param $platform
* @param $account
* @throws ProcessFailedException
*/
private function download($appId, $platform, $account)
{
$arguments =
[
'login' => $account,
'@sSteamCmdForcePlatformType' => $platform,
'@NoPromptForPassword' => 1,
'force_install_dir' => getenv('DOWNLOADS_DIRECTORY').'/'.$platform.'/'.$appId,
'app_license_request' => $appId,
'app_update' => $appId,
'quit' => null,
];
// Build argument string
foreach ($arguments as $argument => $value) {
$argumentString .= "+$argument $value ";
}
// Start SteamCMD with the arguments, using "unbuffer"
// as SteamCMD buffers output when it is not run in a
// tty, which prevents us showing output line by line
$download = new Process('unbuffer '.getenv('STEAMCMD_PATH').' '.$argumentString);
// Set a long timeout as downloading could take a while
$download->setTimeout(14400);
$download->setIdleTimeout(60);
$steamCmd = (new SteamCmd(getenv('STEAMCMD_PATH')))
->login($account)
->platform($platform)
->directory(getenv('DOWNLOADS_DIRECTORY').'/'.$platform.'/'.$appId)
->update($appId)
->run();
// Show SteamCMD output line by line
$download->run(function ($type, $buffer) {
$steamCmd->run(function ($type, $buffer) {
$this->line(str_replace(["\r", "\n"], '', $buffer));
});
if (!$download->isSuccessful()) {
throw new ProcessFailedException($download);
if (!$steamCmd->isSuccessful()) {
throw new ProcessFailedException($steamCmd);
}
}
/**
* Check all Steam accounts specified in the accounts table are authorised
*/
private function checkSteamAccountsAreAuthorised()
{
$this->info('Checking all Steam accounts are authorised');
foreach ($this->steamAccounts() as $account) {
$steamCmd = (new SteamCmd(getenv('STEAMCMD_PATH')))
->login($account)
->run();
// Show SteamCMD output line by line
$steamCmd->run(function ($type, $buffer) {
$this->line(str_replace(["\r", "\n"], '', $buffer));
});
if (!$steamCmd->isSuccessful()) {
$this->error('Steam account '.$account.' is not authorised');
$this->comment('Please re-run "./lancache-autofill steam:authorise-account '.$account.'"');
die();
}
$this->info('Steam account '.$account.' is authorised and will be used to download apps');
}
}
}