Skip to content

Commit 7540608

Browse files
committed
add login progress and boosting link button
1 parent a95602b commit 7540608

File tree

3 files changed

+123
-13
lines changed

3 files changed

+123
-13
lines changed

StarSharksTool/AccountManagement.Designer.cs

Lines changed: 24 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

StarSharksTool/AccountManagement.cs

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ namespace StarSharksTool
2626
{
2727
public partial class AccountManagement : Form
2828
{
29+
public int totalAccountCount = 0;
30+
public int loadedAccountCount = 0;
2931
private readonly IDistributedCache cache;
3032
public AccountManagement()
3133
{
@@ -138,8 +140,18 @@ private async Task LoadAccount()
138140
long accountCount = 0;
139141
Global.Accounts.Clear();
140142

143+
144+
MethodInvoker resetLoginProgressMI = new MethodInvoker(() =>
145+
{
146+
this.totalAccountCount = appSettings.Accounts.Count;
147+
this.loadedAccountCount = 0;
148+
processLbl.Text = $"账号登录进度 0 / {appSettings.Accounts.Count}";
149+
progressBar1.Value = 0;
150+
});
151+
141152
if (appSettings.Accounts.Count > 0)
142153
{
154+
BeginInvoke(resetLoginProgressMI);
143155
try
144156
{
145157
var c = appSettings.Accounts[0].DecryptedPrivateKey;
@@ -151,7 +163,42 @@ private async Task LoadAccount()
151163
}
152164
}
153165

154-
var loginResponses = appSettings.Accounts.Select(c => Services.Service.Login(new Account(c.DecryptedPrivateKey, 56), c.Alias, Global.Cache)).ToList();
166+
167+
MethodInvoker accountLoginMI = new MethodInvoker(() =>
168+
{
169+
this.loadedAccountCount = this.loadedAccountCount + 1;
170+
var progressPercentage = ((double)this.loadedAccountCount / (double)this.totalAccountCount) * 100;
171+
if (progressPercentage > 100)
172+
{
173+
progressPercentage = 100;
174+
}
175+
this.progressBar1.Value = (int)progressPercentage;
176+
processLbl.Text = $"账号登录进度 {this.loadedAccountCount} / {appSettings.Accounts.Count}";
177+
});
178+
179+
180+
181+
MethodInvoker resetSharkLoadMI = new MethodInvoker(() =>
182+
{
183+
this.totalAccountCount = appSettings.Accounts.Count;
184+
this.loadedAccountCount = 0;
185+
processLbl.Text = $"鲨鱼加载进度 0 / {appSettings.Accounts.Count}";
186+
progressBar1.Value = 0;
187+
});
188+
189+
MethodInvoker sharkLoadMI = new MethodInvoker(() =>
190+
{
191+
this.loadedAccountCount = this.loadedAccountCount + 1;
192+
var progressPercentage = ((double)this.loadedAccountCount / (double)this.totalAccountCount) * 100;
193+
if (progressPercentage > 100)
194+
{
195+
progressPercentage = 100;
196+
}
197+
this.progressBar1.Value = (int)progressPercentage;
198+
processLbl.Text = $"鲨鱼加载进度 {this.loadedAccountCount} / {appSettings.Accounts.Count}";
199+
});
200+
201+
var loginResponses = appSettings.Accounts.Select(c => Services.Service.Login(new Account(c.DecryptedPrivateKey, 56), c.Alias, Global.Cache, 0, () => { BeginInvoke(accountLoginMI); })).ToList();
155202
await Task.WhenAll(loginResponses);
156203
var accountInfos = loginResponses.ToDictionary(c => c.Result.Address.ToLower(), c => c.Result);
157204

@@ -167,6 +214,7 @@ private async Task LoadAccount()
167214
loadFinished = true;
168215
break;
169216
}
217+
BeginInvoke(resetSharkLoadMI);
170218
await Parallel.ForEachAsync(waitingLoadAddresses, new ParallelOptions { MaxDegreeOfParallelism = 4 }, async (address, cancelToken) =>
171219
{
172220
GET_RETRY:
@@ -194,8 +242,9 @@ private async Task LoadAccount()
194242
throw new Exception();
195243
}
196244
accountDetailInfo.Add(address, (sharkAccountInfo.Result, sharks.Result, seaBalanceOfFunctionReturn.Result, sssBalanceOfFunctionReturn.Result, bnbBalance.Result));
245+
BeginInvoke(sharkLoadMI);
197246
}
198-
catch(Exception e)
247+
catch (Exception e)
199248
{
200249
Global.GetLogger("AccountManagement").LogError(e, e.Message);
201250
goto GET_RETRY;
@@ -305,7 +354,7 @@ private async Task LoadAccount()
305354
};
306355

307356
var quickConnectButton = new Button();
308-
quickConnectButton.Text = "ADB登录";
357+
quickConnectButton.Text = "雷电登录";
309358
quickConnectButton.Location = new Point(290, 0);
310359
quickConnectButton.Click += (object? sender, EventArgs e) =>
311360
{
@@ -341,13 +390,24 @@ private async Task LoadAccount()
341390
};
342391

343392
var copyAddressButton = new Button();
344-
copyAddressButton.Text = "复制";
393+
copyAddressButton.Text = "复制地址";
345394
copyAddressButton.Location = new Point(430, 0);
346395
copyAddressButton.Click += (object? sender, EventArgs e) =>
347396
{
348397
Clipboard.SetDataObject(bscAccount.Address);
398+
MessageBox.Show("复制成功");
349399
};
350400

401+
var copyLinkButton = new Button();
402+
copyLinkButton.Text = "复制代打链接";
403+
copyLinkButton.Location = new Point(500, 0);
404+
copyLinkButton.Width = 100;
405+
copyLinkButton.Click += async (object? sender, EventArgs e) =>
406+
{
407+
var link = await Services.Service.CopyGameToken(bscAccount.Address);
408+
Clipboard.SetDataObject(link);
409+
MessageBox.Show("复制成功");
410+
};
351411

352412

353413
var groupBox = new GroupBox();
@@ -361,12 +421,13 @@ private async Task LoadAccount()
361421
groupBox.Controls.Add(quickConnectButton);
362422
groupBox.Controls.Add(withdrawButton);
363423
groupBox.Controls.Add(copyAddressButton);
424+
groupBox.Controls.Add(copyLinkButton);
364425

365426
flowLayoutPanel1.Controls.Add(groupBox);
366427
Global.Accounts.Add(account);
367428
}
368429
}
369-
catch(Exception e)
430+
catch (Exception e)
370431
{
371432
Global.GetLogger("AccountManagement").LogError(e, e.Message);
372433
goto RETRY;
@@ -610,7 +671,7 @@ private void AccountManagement_Resize(object sender, EventArgs e)
610671
// Width - 29;
611672
// Height - 154;
612673
flowLayoutPanel1.Width = this.Width - 29;
613-
flowLayoutPanel1.Height = this.Height - 154;
674+
flowLayoutPanel1.Height = this.Height - 124;
614675
}
615676
}
616677
}

StarSharksTool/Services/Service.cs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ internal async Task TransferSharks(IEnumerable<TransferRecord> transferRecords)
106106
}
107107
}
108108
}
109-
catch (Exception ex){
109+
catch (Exception ex)
110+
{
110111

111112
Global.GetLogger("SharkManagement").LogError(ex, ex.Message);
112113
throw ex;
@@ -179,7 +180,7 @@ internal async static Task<MarketRentResponseModel> GetMarketplace(int maxPrice,
179180
return responseModel;
180181
}
181182
}
182-
catch(Exception e)
183+
catch (Exception e)
183184
{
184185
Global.GetLogger("Service").LogError(e, e.Message);
185186
return new MarketRentResponseModel { Data = new Models.RentModels.Data { Sharks = new List<Shark> { } } };
@@ -464,7 +465,7 @@ internal static string Sign(string message, string privateKey)
464465
var signer1 = new EthereumMessageSigner();
465466
return signer1.EncodeUTF8AndSign(message, new EthECKey(privateKey));
466467
}
467-
internal static async Task<(string WebsiteToken, string GameToken, string Address, Account Account, string Alias)> Login(Account account, string alias, Microsoft.Extensions.Caching.Distributed.IDistributedCache? cache, int maxRetry = 0)
468+
internal static async Task<(string WebsiteToken, string GameToken, string Address, Account Account, string Alias)> Login(Account account, string alias, Microsoft.Extensions.Caching.Distributed.IDistributedCache? cache, int maxRetry = 0, Action callback = null)
468469
{
469470
try
470471
{
@@ -474,6 +475,7 @@ internal static string Sign(string message, string privateKey)
474475
var responseModel = JsonConvert.DeserializeObject<ResponseModel<LoginResponseModel>>(content);
475476
if (responseModel?.Data != null)
476477
{
478+
callback();
477479
return (responseModel!.Data!.Authorization!.Remove(0, 7), responseModel!.Data!.QRCode!, account.Address, account, alias);
478480
}
479481
}
@@ -497,17 +499,42 @@ internal static string Sign(string message, string privateKey)
497499
await cache.SetStringAsync($"StarsharkToken:{account.Address.ToLower()}", content);
498500
if (responseModel?.Data != null)
499501
{
502+
callback();
500503
return (responseModel!.Data!.Authorization!.Remove(0, 7), responseModel!.Data!.QRCode!, account.Address, account, alias);
501504
}
502-
return await Login(account, alias, cache);
505+
return await Login(account, alias, cache, callback: callback);
503506
}
504507
}
505508
catch (Exception e)
506509
{
507510
Global.GetLogger("Service").LogError(e, e.Message);
508-
return await Login(account, alias, cache, maxRetry);
511+
return await Login(account, alias, cache, maxRetry, callback: callback);
512+
}
513+
}
514+
internal static async Task<string> CopyGameToken(string address)
515+
{
516+
var account = Global.Accounts.First(c => c.Account.Address.Equals(address, StringComparison.CurrentCultureIgnoreCase));
517+
CancellationTokenSource cs = new CancellationTokenSource();
518+
string url = "https://starsharks.com/go/auth-api/account/gen-game-token";
519+
var sharkResp = new WithdrawResponseModel();
520+
//Global.HTTPCLIENT
521+
var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, url);
522+
httpRequestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", account.WebsiteToken);
523+
httpRequestMessage.Content = new StringContent(JsonConvert.SerializeObject(new { }), Encoding.UTF8, "application/json");
524+
var client = Global.HTTPCLIENT;
525+
{
526+
var httpResponse = await client.SendAsync(httpRequestMessage);
527+
var content = await httpResponse.Content.ReadAsStringAsync();
528+
if (!httpResponse.IsSuccessStatusCode)
529+
{
530+
Global.GetLogger("Service").LogError($"{url} 失败: {content}");
531+
throw new HttpRequestException();
532+
}
533+
var obj = JsonConvert.DeserializeObject<dynamic>(content);
534+
return $"https://starsharks.com/market/link-game?code={obj?.data.sid}";
509535
}
510536
}
537+
511538
internal static async Task<string> RandomString()
512539
{
513540
var httpClient = Global.HTTPCLIENT;

0 commit comments

Comments
 (0)