Skip to content

Commit abaf029

Browse files
committed
started working on dynamic account number, merging with ratelimit
1 parent e3e4bb6 commit abaf029

File tree

2 files changed

+92
-34
lines changed

2 files changed

+92
-34
lines changed

src-tauri/src/account.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::{collections::VecDeque, thread};
2-
31
use chrono::{DateTime, Duration, Utc};
42
use regex::Regex;
53
use reqwest::{
@@ -258,14 +256,27 @@ impl Account {
258256
None
259257
}
260258

261-
pub fn opt_reauth(&mut self, proxy: Option<Proxy>) {
259+
pub fn opt_reauth(&mut self, proxy: Option<Proxy>) -> Option<()> {
262260
if self.time > Utc::now() {
263-
return;
261+
return Some(());
262+
}
263+
if let Err(e) = self.reauth(proxy) {
264+
log(
265+
"ERROR",
266+
Color::from((255, 0, 0)),
267+
&format!("Failed to reauth {}: {}", self.user, e),
268+
);
269+
return None;
264270
}
265-
self.reauth(proxy);
271+
log(
272+
"Success",
273+
Color::from((0, 255, 0)),
274+
&format!("Reauthed {}.", self.user),
275+
);
276+
Some(())
266277
}
267278

268-
pub fn reauth(&mut self, proxy: Option<Proxy>) -> Result<(), String> {
279+
fn reauth(&mut self, proxy: Option<Proxy>) -> Result<(), String> {
269280
let Ok(client) = (if let Some(proxy) = proxy {
270281
ClientBuilder::new().cookie_store(true).proxy(proxy).build()
271282
} else {

src-tauri/src/sniper.rs

Lines changed: 75 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::{
22
collections::VecDeque,
3+
sync::mpsc::{channel, TryRecvError},
34
thread::{self, sleep},
45
time::Duration,
56
};
@@ -34,7 +35,6 @@ fn snipe(name: String, accounts: Vec<String>, claim: String, proxies: Vec<String
3435
thread::sleep(Duration::from_secs(1));
3536

3637
let mut proxy_list = VecDeque::new();
37-
proxy_list.push_back(None);
3838

3939
for p in proxies {
4040
let Ok(proxy) = Proxy::all(p) else {
@@ -47,6 +47,7 @@ fn snipe(name: String, accounts: Vec<String>, claim: String, proxies: Vec<String
4747
};
4848
proxy_list.push_back(Some(proxy));
4949
}
50+
proxy_list.push_back(None);
5051

5152
log(
5253
"SUCCESS",
@@ -60,7 +61,7 @@ fn snipe(name: String, accounts: Vec<String>, claim: String, proxies: Vec<String
6061

6162
for (i, accs) in accounts.enumerate() {
6263
let proxy = proxy_list[i];
63-
thread::spawn(|| {
64+
threads.push(thread::spawn(|| {
6465
let mut out = Vec::new();
6566
for (i, acc) in accs.iter().enumerate() {
6667
if i != 0 {
@@ -88,23 +89,34 @@ fn snipe(name: String, accounts: Vec<String>, claim: String, proxies: Vec<String
8889
out.push(acc);
8990
};
9091
}
92+
if proxy.is_none() {
93+
sleep(Duration::from_secs(21));
94+
}
9195
out
92-
});
96+
}));
9397
}
9498

95-
let mut accounts = match Account::parse_list(accounts) {
96-
Some(accs) => accs,
97-
_ => {
98-
log(
99+
let mut accounts = VecDeque::new();
100+
101+
for i in threads {
102+
match i.join() {
103+
Ok(accs) => accounts.append(&mut VecDeque::from(accs)),
104+
Err(_) => log(
99105
"ERROR",
100106
Color::from((255, 0, 0)),
101-
"Failed to authenticate accounts!",
102-
);
103-
alert("Failed to authenticate accounts!");
104-
app_handle().emit("stop", true).unwrap();
105-
return;
107+
"A thread to sign in accounts failed.",
108+
),
106109
}
107-
};
110+
}
111+
let mut accounts_num = accounts.len();
112+
113+
if accounts_num == 0 {
114+
log("ERROR", Color::from((255, 0, 0)), "No working accounts!");
115+
alert("No working accounts!");
116+
app_handle().emit("stop", true).unwrap();
117+
return;
118+
}
119+
108120
let claim = claim.split(":").collect::<Vec<&str>>();
109121
let user = match claim.get(0) {
110122
Some(user) => user,
@@ -167,16 +179,6 @@ fn snipe(name: String, accounts: Vec<String>, claim: String, proxies: Vec<String
167179
return;
168180
}
169181
};
170-
if accounts.len() < 4 {
171-
log(
172-
"ERROR",
173-
Color::from((255, 0, 0)),
174-
"Slow needs at least 4 working accounts!",
175-
);
176-
alert("Slow needs at least 4 working accounts!");
177-
app_handle().emit("stop", true).unwrap();
178-
return;
179-
}
180182
thread::sleep(Duration::from_secs(1));
181183
let url = format!(
182184
"https://api.minecraftservices.com/minecraft/profile/name/{}/available",
@@ -195,7 +197,50 @@ fn snipe(name: String, accounts: Vec<String>, claim: String, proxies: Vec<String
195197
Color::from((0, 255, 0)),
196198
format!("Sniping {}!", name).as_str(),
197199
);
200+
let (tx_death, rx_death) = channel::<()>();
201+
let (tx_acc, rx_acc) = channel::<Account>();
202+
198203
loop {
204+
if !get_thread_status() {
205+
return;
206+
}
207+
loop {
208+
match rx_death.try_recv() {
209+
Ok(_) => accounts_num -= 1,
210+
Err(TryRecvError::Empty) => break,
211+
_ => {
212+
log(
213+
"ERROR",
214+
Color::from((255, 0, 0)),
215+
"Account death receiver died!",
216+
);
217+
alert("Account death receiver died!");
218+
app_handle().emit("stop", true).unwrap();
219+
return;
220+
}
221+
}
222+
}
223+
224+
if accounts_num == 0 {
225+
log("ERROR", Color::from((255, 0, 0)), "No working accounts!");
226+
alert("No working accounts!");
227+
app_handle().emit("stop", true).unwrap();
228+
return;
229+
}
230+
231+
loop {
232+
match rx_acc.try_recv() {
233+
Ok(acc) => accounts.push_back(acc),
234+
Err(TryRecvError::Empty) => break,
235+
_ => {
236+
log("ERROR", Color::from((255, 0, 0)), "Account receiver died!");
237+
alert("Account receiver died!");
238+
app_handle().emit("stop", true).unwrap();
239+
return;
240+
}
241+
}
242+
}
243+
199244
let account = match accounts.pop_front() {
200245
Some(token) => token,
201246
_ => {
@@ -205,7 +250,10 @@ fn snipe(name: String, accounts: Vec<String>, claim: String, proxies: Vec<String
205250
return;
206251
}
207252
};
208-
let account = match account.reauth() {
253+
254+
thread::spawn(|| {});
255+
sleep(dur);
256+
/* let account = match account.reauth() {
209257
Some(acc) => acc,
210258
_ => {
211259
if accounts.len() < 4 {
@@ -238,9 +286,6 @@ fn snipe(name: String, accounts: Vec<String>, claim: String, proxies: Vec<String
238286
};
239287
240288
for i in 1..31 {
241-
if !get_thread_status() {
242-
return;
243-
}
244289
let response = match client.get(&url).send() {
245290
Ok(res) => res,
246291
_ => {
@@ -311,6 +356,8 @@ fn snipe(name: String, accounts: Vec<String>, claim: String, proxies: Vec<String
311356
}
312357
thread::sleep(Duration::from_secs(3));
313358
}
314-
accounts.push_back(account);
359+
accounts.push_back(account); */
315360
}
316361
}
362+
363+
fn calculate_delay(accounts: u32, proxies: u32) -> u32 {}

0 commit comments

Comments
 (0)