Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

World of Tanks Automatic Clan Reserves

Also written up at jane.berlin/www/articles/reserves.html.

What Is It?

A small Ruby script that automatically activates our World of Tanks clan's Stronghold reserves — Battle Payments and Military Maneuvers — twice a day, so nobody has to be online at the exact moment to hit "activate" before clan battles.

Why It Has To Prolong the Token First

Every run, before it activates anything, it prolongs (refreshes) the Wargaming API access token via /wot/auth/prolongate/. The token has a TTL and goes stale — it has to be carried over and refreshed regularly, or the next run's activateclanreserve calls just fail with an expired token. So the very first thing the script does is trade the current token for a fresh one, and only then does it use that fresh token to activate BATTLE_PAYMENTS and MILITARY_MANEUVERS at /wot/stronghold/activateclanreserve/.

Two Versions: cron and Lambda

program.rb — the original, run via crontab twice a day on a plain box. The refreshed token is written back to access_token.txt (with the previous one backed up to old_access_token.txt) so the next cron run picks it up from disk.

lambda_function.rb — where it eventually ended up. Lambda invocations don't share a filesystem between runs, so writing the refreshed token to a local file doesn't carry it over to the next invocation. Instead, lambda_function.rb calls back into its own Lambda configuration via aws-sdk-lambda's update_function_configuration and rewrites its own access_token environment variable with the freshly prolonged token, every time it runs. The next scheduled invocation reads that updated env var to pick up where the last one left off — the token carry-over mechanism just moves from a file to the function's own config.

The World of Tanks API

Reserves (in Wargaming's terms, "boosters") are documented in the WoT Encyclopedia API: developers.wargaming.net — Boosters. That's where the reserve types used here (BATTLE_PAYMENTS, MILITARY_MANEUVERS) come from.

The Stack

  • Ruby
  • HTTParty (program.rb) / stdlib Net::HTTP (lambda_function.rb) — for the API calls
  • aws-sdk-lambda — lets the Lambda version update its own environment variables
  • Wargaming.net Public API (World of Tanks EU, Stronghold endpoints)
  • cron (program.rb) / AWS Lambda scheduled invocation (lambda_function.rb)

Note

access_token.txt and old_access_token.txt are runtime state for the cron version, not checked into the repo — only the scripts, crontab, and the Gemfile are tracked. The Lambda version has no local state at all; its "state" is the access_token environment variable on the function itself.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages