Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Reintroduce spread
Browse files Browse the repository at this point in the history
  • Loading branch information
tropicbliss committed Nov 23, 2021
1 parent 55efdac commit a4d110d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "buckshot"
version = "4.0.5"
version = "4.0.6"
authors = ["tropicbliss <[email protected]>"]
edition = "2021"
license = "MIT"
Expand Down
3 changes: 3 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct PrivateConfig {
mode: SnipeTask,
skin: Option<Skin>,
name_queue: Option<NameQueue>,
spread: u32,
}

#[derive(Deserialize, Clone)]
Expand All @@ -27,6 +28,7 @@ pub struct Config {
pub mode: SnipeTask,
pub skin: Option<Skin>,
pub name_queue: Option<NameQueue>,
pub spread: u32,
}

#[derive(PartialEq)]
Expand Down Expand Up @@ -112,6 +114,7 @@ impl From<PrivateConfig> for Config {
mode: item.mode,
skin: item.skin,
name_queue: item.name_queue,
spread: item.spread,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ use std::time::Duration;

pub const CONFIG_PATH: &str = "config.toml";
pub const IO_TIMEOUT: Duration = Duration::from_secs(5);
pub const BARRIER_THRESHOLD: u32 = 27;
7 changes: 4 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,10 @@ async fn main() -> Result<()> {
writeln!(stdout(), "Setup complete")?;
let mut is_success = None;
let is_gc = task == &SnipeTask::Giftcode;
let res_data = sockets::snipe_executor(name, &bearer_tokens, snipe_time, is_gc)
.await
.with_context(|| format!("Failed to execute the snipe of {}", name))?;
let res_data =
sockets::snipe_executor(name, &bearer_tokens, snipe_time, is_gc, config.spread)
.await
.with_context(|| format!("Failed to execute the snipe of {}", name))?;
for res in res_data {
let formatted_timestamp = res.timestamp.format("%F %T%.6f");
match res.status {
Expand Down
13 changes: 11 additions & 2 deletions src/sockets.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::constants::IO_TIMEOUT;
use crate::constants::{BARRIER_THRESHOLD, IO_TIMEOUT};
use anyhow::Result;
use chrono::{DateTime, Duration, Local};
use native_tls::TlsConnector;
Expand All @@ -22,6 +22,7 @@ pub async fn snipe_executor(
bearer_tokens: &[String],
snipe_time: DateTime<Local>,
is_gc: bool,
spread: u32,
) -> Result<Vec<ResData>> {
let req_count = if is_gc { 6 } else { 3 };
let addr = "api.minecraftservices.com:443"
Expand All @@ -32,7 +33,13 @@ pub async fn snipe_executor(
let cx = tokio_native_tls::TlsConnector::from(cx);
let cx = Arc::new(cx);
let mut handles = Vec::with_capacity(req_count * bearer_tokens.len());
let barrier = Arc::new(Barrier::new(req_count * bearer_tokens.len()));
let barrier_count = if spread <= BARRIER_THRESHOLD {
req_count * bearer_tokens.len()
} else {
0
};
let barrier = Arc::new(Barrier::new(barrier_count));
let mut snipe_time = snipe_time;
for (account_idx, bearer_token) in bearer_tokens.iter().enumerate() {
let payload = if is_gc {
let post_body = json!({ "profileName": name }).to_string();
Expand Down Expand Up @@ -91,6 +98,8 @@ pub async fn snipe_executor(
account_idx,
}
});
// Before you rag on me for not using +=, += doesn't work here
snipe_time = snipe_time + Duration::milliseconds(i64::from(spread));
handles.push(handle);
}
}
Expand Down

0 comments on commit a4d110d

Please sign in to comment.