Skip to content

Commit

Permalink
v2.0.1
Browse files Browse the repository at this point in the history
- fix: revision not added to list when fetched
- fix: applied clippy fixes
- build: update dependencies
- fix: failsafe when converting data to bytes
  • Loading branch information
Phill030 authored Dec 10, 2023
2 parents 7fcbfac + 1e01e1f commit 79df446
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 52 deletions.
30 changes: 15 additions & 15 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "aurorium"
authors = ["Phill030"]
version = "2.0.0"
version = "2.0.1"
edition = "2021"

[dependencies]
Expand All @@ -24,5 +24,5 @@ serde = { version = "1.0.193", features = ["derive"] }
serde_json = "1.0.108"
thiserror = "1.0.50"
tokio-util = { version = "0.7.10", features = ["io-util", "rt"] }
tokio = { version = "1.34.0", features = ["full"] }
tokio = { version = "1.35.0", features = ["full"] }
tower = { version = "0.4.13", features = ["limit"] }
25 changes: 10 additions & 15 deletions src/http/http_request.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use std::{collections::HashMap, path::PathBuf};

use crate::revision_checker::revision_checker::Revision;
use console::{style, Emoji};
use futures::StreamExt;
use quickxml_to_serde::Config;
use serde::Deserialize;

use crate::revision_checker::revision_checker::Revision;
use std::{collections::HashMap, path::PathBuf};

#[derive(Debug, Clone)]
pub struct HttpRequest {
Expand Down Expand Up @@ -42,7 +40,7 @@ static LINK: Emoji<'_, '_> = Emoji("🔗 ", "");
static BOX: Emoji<'_, '_> = Emoji("📦 ", "");

impl HttpRequest {
pub async fn new(revision: Revision, max_concurrent_downloads: usize) -> Self {
pub fn new(revision: Revision, max_concurrent_downloads: usize) -> Self {
println!(
"{} {}Resolving revision...",
style("[1/6]").bold().dim(),
Expand Down Expand Up @@ -79,7 +77,7 @@ impl HttpRequest {
}
}
} else {
log::error!("Could not fetch LatestFileList.bin")
log::error!("Could not fetch LatestFileList.bin");
};

let xml_url = &self
Expand Down Expand Up @@ -199,15 +197,12 @@ impl HttpRequest {
if !path.exists() {
match request_file(format!("{}/{}", &url_cloned, &wad.filename)).await {
Ok(res) => {
let bytes = res
.bytes()
.await
.expect("Could not convert to bytes!")
.to_vec();

write_to_file(&path, &bytes).await.unwrap();

log::info!("[✔] Fetched {}", wad.filename);
if let Ok(bytes) = res.bytes().await {
write_to_file(&path, &bytes.to_vec()).await.unwrap();
log::info!("[✔] Fetched {}", wad.filename);
} else {
log::warn!("[❌] Could not convert response to bytes");
}
}
Err(why) => {
log::warn!("[❌] Could not fetch {}, {}", wad.filename, why);
Expand Down
9 changes: 5 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn opts() -> OptionParser<Opt> {
construct!(Opt { verbose, ip, concurrent_downloads, rl_max_requests, rl_reset_duration, rl_disable, rc_interval })
.to_options()
.footer("Copyright (c) 2023 Phill030")
.descr("By default, only the webserver will start. If you want to fetch from a revision, use the --revision or -r parameter.")
.descr("This project is not associated with Wizard101rewritten in any way. Any use of this in reference of Wizard101rewritten will not be tolerated.")
}

#[tokio::main]
Expand All @@ -87,7 +87,6 @@ async fn main() {
env_logger::init_from_env(env_logger::Env::new().default_filter_or(filter));

check_revision(opts.concurrent_downloads).await;

if opts.rc_interval > 0 {
tokio::spawn(async move {
loop {
Expand Down Expand Up @@ -130,9 +129,11 @@ async fn check_revision(concurrent_downloads: usize) {
.to_vec()
.contains(&fetched_revision.revision)
{
let mut req = HttpRequest::new(fetched_revision, concurrent_downloads).await;
let mut req = HttpRequest::new(fetched_revision, concurrent_downloads);
req.propogate_filelist().await;

explore_revisions().await.unwrap();
} else {
log::warn!("Newest revision is already fetched!")
log::info!("Newest revision is already fetched!");
}
}
8 changes: 4 additions & 4 deletions src/rate_limit/rate_limiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ impl RateLimiter {
*requests += 1;

return requests < &mut self.max_requests;
} else {
lock.insert(ip, 1);
return true;
}

lock.insert(ip, 1);
return true;
}

return false;
false
}
}
17 changes: 6 additions & 11 deletions src/revision_checker/revision_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ impl Revision {
let mut ip = format!("{URL}:{PORT}").to_socket_addrs()?;
log::info!("Successfully connected to {URL}");

Ok(TcpStream::connect_timeout(
&ip.next().unwrap(),
Duration::from_secs(20),
)?)
TcpStream::connect_timeout(&ip.next().unwrap(), Duration::from_secs(20))
}

pub async fn check<const N: usize>() -> Result<Revision, RevisionError> {
Expand All @@ -42,7 +39,7 @@ impl Revision {
stream.read(&mut buffer)?; // We don't need the SessionOffer
buffer = [0u8; N];

stream.write_all(&hex_decode(SESSION_ACCEPT, Endianness::Little).unwrap()[..])?;
stream.write_all(&hex_decode(SESSION_ACCEPT, &Endianness::Little).unwrap()[..])?;

stream.read(&mut buffer)?;
let mut cursor = Cursor::new(buffer);
Expand Down Expand Up @@ -97,17 +94,15 @@ impl Revision {
String::from_utf8_lossy(&buff).to_string()
}

pub fn parse_revision(url: &String) -> String {
pub fn parse_revision(url: &str) -> String {
let reg = Regex::new(r"/V_([^/]+)/").unwrap();

if let Some(captures) = reg.captures(&url) {
if let Some(captures) = reg.captures(url) {
if let Some(version) = captures.get(1) {
return format!("V_{}", version.as_str());
} else {
return String::from("");
}
} else {
return String::from("");
}

String::new()
}
}
2 changes: 1 addition & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub enum Endianness {
Big,
}

pub fn hex_decode(hex_string: &str, endianness: Endianness) -> Option<Vec<u8>> {
pub fn hex_decode(hex_string: &str, endianness: &Endianness) -> Option<Vec<u8>> {
// Check if the hex string is a valid length
if hex_string.len() % 2 != 0 {
return None;
Expand Down

0 comments on commit 79df446

Please sign in to comment.