Skip to content

Commit

Permalink
Merge pull request #8 from Revive101/dev
Browse files Browse the repository at this point in the history
Dev -> main
  • Loading branch information
Phill030 authored Dec 7, 2023
2 parents 9119c19 + 896903c commit 7fcbfac
Show file tree
Hide file tree
Showing 9 changed files with 274 additions and 89 deletions.
64 changes: 43 additions & 21 deletions Cargo.lock

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

15 changes: 9 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
[package]
name = "aurorium"
authors = ["Phill030"]
version = "1.1.0"
version = "2.0.0"
edition = "2021"

[dependencies]
axum = { version = "0.6.20", features = ["headers"] }
bpaf = "0.9.6"
# axum-extra = { version = "0.9.0", features = ["typed-header"] } # SOON
bpaf = "0.9.8"
chrono = "0.4.31"
console = "0.15.7"
env_logger = "0.10.1"
futures = "0.3.29"
indicatif = "0.17.7"
lazy_static = "1.4.0"
log = "0.4.20"
quick-xml = { version = "0.31.0", features = ["serialize"] }
quickxml_to_serde = { version = "0.5", features = ["json_types"] }
regex = "1.10.2"
reqwest = "0.11.22"
rayon = "1.8.0"
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"] }
futures = "0.3.29"
console = "0.15.7"
indicatif = "0.17.7"
lazy_static = "1.4.0"
tower = { version = "0.4.13", features = ["limit"] }
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ git clone https://github.com/Revive101/Aurorium.git
### Usage

To run the executable, use `cargo run` alternatively you can build it using `cargo build` or in release `cargo build --release`.
If you just want to host already fetched revisions of the game, simply start the executable. In order to fetch a revision, you need to provide the executable with the `--revision` / `-r` argument.
Since Version 2.0, Aurorium automatically fetches the newest Revision from their server and downloads all resources associated with it. (In Version < 2.0 you need to provide the executable with `--revision` or `-r`)

If you get an `error: linker link.exe not found` error, that means you are missing the buildtools from Microsoft for C++. To solve this issue you can either install `Build Tools for Visual Studio 2019/2022` or use following commands on windows:

Expand All @@ -49,7 +49,6 @@ rustup default stable-x86_64-pc-windows-msvc
```

to mark this toolchain as default, then try to build the project again.

For 64-Bit Linux-Based systems, you need to use `x86_64-unknown-linux-gnu` as target.

The structure of a revision looks like following: `V_r[Major].[Minor]`. Sometimes, the Minor version can even be `WizardDev`. Example: `V_r746756.WizardDev`.
Expand All @@ -59,14 +58,14 @@ The structure of a revision looks like following: `V_r[Major].[Minor]`. Sometime
You can provide the (built) executable with following parameters:

```
-v, --verbose Activate verbosity (Default: warn)
-r, --revision=<String> Fetch from a revision string (Example V_r740872.Wizard_1_520)
-i, --ip=<SocketAddr> Override the default endpoint IP (Default: 0.0.0.0:12369)
-v, --verbose Activate verbosity (Default: warn)
-i, --ip=<SocketAddr> Override the default endpoint IP (Default: 0.0.0.0:12369)
-c, --concurrent_downloads=<usize> Override the count of concurrent downloads at once (Default: 8)
--max_requests=<u32> Change the amount of requests a user can send before getting rate-limited by the server
--max_requests=<u32> Change the amount of requests a user can send before getting rate-limited by the server
--reset_duration=<u32> Change the duration for the interval in which the rate-limit list get's cleared (In seconds)
--disable_ratelimit Disable ratelimits
-h, --help Prints help information
--disable_ratelimit Disable ratelimits
--revision_check_interval=<u64> Change the interval for checking for new revisions (In minutes)
-h, --help Prints help information
```

## Contributing
Expand Down
11 changes: 11 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use thiserror::Error;

#[derive(Debug, Error)]
pub enum RevisionError {
#[error("IO Error while reading/writing TcpStream")]
IO(#[from] std::io::Error),
#[error("Received invalid MagicHeader sequence")]
InvalidMagicHeader,
#[error("Expected SERVICE_ID (8) & MESSAGE_ID (2) but got {0} & {1}")]
InvalidProtocol(u8, u8),
}
45 changes: 21 additions & 24 deletions src/http/http_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ use futures::StreamExt;
use quickxml_to_serde::Config;
use serde::Deserialize;

use crate::revision_checker::revision_checker::Revision;

#[derive(Debug, Clone)]
pub struct HttpRequest {
pub filelist_url: String,
pub file_url: String,
pub list_file_url: String,
pub url_prefix: String,
pub files: FileList,
pub revision: String,
max_concurrent_downloads: usize,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub struct FileList {
pub revision: String,
pub wad_list: Vec<File>,
pub util_list: Vec<File>,
}
Expand All @@ -40,23 +42,19 @@ static LINK: Emoji<'_, '_> = Emoji("🔗 ", "");
static BOX: Emoji<'_, '_> = Emoji("📦 ", "");

impl HttpRequest {
pub async fn new(revision: String, concurrent: usize) -> HttpRequest {
const BASE_URL: &str = "http://versionec.us.wizard101.com/WizPatcher";
pub async fn new(revision: Revision, max_concurrent_downloads: usize) -> Self {
println!(
"{} {}Resolving revision...",
style("[1/6]").bold().dim(),
LOOKING_GLASS
);

HttpRequest {
filelist_url: format!("{BASE_URL}/{revision}/Windows"),
file_url: format!("{BASE_URL}/{revision}/LatestBuild"),
max_concurrent_downloads: concurrent,
files: FileList {
wad_list: Vec::new(),
util_list: Vec::new(),
revision: revision.replace("\r\n", ""),
},
revision: revision.revision,
url_prefix: revision.url_prefix,
list_file_url: revision.list_file_url,
files: FileList::default(),
max_concurrent_downloads,
}
}

Expand All @@ -67,11 +65,9 @@ impl HttpRequest {
TRUCK
);

let save_path = PathBuf::from("files").join(&self.files.revision);
let bin_url = &format!("{}/LatestFileList.bin", &self.filelist_url);
let save_path = PathBuf::from("files").join(&self.revision);

// LatestFileList.bin TODO: Move this into their own functions!!
if let Ok(res) = request_file(&bin_url).await {
if let Ok(res) = request_file(&self.list_file_url).await {
if !save_path.join("utils").join("LatestFileList.bin").exists() {
if let Err(_) = write_to_file(
&save_path.join("utils").join("LatestFileList.bin"),
Expand All @@ -86,9 +82,10 @@ impl HttpRequest {
log::error!("Could not fetch LatestFileList.bin")
};

let xml_url = &format!("{}/LatestFileList.xml", &self.filelist_url);
// LatestFileList.xml TODO: Move this into their own functions!!
match request_file(&xml_url).await {
let xml_url = &self
.list_file_url
.replace("LatestFileList.bin", "LatestFileList.xml");
match request_file(xml_url).await {
Ok(res) => {
let xml_text = res.text().await.unwrap_or(String::new());

Expand Down Expand Up @@ -175,7 +172,7 @@ impl HttpRequest {
});

println!(
"{} {}Inserted {} wad files & {} util files...",
"{} {}Inserted {} wad files & {} util files into list...",
style("[3/6]").bold().dim(),
LINK,
&self.files.wad_list.len(),
Expand All @@ -190,7 +187,7 @@ impl HttpRequest {

/// This is pure 🌟 Magic 🌟
async fn fetch_wads(&mut self, save_path: PathBuf) {
let url = self.file_url.clone();
let url = self.url_prefix.clone();
futures::stream::iter(self.files.wad_list.clone().into_iter().map(|wad| {
let url_cloned = url.clone();

Expand Down Expand Up @@ -238,7 +235,7 @@ impl HttpRequest {
/// This is pure 🌟 Magic 🌟
async fn fetch_utils(&mut self, save_path: PathBuf) {
println!("{} {}fetching util files", style("[5/6]").bold().dim(), BOX);
let url = self.file_url.clone();
let url = self.url_prefix.clone();
futures::stream::iter(self.files.util_list.clone().into_iter().map(|util| {
let url_cloned = url.clone();

Expand Down
Loading

0 comments on commit 7fcbfac

Please sign in to comment.