srdusr
aboutsummaryrefslogtreecommitdiffstats
path: root/crates/server
diff options
context:
space:
mode:
Diffstat (limited to 'crates/server')
-rw-r--r--crates/server/migrations/0012_store_catalogue.sql40
-rw-r--r--crates/server/migrations/0013_supporter.sql5
-rw-r--r--crates/server/src/auth.rs17
-rw-r--r--crates/server/src/cosmetics.rs8
4 files changed, 64 insertions, 6 deletions
diff --git a/crates/server/migrations/0012_store_catalogue.sql b/crates/server/migrations/0012_store_catalogue.sql
new file mode 100644
index 0000000..f7e5d99
--- /dev/null
+++ b/crates/server/migrations/0012_store_catalogue.sql
@@ -0,0 +1,40 @@
+- A fuller catalogue. The store shipped with six items, which is not enough
+- for the screen to be worth opening twice.
+--
+- Racer sprites join carets and flair as a third slot: the sprite shown for
+- you in a multiplayer race. Unequipped players fall back to the sprite their
+- position in the room assigns, so nothing is required to race.
+ALTER TABLE cosmetics DROP CONSTRAINT IF EXISTS cosmetics_category_check;
+ALTER TABLE cosmetics ADD CONSTRAINT cosmetics_category_check
+ CHECK (category IN ('caret', 'flair', 'sprite'));
+
+ALTER TABLE users ADD COLUMN equipped_sprite TEXT;
+
+INSERT INTO cosmetics (id, name, category, price_cents, value) VALUES
+ - Carets. Priced the same as each other: they are the same thing in a
+ - different colour, and pricing them apart would only be arbitrary.
+ ('caret-crimson', 'Crimson Caret', 'caret', 199, '#ff3b5c'),
+ ('caret-violet', 'Violet Caret', 'caret', 199, '#a855f7'),
+ ('caret-lime', 'Lime Caret', 'caret', 199, '#a3e635'),
+ ('caret-ice', 'Ice Caret', 'caret', 199, '#7dd3fc'),
+ ('caret-ember', 'Ember Caret', 'caret', 199, '#fb923c'),
+ ('caret-bone', 'Bone Caret', 'caret', 199, '#e7e5e4'),
+ ('caret-void', 'Void Caret', 'caret', 299, '#6b21a8'),
+ ('caret-signal', 'Signal Caret', 'caret', 299, '#22d3ee'),
+
+ - Flair, shown beside a username on the leaderboard and public profile.
+ ('flair-crown', 'Crown', 'flair', 149, 'crown'),
+ ('flair-circuit', 'Circuit', 'flair', 149, 'circuit'),
+ ('flair-eye', 'Eye', 'flair', 149, 'eye'),
+ ('flair-shard', 'Shard', 'flair', 149, 'shard'),
+ ('flair-moth', 'Moth', 'flair', 199, 'moth'),
+ ('flair-reactor', 'Reactor', 'flair', 199, 'reactor'),
+
+ - Race sprites.
+ ('sprite-dart', 'Dart', 'sprite', 249, 'dart'),
+ ('sprite-rocket', 'Rocket', 'sprite', 249, 'rocket'),
+ ('sprite-helm', 'Helm', 'sprite', 249, 'helm'),
+ ('sprite-core', 'Core', 'sprite', 249, 'core'),
+ ('sprite-signal', 'Signal', 'sprite', 249, 'signal'),
+ ('sprite-blade', 'Blade', 'sprite', 249, 'blade')
+ON CONFLICT (id) DO NOTHING;
diff --git a/crates/server/migrations/0013_supporter.sql b/crates/server/migrations/0013_supporter.sql
new file mode 100644
index 0000000..9e8531f
--- /dev/null
+++ b/crates/server/migrations/0013_supporter.sql
@@ -0,0 +1,5 @@
+- Whether an account has paid to remove the ad slots. There is no payment
+- processor yet, so nothing sets this to true, but the flag exists so the
+- slots have a real rule to follow rather than being shown to everybody with
+- a note saying they will be conditional later.
+ALTER TABLE users ADD COLUMN is_supporter BOOLEAN NOT NULL DEFAULT FALSE;
diff --git a/crates/server/src/auth.rs b/crates/server/src/auth.rs
index 382dbfa..caf428b 100644
--- a/crates/server/src/auth.rs
+++ b/crates/server/src/auth.rs
@@ -306,8 +306,17 @@ async fn logout(State(state): State<Arc<AppState>>, jar: CookieJar) -> Result<im
}
async fn me(State(state): State<Arc<AppState>>, jar: CookieJar) -> Result<impl IntoResponse, AppError> {
- match current_user(&state.db, &jar).await {
- Some(user) => Ok(Json(user)),
- None => Err(AppError::Unauthorized),
- }
+ let user = current_user(&state.db, &jar).await.ok_or(AppError::Unauthorized)?;
+ // Whether the ad slots are shown. Fetched here so the client has it with
+ // the identity rather than asking a second time.
+ let is_supporter: bool = sqlx::query_scalar("SELECT is_supporter FROM users WHERE id = $1")
+ .bind(&user.id)
+ .fetch_optional(&state.db)
+ .await?
+ .unwrap_or(false);
+ Ok(Json(serde_json::json!({
+ "id": user.id,
+ "username": user.username,
+ "is_supporter": is_supporter,
+ })))
}
diff --git a/crates/server/src/cosmetics.rs b/crates/server/src/cosmetics.rs
index f128095..460fc66 100644
--- a/crates/server/src/cosmetics.rs
+++ b/crates/server/src/cosmetics.rs
@@ -51,6 +51,7 @@ struct MyCosmetics {
owned: Vec<String>,
equipped_caret: Option<String>,
equipped_flair: Option<String>,
+ equipped_sprite: Option<String>,
}
async fn my_cosmetics(State(state): State<Arc<AppState>>, jar: CookieJar) -> Result<impl IntoResponse, AppError> {
@@ -62,7 +63,7 @@ async fn my_cosmetics(State(state): State<Arc<AppState>>, jar: CookieJar) -> Res
.await?;
let owned: Vec<String> = owned_rows.into_iter().filter_map(|r| r.try_get("cosmetic_id").ok()).collect();
- let equip_row = sqlx::query("SELECT equipped_caret, equipped_flair FROM users WHERE id = $1")
+ let equip_row = sqlx::query("SELECT equipped_caret, equipped_flair, equipped_sprite FROM users WHERE id = $1")
.bind(&user.id)
.fetch_one(&state.db)
.await?;
@@ -76,6 +77,7 @@ async fn my_cosmetics(State(state): State<Arc<AppState>>, jar: CookieJar) -> Res
// into Option<String> correctly does. Found via a real NULL column
// round-tripping as "" instead of JSON null.
equipped_caret: equip_row.try_get::<Option<String>, _>("equipped_caret").unwrap_or(None),
+ equipped_sprite: equip_row.try_get::<Option<String>, _>("equipped_sprite").unwrap_or(None),
equipped_flair: equip_row.try_get::<Option<String>, _>("equipped_flair").unwrap_or(None),
}))
}
@@ -126,6 +128,7 @@ async fn equip(State(state): State<Arc<AppState>>, jar: CookieJar, Path(cosmetic
let column = match category.as_str() {
"caret" => "equipped_caret",
"flair" => "equipped_flair",
+ "sprite" => "equipped_sprite",
_ => return Err(AppError::Internal(anyhow::anyhow!("unknown cosmetic category"))),
};
@@ -147,7 +150,8 @@ async fn unequip(State(state): State<Arc<AppState>>, jar: CookieJar, Json(body):
let column = match body.category.as_str() {
"caret" => "equipped_caret",
"flair" => "equipped_flair",
- _ => return Err(AppError::InvalidInput("category must be 'caret' or 'flair'".into())),
+ "sprite" => "equipped_sprite",
+ _ => return Err(AppError::InvalidInput("category must be 'caret', 'flair' or 'sprite'".into())),
};
let query = format!("UPDATE users SET {column} = NULL WHERE id = $1");
sqlx::query(&query).bind(&user.id).execute(&state.db).await?;