|
|
|
|
@@ -38,6 +38,7 @@ namespace ArchiSteamFarm {
|
|
|
|
|
internal sealed class Bot {
|
|
|
|
|
private const ulong ArchiSCFarmGroup = 103582791440160998;
|
|
|
|
|
private const ushort CallbackSleep = 500; // In miliseconds
|
|
|
|
|
private const ushort MaxSteamMessageLength = 2048;
|
|
|
|
|
|
|
|
|
|
internal static readonly Dictionary<string, Bot> Bots = new Dictionary<string, Bot>();
|
|
|
|
|
|
|
|
|
|
@@ -63,7 +64,7 @@ namespace ArchiSteamFarm {
|
|
|
|
|
internal bool KeepRunning { get; private set; }
|
|
|
|
|
|
|
|
|
|
private bool InvalidPassword, LoggedInElsewhere;
|
|
|
|
|
private string AuthCode, TwoFactorAuth;
|
|
|
|
|
private string AuthCode, TwoFactorCode;
|
|
|
|
|
|
|
|
|
|
internal static async Task RefreshCMs(uint cellID) {
|
|
|
|
|
bool initialized = false;
|
|
|
|
|
@@ -163,7 +164,7 @@ namespace ArchiSteamFarm {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ArchiHandler = new ArchiHandler();
|
|
|
|
|
ArchiHandler = new ArchiHandler(this);
|
|
|
|
|
SteamClient.AddHandler(ArchiHandler);
|
|
|
|
|
|
|
|
|
|
CallbackManager = new CallbackManager(SteamClient);
|
|
|
|
|
@@ -271,13 +272,21 @@ namespace ArchiSteamFarm {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var userNonce = await SteamUser.RequestWebAPIUserNonce();
|
|
|
|
|
if (userNonce == null || userNonce.Result != EResult.OK || string.IsNullOrEmpty(userNonce.Nonce)) {
|
|
|
|
|
SteamUser.WebAPIUserNonceCallback callback;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
callback = await SteamUser.RequestWebAPIUserNonce();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
Logging.LogGenericException(e, BotName);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (callback == null || callback.Result != EResult.OK || string.IsNullOrEmpty(callback.Nonce)) {
|
|
|
|
|
Start().Forget();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!ArchiWebHandler.Init(SteamClient, userNonce.Nonce, BotConfig.SteamParentalPIN)) {
|
|
|
|
|
if (!ArchiWebHandler.Init(SteamClient, callback.Nonce, BotConfig.SteamParentalPIN)) {
|
|
|
|
|
Start().Forget();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
@@ -401,7 +410,7 @@ namespace ArchiSteamFarm {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2FA tokens are expiring soon, use limiter only when we don't have any pending
|
|
|
|
|
if (TwoFactorAuth == null) {
|
|
|
|
|
if (TwoFactorCode == null) {
|
|
|
|
|
await Program.LimitSteamRequestsAsync().ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -452,7 +461,9 @@ namespace ArchiSteamFarm {
|
|
|
|
|
// But here we're dealing with WinAuth authenticator
|
|
|
|
|
Logging.LogGenericInfo("ASF requires a few more steps to complete authenticator import...", BotName);
|
|
|
|
|
|
|
|
|
|
InitializeLoginAndPassword();
|
|
|
|
|
if (!InitializeLoginAndPassword()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UserLogin userLogin = new UserLogin(BotConfig.SteamLogin, BotConfig.SteamPassword);
|
|
|
|
|
LoginResult loginResult;
|
|
|
|
|
@@ -460,6 +471,9 @@ namespace ArchiSteamFarm {
|
|
|
|
|
switch (loginResult) {
|
|
|
|
|
case LoginResult.Need2FA:
|
|
|
|
|
userLogin.TwoFactorCode = Program.GetUserInput(Program.EUserInputType.TwoFactorAuthentication, BotName);
|
|
|
|
|
if (string.IsNullOrEmpty(userLogin.TwoFactorCode)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Logging.LogGenericError("Unhandled situation: " + loginResult, BotName);
|
|
|
|
|
@@ -932,8 +946,8 @@ namespace ArchiSteamFarm {
|
|
|
|
|
return await bot.ResponseAddLicense(steamID, gamesToRedeem).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<string> ResponseOwns(ulong steamID, string games) {
|
|
|
|
|
if (steamID == 0 || string.IsNullOrEmpty(games) || !IsMaster(steamID)) {
|
|
|
|
|
private async Task<string> ResponseOwns(ulong steamID, string query) {
|
|
|
|
|
if (steamID == 0 || string.IsNullOrEmpty(query) || !IsMaster(steamID)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -942,37 +956,42 @@ namespace ArchiSteamFarm {
|
|
|
|
|
return "List of owned games is empty!";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if this is uint
|
|
|
|
|
uint appID;
|
|
|
|
|
if (uint.TryParse(games, out appID)) {
|
|
|
|
|
string ownedName;
|
|
|
|
|
if (ownedGames.TryGetValue(appID, out ownedName)) {
|
|
|
|
|
return "Owned already: " + appID + " | " + ownedName;
|
|
|
|
|
} else {
|
|
|
|
|
return "Not owned yet: " + appID;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StringBuilder response = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
// This is a string
|
|
|
|
|
foreach (KeyValuePair<uint, string> game in ownedGames) {
|
|
|
|
|
if (game.Value.IndexOf(games, StringComparison.OrdinalIgnoreCase) < 0) {
|
|
|
|
|
string[] games = query.Split(',');
|
|
|
|
|
foreach (string game in games) {
|
|
|
|
|
// Check if this is appID
|
|
|
|
|
uint appID;
|
|
|
|
|
if (uint.TryParse(game, out appID)) {
|
|
|
|
|
string ownedName;
|
|
|
|
|
if (ownedGames.TryGetValue(appID, out ownedName)) {
|
|
|
|
|
response.Append(Environment.NewLine + "Owned already: " + appID + " | " + ownedName);
|
|
|
|
|
} else {
|
|
|
|
|
response.Append(Environment.NewLine + "Not owned yet: " + appID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response.AppendLine(Environment.NewLine + "Owned already: " + game.Key + " | " + game.Value);
|
|
|
|
|
// This is a string, so check our entire library
|
|
|
|
|
foreach (KeyValuePair<uint, string> ownedGame in ownedGames) {
|
|
|
|
|
if (ownedGame.Value.IndexOf(game, StringComparison.OrdinalIgnoreCase) < 0) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response.Append(Environment.NewLine + "Owned already: " + ownedGame.Key + " | " + ownedGame.Value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (response.Length > 0) {
|
|
|
|
|
return response.ToString();
|
|
|
|
|
} else {
|
|
|
|
|
return "Not owned yet: " + games;
|
|
|
|
|
return "Not owned yet: " + query;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static async Task<string> ResponseOwns(ulong steamID, string botName, string games) {
|
|
|
|
|
if (steamID == 0 || string.IsNullOrEmpty(botName) || string.IsNullOrEmpty(games)) {
|
|
|
|
|
private static async Task<string> ResponseOwns(ulong steamID, string botName, string query) {
|
|
|
|
|
if (steamID == 0 || string.IsNullOrEmpty(botName) || string.IsNullOrEmpty(query)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -981,7 +1000,7 @@ namespace ArchiSteamFarm {
|
|
|
|
|
return "Couldn't find any bot named " + botName + "!";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return await bot.ResponseOwns(steamID, games).ConfigureAwait(false);
|
|
|
|
|
return await bot.ResponseOwns(steamID, query).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<string> ResponsePlay(ulong steamID, HashSet<uint> gameIDs) {
|
|
|
|
|
@@ -1130,9 +1149,31 @@ namespace ArchiSteamFarm {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (new SteamID(steamID).IsChatAccount) {
|
|
|
|
|
SteamFriends.SendChatRoomMessage(steamID, EChatEntryType.ChatMsg, message);
|
|
|
|
|
SendMessageToChannel(steamID, message);
|
|
|
|
|
} else {
|
|
|
|
|
SteamFriends.SendChatMessage(steamID, EChatEntryType.ChatMsg, message);
|
|
|
|
|
SendMessageToUser(steamID, message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SendMessageToChannel(ulong steamID, string message) {
|
|
|
|
|
if (steamID == 0 || string.IsNullOrEmpty(message)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < message.Length; i += MaxSteamMessageLength - 6) {
|
|
|
|
|
string messagePart = (i > 0 ? "..." : "") + message.Substring(i, Math.Min(MaxSteamMessageLength - 6, message.Length - i)) + (MaxSteamMessageLength - 6 < message.Length - i ? "..." : "");
|
|
|
|
|
SteamFriends.SendChatRoomMessage(steamID, EChatEntryType.ChatMsg, messagePart);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SendMessageToUser(ulong steamID, string message) {
|
|
|
|
|
if (steamID == 0 || string.IsNullOrEmpty(message)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < message.Length; i += MaxSteamMessageLength - 6) {
|
|
|
|
|
string messagePart = (i > 0 ? "..." : "") + message.Substring(i, Math.Min(MaxSteamMessageLength - 6, message.Length - i)) + (MaxSteamMessageLength - 6 < message.Length - i ? "..." : "");
|
|
|
|
|
SteamFriends.SendChatMessage(steamID, EChatEntryType.ChatMsg, messagePart);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1143,7 +1184,9 @@ namespace ArchiSteamFarm {
|
|
|
|
|
|
|
|
|
|
Logging.LogGenericInfo("Linking new ASF MobileAuthenticator...", BotName);
|
|
|
|
|
|
|
|
|
|
InitializeLoginAndPassword();
|
|
|
|
|
if (!InitializeLoginAndPassword()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UserLogin userLogin = new UserLogin(BotConfig.SteamLogin, BotConfig.SteamPassword);
|
|
|
|
|
LoginResult loginResult;
|
|
|
|
|
@@ -1151,6 +1194,9 @@ namespace ArchiSteamFarm {
|
|
|
|
|
switch (loginResult) {
|
|
|
|
|
case LoginResult.NeedEmail:
|
|
|
|
|
userLogin.EmailCode = Program.GetUserInput(Program.EUserInputType.SteamGuard, BotName);
|
|
|
|
|
if (string.IsNullOrEmpty(userLogin.EmailCode)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Logging.LogGenericError("Unhandled situation: " + loginResult, BotName);
|
|
|
|
|
@@ -1165,6 +1211,9 @@ namespace ArchiSteamFarm {
|
|
|
|
|
switch (linkResult) {
|
|
|
|
|
case AuthenticatorLinker.LinkResult.MustProvidePhoneNumber:
|
|
|
|
|
authenticatorLinker.PhoneNumber = Program.GetUserInput(Program.EUserInputType.PhoneNumber, BotName);
|
|
|
|
|
if (string.IsNullOrEmpty(authenticatorLinker.PhoneNumber)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Logging.LogGenericError("Unhandled situation: " + linkResult, BotName);
|
|
|
|
|
@@ -1174,7 +1223,12 @@ namespace ArchiSteamFarm {
|
|
|
|
|
|
|
|
|
|
BotDatabase.SteamGuardAccount = authenticatorLinker.LinkedAccount;
|
|
|
|
|
|
|
|
|
|
AuthenticatorLinker.FinalizeResult finalizeResult = authenticatorLinker.FinalizeAddAuthenticator(Program.GetUserInput(Program.EUserInputType.SMS, BotName));
|
|
|
|
|
string sms = Program.GetUserInput(Program.EUserInputType.SMS, BotName);
|
|
|
|
|
if (string.IsNullOrEmpty(sms)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AuthenticatorLinker.FinalizeResult finalizeResult = authenticatorLinker.FinalizeAddAuthenticator(sms);
|
|
|
|
|
if (finalizeResult != AuthenticatorLinker.FinalizeResult.Success) {
|
|
|
|
|
Logging.LogGenericError("Unhandled situation: " + finalizeResult, BotName);
|
|
|
|
|
DelinkMobileAuthenticator();
|
|
|
|
|
@@ -1210,14 +1264,22 @@ namespace ArchiSteamFarm {
|
|
|
|
|
SteamFriends.JoinChat(BotConfig.SteamMasterClanID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitializeLoginAndPassword() {
|
|
|
|
|
private bool InitializeLoginAndPassword() {
|
|
|
|
|
if (string.IsNullOrEmpty(BotConfig.SteamLogin)) {
|
|
|
|
|
BotConfig.SteamLogin = Program.GetUserInput(Program.EUserInputType.Login, BotName);
|
|
|
|
|
if (string.IsNullOrEmpty(BotConfig.SteamLogin)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(BotConfig.SteamPassword) && string.IsNullOrEmpty(BotDatabase.LoginKey)) {
|
|
|
|
|
BotConfig.SteamPassword = Program.GetUserInput(Program.EUserInputType.Password, BotName);
|
|
|
|
|
if (string.IsNullOrEmpty(BotConfig.SteamPassword)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnConnected(SteamClient.ConnectedCallback callback) {
|
|
|
|
|
@@ -1248,10 +1310,18 @@ namespace ArchiSteamFarm {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InitializeLoginAndPassword();
|
|
|
|
|
if (!InitializeLoginAndPassword()) {
|
|
|
|
|
Stop();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logging.LogGenericInfo("Logging in...", BotName);
|
|
|
|
|
|
|
|
|
|
// If we have ASF 2FA enabled, we can always provide TwoFactorCode, and save a request
|
|
|
|
|
if (BotDatabase.SteamGuardAccount != null) {
|
|
|
|
|
TwoFactorCode = BotDatabase.SteamGuardAccount.GenerateSteamGuardCode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Please remove me immediately after https://github.com/SteamRE/SteamKit/issues/254 gets fixed
|
|
|
|
|
if (Program.GlobalConfig.HackIgnoreMachineID) {
|
|
|
|
|
Logging.LogGenericWarning("Using workaround for broken GenerateMachineID()!", BotName);
|
|
|
|
|
@@ -1261,7 +1331,7 @@ namespace ArchiSteamFarm {
|
|
|
|
|
AuthCode = AuthCode,
|
|
|
|
|
LoginID = LoginID,
|
|
|
|
|
LoginKey = BotDatabase.LoginKey,
|
|
|
|
|
TwoFactorCode = TwoFactorAuth,
|
|
|
|
|
TwoFactorCode = TwoFactorCode,
|
|
|
|
|
SentryFileHash = sentryHash,
|
|
|
|
|
ShouldRememberPassword = true
|
|
|
|
|
});
|
|
|
|
|
@@ -1274,7 +1344,7 @@ namespace ArchiSteamFarm {
|
|
|
|
|
AuthCode = AuthCode,
|
|
|
|
|
LoginID = LoginID,
|
|
|
|
|
LoginKey = BotDatabase.LoginKey,
|
|
|
|
|
TwoFactorCode = TwoFactorAuth,
|
|
|
|
|
TwoFactorCode = TwoFactorCode,
|
|
|
|
|
SentryFileHash = sentryHash,
|
|
|
|
|
ShouldRememberPassword = true
|
|
|
|
|
});
|
|
|
|
|
@@ -1321,7 +1391,7 @@ namespace ArchiSteamFarm {
|
|
|
|
|
Logging.LogGenericInfo("Reconnecting...", BotName);
|
|
|
|
|
|
|
|
|
|
// 2FA tokens are expiring soon, use limiter only when we don't have any pending
|
|
|
|
|
if (TwoFactorAuth == null) {
|
|
|
|
|
if (TwoFactorCode == null) {
|
|
|
|
|
await Program.LimitSteamRequestsAsync().ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1476,12 +1546,20 @@ namespace ArchiSteamFarm {
|
|
|
|
|
switch (callback.Result) {
|
|
|
|
|
case EResult.AccountLogonDenied:
|
|
|
|
|
AuthCode = Program.GetUserInput(Program.EUserInputType.SteamGuard, BotName);
|
|
|
|
|
if (string.IsNullOrEmpty(AuthCode)) {
|
|
|
|
|
Stop();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case EResult.AccountLoginDeniedNeedTwoFactor:
|
|
|
|
|
if (BotDatabase.SteamGuardAccount == null) {
|
|
|
|
|
TwoFactorAuth = Program.GetUserInput(Program.EUserInputType.TwoFactorAuthentication, BotName);
|
|
|
|
|
TwoFactorCode = Program.GetUserInput(Program.EUserInputType.TwoFactorAuthentication, BotName);
|
|
|
|
|
if (string.IsNullOrEmpty(TwoFactorCode)) {
|
|
|
|
|
Stop();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
TwoFactorAuth = BotDatabase.SteamGuardAccount.GenerateSteamGuardCode();
|
|
|
|
|
Logging.LogGenericWarning("2FA code was invalid despite of using ASF 2FA. Invalid authenticator or bad timing?", BotName);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case EResult.InvalidPassword:
|
|
|
|
|
@@ -1500,18 +1578,22 @@ namespace ArchiSteamFarm {
|
|
|
|
|
string maFilePath = Path.Combine(Program.ConfigDirectory, callback.ClientSteamID.ConvertToUInt64() + ".maFile");
|
|
|
|
|
if (File.Exists(maFilePath)) {
|
|
|
|
|
ImportAuthenticator(maFilePath);
|
|
|
|
|
} else if (TwoFactorAuth == null && BotConfig.UseAsfAsMobileAuthenticator) {
|
|
|
|
|
} else if (TwoFactorCode == null && BotConfig.UseAsfAsMobileAuthenticator) {
|
|
|
|
|
LinkMobileAuthenticator();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Reset one-time-only access tokens
|
|
|
|
|
AuthCode = TwoFactorAuth = null;
|
|
|
|
|
AuthCode = TwoFactorCode = null;
|
|
|
|
|
|
|
|
|
|
ResetGamesPlayed();
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(BotConfig.SteamParentalPIN)) {
|
|
|
|
|
BotConfig.SteamParentalPIN = Program.GetUserInput(Program.EUserInputType.SteamParentalPIN, BotName);
|
|
|
|
|
if (string.IsNullOrEmpty(BotConfig.SteamParentalPIN)) {
|
|
|
|
|
Stop();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!ArchiWebHandler.Init(SteamClient, callback.WebAPIUserNonce, BotConfig.SteamParentalPIN)) {
|
|
|
|
|
|