diff --git a/ArchiSteamFarm/ArchiHandler.cs b/ArchiSteamFarm/ArchiHandler.cs index bd417c2742d5b..5fc6c7833f2c9 100644 --- a/ArchiSteamFarm/ArchiHandler.cs +++ b/ArchiSteamFarm/ArchiHandler.cs @@ -205,8 +205,10 @@ internal AsyncJob RedeemKey(string key) { return null; } - var request = new ClientMsgProtobuf(EMsg.ClientRegisterKey); - request.SourceJobID = Client.GetNextJobID(); + var request = new ClientMsgProtobuf(EMsg.ClientRegisterKey) { + SourceJobID = Client.GetNextJobID() + }; + request.Body.key = key; Client.Send(request); @@ -222,7 +224,7 @@ _ _ _ _ */ - public sealed override void HandleMsg(IPacketMsg packetMsg) { + public override void HandleMsg(IPacketMsg packetMsg) { if (packetMsg == null) { return; } @@ -246,10 +248,6 @@ private void HandleFSOfflineMessageNotification(IPacketMsg packetMsg) { } var response = new ClientMsgProtobuf(packetMsg); - if (response == null) { - return; - } - Client.PostCallback(new OfflineMessageCallback(packetMsg.TargetJobID, response.Body)); } @@ -259,10 +257,6 @@ private void HandlePurchaseResponse(IPacketMsg packetMsg) { } var response = new ClientMsgProtobuf(packetMsg); - if (response == null) { - return; - } - Client.PostCallback(new PurchaseResponseCallback(packetMsg.TargetJobID, response.Body)); } @@ -272,10 +266,6 @@ private void HandleUserNotifications(IPacketMsg packetMsg) { } var response = new ClientMsgProtobuf(packetMsg); - if (response == null) { - return; - } - Client.PostCallback(new NotificationsCallback(packetMsg.TargetJobID, response.Body)); } } diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 69c0a3c6c3ffc..ea7299628aaec 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -241,7 +241,89 @@ internal async Task Restart() { await Start().ConfigureAwait(false); } - internal async Task Start() { + internal async Task OnFarmingFinished(bool farmedSomething) { + if (farmedSomething && SendOnFarmingFinished) { + await ResponseSendTrade().ConfigureAwait(false); + } + if (ShutdownOnFarmingFinished) { + Shutdown(); + } + } + + internal async Task HandleMessage(string message) { + if (string.IsNullOrEmpty(message)) { + return null; + } + + if (!message.StartsWith("!")) { + return await ResponseRedeem(BotName, message, true).ConfigureAwait(false); + } + + if (!message.Contains(" ")) { + switch (message) { + case "!2fa": + return Response2FA(); + case "!2faoff": + return Response2FAOff(); + case "!exit": + Program.Exit(); + return null; + case "!rejoinchat": + return ResponseRejoinChat(); + case "!restart": + Program.Restart(); + return "Done"; + case "!status": + return ResponseStatus(); + case "!statusall": + return ResponseStatusAll(); + case "!stop": + return ResponseStop(); + case "!loot": + return await ResponseSendTrade().ConfigureAwait(false); + default: + return "Unrecognized command: " + message; + } + } else { + string[] args = message.Split(' '); + switch (args[0]) { + case "!2fa": + return Response2FA(args[1]); + case "!2faoff": + return Response2FAOff(args[1]); + case "!addlicense": + if (args.Length > 2) { + return await ResponseAddLicense(args[1], args[2]).ConfigureAwait(false); + } else { + return await ResponseAddLicense(BotName, args[1]).ConfigureAwait(false); + } + case "!play": + if (args.Length > 2) { + return await ResponsePlay(args[1], args[2]).ConfigureAwait(false); + } else { + return await ResponsePlay(BotName, args[1]).ConfigureAwait(false); + } + case "!redeem": + if (args.Length > 2) { + return await ResponseRedeem(args[1], args[2], false).ConfigureAwait(false); + } else { + return await ResponseRedeem(BotName, args[1], false).ConfigureAwait(false); + } + case "!start": + return await ResponseStart(args[1]).ConfigureAwait(false); + case "!stop": + return ResponseStop(args[1]); + case "!status": + return ResponseStatus(args[1]); + case "!loot": + return await ResponseSendTrade(args[1]).ConfigureAwait(false); + default: + return "Unrecognized command: " + args[0]; + } + } + } + + private async Task Start() { if (SteamClient.IsConnected) { return; } @@ -261,7 +343,7 @@ internal async Task Start() { SteamClient.Connect(); } - internal void Stop() { + private void Stop() { if (!SteamClient.IsConnected) { return; } @@ -271,22 +353,13 @@ internal void Stop() { SteamClient.Disconnect(); } - internal void Shutdown() { + private void Shutdown() { KeepRunning = false; Stop(); Program.OnBotShutdown(); } - internal async Task OnFarmingFinished(bool farmedSomething) { - if (farmedSomething && SendOnFarmingFinished) { - await ResponseSendTrade().ConfigureAwait(false); - } - if (ShutdownOnFarmingFinished) { - Shutdown(); - } - } - - internal string ResponseStatus() { + private string ResponseStatus() { 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."; } else { @@ -294,7 +367,7 @@ internal string ResponseStatus() { } } - internal static string ResponseStatus(string botName) { + private static string ResponseStatus(string botName) { if (string.IsNullOrEmpty(botName)) { return null; } @@ -307,7 +380,7 @@ internal static string ResponseStatus(string botName) { return bot.ResponseStatus(); } - internal static string ResponseStatusAll() { + private static string ResponseStatusAll() { StringBuilder result = new StringBuilder(Environment.NewLine); int totalBotsCount = Bots.Count; @@ -324,7 +397,7 @@ internal static string ResponseStatusAll() { return result.ToString(); } - internal async Task ResponseSendTrade() { + private async Task ResponseSendTrade() { if (SteamMasterID == 0) { return "Trade couldn't be send because SteamMasterID is not defined!"; } @@ -349,7 +422,7 @@ internal async Task ResponseSendTrade() { } } - internal static async Task ResponseSendTrade(string botName) { + private static async Task ResponseSendTrade(string botName) { if (string.IsNullOrEmpty(botName)) { return null; } @@ -362,7 +435,7 @@ internal static async Task ResponseSendTrade(string botName) { return await bot.ResponseSendTrade().ConfigureAwait(false); } - internal string Response2FA() { + private string Response2FA() { if (SteamGuardAccount == null) { return "That bot doesn't have ASF 2FA enabled!"; } @@ -371,7 +444,7 @@ internal string Response2FA() { return "2FA Token: " + SteamGuardAccount.GenerateSteamGuardCode() + " (expires in " + timeLeft + " seconds)"; } - internal static string Response2FA(string botName) { + private static string Response2FA(string botName) { if (string.IsNullOrEmpty(botName)) { return null; } @@ -384,7 +457,7 @@ internal static string Response2FA(string botName) { return bot.Response2FA(); } - internal string Response2FAOff() { + private string Response2FAOff() { if (SteamGuardAccount == null) { return "That bot doesn't have ASF 2FA enabled!"; } @@ -396,7 +469,7 @@ internal string Response2FAOff() { } } - internal static string Response2FAOff(string botName) { + private static string Response2FAOff(string botName) { if (string.IsNullOrEmpty(botName)) { return null; } @@ -409,7 +482,7 @@ internal static string Response2FAOff(string botName) { return bot.Response2FAOff(); } - internal async Task ResponseRedeem(string message, bool validate) { + private async Task ResponseRedeem(string message, bool validate) { if (string.IsNullOrEmpty(message)) { return null; } @@ -550,7 +623,7 @@ internal async Task ResponseRedeem(string message, bool validate) { return response.ToString(); } - internal static async Task ResponseRedeem(string botName, string message, bool validate) { + private static async Task ResponseRedeem(string botName, string message, bool validate) { if (string.IsNullOrEmpty(botName) || string.IsNullOrEmpty(message)) { return null; } @@ -563,7 +636,7 @@ internal static async Task ResponseRedeem(string botName, string message return await bot.ResponseRedeem(message, validate).ConfigureAwait(false); } - internal static string ResponseRejoinChat() { + private static string ResponseRejoinChat() { foreach (Bot bot in Bots.Values) { bot.JoinMasterChat(); } @@ -571,7 +644,7 @@ internal static string ResponseRejoinChat() { return "Done!"; } - internal async Task ResponseAddLicense(HashSet gameIDs) { + private async Task ResponseAddLicense(HashSet gameIDs) { if (gameIDs == null || gameIDs.Count == 0) { return null; } @@ -592,7 +665,7 @@ internal async Task ResponseAddLicense(HashSet gameIDs) { return result.ToString(); } - internal static async Task ResponseAddLicense(string botName, string games) { + private static async Task ResponseAddLicense(string botName, string games) { if (string.IsNullOrEmpty(botName) || string.IsNullOrEmpty(games)) { return null; } @@ -620,7 +693,7 @@ internal static async Task ResponseAddLicense(string botName, string gam return await bot.ResponseAddLicense(gamesToRedeem).ConfigureAwait(false); } - internal async Task ResponsePlay(HashSet gameIDs) { + private async Task ResponsePlay(HashSet gameIDs) { if (gameIDs == null || gameIDs.Count == 0) { return null; } @@ -637,7 +710,7 @@ internal async Task ResponsePlay(HashSet gameIDs) { return "Done!"; } - internal static async Task ResponsePlay(string botName, string games) { + private static async Task ResponsePlay(string botName, string games) { if (string.IsNullOrEmpty(botName) || string.IsNullOrEmpty(games)) { return null; } @@ -665,7 +738,7 @@ internal static async Task ResponsePlay(string botName, string games) { return await bot.ResponsePlay(gamesToPlay).ConfigureAwait(false); } - internal async Task ResponseStart() { + private async Task ResponseStart() { if (KeepRunning) { return "That bot instance is already running!"; } @@ -674,7 +747,7 @@ internal async Task ResponseStart() { return "Done!"; } - internal static async Task ResponseStart(string botName) { + private static async Task ResponseStart(string botName) { if (string.IsNullOrEmpty(botName)) { return null; } @@ -687,7 +760,7 @@ internal static async Task ResponseStart(string botName) { return await bot.ResponseStart().ConfigureAwait(false); } - internal string ResponseStop() { + private string ResponseStop() { if (!KeepRunning) { return "That bot instance is already inactive!"; } @@ -696,7 +769,7 @@ internal string ResponseStop() { return "Done!"; } - internal static string ResponseStop(string botName) { + private static string ResponseStop(string botName) { if (string.IsNullOrEmpty(botName)) { return null; } @@ -709,79 +782,6 @@ internal static string ResponseStop(string botName) { return bot.ResponseStop(); } - internal async Task HandleMessage(string message) { - if (string.IsNullOrEmpty(message)) { - return null; - } - - if (!message.StartsWith("!")) { - return await ResponseRedeem(BotName, message, true).ConfigureAwait(false); - } - - if (!message.Contains(" ")) { - switch (message) { - case "!2fa": - return Response2FA(); - case "!2faoff": - return Response2FAOff(); - case "!exit": - Program.Exit(); - return null; - case "!rejoinchat": - return ResponseRejoinChat(); - case "!restart": - Program.Restart(); - return "Done"; - case "!status": - return ResponseStatus(); - case "!statusall": - return ResponseStatusAll(); - case "!stop": - return ResponseStop(); - case "!loot": - return await ResponseSendTrade().ConfigureAwait(false); - default: - return "Unrecognized command: " + message; - } - } else { - string[] args = message.Split(' '); - switch (args[0]) { - case "!2fa": - return Response2FA(args[1]); - case "!2faoff": - return Response2FAOff(args[1]); - case "!addlicense": - if (args.Length > 2) { - return await ResponseAddLicense(args[1], args[2]).ConfigureAwait(false); - } else { - return await ResponseAddLicense(BotName, args[1]).ConfigureAwait(false); - } - case "!play": - if (args.Length > 2) { - return await ResponsePlay(args[1], args[2]).ConfigureAwait(false); - } else { - return await ResponsePlay(BotName, args[1]).ConfigureAwait(false); - } - case "!redeem": - if (args.Length > 2) { - return await ResponseRedeem(args[1], args[2], false).ConfigureAwait(false); - } else { - return await ResponseRedeem(BotName, args[1], false).ConfigureAwait(false); - } - case "!start": - return await ResponseStart(args[1]).ConfigureAwait(false); - case "!stop": - return ResponseStop(args[1]); - case "!status": - return ResponseStatus(args[1]); - case "!loot": - return await ResponseSendTrade(args[1]).ConfigureAwait(false); - default: - return "Unrecognized command: " + args[0]; - } - } - } - private void HandleCallbacks() { TimeSpan timeSpan = TimeSpan.FromMilliseconds(CallbackSleep); while (KeepRunning) { diff --git a/ArchiSteamFarm/CMsgClientClanInviteAction.cs b/ArchiSteamFarm/CMsgClientClanInviteAction.cs index 7121e62e95493..d8369aaeb0998 100644 --- a/ArchiSteamFarm/CMsgClientClanInviteAction.cs +++ b/ArchiSteamFarm/CMsgClientClanInviteAction.cs @@ -28,7 +28,7 @@ limitations under the License. using System.IO; namespace ArchiSteamFarm { - internal sealed class CMsgClientClanInviteAction : ISteamSerializableMessage, ISteamSerializable { + internal sealed class CMsgClientClanInviteAction : ISteamSerializableMessage { internal ulong GroupID { get; set; } = 0; internal bool AcceptInvite { get; set; } = true; diff --git a/ArchiSteamFarm/Debugging.cs b/ArchiSteamFarm/Debugging.cs index 94bdb84790de3..99db846540df3 100644 --- a/ArchiSteamFarm/Debugging.cs +++ b/ArchiSteamFarm/Debugging.cs @@ -30,6 +30,6 @@ internal static class Debugging { internal static readonly bool IsDebugBuild = false; #endif - internal static bool IsReleaseBuild { get { return !IsDebugBuild; } } + internal static bool IsReleaseBuild => !IsDebugBuild; } } diff --git a/ArchiSteamFarm/Program.cs b/ArchiSteamFarm/Program.cs index 97fba75cb504e..80781a6c34245 100644 --- a/ArchiSteamFarm/Program.cs +++ b/ArchiSteamFarm/Program.cs @@ -221,7 +221,7 @@ private static void UnhandledExceptionHandler(object sender, UnhandledExceptionE } private static void Main(string[] args) { - AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionHandler); + AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler; Logging.LogGenericInfo("Archi's Steam Farm, version " + Version); Directory.SetCurrentDirectory(ExecutableDirectory); diff --git a/ArchiSteamFarm/Utilities.cs b/ArchiSteamFarm/Utilities.cs index d797370e0f46f..d5c43cc4c0afe 100644 --- a/ArchiSteamFarm/Utilities.cs +++ b/ArchiSteamFarm/Utilities.cs @@ -22,7 +22,6 @@ limitations under the License. */ -using System.Net; using System.Text.RegularExpressions; using System.Threading.Tasks; diff --git a/ArchiSteamFarm/WCF.cs b/ArchiSteamFarm/WCF.cs index f2d050bbb7d3d..9ef7073ddcd04 100644 --- a/ArchiSteamFarm/WCF.cs +++ b/ArchiSteamFarm/WCF.cs @@ -33,7 +33,7 @@ internal interface IWCF { string HandleCommand(string input); } - internal class WCF : IWCF { + internal sealed class WCF : IWCF { private const string URL = "http://localhost:1242/ASF"; // 1242 = 1024 + A(65) + S(83) + F(70) @@ -118,7 +118,7 @@ public string HandleCommand(string input) { } } - internal class Client : ClientBase, IWCF { + internal sealed class Client : ClientBase, IWCF { internal Client(Binding binding, EndpointAddress address) : base(binding, address) { } public string HandleCommand(string input) {