1
0
mirror of https://git.ngram.ca/OpenJam/rc-servers synced 2026-08-23 23:08:52 +00:00

Create RC database layer

This commit is contained in:
NGnius (Graham)
2025-05-07 20:23:22 -04:00
parent 69c6c54650
commit 77ddeb7891
55 changed files with 2689 additions and 395 deletions

View File

@@ -0,0 +1,37 @@
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "campaigns")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: u32,
pub user_id: u32,
pub creation_time: i64, // seconds since unix epoch
pub campaign_id: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::user::Entity",
from = "Column::UserId",
to = "super::user::Column::Id"
)]
User,
#[sea_orm(has_many = "super::campaign_difficulty_completion::Entity")]
CampaignCompletion,
}
impl Related<super::user::Entity> for Entity {
fn to() -> RelationDef {
Relation::User.def()
}
}
impl Related<super::campaign_difficulty_completion::Entity> for Entity {
fn to() -> RelationDef {
Relation::CampaignCompletion.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@@ -0,0 +1,31 @@
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "campaigns_completion")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: u32,
pub campaign_id: u32,
pub creation_time: i64, // seconds since unix epoch
pub level: u32,
pub wave: u32,
pub complete: bool,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::campaign::Entity",
from = "Column::CampaignId",
to = "super::campaign::Column::Id"
)]
Campaign,
}
impl Related<super::campaign::Entity> for Entity {
fn to() -> RelationDef {
Relation::Campaign.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@@ -0,0 +1,6 @@
use sea_orm::FromQueryResult;
#[derive(FromQueryResult)]
pub struct Id {
pub id: u32,
}

View File

@@ -0,0 +1,70 @@
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "garages")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: u32,
pub user_id: u32,
pub creation_time: i64, // seconds since unix epoch
pub slot: u32,
pub name: String,
pub crf_id: Option<u32>,
pub was_rated: bool,
pub movement_categories: String, // csv?
pub uuid: i64,
pub thumbnail_version: u32,
pub total_robot_cpu: u32,
pub total_cosmetic_cpu: u32,
pub total_robot_ranking: u32,
pub bay_cpu: u32,
pub tutorial_robot: bool,
pub starter_robot_index: Option<u32>,
pub control_type: ControlType,
pub vertical_strafing: bool,
pub sideways_driving: bool,
pub tracks_turn_on_spot: bool,
pub mastery_level: u32,
pub bay_skin_id: String,
pub weapon_order: String, // csv?
pub robot_data: Vec<u8>,
pub colour_data: Vec<u8>,
pub selected: bool,
}
impl Model {
pub fn cube_count(&self) -> u32 {
if self.robot_data.len() >= 4 {
u32::from_le_bytes([self.robot_data[0], self.robot_data[1], self.robot_data[2], self.robot_data[3]])
} else {
0
}
}
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::user::Entity",
from = "Column::UserId",
to = "super::user::Column::Id"
)]
User,
}
impl Related<super::user::Entity> for Entity {
fn to() -> RelationDef {
Relation::User.def()
}
}
impl ActiveModelBehavior for ActiveModel {}
#[repr(u8)]
#[derive(Clone, Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "u8", db_type = "TinyInteger")]
pub enum ControlType {
Camera = 0,
Keyboard = 1,
Count = 2,
}

View File

@@ -0,0 +1,17 @@
pub mod user;
pub mod user_aux;
pub mod permissions;
pub mod garage;
pub mod campaign;
pub mod campaign_difficulty_completion;
pub mod common_query;
pub fn parse_int_csv(s: &str) -> Vec<u32> {
s.split(',').filter_map(|i_as_s| {
i_as_s.parse().ok()
}).collect()
}
pub fn dump_csv<T: std::string::ToString>(slice: &[T]) -> String {
itertools::Itertools::intersperse(slice.iter().map(|x| x.to_string()), ",".to_owned()).collect()
}

View File

@@ -0,0 +1,32 @@
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "permissions")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: u32,
pub user_id: u32,
pub moderator: bool,
pub administrator: bool,
pub developer: bool,
pub royalty: bool,
pub banned: bool,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::user::Entity",
from = "Column::UserId",
to = "super::user::Column::Id"
)]
User,
}
impl Related<super::user::Entity> for Entity {
fn to() -> RelationDef {
Relation::User.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@@ -0,0 +1,52 @@
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "users")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: u32,
pub creation_time: i64, // seconds since unix epoch
pub public_id: String,
pub display_name: String,
pub password: String,
pub email: String,
pub steam_id: Option<String>, // u64
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_one = "super::permissions::Entity")]
Permission,
#[sea_orm(has_many = "super::garage::Entity")]
Garages,
#[sea_orm(has_many = "super::user_aux::Entity")]
Aux,
#[sea_orm(has_many = "super::campaign::Entity")]
Campaigns,
}
impl Related<super::permissions::Entity> for Entity {
fn to() -> RelationDef {
Relation::Permission.def()
}
}
impl Related<super::garage::Entity> for Entity {
fn to() -> RelationDef {
Relation::Garages.def()
}
}
impl Related<super::user_aux::Entity> for Entity {
fn to() -> RelationDef {
Relation::Aux.def()
}
}
impl Related<super::campaign::Entity> for Entity {
fn to() -> RelationDef {
Relation::Campaigns.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@@ -0,0 +1,42 @@
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "users_aux")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: u32,
pub user_id: u32,
pub creation_time: i64, // seconds since unix epoch
pub descriptor: Descriptor,
pub data: String, // usually JSON
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::user::Entity",
from = "Column::UserId",
to = "super::user::Column::Id"
)]
User,
}
impl Related<super::user::Entity> for Entity {
fn to() -> RelationDef {
Relation::User.def()
}
}
impl ActiveModelBehavior for ActiveModel {}
#[derive(Clone, Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "String(StringLen::None)", rename_all = "PascalCase")]
pub enum Descriptor {
UserXP, // u32
PremiumExpiry, // u64, seconds since Unix epoch
UnlockedParts, // rc_core::persist::user::UnlockedParts
TechPoints, // u32
UserRank, // u32
UserFreeCurrency, // u64
UserPaidCurrency, // u64
}