Skip to content

Commit

Permalink
fix to /game/rtp/get.
Browse files Browse the repository at this point in the history
  • Loading branch information
schwarzlichtbezirk committed Dec 8, 2024
1 parent 4c651e3 commit 5ec42a4
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 30 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Slots games server. Releases functionality for Megajack, Novomatic, NetEnt, BetS
Server provides HTTP-based API for popular slots and have well-optimized performance for thousands requests per second. Can be deployed on dedicated server or as portable application for Linux or Windows.

```text
total: 125 games, 64 algorithms, 9 providers
AGT: 43 games
total: 127 games, 64 algorithms, 9 providers
AGT: 45 games
Aristocrat: 4 games
BetSoft: 3 games
Megajack: 3 games
Expand All @@ -30,6 +30,8 @@ Slotopol: 4 games

*Last added games*:

* '[Book of Set](https://demo.agtsoftware.com/games/agt/bookofset)' AGT 5x3 videoslot
* '[Pharaoh II](https://demo.agtsoftware.com/games/agt/pharaoh2)' AGT 5x3 videoslot
* '[Lucky Slot](https://demo.agtsoftware.com/games/agt/luckyslot)' AGT 5x3 videoslot
* '[Egypt](https://demo.agtsoftware.com/games/agt/egypt)' AGT 5x3 videoslot
* '[Sun City](https://demo.agtsoftware.com/games/agt/suncity)' AGT 5x3 videoslot
Expand Down
11 changes: 6 additions & 5 deletions api/errcodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,12 @@ const (

// POST /game/rtp/get

AEC_game_rdget_nobind
AEC_game_rdget_notopened
AEC_game_rdget_noclub
AEC_game_rdget_nouser
AEC_game_rdget_noaccess
AEC_game_rtpget_nobind
AEC_game_rtpget_notopened
AEC_game_rtpget_noinfo
AEC_game_rtpget_noclub
AEC_game_rtpget_nouser
AEC_game_rtpget_noaccess

// POST /slot/bet/get

Expand Down
22 changes: 13 additions & 9 deletions api/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ func ApiGameJoin(c *gin.Context) {
ret.GID = gid
ret.Game = anygame
// make game screen object
club.mux.RLock()
var rtp = GetRTP(user, club)
club.mux.RUnlock()
switch game := anygame.(type) {
case slot.SlotGame:
var scrn = game.NewScreen()
Expand Down Expand Up @@ -230,40 +228,46 @@ func ApiGameRtpGet(c *gin.Context) {
var ret struct {
XMLName xml.Name `json:"-" yaml:"-" xml:"ret"`
MRTP float64 `json:"mrtp" yaml:"mrtp" xml:"mrtp"`
RTP float64 `json:"rtp" yaml:"rtp" xml:"rtp"`
}

if err = c.ShouldBind(&arg); err != nil {
Ret400(c, AEC_game_rdget_nobind, err)
Ret400(c, AEC_game_rtpget_nobind, err)
return
}

var scene *Scene
if scene, ok = Scenes.Get(arg.GID); !ok {
Ret404(c, AEC_game_rdget_notopened, ErrNotOpened)
Ret404(c, AEC_game_rtpget_notopened, ErrNotOpened)
return
}

var gi *game.GameInfo
if gi = game.GetInfo(scene.Alias); gi == nil {
Ret500(c, AEC_game_rtpget_noinfo, ErrNoAliase)
return
}

var club *Club
if club, ok = Clubs.Get(scene.CID); !ok {
Ret500(c, AEC_game_rdget_noclub, ErrNoClub)
Ret500(c, AEC_game_rtpget_noclub, ErrNoClub)
return
}

var user *User
if user, ok = Users.Get(scene.UID); !ok {
Ret500(c, AEC_game_rdget_nouser, ErrNoUser)
Ret500(c, AEC_game_rtpget_nouser, ErrNoUser)
return
}

var admin, al = MustAdmin(c, scene.CID)
if admin != user && al&ALgame == 0 {
Ret403(c, AEC_game_rdget_noaccess, ErrNoAccess)
Ret403(c, AEC_game_rtpget_noaccess, ErrNoAccess)
return
}

club.mux.RLock()
ret.MRTP = GetRTP(user, club)
club.mux.RUnlock()
ret.RTP = gi.FindRTP(ret.MRTP)

RetOk(c, ret)
}
2 changes: 1 addition & 1 deletion api/keno.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ func ApiKenoSpin(c *gin.Context) {

club.mux.RLock()
var bank = club.Bank
var mrtp = GetRTP(user, club)
club.mux.RUnlock()
var mrtp = GetRTP(user, club)

// spin until gain less than bank value
var wins keno.Wins
Expand Down
2 changes: 2 additions & 0 deletions api/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ func GetRTP(user *User, club *Club) float64 {
return props.MRTP
}
}
club.mux.RLock()
defer club.mux.RUnlock()
if club.MRTP != 0 {
return club.MRTP
}
Expand Down
2 changes: 0 additions & 2 deletions api/props.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,7 @@ func ApiPropsRtpGet(c *gin.Context) {
}

if arg.All {
club.mux.RLock()
ret.MRTP = GetRTP(user, club)
club.mux.RUnlock()
} else {
ret.MRTP = user.GetRTP(arg.CID)
}
Expand Down
4 changes: 2 additions & 2 deletions api/slot.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ func ApiSlotSpin(c *gin.Context) {

club.mux.RLock()
var bank = club.Bank
var mrtp = GetRTP(user, club)
club.mux.RUnlock()
var mrtp = GetRTP(user, club)

// spin until gain less than bank value
var wins slot.Wins
Expand Down Expand Up @@ -436,8 +436,8 @@ func ApiSlotDoubleup(c *gin.Context) {

club.mux.RLock()
var bank = club.Bank
var mrtp = GetRTP(user, club)
club.mux.RUnlock()
var mrtp = GetRTP(user, club)

var multgain float64 // new multiplied gain
if bank >= risk*float64(arg.Mult) {
Expand Down
10 changes: 6 additions & 4 deletions docs/list-all.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
'Big Five' AGT 5x3 videoslot
'Bigfoot' AGT 5x3 videoslot
'Bitcoin' AGT 5x3 videoslot
'Book of Set' AGT 5x3 videoslot
'Captain's Treasure' Playtech 5x3 videoslot
'Casino' AGT 5x4 videoslot
'Champagne' Megajack 5x3 videoslot
Expand Down Expand Up @@ -84,8 +85,9 @@
'Marco Polo' Novomatic 5x3 videoslot
'Pandora's Box' NetEnt 5x3 videoslot
'Panther Moon' Playtech 5x3 videoslot
'Pharaon's Gold II' Novomatic 5x3 videoslot
'Pharaon's Gold III' Novomatic 5x3 videoslot
'Pharaoh II' AGT 5x3 videoslot
'Pharaoh's Gold II' Novomatic 5x3 videoslot
'Pharaoh's Gold III' Novomatic 5x3 videoslot
'Piggy Riches' NetEnt 5x3 videoslot
'Pirates Gold' AGT 5x3 videoslot
'Plenty on Twenty' Novomatic 5x3 videoslot
Expand Down Expand Up @@ -128,8 +130,8 @@
'Wild Witches' NetEnt 5x3 videoslot
'Wizard' AGT 5x4 videoslot
total: 125 games, 64 algorithms, 9 providers
AGT: 43 games
total: 127 games, 64 algorithms, 9 providers
AGT: 45 games
Aristocrat: 4 games
BetSoft: 3 games
Megajack: 3 games
Expand Down
21 changes: 21 additions & 0 deletions game/linkdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package game

import (
"context"
"math"
"sort"

"github.com/slotopol/server/util"
Expand Down Expand Up @@ -58,6 +59,17 @@ func MakeRtpList[T any](reelsmap map[float64]T) []float64 {
return list
}

func GetInfo(alias string) *GameInfo {
for _, gi := range GameList {
for _, ga := range gi.Aliases {
if aid := util.ToID(ga.Prov + "/" + ga.Name); alias == aid {
return gi
}
}
}
return nil
}

func (gi *GameInfo) SetupFactory(game func() any, scan Scanner) {
GameList = append(GameList, gi)
for _, ga := range gi.Aliases {
Expand All @@ -66,3 +78,12 @@ func (gi *GameInfo) SetupFactory(game func() any, scan Scanner) {
ScanFactory[aid] = scan
}
}

func (gi *GameInfo) FindRTP(mrtp float64) (rtp float64) {
for _, p := range gi.RTP {
if math.Abs(mrtp-p) < math.Abs(mrtp-rtp) {
rtp = p
}
}
return
}
6 changes: 4 additions & 2 deletions game/slot/agt/aislot/aislot_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (

var Info = game.GameInfo{
Aliases: []game.GameAlias{
{Prov: "AGT", Name: "AI"}, // see: https://demo.agtsoftware.com/games/agt/aislot
{Prov: "AGT", Name: "Tesla"}, // see: https://demo.agtsoftware.com/games/agt/tesla
{Prov: "AGT", Name: "AI"}, // see: https://demo.agtsoftware.com/games/agt/aislot
{Prov: "AGT", Name: "Tesla"}, // see: https://demo.agtsoftware.com/games/agt/tesla
{Prov: "AGT", Name: "Book of Set"}, // see: https://demo.agtsoftware.com/games/agt/bookofset
{Prov: "AGT", Name: "Pharaoh II"}, // see: https://demo.agtsoftware.com/games/agt/pharaoh2
},
GP: game.GPsel |
game.GPretrig |
Expand Down
2 changes: 1 addition & 1 deletion game/slot/agt/aislot/aislot_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var LinePay = [10][5]float64{
var ScatPay = [5]float64{0, 0, 2, 25, 250} // 1 scatter

// Bet lines
var BetLines = slot.BetLinesAgt5x3[:15]
var BetLines = slot.BetLinesAgt5x3[:30]

type Game struct {
slot.Slot5x3 `yaml:",inline"`
Expand Down
4 changes: 2 additions & 2 deletions game/slot/novomatic/dolphinspearl/dolphinspearl_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ var Info = game.GameInfo{
{Prov: "Novomatic", Name: "King Of Cards"},
{Prov: "Novomatic", Name: "Lucky Lady's Charm"},
{Prov: "Novomatic", Name: "Lucky Lady's Charm Deluxe"},
{Prov: "Novomatic", Name: "Pharaon's Gold II"},
{Prov: "Novomatic", Name: "Pharaon's Gold III"},
{Prov: "Novomatic", Name: "Pharaoh's Gold II"},
{Prov: "Novomatic", Name: "Pharaoh's Gold III"},
{Prov: "Novomatic", Name: "Polar Fox"},
{Prov: "Novomatic", Name: "Ramses II"},
{Prov: "Novomatic", Name: "Royal Treasures"},
Expand Down
12 changes: 12 additions & 0 deletions game/slot/screen.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ type Screenx struct {
data [40]Sym
}

// Declare conformity with Screen interface.
var _ Screen = (*Screenx)(nil)

var poolsx = sync.Pool{
New: func() any {
return &Screen3x3{}
Expand Down Expand Up @@ -220,6 +223,9 @@ func (s *Screenx) UnmarshalJSON(b []byte) (err error) {
// Screen for 3x3 slots.
type Screen3x3 [3][3]Sym

// Declare conformity with Screen interface.
var _ Screen = (*Screen3x3)(nil)

var pools3x3 = sync.Pool{
New: func() any {
return &Screen3x3{}
Expand Down Expand Up @@ -369,6 +375,9 @@ func (s *Screen3x3) FillSym() Sym {
// Screen for 5x3 slots.
type Screen5x3 [5][3]Sym

// Declare conformity with Screen interface.
var _ Screen = (*Screen5x3)(nil)

var pools5x3 = sync.Pool{
New: func() any {
return &Screen5x3{}
Expand Down Expand Up @@ -515,6 +524,9 @@ func (s *Screen5x3) FillSym() Sym {
// Screen for 5x4 slots.
type Screen5x4 [5][4]Sym

// Declare conformity with Screen interface.
var _ Screen = (*Screen5x4)(nil)

var pools5x4 = sync.Pool{
New: func() any {
return &Screen5x4{}
Expand Down

0 comments on commit 5ec42a4

Please sign in to comment.