|
|
|
|
@@ -1,5 +1,5 @@
|
|
|
|
|
use axum::{
|
|
|
|
|
Json,
|
|
|
|
|
Json, debug_handler,
|
|
|
|
|
extract::{Query, State},
|
|
|
|
|
};
|
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
@@ -21,11 +21,14 @@ pub struct Weapon {
|
|
|
|
|
#[derive(Deserialize, Serialize)]
|
|
|
|
|
pub struct SkinInfo {
|
|
|
|
|
id: Uuid,
|
|
|
|
|
weapon_id: Uuid,
|
|
|
|
|
name: String,
|
|
|
|
|
display: String,
|
|
|
|
|
paint_index: i32,
|
|
|
|
|
color: String,
|
|
|
|
|
float: f64,
|
|
|
|
|
min_float: f64,
|
|
|
|
|
max_float: f64,
|
|
|
|
|
pattern: i32,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -63,6 +66,7 @@ enum Categories {
|
|
|
|
|
Pistols,
|
|
|
|
|
Heavy,
|
|
|
|
|
Equipment,
|
|
|
|
|
Weapons, // Special category to get all weapons except gloves and knives
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Categories {
|
|
|
|
|
@@ -75,6 +79,7 @@ impl Categories {
|
|
|
|
|
Categories::Pistols => "Pistols",
|
|
|
|
|
Categories::Heavy => "Heavy",
|
|
|
|
|
Categories::Equipment => "Equipment",
|
|
|
|
|
Categories::Weapons => "",
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -102,10 +107,19 @@ pub async fn skin_info(
|
|
|
|
|
}
|
|
|
|
|
// Same with category
|
|
|
|
|
if let Some(category) = info_query.category {
|
|
|
|
|
default_skins = default_skins
|
|
|
|
|
default_skins = match category {
|
|
|
|
|
Categories::Weapons => default_skins
|
|
|
|
|
.into_iter()
|
|
|
|
|
.filter(|x| {
|
|
|
|
|
![Categories::Gloves.as_str(), Categories::Knives.as_str()]
|
|
|
|
|
.contains(&x.category.as_str())
|
|
|
|
|
})
|
|
|
|
|
.collect(),
|
|
|
|
|
_ => default_skins
|
|
|
|
|
.into_iter()
|
|
|
|
|
.filter(|x| category.as_str() == x.category)
|
|
|
|
|
.collect();
|
|
|
|
|
.collect(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// For each remaining default weapon, see if the user has set a skin
|
|
|
|
|
// Secific cases for Knives and Gloves
|
|
|
|
|
@@ -113,7 +127,10 @@ pub async fn skin_info(
|
|
|
|
|
for default in default_skins {
|
|
|
|
|
struct Info {
|
|
|
|
|
id: Uuid,
|
|
|
|
|
weapon_id: Uuid,
|
|
|
|
|
float: f64,
|
|
|
|
|
min_float: f64,
|
|
|
|
|
max_float: f64,
|
|
|
|
|
pattern: i32,
|
|
|
|
|
team: i32,
|
|
|
|
|
name: String,
|
|
|
|
|
@@ -124,10 +141,10 @@ pub async fn skin_info(
|
|
|
|
|
}
|
|
|
|
|
let user_skin = match default.category.as_str() {
|
|
|
|
|
"Gloves" | "Knives" => {
|
|
|
|
|
query_as!(Info, "SELECT us.id, us.float, us.pattern, us.team, w.name, w.display as wd, s.display as sd, s.paint_index, r.color FROM user_skins us JOIN skins s ON us.skin_id = s.id JOIN weapons w ON s.weapon = w.id JOIN rarity r ON r.id = s.rarity WHERE us.user_id = $1 AND w.category = $2", uuid, default.category).fetch_all(&pool).await?
|
|
|
|
|
query_as!(Info, "SELECT us.id, w.id as weapon_id, us.float, us.pattern, us.team, w.name, w.display as wd, s.display as sd, s.paint_index, s.min_float, s.max_float, r.color FROM user_skins us JOIN skins s ON us.skin_id = s.id JOIN weapons w ON s.weapon = w.id JOIN rarity r ON r.id = s.rarity WHERE us.user_id = $1 AND w.category = $2", uuid, default.category).fetch_all(&pool).await?
|
|
|
|
|
},
|
|
|
|
|
_ => {
|
|
|
|
|
query_as!(Info, "SELECT us.id, us.float, us.pattern, us.team, w.name, w.display as wd, s.display as sd, s.paint_index, r.color FROM user_skins us JOIN skins s ON us.skin_id = s.id JOIN weapons w ON s.weapon = w.id JOIN rarity r ON r.id = s.rarity WHERE us.user_id = $1 AND w.id = $2", uuid, default.id).fetch_all(&pool).await?
|
|
|
|
|
query_as!(Info, "SELECT us.id, w.id as weapon_id, us.float, us.pattern, us.team, w.name, w.display as wd, s.display as sd, s.paint_index, s.min_float, s.max_float, r.color FROM user_skins us JOIN skins s ON us.skin_id = s.id JOIN weapons w ON s.weapon = w.id JOIN rarity r ON r.id = s.rarity WHERE us.user_id = $1 AND w.id = $2", uuid, default.id).fetch_all(&pool).await?
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
let user_skin = if let Some(team) = info_query.team {
|
|
|
|
|
@@ -137,7 +154,10 @@ pub async fn skin_info(
|
|
|
|
|
.min_by(|x, y| x.team.cmp(&y.team))
|
|
|
|
|
.unwrap_or(Info {
|
|
|
|
|
id: Uuid::nil(),
|
|
|
|
|
weapon_id: default.id,
|
|
|
|
|
float: 0.0,
|
|
|
|
|
min_float: 0.0,
|
|
|
|
|
max_float: 1.0,
|
|
|
|
|
pattern: 0,
|
|
|
|
|
team: 2,
|
|
|
|
|
name: default.name,
|
|
|
|
|
@@ -152,7 +172,10 @@ pub async fn skin_info(
|
|
|
|
|
.max_by(|x, y| x.team.cmp(&y.team))
|
|
|
|
|
.unwrap_or(Info {
|
|
|
|
|
id: Uuid::nil(),
|
|
|
|
|
weapon_id: default.id,
|
|
|
|
|
float: 0.0,
|
|
|
|
|
min_float: 0.0,
|
|
|
|
|
max_float: 1.0,
|
|
|
|
|
pattern: 0,
|
|
|
|
|
team: 2,
|
|
|
|
|
name: default.name,
|
|
|
|
|
@@ -170,10 +193,13 @@ pub async fn skin_info(
|
|
|
|
|
let info = SkinInfo {
|
|
|
|
|
display,
|
|
|
|
|
id: user_skin.id,
|
|
|
|
|
weapon_id: user_skin.weapon_id,
|
|
|
|
|
name: user_skin.name,
|
|
|
|
|
paint_index: user_skin.paint_index,
|
|
|
|
|
color: user_skin.color,
|
|
|
|
|
float: user_skin.float,
|
|
|
|
|
min_float: user_skin.min_float,
|
|
|
|
|
max_float: user_skin.max_float,
|
|
|
|
|
pattern: user_skin.pattern,
|
|
|
|
|
};
|
|
|
|
|
skin_infos.push(info);
|
|
|
|
|
@@ -183,3 +209,103 @@ pub async fn skin_info(
|
|
|
|
|
Err(AppError::Unauthorised)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Deserialize, Serialize)]
|
|
|
|
|
pub struct AgentInfoQuery {
|
|
|
|
|
team: Teams,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[debug_handler]
|
|
|
|
|
pub async fn agent_info(
|
|
|
|
|
State(pool): State<PgPool>,
|
|
|
|
|
session: Session,
|
|
|
|
|
Query(info_query): Query<AgentInfoQuery>,
|
|
|
|
|
) -> Result<Json<SkinInfo>, AppError> {
|
|
|
|
|
if let Some(uuid) = session.get::<Uuid>("uuid").await? {
|
|
|
|
|
let agent = query!("SELECT us.id, a.id as weapon_id, a.name, a.display, r.color FROM user_skins us JOIN agents a ON a.id = us.agent_id JOIN rarity r ON r.id = a.rarity WHERE us.user_id=$1 AND us.team=$2", uuid, info_query.team.as_i32()).fetch_optional(&pool).await?;
|
|
|
|
|
match agent {
|
|
|
|
|
Some(agent) => Ok(Json(SkinInfo {
|
|
|
|
|
id: agent.id,
|
|
|
|
|
weapon_id: agent.weapon_id,
|
|
|
|
|
name: agent.name,
|
|
|
|
|
display: agent.display,
|
|
|
|
|
paint_index: 0,
|
|
|
|
|
color: agent.color,
|
|
|
|
|
float: 0.0,
|
|
|
|
|
min_float: 0.0,
|
|
|
|
|
max_float: 0.0,
|
|
|
|
|
pattern: 0,
|
|
|
|
|
})),
|
|
|
|
|
None => {
|
|
|
|
|
let default = query!("SELECT a.name, a.id as weapon_id, a.display, r.color FROM agents a JOIN rarity r ON r.id = a.rarity WHERE a.team = $1 AND a.default = true", info_query.team.as_i32()).fetch_one(&pool).await?;
|
|
|
|
|
Ok(Json(SkinInfo {
|
|
|
|
|
id: Uuid::nil(),
|
|
|
|
|
weapon_id: default.weapon_id,
|
|
|
|
|
name: default.name,
|
|
|
|
|
display: default.display,
|
|
|
|
|
paint_index: 0,
|
|
|
|
|
color: default.color,
|
|
|
|
|
float: 0.0,
|
|
|
|
|
min_float: 0.0,
|
|
|
|
|
max_float: 0.0,
|
|
|
|
|
pattern: 0,
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Err(AppError::Unauthorised)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Default, Debug)]
|
|
|
|
|
pub struct PaintIndexInfo {
|
|
|
|
|
name: String,
|
|
|
|
|
paint_index: i32,
|
|
|
|
|
display: String,
|
|
|
|
|
color: String,
|
|
|
|
|
min_float: f64,
|
|
|
|
|
max_float: f64,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
|
pub struct PaintQuery {
|
|
|
|
|
weapon: Uuid,
|
|
|
|
|
team: Teams,
|
|
|
|
|
agent: Option<bool>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub async fn list_paint_index(
|
|
|
|
|
State(pool): State<PgPool>,
|
|
|
|
|
Query(paint_query): Query<PaintQuery>,
|
|
|
|
|
) -> Result<Json<Vec<PaintIndexInfo>>, AppError> {
|
|
|
|
|
let agent = match paint_query.agent {
|
|
|
|
|
Some(agent) => agent,
|
|
|
|
|
None => false,
|
|
|
|
|
};
|
|
|
|
|
let paints = if agent {
|
|
|
|
|
let values = query!("SELECT a.name, a.def_index, a.display, r.color FROM agents a JOIN rarity r ON r.id = a.rarity WHERE a.team=$1", paint_query.team.as_i32()).fetch_all(&pool).await?;
|
|
|
|
|
values
|
|
|
|
|
.into_iter()
|
|
|
|
|
.map(|x| PaintIndexInfo {
|
|
|
|
|
name: x.name,
|
|
|
|
|
paint_index: x.def_index,
|
|
|
|
|
display: x.display,
|
|
|
|
|
color: x.color,
|
|
|
|
|
min_float: 0.0,
|
|
|
|
|
max_float: 0.0,
|
|
|
|
|
})
|
|
|
|
|
.collect()
|
|
|
|
|
} else {
|
|
|
|
|
let category = query!(
|
|
|
|
|
"SELECT w.category FROM weapons w WHERE w.id=$1",
|
|
|
|
|
paint_query.weapon
|
|
|
|
|
)
|
|
|
|
|
.fetch_one(&pool)
|
|
|
|
|
.await?;
|
|
|
|
|
match category.category.as_str() {
|
|
|
|
|
"Knives" | "Gloves" => query_as!(PaintIndexInfo, "SELECT w.name, s.paint_index, s.display, r.color, s.min_float, s.max_float FROM skins s JOIN rarity r ON r.id = s.rarity JOIN weapons w ON w.id = s.weapon WHERE w.category=$1", category.category).fetch_all(&pool).await?,
|
|
|
|
|
_ => query_as!(PaintIndexInfo, "SELECT w.name, s.paint_index, s.display, r.color, s.min_float, s.max_float FROM skins s JOIN rarity r ON r.id = s.rarity JOIN weapons w ON w.id = s.weapon WHERE w.id=$1", paint_query.weapon).fetch_all(&pool).await?
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Ok(Json(paints))
|
|
|
|
|
}
|
|
|
|
|
|