spi

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SECnull = iota

	// authorization
	SEC_auth_absent
	SEC_auth_scheme
	SEC_basic_decode
	SEC_basic_nouser
	SEC_basic_deny
	SEC_token_nouser
	SEC_token_malform
	SEC_token_notsign
	SEC_token_badclaims
	SEC_token_expired
	SEC_token_notyet
	SEC_token_issuer
	SEC_token_error

	// 404
	SEC_nourl

	// POST /signup
	SEC_signup_nobind
	SEC_signup_smallsec
	SEC_signup_insert

	// POST /signin
	SEC_signin_nobind
	SEC_signin_nosecret
	SEC_signin_smallsec
	SEC_signin_nouser
	SEC_signin_denypass
	SEC_signin_sigtime
	SEC_signin_timeout
	SEC_signin_hs256
	SEC_signin_denyhash

	// POST /game/join
	SEC_game_join_nobind
	SEC_game_join_norid
	SEC_game_join_nouid
	SEC_game_join_noalias
	SEC_game_join_noclub
	SEC_game_join_nouser
	SEC_prop_join_noaccess
	SEC_game_join_noreels
	SEC_game_join_open
	SEC_game_join_props

	// POST /game/part
	SEC_game_part_nobind
	SEC_game_part_nogid
	SEC_game_part_notopened
	SEC_game_part_nouser
	SEC_prop_part_noaccess

	// POST /game/state
	SEC_game_state_nobind
	SEC_game_state_nogid
	SEC_game_state_notopened
	SEC_game_state_nouser
	SEC_prop_state_noaccess
	SEC_game_state_noprops

	// POST /game/bet
	SEC_game_betget_nobind
	SEC_game_betget_nogid
	SEC_game_betget_notopened
	SEC_prop_betget_noaccess

	// POST /game/bet
	SEC_game_betset_nobind
	SEC_game_betset_nogid
	SEC_game_betset_notopened
	SEC_prop_betset_noaccess
	SEC_game_betset_badbet

	// POST /game/sbl
	SEC_game_sblget_nobind
	SEC_game_sblget_nogid
	SEC_game_sblget_notopened
	SEC_prop_sblget_noaccess

	// POST /game/sbl
	SEC_game_sblset_nobind
	SEC_game_sblset_nogid
	SEC_game_sblset_notopened
	SEC_prop_sblset_noaccess
	SEC_game_sblset_badlines

	// POST /game/reels/get
	SEC_game_rdget_nobind
	SEC_game_rdget_nogid
	SEC_game_rdget_notopened
	SEC_prop_rdget_noaccess

	// POST /game/reels/set
	SEC_game_rdset_nobind
	SEC_game_rdset_nogid
	SEC_game_rdset_notopened
	SEC_prop_rdset_noaccess
	SEC_game_rdset_badreels

	// POST /game/spin
	SEC_game_spin_nobind
	SEC_game_spin_nogid
	SEC_game_spin_notopened
	SEC_game_spin_noclub
	SEC_game_spin_nouser
	SEC_prop_spin_noaccess
	SEC_game_spin_noprops
	SEC_game_spin_nomoney
	SEC_game_spin_badbank
	SEC_game_spin_sqlbank
	SEC_game_spin_sqlupdate

	// POST /game/doubleup
	SEC_game_doubleup_nobind
	SEC_game_doubleup_nogid
	SEC_game_doubleup_nomult
	SEC_game_doubleup_bigmult
	SEC_game_doubleup_notopened
	SEC_game_doubleup_noclub
	SEC_game_doubleup_nouser
	SEC_prop_doubleup_noaccess
	SEC_game_doubleup_noprops
	SEC_game_doubleup_nomoney

	// POST /game/collect
	SEC_game_collect_nobind
	SEC_game_collect_nogid
	SEC_game_collect_notopened
	SEC_prop_collect_noaccess
	SEC_prop_collect_denied

	// POST /prop/wallet
	SEC_prop_walletget_nobind
	SEC_prop_walletget_norid
	SEC_prop_walletget_nouid
	SEC_prop_walletget_noclub
	SEC_prop_walletget_nouser
	SEC_prop_walletget_noaccess

	// POST /prop/wallet
	SEC_prop_walletadd_nobind
	SEC_prop_walletadd_norid
	SEC_prop_walletadd_nouid
	SEC_prop_walletadd_noadd
	SEC_prop_walletadd_limit
	SEC_prop_walletadd_noclub
	SEC_prop_walletadd_nouser
	SEC_prop_walletadd_nomoney
	SEC_prop_walletadd_noaccess
	SEC_prop_walletadd_sqlupdate
	SEC_prop_walletadd_sqlinsert
	SEC_prop_walletadd_sqllog

	// POST /user/rename
	SEC_user_rename_nobind
	SEC_user_rename_nouid
	SEC_user_rename_nouser
	SEC_prop_rename_noaccess
	SEC_user_rename_update

	// POST /user/secret
	SEC_user_secret_nobind
	SEC_user_secret_nouid
	SEC_user_secret_smallsec
	SEC_user_secret_nouser
	SEC_prop_secret_noaccess
	SEC_prop_secret_nosecret
	SEC_user_secret_update

	// POST /user/delete
	SEC_user_delete_nobind
	SEC_user_delete_nouid
	SEC_user_delete_nouser
	SEC_prop_delete_noaccess
	SEC_prop_delete_nosecret
	SEC_prop_delete_sqluser
	SEC_game_delete_sqllock
	SEC_prop_delete_sqlprops
	SEC_prop_delete_sqlgames

	// POST /club/rename
	SEC_club_rename_nobind
	SEC_club_rename_nouid
	SEC_club_rename_noclub
	SEC_club_rename_noaccess
	SEC_club_rename_update

	// POST /club/cashin
	SEC_club_cashin_nobind
	SEC_club_cashin_nouid
	SEC_club_cashin_nosum
	SEC_club_cashin_noclub
	SEC_club_cashin_noaccess
	SEC_club_cashin_bankout
	SEC_club_cashin_fundout
	SEC_club_cashin_lockout
	SEC_game_cashin_sqlbank
	SEC_game_cashin_sqllog
)

Variables

View Source
var (
	ErrNoJwtID  = errors.New("jwt-token does not have user id")
	ErrBadJwtID = errors.New("jwt-token id does not refer to registered user")
	ErrNoAuth   = errors.New("authorization is required")
	ErrNoScheme = errors.New("authorization does not have expected scheme")
	ErrNoSecret = errors.New("expected password or SHA25 hash on it and current time as a nonce")
	ErrSmallKey = errors.New("password too small")
	ErrNoCred   = errors.New("user with given credentials does not registered")
	ErrNotPass  = errors.New("password is incorrect")
	ErrSigTime  = errors.New("signing time can not been recognized (time in RFC3339 expected)")
	ErrSigOut   = errors.New("nonce is expired")
	ErrBadHash  = errors.New("hash cannot be decoded in hexadecimal")
)
View Source
var (
	Err404       = errors.New("page not found")
	ErrNoUID     = errors.New("user ID does not provided")
	ErrNoCID     = errors.New("club ID does not provided")
	ErrNoGID     = errors.New("game ID does not provided")
	ErrNoClub    = errors.New("club with given ID does not found")
	ErrNoUser    = errors.New("user with given ID does not found")
	ErrNoWallet  = errors.New("wallet for given user and club does not found")
	ErrNoAddSum  = errors.New("no sum to change balance of bank or fund or deposit")
	ErrNoMoney   = errors.New("not enough money on balance")
	ErrBankOut   = errors.New("not enough money at bank")
	ErrFundOut   = errors.New("not enough money at jackpot fund")
	ErrLockOut   = errors.New("not enough money at deposit")
	ErrNoAccess  = errors.New("no access rights for this feature")
	ErrNotConf   = errors.New("password confirmation does not pass")
	ErrNoMult    = errors.New("gamble multiplier not given")
	ErrBigMult   = errors.New("gamble multiplier too big")
	ErrZero      = errors.New("given value is zero")
	ErrTooBig    = errors.New("given value exceeds the limit")
	ErrNoAliase  = errors.New("no game alias")
	ErrNoReels   = errors.New("no reels for given game with selected percentage")
	ErrNotOpened = errors.New("game with given ID is not opened")
	ErrBadBank   = errors.New("can not generate spin with current bank balance")
)

AuthGetters is the list of functions to extract the authorization data from the parts of request. List and order in it can be changed.

View Source
var (
	Cfg = cfg.Cfg
)

All created clubs, by CID.

All opened games, by GID.

All registered users, by UID.

Functions

func Auth

func Auth(required bool) gin.HandlerFunc

Auth is authorization middleware, sets User object associated with authorization to gin context. `required` parameter tells to continue if authorization is absent.

func GetAdmin

func GetAdmin(c *gin.Context, cid uint64) (*User, AL)

GetAdmin always returns User pointer for authorized requests, and access level for it.

func Handle404

func Handle404(c *gin.Context)

func Negotiate

func Negotiate(c *gin.Context, code int, data any)

func Ret400

func Ret400(c *gin.Context, code int, err error)

func Ret401

func Ret401(c *gin.Context, code int, err error)

func Ret403

func Ret403(c *gin.Context, code int, err error)

func Ret404

func Ret404(c *gin.Context, code int, err error)

func Ret500

func Ret500(c *gin.Context, code int, err error)

func RetErr

func RetErr(c *gin.Context, status, code int, err error)

func RetOk

func RetOk(c *gin.Context, data any)

func Router

func Router(r *gin.Engine)

func SpiClubCashin

func SpiClubCashin(c *gin.Context)

Adding or withdrawing coins from club bank, fund and lock balances.

func SpiClubRename

func SpiClubRename(c *gin.Context)

Rename the club.

func SpiGameBetGet

func SpiGameBetGet(c *gin.Context)

Returns bet value.

func SpiGameBetSet

func SpiGameBetSet(c *gin.Context)

Set bet value.

func SpiGameCollect

func SpiGameCollect(c *gin.Context)

func SpiGameDoubleup

func SpiGameDoubleup(c *gin.Context)

Double up gamble on last gain.

func SpiGameJoin

func SpiGameJoin(c *gin.Context)

Joins to game and creates new instance of game.

func SpiGameList

func SpiGameList(c *gin.Context)

Returns full list of all available games by game type IDs.

func SpiGamePart

func SpiGamePart(c *gin.Context)

Removes instance of opened game.

func SpiGameReelsGet

func SpiGameReelsGet(c *gin.Context)

Returns reels descriptor for given GID.

func SpiGameReelsSet

func SpiGameReelsSet(c *gin.Context)

Set reels descriptor for given GID. Only game admin can change reels.

func SpiGameSblGet

func SpiGameSblGet(c *gin.Context)

Returns selected bet lines bitset.

func SpiGameSblSet

func SpiGameSblSet(c *gin.Context)

Set selected bet lines bitset.

func SpiGameSpin

func SpiGameSpin(c *gin.Context)

Make a spin.

func SpiGameState

func SpiGameState(c *gin.Context)

Returns full state of game with given GID, and balance on wallet.

func SpiMemUsage

func SpiMemUsage(c *gin.Context)

Memory usage footprint.

func SpiPing

func SpiPing(c *gin.Context)

Check service response.

func SpiPropsWalletAdd

func SpiPropsWalletAdd(c *gin.Context)

Adds some coins to user wallet. Addend can be < 0 to remove some coins.

func SpiPropsWalletGet

func SpiPropsWalletGet(c *gin.Context)

Returns balance at wallet for pointed user at pointed club.

func SpiRefresh

func SpiRefresh(c *gin.Context)

func SpiServInfo

func SpiServInfo(c *gin.Context)

Static service system information.

func SpiSignin

func SpiSignin(c *gin.Context)

func SpiSignup

func SpiSignup(c *gin.Context)

func SpiUserDelete

func SpiUserDelete(c *gin.Context)

Deletes registration, drops user and all linked records from database, and moves all remained coins at wallets to clubs deposits.

func SpiUserRename

func SpiUserRename(c *gin.Context)

Changes 'Name' of given user.

func SpiUserSecret

func SpiUserSecret(c *gin.Context)

Types

type AL

type AL uint

Access level.

const (
	ALban   AL = 1 << iota // user have no access to club
	ALgame                 // can change club game settings
	ALuser                 // can change user balance and move user money to/from club deposit
	ALclub                 // can change club bank, fund, deposit
	ALadmin                // can change same access levels to other users
	ALall   = ALgame | ALuser | ALclub | ALadmin
)

type AuthGetter

type AuthGetter func(c *gin.Context) (*User, int, error)

type AuthResp

type AuthResp struct {
	XMLName xml.Name `json:"-" yaml:"-" xml:"ret"`
	UID     uint64   `json:"uid" yaml:"uid" xml:"uid"`
	Access  string   `json:"access" yaml:"access" xml:"access"`
	Refrsh  string   `json:"refrsh" yaml:"refrsh" xml:"refrsh"`
	Expire  string   `json:"expire" yaml:"expire" xml:"expire"`
	Living  string   `json:"living" yaml:"living" xml:"living"`
}

func (*AuthResp) Setup

func (r *AuthResp) Setup(user *User)

type Banklog

type Banklog struct {
	ID      uint64    `xorm:"pk autoincr" json:"id" yaml:"id" xml:"id,attr"`
	CTime   time.Time `xorm:"created 'ctime'" json:"ctime" yaml:"ctime" xml:"ctime"`
	Bank    float64   `xorm:"notnull 'bank'" json:"bank" yaml:"bank" xml:"bank"`
	Fund    float64   `xorm:"notnull 'fund'" json:"fund" yaml:"fund" xml:"fund"`
	Lock    float64   `xorm:"notnull 'lock'" json:"lock" yaml:"lock" xml:"lock"`
	BankSum float64   `xorm:"notnull 'banksum'" json:"banksum" yaml:"banksum" xml:"banksum" form:"banksum"`
	FundSum float64   `xorm:"notnull 'fundsum'" json:"fundsum" yaml:"fundsum" xml:"fundsum" form:"fundsum"`
	LockSum float64   `xorm:"notnull 'locksum'" json:"locksum" yaml:"locksum" xml:"locksum" form:"locksum"`
}

type Claims

type Claims struct {
	jwt.RegisteredClaims
	UID uint64 `json:"uid,omitempty"`
}

Claims of JWT-tokens. Contains additional profile identifier.

func (*Claims) Validate

func (c *Claims) Validate() error

type Club

type Club struct {
	CID   uint64    `xorm:"pk autoincr" json:"cid" yaml:"cid" xml:"cid,attr"`
	CTime time.Time `xorm:"created 'ctime'" json:"ctime" yaml:"ctime" xml:"ctime"`
	Name  string    `json:"name,omitempty" yaml:"name,omitempty" xml:"name,omitempty"`
	Bank  float64   `xorm:"notnull" json:"bank" yaml:"bank" xml:"bank"` // users win/lost balance, in coins
	Fund  float64   `xorm:"notnull" json:"fund" yaml:"fund" xml:"fund"` // jackpot fund, in coins
	Lock  float64   `xorm:"notnull" json:"lock" yaml:"lock" xml:"lock"` // not changed deposit within games

	JptRate float64 `xorm:"'jptrate' notnull default 0.015" json:"jptrate" yaml:"jptrate" xml:"jptrate"`
	GainRTP float64 `xorm:"'gainrtp' notnull default 95.00" json:"gainrtp" yaml:"gainrtp" xml:"gainrtp"`
	// contains filtered or unexported fields
}

Club means independent bank into which gambles some users.

type OpenGame

type OpenGame struct {
	GID   uint64    `xorm:"pk autoincr" json:"gid" yaml:"gid" xml:"gid,attr"`
	CTime time.Time `xorm:"created 'ctime'" json:"ctime" yaml:"ctime" xml:"ctime"`
	CID   uint64    `xorm:"notnull" json:"cid" yaml:"cid" xml:"cid,attr"`
	UID   uint64    `xorm:"notnull" json:"uid" yaml:"uid" xml:"uid,attr"`
	Alias string    `xorm:"notnull" json:"alias" yaml:"alias" xml:"alias"`
	State `xorm:"-" yaml:",inline"`
}

OpenGame is opened game for user with UID at club with CID. Each instance of game have own GID. Alias - is game type identifier.

func (OpenGame) TableName

func (OpenGame) TableName() string

type Props

type Props struct {
	CID    uint64  `xorm:"notnull index(bid)" json:"cid" yaml:"cid" xml:"cid,attr"`
	UID    uint64  `xorm:"notnull index(bid)" json:"uid" yaml:"uid" xml:"uid,attr"`
	Wallet float64 `xorm:"notnull" json:"wallet" yaml:"wallet" xml:"wallet"` // in coins
	Access AL      `xorm:"notnull" json:"access" yaml:"access" xml:"access"`
}

Props contains properties for user at some club. Any property can be zero by default, or if object does not created at DB.

type Session

type Session = xorm.Session

type Spinlog

type Spinlog struct {
	ID     uint64    `xorm:"pk autoincr" json:"id" yaml:"id" xml:"id,attr"`
	CTime  time.Time `xorm:"created 'ctime'" json:"ctime" yaml:"ctime" xml:"ctime"`
	GID    uint64    `xorm:"notnull" json:"gid" yaml:"gid" xml:"gid,attr"`
	Game   string    `xorm:"notnull" json:"game" yaml:"game" xml:"game"`
	Screen string    `xorm:"notnull" json:"screen,omitempty" yaml:"screen,omitempty" xml:"screen,omitempty"`
	Wins   string    `json:"wins,omitempty" yaml:"wins,omitempty" xml:"wins,omitempty"`
	Gain   float64   `xorm:"notnull" json:"gain" yaml:"gain" xml:"gain"`
	Wallet float64   `xorm:"notnull" json:"wallet" yaml:"wallet" xml:"wallet"`
}

func (*Spinlog) MarshalState

func (sl *Spinlog) MarshalState(s *State) (err error)

type State

type State struct {
	Game         game.SlotGame `json:"game" yaml:"game" xml:"game"`
	Scrn         game.Screen   `json:"scrn" yaml:"scrn" xml:"scrn"`
	game.WinScan `yaml:",inline"`
}

State structure represents full current game state.

type User

type User struct {
	UID    uint64    `xorm:"pk autoincr" json:"uid" yaml:"uid" xml:"uid,attr"`
	CTime  time.Time `xorm:"created 'ctime'" json:"ctime" yaml:"ctime" xml:"ctime"`
	Email  string    `xorm:"notnull unique index" json:"email" yaml:"email" xml:"email"`
	Secret string    `xorm:"notnull" json:"secret" yaml:"secret" xml:"secret"` // auth password
	Name   string    `json:"name,omitempty" yaml:"name,omitempty" xml:"name,omitempty"`
	GAL    AL        `json:"gal,omitempty" yaml:"gal,omitempty" xml:"gal,omitempty"` // global access level
	// contains filtered or unexported fields
}

User means registration of somebody. Each user can have splitted wallet with some coins balance in each Club. User can opens several games without any limitation.

func GetBasicAuth

func GetBasicAuth(credentials string) (user *User, code int, err error)

func GetBearerAuth

func GetBearerAuth(tokenstr string) (user *User, code int, err error)

func UserFromCookie

func UserFromCookie(c *gin.Context) (*User, int, error)

func UserFromForm

func UserFromForm(c *gin.Context) (*User, int, error)

func UserFromHeader

func UserFromHeader(c *gin.Context) (*User, int, error)

func UserFromQuery

func UserFromQuery(c *gin.Context) (*User, int, error)

func (*User) GetAL

func (user *User) GetAL(cid uint64) AL

func (*User) GetWallet

func (user *User) GetWallet(cid uint64) float64

func (*User) Init

func (user *User) Init()

func (*User) InsertProps

func (user *User) InsertProps(props *Props)

type Walletlog

type Walletlog struct {
	ID     uint64    `xorm:"pk autoincr" json:"id" yaml:"id" xml:"id,attr"`
	CTime  time.Time `xorm:"created 'ctime'" json:"ctime" yaml:"ctime" xml:"ctime"`
	CID    uint64    `xorm:"notnull index(bid)" json:"cid" yaml:"cid" xml:"cid,attr"`
	UID    uint64    `xorm:"notnull index(bid)" json:"uid" yaml:"uid" xml:"uid,attr"`
	AdmID  uint64    `xorm:"notnull" json:"admid" yaml:"admid" xml:"admid"`
	Wallet float64   `xorm:"notnull" json:"wallet" yaml:"wallet" xml:"wallet"` // in coins
	Addend float64   `xorm:"notnull" json:"addend" yaml:"addend" xml:"addend"`
}

Jump to

Keyboard shortcuts

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