diff --git a/.gitignore b/.gitignore
index cfb4bb0..68b3e7e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,4 @@
/target
-/data
-
.env
config.toml
\ No newline at end of file
diff --git a/config.example.toml b/config.example.toml
index 76fb6e2..20e2599 100644
--- a/config.example.toml
+++ b/config.example.toml
@@ -16,8 +16,4 @@ port = 8000
[accounts]
# allow new accounts to be created
-allow_registration = true
-
-[db]
-# path for your data to be stored
-data_folder = "data"
\ No newline at end of file
+allow_registration = true
\ No newline at end of file
diff --git a/readme.md b/readme.md
index 6f91c6f..9d7eb6f 100644
--- a/readme.md
+++ b/readme.md
@@ -30,12 +30,11 @@ _these features are implemented_
### building
-- run `cargo build --release`
+- run `cargo build`
## todo
-- green name users...
-- patch uploadlevel to use 2.2 unlisted(honsetly idk what this is)
-- clean up uploadlevel
+- probably work on the code warnings we get hehe
+- green name users... (add udid auth to auth function, use userName instead of accountID in uploading levels, and it goes on and on and on and on...)
- add level parsing
-- maybe swap to chrono instead of `(TO_CHAR(CURRENT_TIMESTAMP, 'YYYY-MM-DD HH24:MI:SS.MS'))` (thats REALLY ugly!!)
\ No newline at end of file
+- maybe swap to timestamp type instead of `(TO_CHAR(CURRENT_TIMESTAMP, 'YYYY-MM-DD HH24:MI:SS.MS'))` (thats REALLY ugly!!)
\ No newline at end of file
diff --git a/src/config.rs b/src/config.rs
index c6b37ae..ee9a2aa 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -5,8 +5,7 @@ use std::sync::LazyLock;
#[derive(Deserialize)]
pub struct Config {
pub general: ConfigGeneral,
- pub accounts: ConfigAccounts,
- pub db: ConfigDB
+ pub accounts: ConfigAccounts
}
#[derive(Deserialize)]
@@ -20,11 +19,6 @@ pub struct ConfigAccounts {
pub allow_registration: bool
}
-#[derive(Deserialize)]
-pub struct ConfigDB {
- pub data_folder: String
-}
-
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/db/models.rs b/src/db/models.rs
index b78af61..0dd7f17 100644
--- a/src/db/models.rs
+++ b/src/db/models.rs
@@ -121,29 +121,4 @@ pub struct Level {
pub featured: i32,
pub epic: i32,
pub rated_coins: i32
-}
-
-#[derive(Insertable, Deserialize)]
-#[diesel(table_name = levels)]
-pub struct NewLevel {
- pub name: String,
- pub user_id: i32,
- pub description: String,
- pub original: i32,
- pub game_version: i32,
- pub binary_version: i32,
- pub password: Option,
- pub requested_stars: i32,
- pub unlisted: i32,
- pub version: i32,
- pub extra_data: Vec,
- pub level_info: Vec,
- pub editor_time: i32,
- pub editor_time_copies: i32,
- pub song_id: i32,
- pub length: i32,
- pub objects: i32,
- pub coins: i32,
- pub has_ldm: i32,
- pub two_player: i32
}
\ No newline at end of file
diff --git a/src/endpoints/accounts/login_account.rs b/src/endpoints/accounts/login_account.rs
index 87a084f..bda02e3 100644
--- a/src/endpoints/accounts/login_account.rs
+++ b/src/endpoints/accounts/login_account.rs
@@ -20,7 +20,7 @@ pub struct FromLoginAccount {
pub fn login_account(input: Form) -> status::Custom<&'static str> {
let connection = &mut db::establish_connection_pg();
- if input.userName != helpers::clean::clean_no_space(input.userName.as_ref()) {
+ if input.userName != helpers::clean::clean(input.userName.as_ref()) {
return status::Custom(Status::Ok, "-4")
}
diff --git a/src/endpoints/accounts/register_account.rs b/src/endpoints/accounts/register_account.rs
index de04a33..92c02f5 100644
--- a/src/endpoints/accounts/register_account.rs
+++ b/src/endpoints/accounts/register_account.rs
@@ -26,7 +26,7 @@ pub fn register_account(input: Form) -> status::Custom<&'st
return status::Custom(Status::Ok, "-1")
}
- if input.userName != helpers::clean::clean_no_space(input.userName.as_ref()) {
+ if input.userName != helpers::clean::clean(input.userName.as_ref()) {
return status::Custom(Status::Ok, "-4")
}
diff --git a/src/endpoints/levels/upload_level.rs b/src/endpoints/levels/upload_level.rs
index bae6579..2444bca 100644
--- a/src/endpoints/levels/upload_level.rs
+++ b/src/endpoints/levels/upload_level.rs
@@ -5,10 +5,6 @@ use rocket::response::status;
use diesel::prelude::*;
-use base64::{Engine as _, engine::general_purpose};
-
-use std::fs;
-
use crate::helpers;
use crate::db;
@@ -16,27 +12,9 @@ use crate::db;
pub struct FormUploadLevel {
accountID: i32,
+ password: Option,
gjp: Option,
gjp2: Option,
-
- password: Option,
- songID: i32,
- audioTrack: i32,
- levelName: String,
- levelDesc: String,
- levelID: i32,
- levelVersion: i32,
- levelInfo: String,
- levelString: String,
- gameVersion: i32,
- extraString: Option,
- requestedStars: Option,
- binaryVersion: Option,
- unlisted: Option,
- original: Option,
- wt: Option,
- wt2: Option,
- ldm: Option
}
#[post("/uploadGJLevel21.php", data = "")]
@@ -44,121 +22,15 @@ pub fn upload_level(input: Form) -> status::Custom<&'static str
let connection = &mut db::establish_connection_pg();
// account verification
- let (user_id_val, _account_id_val): (i32, i32);
+ let (user_id_val, account_id_val): (i32, i32);
- // password argument is used for the level, so
- match helpers::accounts::auth(input.accountID.clone(), None, input.gjp.clone(), input.gjp2.clone()) {
+ match helpers::accounts::auth(input.accountID.clone(), input.password.clone(), input.gjp.clone(), input.gjp2.clone()) {
Ok((user_id, account_id)) => {
user_id_val = user_id;
- _account_id_val = account_id;
+ account_id_val = account_id;
},
Err(_) => return status::Custom(Status::Ok, "-1")
};
- let description_val;
- if input.gameVersion >= 20 {
- description_val = String::from_utf8(general_purpose::URL_SAFE.decode(input.levelDesc.clone()).expect("couldn't decode base64")).expect("invalid UTF-8 sequence (how)")
- } else {
- description_val = input.levelDesc.clone()
- }
-
- let song_id_val = if input.songID == 0 {
- input.audioTrack
- } else {
- input.songID
- };
-
- let extra_string;
- match input.extraString.clone() {
- Some(extra_string_val) => { extra_string = extra_string_val },
- None => { extra_string = helpers::levels::DEFAULT_EXTRA_STRING.to_owned() }
- }
-
- // db shit
- use crate::models::{Level, NewLevel};
-
- {
- use crate::schema::levels::dsl::*;
-
- if levels
- .filter(id.eq(input.levelID))
- .count()
- .get_result::(connection)
- .expect("couldnt get count of levels") > 0 {
- // update level
- let level_user_id = levels
- .filter(id.eq(input.levelID))
- .select(user_id)
- .get_result::(connection)
- .expect("couldnt query levels");
-
- if level_user_id != user_id_val {
- return status::Custom(Status::Ok, "-1")
- }
-
- let updated_level = diesel::update(levels)
- .filter(id.eq(input.levelID))
- .set((
- description.eq(description_val.chars().take(140).collect::()),
- password.eq(input.password.clone()),
- requested_stars.eq(match input.requestedStars {
- Some(requested_stars_val) => requested_stars_val.clamp(0, 10),
- None => 0
- }),
- version.eq(input.levelVersion),
- extra_data.eq(extra_string.as_bytes().to_owned()),
- level_info.eq(input.levelInfo.clone().into_bytes()),
- editor_time.eq(input.wt.unwrap_or(0)),
- editor_time_copies.eq(input.wt2.unwrap_or(0)),
- song_id.eq(song_id_val),
- length.eq(0), // unimplemeneted
- objects.eq(0), // unimplemented
- coins.eq(0), // unimplemented
- has_ldm.eq(input.ldm.unwrap_or(0)),
- two_player.eq(0) // unimplemented
- ))
- .get_result::(connection)
- .expect("failed to update level");
-
- fs::write(format!("{}/levels/{}.lvl", crate::CONFIG.db.data_folder, updated_level.id), general_purpose::URL_SAFE.decode(input.levelString.clone()).expect("user provided invalid level string")).expect("couldnt write level to file");
-
- return status::Custom(Status::Ok, Box::leak(input.levelID.to_string().into_boxed_str()))
- } else {
- // upload level
- let new_level = NewLevel {
- name: helpers::clean::clean_basic(&input.levelName).chars().take(20).collect(),
- user_id: user_id_val,
- description: description_val.chars().take(140).collect(),
- original: input.original.unwrap_or(0),
- game_version: input.gameVersion,
- binary_version: input.binaryVersion.unwrap_or(0),
- password: input.password.clone(),
- requested_stars: match input.requestedStars {
- Some(requested_stars_val) => requested_stars_val.clamp(0, 10),
- None => 0
- },
- unlisted: input.unlisted.unwrap_or(0),
- version: input.levelVersion,
- extra_data: extra_string.as_bytes().to_owned(),
- level_info: input.levelInfo.clone().into_bytes(),
- editor_time: input.wt.unwrap_or(0),
- editor_time_copies: input.wt2.unwrap_or(0),
- song_id: song_id_val,
- length: 0, // not implemeneted
- objects: 0, // not implemeneted
- coins: 0, // not implemeneted
- has_ldm: input.ldm.unwrap_or(0),
- two_player: 0 // not implemented
- };
-
- let inserted_level = diesel::insert_into(levels)
- .values(&new_level)
- .get_result::(connection)
- .expect("failed to insert level");
-
- fs::write(format!("{}/levels/{}.lvl", crate::CONFIG.db.data_folder, inserted_level.id), general_purpose::URL_SAFE.decode(input.levelString.clone()).expect("user provided invalid level string")).expect("couldnt write level to file");
-
- return status::Custom(Status::Ok, "1")
- }
- }
+ return status::Custom(Status::Ok, "1")
}
\ No newline at end of file
diff --git a/src/helpers.rs b/src/helpers.rs
index dcc409e..49728fc 100644
--- a/src/helpers.rs
+++ b/src/helpers.rs
@@ -1,5 +1,4 @@
pub mod accounts;
pub mod clean;
pub mod encryption;
-pub mod format;
-pub mod levels;
\ No newline at end of file
+pub mod format;
\ No newline at end of file
diff --git a/src/helpers/clean.rs b/src/helpers/clean.rs
index afd4161..855b39a 100644
--- a/src/helpers/clean.rs
+++ b/src/helpers/clean.rs
@@ -1,11 +1,6 @@
use regex::Regex;
-pub fn clean_no_space(string: &str) -> String {
+pub fn clean(string: &str) -> String {
let regex = Regex::new(r"[^a-zA-z0-9_-]").unwrap();
return regex.replace_all(string, "").to_string();
-}
-
-pub fn clean_basic(string: &str) -> String {
- let regex = Regex::new(r"[^A-Za-z0-9\-_ ]").unwrap();
- return regex.replace_all(string, "").to_string();
}
\ No newline at end of file
diff --git a/src/helpers/levels.rs b/src/helpers/levels.rs
deleted file mode 100644
index d85a395..0000000
--- a/src/helpers/levels.rs
+++ /dev/null
@@ -1,7 +0,0 @@
-use std::sync::LazyLock;
-
-pub static DEFAULT_EXTRA_STRING: LazyLock = LazyLock::new(|| {
- let string = String::from("29_29_29_40_29_29_29_29_29_29_29_29_29_29_29_29");
-
- return string;
-});
\ No newline at end of file
diff --git a/src/main.rs b/src/main.rs
index d9dfe45..6c30eb8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,8 +4,6 @@
#[macro_use] extern crate maplit;
#[macro_use] extern crate rocket;
-use std::fs;
-
mod db;
use db::*;
@@ -25,8 +23,6 @@ fn index() -> String {
#[launch]
fn rocket() -> _ {
- fs::create_dir_all(&CONFIG.db.data_folder).expect("failed to create data directory!");
- fs::create_dir_all(format!("{}/levels", &CONFIG.db.data_folder)).expect("failed to create data directory for levels");
rocket::build()
.configure(rocket::Config::figment().merge(("port", CONFIG.general.port)))
.mount("/", routes![