2024-10-18 16:07:35 -07:00
|
|
|
use crate::validate::{
|
|
|
|
|
SupportedGameVersions, ValidationError, ValidationResult,
|
|
|
|
|
};
|
2022-06-26 10:39:38 -07:00
|
|
|
use std::io::Cursor;
|
|
|
|
|
use zip::ZipArchive;
|
|
|
|
|
|
2022-09-02 17:39:58 +02:00
|
|
|
pub struct PluginYmlValidator;
|
2022-06-26 10:39:38 -07:00
|
|
|
|
2022-09-02 17:39:58 +02:00
|
|
|
impl super::Validator for PluginYmlValidator {
|
2022-06-26 10:39:38 -07:00
|
|
|
fn get_file_extensions(&self) -> &[&str] {
|
|
|
|
|
&["zip", "jar"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_supported_loaders(&self) -> &[&str] {
|
2024-06-12 14:38:35 -07:00
|
|
|
&["bukkit", "spigot", "paper", "purpur", "folia"]
|
2022-06-26 10:39:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_supported_game_versions(&self) -> SupportedGameVersions {
|
|
|
|
|
SupportedGameVersions::All
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn validate(
|
|
|
|
|
&self,
|
|
|
|
|
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
|
|
|
|
) -> Result<ValidationResult, ValidationError> {
|
2023-08-07 13:53:21 -05:00
|
|
|
if !archive
|
|
|
|
|
.file_names()
|
|
|
|
|
.any(|name| name == "plugin.yml" || name == "paper-plugin.yml")
|
|
|
|
|
{
|
2022-08-16 17:42:04 -07:00
|
|
|
return Ok(ValidationResult::Warning(
|
2023-08-07 13:53:21 -05:00
|
|
|
"No plugin.yml or paper-plugin.yml present for plugin file.",
|
2022-08-16 17:42:04 -07:00
|
|
|
));
|
2023-08-07 13:53:21 -05:00
|
|
|
};
|
2022-06-26 10:39:38 -07:00
|
|
|
|
|
|
|
|
Ok(ValidationResult::Pass)
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-10 03:25:44 +00:00
|
|
|
|
|
|
|
|
pub struct BungeeCordValidator;
|
|
|
|
|
|
|
|
|
|
impl super::Validator for BungeeCordValidator {
|
|
|
|
|
fn get_file_extensions(&self) -> &[&str] {
|
|
|
|
|
&["zip", "jar"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_supported_loaders(&self) -> &[&str] {
|
|
|
|
|
&["bungeecord", "waterfall"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_supported_game_versions(&self) -> SupportedGameVersions {
|
|
|
|
|
SupportedGameVersions::All
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn validate(
|
|
|
|
|
&self,
|
|
|
|
|
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
|
|
|
|
) -> Result<ValidationResult, ValidationError> {
|
2023-09-10 12:49:35 -04:00
|
|
|
if !archive
|
|
|
|
|
.file_names()
|
|
|
|
|
.any(|name| name == "plugin.yml" || name == "bungee.yml")
|
|
|
|
|
{
|
2023-04-16 20:03:53 -07:00
|
|
|
return Ok(ValidationResult::Warning(
|
2023-09-10 12:49:35 -04:00
|
|
|
"No plugin.yml or bungee.yml present for plugin file.",
|
2023-04-16 20:03:53 -07:00
|
|
|
));
|
2023-09-10 12:49:35 -04:00
|
|
|
};
|
2022-07-10 03:25:44 +00:00
|
|
|
|
|
|
|
|
Ok(ValidationResult::Pass)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct VelocityValidator;
|
|
|
|
|
|
|
|
|
|
impl super::Validator for VelocityValidator {
|
|
|
|
|
fn get_file_extensions(&self) -> &[&str] {
|
|
|
|
|
&["zip", "jar"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_supported_loaders(&self) -> &[&str] {
|
|
|
|
|
&["velocity"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_supported_game_versions(&self) -> SupportedGameVersions {
|
|
|
|
|
SupportedGameVersions::All
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn validate(
|
|
|
|
|
&self,
|
|
|
|
|
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
|
|
|
|
) -> Result<ValidationResult, ValidationError> {
|
2022-08-06 17:44:16 -07:00
|
|
|
if archive.by_name("velocity-plugin.json").is_err() {
|
|
|
|
|
return Ok(ValidationResult::Warning(
|
|
|
|
|
"No velocity-plugin.json present for plugin file.",
|
|
|
|
|
));
|
|
|
|
|
}
|
2022-07-10 03:25:44 +00:00
|
|
|
|
|
|
|
|
Ok(ValidationResult::Pass)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct SpongeValidator;
|
|
|
|
|
|
|
|
|
|
impl super::Validator for SpongeValidator {
|
|
|
|
|
fn get_file_extensions(&self) -> &[&str] {
|
|
|
|
|
&["zip", "jar"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_supported_loaders(&self) -> &[&str] {
|
|
|
|
|
&["sponge"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_supported_game_versions(&self) -> SupportedGameVersions {
|
|
|
|
|
SupportedGameVersions::All
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn validate(
|
|
|
|
|
&self,
|
|
|
|
|
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
|
|
|
|
) -> Result<ValidationResult, ValidationError> {
|
2023-08-21 11:21:05 -07:00
|
|
|
if !archive.file_names().any(|name| {
|
|
|
|
|
name == "sponge_plugins.json"
|
|
|
|
|
|| name == "mcmod.info"
|
|
|
|
|
|| name == "META-INF/sponge_plugins.json"
|
|
|
|
|
}) {
|
2022-07-10 03:25:44 +00:00
|
|
|
return Ok(ValidationResult::Warning(
|
|
|
|
|
"No sponge_plugins.json or mcmod.info present for Sponge plugin.",
|
|
|
|
|
));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Ok(ValidationResult::Pass)
|
|
|
|
|
}
|
|
|
|
|
}
|