Documentation ¶
Index ¶
- Constants
- Variables
- func Auth(required bool) gin.HandlerFunc
- func GetAdmin(c *gin.Context, cid uint64) (*User, AL)
- func Handle404(c *gin.Context)
- func Negotiate(c *gin.Context, code int, data any)
- func Ret400(c *gin.Context, code int, err error)
- func Ret401(c *gin.Context, code int, err error)
- func Ret403(c *gin.Context, code int, err error)
- func Ret404(c *gin.Context, code int, err error)
- func Ret500(c *gin.Context, code int, err error)
- func RetErr(c *gin.Context, status, code int, err error)
- func RetOk(c *gin.Context, data any)
- func Router(r *gin.Engine)
- func SpiClubCashin(c *gin.Context)
- func SpiClubRename(c *gin.Context)
- func SpiGameBetGet(c *gin.Context)
- func SpiGameBetSet(c *gin.Context)
- func SpiGameCollect(c *gin.Context)
- func SpiGameDoubleup(c *gin.Context)
- func SpiGameJoin(c *gin.Context)
- func SpiGameList(c *gin.Context)
- func SpiGamePart(c *gin.Context)
- func SpiGameReelsGet(c *gin.Context)
- func SpiGameReelsSet(c *gin.Context)
- func SpiGameSblGet(c *gin.Context)
- func SpiGameSblSet(c *gin.Context)
- func SpiGameSpin(c *gin.Context)
- func SpiGameState(c *gin.Context)
- func SpiMemUsage(c *gin.Context)
- func SpiPing(c *gin.Context)
- func SpiPropsWalletAdd(c *gin.Context)
- func SpiPropsWalletGet(c *gin.Context)
- func SpiRefresh(c *gin.Context)
- func SpiServInfo(c *gin.Context)
- func SpiSignin(c *gin.Context)
- func SpiSignup(c *gin.Context)
- func SpiUserDelete(c *gin.Context)
- func SpiUserRename(c *gin.Context)
- func SpiUserSecret(c *gin.Context)
- type AL
- type AuthGetter
- type AuthResp
- type Banklog
- type Claims
- type Club
- type OpenGame
- type Props
- type Session
- type Spinlog
- type State
- type User
- func GetBasicAuth(credentials string) (user *User, code int, err error)
- func GetBearerAuth(tokenstr string) (user *User, code int, err error)
- func UserFromCookie(c *gin.Context) (*User, int, error)
- func UserFromForm(c *gin.Context) (*User, int, error)
- func UserFromHeader(c *gin.Context) (*User, int, error)
- func UserFromQuery(c *gin.Context) (*User, int, error)
- type Walletlog
Constants ¶
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_noclub SEC_game_join_nouser SEC_prop_join_noaccess SEC_game_join_noalias 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 ¶
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") )
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") )
var AuthGetters = []AuthGetter{ UserFromHeader, UserFromQuery, UserFromCookie, }
AuthGetters is the list of functions to extract the authorization data from the parts of request. List and order in it can be changed.
var (
Cfg = cfg.Cfg
)
var Clubs util.RWMap[uint64, *Club]
All created clubs, by CID.
var Offered = []string{ binding.MIMEJSON, binding.MIMEXML, binding.MIMEYAML, binding.MIMETOML, }
var OpenGames util.RWMap[uint64, OpenGame]
All opened games, by GID.
var Users util.RWMap[uint64, *User]
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 ¶
GetAdmin always returns User pointer for authorized requests, and access level for it.
func SpiClubCashin ¶
Adding or withdrawing coins from club bank, fund and lock balances.
func SpiGameCollect ¶
func SpiGameList ¶
Returns full list of all available games by game type IDs.
func SpiGameReelsSet ¶
Set reels descriptor for given GID. Only game admin can change reels.
func SpiGameState ¶
Returns full state of game with given GID, and balance on wallet.
func SpiPropsWalletAdd ¶
Adds some coins to user wallet. Addend can be < 0 to remove some coins.
func SpiPropsWalletGet ¶
Returns balance at wallet for pointed user at pointed club.
func SpiRefresh ¶
func SpiUserDelete ¶
Deletes registration, drops user and all linked records from database, and moves all remained coins at wallets to clubs deposits.
func SpiUserSecret ¶
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 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"` }
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.
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.
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 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 ¶
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 (*User) InsertProps ¶
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"` }