roomconfig.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. package config
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "os"
  6. "bet24.com/log"
  7. item "bet24.com/servers/micros/item_inventory/proto"
  8. platformconfig "bet24.com/servers/micros/platformconfig/proto"
  9. )
  10. const config_key = "masharie_table_rooms"
  11. const config_key_chip = "masharie_table_chip_rooms"
  12. const config_key_private = "masharie_table_private_rooms"
  13. type OpenHistory struct {
  14. SerialNumber int
  15. AreaResult []int
  16. }
  17. type RoomInfoBase struct {
  18. RoomName string
  19. ServerIP string
  20. ServerPort int
  21. MinBet int
  22. MaxBet int //个人最大下注额
  23. PersonalBetRatio int //每次下注计算 (下注金额+已经下注金额)/(以下注金额+自身携带金额)<= PersonalBetRatio
  24. TotalMax int
  25. BetTime int
  26. OpenTime int
  27. PrizesTime int
  28. HistoryCount int
  29. State int
  30. StateSec int
  31. SerialNumber int
  32. Historys []OpenHistory
  33. TotalBet int
  34. ProjectMultiple []float64 //项目倍数
  35. WeekRankAward [][]item.ItemPack //周榜奖励
  36. BankerTaxRate int
  37. TaxRate int
  38. BankerConf
  39. }
  40. type BankerConf struct {
  41. BankerMin int // 庄家下限
  42. BankruptcyAmount int // 庄家破产金额 低于此金额,庄家自动下庄
  43. MaxBankerSet int // 庄家局数轮换,有排队的情况 0时不限制
  44. MaxBetRate int
  45. }
  46. type RoomInfo struct {
  47. RoomInfoBase
  48. MinRoom int
  49. JackpotRate int // 排行榜奖池比例
  50. PrizePoolRate int // 彩金奖池比例
  51. FreeChipsLimit int // 免费筹码上限
  52. RobotConfig []RobotInfo // 机器人配置
  53. ChipAmounts []int // 机器人筹码配置
  54. Test bool
  55. }
  56. type RobotInfo struct {
  57. HourStart int
  58. HourEnd int
  59. CountMin int
  60. CountMax int
  61. GoldMin int
  62. GoldMax int
  63. Online int
  64. }
  65. var Rooms struct {
  66. Rooms []RoomInfo
  67. }
  68. var Room *RoomInfo
  69. var RoomConfigName string
  70. func getConfigKey() string {
  71. // 私人场优先
  72. if Server.IsPrivateRoom {
  73. return config_key_private
  74. }
  75. if Server.IsChipRoom {
  76. return config_key_chip
  77. }
  78. return config_key
  79. }
  80. func loadRedisConfig(createRoom bool) bool {
  81. data := platformconfig.GetConfig(getConfigKey())
  82. if data == "" {
  83. log.Release(" config msg is null")
  84. return false
  85. }
  86. ok, _ := marshalData([]byte(data))
  87. return ok
  88. }
  89. func loadRoomConfig() {
  90. if loadRedisConfig(true) {
  91. log.Release("using remote config ignored rooms.json !!!")
  92. return
  93. }
  94. // 保存
  95. // 加载房间表
  96. data, err := os.ReadFile("masharie_table/rooms.json")
  97. //fmt.Println(string(data))
  98. if err != nil {
  99. log.Release("read rooms failed masharie_table/rooms.json")
  100. return
  101. }
  102. if ok, newConfig := marshalData(data); ok {
  103. // 写入redis
  104. platformconfig.SetConfig(getConfigKey(), newConfig)
  105. }
  106. }
  107. func marshalData(data []byte) (bool, string) {
  108. changedConfigString := string(data)
  109. err := json.Unmarshal(data, &Rooms)
  110. if err != nil {
  111. log.Release("Unmarshal rooms failed err:%v", err)
  112. return false, changedConfigString
  113. }
  114. if len(Rooms.Rooms) <= 0 {
  115. log.Release("Rooms.Rooms == 0")
  116. return false, changedConfigString
  117. }
  118. Room = &Rooms.Rooms[0]
  119. if len(Server.ServerIP) > 0 {
  120. ws := "ws"
  121. if len(Server.CertFile) > 0 {
  122. ws = "wss"
  123. }
  124. for i := 0; i < len(Rooms.Rooms); i++ {
  125. Rooms.Rooms[i].ServerIP = fmt.Sprintf("%s://%s:%d", ws, Server.ServerIP, Server.ServerPort)
  126. }
  127. }
  128. return true, changedConfigString
  129. }
  130. func OnConfigChanged(key string) {
  131. if key != getConfigKey() {
  132. return
  133. }
  134. log.Release("正在刷新配置信息")
  135. loadRedisConfig(false)
  136. }