Skip to content

Commit bb7d539

Browse files
committed
2.0.0: Update packages and fix Windows bug (#2)
Turns out that the `USERNAME` env variable is also used for the Windows username... Breaking change: now using `ACCOUNT_NAME`.
1 parent ac6583a commit bb7d539

File tree

4 files changed

+255
-1384
lines changed

4 files changed

+255
-1384
lines changed

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ _`steam-hour-farmer` is a program that emulates you playing a game on Steam, wit
2121
5. In this directory, make an `.env` file with the content:
2222
2323
```sh
24-
USERNAME="your_steam_username"
24+
ACCOUNT_NAME="your_steam_username"
2525
PASSWORD="your_steam_password"
2626
GAMES="440,4000"
2727
```
@@ -38,8 +38,6 @@ _`steam-hour-farmer` is a program that emulates you playing a game on Steam, wit
3838
3939
to be Online. Do not write this value if you don't want the user's presence to change.
4040
41-
If you have access to your Steam Shared Secret, you can input it into a `SHARED_SECRET` variable. This will prevent you from needing to input your Steam Guard code at all.
42-
4341
All of this configuration can be passed via environment variables too - they don't need to be in this `.env` file.
4442
4543
6. Run the program in the same directory:
@@ -48,6 +46,15 @@ _`steam-hour-farmer` is a program that emulates you playing a game on Steam, wit
4846
steam-hour-farmer
4947
```
5048
49+
> [!TIP]
50+
> If you have access to your Steam Shared Secret (using something like [SteamDesktopAuthenticator](https://github.com/Jessecar96/SteamDesktopAuthenticator)), you can input it into a `SHARED_SECRET` variable like so:
51+
>
52+
> ```sh
53+
> SHARED_SECRET="xxxxxxxxxx"
54+
> ```
55+
>
56+
> This will prevent you from needing to input your Steam Guard code at all, and will allow the bot to reconnect without any manual intervention.
57+
5158
When the bot starts, it will request a Steam Guard code via email or the mobile application. When you start playing on another machine, the bot will be kicked from its session, requiring a re-login, with a new Steam Guard code.
5259
5360
This can be remedied by using the Steam Shared Secret, or disabling Steam Guard.

index.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const TOTP = require("steam-totp");
99
console.log(`Documentation: https://github.com/tacheometry/steam-hour-farmer`);
1010

1111
require("dotenv").config();
12-
let { USERNAME, PASSWORD, PERSONA, GAMES, SHARED_SECRET } = process.env;
12+
let { ACCOUNT_NAME, PASSWORD, PERSONA, GAMES, SHARED_SECRET } = process.env;
1313
{
1414
PERSONA = parseInt(PERSONA);
1515
const shouldExist = (name) => {
@@ -21,7 +21,7 @@ let { USERNAME, PASSWORD, PERSONA, GAMES, SHARED_SECRET } = process.env;
2121
}
2222
};
2323

24-
shouldExist("USERNAME");
24+
shouldExist("ACCOUNT_NAME");
2525
shouldExist("PASSWORD");
2626
shouldExist("GAMES");
2727
}
@@ -40,9 +40,10 @@ const consoleQuestion = util
4040

4141
const getTOTP = () => TOTP.generateAuthCode(SHARED_SECRET);
4242

43-
const User = new Steam({
43+
const user = new Steam({
4444
machineIdType: Steam.EMachineIDType.PersistentRandom,
4545
dataDirectory: "SteamData",
46+
renewRefreshTokens: true,
4647
});
4748

4849
let playingOnOtherSession = false;
@@ -60,10 +61,10 @@ const logOn = () => {
6061
if (Date.now() - lastLogOnTime <= MIN_REQUEST_TIME) return;
6162
if (Date.now() < onlyLogInAfter) return;
6263
console.log("Logging in...");
63-
User.logOn({
64-
accountName: USERNAME,
64+
user.logOn({
65+
accountName: ACCOUNT_NAME,
6566
password: PASSWORD,
66-
rememberPassword: true,
67+
machineName: "steam-hour-farmer",
6768
clientOS: Steam.EOSType.Windows10,
6869
twoFactorCode: SHARED_SECRET
6970
? TOTP.generateAuthCode(SHARED_SECRET)
@@ -85,7 +86,7 @@ const refreshGames = () => {
8586
notification = "Farming is paused.";
8687
} else {
8788
if (Date.now() - lastGameRefreshTime <= MIN_REQUEST_TIME) return;
88-
User.gamesPlayed(SHOULD_PLAY);
89+
user.gamesPlayed(SHOULD_PLAY);
8990
notification = "Farming...";
9091
lastGameRefreshTime = Date.now();
9192
}
@@ -95,7 +96,7 @@ const refreshGames = () => {
9596
}
9697
};
9798

98-
User.on("steamGuard", async (domain, callback) => {
99+
user.on("steamGuard", async (domain, callback) => {
99100
if (SHARED_SECRET) return callback(getTOTP());
100101
const manualCode = await consoleQuestion(
101102
`Enter Steam Guard code` +
@@ -105,19 +106,19 @@ User.on("steamGuard", async (domain, callback) => {
105106
callback(manualCode);
106107
});
107108

108-
User.on("playingState", (blocked, app) => {
109+
user.on("playingState", (blocked, app) => {
109110
playingOnOtherSession = blocked;
110111
refreshGames();
111112
});
112113

113-
User.on("loggedOn", () => {
114+
user.on("loggedOn", () => {
114115
authenticated = true;
115-
console.log(`Successfully logged in to Steam with ID ${User.steamID}`);
116-
if (PERSONA !== undefined) User.setPersona(PERSONA);
116+
console.log(`Successfully logged in to Steam with ID ${user.steamID}`);
117+
if (PERSONA !== undefined) user.setPersona(PERSONA);
117118
refreshGames();
118119
});
119120

120-
User.on("error", (e) => {
121+
user.on("error", (e) => {
121122
switch (e.eresult) {
122123
case Steam.EResult.LoggedInElsewhere: {
123124
authenticated = false;

0 commit comments

Comments
 (0)