object blacklist, storing second length

This commit is contained in:
Reid 2023-09-05 22:34:00 -07:00
parent 86adf64575
commit be729aa533
Signed by: reidlab
GPG key ID: 6C9EAA3364F962C8
4 changed files with 25 additions and 10 deletions

View file

@ -20,4 +20,8 @@ allow_registration = true
[db] [db]
# path for your data to be stored # path for your data to be stored
data_folder = "data" data_folder = "data"
[levels]
# object ids to block
blocklist = [ 31 ] # start position

View file

@ -24,12 +24,12 @@ CREATE TABLE levels (
song_id INTEGER NOT NULL, song_id INTEGER NOT NULL,
length INTEGER NOT NULL, length INTEGER NOT NULL,
length_real DOUBLE PRECISION NOT NULL, length_real DOUBLE PRECISION NOT NULL,
objects INTEGER NOT NULL, objects INTEGER NOT NULL,
coins INTEGER NOT NULL DEFAULT 0, coins INTEGER NOT NULL DEFAULT 0,
has_ldm INTEGER NOT NULL DEFAULT 0, has_ldm INTEGER NOT NULL DEFAULT 0,
two_player INTEGER NOT NULL DEFAULT 0, two_player INTEGER NOT NULL DEFAULT 0,
downloads INTEGER NOT NULL DEFAULT 0, downloads INTEGER NOT NULL DEFAULT 0,
likes INTEGER NOT NULL DEFAULT 0, likes INTEGER NOT NULL DEFAULT 0,

View file

@ -6,7 +6,8 @@ use std::sync::LazyLock;
pub struct Config { pub struct Config {
pub general: ConfigGeneral, pub general: ConfigGeneral,
pub accounts: ConfigAccounts, pub accounts: ConfigAccounts,
pub db: ConfigDB pub db: ConfigDB,
pub levels: ConfigLevels
} }
#[derive(Deserialize)] #[derive(Deserialize)]
@ -25,6 +26,11 @@ pub struct ConfigDB {
pub data_folder: String pub data_folder: String
} }
#[derive(Deserialize)]
pub struct ConfigLevels {
pub blocklist: Vec<i32>
}
impl Config { impl Config {
pub fn load_from_file(file_path: &str) -> Self { pub fn load_from_file(file_path: &str) -> Self {
let toml_str = fs::read_to_string(file_path).expect("Error finding toml config:"); let toml_str = fs::read_to_string(file_path).expect("Error finding toml config:");

View file

@ -91,9 +91,14 @@ pub fn upload_level(input: Form<FormUploadLevel>) -> status::Custom<&'static str
let two_player_val = if inner_level_string.get("kA10").unwrap_or(&String::from("0")).parse::<i32>().expect("kA10 not int") == 1 { 1 } else { 0 }; let two_player_val = if inner_level_string.get("kA10").unwrap_or(&String::from("0")).parse::<i32>().expect("kA10 not int") == 1 { 1 } else { 0 };
let level_length_val = helpers::levels::secs_to_time(level_length_secs); let level_length_val = helpers::levels::secs_to_time(level_length_secs);
// blocking // blocking coins
if coins_val > 3 { 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 🤣😁 // data base 🤣😁