diff --git a/src/database/map.rs b/src/database/map.rs index e4df32c..3d4acf7 100644 --- a/src/database/map.rs +++ b/src/database/map.rs @@ -1,6 +1,8 @@ -use mysql_common::chrono::NaiveDateTime; +use mysql_common::{chrono::NaiveDateTime, frunk::HList}; 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)] #[serde(crate = "rocket::serde")] pub struct Map { @@ -9,7 +11,49 @@ pub struct Map { pub points: i8, pub stars: i8, 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 } /* diff --git a/src/database/mod.rs b/src/database/mod.rs index 3563173..02fb261 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -3,6 +3,7 @@ use std::result::Result; use std::error::Error; use mysql::*; use mysql::prelude::*; +use mysql_common::frunk::hlist_pat; pub mod map; @@ -12,21 +13,10 @@ pub fn get_maps(pool: &Pool) -> Result, Box> { let mut conn = pool.get_conn()?; let maps = conn.query_map( - "SELECT * FROM record_maps", - |( - name, - server, - points, - stars, - mapper, - timestamp, - )| map::Map { - name, - server, - points, - stars, - mapper, - timestamp + "SELECT * FROM record_maps AS maps JOIN record_mapinfo AS mapinfo ON maps.Map = mapinfo.Map", + |row: map::MapRow| { + 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; + 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 } } )?; @@ -35,17 +25,18 @@ pub fn get_maps(pool: &Pool) -> Result, Box> { pub fn get_map_by_name(pool: &Pool, name: &str) -> Result, Box> { 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 = conn.exec_first( &stmt, (name,) )?; Ok(match map { - Some((name, server, points, stars, mapper, timestamp)) => Some(map::Map { - name, server, points, stars, mapper, timestamp - }), + Some(row) => { + 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 }) }