diff --git a/src/validate/mod.rs b/src/validate/mod.rs index b70dba19c..b0844f505 100644 --- a/src/validate/mod.rs +++ b/src/validate/mod.rs @@ -3,10 +3,10 @@ use crate::models::projects::{GameVersion, Loader}; use crate::validate::fabric::FabricValidator; use crate::validate::forge::{ForgeValidator, LegacyForgeValidator}; use crate::validate::liteloader::LiteLoaderValidator; -use crate::validate::pack::PackValidator; -use crate::validate::plugin::PluginValidator; +use crate::validate::modpack::ModpackValidator; +use crate::validate::plugin::*; use crate::validate::quilt::QuiltValidator; -use crate::validate::resourcepack::ResourcePackValidator; +use crate::validate::resourcepack::{PackValidator, TexturePackValidator}; use std::io::Cursor; use thiserror::Error; use time::OffsetDateTime; @@ -15,7 +15,7 @@ use zip::ZipArchive; mod fabric; mod forge; mod liteloader; -mod pack; +mod modpack; mod plugin; mod quilt; mod resourcepack; @@ -76,15 +76,19 @@ pub trait Validator: Sync { ) -> Result; } -static VALIDATORS: [&dyn Validator; 8] = [ - &PackValidator, +static VALIDATORS: [&dyn Validator; 12] = [ + &ModpackValidator, &FabricValidator, &ForgeValidator, &LegacyForgeValidator, &QuiltValidator, &LiteLoaderValidator, - &ResourcePackValidator, - &PluginValidator, + &PackValidator, + &TexturePackValidator, + &BukkitValidator, + &BungeeCordValidator, + &VelocityValidator, + &SpongeValidator, ]; /// The return value is whether this file should be marked as primary or not, based on the analysis of the file @@ -97,8 +101,8 @@ pub async fn validate_file( all_game_versions: Vec, ) -> Result { actix_web::web::block(move || { - let reader = std::io::Cursor::new(data); - let mut zip = zip::ZipArchive::new(reader)?; + let reader = Cursor::new(data); + let mut zip = ZipArchive::new(reader)?; let mut visited = false; for validator in &VALIDATORS { diff --git a/src/validate/pack.rs b/src/validate/modpack.rs similarity index 97% rename from src/validate/pack.rs rename to src/validate/modpack.rs index bec42a5d4..8b01301d8 100644 --- a/src/validate/pack.rs +++ b/src/validate/modpack.rs @@ -8,9 +8,9 @@ use std::path::Component; use validator::Validate; use zip::ZipArchive; -pub struct PackValidator; +pub struct ModpackValidator; -impl super::Validator for PackValidator { +impl super::Validator for ModpackValidator { fn get_file_extensions(&self) -> &[&str] { &["mrpack"] } diff --git a/src/validate/plugin.rs b/src/validate/plugin.rs index 90e203e40..d81127520 100644 --- a/src/validate/plugin.rs +++ b/src/validate/plugin.rs @@ -4,9 +4,9 @@ use crate::validate::{ use std::io::Cursor; use zip::ZipArchive; -pub struct PluginValidator; +pub struct BukkitValidator; -impl super::Validator for PluginValidator { +impl super::Validator for BukkitValidator { fn get_file_extensions(&self) -> &[&str] { &["zip", "jar"] } @@ -36,3 +36,105 @@ impl super::Validator for PluginValidator { Ok(ValidationResult::Pass) } } + +pub struct BungeeCordValidator; + +impl super::Validator for BungeeCordValidator { + fn get_file_extensions(&self) -> &[&str] { + &["zip", "jar"] + } + + fn get_project_types(&self) -> &[&str] { + &["mod"] + } + + fn get_supported_loaders(&self) -> &[&str] { + &["bungeecord", "waterfall"] + } + + fn get_supported_game_versions(&self) -> SupportedGameVersions { + SupportedGameVersions::All + } + + fn validate( + &self, + archive: &mut ZipArchive>, + ) -> Result { + archive.by_name("bungee.yml").map_err(|_| { + ValidationError::InvalidInput( + "No bungee.yml present for plugin file.".into(), + ) + })?; + + Ok(ValidationResult::Pass) + } +} + +pub struct VelocityValidator; + +impl super::Validator for VelocityValidator { + fn get_file_extensions(&self) -> &[&str] { + &["zip", "jar"] + } + + fn get_project_types(&self) -> &[&str] { + &["mod"] + } + + fn get_supported_loaders(&self) -> &[&str] { + &["velocity"] + } + + fn get_supported_game_versions(&self) -> SupportedGameVersions { + SupportedGameVersions::All + } + + fn validate( + &self, + archive: &mut ZipArchive>, + ) -> Result { + archive.by_name("velocity-plugin.json").map_err(|_| { + ValidationError::InvalidInput( + "No velocity-plugin.json present for plugin file.".into(), + ) + })?; + + Ok(ValidationResult::Pass) + } +} + +pub struct SpongeValidator; + +impl super::Validator for SpongeValidator { + fn get_file_extensions(&self) -> &[&str] { + &["zip", "jar"] + } + + fn get_project_types(&self) -> &[&str] { + &["mod"] + } + + fn get_supported_loaders(&self) -> &[&str] { + &["sponge"] + } + + fn get_supported_game_versions(&self) -> SupportedGameVersions { + SupportedGameVersions::All + } + + fn validate( + &self, + archive: &mut ZipArchive>, + ) -> Result { + if !archive + .file_names() + .any(|name| name == "sponge_plugins.json" || name == "mcmod.info") + { + return Ok(ValidationResult::Warning( + "No sponge_plugins.json or mcmod.info present for Sponge plugin.", + )); + }; + + Ok(ValidationResult::Pass) + } +} diff --git a/src/validate/quilt.rs b/src/validate/quilt.rs index e5293297d..927002896 100644 --- a/src/validate/quilt.rs +++ b/src/validate/quilt.rs @@ -17,7 +17,7 @@ impl super::Validator for QuiltValidator { } fn get_supported_loaders(&self) -> &[&str] { - &["fabric"] + &["quilt"] } fn get_supported_game_versions(&self) -> SupportedGameVersions { diff --git a/src/validate/resourcepack.rs b/src/validate/resourcepack.rs index 3a3f458c2..dcdfeedc2 100644 --- a/src/validate/resourcepack.rs +++ b/src/validate/resourcepack.rs @@ -2,11 +2,48 @@ use crate::validate::{ SupportedGameVersions, ValidationError, ValidationResult, }; use std::io::Cursor; +use time::OffsetDateTime; use zip::ZipArchive; -pub struct ResourcePackValidator; +pub struct PackValidator; -impl super::Validator for ResourcePackValidator { +impl super::Validator for PackValidator { + fn get_file_extensions(&self) -> &[&str] { + &["zip"] + } + + fn get_project_types(&self) -> &[&str] { + &["resourcepack", "datapack"] + } + + fn get_supported_loaders(&self) -> &[&str] { + &["minecraft"] + } + + fn get_supported_game_versions(&self) -> SupportedGameVersions { + // Time since release of 13w24a which replaced texture packs with resource packs + SupportedGameVersions::PastDate(OffsetDateTime::from_unix_timestamp( + 1371137542, + )) + } + + fn validate( + &self, + archive: &mut ZipArchive>, + ) -> Result { + archive.by_name("pack.mcmeta").map_err(|_| { + ValidationError::InvalidInput( + "No pack.mcmeta present for pack file.".into(), + ) + })?; + + Ok(ValidationResult::Pass) + } +} + +pub struct TexturePackValidator; + +impl super::Validator for TexturePackValidator { fn get_file_extensions(&self) -> &[&str] { &["zip"] } @@ -20,16 +57,20 @@ impl super::Validator for ResourcePackValidator { } fn get_supported_game_versions(&self) -> SupportedGameVersions { - SupportedGameVersions::All + // a1.2.2a to 13w23b + SupportedGameVersions::Range( + OffsetDateTime::from_unix_timestamp(1289339999), + OffsetDateTime::from_unix_timestamp(1370651522), + ) } fn validate( &self, archive: &mut ZipArchive>, ) -> Result { - archive.by_name("pack.mcmeta").map_err(|_| { + archive.by_name("pack.txt").map_err(|_| { ValidationError::InvalidInput( - "No pack.mcmeta present for resourcepack file.".into(), + "No pack.txt present for pack file.".into(), ) })?;