mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2025-12-17 15:00:29 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d0d670f1a5 | ||
|
|
3597c8f138 | ||
|
|
8a8ec29b41 | ||
|
|
a3352d032d | ||
|
|
d5f8647fcc | ||
|
|
79a700d786 | ||
|
|
bc223f0644 | ||
|
|
2b0d82453b | ||
|
|
fa0150e745 | ||
|
|
c95d11ef66 | ||
|
|
63b268f9c4 | ||
|
|
03d38f8a2a |
@@ -43,10 +43,6 @@ namespace ArchiSteamFarm {
|
||||
|
||||
private static readonly uint LoginID = MsgClientLogon.ObfuscationMask; // This must be the same for all ASF bots and all ASF processes
|
||||
|
||||
private readonly string SentryFile;
|
||||
private readonly Timer AcceptConfirmationsTimer;
|
||||
private readonly Timer SendItemsTimer;
|
||||
|
||||
internal readonly string BotName;
|
||||
internal readonly ArchiHandler ArchiHandler;
|
||||
internal readonly ArchiWebHandler ArchiWebHandler;
|
||||
@@ -54,6 +50,9 @@ namespace ArchiSteamFarm {
|
||||
internal readonly BotDatabase BotDatabase;
|
||||
internal readonly SteamClient SteamClient;
|
||||
|
||||
private readonly string SentryFile;
|
||||
private readonly Timer AcceptConfirmationsTimer;
|
||||
private readonly Timer SendItemsTimer;
|
||||
private readonly CallbackManager CallbackManager;
|
||||
private readonly CardsFarmer CardsFarmer;
|
||||
private readonly SteamApps SteamApps;
|
||||
@@ -63,8 +62,7 @@ namespace ArchiSteamFarm {
|
||||
|
||||
internal bool KeepRunning { get; private set; } = false;
|
||||
|
||||
private bool InvalidPassword = false;
|
||||
private bool LoggedInElsewhere = false;
|
||||
private bool InvalidPassword, LoggedInElsewhere;
|
||||
private string AuthCode, TwoFactorAuth;
|
||||
|
||||
internal static async Task RefreshCMs(uint cellID) {
|
||||
@@ -179,14 +177,16 @@ namespace ArchiSteamFarm {
|
||||
BotDatabase = BotDatabase.Load(botPath + ".db");
|
||||
SentryFile = botPath + ".bin";
|
||||
|
||||
// Support and convert SDA files
|
||||
string maFilePath = botPath + ".maFile";
|
||||
if (BotDatabase.SteamGuardAccount == null && File.Exists(maFilePath)) {
|
||||
ImportAuthenticator(maFilePath);
|
||||
if (BotDatabase.SteamGuardAccount == null) {
|
||||
// Support and convert SDA files
|
||||
string maFilePath = botPath + ".maFile";
|
||||
if (File.Exists(maFilePath)) {
|
||||
ImportAuthenticator(maFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize
|
||||
SteamClient = new SteamClient();
|
||||
SteamClient = new SteamClient(Program.GlobalConfig.SteamProtocol);
|
||||
|
||||
if (Program.GlobalConfig.Debug && !Debugging.NetHookAlreadyInitialized && Directory.Exists(Program.DebugDirectory)) {
|
||||
try {
|
||||
@@ -252,7 +252,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
// Start
|
||||
Start().Wait();
|
||||
Task.Run(async () => await Start().ConfigureAwait(false)).Forget();
|
||||
}
|
||||
|
||||
internal bool IsMaster(ulong steamID) {
|
||||
@@ -312,6 +312,7 @@ namespace ArchiSteamFarm {
|
||||
if (farmedSomething && BotConfig.SendOnFarmingFinished) {
|
||||
await ResponseSendTrade(BotConfig.SteamMasterID).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (BotConfig.ShutdownOnFarmingFinished) {
|
||||
await Shutdown().ConfigureAwait(false);
|
||||
}
|
||||
@@ -353,7 +354,7 @@ namespace ArchiSteamFarm {
|
||||
case "!update":
|
||||
return await ResponseUpdate(steamID).ConfigureAwait(false);
|
||||
default:
|
||||
return "Unrecognized command: " + message;
|
||||
return ResponseUnknown(steamID);
|
||||
}
|
||||
} else {
|
||||
string[] args = message.Split(' ');
|
||||
@@ -399,7 +400,7 @@ namespace ArchiSteamFarm {
|
||||
case "!stop":
|
||||
return await ResponseStop(steamID, args[1]).ConfigureAwait(false);
|
||||
default:
|
||||
return "Unrecognized command: " + args[0];
|
||||
return ResponseUnknown(steamID);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -511,7 +512,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
if (!IsMaster(steamID)) {
|
||||
return "ERROR: Not authorized!";
|
||||
return null;
|
||||
}
|
||||
|
||||
if (CardsFarmer.CurrentGamesFarming.Count > 0) {
|
||||
@@ -540,7 +541,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
if (!IsOwner(steamID)) {
|
||||
return "ERROR: Not authorized!";
|
||||
return null;
|
||||
}
|
||||
|
||||
StringBuilder result = new StringBuilder(Environment.NewLine);
|
||||
@@ -565,7 +566,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
if (!IsMaster(steamID)) {
|
||||
return "ERROR: Not authorized!";
|
||||
return null;
|
||||
}
|
||||
|
||||
if (BotConfig.SteamMasterID == 0) {
|
||||
@@ -606,7 +607,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
if (!IsMaster(steamID)) {
|
||||
return "ERROR: Not authorized!";
|
||||
return null;
|
||||
}
|
||||
|
||||
if (BotDatabase.SteamGuardAccount == null) {
|
||||
@@ -636,7 +637,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
if (!IsMaster(steamID)) {
|
||||
return "ERROR: Not authorized!";
|
||||
return null;
|
||||
}
|
||||
|
||||
if (BotDatabase.SteamGuardAccount == null) {
|
||||
@@ -669,7 +670,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
if (!IsMaster(steamID)) {
|
||||
return "ERROR: Not authorized!";
|
||||
return null;
|
||||
}
|
||||
|
||||
if (BotDatabase.SteamGuardAccount == null) {
|
||||
@@ -699,7 +700,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
if (!IsOwner(steamID)) {
|
||||
return "ERROR: Not authorized!";
|
||||
return null;
|
||||
}
|
||||
|
||||
Program.Exit();
|
||||
@@ -712,7 +713,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
if (!IsMaster(steamID)) {
|
||||
return "ERROR: Not authorized!";
|
||||
return null;
|
||||
}
|
||||
|
||||
await CardsFarmer.RestartFarming().ConfigureAwait(false);
|
||||
@@ -738,7 +739,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
if (!IsMaster(steamID)) {
|
||||
return "ERROR: Not authorized!";
|
||||
return null;
|
||||
}
|
||||
|
||||
StringBuilder response = new StringBuilder();
|
||||
@@ -896,7 +897,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
if (!IsOwner(steamID)) {
|
||||
return "ERROR: Not authorized!";
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (Bot bot in Bots.Values) {
|
||||
@@ -912,7 +913,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
if (!IsOwner(steamID)) {
|
||||
return "ERROR: Not authorized!";
|
||||
return null;
|
||||
}
|
||||
|
||||
Program.Restart();
|
||||
@@ -925,7 +926,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
if (!IsMaster(steamID)) {
|
||||
return "ERROR: Not authorized!";
|
||||
return null;
|
||||
}
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
@@ -978,7 +979,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
if (!IsMaster(steamID)) {
|
||||
return "ERROR: Not authorized!";
|
||||
return null;
|
||||
}
|
||||
|
||||
Dictionary<uint, string> ownedGames = await ArchiWebHandler.GetOwnedGames().ConfigureAwait(false);
|
||||
@@ -1034,7 +1035,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
if (!IsMaster(steamID)) {
|
||||
return "ERROR: Not authorized!";
|
||||
return null;
|
||||
}
|
||||
|
||||
if (gameIDs.Contains(0)) {
|
||||
@@ -1083,7 +1084,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
if (!IsMaster(steamID)) {
|
||||
return "ERROR: Not authorized!";
|
||||
return null;
|
||||
}
|
||||
|
||||
if (KeepRunning) {
|
||||
@@ -1113,7 +1114,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
if (!IsMaster(steamID)) {
|
||||
return "ERROR: Not authorized!";
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!KeepRunning) {
|
||||
@@ -1137,13 +1138,25 @@ namespace ArchiSteamFarm {
|
||||
return await bot.ResponseStop(steamID).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private string ResponseUnknown(ulong steamID) {
|
||||
if (steamID == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!IsMaster(steamID)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return "ERROR: Unknown command!";
|
||||
}
|
||||
|
||||
private static async Task<string> ResponseUpdate(ulong steamID) {
|
||||
if (steamID == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!IsOwner(steamID)) {
|
||||
return "ERROR: Not authorized!";
|
||||
return null;
|
||||
}
|
||||
|
||||
await Program.CheckForUpdate().ConfigureAwait(false);
|
||||
@@ -1157,12 +1170,12 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
}
|
||||
|
||||
private async Task HandleMessage(ulong steamID, string message) {
|
||||
if (steamID == 0 || string.IsNullOrEmpty(message)) {
|
||||
private async Task HandleMessage(ulong chatID, ulong steamID, string message) {
|
||||
if (chatID == 0 || steamID == 0 || string.IsNullOrEmpty(message)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SendMessage(steamID, await Response(steamID, message).ConfigureAwait(false));
|
||||
SendMessage(chatID, await Response(steamID, message).ConfigureAwait(false));
|
||||
}
|
||||
|
||||
private void SendMessage(ulong steamID, string message) {
|
||||
@@ -1396,7 +1409,7 @@ namespace ArchiSteamFarm {
|
||||
SteamFriends.LeaveChat(callback.ChatRoomID);
|
||||
break;
|
||||
default:
|
||||
await HandleMessage(callback.ChatRoomID, callback.Message).ConfigureAwait(false);
|
||||
await HandleMessage(callback.ChatRoomID, callback.ChatterID, callback.Message).ConfigureAwait(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1434,11 +1447,7 @@ namespace ArchiSteamFarm {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IsMaster(callback.Sender)) {
|
||||
return;
|
||||
}
|
||||
|
||||
await HandleMessage(callback.Sender, callback.Message).ConfigureAwait(false);
|
||||
await HandleMessage(callback.Sender, callback.Sender, callback.Message).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async void OnFriendMsgHistory(SteamFriends.FriendMsgHistoryCallback callback) {
|
||||
@@ -1472,7 +1481,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
// Handle the message
|
||||
await HandleMessage(callback.SteamID, lastMessage.Message).ConfigureAwait(false);
|
||||
await HandleMessage(callback.SteamID, callback.SteamID, lastMessage.Message).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private void OnAccountInfo(SteamUser.AccountInfoCallback callback) {
|
||||
@@ -1528,19 +1537,18 @@ namespace ArchiSteamFarm {
|
||||
Program.GlobalDatabase.CellID = callback.CellID;
|
||||
}
|
||||
|
||||
// Support and convert SDA files
|
||||
string maFilePath = Path.Combine(Program.ConfigDirectory, callback.ClientSteamID.ConvertToUInt64() + ".maFile");
|
||||
if (BotDatabase.SteamGuardAccount == null && File.Exists(maFilePath)) {
|
||||
ImportAuthenticator(maFilePath);
|
||||
}
|
||||
|
||||
if (BotConfig.UseAsfAsMobileAuthenticator && TwoFactorAuth == null && BotDatabase.SteamGuardAccount == null) {
|
||||
LinkMobileAuthenticator();
|
||||
if (BotDatabase.SteamGuardAccount == null) {
|
||||
// Support and convert SDA files
|
||||
string maFilePath = Path.Combine(Program.ConfigDirectory, callback.ClientSteamID.ConvertToUInt64() + ".maFile");
|
||||
if (File.Exists(maFilePath)) {
|
||||
ImportAuthenticator(maFilePath);
|
||||
} else if (TwoFactorAuth == null && BotConfig.UseAsfAsMobileAuthenticator) {
|
||||
LinkMobileAuthenticator();
|
||||
}
|
||||
}
|
||||
|
||||
// Reset one-time-only access tokens
|
||||
AuthCode = null;
|
||||
TwoFactorAuth = null;
|
||||
AuthCode = TwoFactorAuth = null;
|
||||
|
||||
ResetGamesPlayed();
|
||||
|
||||
@@ -1554,20 +1562,24 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
if (BotConfig.DismissInventoryNotifications) {
|
||||
await ArchiWebHandler.MarkInventory().ConfigureAwait(false);
|
||||
Task.Run(async () => await ArchiWebHandler.MarkInventory().ConfigureAwait(false)).Forget();
|
||||
}
|
||||
|
||||
if (BotConfig.SteamMasterClanID != 0) {
|
||||
await ArchiWebHandler.JoinClan(BotConfig.SteamMasterClanID).ConfigureAwait(false);
|
||||
JoinMasterChat();
|
||||
Task.Run(async () => {
|
||||
await ArchiWebHandler.JoinClan(BotConfig.SteamMasterClanID).ConfigureAwait(false);
|
||||
JoinMasterChat();
|
||||
}).Forget();
|
||||
}
|
||||
|
||||
if (Program.GlobalConfig.Statistics) {
|
||||
await ArchiWebHandler.JoinClan(ArchiSCFarmGroup).ConfigureAwait(false);
|
||||
SteamFriends.JoinChat(ArchiSCFarmGroup);
|
||||
Task.Run(async () => {
|
||||
await ArchiWebHandler.JoinClan(ArchiSCFarmGroup).ConfigureAwait(false);
|
||||
SteamFriends.JoinChat(ArchiSCFarmGroup);
|
||||
}).Forget();
|
||||
}
|
||||
|
||||
Trading.CheckTrades();
|
||||
Task.Run(() => Trading.CheckTrades()).Forget();
|
||||
|
||||
Task.Run(async () => await CardsFarmer.StartFarming().ConfigureAwait(false)).Forget();
|
||||
break;
|
||||
|
||||
@@ -57,10 +57,10 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
}
|
||||
|
||||
[JsonProperty(Required = Required.AllowNull)]
|
||||
[JsonProperty]
|
||||
private string _LoginKey;
|
||||
|
||||
[JsonProperty(Required = Required.AllowNull)]
|
||||
[JsonProperty]
|
||||
private SteamGuardAccount _SteamGuardAccount;
|
||||
|
||||
private string FilePath;
|
||||
|
||||
@@ -26,6 +26,7 @@ using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace ArchiSteamFarm {
|
||||
internal sealed class GlobalConfig {
|
||||
@@ -47,6 +48,9 @@ namespace ArchiSteamFarm {
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal EUpdateChannel UpdateChannel { get; private set; } = EUpdateChannel.Stable;
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal ProtocolType SteamProtocol { get; private set; } = ProtocolType.Tcp;
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal ulong SteamOwnerID { get; private set; } = 0;
|
||||
|
||||
@@ -107,6 +111,18 @@ namespace ArchiSteamFarm {
|
||||
return null;
|
||||
}
|
||||
|
||||
// SK2 supports only TCP and UDP steam protocols
|
||||
// Make sure that user can't screw this up
|
||||
switch (globalConfig.SteamProtocol) {
|
||||
case ProtocolType.Tcp:
|
||||
case ProtocolType.Udp:
|
||||
break;
|
||||
default:
|
||||
Logging.LogGenericWarning("Configured SteamProtocol is invalid: " + globalConfig.SteamProtocol + ", default TCP protocol will be used instead");
|
||||
globalConfig.SteamProtocol = ProtocolType.Tcp;
|
||||
break;
|
||||
}
|
||||
|
||||
return globalConfig;
|
||||
}
|
||||
|
||||
|
||||
@@ -343,6 +343,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
Logging.LogGenericInfo("No bots are running, exiting");
|
||||
Thread.Sleep(5000);
|
||||
ShutdownResetEvent.Set();
|
||||
}
|
||||
|
||||
@@ -417,7 +418,7 @@ namespace ArchiSteamFarm {
|
||||
Logging.LogGenericException(args.Exception);
|
||||
}
|
||||
|
||||
private static void Main(string[] args) {
|
||||
private static void Init(string[] args) {
|
||||
AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;
|
||||
TaskScheduler.UnobservedTaskException += UnobservedTaskExceptionHandler;
|
||||
|
||||
@@ -476,6 +477,8 @@ namespace ArchiSteamFarm {
|
||||
// Before attempting to connect, initialize our list of CMs
|
||||
Bot.RefreshCMs(GlobalDatabase.CellID).Wait();
|
||||
|
||||
bool isRunning = false;
|
||||
|
||||
foreach (var configFile in Directory.EnumerateFiles(ConfigDirectory, "*.json")) {
|
||||
string botName = Path.GetFileNameWithoutExtension(configFile);
|
||||
if (botName.Equals(ASF)) {
|
||||
@@ -483,7 +486,9 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
Bot bot = new Bot(botName);
|
||||
if (bot.BotConfig == null || !bot.BotConfig.Enabled) {
|
||||
if (bot.BotConfig != null && bot.BotConfig.Enabled) {
|
||||
isRunning = true;
|
||||
} else {
|
||||
Logging.LogGenericInfo("Not starting this instance because it's disabled in config file", botName);
|
||||
}
|
||||
}
|
||||
@@ -493,23 +498,28 @@ namespace ArchiSteamFarm {
|
||||
string botName = Path.GetFileNameWithoutExtension(configFile);
|
||||
Logging.LogGenericWarning("Found legacy " + botName + ".xml config file, it will now be converted to new ASF V2.0 format!");
|
||||
Bot bot = new Bot(botName);
|
||||
if (bot.BotConfig == null || !bot.BotConfig.Enabled) {
|
||||
if (bot.BotConfig != null && bot.BotConfig.Enabled) {
|
||||
isRunning = true;
|
||||
} else {
|
||||
Logging.LogGenericInfo("Not starting this instance because it's disabled in config file", botName);
|
||||
}
|
||||
}
|
||||
// CONVERSION END
|
||||
|
||||
// Check if we got any bots running
|
||||
OnBotShutdown();
|
||||
if (!isRunning) {
|
||||
OnBotShutdown();
|
||||
}
|
||||
}
|
||||
|
||||
private static void Main(string[] args) {
|
||||
Init(args);
|
||||
|
||||
// Wait for signal to shutdown
|
||||
ShutdownResetEvent.WaitOne();
|
||||
|
||||
// We got a signal to shutdown, consider giving user some time to read the message
|
||||
Thread.Sleep(5000);
|
||||
|
||||
// This is over, cleanup only now
|
||||
WCF.StopServer();
|
||||
// We got a signal to shutdown
|
||||
Environment.Exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("2.0.1.2")]
|
||||
[assembly: AssemblyFileVersion("2.0.1.2")]
|
||||
[assembly: AssemblyVersion("2.0.1.4")]
|
||||
[assembly: AssemblyFileVersion("2.0.1.4")]
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Debug": false,
|
||||
"AutoUpdates": true,
|
||||
"UpdateChannel": 1,
|
||||
"SteamProtocol": 6,
|
||||
"SteamOwnerID": 0,
|
||||
"MaxFarmingTime": 10,
|
||||
"IdleFarmingPeriod": 3,
|
||||
|
||||
Reference in New Issue
Block a user