mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-05 00:20:08 +00:00
WCF: Make it possible to launch also non-targetted commands
This commit is contained in:
@@ -98,6 +98,14 @@ namespace ArchiSteamFarm {
|
||||
return true;
|
||||
}
|
||||
|
||||
internal static string GetAnyBotName() {
|
||||
foreach (string botName in Bots.Keys) {
|
||||
return botName;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
internal static int GetRunningBotsCount() {
|
||||
return Bots.Count;
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
internal static void OnBotShutdown() {
|
||||
if (Mode != EMode.Server && Bot.GetRunningBotsCount() == 0) {
|
||||
if (Bot.GetRunningBotsCount() == 0) {
|
||||
Logging.LogGenericInfo("Main", "No bots are running, exiting");
|
||||
ShutdownResetEvent.Set();
|
||||
}
|
||||
@@ -190,10 +190,10 @@ namespace ArchiSteamFarm {
|
||||
continue;
|
||||
}
|
||||
|
||||
Logging.LogGenericNotice("WCF", "Command sent: " + arg);
|
||||
Logging.LogGenericNotice("WCF", "Command sent: \"" + arg + "\"");
|
||||
|
||||
// We intentionally execute this async block synchronously
|
||||
Logging.LogGenericNotice("WCF", "Response received: " + WCF.SendCommand(arg));
|
||||
Logging.LogGenericNotice("WCF", "Response received: \"" + WCF.SendCommand(arg) + "\"");
|
||||
/*
|
||||
Task.Run(async () => {
|
||||
Logging.LogGenericNotice("WCF", "Response received: " + await WCF.SendCommand(arg).ConfigureAwait(false));
|
||||
@@ -257,12 +257,14 @@ namespace ArchiSteamFarm {
|
||||
// Check if we got any bots running
|
||||
OnBotShutdown();
|
||||
|
||||
// Wait for signal to shutdown
|
||||
ShutdownResetEvent.WaitOne();
|
||||
|
||||
// We got a signal to shutdown
|
||||
WCF.StopServer();
|
||||
// We got a signal to shutdown, consider giving user some time to read the message
|
||||
Thread.Sleep(5000);
|
||||
|
||||
Thread.Sleep(5000); // We're shuting down, consider giving user some time to read the message
|
||||
// This is over, cleanup only now
|
||||
WCF.StopServer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,21 +63,27 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
string[] args = input.Split(' ');
|
||||
if (args.Length < 2) {
|
||||
return "ERROR: Too few arguments, expected: <Command> <BotName> (ExtraArgs)";
|
||||
|
||||
string botName;
|
||||
|
||||
if (args.Length > 1) { // If we have args[1] provided, use given botName
|
||||
botName = args[1];
|
||||
} else { // If not, just pick first one
|
||||
botName = Bot.GetAnyBotName();
|
||||
}
|
||||
|
||||
// Bot name is args[1]
|
||||
string botName = args[1];
|
||||
if (string.IsNullOrEmpty(botName)) {
|
||||
return "ERROR: Invalid botName: " + botName;
|
||||
}
|
||||
|
||||
Bot bot;
|
||||
if (!Bot.Bots.TryGetValue(botName, out bot)) {
|
||||
return "ERROR: Couldn't find any bot named " + botName;
|
||||
return "ERROR: Couldn't find any bot named: " + botName;
|
||||
}
|
||||
|
||||
string command = '!' + input;
|
||||
Logging.LogGenericInfo("WCF", "Received command: \"" + command + "\"");
|
||||
Logging.LogGenericInfo("WCF", "Received command: \"" + input + "\"");
|
||||
|
||||
string command = '!' + input;
|
||||
string output = bot.HandleMessage(command).Result; // TODO: This should be asynchronous
|
||||
|
||||
Logging.LogGenericInfo("WCF", "Answered to command: \"" + input + "\" with: \"" + output + "\"");
|
||||
|
||||
Reference in New Issue
Block a user