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

Commit

Permalink
Make droptimes work again.
Browse files Browse the repository at this point in the history
  • Loading branch information
tropicbliss committed Jul 24, 2021
1 parent 4f43418 commit 949b3b7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 86 deletions.
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 = "2.0.3"
version = "2.0.4"
authors = ["tropicbliss <[email protected]>"]
edition = "2018"
license = "MIT"
Expand Down
3 changes: 1 addition & 2 deletions src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
pub const YGGDRASIL_ORIGIN_SERVER: &str = "https://authserver.mojang.com";
pub const MOJANG_API_SERVER: &str = "https://api.mojang.com";
pub const MINECRAFTSERVICES_API_SERVER: &str = "https://api.minecraftservices.com";
pub const NAMEMC_API: &str = "http://drops.peet.ws";
pub const NAMEMC_API: &str = "http://api.coolkidmacho.com";
pub const REGULAR_SNIPE_REQS: u8 = 3;
pub const GC_SNIPE_REQS: u8 = 6;
pub const SERVER_RESPONSE_TIME: u8 = 40;
pub const NAMEMC_USER_AGENT: &str = "PiratSnipe";
pub const BUCKSHOT_API_SERVER: &str = "https://auth.buckshotrs.com";
pub const AUTH_USER_AGENT: &str =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0";
62 changes: 19 additions & 43 deletions src/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,10 @@ use serde_json::{json, Value};
use tokio::fs::File;
use tokio_util::codec::{BytesCodec, FramedRead};

pub enum AuthenicationError {
RetryableAuthenticationError,
}

pub enum NameAvailabilityError {
NameNotAvailableError,
}

pub struct NameMC {
pub droptime: DateTime<Utc>,
pub searches: u32,
}

pub struct Requests {
client: Client,
}
Expand Down Expand Up @@ -67,11 +58,7 @@ impl Requests {
}
}

pub async fn authenticate_microsoft(
&self,
username: &str,
password: &str,
) -> Result<String, AuthenicationError> {
pub async fn authenticate_microsoft(&self, username: &str, password: &str) -> String {
let function_id = "AuthenticateMicrosoft";
if username.is_empty() || password.is_empty() {
cli::pretty_panik(function_id, "You did not provide a username or password.");
Expand All @@ -90,20 +77,16 @@ impl Requests {
200 => {
let body = res.text().await.unwrap();
let v: Value = serde_json::from_str(&body).unwrap();
Ok(v["access_token"].as_str().unwrap().to_string())
v["access_token"].as_str().unwrap().to_string()
}
400 => {
let body = res.text().await.unwrap();
let v: Value = serde_json::from_str(&body).unwrap();
let err = v["error"].as_str().unwrap().to_string();
if err == "This API is currently overloaded. Please try again later." {
Err(AuthenicationError::RetryableAuthenticationError)
} else {
cli::pretty_panik(
function_id,
&format!("Authentication error. Reason: {}", err),
)
}
cli::pretty_panik(
function_id,
&format!("Authentication error. Reason: {}", err),
);
}
status => cli::http_not_ok_panik(function_id, status),
}
Expand Down Expand Up @@ -177,34 +160,27 @@ impl Requests {
pub async fn check_name_availability_time(
&self,
username_to_snipe: &str,
) -> Result<NameMC, NameAvailabilityError> {
) -> Result<DateTime<Utc>, NameAvailabilityError> {
let function_id = "CheckNameAvailabilityTime";
let url = format!("{}/droptime", constants::NAMEMC_API);
let res = self
.client
.get(url)
.header(reqwest::header::USER_AGENT, constants::NAMEMC_USER_AGENT)
.query(&[("name", username_to_snipe)])
.send()
.await;
let url = format!("{}/droptime/{}", constants::NAMEMC_API, username_to_snipe);
let res = self.client.get(url).send().await;
let res = match res {
Err(e) if e.is_timeout() => cli::http_timeout_panik(function_id),
_ => res.unwrap(),
};
let status = res.status().as_u16();
if status != 200 {
cli::http_not_ok_panik(function_id, status);
}
let body = res.text().await.unwrap();
let v: Value = serde_json::from_str(&body).unwrap();
match v.get("UNIX") {
Some(x) => {
let searches = v["searches"].as_i64().unwrap() as u32;
let epoch = x.as_i64().unwrap();
match status {
200 => {
let body = res.text().await.unwrap();
let v: Value = serde_json::from_str(&body).unwrap();
let epoch = v["UNIX"].as_i64().unwrap();
let droptime = Utc.timestamp(epoch, 0);
Ok(NameMC { droptime, searches })
Ok(droptime)
}
404 => Err(NameAvailabilityError::NameNotAvailableError),
status => {
cli::http_not_ok_panik(function_id, status);
}
None => Err(NameAvailabilityError::NameNotAvailableError),
}
}

Expand Down
51 changes: 11 additions & 40 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl Sniper {
println!("Moving on to next name...");
}
let snipe_time = match self.get_snipe_time(&requestor, &username_to_snipe).await {
Some(x) => x.droptime,
Some(x) => x,
None => {
continue;
}
Expand Down Expand Up @@ -124,6 +124,7 @@ impl Sniper {
cli::exit_program();
}

#[allow(clippy::too_many_arguments)] // This sniper is poorly written, shut up
async fn snipe(
&self,
droptime: &DateTime<Utc>,
Expand Down Expand Up @@ -182,12 +183,7 @@ impl Sniper {
snipe_time
}
};
let searches = match namemc_data {
Some(x) => x.searches,
None => {
return None;
}
};
namemc_data?; // Ok this is the weirdest statement I have ever written in programming
bunt::println!(
"{$green}Signed in to {} successfully.{/$}",
self.config.account.username
Expand All @@ -214,9 +210,8 @@ impl Sniper {
};
if is_success {
bunt::println!(
"{$green}Successfully sniped {} with {} searches! Snipe attempt(s): {}.{/$}",
"{$green}Successfully sniped {}! Snipe attempt(s): {}.{/$}",
username_to_snipe,
searches,
attempt
);
if self.config.config.change_skin {
Expand All @@ -227,7 +222,6 @@ impl Sniper {
}

async fn setup(&self, requestor: &Arc<requests::Requests>, task: &SnipeTask) -> String {
let function_id = "Setup";
match task {
SnipeTask::Mojang => {
let access_token = requestor
Expand All @@ -247,35 +241,12 @@ impl Sniper {
access_token
}
_ => {
let mut count = 0;
loop {
count += 1;
match requestor
.authenticate_microsoft(
&self.config.account.username,
&self.config.account.password,
)
.await
{
Ok(x) => break x,
Err(requests::AuthenicationError::RetryableAuthenticationError) => {
cli::kalm_panik(
function_id,
&format!(
"Authentication error. Retrying in 10 seconds. Attempt(s): {}.",
count
),
);
time::sleep(std::time::Duration::from_secs(10)).await;
if count == 3 {
cli::pretty_panik(
function_id,
"Authentication failed due to an unknown server error. Please try again later."
);
}
}
}
}
requestor
.authenticate_microsoft(
&self.config.account.username,
&self.config.account.password,
)
.await
}
}
}
Expand All @@ -284,7 +255,7 @@ impl Sniper {
&self,
requestor: &Arc<requests::Requests>,
username_to_snipe: &str,
) -> Option<requests::NameMC> {
) -> Option<DateTime<Utc>> {
let function_id = "GetSnipeTime";
match requestor
.check_name_availability_time(&username_to_snipe)
Expand Down

0 comments on commit 949b3b7

Please sign in to comment.