roomconfig.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package config
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "os"
  6. "bet24.com/log"
  7. platformconfig "bet24.com/servers/micros/platformconfig/proto"
  8. )
  9. const config_key = "luckyfruit_table_rooms"
  10. const config_key_chip = "luckyfruit_table_chip_rooms"
  11. const config_key_private = "luckyfruit_table_private_rooms"
  12. type OpenHistory struct {
  13. SerialNumber int
  14. SpinResult int
  15. }
  16. type RoomInfoBase struct {
  17. RoomName string
  18. ServerIP string
  19. ServerPort int
  20. MinBet int
  21. MaxBet int //个人最大下注额
  22. TotalMax int
  23. BetTime int
  24. OpenTime int
  25. HistoryCount int
  26. State int
  27. StateSec int
  28. SerialNumber int
  29. Historys []OpenHistory
  30. TotalBet int
  31. Odds []float64
  32. TaxRate int
  33. }
  34. type RoomInfo struct {
  35. RoomInfoBase
  36. MinRoom int
  37. RobotConfig []RobotInfo // 机器人配置
  38. JackpotRate int // 奖池比例
  39. FreeChipsLimit int // 免费筹码上限
  40. ChipAmounts []int // 机器人筹码配置
  41. Probability []int // 概率
  42. Test bool
  43. }
  44. type RobotInfo struct {
  45. HourStart int
  46. HourEnd int
  47. CountMin int
  48. CountMax int
  49. GoldMin int
  50. GoldMax int
  51. Online int
  52. }
  53. var Rooms struct {
  54. Rooms []RoomInfo
  55. }
  56. var Room *RoomInfo
  57. var RoomConfigName string
  58. func getConfigKey() string {
  59. // 私人场优先
  60. if Server.IsPrivateRoom {
  61. return config_key_private
  62. }
  63. if Server.IsChipRoom {
  64. return config_key_chip
  65. }
  66. return config_key
  67. }
  68. func loadRedisConfig(createRoom bool) bool {
  69. data := platformconfig.GetConfig(getConfigKey())
  70. if data == "" {
  71. log.Release(" config msg is null")
  72. return false
  73. }
  74. ok, _ := marshalData([]byte(data))
  75. return ok
  76. }
  77. func loadRoomConfig() {
  78. if loadRedisConfig(true) {
  79. log.Release("using remote config ignored rooms.json !!!")
  80. return
  81. }
  82. // 保存
  83. // 加载房间表
  84. data, err := os.ReadFile("luckyfruit_table/rooms.json")
  85. //fmt.Println(string(data))
  86. if err != nil {
  87. log.Release("read rooms failed luckyfruit_table/rooms.json")
  88. return
  89. }
  90. if ok, newConfig := marshalData(data); ok {
  91. // 写入redis
  92. platformconfig.SetConfig(getConfigKey(), newConfig)
  93. }
  94. }
  95. func marshalData(data []byte) (bool, string) {
  96. changedConfigString := string(data)
  97. err := json.Unmarshal(data, &Rooms)
  98. if err != nil {
  99. log.Release("Unmarshal rooms failed err:%v", err)
  100. return false, changedConfigString
  101. }
  102. if len(Rooms.Rooms) <= 0 {
  103. log.Release("Rooms.Rooms == 0")
  104. return false, changedConfigString
  105. }
  106. Room = &Rooms.Rooms[0]
  107. if len(Server.ServerIP) > 0 {
  108. ws := "ws"
  109. if len(Server.CertFile) > 0 {
  110. ws = "wss"
  111. }
  112. for i := 0; i < len(Rooms.Rooms); i++ {
  113. Rooms.Rooms[i].ServerIP = fmt.Sprintf("%s://%s:%d", ws, Server.ServerIP, Server.ServerPort)
  114. }
  115. }
  116. return true, changedConfigString
  117. }
  118. func OnConfigChanged(key string) {
  119. if key != getConfigKey() {
  120. return
  121. }
  122. log.Release("正在刷新配置信息")
  123. loadRedisConfig(false)
  124. }