state

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const Nil = redis.Nil

Variables

This section is empty.

Functions

func InitDB

func InitDB(path string) (*gorm.DB, error)

Types

type Aliasable

type Aliasable struct {
	UUID string `gorm:"not null;size:32;unique;uniqueIndex"`
	// A human-readable alias
	Alias string `gorm:"unique;uniqueIndex"`
}

type Asset

type Asset struct {
	Creatable
	Hash string `gorm:"not null;size:32;unique;uniqueIndex"`
	// The ID of the asset store in the cluster config where this asset can
	// be found
	Location  string `gorm:"not null"`
	Extension string `gorm:"not null"`
	Size      uint   `gorm:"not null"`
	Accessed  time.Time
}

type AuthCode

type AuthCode struct {
	Entity
	UserID  uint   `gorm:"not null"`
	User    *User  `gorm:"foreignKey:UserID"`
	Value   string `gorm:"not null;unique;uniqueIndex"`
	Expires time.Time
}

A Discord login code for a user.

type Creatable

type Creatable struct {
	Entity
	Created   time.Time
	CreatorID uint  `gorm:"not null"`
	Creator   *User `gorm:"foreignKey:CreatorID"`
}

func NewCreatable

func NewCreatable(creator *User) Creatable

type ELOType

type ELOType struct {
	Entity
	Name string `gorm:"size:16"`
}

A "type" of ELO tracking e.g. ffa or insta

type Entity

type Entity struct {
	ID uint `gorm:"primaryKey"`
}

type Host

type Host struct {
	Entity
	// The hash of the user's IP
	UUID string
}
type Link struct {
	Entity
	SpaceID uint `gorm:"not null"`

	DestinationID uint   `gorm:"not null"`
	Destination   *Space `gorm:"foreignKey:DestinationID"`

	Teleport uint `gorm:"not null;size:255"`
	Teledest uint `gorm:"not null;size:255"`
}

type Map

type Map struct {
	Creatable

	UUID string `gorm:"not null;size:32;unique;uniqueIndex"`

	OgzID uint   `gorm:"not null"`
	Ogz   *Asset `gorm:"foreignKey:OgzID"`

	CfgID uint   // null OK
	Cfg   *Asset `gorm:"foreignKey:CfgID"`

	DiffID uint     // null OK
	Diff   *MapDiff `gorm:"foreignKey:DiffID"`
}

type MapDiff

type MapDiff struct {
	Entity
	Span

	OldID uint `gorm:"not null"`
	Old   *Map `gorm:"foreignKey:OldID"`

	NewID uint `gorm:"not null"`
	New   *Map `gorm:"foreignKey:NewID"`

	EditsID uint   `gorm:"not null"`
	Edits   *Asset `gorm:"foreignKey:EditsID"`
}

type MapPointer

type MapPointer struct {
	Creatable
	Aliasable

	MapID uint `gorm:"not null"`
	Map   *Map `gorm:"foreignKey:MapID"`
}

type Ranking

type Ranking struct {
	Entity

	UserID uint `gorm:"not null"`
	TypeID uint `gorm:"not null"`
	Rating uint
	Wins   uint
	Draws  uint
	Losses uint

	Type *ELOType `gorm:"foreignKey:TypeID"`
}

type Session

type Session struct {
	Entity
	Span

	UserID uint   // null OK
	UUID   string `gorm:"not null"`
	HostID uint   `gorm:"not null"`

	// desktop, mobile, web
	Device string `gorm:"not null"`

	Visits []*Visit `gorm:"foreignKey:SessionID"`
}

Logs a player's game session from start to finish.

type Space

type Space struct {
	Creatable
	Aliasable

	Description string `gorm:"size:25"`

	OwnerID uint
	Owner   *User `gorm:"foreignKey:OwnerID"`

	MapPointerID uint `gorm:"not null"`
	MapPointer   *MapPointer

	Links []*Link `gorm:"foreignKey:SpaceID"`
}

type Span

type Span struct {
	Start time.Time
	End   time.Time
}

type StateService

type StateService struct {
	Client *redis.Client
}

func NewStateService

func NewStateService(settings config.RedisSettings) *StateService

type User

type User struct {
	Entity

	// The most recent Sauer name the user used
	Nickname string `gorm:"size:15"`

	// Discord unique ID
	UUID string `gorm:"unique;uniqueIndex;size:32"`
	// The user's Discord username
	Username string `gorm:"size:32"`
	// #1234 or whatever
	Discriminator string `gorm:"size:32"`
	// The prefix for Discord's avatar scheme
	Avatar string `gorm:"size:128"`

	// For desktop auth
	PublicKey  string
	PrivateKey string

	LastLogin time.Time

	HomeID uint
	Home   *Space `gorm:"foreignKey:HomeID"`

	Ranking  []*Ranking    `gorm:"foreignKey:UserID"`
	Maps     []*MapPointer `gorm:"foreignKey:CreatorID"`
	Spaces   []*Space      `gorm:"foreignKey:OwnerID"`
	Sessions []*Session    `gorm:"foreignKey:UserID"`
}

func (*User) Reference

func (u *User) Reference() string

type Visit

type Visit struct {
	Entity
	Span
	UserID    uint
	SessionID uint `gorm:"not null"`

	// The server's alias, if set.
	Location     string
	MapID        uint
	MapPointerID uint
	SpaceID      uint
}

A session in a particular space, server, or map.

Jump to

Keyboard shortcuts

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