Compare commits

..

13 Commits

Author SHA1 Message Date
JustArchi
d5f8647fcc Misc 2016-03-18 20:36:13 +01:00
JustArchi
79a700d786 Fix group chat commands, #165 2016-03-18 20:35:42 +01:00
JustArchi
bc223f0644 Misc 2016-03-18 14:54:42 +01:00
JustArchi
2b0d82453b Speedup login by doing independent tasks in parallel 2016-03-18 14:47:52 +01:00
JustArchi
fa0150e745 Code review 2016-03-18 14:39:59 +01:00
JustArchi
c95d11ef66 Actually do not respond to non-authorized users at all 2016-03-18 14:13:04 +01:00
JustArchi
63b268f9c4 Bump 2016-03-18 14:09:24 +01:00
JustArchi
03d38f8a2a Fix derp, #165 2016-03-18 14:05:18 +01:00
JustArchi
c88d9bf123 Implement SteamOwnerID 2016-03-18 09:02:09 +01:00
JustArchi
053ebe15bb Prepare for SteamOwnerID 2016-03-18 03:52:36 +01:00
JustArchi
b03bfb6bbc Don't touch old log when disabled 2016-03-18 03:48:00 +01:00
JustArchi
e48867000e Add LogToFile, closes #168 2016-03-18 03:45:59 +01:00
JustArchi
e08cdbd74d Bump 2016-03-16 19:58:21 +01:00
8 changed files with 322 additions and 160 deletions

View File

@@ -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 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 string BotName;
internal readonly ArchiHandler ArchiHandler; internal readonly ArchiHandler ArchiHandler;
internal readonly ArchiWebHandler ArchiWebHandler; internal readonly ArchiWebHandler ArchiWebHandler;
@@ -54,6 +50,9 @@ namespace ArchiSteamFarm {
internal readonly BotDatabase BotDatabase; internal readonly BotDatabase BotDatabase;
internal readonly SteamClient SteamClient; internal readonly SteamClient SteamClient;
private readonly string SentryFile;
private readonly Timer AcceptConfirmationsTimer;
private readonly Timer SendItemsTimer;
private readonly CallbackManager CallbackManager; private readonly CallbackManager CallbackManager;
private readonly CardsFarmer CardsFarmer; private readonly CardsFarmer CardsFarmer;
private readonly SteamApps SteamApps; private readonly SteamApps SteamApps;
@@ -63,8 +62,7 @@ namespace ArchiSteamFarm {
internal bool KeepRunning { get; private set; } = false; internal bool KeepRunning { get; private set; } = false;
private bool InvalidPassword = false; private bool InvalidPassword, LoggedInElsewhere;
private bool LoggedInElsewhere = false;
private string AuthCode, TwoFactorAuth; private string AuthCode, TwoFactorAuth;
internal static async Task RefreshCMs(uint cellID) { internal static async Task RefreshCMs(uint cellID) {
@@ -87,6 +85,14 @@ namespace ArchiSteamFarm {
} }
} }
private static bool IsOwner(ulong steamID) {
if (steamID == 0) {
return false;
}
return steamID == Program.GlobalConfig.SteamOwnerID;
}
private static bool IsValidCdKey(string key) { private static bool IsValidCdKey(string key) {
if (string.IsNullOrEmpty(key)) { if (string.IsNullOrEmpty(key)) {
return false; return false;
@@ -171,10 +177,12 @@ namespace ArchiSteamFarm {
BotDatabase = BotDatabase.Load(botPath + ".db"); BotDatabase = BotDatabase.Load(botPath + ".db");
SentryFile = botPath + ".bin"; SentryFile = botPath + ".bin";
// Support and convert SDA files if (BotDatabase.SteamGuardAccount == null) {
string maFilePath = botPath + ".maFile"; // Support and convert SDA files
if (BotDatabase.SteamGuardAccount == null && File.Exists(maFilePath)) { string maFilePath = botPath + ".maFile";
ImportAuthenticator(maFilePath); if (File.Exists(maFilePath)) {
ImportAuthenticator(maFilePath);
}
} }
// Initialize // Initialize
@@ -232,7 +240,7 @@ namespace ArchiSteamFarm {
if (BotConfig.SendTradePeriod > 0 && SendItemsTimer == null) { if (BotConfig.SendTradePeriod > 0 && SendItemsTimer == null) {
SendItemsTimer = new Timer( SendItemsTimer = new Timer(
async e => await ResponseSendTrade().ConfigureAwait(false), async e => await ResponseSendTrade(BotConfig.SteamMasterID).ConfigureAwait(false),
null, null,
TimeSpan.FromHours(BotConfig.SendTradePeriod), // Delay TimeSpan.FromHours(BotConfig.SendTradePeriod), // Delay
TimeSpan.FromHours(BotConfig.SendTradePeriod) // Period TimeSpan.FromHours(BotConfig.SendTradePeriod) // Period
@@ -244,7 +252,15 @@ namespace ArchiSteamFarm {
} }
// Start // Start
Start().Wait(); Task.Run(async () => await Start().ConfigureAwait(false)).Forget();
}
internal bool IsMaster(ulong steamID) {
if (steamID == 0) {
return false;
}
return steamID == BotConfig.SteamMasterID || IsOwner(steamID);
} }
internal async Task AcceptConfirmations(Confirmation.ConfirmationType allowedConfirmationType = Confirmation.ConfirmationType.Unknown) { internal async Task AcceptConfirmations(Confirmation.ConfirmationType allowedConfirmationType = Confirmation.ConfirmationType.Unknown) {
@@ -294,99 +310,97 @@ namespace ArchiSteamFarm {
internal async Task OnFarmingFinished(bool farmedSomething) { internal async Task OnFarmingFinished(bool farmedSomething) {
if (farmedSomething && BotConfig.SendOnFarmingFinished) { if (farmedSomething && BotConfig.SendOnFarmingFinished) {
await ResponseSendTrade().ConfigureAwait(false); await ResponseSendTrade(BotConfig.SteamMasterID).ConfigureAwait(false);
} }
if (BotConfig.ShutdownOnFarmingFinished) { if (BotConfig.ShutdownOnFarmingFinished) {
await Shutdown().ConfigureAwait(false); await Shutdown().ConfigureAwait(false);
} }
} }
internal async Task<string> HandleMessage(string message) { internal async Task<string> Response(ulong steamID, string message) {
if (string.IsNullOrEmpty(message)) { if (steamID == 0 || string.IsNullOrEmpty(message)) {
return null; return null;
} }
if (!message.StartsWith("!")) { if (!message.StartsWith("!")) {
return await ResponseRedeem(BotName, message, true).ConfigureAwait(false); return await ResponseRedeem(steamID, BotName, message, true).ConfigureAwait(false);
} }
if (!message.Contains(" ")) { if (!message.Contains(" ")) {
switch (message) { switch (message) {
case "!2fa": case "!2fa":
return Response2FA(); return Response2FA(steamID);
case "!2faoff": case "!2faoff":
return Response2FAOff(); return Response2FAOff(steamID);
case "!2faok": case "!2faok":
return await Response2FAOK().ConfigureAwait(false); return await Response2FAOK(steamID).ConfigureAwait(false);
case "!exit": case "!exit":
Program.Exit(); return ResponseExit(steamID);
return null;
case "!farm": case "!farm":
return await ResponseFarm().ConfigureAwait(false); return await ResponseFarm(steamID).ConfigureAwait(false);
case "!loot": case "!loot":
return await ResponseSendTrade().ConfigureAwait(false); return await ResponseSendTrade(steamID).ConfigureAwait(false);
case "!rejoinchat": case "!rejoinchat":
return ResponseRejoinChat(); return ResponseRejoinChat(steamID);
case "!restart": case "!restart":
Program.Restart(); return ResponseRestart(steamID);
return null;
case "!status": case "!status":
return ResponseStatus(); return ResponseStatus(steamID);
case "!statusall": case "!statusall":
return ResponseStatusAll(); return ResponseStatusAll(steamID);
case "!stop": case "!stop":
return await ResponseStop().ConfigureAwait(false); return await ResponseStop(steamID).ConfigureAwait(false);
case "!update": case "!update":
await Program.CheckForUpdate().ConfigureAwait(false); return await ResponseUpdate(steamID).ConfigureAwait(false);
return "Done!";
default: default:
return "Unrecognized command: " + message; return ResponseUnknown(steamID);
} }
} else { } else {
string[] args = message.Split(' '); string[] args = message.Split(' ');
switch (args[0]) { switch (args[0]) {
case "!2fa": case "!2fa":
return Response2FA(args[1]); return Response2FA(steamID, args[1]);
case "!2faoff": case "!2faoff":
return Response2FAOff(args[1]); return Response2FAOff(steamID, args[1]);
case "!2faok": case "!2faok":
return await Response2FAOK(args[1]).ConfigureAwait(false); return await Response2FAOK(steamID, args[1]).ConfigureAwait(false);
case "!addlicense": case "!addlicense":
if (args.Length > 2) { if (args.Length > 2) {
return await ResponseAddLicense(args[1], args[2]).ConfigureAwait(false); return await ResponseAddLicense(steamID, args[1], args[2]).ConfigureAwait(false);
} else { } else {
return await ResponseAddLicense(BotName, args[1]).ConfigureAwait(false); return await ResponseAddLicense(steamID, BotName, args[1]).ConfigureAwait(false);
} }
case "!farm": case "!farm":
return await ResponseFarm(args[1]).ConfigureAwait(false); return await ResponseFarm(steamID, args[1]).ConfigureAwait(false);
case "!loot": case "!loot":
return await ResponseSendTrade(args[1]).ConfigureAwait(false); return await ResponseSendTrade(steamID, args[1]).ConfigureAwait(false);
case "!owns": case "!owns":
if (args.Length > 2) { if (args.Length > 2) {
return await ResponseOwns(args[1], args[2]).ConfigureAwait(false); return await ResponseOwns(steamID, args[1], args[2]).ConfigureAwait(false);
} else { } else {
return await ResponseOwns(BotName, args[1]).ConfigureAwait(false); return await ResponseOwns(steamID, BotName, args[1]).ConfigureAwait(false);
} }
case "!play": case "!play":
if (args.Length > 2) { if (args.Length > 2) {
return await ResponsePlay(args[1], args[2]).ConfigureAwait(false); return await ResponsePlay(steamID, args[1], args[2]).ConfigureAwait(false);
} else { } else {
return await ResponsePlay(BotName, args[1]).ConfigureAwait(false); return await ResponsePlay(steamID, BotName, args[1]).ConfigureAwait(false);
} }
case "!redeem": case "!redeem":
if (args.Length > 2) { if (args.Length > 2) {
return await ResponseRedeem(args[1], args[2], false).ConfigureAwait(false); return await ResponseRedeem(steamID, args[1], args[2], false).ConfigureAwait(false);
} else { } else {
return await ResponseRedeem(BotName, args[1], false).ConfigureAwait(false); return await ResponseRedeem(steamID, BotName, args[1], false).ConfigureAwait(false);
} }
case "!start": case "!start":
return await ResponseStart(args[1]).ConfigureAwait(false); return await ResponseStart(steamID, args[1]).ConfigureAwait(false);
case "!status": case "!status":
return ResponseStatus(args[1]); return ResponseStatus(steamID, args[1]);
case "!stop": case "!stop":
return await ResponseStop(args[1]).ConfigureAwait(false); return await ResponseStop(steamID, args[1]).ConfigureAwait(false);
default: default:
return "Unrecognized command: " + args[0]; return ResponseUnknown(steamID);
} }
} }
} }
@@ -492,7 +506,15 @@ namespace ArchiSteamFarm {
Logging.LogGenericInfo("Successfully finished importing mobile authenticator!", BotName); Logging.LogGenericInfo("Successfully finished importing mobile authenticator!", BotName);
} }
private string ResponseStatus() { private string ResponseStatus(ulong steamID) {
if (steamID == 0) {
return null;
}
if (!IsMaster(steamID)) {
return null;
}
if (CardsFarmer.CurrentGamesFarming.Count > 0) { if (CardsFarmer.CurrentGamesFarming.Count > 0) {
return "Bot " + BotName + " is currently farming appIDs: " + string.Join(", ", CardsFarmer.CurrentGamesFarming) + " and has a total of " + CardsFarmer.GamesToFarm.Count + " games left to farm."; return "Bot " + BotName + " is currently farming appIDs: " + string.Join(", ", CardsFarmer.CurrentGamesFarming) + " and has a total of " + CardsFarmer.GamesToFarm.Count + " games left to farm.";
} else { } else {
@@ -500,8 +522,8 @@ namespace ArchiSteamFarm {
} }
} }
private static string ResponseStatus(string botName) { private static string ResponseStatus(ulong steamID, string botName) {
if (string.IsNullOrEmpty(botName)) { if (steamID == 0 || string.IsNullOrEmpty(botName)) {
return null; return null;
} }
@@ -510,17 +532,25 @@ namespace ArchiSteamFarm {
return "Couldn't find any bot named " + botName + "!"; return "Couldn't find any bot named " + botName + "!";
} }
return bot.ResponseStatus(); return bot.ResponseStatus(steamID);
} }
private static string ResponseStatusAll() { private static string ResponseStatusAll(ulong steamID) {
if (steamID == 0) {
return null;
}
if (!IsOwner(steamID)) {
return null;
}
StringBuilder result = new StringBuilder(Environment.NewLine); StringBuilder result = new StringBuilder(Environment.NewLine);
int totalBotsCount = Bots.Count; int totalBotsCount = Bots.Count;
int runningBotsCount = 0; int runningBotsCount = 0;
foreach (Bot bot in Bots.Values) { foreach (Bot bot in Bots.Values) {
result.Append(bot.ResponseStatus() + Environment.NewLine); result.Append(bot.ResponseStatus(steamID) + Environment.NewLine);
if (bot.KeepRunning) { if (bot.KeepRunning) {
runningBotsCount++; runningBotsCount++;
} }
@@ -530,7 +560,15 @@ namespace ArchiSteamFarm {
return result.ToString(); return result.ToString();
} }
private async Task<string> ResponseSendTrade() { private async Task<string> ResponseSendTrade(ulong steamID) {
if (steamID == 0) {
return null;
}
if (!IsMaster(steamID)) {
return null;
}
if (BotConfig.SteamMasterID == 0) { if (BotConfig.SteamMasterID == 0) {
return "Trade couldn't be send because SteamMasterID is not defined!"; return "Trade couldn't be send because SteamMasterID is not defined!";
} }
@@ -550,8 +588,8 @@ namespace ArchiSteamFarm {
} }
} }
private static async Task<string> ResponseSendTrade(string botName) { private static async Task<string> ResponseSendTrade(ulong steamID, string botName) {
if (string.IsNullOrEmpty(botName)) { if (steamID == 0 || string.IsNullOrEmpty(botName)) {
return null; return null;
} }
@@ -560,10 +598,18 @@ namespace ArchiSteamFarm {
return "Couldn't find any bot named " + botName + "!"; return "Couldn't find any bot named " + botName + "!";
} }
return await bot.ResponseSendTrade().ConfigureAwait(false); return await bot.ResponseSendTrade(steamID).ConfigureAwait(false);
} }
private string Response2FA() { private string Response2FA(ulong steamID) {
if (steamID == 0) {
return null;
}
if (!IsMaster(steamID)) {
return null;
}
if (BotDatabase.SteamGuardAccount == null) { if (BotDatabase.SteamGuardAccount == null) {
return "That bot doesn't have ASF 2FA enabled!"; return "That bot doesn't have ASF 2FA enabled!";
} }
@@ -572,8 +618,8 @@ namespace ArchiSteamFarm {
return "2FA Token: " + BotDatabase.SteamGuardAccount.GenerateSteamGuardCode() + " (expires in " + timeLeft + " seconds)"; return "2FA Token: " + BotDatabase.SteamGuardAccount.GenerateSteamGuardCode() + " (expires in " + timeLeft + " seconds)";
} }
private static string Response2FA(string botName) { private static string Response2FA(ulong steamID, string botName) {
if (string.IsNullOrEmpty(botName)) { if (steamID == 0 || string.IsNullOrEmpty(botName)) {
return null; return null;
} }
@@ -582,10 +628,18 @@ namespace ArchiSteamFarm {
return "Couldn't find any bot named " + botName + "!"; return "Couldn't find any bot named " + botName + "!";
} }
return bot.Response2FA(); return bot.Response2FA(steamID);
} }
private string Response2FAOff() { private string Response2FAOff(ulong steamID) {
if (steamID == 0) {
return null;
}
if (!IsMaster(steamID)) {
return null;
}
if (BotDatabase.SteamGuardAccount == null) { if (BotDatabase.SteamGuardAccount == null) {
return "That bot doesn't have ASF 2FA enabled!"; return "That bot doesn't have ASF 2FA enabled!";
} }
@@ -597,8 +651,8 @@ namespace ArchiSteamFarm {
} }
} }
private static string Response2FAOff(string botName) { private static string Response2FAOff(ulong steamID, string botName) {
if (string.IsNullOrEmpty(botName)) { if (steamID == 0 || string.IsNullOrEmpty(botName)) {
return null; return null;
} }
@@ -607,10 +661,18 @@ namespace ArchiSteamFarm {
return "Couldn't find any bot named " + botName + "!"; return "Couldn't find any bot named " + botName + "!";
} }
return bot.Response2FAOff(); return bot.Response2FAOff(steamID);
} }
private async Task<string> Response2FAOK() { private async Task<string> Response2FAOK(ulong steamID) {
if (steamID == 0) {
return null;
}
if (!IsMaster(steamID)) {
return null;
}
if (BotDatabase.SteamGuardAccount == null) { if (BotDatabase.SteamGuardAccount == null) {
return "That bot doesn't have ASF 2FA enabled!"; return "That bot doesn't have ASF 2FA enabled!";
} }
@@ -619,8 +681,8 @@ namespace ArchiSteamFarm {
return "Done!"; return "Done!";
} }
private static async Task<string> Response2FAOK(string botName) { private static async Task<string> Response2FAOK(ulong steamID, string botName) {
if (string.IsNullOrEmpty(botName)) { if (steamID == 0 || string.IsNullOrEmpty(botName)) {
return null; return null;
} }
@@ -629,16 +691,37 @@ namespace ArchiSteamFarm {
return "Couldn't find any bot named " + botName + "!"; return "Couldn't find any bot named " + botName + "!";
} }
return await bot.Response2FAOK().ConfigureAwait(false); return await bot.Response2FAOK(steamID).ConfigureAwait(false);
} }
private async Task<string> ResponseFarm() { private static string ResponseExit(ulong steamID) {
if (steamID == 0) {
return null;
}
if (!IsOwner(steamID)) {
return null;
}
Program.Exit();
return null;
}
private async Task<string> ResponseFarm(ulong steamID) {
if (steamID == 0) {
return null;
}
if (!IsMaster(steamID)) {
return null;
}
await CardsFarmer.RestartFarming().ConfigureAwait(false); await CardsFarmer.RestartFarming().ConfigureAwait(false);
return "Done!"; return "Done!";
} }
private static async Task<string> ResponseFarm(string botName) { private static async Task<string> ResponseFarm(ulong steamID, string botName) {
if (string.IsNullOrEmpty(botName)) { if (steamID == 0 || string.IsNullOrEmpty(botName)) {
return null; return null;
} }
@@ -647,11 +730,15 @@ namespace ArchiSteamFarm {
return "Couldn't find any bot named " + botName + "!"; return "Couldn't find any bot named " + botName + "!";
} }
return await bot.ResponseFarm().ConfigureAwait(false); return await bot.ResponseFarm(steamID).ConfigureAwait(false);
} }
private async Task<string> ResponseRedeem(string message, bool validate) { private async Task<string> ResponseRedeem(ulong steamID, string message, bool validate) {
if (string.IsNullOrEmpty(message)) { if (steamID == 0 || string.IsNullOrEmpty(message)) {
return null;
}
if (!IsMaster(steamID)) {
return null; return null;
} }
@@ -791,8 +878,8 @@ namespace ArchiSteamFarm {
return response.ToString(); return response.ToString();
} }
private static async Task<string> ResponseRedeem(string botName, string message, bool validate) { private static async Task<string> ResponseRedeem(ulong steamID, string botName, string message, bool validate) {
if (string.IsNullOrEmpty(botName) || string.IsNullOrEmpty(message)) { if (steamID == 0 || string.IsNullOrEmpty(botName) || string.IsNullOrEmpty(message)) {
return null; return null;
} }
@@ -801,10 +888,18 @@ namespace ArchiSteamFarm {
return "Couldn't find any bot named " + botName + "!"; return "Couldn't find any bot named " + botName + "!";
} }
return await bot.ResponseRedeem(message, validate).ConfigureAwait(false); return await bot.ResponseRedeem(steamID, message, validate).ConfigureAwait(false);
} }
private static string ResponseRejoinChat() { private static string ResponseRejoinChat(ulong steamID) {
if (steamID == 0) {
return null;
}
if (!IsOwner(steamID)) {
return null;
}
foreach (Bot bot in Bots.Values) { foreach (Bot bot in Bots.Values) {
bot.JoinMasterChat(); bot.JoinMasterChat();
} }
@@ -812,8 +907,25 @@ namespace ArchiSteamFarm {
return "Done!"; return "Done!";
} }
private async Task<string> ResponseAddLicense(HashSet<uint> gameIDs) { private static string ResponseRestart(ulong steamID) {
if (gameIDs == null || gameIDs.Count == 0) { if (steamID == 0) {
return null;
}
if (!IsOwner(steamID)) {
return null;
}
Program.Restart();
return null;
}
private async Task<string> ResponseAddLicense(ulong steamID, HashSet<uint> gameIDs) {
if (steamID == 0 || gameIDs == null || gameIDs.Count == 0) {
return null;
}
if (!IsMaster(steamID)) {
return null; return null;
} }
@@ -833,8 +945,8 @@ namespace ArchiSteamFarm {
return result.ToString(); return result.ToString();
} }
private static async Task<string> ResponseAddLicense(string botName, string games) { private static async Task<string> ResponseAddLicense(ulong steamID, string botName, string games) {
if (string.IsNullOrEmpty(botName) || string.IsNullOrEmpty(games)) { if (steamID == 0 || string.IsNullOrEmpty(botName) || string.IsNullOrEmpty(games)) {
return null; return null;
} }
@@ -858,11 +970,15 @@ namespace ArchiSteamFarm {
return "Couldn't parse any games given!"; return "Couldn't parse any games given!";
} }
return await bot.ResponseAddLicense(gamesToRedeem).ConfigureAwait(false); return await bot.ResponseAddLicense(steamID, gamesToRedeem).ConfigureAwait(false);
} }
private async Task<string> ResponseOwns(string games) { private async Task<string> ResponseOwns(ulong steamID, string games) {
if (string.IsNullOrEmpty(games)) { if (steamID == 0 || string.IsNullOrEmpty(games)) {
return null;
}
if (!IsMaster(steamID)) {
return null; return null;
} }
@@ -900,8 +1016,8 @@ namespace ArchiSteamFarm {
} }
} }
private static async Task<string> ResponseOwns(string botName, string games) { private static async Task<string> ResponseOwns(ulong steamID, string botName, string games) {
if (string.IsNullOrEmpty(botName) || string.IsNullOrEmpty(games)) { if (steamID == 0 || string.IsNullOrEmpty(botName) || string.IsNullOrEmpty(games)) {
return null; return null;
} }
@@ -910,11 +1026,15 @@ namespace ArchiSteamFarm {
return "Couldn't find any bot named " + botName + "!"; return "Couldn't find any bot named " + botName + "!";
} }
return await bot.ResponseOwns(games).ConfigureAwait(false); return await bot.ResponseOwns(steamID, games).ConfigureAwait(false);
} }
private async Task<string> ResponsePlay(HashSet<uint> gameIDs) { private async Task<string> ResponsePlay(ulong steamID, HashSet<uint> gameIDs) {
if (gameIDs == null || gameIDs.Count == 0) { if (steamID == 0 || gameIDs == null || gameIDs.Count == 0) {
return null;
}
if (!IsMaster(steamID)) {
return null; return null;
} }
@@ -930,8 +1050,8 @@ namespace ArchiSteamFarm {
return "Done!"; return "Done!";
} }
private static async Task<string> ResponsePlay(string botName, string games) { private static async Task<string> ResponsePlay(ulong steamID, string botName, string games) {
if (string.IsNullOrEmpty(botName) || string.IsNullOrEmpty(games)) { if (steamID == 0 || string.IsNullOrEmpty(botName) || string.IsNullOrEmpty(games)) {
return null; return null;
} }
@@ -955,10 +1075,18 @@ namespace ArchiSteamFarm {
return "Couldn't parse any games given!"; return "Couldn't parse any games given!";
} }
return await bot.ResponsePlay(gamesToPlay).ConfigureAwait(false); return await bot.ResponsePlay(steamID, gamesToPlay).ConfigureAwait(false);
} }
private async Task<string> ResponseStart() { private async Task<string> ResponseStart(ulong steamID) {
if (steamID == 0) {
return null;
}
if (!IsMaster(steamID)) {
return null;
}
if (KeepRunning) { if (KeepRunning) {
return "That bot instance is already running!"; return "That bot instance is already running!";
} }
@@ -967,8 +1095,8 @@ namespace ArchiSteamFarm {
return "Done!"; return "Done!";
} }
private static async Task<string> ResponseStart(string botName) { private static async Task<string> ResponseStart(ulong steamID, string botName) {
if (string.IsNullOrEmpty(botName)) { if (steamID == 0 || string.IsNullOrEmpty(botName)) {
return null; return null;
} }
@@ -977,10 +1105,18 @@ namespace ArchiSteamFarm {
return "Couldn't find any bot named " + botName + "!"; return "Couldn't find any bot named " + botName + "!";
} }
return await bot.ResponseStart().ConfigureAwait(false); return await bot.ResponseStart(steamID).ConfigureAwait(false);
} }
private async Task<string> ResponseStop() { private async Task<string> ResponseStop(ulong steamID) {
if (steamID == 0) {
return null;
}
if (!IsMaster(steamID)) {
return null;
}
if (!KeepRunning) { if (!KeepRunning) {
return "That bot instance is already inactive!"; return "That bot instance is already inactive!";
} }
@@ -989,8 +1125,8 @@ namespace ArchiSteamFarm {
return "Done!"; return "Done!";
} }
private static async Task<string> ResponseStop(string botName) { private static async Task<string> ResponseStop(ulong steamID, string botName) {
if (string.IsNullOrEmpty(botName)) { if (steamID == 0 || string.IsNullOrEmpty(botName)) {
return null; return null;
} }
@@ -999,7 +1135,32 @@ namespace ArchiSteamFarm {
return "Couldn't find any bot named " + botName + "!"; return "Couldn't find any bot named " + botName + "!";
} }
return await bot.ResponseStop().ConfigureAwait(false); 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 null;
}
await Program.CheckForUpdate().ConfigureAwait(false);
return "Done!";
} }
private void HandleCallbacks() { private void HandleCallbacks() {
@@ -1009,12 +1170,12 @@ namespace ArchiSteamFarm {
} }
} }
private async Task HandleMessage(ulong steamID, string message) { private async Task HandleMessage(ulong chatID, ulong steamID, string message) {
if (steamID == 0 || string.IsNullOrEmpty(message)) { if (chatID == 0 || steamID == 0 || string.IsNullOrEmpty(message)) {
return; return;
} }
SendMessage(steamID, await HandleMessage(message).ConfigureAwait(false)); SendMessage(chatID, await Response(steamID, message).ConfigureAwait(false));
} }
private void SendMessage(ulong steamID, string message) { private void SendMessage(ulong steamID, string message) {
@@ -1223,7 +1384,7 @@ namespace ArchiSteamFarm {
return; return;
} }
if (callback.PatronID != BotConfig.SteamMasterID) { if (!IsMaster(callback.PatronID)) {
return; return;
} }
@@ -1239,7 +1400,7 @@ namespace ArchiSteamFarm {
return; return;
} }
if (callback.ChatterID != BotConfig.SteamMasterID) { if (!IsMaster(callback.ChatterID)) {
return; return;
} }
@@ -1248,7 +1409,7 @@ namespace ArchiSteamFarm {
SteamFriends.LeaveChat(callback.ChatRoomID); SteamFriends.LeaveChat(callback.ChatRoomID);
break; break;
default: default:
await HandleMessage(callback.ChatRoomID, callback.Message).ConfigureAwait(false); await HandleMessage(callback.ChatRoomID, callback.ChatterID, callback.Message).ConfigureAwait(false);
break; break;
} }
} }
@@ -1268,9 +1429,10 @@ namespace ArchiSteamFarm {
// TODO: Accept clan invites from master? // TODO: Accept clan invites from master?
break; break;
default: default:
if (friend.SteamID == BotConfig.SteamMasterID) { if (!IsMaster(friend.SteamID)) {
SteamFriends.AddFriend(friend.SteamID); break;
} }
SteamFriends.AddFriend(friend.SteamID);
break; break;
} }
} }
@@ -1285,11 +1447,7 @@ namespace ArchiSteamFarm {
return; return;
} }
if (callback.Sender != BotConfig.SteamMasterID) { await HandleMessage(callback.Sender, callback.Sender, callback.Message).ConfigureAwait(false);
return;
}
await HandleMessage(callback.Sender, callback.Message).ConfigureAwait(false);
} }
private async void OnFriendMsgHistory(SteamFriends.FriendMsgHistoryCallback callback) { private async void OnFriendMsgHistory(SteamFriends.FriendMsgHistoryCallback callback) {
@@ -1301,7 +1459,7 @@ namespace ArchiSteamFarm {
return; return;
} }
if (callback.SteamID != BotConfig.SteamMasterID) { if (!IsMaster(callback.SteamID)) {
return; return;
} }
@@ -1323,7 +1481,7 @@ namespace ArchiSteamFarm {
} }
// Handle the message // 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) { private void OnAccountInfo(SteamUser.AccountInfoCallback callback) {
@@ -1379,19 +1537,18 @@ namespace ArchiSteamFarm {
Program.GlobalDatabase.CellID = callback.CellID; Program.GlobalDatabase.CellID = callback.CellID;
} }
// Support and convert SDA files if (BotDatabase.SteamGuardAccount == null) {
string maFilePath = Path.Combine(Program.ConfigDirectory, callback.ClientSteamID.ConvertToUInt64() + ".maFile"); // Support and convert SDA files
if (BotDatabase.SteamGuardAccount == null && File.Exists(maFilePath)) { string maFilePath = Path.Combine(Program.ConfigDirectory, callback.ClientSteamID.ConvertToUInt64() + ".maFile");
ImportAuthenticator(maFilePath); if (File.Exists(maFilePath)) {
} ImportAuthenticator(maFilePath);
} else if (TwoFactorAuth == null && BotConfig.UseAsfAsMobileAuthenticator) {
if (BotConfig.UseAsfAsMobileAuthenticator && TwoFactorAuth == null && BotDatabase.SteamGuardAccount == null) { LinkMobileAuthenticator();
LinkMobileAuthenticator(); }
} }
// Reset one-time-only access tokens // Reset one-time-only access tokens
AuthCode = null; AuthCode = TwoFactorAuth = null;
TwoFactorAuth = null;
ResetGamesPlayed(); ResetGamesPlayed();
@@ -1405,20 +1562,24 @@ namespace ArchiSteamFarm {
} }
if (BotConfig.DismissInventoryNotifications) { if (BotConfig.DismissInventoryNotifications) {
await ArchiWebHandler.MarkInventory().ConfigureAwait(false); Task.Run(async () => await ArchiWebHandler.MarkInventory().ConfigureAwait(false)).Forget();
} }
if (BotConfig.SteamMasterClanID != 0) { if (BotConfig.SteamMasterClanID != 0) {
await ArchiWebHandler.JoinClan(BotConfig.SteamMasterClanID).ConfigureAwait(false); Task.Run(async () => {
JoinMasterChat(); await ArchiWebHandler.JoinClan(BotConfig.SteamMasterClanID).ConfigureAwait(false);
JoinMasterChat();
}).Forget();
} }
if (Program.GlobalConfig.Statistics) { if (Program.GlobalConfig.Statistics) {
await ArchiWebHandler.JoinClan(ArchiSCFarmGroup).ConfigureAwait(false); Task.Run(async () => {
SteamFriends.JoinChat(ArchiSCFarmGroup); 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(); Task.Run(async () => await CardsFarmer.StartFarming().ConfigureAwait(false)).Forget();
break; break;

View File

@@ -57,10 +57,10 @@ namespace ArchiSteamFarm {
} }
} }
[JsonProperty(Required = Required.AllowNull)] [JsonProperty]
private string _LoginKey; private string _LoginKey;
[JsonProperty(Required = Required.AllowNull)] [JsonProperty]
private SteamGuardAccount _SteamGuardAccount; private SteamGuardAccount _SteamGuardAccount;
private string FilePath; private string FilePath;

View File

@@ -47,6 +47,9 @@ namespace ArchiSteamFarm {
[JsonProperty(Required = Required.DisallowNull)] [JsonProperty(Required = Required.DisallowNull)]
internal EUpdateChannel UpdateChannel { get; private set; } = EUpdateChannel.Stable; internal EUpdateChannel UpdateChannel { get; private set; } = EUpdateChannel.Stable;
[JsonProperty(Required = Required.DisallowNull)]
internal ulong SteamOwnerID { get; private set; } = 0;
[JsonProperty(Required = Required.DisallowNull)] [JsonProperty(Required = Required.DisallowNull)]
internal byte MaxFarmingTime { get; private set; } = 10; internal byte MaxFarmingTime { get; private set; } = 10;
@@ -77,6 +80,9 @@ namespace ArchiSteamFarm {
[JsonProperty(Required = Required.DisallowNull)] [JsonProperty(Required = Required.DisallowNull)]
internal ushort WCFPort { get; private set; } = 1242; internal ushort WCFPort { get; private set; } = 1242;
[JsonProperty(Required = Required.DisallowNull)]
internal bool LogToFile { get; private set; } = true;
[JsonProperty(Required = Required.DisallowNull)] [JsonProperty(Required = Required.DisallowNull)]
internal bool Statistics { get; private set; } = true; internal bool Statistics { get; private set; } = true;

View File

@@ -31,18 +31,18 @@ namespace ArchiSteamFarm {
internal static class Logging { internal static class Logging {
private static readonly object FileLock = new object(); private static readonly object FileLock = new object();
internal static bool? LogToFile { get; set; } = null; private static bool LogToFile = false;
internal static void Init() { internal static void Init() {
if (!LogToFile.HasValue) { LogToFile = Program.GlobalConfig.LogToFile;
LogToFile = true;
}
lock (FileLock) { if (LogToFile) {
try { lock (FileLock) {
File.Delete(Program.LogFile); try {
} catch (Exception e) { File.Delete(Program.LogFile);
LogGenericException(e); } catch (Exception e) {
LogGenericException(e);
}
} }
} }
} }
@@ -123,7 +123,7 @@ namespace ArchiSteamFarm {
} catch { } } catch { }
} }
if (LogToFile.GetValueOrDefault()) { if (LogToFile) {
lock (FileLock) { lock (FileLock) {
try { try {
File.AppendAllText(Program.LogFile, loggedMessage); File.AppendAllText(Program.LogFile, loggedMessage);

View File

@@ -371,13 +371,6 @@ namespace ArchiSteamFarm {
switch (arg) { switch (arg) {
case "--client": case "--client":
Mode = EMode.Client; Mode = EMode.Client;
Logging.LogToFile = false;
break;
case "--log":
Logging.LogToFile = true;
break;
case "--no-log":
Logging.LogToFile = false;
break; break;
case "--server": case "--server":
Mode = EMode.Server; Mode = EMode.Server;
@@ -451,11 +444,11 @@ namespace ArchiSteamFarm {
// If debugging is on, we prepare debug directory prior to running // If debugging is on, we prepare debug directory prior to running
if (GlobalConfig.Debug) { if (GlobalConfig.Debug) {
if (Directory.Exists(Program.DebugDirectory)) { if (Directory.Exists(DebugDirectory)) {
Directory.Delete(Program.DebugDirectory, true); Directory.Delete(DebugDirectory, true);
Thread.Sleep(1000); // Dirty workaround giving Windows some time to sync Thread.Sleep(1000); // Dirty workaround giving Windows some time to sync
} }
Directory.CreateDirectory(Program.DebugDirectory); Directory.CreateDirectory(DebugDirectory);
SteamKit2.DebugLog.AddListener(new Debugging.DebugListener(Path.Combine(Program.DebugDirectory, "debug.txt"))); SteamKit2.DebugLog.AddListener(new Debugging.DebugListener(Path.Combine(Program.DebugDirectory, "debug.txt")));
SteamKit2.DebugLog.Enabled = true; SteamKit2.DebugLog.Enabled = true;

View File

@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.1.1")] [assembly: AssemblyVersion("2.0.1.3")]
[assembly: AssemblyFileVersion("2.0.1.1")] [assembly: AssemblyFileVersion("2.0.1.3")]

View File

@@ -116,7 +116,7 @@ namespace ArchiSteamFarm {
Logging.LogGenericInfo("Received command: " + input); Logging.LogGenericInfo("Received command: " + input);
string command = '!' + input; string command = '!' + input;
string output = bot.HandleMessage(command).Result; // TODO: This should be asynchronous string output = bot.Response(Program.GlobalConfig.SteamOwnerID, command).Result; // TODO: This should be asynchronous
Logging.LogGenericInfo("Answered to command: " + input + " with: " + output); Logging.LogGenericInfo("Answered to command: " + input + " with: " + output);
return output; return output;

View File

@@ -2,6 +2,7 @@
"Debug": false, "Debug": false,
"AutoUpdates": true, "AutoUpdates": true,
"UpdateChannel": 1, "UpdateChannel": 1,
"SteamOwnerID": 0,
"MaxFarmingTime": 10, "MaxFarmingTime": 10,
"IdleFarmingPeriod": 3, "IdleFarmingPeriod": 3,
"FarmingDelay": 5, "FarmingDelay": 5,
@@ -12,6 +13,7 @@
"HttpTimeout": 60, "HttpTimeout": 60,
"WCFHostname": "localhost", "WCFHostname": "localhost",
"WCFPort": 1242, "WCFPort": 1242,
"LogToFile": true,
"Statistics": true, "Statistics": true,
"HackIgnoreMachineID": false, "HackIgnoreMachineID": false,
"Blacklist": [ "Blacklist": [