mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 22:20:52 +00:00
WCF 1.5/2
This commit is contained in:
@@ -31,6 +31,7 @@ using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
|
||||
@@ -39,9 +40,9 @@ namespace ArchiSteamFarm {
|
||||
private const ulong ArchiSCFarmGroup = 103582791440160998;
|
||||
private const ushort CallbackSleep = 500; // In miliseconds
|
||||
|
||||
private static readonly ConcurrentDictionary<string, Bot> Bots = new ConcurrentDictionary<string, Bot>();
|
||||
private static readonly uint LoginID = MsgClientLogon.ObfuscationMask; // This must be the same for all ASF bots and all ASF processes
|
||||
|
||||
internal static readonly ConcurrentDictionary<string, Bot> Bots = new ConcurrentDictionary<string, Bot>();
|
||||
internal static readonly HashSet<uint> GlobalBlacklist = new HashSet<uint> { 303700, 335590, 368020, 425280 };
|
||||
|
||||
private readonly string ConfigFile, LoginKeyFile, MobileAuthenticatorFile, SentryFile;
|
||||
@@ -424,26 +425,17 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
}
|
||||
|
||||
private void ResponseStatus(ulong steamID, string botName = null) {
|
||||
if (steamID == 0) {
|
||||
return;
|
||||
internal static string ResponseStatus(string botName) {
|
||||
if (string.IsNullOrEmpty(botName)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Bot bot;
|
||||
|
||||
if (string.IsNullOrEmpty(botName)) {
|
||||
bot = this;
|
||||
} else {
|
||||
if (!Bots.TryGetValue(botName, out bot)) {
|
||||
SendMessage(steamID, "Couldn't find any bot named " + botName + "!");
|
||||
return;
|
||||
}
|
||||
if (!Bots.TryGetValue(botName, out bot)) {
|
||||
return "Couldn't find any bot named " + botName + "!";
|
||||
}
|
||||
|
||||
if (bot.CardsFarmer.CurrentGamesFarming.Count > 0) {
|
||||
SendMessage(steamID, "Bot " + bot.BotName + " is currently farming appIDs: " + string.Join(", ", bot.CardsFarmer.CurrentGamesFarming) + " and has a total of " + bot.CardsFarmer.GamesToFarm.Count + " games left to farm");
|
||||
}
|
||||
SendMessage(steamID, "Currently " + Bots.Count + " bots are running");
|
||||
return "Bot " + bot.BotName + " is currently farming appIDs: " + string.Join(", ", bot.CardsFarmer.CurrentGamesFarming) + " and has a total of " + bot.CardsFarmer.GamesToFarm.Count + " games left to farm";
|
||||
}
|
||||
|
||||
private void Response2FA(ulong steamID, string botName = null) {
|
||||
@@ -582,7 +574,7 @@ namespace ArchiSteamFarm {
|
||||
await Program.Restart().ConfigureAwait(false);
|
||||
break;
|
||||
case "!status":
|
||||
ResponseStatus(steamID);
|
||||
SendMessage(steamID, ResponseStatus(BotName));
|
||||
break;
|
||||
case "!stop":
|
||||
await Shutdown().ConfigureAwait(false);
|
||||
@@ -607,7 +599,7 @@ namespace ArchiSteamFarm {
|
||||
await ResponseStop(steamID, args[1]).ConfigureAwait(false);
|
||||
break;
|
||||
case "!status":
|
||||
ResponseStatus(steamID, args[1]);
|
||||
SendMessage(steamID, ResponseStatus(args[1]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace ArchiSteamFarm {
|
||||
|
||||
internal static async Task Restart() {
|
||||
await Bot.ShutdownAllBots().ConfigureAwait(false);
|
||||
System.Diagnostics.Process.Start(ExecutableFile);
|
||||
System.Diagnostics.Process.Start(ExecutableFile, string.Join(" ", Environment.GetCommandLineArgs()));
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
internal static void OnBotShutdown() {
|
||||
if (Bot.GetRunningBotsCount() == 0) {
|
||||
if (Mode != EMode.Server && Bot.GetRunningBotsCount() == 0) {
|
||||
Logging.LogGenericInfo("Main", "No bots are running, exiting");
|
||||
ShutdownResetEvent.Set();
|
||||
}
|
||||
@@ -190,7 +190,8 @@ namespace ArchiSteamFarm {
|
||||
continue;
|
||||
}
|
||||
|
||||
WCF.SendCommand(arg);
|
||||
Logging.LogGenericNotice("WCF", "Command sent: " + arg);
|
||||
Logging.LogGenericNotice("WCF", "Response received: " + WCF.SendCommand(arg));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
using System;
|
||||
using System.ServiceModel;
|
||||
using System.ServiceModel.Channels;
|
||||
|
||||
namespace ArchiSteamFarm {
|
||||
[ServiceContract]
|
||||
internal interface IWCF {
|
||||
[OperationContract]
|
||||
string SendCommand(string command);
|
||||
string HandleCommand(string input);
|
||||
}
|
||||
|
||||
internal class WCF : IWCF {
|
||||
|
||||
private const string URL = "http://localhost:1242/ASF"; // 1242 = 1024 + A(65) + S(83) + F(70)
|
||||
|
||||
private ServiceHost ServiceHost;
|
||||
private Client Client;
|
||||
|
||||
internal void StartServer() {
|
||||
if (ServiceHost != null) {
|
||||
@@ -45,8 +48,45 @@ namespace ArchiSteamFarm {
|
||||
ServiceHost = null;
|
||||
}
|
||||
|
||||
public string SendCommand(string command) {
|
||||
throw new NotImplementedException();
|
||||
internal string SendCommand(string input) {
|
||||
if (Client == null) {
|
||||
Client = new Client(new BasicHttpBinding(), new EndpointAddress(URL));
|
||||
}
|
||||
|
||||
return Client.HandleCommand(input);
|
||||
}
|
||||
|
||||
public string HandleCommand(string input) {
|
||||
if (string.IsNullOrEmpty(input)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
string[] args = input.Split(' ');
|
||||
if (args.Length < 2) {
|
||||
return "Too few arguments, expected: <Command> <BotName> <ExtraArgs>";
|
||||
}
|
||||
|
||||
string command = args[0];
|
||||
string botName = args[1];
|
||||
string argument;
|
||||
if (args.Length > 2) {
|
||||
argument = args[3];
|
||||
}
|
||||
|
||||
switch (command) {
|
||||
case "status":
|
||||
return Bot.ResponseStatus(botName);
|
||||
default:
|
||||
return "Unrecognized command: " + command;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class Client : ClientBase<IWCF>, IWCF {
|
||||
internal Client(Binding binding, EndpointAddress address) : base(binding, address) { }
|
||||
|
||||
public string HandleCommand(string input) {
|
||||
return Channel.HandleCommand(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user