| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- package config
- import (
- "encoding/json"
- "fmt"
- "math/rand"
- "os"
- "bet24.com/log"
- coreservice "bet24.com/servers/coreservice/client"
- )
- const config_key = "spinplay_rooms"
- const config_key_private = "private_spinplay_rooms"
- type RobotConfig struct {
- MinRobotGold int
- MaxRobotGold int
- RobotOnlineSec int
- RobotCount int
- MinRoom int
- MinActionSec int
- MaxActionSec int
- }
- type PrivateRoomConfig struct {
- TargetOptions []int // 初始携带分选项
- UserCountOptions []int // 玩家人数选项
- EnrollFeeOptions []int
- }
- type JackPot struct {
- Odd int // 倍数
- Probility int // 概率
- ControlProbility int // 控制概率
- }
- type RoomInfoParam struct {
- JackPots []JackPot // 奖池配置数据
- InitScore int // 初始携带分
- WinScore int // 游戏结束时赢牌玩家最小分数
- MinRobBankerScore int // 最小抢庄分
- MinRobBankerDifferScore int // 抢庄最小间隔
- MinBankerGiveScore int // 庄家最小给分
- BetLevel int // 投注挡位
- }
- type RoomInfoSec struct {
- SecFree int
- SecJackPot int
- SecSendCard int
- SecRobBanker int
- SecConfirmBanker int
- SecAction int
- SecCompareCard int
- SecRoundEnd int
- SecEnd int
- }
- type RoomInfoBase struct {
- RoomID int
- RoomName string
- RoomDesc string
- MinGold int
- MaxGold int
- BaseScore int
- ServerIP string
- ServerPort int
- LockLevel int
- LevelParam int
- RoomInfoSec
- RoomInfoParam
- PrivateRoomConfig
- }
- type RoomInfo struct {
- RoomInfoBase
- RobotConfig
- }
- func (ri *RoomInfo) GetJackpotAmount(poolValue int) int {
- total := 0
- max := 0
- l := len(ri.JackPots)
- if l > 0 {
- max = ri.JackPots[l-1].Odd
- }
- if poolValue < max {
- for i := 0; i < len(ri.JackPots); i++ {
- total += ri.JackPots[i].ControlProbility
- }
- r := rand.Intn(total)
- start := 0
- for i := 0; i < len(ri.JackPots); i++ {
- start += ri.JackPots[i].ControlProbility
- if r < start {
- return ri.JackPots[i].Odd
- }
- }
- return ri.JackPots[0].Odd
- }
- for i := 0; i < len(ri.JackPots); i++ {
- total += ri.JackPots[i].Probility
- }
- r := rand.Intn(total)
- start := 0
- for i := 0; i < len(ri.JackPots); i++ {
- start += ri.JackPots[i].Probility
- if r < start {
- return ri.JackPots[i].Odd
- }
- }
- return ri.JackPots[0].Odd
- }
- var Rooms struct {
- Rooms []RoomInfo
- }
- func getConfigKey() string {
- if Server.IsPrivateRoom > 0 {
- return config_key_private
- }
- return config_key
- }
- func loadRedisConfig() bool {
- data := coreservice.GetPlatformConfig(getConfigKey())
- if data == "" {
- log.Release(" config msg is null")
- return false
- }
- return marshalData([]byte(data))
- }
- func loadRoomConfig() {
- if loadRedisConfig() {
- log.Release("using remote config ignored rooms.json !!!")
- return
- }
- // 加载房间表
- data, err := os.ReadFile("spinplay/rooms.json")
- //fmt.Println(string(data))
- if err != nil {
- log.Release("read rooms failed spinplay/rooms.json")
- return
- }
- if marshalData(data) {
- // 写入redis
- coreservice.SetPlatformConfig(getConfigKey(), string(data))
- }
- }
- func marshalData(data []byte) bool {
- err := json.Unmarshal(data, &Rooms)
- if err != nil {
- log.Release("Unmarshal rooms failed err:%v", err)
- return false
- }
- if len(Rooms.Rooms) <= 0 {
- log.Release("Rooms.Rooms == 0")
- return false
- }
- if len(Server.ServerIP) > 0 {
- ws := "ws"
- if len(Server.CertFile) > 0 {
- ws = "wss"
- }
- for i := 0; i < len(Rooms.Rooms); i++ {
- Rooms.Rooms[i].ServerIP = fmt.Sprintf("%s://%s:%d", ws, Server.ServerIP, Server.ServerPort)
- }
- }
- return true
- }
- func OnConfigChanged(key string) {
- if key != config_key {
- return
- }
- log.Release("正在刷新配置信息")
- loadRedisConfig()
- }
|