Skip to content

Commit

Permalink
🎨 ArchiSteamFarmPlus fixs
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzaz committed Feb 19, 2024
1 parent a973570 commit 4a5e344
Show file tree
Hide file tree
Showing 11 changed files with 657 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
namespace BD.WTTS.Models;

public class ArchiSteamFarmCommand
{
private const string ExecuteCommandChar = "!";

public static readonly Lazy<IReadOnlyCollection<ArchiSteamFarmCommand>> Commands = new(new ArchiSteamFarmCommand[]
{
new("2fa","2fa [Bots]","为指定机器人生成临时的​两步验证​令牌。"),
new("2fano","2fano [Bots]","为指定机器人拒绝所有等待操作的​两步验证​交易确认。"),
new("2faok","2faok [Bots]","为指定机器人接受所有等待操作的​两步验证​交易确认。"),
new("addlicense","addlicense [Bots] <Licenses>","为指定机器人激活给定的 Licenses (许可),该参数解释详见​下文。"),
new("balance","balance [Bots]","显示指定机器人的 Steam 钱包余额。"),
new("bgr","bgr [Bots]","显示指定机器人的 BGR(后台游戏激活器)队列信息。"),
new("encrypt","encrypt <encryptionMethod> <stringToEncrypt>","以给定的加密方式加密字符串——详见​下文的解释。"),
new("farm","farm [Bots]","重新启动指定机器人的挂卡模块。"),
new("fb","fb [Bots]","列出指定机器人的自动挂卡黑名单。"),
new("fbadd","fbadd [Bots] <AppIDs>","将给定的 AppIDs 加入指定机器人的自动挂卡黑名单。"),
new("fbrm","fbrm [Bots] <AppIDs>","将给定的 AppIDs 从指定机器人的自动挂卡黑名单中移除。"),
new("fq","fq [Bots]","列出指定机器人的优先挂卡队列。"),
new("fqadd","fqadd [Bots] <AppIDs>","将给定的 AppIDs 加入指定机器人的优先挂卡队列。"),
new("fqrm","fqrm [Bots] <AppIDs>","将给定的 AppIDs 从指定机器人的优先挂卡队列中移除。"),
new("hash","hash <hashingMethod> <stringToHash>","以指定的加密方式生成给定字符串的哈希值——详见​下文的解释。"),
new("help","help","显示帮助(指向此页面的链接)。"),
new("input","input [Bots] <Type> <Value>","为指定机器人填写给定的输入值,仅在 Headless 模式中可用——详见​下文的解释。"),
new("level","level [Bots]","显示指定机器人的 Steam 帐户等级。"),
new("loot","loot [Bots]","将指定机器人的所有 LootableTypes 社区物品拾取到其 SteamUserPermissions 属性中设置的 Master 用户(如果有多个则取 steamID 最小的)。"),
new("loot@","loot@ [Bots] <AppIDs>","将指定机器人的所有符合给定 AppIDs 的 LootableTypes 社区物品拾取到其 SteamUserPermissions 属性中设置的 Master 用户(如果有多个则取 steamID 最小的)。 此命令与 loot% 相反。"),
new("loot%","loot% [Bots] <AppIDs>","将指定机器人的所有不符合给定 AppIDs 的 LootableTypes 社区物品拾取到其 SteamUserPermissions 属性中设置的 Master 用户(如果有多个则取 steamID 最小的)。 此命令与 loot@ 相反。"),
new("loot^","loot^ [Bots] <AppID> <ContextID>","将指定机器人的 ContextID 库存分类中符合给定 AppID 的物品拾取到其 SteamUserPermissions 属性中设置的 Master 用户(如果有多个则取 steamID 最小的)。"),
new("mab","mab [Bots]","列出 MatchActively 自动交易的 App 黑名单。"),
new("mabadd","mabadd [Bots] <AppIDs>","将给定的 AppIDs 加入到 MatchActively 自动交易的 App 黑名单。"),
new("mabrm","mabrm [Bots] <AppIDs>","将给定的 AppIDs 从 MatchActively 自动交易 App 黑名单中移除。"),
new("nickname","nickname [Bots] <Nickname>","将指定机器人的昵称更改为 Nickname。"),
new("owns","owns [Bots] <Games>","检查指定机器人是否已拥有 Games,该参数解释详见​下文。"),
new("pause","pause [Bots]","永久暂停指定机器人的自动挂卡模块。 ASF 在本次会话中将不会再尝试对此帐户进行挂卡,除非您手动 resume 或者重启 ASF。"),
new("pause~","pause~ [Bots]","临时暂停指定机器人的自动挂卡模块。 挂卡进程将会在下次游戏事件或者机器人断开连接时自动恢复。 您可以 resume 以恢复挂卡。"),
new("pause&","pause& [Bots] <Seconds>","临时暂停指定机器人的自动挂卡模块 Seconds 秒。 之后,挂卡模块会自动恢复。"),
new("play","play [Bots] <AppIDs,GameName>","切换到手动挂卡——使指定机器人运行给定的 AppIDs,并且可选自定义 GameName 为游戏名称。 若要此功能正常工作,您的 Steam 帐户必须拥有所有您指定的 AppIDs 的有效许可,包括免费游戏。 使用 reset 或 resume 命令恢复。"),
new("points","points [Bots]","显示指定机器人的 Steam 商店​点数余额。"),
new("privacy","privacy [Bots] <Settings>","更改指定机器人的 Steam 隐私设置,可用选项见​下文。"),
new("redeem","redeem [Bots] <Keys>","为指定机器人激活给定的游戏序列号或钱包充值码。"),
new("redeem^","redeem^ [Bots] <Modes> <Keys>","以 Modes 模式为指定机器人激活给定的游戏序列号或钱包充值码,模式详见下文的​解释。"),
new("reset","reset [Bots]","重置为原始(之前的)游玩状态,用来配合 play 命令的手动挂卡模式使用。"),
new("resume","resume [Bots]","恢复指定机器人的自动挂卡进程。"),
new("start","start [Bots]","启动指定机器人。"),
new("stats","stats","显示进程统计信息,例如托管内存用量。"),
new("status","status [Bots]","显示指定机器人的状态。"),
new("stop","stop [Bots]","停止指定机器人。"),
new("tb","tb [Bots]","列出指定机器人的交易黑名单用户。"),
new("tbadd","tbadd [Bots] <SteamIDs64>","将给定的 SteamIDs 加入指定机器人的交易黑名单。"),
new("tbrm","tbrm [Bots] <SteamIDs64>","将给定的 SteamIDs 从指定机器人的交易黑名单中移除。"),
new("transfer","transfer [Bots] <TargetBot>","将指定机器人的所有 TransferableTypes 社区物品转移到一个目标机器人。"),
new("transfer@","transfer@ [Bots] <AppIDs> <TargetBot>","将指定机器人的所有符合给定 AppIDs 的 TransferableTypes 社区物品转移到一个目标机器人。 此命令与 transfer% 相反。"),
new("transfer%","transfer% [Bots] <AppIDs> <TargetBot>","将指定机器人的所有不符合给定 AppIDs 的 TransferableTypes 社区物品转移到一个目标机器人。 此命令与 transfer@ 相反。"),
new("transfer^","transfer^ [Bots] <AppID> <ContextID> <TargetBot>","将指定机器人的 ContextID 库存分类中符合给定 AppID 的物品转移到一个目标机器人。"),
new("unpack","unpack [Bots]","拆开指定机器人库存中的所有补充包。"),
new("version","version","显示 ASF 的版本号。"),
});

public ArchiSteamFarmCommand(string command, string? text = null, string? description = null)
{
Command = ExecuteCommandChar + command;
CommandText = ExecuteCommandChar + text;
Description = description;
}

public string Command { get; }

public string? CommandText { get; }

//public int Access { get; }

public string? Description { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
namespace BD.WTTS.Models;

/// <summary>
/// 命令历史记录
/// </summary>
public class ArchiSteamFarmCommandHistory
{
private List<string> commandHistory = new List<string>();
private int currentIndex = -1;
private string currentCommand = string.Empty;

#region Properties

/// <summary>
/// Gets the total number of commands in the history.
/// </summary>
public int Count
{
get { return commandHistory.Count; }
}

/// <summary>
/// Gets or sets the current command.
/// </summary>
/// <value>
/// The current command.
/// </value>
public string CurrentCommand
{
get
{ return currentCommand; }

set
{
if (!string.IsNullOrEmpty(value))
{
currentCommand = value;
}
}
}

/// <summary>
/// Gets the command history list.
/// </summary>
public List<string> CommandHistoryList
{
get { return commandHistory; }
}

/// <summary>
/// Gets or sets the current command history index.
/// </summary>
/// <value>
/// The current index.
/// </value>
public int CurrentIndex
{
get { return currentIndex; }
set { currentIndex = value; }
}

#endregion

#region Command Control

/// <summary>
/// Adds to history. Skips empty commands.
/// </summary>
/// <param name="command">The command to add.</param>
public void AddCommandToHistory(string command)
{
if (!string.IsNullOrEmpty(command)) { commandHistory.Add(command); }
}

/// <summary>
/// Clears the command history.
/// </summary>
public void ClearHistory()
{
commandHistory.Clear();
currentIndex = -1;
}

/// <summary>
/// Gets the next or previous command in the que.
/// </summary>
/// <returns></returns>
private string GetCommand()
{
string selected = currentCommand;

if (commandHistory.Count > 0)
{
if (currentIndex >= 0 && currentIndex < commandHistory.Count)
{
selected = commandHistory.ElementAt(currentIndex);
}
}

return selected;
}

/// <summary>
/// Gets the command at the selected index number.
/// </summary>
/// <param name="indexNumber">The index number.</param>
/// <returns></returns>
public string GetCommand(int indexNumber)
{
if (indexNumber >= 0 && indexNumber < commandHistory.Count) { return commandHistory.ElementAt(indexNumber); }
return string.Empty;
}

/// <summary>
/// Gets the previous command.
/// </summary>
/// <returns>The previous command.</returns>
public string GetPrevious()
{
currentIndex--;
if (currentIndex < 0) { currentIndex = commandHistory.Count - 1; }
return GetCommand();
}

/// <summary>
/// Gets the next command.
/// </summary>
/// <returns>The next command.</returns>
public string GetNext()
{
currentIndex++;
if (currentIndex >= commandHistory.Count) { currentIndex = 0; }
return GetCommand();
}

/// <summary>
/// Removes a command from the command history.
/// </summary>
/// <param name="indexNumber">The index number of the command to remove.</param>
public void RemoveFromCommandHistory(int indexNumber)
{
if (indexNumber >= 0 && indexNumber < commandHistory.Count)
{
commandHistory.RemoveAt(indexNumber);
}
else
{
throw new ArgumentOutOfRangeException("The selected index number was outside of the bounds of the list");
}
}

#endregion
}
12 changes: 9 additions & 3 deletions src/BD.WTTS.Client.Plugins.ArchiSteamFarmPlus/Plugins/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,23 @@ namespace BD.WTTS.Plugins;
#endif
public sealed class Plugin : PluginBase<Plugin>, IPlugin
{
const string moduleName = "ArchiSteamFarmPlus";
const string moduleName = AssemblyInfo.ArchiSteamFarmPlus;

public override Guid Id => Guid.Parse(AssemblyInfo.ArchiSteamFarmPlusId);

public sealed override string UniqueEnglishName => moduleName;

public override string Name => moduleName;
public override string Name => BDStrings.ArchiSteamFarmPlus;

protected sealed override string? AuthorOriginalString => null;

public sealed override string Description => moduleName;

public sealed override object? Icon => Resources.asf;

public override IEnumerable<MenuTabItemViewModel>? GetMenuTabItems()
{
yield return new MenuTabItemViewModel(this, "ArchiSteamFarmPlus")
yield return new MenuTabItemViewModel(this, nameof(BDStrings.ArchiSteamFarmPlus))
{
PageType = typeof(MainFramePage),
IsResourceGet = true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#if (WINDOWS || MACCATALYST || MACOS || LINUX) && !(IOS || ANDROID)
using ASFStrings = ArchiSteamFarm.Localization.Strings;
using AppResources = BD.WTTS.Client.Resources.Strings;
using ArchiSteamFarm.Core;
using ArchiSteamFarm.Storage;
using ArchiSteamFarm.Steam;
using ArchiSteamFarm.Steam.Storage;
using ArchiSteamFarm.IPC;
using Newtonsoft.Json.Linq;

Expand Down Expand Up @@ -58,7 +54,7 @@ public async Task ShellMessageInput(string data)
{
var result = await ExecuteCommandAsync(data);
if (!string.IsNullOrEmpty(result))
OnConsoleWirteLine?.Invoke(result);
OnConsoleWirteLine?.Invoke(Environment.NewLine + result);
}
}
}
Expand Down Expand Up @@ -127,7 +123,7 @@ public async Task ShellMessageInput(string data)
ASFProcess = Process.Start(options);

ASFService.Current.ConsoleLogText = string.Empty;
ThreadPool.QueueUserWorkItem(ReadOutPutData);
Task2.InBackground(ReadOutPutData, true);
AppDomain.CurrentDomain.ProcessExit += ExitHandler;
AppDomain.CurrentDomain.UnhandledException += ExitHandler;

Expand Down Expand Up @@ -228,10 +224,11 @@ async Task<bool> DownloadASFRelease(string downloadUrl, string savePath)

private void ExitHandler(object? sender, EventArgs eventArgs)
{
ASFService.Current.StopASFAsync().GetAwaiter().GetResult();
StopAsync().GetAwaiter().GetResult();
ASFService.Current.SteamBotsSourceList.Clear();
}

private async void ReadOutPutData(object? obj)
private async void ReadOutPutData()
{
using (StreamReader sr = ASFProcess!.StandardOutput)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#if (WINDOWS || MACCATALYST || MACOS || LINUX) && !(IOS || ANDROID)
using ArchiSteamFarm.Core;
using ArchiSteamFarm.Steam;
using ArchiSteamFarm.Steam.Storage;
using ArchiSteamFarm.Storage;
using Newtonsoft.Json;
using AppResources = BD.WTTS.Client.Resources.Strings;

Expand Down Expand Up @@ -33,14 +29,6 @@ public string? ConsoleLogText
set => this.RaiseAndSetIfChanged(ref _ConsoleLogText, value);
}

string? _ConsoleLogInput;

public string? ConsoleLogInput
{
get => _ConsoleLogInput;
set => this.RaiseAndSetIfChanged(ref _ConsoleLogInput, value);
}

public IConsoleBuilder ConsoleLogBuilder { get; } = new ConsoleBuilder();

public SourceCache<BotViewModel, string> SteamBotsSourceList;
Expand Down Expand Up @@ -76,19 +64,19 @@ void OnConsoleWirteLine(string message)
{
MainThread2.InvokeOnMainThreadAsync(() =>
{
ConsoleLogBuilder.AppendLine(message);
var text = ConsoleLogBuilder.ToString();
ConsoleLogText = text;
//ConsoleLogBuilder.Append(message); // message 包含换行
//var text = ConsoleLogBuilder.ToString();
ConsoleLogText += message;
});
}

public void ShellMessageInput()
public void ShellMessageInput(string? input)
{
if (string.IsNullOrEmpty(ConsoleLogInput))
if (string.IsNullOrEmpty(input))
{
return;
}
archiSteamFarmService.ShellMessageInput(ConsoleLogInput);
archiSteamFarmService.ShellMessageInput(input);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace BD.WTTS.UI.ViewModels;

public sealed partial class ArchiSteamFarmPlusPageViewModel : ViewModelBase
{

private readonly IArchiSteamFarmService asfService = IArchiSteamFarmService.Instance;

public ArchiSteamFarmPlusPageViewModel()
Expand All @@ -14,8 +15,6 @@ public ArchiSteamFarmPlusPageViewModel()

OpenASFBrowser = ReactiveCommand.Create<string>(ASFService.Current.OpenBrowser);

ShellMessageInput = ReactiveCommand.Create(ShellMessageInput_Click);

RunOrStop = ReactiveCommand.Create(RunOrStopASF);
}

Expand Down Expand Up @@ -63,7 +62,5 @@ public static void StartOrStopASF_Click(bool? startOrStop = null) => Task.Run(as

public void RunOrStopASF() => StartOrStopASF_Click();

public void ShellMessageInput_Click() => ASFService.Current.ShellMessageInput();

public string? IPCUrl => ASFService.Current.IPCUrl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public sealed partial class ArchiSteamFarmPlusPageViewModel
/// </summary>
public ICommand OpenASFBrowser { get; }

public ICommand ShellMessageInput { get; }

private bool _IsRedeemKeyDialogOpen;

public bool IsRedeemKeyDialogOpen
Expand Down
Loading

0 comments on commit 4a5e344

Please sign in to comment.