waterpool.pb.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. package proto
  2. import (
  3. "context"
  4. "bet24.com/log"
  5. "bet24.com/servers/micros/common"
  6. "github.com/smallnest/rpcx/client"
  7. )
  8. const ServiceName = "waterpool"
  9. var consulAddr = common.Default_Consul_Addr
  10. func getClient() client.XClient {
  11. return common.GetClientPool().GetClient(ServiceName, consulAddr)
  12. }
  13. type Request struct {
  14. Name string
  15. UserGold int
  16. Amount int
  17. GameId int
  18. IsSlots bool
  19. RoomName string
  20. }
  21. type Response struct {
  22. Data string
  23. RetCode int
  24. WaterType int
  25. WaterProb int
  26. }
  27. func SetConsulAddr(addr string) {
  28. consulAddr = addr
  29. }
  30. func SayHello(name string) string {
  31. xclient := getClient()
  32. //defer xclient.Close()
  33. args := &Request{
  34. Name: name,
  35. }
  36. reply := &Response{}
  37. err := xclient.Call(context.Background(), "SayHello", args, reply)
  38. if err != nil {
  39. log.Debug("waterpool failed to call: %v", err)
  40. common.GetClientPool().RemoveClient(ServiceName)
  41. return ""
  42. }
  43. log.Debug("SayHello return %s", reply.Data)
  44. return reply.Data
  45. }
  46. // 调控模式
  47. const (
  48. PoolControl_Invalid = -1
  49. PoolControl_Normal = 0 // 0不调控
  50. PoolControl_Lose = 1 // 1扣减
  51. PoolControl_Win = 2 // 2放水
  52. )
  53. func AddBet(userGold int, betAmount int, isSlots bool, gameId int, param ...string) {
  54. xclient := getClient()
  55. //defer xclient.Close()
  56. roomName := ""
  57. if len(param) > 0 {
  58. roomName = param[0]
  59. }
  60. args := &Request{
  61. UserGold: userGold,
  62. Amount: betAmount,
  63. GameId: gameId,
  64. IsSlots: isSlots,
  65. RoomName: roomName,
  66. }
  67. err := xclient.Call(context.Background(), "AddBet", args, nil)
  68. if err != nil {
  69. log.Debug("waterpool.AddBet failed to call: %v", err)
  70. common.GetClientPool().RemoveClient(ServiceName)
  71. }
  72. }
  73. func ReducePool(userGold int, amount int, isSlots bool, gameId int, param ...string) {
  74. xclient := getClient()
  75. roomName := ""
  76. if len(param) > 0 {
  77. roomName = param[0]
  78. }
  79. args := &Request{
  80. UserGold: userGold,
  81. Amount: amount,
  82. GameId: gameId,
  83. IsSlots: isSlots,
  84. RoomName: roomName,
  85. }
  86. err := xclient.Call(context.Background(), "ReducePool", args, nil)
  87. if err != nil {
  88. log.Debug("waterpool.ReducePool failed to call: %v", err)
  89. common.GetClientPool().RemoveClient(ServiceName)
  90. }
  91. }
  92. func GetControlType(userGold int, isSlots bool, gameId int) int {
  93. xclient := getClient()
  94. //defer xclient.Close()
  95. args := &Request{
  96. UserGold: userGold,
  97. GameId: gameId,
  98. IsSlots: isSlots,
  99. }
  100. reply := &Response{}
  101. err := xclient.Call(context.Background(), "GetControlType", args, reply)
  102. if err != nil {
  103. log.Debug("waterpool.GetControlType failed to call: %v", err)
  104. common.GetClientPool().RemoveClient(ServiceName)
  105. return 0
  106. }
  107. return reply.RetCode
  108. }
  109. func GetControlProb(userGold int, isSlots bool, gameId int, roomName string) (int, int) {
  110. xclient := getClient()
  111. //defer xclient.Close()
  112. args := &Request{
  113. UserGold: userGold,
  114. GameId: gameId,
  115. IsSlots: isSlots,
  116. RoomName: roomName,
  117. }
  118. reply := &Response{}
  119. err := xclient.Call(context.Background(), "GetControlProb", args, reply)
  120. if err != nil {
  121. log.Debug("waterpool.GetControlProb failed to call: %v", err)
  122. common.GetClientPool().RemoveClient(ServiceName)
  123. return 0, 0
  124. }
  125. return reply.WaterType, reply.WaterProb
  126. }