mirror of
https://github.com/zeropingheroes/lancache-autofill
synced 2024-11-10 02:14:12 +00:00
parent
68d6001838
commit
6ad33cf140
4 changed files with 146 additions and 12 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -6,3 +6,4 @@ database.sqlite
|
|||
.DS_Store
|
||||
.swp
|
||||
*.txt
|
||||
*.bucket
|
|
@ -11,16 +11,17 @@
|
|||
"keywords": ["lanager", "lan", "party", "lancache", "steamcache"],
|
||||
"license": "AGPL-3.0",
|
||||
"require": {
|
||||
"illuminate/console": "5.5.*",
|
||||
"illuminate/support": "5.5.*",
|
||||
"illuminate/container": "5.5.*",
|
||||
"illuminate/events": "5.5.*",
|
||||
"illuminate/database": "5.5.*",
|
||||
"illuminate/translation": "5.5.*",
|
||||
"bandwidth-throttle/token-bucket": "^2.0",
|
||||
"guzzlehttp/guzzle": "^6.3",
|
||||
"illuminate/console": "5.5.*",
|
||||
"illuminate/container": "5.5.*",
|
||||
"illuminate/database": "5.5.*",
|
||||
"illuminate/events": "5.5.*",
|
||||
"illuminate/support": "5.5.*",
|
||||
"illuminate/translation": "5.5.*",
|
||||
"symfony/process": "^3.3",
|
||||
"vlucas/phpdotenv": "^2.4",
|
||||
"syntax/steam-api": "2.0.*"
|
||||
"syntax/steam-api": "2.0.*",
|
||||
"vlucas/phpdotenv": "^2.4"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {"Zeropingheroes\\LancacheAutofill\\": "src/"}
|
||||
|
@ -37,4 +38,4 @@
|
|||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true
|
||||
}
|
||||
}
|
||||
|
|
117
composer.lock
generated
117
composer.lock
generated
|
@ -4,8 +4,64 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "a67ae95addd33b471f75b6722fe32b6e",
|
||||
"content-hash": "bc39ae19d7d209f1f067847f7f22e792",
|
||||
"packages": [
|
||||
{
|
||||
"name": "bandwidth-throttle/token-bucket",
|
||||
"version": "2.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/bandwidth-throttle/token-bucket.git",
|
||||
"reference": "a0c31a4d0fbcf0c1a68c895fc91bf71455bcec08"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/bandwidth-throttle/token-bucket/zipball/a0c31a4d0fbcf0c1a68c895fc91bf71455bcec08",
|
||||
"reference": "a0c31a4d0fbcf0c1a68c895fc91bf71455bcec08",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-bcmath": "*",
|
||||
"malkusch/lock": "^1",
|
||||
"php": ">=5.6"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-redis": "^2.2.4|^3",
|
||||
"mikey179/vfsstream": "^1.5.0",
|
||||
"php-mock/php-mock-phpunit": "^1",
|
||||
"phpunit/phpunit": "^5",
|
||||
"predis/predis": "^1"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"bandwidthThrottle\\tokenBucket\\": "classes/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"WTFPL"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Markus Malkusch",
|
||||
"email": "markus@malkusch.de",
|
||||
"homepage": "http://markus.malkusch.de",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "Implementation of the Token Bucket algorithm.",
|
||||
"homepage": "https://github.com/bandwidth-throttle/token-bucket",
|
||||
"keywords": [
|
||||
"bandwidth",
|
||||
"rate limit",
|
||||
"rate limiting",
|
||||
"throttle",
|
||||
"throttling",
|
||||
"token bucket"
|
||||
],
|
||||
"time": "2017-10-13T19:09:01+00:00"
|
||||
},
|
||||
{
|
||||
"name": "doctrine/inflector",
|
||||
"version": "v1.3.0",
|
||||
|
@ -629,6 +685,65 @@
|
|||
],
|
||||
"time": "2018-11-23T23:41:29+00:00"
|
||||
},
|
||||
{
|
||||
"name": "malkusch/lock",
|
||||
"version": "1.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/malkusch/lock.git",
|
||||
"reference": "5555f291092a0ed5ab4f02d8be7031b877d8d165"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/malkusch/lock/zipball/5555f291092a0ed5ab4f02d8be7031b877d8d165",
|
||||
"reference": "5555f291092a0ed5ab4f02d8be7031b877d8d165",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.6",
|
||||
"psr/log": "^1"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-redis": "^2.2.4|^3",
|
||||
"kriswallsmith/spork": "^0.3",
|
||||
"mikey179/vfsstream": "^1.5.0",
|
||||
"php-mock/php-mock-phpunit": "^1",
|
||||
"phpunit/phpunit": "^5",
|
||||
"predis/predis": "~1.0",
|
||||
"zetacomponents/system-information": "~1.1"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"malkusch\\lock\\": "classes/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"WTFPL"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Markus Malkusch",
|
||||
"email": "markus@malkusch.de",
|
||||
"homepage": "http://markus.malkusch.de",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "Mutex library for exclusive code execution.",
|
||||
"homepage": "https://github.com/malkusch/lock",
|
||||
"keywords": [
|
||||
"cas",
|
||||
"flock",
|
||||
"lock",
|
||||
"memcache",
|
||||
"mutex",
|
||||
"redis",
|
||||
"redlock",
|
||||
"semaphore"
|
||||
],
|
||||
"time": "2016-08-05T11:03:36+00:00"
|
||||
},
|
||||
{
|
||||
"name": "monolog/monolog",
|
||||
"version": "1.24.0",
|
||||
|
|
|
@ -5,6 +5,10 @@ namespace Zeropingheroes\LancacheAutofill\Commands\Steam;
|
|||
use Illuminate\Console\Command;
|
||||
use Zeropingheroes\LancacheAutofill\Models\SteamQueueItem;
|
||||
use Steam;
|
||||
use bandwidthThrottle\tokenBucket\Rate;
|
||||
use bandwidthThrottle\tokenBucket\TokenBucket;
|
||||
use bandwidthThrottle\tokenBucket\BlockingConsumer;
|
||||
use bandwidthThrottle\tokenBucket\storage\FileStorage;
|
||||
|
||||
class QueueUsersRecentApps extends Command
|
||||
{
|
||||
|
@ -56,10 +60,22 @@ class QueueUsersRecentApps extends Command
|
|||
return trim($steamId);
|
||||
});
|
||||
|
||||
$users = Steam::user($steamIds[0])->GetPlayerSummaries($steamIds);
|
||||
// Rate limit requests to 200 requests every 5 minutes, to match Steam's rate limit
|
||||
$storage = new FileStorage(base_path('steam-api.bucket')); // store state in base directory
|
||||
$rate = new Rate(40, Rate::MINUTE); // add 40 tokens every minute (= 200 over 5 minutes)
|
||||
$bucket = new TokenBucket(200, $rate, $storage); // bucket can never have more than 200 tokens saved up
|
||||
$consumer = new BlockingConsumer($bucket); // if no tokens are available, block further execution until there are tokens
|
||||
$bucket->bootstrap(200); // fill the bucket with 200 tokens initially
|
||||
|
||||
$chunkedSteamIds = array_chunk($steamIds, 10);
|
||||
|
||||
$users = [];
|
||||
foreach($chunkedSteamIds as $chunkOf100SteamIds) {
|
||||
$consumer->consume(1);
|
||||
$users = array_merge($users, Steam::user($chunkOf100SteamIds[0])->GetPlayerSummaries($chunkOf100SteamIds));
|
||||
}
|
||||
|
||||
foreach ($users as $user) {
|
||||
|
||||
$this->info('');
|
||||
|
||||
if ($user->communityVisibilityState != 3) {
|
||||
|
@ -67,6 +83,7 @@ class QueueUsersRecentApps extends Command
|
|||
continue;
|
||||
}
|
||||
|
||||
$consumer->consume(1);
|
||||
$apps = Steam::player($user->steamId)->GetRecentlyPlayedGames();
|
||||
|
||||
if (empty($apps)) {
|
||||
|
|
Loading…
Reference in a new issue