Skip to content

Commit fa12ffd

Browse files
committed
Add headlness mode
1 parent ecb27ad commit fa12ffd

File tree

6 files changed

+61
-5
lines changed

6 files changed

+61
-5
lines changed

ArchiSteamFarm/Bot.cs

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -452,14 +452,19 @@ private void ImportAuthenticator(string maFilePath) {
452452
// But here we're dealing with WinAuth authenticator
453453
Logging.LogGenericInfo("ASF requires a few more steps to complete authenticator import...", BotName);
454454

455-
InitializeLoginAndPassword();
455+
if (!InitializeLoginAndPassword()) {
456+
return;
457+
}
456458

457459
UserLogin userLogin = new UserLogin(BotConfig.SteamLogin, BotConfig.SteamPassword);
458460
LoginResult loginResult;
459461
while ((loginResult = userLogin.DoLogin()) != LoginResult.LoginOkay) {
460462
switch (loginResult) {
461463
case LoginResult.Need2FA:
462464
userLogin.TwoFactorCode = Program.GetUserInput(Program.EUserInputType.TwoFactorAuthentication, BotName);
465+
if (string.IsNullOrEmpty(userLogin.TwoFactorCode)) {
466+
return;
467+
}
463468
break;
464469
default:
465470
Logging.LogGenericError("Unhandled situation: " + loginResult, BotName);
@@ -1143,14 +1148,19 @@ private void LinkMobileAuthenticator() {
11431148

11441149
Logging.LogGenericInfo("Linking new ASF MobileAuthenticator...", BotName);
11451150

1146-
InitializeLoginAndPassword();
1151+
if (!InitializeLoginAndPassword()) {
1152+
return;
1153+
}
11471154

11481155
UserLogin userLogin = new UserLogin(BotConfig.SteamLogin, BotConfig.SteamPassword);
11491156
LoginResult loginResult;
11501157
while ((loginResult = userLogin.DoLogin()) != LoginResult.LoginOkay) {
11511158
switch (loginResult) {
11521159
case LoginResult.NeedEmail:
11531160
userLogin.EmailCode = Program.GetUserInput(Program.EUserInputType.SteamGuard, BotName);
1161+
if (string.IsNullOrEmpty(userLogin.EmailCode)) {
1162+
return;
1163+
}
11541164
break;
11551165
default:
11561166
Logging.LogGenericError("Unhandled situation: " + loginResult, BotName);
@@ -1165,6 +1175,9 @@ private void LinkMobileAuthenticator() {
11651175
switch (linkResult) {
11661176
case AuthenticatorLinker.LinkResult.MustProvidePhoneNumber:
11671177
authenticatorLinker.PhoneNumber = Program.GetUserInput(Program.EUserInputType.PhoneNumber, BotName);
1178+
if (string.IsNullOrEmpty(authenticatorLinker.PhoneNumber)) {
1179+
return;
1180+
}
11681181
break;
11691182
default:
11701183
Logging.LogGenericError("Unhandled situation: " + linkResult, BotName);
@@ -1174,7 +1187,12 @@ private void LinkMobileAuthenticator() {
11741187

11751188
BotDatabase.SteamGuardAccount = authenticatorLinker.LinkedAccount;
11761189

1177-
AuthenticatorLinker.FinalizeResult finalizeResult = authenticatorLinker.FinalizeAddAuthenticator(Program.GetUserInput(Program.EUserInputType.SMS, BotName));
1190+
string sms = Program.GetUserInput(Program.EUserInputType.SMS, BotName);
1191+
if (string.IsNullOrEmpty(sms)) {
1192+
return;
1193+
}
1194+
1195+
AuthenticatorLinker.FinalizeResult finalizeResult = authenticatorLinker.FinalizeAddAuthenticator(sms);
11781196
if (finalizeResult != AuthenticatorLinker.FinalizeResult.Success) {
11791197
Logging.LogGenericError("Unhandled situation: " + finalizeResult, BotName);
11801198
DelinkMobileAuthenticator();
@@ -1210,14 +1228,22 @@ private void JoinMasterChat() {
12101228
SteamFriends.JoinChat(BotConfig.SteamMasterClanID);
12111229
}
12121230

1213-
private void InitializeLoginAndPassword() {
1231+
private bool InitializeLoginAndPassword() {
12141232
if (string.IsNullOrEmpty(BotConfig.SteamLogin)) {
12151233
BotConfig.SteamLogin = Program.GetUserInput(Program.EUserInputType.Login, BotName);
1234+
if (string.IsNullOrEmpty(BotConfig.SteamLogin)) {
1235+
return false;
1236+
}
12161237
}
12171238

12181239
if (string.IsNullOrEmpty(BotConfig.SteamPassword) && string.IsNullOrEmpty(BotDatabase.LoginKey)) {
12191240
BotConfig.SteamPassword = Program.GetUserInput(Program.EUserInputType.Password, BotName);
1241+
if (string.IsNullOrEmpty(BotConfig.SteamPassword)) {
1242+
return false;
1243+
}
12201244
}
1245+
1246+
return true;
12211247
}
12221248

12231249
private void OnConnected(SteamClient.ConnectedCallback callback) {
@@ -1248,7 +1274,10 @@ private void OnConnected(SteamClient.ConnectedCallback callback) {
12481274
}
12491275
}
12501276

1251-
InitializeLoginAndPassword();
1277+
if (!InitializeLoginAndPassword()) {
1278+
Stop();
1279+
return;
1280+
}
12521281

12531282
Logging.LogGenericInfo("Logging in...", BotName);
12541283

@@ -1476,10 +1505,18 @@ private async void OnLoggedOn(SteamUser.LoggedOnCallback callback) {
14761505
switch (callback.Result) {
14771506
case EResult.AccountLogonDenied:
14781507
AuthCode = Program.GetUserInput(Program.EUserInputType.SteamGuard, BotName);
1508+
if (string.IsNullOrEmpty(AuthCode)) {
1509+
Stop();
1510+
return;
1511+
}
14791512
break;
14801513
case EResult.AccountLoginDeniedNeedTwoFactor:
14811514
if (BotDatabase.SteamGuardAccount == null) {
14821515
TwoFactorAuth = Program.GetUserInput(Program.EUserInputType.TwoFactorAuthentication, BotName);
1516+
if (string.IsNullOrEmpty(TwoFactorAuth)) {
1517+
Stop();
1518+
return;
1519+
}
14831520
} else {
14841521
TwoFactorAuth = BotDatabase.SteamGuardAccount.GenerateSteamGuardCode();
14851522
}
@@ -1512,6 +1549,10 @@ private async void OnLoggedOn(SteamUser.LoggedOnCallback callback) {
15121549

15131550
if (string.IsNullOrEmpty(BotConfig.SteamParentalPIN)) {
15141551
BotConfig.SteamParentalPIN = Program.GetUserInput(Program.EUserInputType.SteamParentalPIN, BotName);
1552+
if (string.IsNullOrEmpty(BotConfig.SteamParentalPIN)) {
1553+
Stop();
1554+
return;
1555+
}
15151556
}
15161557

15171558
if (!ArchiWebHandler.Init(SteamClient, callback.WebAPIUserNonce, BotConfig.SteamParentalPIN)) {

ArchiSteamFarm/GlobalConfig.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ internal enum EUpdateChannel : byte {
4949
[JsonProperty(Required = Required.DisallowNull)]
5050
internal bool Debug { get; private set; } = false;
5151

52+
[JsonProperty(Required = Required.DisallowNull)]
53+
internal bool Headless { get; private set; } = false;
54+
5255
[JsonProperty(Required = Required.DisallowNull)]
5356
internal bool AutoUpdates { get; private set; } = true;
5457

ArchiSteamFarm/Program.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,11 @@ internal static string GetUserInput(EUserInputType userInputType, string botName
274274
return null;
275275
}
276276

277+
if (GlobalConfig.Headless) {
278+
Logging.LogGenericWarning("Received a request for user input, but process is running in headless mode!");
279+
return null;
280+
}
281+
277282
string result;
278283
lock (ConsoleLock) {
279284
ConsoleIsBusy = true;

ArchiSteamFarm/WCF.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ internal sealed class WCF : IWCF {
4444
internal static void Init() {
4545
if (string.IsNullOrEmpty(Program.GlobalConfig.WCFHostname)) {
4646
Program.GlobalConfig.WCFHostname = Program.GetUserInput(Program.EUserInputType.WCFHostname);
47+
if (string.IsNullOrEmpty(Program.GlobalConfig.WCFHostname)) {
48+
return;
49+
}
4750
}
4851

4952
URL = "http://" + Program.GlobalConfig.WCFHostname + ":" + Program.GlobalConfig.WCFPort + "/ASF";

ArchiSteamFarm/config/ASF.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"Debug": false,
3+
"Headless": false,
34
"AutoUpdates": true,
45
"UpdateChannel": 1,
56
"SteamProtocol": 6,

ConfigGenerator/GlobalConfig.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ internal enum EUpdateChannel : byte {
4848
[JsonProperty(Required = Required.DisallowNull)]
4949
public bool Debug { get; set; } = false;
5050

51+
[JsonProperty(Required = Required.DisallowNull)]
52+
public bool Headless { get; set; } = false;
53+
5154
[JsonProperty(Required = Required.DisallowNull)]
5255
public bool AutoUpdates { get; set; } = true;
5356

0 commit comments

Comments
 (0)