Compare commits
2 Commits
a387718b57
...
74449fd78b
| Author | SHA1 | Date | |
|---|---|---|---|
| 74449fd78b | |||
| a8434a5c9b |
@@ -32,5 +32,6 @@ CREATE TABLE IF NOT EXISTS agents (
|
||||
display varchar NOT NULL,
|
||||
def_index integer NOT NULL,
|
||||
team integer NOT NULL, -- 0 = CT, 1 = T, 2 = BOTH
|
||||
model_player varchar NOT NULl
|
||||
model_player varchar NOT NULL,
|
||||
"default" boolean DEFAULT false NOT NULL
|
||||
);
|
||||
|
||||
@@ -17,7 +17,7 @@ use tower_sessions_sqlx_store::sqlx::PgPool as SessionPgPool;
|
||||
mod error;
|
||||
mod skins;
|
||||
mod users;
|
||||
use skins::{skin_info, weapons};
|
||||
use skins::{agent_info, skin_info, weapons};
|
||||
use users::{login, logout, me, reload, update};
|
||||
|
||||
#[tokio::main]
|
||||
@@ -40,6 +40,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
.route("/reload", get(reload))
|
||||
.route("/weapons", get(weapons))
|
||||
.route("/skin", get(skin_info))
|
||||
.route("/agent", get(agent_info))
|
||||
.layer(
|
||||
CorsLayer::new()
|
||||
.allow_origin("http://localhost:5173".parse::<HeaderValue>().unwrap())
|
||||
|
||||
43
src/skins.rs
43
src/skins.rs
@@ -1,5 +1,5 @@
|
||||
use axum::{
|
||||
Json,
|
||||
Json, debug_handler,
|
||||
extract::{Query, State},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -183,3 +183,44 @@ 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.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,
|
||||
name: agent.name,
|
||||
display: agent.display,
|
||||
paint_index: 0,
|
||||
color: agent.color,
|
||||
float: 0.0,
|
||||
pattern: 0,
|
||||
})),
|
||||
None => {
|
||||
let default = query!("SELECT a.name, 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(),
|
||||
name: default.name,
|
||||
display: default.display,
|
||||
paint_index: 0,
|
||||
color: default.color,
|
||||
float: 0.0,
|
||||
pattern: 0,
|
||||
}))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Err(AppError::Unauthorised)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user