model

package
v0.0.0-...-e36e409 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2019 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Unbound = RowBound{math.MaxInt32, 0}

Functions

func Configure

func Configure(database *gorm.DB) (*gorm.DB, error)

func LoadFromConfig

func LoadFromConfig() (*gorm.DB, error)

func UserExistById

func UserExistById(db *gorm.DB, id uint) (bool, error)

func UserExistByUsername

func UserExistByUsername(db *gorm.DB, username string) (bool, error)

Types

type Claims

type Claims struct {
	jwt.StandardClaims
	UserID   uint     `json:"userId"`
	Username string   `json:"username"`
	Roles    []string `json:"roles"`
}

type Player

type Player struct {
	UserID uint        `gorm:"primary_key"`
	RoomID uint        `gorm:"default:0"`
	Room   *Room       `gorm:"-"` //gorm can't handle this, need put manually
	State  PlayerState `gorm:"default:0"`
	Seat   uint        `gorm:"default:0"`
}

func (*Player) GetByUserID

func (p *Player) GetByUserID(db *gorm.DB, id uint) error

func (*Player) IsInGame

func (p *Player) IsInGame() bool

func (*Player) Ready

func (p *Player) Ready(db *gorm.DB) error

type PlayerState

type PlayerState uint
const (
	OUT_OF_GAME PlayerState = 0
	NOT_READY   PlayerState = 1
	READY       PlayerState = 2
	HOST        PlayerState = 3
)

func (PlayerState) String

func (s PlayerState) String() string

type Profile

type Profile struct {
	UserID    uint `gorm:"primary_key"`
	Nickname  string
	Sex       Sex
	AvatarURL string
}

func EmptyProfile

func EmptyProfile(id uint) *Profile

func (*Profile) FindByUserID

func (profile *Profile) FindByUserID(db *gorm.DB, id uint) error

func (*Profile) Save

func (profile *Profile) Save(db *gorm.DB) error

type Role

type Role struct {
	ID     uint `gorm:"primary_key"`
	UserID uint
	Name   string
}

type Room

type Room struct {
	ID          uint `gorm:"primary_key"`
	GameId      string
	PlayerCount uint
	RoomName    string
	CreatedTime time.Time
	Players     []*Player
	Options     *StringMap `gorm:"type:json"`
}

func FindRoomsByGame

func FindRoomsByGame(db *gorm.DB, game string, bound RowBound) ([]*Room, error)

func (*Room) Attribute

func (r *Room) Attribute() *sync.Map

func (*Room) CreateByHost

func (r *Room) CreateByHost(db *gorm.DB, host *Player) error

func (*Room) Do

func (r *Room) Do(f func())

func (*Room) DoAndWait

func (r *Room) DoAndWait(f func())

func (*Room) EventHostId

func (r *Room) EventHostId() string

func (*Room) Exit

func (r *Room) Exit(db *gorm.DB, p *Player) error

func (*Room) FindByID

func (r *Room) FindByID(db *gorm.DB, id uint) error

func (*Room) FindByUserID

func (r *Room) FindByUserID(db *gorm.DB, id uint) error

func (*Room) FindHost

func (r *Room) FindHost() *Player

func (*Room) FindPlayer

func (r *Room) FindPlayer(f func(p *Player) bool) (*Player, bool)

func (*Room) FindPlayerBySeat

func (r *Room) FindPlayerBySeat(seat uint) (*Player, bool)

func (*Room) FindSeatByPlayer

func (r *Room) FindSeatByPlayer(userId uint) int

func (*Room) GetNextSeat

func (r *Room) GetNextSeat() (uint, bool)

func (*Room) IsAllReady

func (r *Room) IsAllReady() bool

func (*Room) Join

func (r *Room) Join(db *gorm.DB, p *Player) error

func (*Room) Listen

func (r *Room) Listen() space.Subscription

func (*Room) RemovePlayer

func (r *Room) RemovePlayer(userId uint)

func (*Room) SendEvent

func (r *Room) SendEvent(e space.Message)

func (*Room) SwapSeat

func (r *Room) SwapSeat(db *gorm.DB, a, b uint) error

type RowBound

type RowBound struct {
	Limit  int
	Offset int
}

type Sex

type Sex uint8
const (
	Unknown Sex = 0
	Male    Sex = 1
	Female  Sex = 2
)

type StringMap

type StringMap struct {
	Src   map[string]string
	Valid bool
}

func NewEmptyStringMap

func NewEmptyStringMap() *StringMap

func NewStringMap

func NewStringMap(src map[string]string) *StringMap

func (*StringMap) Scan

func (ls *StringMap) Scan(value interface{}) error

func (*StringMap) Value

func (ls *StringMap) Value() (driver.Value, error)

type User

type User struct {
	ID       uint   `gorm:"primary_key"`
	Username string `gorm:"unique;not null"`
	Password string
	Roles    []Role
}

func (*User) ChangePassword

func (user *User) ChangePassword(db *gorm.DB, old, new string) error

func (*User) CreateAccount

func (user *User) CreateAccount(db *gorm.DB) error

func (*User) FindByID

func (user *User) FindByID(db *gorm.DB, id uint) error

func (*User) FindByUsername

func (user *User) FindByUsername(db *gorm.DB, username string) error

func (*User) GenerateToken

func (user *User) GenerateToken(key string) (string, error)

func (*User) GetRoleStrings

func (user *User) GetRoleStrings() []string

func (*User) MatchPassword

func (user *User) MatchPassword(pwd string) bool

func (*User) SetRoles

func (user *User) SetRoles(roles []string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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