Now getting extra map data.

This commit is contained in:
BurnyLlama 2022-11-06 16:34:51 +01:00
parent 7e92d8c5be
commit 8c1e2471ad
2 changed files with 57 additions and 22 deletions

View File

@ -1,6 +1,8 @@
use mysql_common::chrono::NaiveDateTime; use mysql_common::{chrono::NaiveDateTime, frunk::HList};
use rocket::serde::{Serialize, Deserialize}; use rocket::serde::{Serialize, Deserialize};
pub type MapRow = HList!(String, String, i8, i8, String, NaiveDateTime, String, i32, i32, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool);
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(crate = "rocket::serde")] #[serde(crate = "rocket::serde")]
pub struct Map { pub struct Map {
@ -9,7 +11,49 @@ pub struct Map {
pub points: i8, pub points: i8,
pub stars: i8, pub stars: i8,
pub mapper: String, pub mapper: String,
pub timestamp: NaiveDateTime pub timestamp: NaiveDateTime,
pub width: i32,
pub height: i32,
pub death: bool,
pub through: bool,
pub jump: bool,
pub dfreeze: bool,
pub ehook_start: bool,
pub hit_end: bool,
pub solo_start: bool,
pub tele_gun: bool,
pub tele_grenade: bool,
pub tele_laser: bool,
pub npc_start: bool,
pub super_start: bool,
pub jetpack_start: bool,
pub walljump: bool,
pub nph_start: bool,
pub weapon_shotgun: bool,
pub weapon_grenade: bool,
pub powerup_ninja: bool,
pub weapon_rifle: bool,
pub laser_stop: bool,
pub crazy_shotgun: bool,
pub dragger: bool,
pub door: bool,
pub switch_timed: bool,
pub switch: bool,
pub stop: bool,
pub through_all: bool,
pub tune: bool,
pub oldlaser: bool,
pub teleinevil: bool,
pub telein: bool,
pub telecheck: bool,
pub teleinweapon: bool,
pub teleinhook: bool,
pub checkpoint_first: bool,
pub bonus: bool,
pub boost: bool,
pub plasmaf: bool,
pub plasmae: bool,
pub plasmau: bool
} }
/* /*

View File

@ -3,6 +3,7 @@ use std::result::Result;
use std::error::Error; use std::error::Error;
use mysql::*; use mysql::*;
use mysql::prelude::*; use mysql::prelude::*;
use mysql_common::frunk::hlist_pat;
pub mod map; pub mod map;
@ -12,21 +13,10 @@ pub fn get_maps(pool: &Pool) -> Result<Vec<map::Map>, Box<dyn Error>> {
let mut conn = pool.get_conn()?; let mut conn = pool.get_conn()?;
let maps = conn.query_map( let maps = conn.query_map(
"SELECT * FROM record_maps", "SELECT * FROM record_maps AS maps JOIN record_mapinfo AS mapinfo ON maps.Map = mapinfo.Map",
|( |row: map::MapRow| {
name, let hlist_pat![ name, server, points, stars, mapper, timestamp, _name_again, width, height, death, through, jump, dfreeze, hit_end, ehook_start, solo_start, tele_gun, tele_grenade, tele_laser, npc_start, super_start, jetpack_start, walljump, nph_start, weapon_shotgun, weapon_grenade, powerup_ninja, weapon_rifle, laser_stop, crazy_shotgun, dragger, door, switch_timed, switch, stop, through_all, tune, oldlaser, teleinevil, telein, telecheck, teleinweapon, teleinhook, checkpoint_first, bonus, boost, plasmaf, plasmae, plasmau ] = row;
server, map::Map { name, server, points, stars, mapper, timestamp, width, height, death, through, jump, dfreeze, hit_end, ehook_start, solo_start, tele_gun, tele_grenade, tele_laser, npc_start, super_start, jetpack_start, walljump, nph_start, weapon_shotgun, weapon_grenade, powerup_ninja, weapon_rifle, laser_stop, crazy_shotgun, dragger, door, switch_timed, switch, stop, through_all, tune, oldlaser, teleinevil, telein, telecheck, teleinweapon, teleinhook, checkpoint_first, bonus, boost, plasmaf, plasmae, plasmau }
points,
stars,
mapper,
timestamp,
)| map::Map {
name,
server,
points,
stars,
mapper,
timestamp
} }
)?; )?;
@ -35,17 +25,18 @@ pub fn get_maps(pool: &Pool) -> Result<Vec<map::Map>, Box<dyn Error>> {
pub fn get_map_by_name(pool: &Pool, name: &str) -> Result<Option<map::Map>, Box<dyn Error>> { pub fn get_map_by_name(pool: &Pool, name: &str) -> Result<Option<map::Map>, Box<dyn Error>> {
let mut conn = pool.get_conn()?; let mut conn = pool.get_conn()?;
let stmt = conn.prep("SELECT * FROM record_maps WHERE Map = ?")?; let stmt = conn.prep("SELECT * FROM record_maps AS maps JOIN record_mapinfo AS mapinfo ON maps.Map = mapinfo.Map WHERE maps.Map = ?")?;
let map = conn.exec_first( let map: Option<map::MapRow> = conn.exec_first(
&stmt, &stmt,
(name,) (name,)
)?; )?;
Ok(match map { Ok(match map {
Some((name, server, points, stars, mapper, timestamp)) => Some(map::Map { Some(row) => {
name, server, points, stars, mapper, timestamp let hlist_pat![ name, server, points, stars, mapper, timestamp, _name_again, width, height, death, through, jump, dfreeze, hit_end, ehook_start, solo_start, tele_gun, tele_grenade, tele_laser, npc_start, super_start, jetpack_start, walljump, nph_start, weapon_shotgun, weapon_grenade, powerup_ninja, weapon_rifle, laser_stop, crazy_shotgun, dragger, door, switch_timed, switch, stop, through_all, tune, oldlaser, teleinevil, telein, telecheck, teleinweapon, teleinhook, checkpoint_first, bonus, boost, plasmaf, plasmae, plasmau ] = row;
}), Some(map::Map { name, server, points, stars, mapper, timestamp, width, height, death, through, jump, dfreeze, hit_end, ehook_start, solo_start, tele_gun, tele_grenade, tele_laser, npc_start, super_start, jetpack_start, walljump, nph_start, weapon_shotgun, weapon_grenade, powerup_ninja, weapon_rifle, laser_stop, crazy_shotgun, dragger, door, switch_timed, switch, stop, through_all, tune, oldlaser, teleinevil, telein, telecheck, teleinweapon, teleinhook, checkpoint_first, bonus, boost, plasmaf, plasmae, plasmau })
},
None => None None => None
}) })
} }