Skip to content

Commit

Permalink
Updating to use new SteamCmd class
Browse files Browse the repository at this point in the history
  • Loading branch information
ilumos committed Sep 3, 2017
1 parent 3228d70 commit 22d9553
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 58 deletions.
20 changes: 8 additions & 12 deletions src/Commands/Steam/AuthoriseAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -31,28 +31,24 @@ public function handle()
{
$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();
}
Expand Down
84 changes: 38 additions & 46 deletions src/Commands/Steam/StartDownloading.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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
{
Expand Down Expand Up @@ -36,23 +36,7 @@ public function handle()
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()) {
Expand Down Expand Up @@ -139,44 +123,52 @@ private function steamAccounts()
* 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');
}
}
}

0 comments on commit 22d9553

Please sign in to comment.