gpt4 book ai didi

c# - 无法使用 SteamKit2 连接到 Steam

转载 作者:行者123 更新时间:2023-11-30 21:57:05 26 4
gpt4 key购买 nike

我正在使用 SteamKit2 在 C# 中制作一个交易报价机器人,并且大部分时间它都能成功连接到 Steam。但有些时候,当我让它在 client.connect(); 被调用之前输出“正在连接到 Steam...”时,它会卡住。它经常发生,需要修复,但我不知道问题出在哪里。这是我的代码(很多来自 SteamKit2 教程):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SteamKit2;

namespace ATO
{
class OfferSender
{
string username;
string password;

SteamClient client;
CallbackManager manager;
SteamUser user;

bool isRunning = false;

public OfferSender()
{

}

public void login()
{
Console.Write("Please enter your username: ");
username = Console.ReadLine();

Console.Write("Please enter your password: ");
password = Console.ReadLine();


client = new SteamClient();

manager = new CallbackManager(client);

user = client.GetHandler<SteamUser>();

new Callback<SteamClient.ConnectedCallback>(OnConnected, manager);

new Callback<SteamUser.LoggedOnCallback>(OnLoggedOn, manager);

isRunning = true;

Console.WriteLine("\nConnecting to Steam...\n");

client.Connect();



while(isRunning)
{
manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
}
Console.ReadKey();
}

public void OnConnected(SteamClient.ConnectedCallback callback)
{
if (callback.Result != EResult.OK)
{
Console.WriteLine("Error connecting to Steam: {0}", callback.Result);
isRunning = false;
return;
}

Console.WriteLine("Connected to steam.\nLogging in {0}...\n", username);

user.LogOn(new SteamUser.LogOnDetails {
Username = username,
Password = password
});
}

public void OnLoggedOn(SteamUser.LoggedOnCallback callback)
{
if (callback.Result == EResult.AccountLogonDenied)
{
Console.WriteLine("This account is SteamGuard protected.");
return;
}
if(callback.Result != EResult.OK)
{
Console.WriteLine("Unable to log in to steam {0}\n", callback.Result);
isRunning = false;
return;
}
Console.WriteLine("successfully logged in!");
Environment.Exit(0);
}

}
}

我该如何解决这个问题?

最佳答案

好吧,在用头敲击键盘后,我终于发现 Steam 会像任何其他新计算机或浏览器登录一样请求 AuthCode。

就是这样......

下面的代码处理 AuthCode 和 TwoFactor 身份验证: https://github.com/SteamRE/SteamKit/tree/master/Samples/5.SteamGuard

关于c# - 无法使用 SteamKit2 连接到 Steam,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30946313/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com