ZeroLauncher/Manager/LoginManager.cs

121 lines
4.9 KiB
C#
Raw Normal View History

2024-05-19 10:43:41 +08:00
using System.Diagnostics;
using System.Drawing;
2024-06-23 10:04:00 +08:00
using System.IO;
2024-03-07 21:04:59 +08:00
using System.Net;
using System.Net.Http;
2024-05-19 10:43:41 +08:00
using Zerolauncher.util;
2024-03-07 21:04:59 +08:00
namespace Zerolauncher.Manager
{
internal class LoginManager
{
2024-03-22 19:45:11 +08:00
2024-03-07 21:04:59 +08:00
//private static readonly HttpClient client = new HttpClient();
public static async Task SendPostRequest()
{
var client = new HttpClient();
client.DefaultRequestVersion = HttpVersion.Version20;
client.DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrLower;
var values = new Dictionary<string, string>
{
{ "thing1", "hello" },
{ "thing2", "world" }
};
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync("http://www.example.com/recepticle.aspx", content);
var responseString = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseString);
}
public static async Task LoginTest()
{
var client = new HttpClient();
client.DefaultRequestVersion = HttpVersion.Version20;
client.DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrLower;
var values = new Dictionary<string, string>
{
{ "thing1", "hello" },
{ "thing2", "world" }
};
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync("http://www.example.com/recepticle.aspx", content);
var responseString = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseString);
}
2024-03-22 19:45:11 +08:00
public static async Task<string?> AssetNet(HttpClient client, SingleGame game, string url, FormUrlEncodedContent? content =null)
2024-03-07 21:04:59 +08:00
{
2024-03-22 19:45:11 +08:00
try
{
var response = content != null? await client.PostAsync(url, content): await client.GetAsync(url);
2024-04-22 00:19:47 +08:00
game.Send($"{StaticHandleS.HintText} response.StatusCode{response.StatusCode}");
2024-03-22 19:45:11 +08:00
return await response.Content.ReadAsStringAsync();
}
catch (Exception ex)
{
game.Send($"{StaticHandleS.HintText} 网络发生错误,类型:{ex.GetType().Name},消息:{ex.Message}");
return null;
}
2024-03-07 21:04:59 +08:00
}
2024-05-19 10:43:41 +08:00
public static void DoLogin(SingleGame game)
2024-03-07 21:04:59 +08:00
{
var client = new HttpClient();
2024-04-22 00:19:47 +08:00
client.DefaultRequestVersion = HttpVersion.Version20;
client.DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrLower;
client.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 Edg/124.0.0.0");
string? need_web = null;
2024-03-09 18:29:16 +08:00
client.Timeout = TimeSpan.FromSeconds(3);
2024-05-12 16:43:07 +08:00
game.Send($"{StaticHandleS.HintText} 尝试登玩家{game.account.nickName}到{ServicesStaticInfo.ServicesName[game.account.providerId]}的{ServicesStaticInfo.ServerNames[game.account.serverId]}服");
2024-04-22 00:19:47 +08:00
switch (game.account.providerId)
2024-03-07 21:04:59 +08:00
{
case 0:
2024-04-22 00:19:47 +08:00
case 1:
2024-05-12 16:43:07 +08:00
need_web = "https://www.917play.com.tw/ddt_webserver";
2024-04-22 00:19:47 +08:00
break;
default:
2024-03-07 21:04:59 +08:00
game.Send($"{StaticHandleS.HintText} 错误。未适配的运营商:{game.account.serverId}");
break;
}
2024-04-22 00:19:47 +08:00
client.Dispose();
2024-03-07 21:04:59 +08:00
if (need_web == null) return;
2024-05-12 16:43:07 +08:00
//for (int i = 6; i > 0; i--)
//{
// await Task.Delay(1000);
// if (!game.Send($"{StaticHandleS.HintText} 自动登录失败,将在{i}后启用网页登录,关闭窗口取消")) { return; }
//}
game.Send($"{StaticHandleS.UseBrowser} {need_web} {game.account.providerId + 4} {ServicesStaticInfo.ServerIds[game.account.serverId]} {game.account.userName} {game.account.userPWD}");
}
2024-05-19 10:43:41 +08:00
public static async Task DoVerify(SingleGame game, string vid, string cookie)
{
var client = new HttpClient();
client.Timeout = TimeSpan.FromSeconds(3);
client.DefaultRequestHeaders.Add("Cookie", cookie);
try
{
var response = await client.GetAsync($"https://www.917play.com.tw/ddt_webserver/verify?{vid}");
var bin = response.Content.ReadAsStream();
if (OnnxManager.onnxVerify == null) OnnxManager.onnxVerify = new OnnxVerify();
var verify = OnnxManager.onnxVerify.RunInference(new Bitmap(bin));
2025-02-26 23:41:34 +08:00
//using (var fileStream = File.Create("tmp.png"))
//{
// bin.Seek(0, SeekOrigin.Begin);//设置复制开始的地方
// bin.CopyTo(fileStream);
//}
2024-06-23 10:04:00 +08:00
game.Send($"{StaticHandleS.VerifyDone} {verify}");
2024-05-19 10:43:41 +08:00
Trace.WriteLine(verify);
}
catch (Exception ex)
{
Trace.WriteLine($"{StaticHandleS.HintText} 请求验证码时网络发生错误,类型:{ex.GetType().Name},消息:{ex.Message}");
}
}
2024-03-07 21:04:59 +08:00
}
}