yeah you can update levels now cool

This commit is contained in:
Reid 2023-09-04 21:26:13 -07:00
parent ac8a121a8c
commit af1e423b56
Signed by: reidlab
GPG key ID: 6C9EAA3364F962C8
5 changed files with 41 additions and 16 deletions

View file

@ -34,10 +34,8 @@ _these features are implemented_
## todo
- probably work on the code warnings we get hehe
- <small>green name users...</small> (add udid auth to auth function, use userName instead of accountID in uploading levels, and it goes on and on and on <small>and on...</small>)
- patch uploadlevel to fix color tags, use 1.9 [levelInfo](https://github.com/Cvolton/GMDprivateServer/blob/master/incl/levels/uploadGJLevel.php#L56)???, and use 2.2 unlisted??
- <small>green name users...</small>
- patch uploadlevel to use 2.2 unlisted(honsetly idk what this is)
- clean up uploadlevel
- add updating levels
- add level parsing
- maybe swap to timestamp type instead of `(TO_CHAR(CURRENT_TIMESTAMP, 'YYYY-MM-DD HH24:MI:SS.MS'))` (thats REALLY ugly!!)
- maybe swap to chrono instead of `(TO_CHAR(CURRENT_TIMESTAMP, 'YYYY-MM-DD HH24:MI:SS.MS'))` (thats REALLY ugly!!)

View file

@ -20,7 +20,7 @@ pub struct FromLoginAccount {
pub fn login_account(input: Form<FromLoginAccount>) -> status::Custom<&'static str> {
let connection = &mut db::establish_connection_pg();
if input.userName != helpers::clean::clean(input.userName.as_ref()) {
if input.userName != helpers::clean::clean_no_space(input.userName.as_ref()) {
return status::Custom(Status::Ok, "-4")
}

View file

@ -26,7 +26,7 @@ pub fn register_account(input: Form<FormRegisterAccount>) -> status::Custom<&'st
return status::Custom(Status::Ok, "-1")
}
if input.userName != helpers::clean::clean(input.userName.as_ref()) {
if input.userName != helpers::clean::clean_no_space(input.userName.as_ref()) {
return status::Custom(Status::Ok, "-4")
}

View file

@ -96,17 +96,39 @@ pub fn upload_level(input: Form<FormUploadLevel>) -> status::Custom<&'static str
return status::Custom(Status::Ok, "-1")
}
// TODO: add level to db, file
let updated_level = diesel::update(levels)
.filter(id.eq(input.levelID))
.set((
description.eq(description_val.chars().take(140).collect::<String>()),
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::<Level, >(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 {
// TODO: clean and filter this to 20 charfacters
name: input.levelName.clone(),
name: helpers::clean::clean_basic(&input.levelName).chars().take(20).collect(),
user_id: user_id_val,
// TODO: filter this to 140 characters
description: description_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),
@ -130,9 +152,9 @@ pub fn upload_level(input: Form<FormUploadLevel>) -> status::Custom<&'static str
};
let inserted_level = diesel::insert_into(levels)
.values(&new_level)
.get_result::<Level, >(connection)
.expect("failed to insert level");
.values(&new_level)
.get_result::<Level, >(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");

View file

@ -1,6 +1,11 @@
use regex::Regex;
pub fn clean(string: &str) -> String {
pub fn clean_no_space(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();
}