model

package
v0.0.0-...-1561e87 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Article

type Article struct {
	ID        uint   `json:"id"`                                      // The article's id. As primary key.
	Title     string `gorm:"type:varchar(50);not null;" json:"title"` // The article's title.
	Summary   string `gorm:"type:text;not null;" json:"summary"`      // The article's summary.
	Content   string `gorm:"type:text;not null;" json:"content"`      // The article's content.
	AuthorID  uint   `gorm:"not null;" json:"author_id"`              // The article's author's id.
	CreatedAt int64  `gorm:"autoUpdateTime:milli" json:"created_at"`  // The article's creation time.
	UpdatedAt int64  `gorm:"autoUpdateTime:milli" json:"updated_at"`  // The article's last update time.
}

type Category

type Category struct {
	ID          uint   `json:"id"`                                                  // The category's id. As primary key.
	Name        string `gorm:"type:varchar(32);not null;unique" json:"name"`        // The category's name.
	Description string `gorm:"type:text" json:"description"`                        // The category's description.
	Color       string `gorm:"type:varchar(7)" json:"color"`                        // The category's theme color. (Such as Rainbow Dash's color is "#60AEE4")
	Icon        string `gorm:"type:varchar(32);default:'fingerprint';" json:"icon"` // The category's icon. (Based on Material Design Icons, Reference site: https://pictogrammers.com/library/mdi/) (Such as "fingerprint": https://pictogrammers.com/library/mdi/icon/fingerprint/)
	CreatedAt   int64  `gorm:"autoUpdateTime:milli" json:"created_at,omitempty"`    // The category's creation time.
	UpdatedAt   int64  `gorm:"autoUpdateTime:milli" json:"updated_at,omitempty"`    // The category's last update time.
}

Category is the category of the challenge.

func (*Category) BeforeDelete

func (c *Category) BeforeDelete(db *gorm.DB) (err error)

type Challenge

type Challenge struct {
	ID            uint          `json:"id"`                                                     // The challenge's id. As primary key.
	Title         string        `gorm:"type:varchar(32);not null;" json:"title"`                // The challenge's title.
	Description   string        `gorm:"type:text;not null;" json:"description"`                 // The challenge's description.
	CategoryID    uint          `gorm:"not null;" json:"category_id"`                           // The challenge's category.
	Category      *Category     `json:"category,omitempty"`                                     // The challenge's category.
	Attachment    *File         `gorm:"-" json:"attachment"`                                    // The challenge's attachment.
	IsPracticable *bool         `gorm:"not null;default:false" json:"is_practicable,omitempty"` // Whether the challenge is practicable. (Is the practice field visible.)
	IsDynamic     *bool         `gorm:"default:false" json:"is_dynamic"`                        // Whether the challenge is based on dynamic container.
	Difficulty    int64         `gorm:"default:1" json:"difficulty"`                            // The degree of difficulty. (From 1 to 5)
	PracticePts   int64         `gorm:"default:200" json:"practice_pts,omitempty"`              // The points will be given when the challenge is solved in practice field.
	Duration      int64         `gorm:"default:1800" json:"duration,omitempty"`                 // The duration of container maintenance in the initial state. (Seconds)
	ImageName     string        `gorm:"type:varchar(255);" json:"image_name,omitempty"`         // The challenge's image name.
	CPULimit      int64         `gorm:"default:1" json:"cpu_limit,omitempty"`                   // The challenge's CPU limit. (0 means no limit)
	MemoryLimit   int64         `gorm:"default:64" json:"memory_limit,omitempty"`               // The challenge's memory limit. (0 means no limit)
	Flags         []*Flag       `json:"flags,omitempty"`
	Hints         []*Hint       `json:"hints,omitempty"`
	Ports         []*Port       `json:"ports,omitempty"`
	Envs          []*Env        `json:"envs,omitempty"`
	Solved        *Submission   `json:"solved,omitempty"`
	Submissions   []*Submission `json:"submissions,omitempty"`
	CreatedAt     int64         `gorm:"autoUpdateTime:milli" json:"created_at,omitempty"` // The challenge's creation time.
	UpdatedAt     int64         `gorm:"autoUpdateTime:milli" json:"updated_at,omitempty"` // The challenge's last update time.
}

Challenge is the challenge for Jeopardy-style CTF game.

func (*Challenge) AfterFind

func (c *Challenge) AfterFind(db *gorm.DB) (err error)

func (*Challenge) BeforeDelete

func (c *Challenge) BeforeDelete(db *gorm.DB) (err error)

func (*Challenge) BeforeUpdate

func (c *Challenge) BeforeUpdate(db *gorm.DB) (err error)

func (*Challenge) Simplify

func (c *Challenge) Simplify()

type Env

type Env struct {
	ID          uint       `json:"id"`
	Key         string     `gorm:"type:varchar(128);not null;" json:"key"`
	Value       string     `gorm:"type:varchar(128);not null;" json:"value"`
	ChallengeID uint       `gorm:"not null;" json:"challenge_id"`
	Challenge   *Challenge `json:"challenge,omitempty"`
}

type File

type File struct {
	Name string `json:"name"`
	Size int64  `json:"size"`
}

File is only a struct for the file information. Not a real model for GORM.

type Flag

type Flag struct {
	ID          uint       `json:"id"`                                                      // The flag id.
	Type        string     `gorm:"type:varchar(16);not null;default:'static';" json:"type"` // The flag type. ("static"/"dynamic"/"pattern")
	Banned      *bool      `gorm:"not null;default:false;" json:"banned"`                   // Whether the flag is banned. If banned, the user who submitted the flag will be judged as cheating.
	Value       string     `gorm:"type:varchar(255);" json:"value"`                         // The flag content. Maybe a string or a regex, or the placeholder for dynamic challenges. (Such as "flag{friendsh1p_1s_magic}" or "flag{[a-zA-Z]{5}}" or "flag{[UUID]}")
	Env         string     `gorm:"type:varchar(16);" json:"env"`                            // The environment variable which is used to be injected with the flag.
	ChallengeID uint       `json:"challenge_id"`                                            // The challenge id. The flag belongs to.
	Challenge   *Challenge `json:"challenge"`                                               // The challenge which the flag belongs to.
}

Flag is the answer of a Challenge. Because of the Flag is only a subsidiary table, it doesn't need the creation time or updated time.

type FlagGen

type FlagGen struct {
	ID    uint   `json:"id"`
	Flag  string `gorm:"type:varchar(128);" json:"flag"`
	PodID uint   `gorm:"not null;" json:"pod_id"`
	Pod   *Pod   `json:"pod"`
}

FlagGen is the generated flag which is injected into the container. It will be generated when Flag's type is "dynamic".

type Game

type Game struct {
	ID                     uint    `json:"id"`                                                           // The game's id. As primary key.
	Title                  string  `gorm:"type:varchar(64);not null" json:"title,omitempty"`             // The game's title.
	Bio                    string  `gorm:"type:text" json:"bio,omitempty"`                               // The game's short description.
	Description            string  `gorm:"type:text" json:"description,omitempty"`                       // The game's description. (Markdown supported.)
	Poster                 *File   `gorm:"-" json:"poster"`                                              // The game's poster image.
	PublicKey              string  `gorm:"type:varchar(255)" json:"public_key,omitempty"`                // The game's public key.
	PrivateKey             string  `gorm:"type:varchar(255)" json:"-"`                                   // The game's private key.
	IsEnabled              *bool   `gorm:"not null;default:false" json:"is_enabled,omitempty"`           // Whether the game is enabled.
	IsPublic               *bool   `gorm:"not null;default:true" json:"is_public,omitempty"`             // Whether the game is public.
	MemberLimitMin         int64   `gorm:"not null;default:1" json:"member_limit_min,omitempty"`         // The minimum team member limit.
	MemberLimitMax         int64   `gorm:"default:10" json:"member_limit_max,omitempty"`                 // The maximum team member limit.
	ParallelContainerLimit int64   `gorm:"not null;default:2" json:"parallel_container_limit,omitempty"` // The maximum parallel container limit.
	FirstBloodRewardRatio  float64 `gorm:"default:5" json:"first_blood_reward_ratio,omitempty"`          // The prize ratio of first blood.
	SecondBloodRewardRatio float64 `gorm:"default:3" json:"second_blood_reward_ratio,omitempty"`         // The prize ratio of second blood.
	ThirdBloodRewardRatio  float64 `gorm:"default:1" json:"third_blood_reward_ratio,omitempty"`          // The prize ratio of third blood.
	IsNeedWriteUp          *bool   `gorm:"not null;default:true" json:"is_need_write_up,omitempty"`      // Whether the game need write up.
	StartedAt              int64   `gorm:"not null" json:"started_at,omitempty"`                         // The game's start time. (Unix)
	EndedAt                int64   `gorm:"not null" json:"ended_at,omitempty"`                           // The game's end time. (Unix)
	CreatedAt              int64   `gorm:"autoUpdateTime:milli" json:"created_at,omitempty"`             // The game's creation time.
	UpdatedAt              int64   `gorm:"autoUpdateTime:milli" json:"updated_at,omitempty"`             // The game's last update time.
}

func (*Game) AfterFind

func (g *Game) AfterFind(db *gorm.DB) (err error)

func (*Game) BeforeDelete

func (g *Game) BeforeDelete(db *gorm.DB) (err error)

type GameChallenge

type GameChallenge struct {
	ID          uint       `json:"id,omitempty"`
	GameID      uint       `gorm:"uniqueIndex:game_challenge_idx" json:"game_id,omitempty"`
	Game        *Game      `json:"game,omitempty"`
	ChallengeID uint       `gorm:"uniqueIndex:game_challenge_idx" json:"challenge_id,omitempty"`
	Challenge   *Challenge `json:"challenge,omitempty"`
	IsEnabled   *bool      `gorm:"default:false;not null;" json:"is_enabled,omitempty"`
	Pts         int64      `gorm:"-" json:"pts,omitempty"`
	MaxPts      int64      `gorm:"default:1000;not null;" json:"max_pts,omitempty"`
	MinPts      int64      `gorm:"default:200;not null;" json:"min_pts,omitempty"`
}

func (*GameChallenge) BeforeDelete

func (g *GameChallenge) BeforeDelete(db *gorm.DB) (err error)

type GameTeam

type GameTeam struct {
	ID        uint   `json:"id,omitempty"`
	TeamID    uint   `gorm:"uniqueIndex:game_team_idx" json:"team_id,omitempty"`
	Team      *Team  `json:"team,omitempty"`
	GameID    uint   `gorm:"uniqueIndex:game_team_idx" json:"game_id,omitempty"`
	Game      *Game  `json:"game,omitempty"`
	Rank      int    `json:"rank,omitempty"`
	Pts       int64  `json:"pts,omitempty"`
	Solved    int    `json:"solved,omitempty"`
	IsAllowed *bool  `gorm:"default:false;not null;" json:"is_allowed,omitempty"`
	Signature string `gorm:"unique" json:"signature,omitempty"`
}

type Hint

type Hint struct {
	ID          uint       `json:"id"`                                     // The hint's id.
	ChallengeID uint       `gorm:"not null;" json:"challenge_id"`          // The challenge which the hint belongs to.
	Challenge   *Challenge `json:"challenge"`                              // The challenge which the hint belongs to.
	Content     string     `gorm:"type:text;not null;" json:"content"`     // The content of the hint.
	PublishedAt int64      `gorm:"not null;" json:"published_at"`          // When the hint will be published.
	CreatedAt   int64      `gorm:"autoUpdateTime:milli" json:"created_at"` // The hint's creation time.
	UpdatedAt   int64      `gorm:"autoUpdateTime:milli" json:"updated_at"` // The hint's last update time.
}

type Nat

type Nat struct {
	ID      uint   `json:"id"`
	PodID   uint   `gorm:"not null" json:"pod_id"`
	Pod     *Pod   `json:"pod,omitempty"`
	SrcPort int    `gorm:"not null" json:"src_port"` // Of Image
	DstPort int    `gorm:"not null" json:"dst_port"` // Of Pod
	Proxy   string `json:"proxy"`                    // Of Platform
	Entry   string `gorm:"type:varchar(128)" json:"entry"`
}

type Notice

type Notice struct {
	ID          uint       `json:"id"`                                                               // The game event's id.
	Type        string     `gorm:"type:varchar(16);not null;default:'notice'" json:"type,omitempty"` // The game event's type. (Such as "first_blood", "second_blood", "third_blood", "new_challenge", "new_hint", "normal")
	GameID      *uint      `gorm:"index;not null;" json:"game_id,omitempty"`                         // The game which this event belongs to.
	Game        *Game      `json:"game,omitempty"`                                                   // The game which this event belongs to.
	UserID      *uint      `gorm:"index" json:"user_id,omitempty"`                                   // The user who is related to this event.
	User        *User      `json:"user,omitempty"`                                                   // The user who is related to this event.
	TeamID      *uint      `gorm:"index" json:"team_id,omitempty"`                                   // The team which is related to this event.
	Team        *Team      `json:"team,omitempty"`                                                   // The team which is related to this event.
	ChallengeID *uint      `json:"challenge_id,omitempty"`                                           // The challenge which is related to this event.
	Challenge   *Challenge `json:"challenge,omitempty"`                                              // The challenge which is related to this event.
	Content     string     `gorm:"type:text" json:"content,omitempty"`                               // The content of this event. (Only for "notice" type)
	CreatedAt   int64      `gorm:"autoUpdateTime:milli" json:"created_at,omitempty"`                 // The game event's creation time.
	UpdatedAt   int64      `gorm:"autoUpdateTime:milli" json:"updated_at,omitempty"`                 // The game event's last update time.
}

func (*Notice) AfterCreate

func (n *Notice) AfterCreate(db *gorm.DB) (err error)

type Pod

type Pod struct {
	ID          uint       `json:"id"`
	GameID      *uint      `gorm:"index;null;default:null" json:"game_id"`
	Game        *Game      `gorm:"foreignkey:GameID;association_foreignkey:ID" json:"game,omitempty"`
	UserID      *uint      `gorm:"index;null;default:null"  json:"user_id"`
	User        *User      `gorm:"foreignkey:UserID;association_foreignkey:ID" json:"user,omitempty"`
	TeamID      *uint      `gorm:"index;null;default:null" json:"team_id"`
	Team        *Team      `gorm:"foreignkey:TeamID;association_foreignkey:ID" json:"team,omitempty"`
	ChallengeID *uint      `gorm:"index;null;default:null" json:"challenge_id"`
	Challenge   *Challenge `gorm:"foreignkey:ChallengeID;association_foreignkey:ID" json:"challenge,omitempty"`
	RemovedAt   int64      `json:"removed_at"`
	Nats        []*Nat     `json:"nats,omitempty"`
}

type Port

type Port struct {
	ID          uint       `json:"id"`                                  // The port's id. As primary key.
	ChallengeID uint       `gorm:"not null;" json:"challenge_id"`       // The JeopardyImage which the port belongs to.
	Challenge   *Challenge `json:"challenge,omitempty"`                 // The JeopardyImage which the port belongs to.
	Value       int        `gorm:"not null;" json:"value"`              // The port number.
	Description string     `gorm:"type:varchar(32)" json:"description"` // The port's description.
}

Port is the mapping between the JeopardyImage and the exposed port of the JeopardyImage. Because of the port is only a subsidiary table, it doesn't need the creation time or updated time.

type Submission

type Submission struct {
	ID              uint           `json:"id"`                                                                                   // The submission's id. As primary key.
	Flag            string         `gorm:"type:varchar(128);not null" json:"flag,omitempty"`                                     // The flag which was submitted for judgement.
	Status          int            `gorm:"not null;default:0" json:"status"`                                                     // The status of the submission. (0-meaningless, 1-accepted, 2-incorrect, 3-cheat, 4-invalid(duplicate, etc.))
	UserID          uint           `gorm:"not null" json:"user_id"`                                                              // The user who submitted the flag.
	User            *User          `json:"user"`                                                                                 // The user who submitted the flag.
	ChallengeID     uint           `gorm:"not null;" json:"challenge_id"`                                                        // The challenge which is related to this submission.
	Challenge       *Challenge     `json:"challenge"`                                                                            // The challenge which is related to this submission.
	GameChallengeID *uint          `gorm:"index;null;default:null" json:"game_challenge_id,omitempty"`                           // The game_challenge which is related to this submission.
	GameChallenge   *GameChallenge `gorm:"foreignkey:GameChallengeID;association_foreignkey:ID" json:"game_challenge,omitempty"` // The game_challenge which is related to this submission.
	TeamID          *uint          `gorm:"index;null;default:null" json:"team_id,omitempty"`                                     // The team which submitted the flag. (Must be set when GameID is set)
	Team            *Team          `gorm:"foreignkey:TeamID;association_foreignkey:ID" json:"team,omitempty"`                    // The team which submitted the flag.
	GameID          *uint          `gorm:"index;null;default:null" json:"game_id,omitempty"`                                     // The game which is related to this submission. (Must be set when TeamID is set)
	Game            *Game          `gorm:"foreignkey:GameID;association_foreignkey:ID" json:"game,omitempty"`                    // The game which is related to this submission.
	Rank            int64          `json:"rank"`                                                                                 // The rank of the submission.
	Pts             int64          `gorm:"-" json:"pts"`                                                                         // The points of the submission.
	CreatedAt       int64          `gorm:"autoUpdateTime:milli" json:"created_at,omitempty"`                                     // The submission's creation time.
	UpdatedAt       int64          `gorm:"autoUpdateTime:milli" json:"updated_at,omitempty"`                                     // The submission's last update time.
}

func (*Submission) Simplify

func (s *Submission) Simplify()

type Team

type Team struct {
	ID          uint    `json:"id"`                                                // The team's id. As primary key.
	Name        string  `gorm:"type:varchar(36);not null" json:"name"`             // The team's name.
	Description string  `gorm:"type:text" json:"description"`                      // The team's description.
	Email       string  `gorm:"type:varchar(64);" json:"email,omitempty"`          // The team's email.
	Avatar      *File   `gorm:"-" json:"avatar"`                                   // The team's avatar.
	CaptainID   uint    `gorm:"not null" json:"captain_id,omitempty"`              // The captain's id.
	Captain     *User   `json:"captain,omitempty"`                                 // The captain's user.
	IsLocked    *bool   `gorm:"not null;default:false" json:"is_locked,omitempty"` // Whether the team is locked. (true/false)
	InviteToken string  `gorm:"type:varchar(32);" json:"invite_token,omitempty"`   // The team's invite token.
	CreatedAt   int64   `gorm:"autoUpdateTime:milli" json:"created_at,omitempty"`  // The team's creation time.
	UpdatedAt   int64   `gorm:"autoUpdateTime:milli" json:"updated_at,omitempty"`  // The team's last update time.
	Users       []*User `gorm:"many2many:user_teams;" json:"users,omitempty"`      // The team's users.
}

func (*Team) AfterCreate

func (t *Team) AfterCreate(db *gorm.DB) (err error)

func (*Team) AfterFind

func (t *Team) AfterFind(db *gorm.DB) (err error)

func (*Team) AfterUpdate

func (t *Team) AfterUpdate(db *gorm.DB) (err error)

func (*Team) BeforeDelete

func (t *Team) BeforeDelete(db *gorm.DB) (err error)

func (*Team) Simplify

func (t *Team) Simplify()

type User

type User struct {
	ID          uint    `json:"id"`                                                                      // The user's id. As primary key.
	Username    string  `gorm:"column:username;type:varchar(16);unique;not null;index;" json:"username"` // The user's username. As a unique identifier.
	Nickname    string  `gorm:"column:nickname;type:varchar(36);not null" json:"nickname"`               // The user's nickname. Not unique.
	Description string  `gorm:"column:description;type:text" json:"description"`                         // The user's description.
	Email       string  `gorm:"column:email;varchar(64);unique;not null" json:"email,omitempty"`         // The user's email.
	Avatar      *File   `gorm:"-" json:"avatar"`                                                         // The user's avatar.
	Signature   string  `gorm:"column:signature;varchar(255);unique;" json:"signature,omitempty"`        // The user's signature.
	Group       string  `gorm:"column:group;varchar(16);not null;" json:"group,omitempty"`               // The user's group.
	Password    string  `gorm:"column:password;type:varchar(255);not null" json:"password,omitempty"`    // The user's password. Crypt.
	CreatedAt   int64   `gorm:"autoUpdateTime:milli" json:"created_at,omitempty"`                        // The user's creation time.
	UpdatedAt   int64   `gorm:"autoUpdateTime:milli" json:"updated_at,omitempty"`                        // The user's last update time.
	Teams       []*Team `gorm:"many2many:user_teams;" json:"teams,omitempty"`                            // The user's teams.
}

func (*User) AfterCreate

func (u *User) AfterCreate(db *gorm.DB) (err error)

AfterCreate Hook Since the PrivateKey used here belongs to the entire Cloudsdale, it relies on GORM Hooks to write the Signature.

func (*User) AfterFind

func (u *User) AfterFind(db *gorm.DB) (err error)

func (*User) BeforeDelete

func (u *User) BeforeDelete(db *gorm.DB) (err error)

func (*User) Simplify

func (u *User) Simplify()

type UserTeam

type UserTeam struct {
	ID     uint `json:"id"`
	UserID uint `gorm:"uniqueIndex:user_team_idx;" json:"user_id"`
	TeamID uint `gorm:"uniqueIndex:user_team_idx;" json:"team_id"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL