From be729aa533bb0e702e3cc5eab7e9287307de927b Mon Sep 17 00:00:00 2001 From: reidlab Date: Tue, 5 Sep 2023 22:34:00 -0700 Subject: [PATCH] object blacklist, storing second length --- config.example.toml | 6 +++++- migrations/2023-09-03-032651_levels/up.sql | 12 ++++++------ src/config.rs | 8 +++++++- src/endpoints/levels/upload_level.rs | 9 +++++++-- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/config.example.toml b/config.example.toml index 76fb6e2..7e20b53 100644 --- a/config.example.toml +++ b/config.example.toml @@ -20,4 +20,8 @@ allow_registration = true [db] # path for your data to be stored -data_folder = "data" \ No newline at end of file +data_folder = "data" + +[levels] +# object ids to block +blocklist = [ 31 ] # start position \ No newline at end of file diff --git a/migrations/2023-09-03-032651_levels/up.sql b/migrations/2023-09-03-032651_levels/up.sql index 601ac01..3b53884 100644 --- a/migrations/2023-09-03-032651_levels/up.sql +++ b/migrations/2023-09-03-032651_levels/up.sql @@ -24,12 +24,12 @@ CREATE TABLE levels ( song_id INTEGER NOT NULL, - length INTEGER NOT NULL, - length_real DOUBLE PRECISION NOT NULL, - objects INTEGER NOT NULL, - coins INTEGER NOT NULL DEFAULT 0, - has_ldm INTEGER NOT NULL DEFAULT 0, - two_player INTEGER NOT NULL DEFAULT 0, + length INTEGER NOT NULL, + length_real DOUBLE PRECISION NOT NULL, + objects INTEGER NOT NULL, + coins INTEGER NOT NULL DEFAULT 0, + has_ldm INTEGER NOT NULL DEFAULT 0, + two_player INTEGER NOT NULL DEFAULT 0, downloads INTEGER NOT NULL DEFAULT 0, likes INTEGER NOT NULL DEFAULT 0, diff --git a/src/config.rs b/src/config.rs index c6b37ae..6333b20 100644 --- a/src/config.rs +++ b/src/config.rs @@ -6,7 +6,8 @@ use std::sync::LazyLock; pub struct Config { pub general: ConfigGeneral, pub accounts: ConfigAccounts, - pub db: ConfigDB + pub db: ConfigDB, + pub levels: ConfigLevels } #[derive(Deserialize)] @@ -25,6 +26,11 @@ pub struct ConfigDB { pub data_folder: String } +#[derive(Deserialize)] +pub struct ConfigLevels { + pub blocklist: Vec +} + impl Config { pub fn load_from_file(file_path: &str) -> Self { let toml_str = fs::read_to_string(file_path).expect("Error finding toml config:"); diff --git a/src/endpoints/levels/upload_level.rs b/src/endpoints/levels/upload_level.rs index 2b03004..347d6c7 100644 --- a/src/endpoints/levels/upload_level.rs +++ b/src/endpoints/levels/upload_level.rs @@ -91,9 +91,14 @@ pub fn upload_level(input: Form) -> status::Custom<&'static str let two_player_val = if inner_level_string.get("kA10").unwrap_or(&String::from("0")).parse::().expect("kA10 not int") == 1 { 1 } else { 0 }; let level_length_val = helpers::levels::secs_to_time(level_length_secs); - // blocking + // blocking coins if coins_val > 3 { - return status::Custom(Status::Ok, "1") + return status::Custom(Status::Ok, "-1") + } + + // forbidden object checking + if let Some(_forbidden_object) = level_objects.iter().find(|obj| crate::CONFIG.levels.blocklist.contains(&obj.id())) { + return status::Custom(Status::Ok, "-1") } // data base 🤣😁