user_pointmatch.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. package gatesink
  2. import (
  3. "bet24.com/log"
  4. "bet24.com/servers/fishhall/config"
  5. pointmatch "bet24.com/servers/micros/matches/proto"
  6. "encoding/json"
  7. "fmt"
  8. "strconv"
  9. )
  10. func (this *user) onPointMatchMsg(msg, data string) {
  11. switch msg {
  12. case "createPointMatch":
  13. this.createPointMatch(msg, data)
  14. case "closePointMatch":
  15. this.closePointMatch(msg, data)
  16. case "enrollPointMatch":
  17. this.enrollPointMatch(msg, data)
  18. case "quitPointMatch":
  19. this.quitPointMatch(msg, data)
  20. case "getPointMatchInfo":
  21. this.getPointMatchInfo(msg, data)
  22. case "getMyPointMatches":
  23. this.getMyPointMatches(msg)
  24. case "getPointMatchConfigs":
  25. this.getPointMatchConfigs(msg)
  26. case "getEnrolledPointMatch":
  27. this.getEnrolledPointMatch(msg)
  28. case "getPointMatchHistory":
  29. this.getPointMatchHistory(msg)
  30. }
  31. }
  32. type createPointMatchInfo struct {
  33. GameId int // 游戏ID
  34. GameRule string // 规则名
  35. TotalUser int // 比赛总报名人数
  36. TableUser int // 每桌人数
  37. Fee int // 报名费
  38. Prize int // 奖金
  39. PlayTime int
  40. EliminateScore int
  41. ShrinkSec int
  42. ShrinkScore int
  43. WinnerCount int
  44. }
  45. func (this *user) createPointMatch(msg, data string) {
  46. var req createPointMatchInfo
  47. if err := json.Unmarshal([]byte(data), &req); err != nil {
  48. retData := fmt.Sprintf("user.createPrivateRoom unmarshal data fail %v", err)
  49. log.Release(retData)
  50. this.WriteMsg(msg, retData)
  51. return
  52. }
  53. if this.isGuest() && config.HallConfig.GuestMatchClose > 0 {
  54. this.WriteMsg(msg, "not for guest users")
  55. return
  56. }
  57. roomNo, errMsg := pointmatch.CreatePointMatch(this.getUserId(), req.GameId, req.GameRule, req.TotalUser,
  58. req.TableUser, req.Fee, req.Prize, req.PlayTime, req.EliminateScore, req.ShrinkSec, req.ShrinkScore, req.WinnerCount)
  59. this.WriteMsg(msg, fmt.Sprintf(`{"RoomNo":%d,"ErrMsg":"%s"}`, roomNo, errMsg))
  60. }
  61. func (this *user) closePointMatch(msg, data string) {
  62. matchNo, err := strconv.Atoi(data)
  63. if err != nil {
  64. log.Release("gatesink.closePointMatch %v", err)
  65. this.WriteMsg(msg, "invalid argument")
  66. return
  67. }
  68. retCode, errMsg := pointmatch.ClosePointMatch(this.getUserId(), matchNo)
  69. this.WriteMsg(msg, fmt.Sprintf(`{"RetCode":%d,"ErrMsg":"%s"}`, retCode, errMsg))
  70. }
  71. func (this *user) enrollPointMatch(msg, data string) {
  72. matchNo, err := strconv.Atoi(data)
  73. if err != nil {
  74. log.Release("gatesink.enrollPointMatch %v", err)
  75. this.WriteMsg(msg, "invalid argument")
  76. return
  77. }
  78. if this.isGuest() && config.HallConfig.GuestMatchClose > 0 {
  79. this.WriteMsg(msg, "not for guest users")
  80. return
  81. }
  82. var retInfo struct {
  83. MatchNo int
  84. ErrMsg string
  85. }
  86. retInfo.MatchNo, retInfo.ErrMsg = pointmatch.EnrollPointMatch(this.getUserId(), matchNo,
  87. this.getNickName(), this.getFaceId(), this.getFaceUrl())
  88. d, _ := json.Marshal(retInfo)
  89. this.WriteMsg(msg, string(d))
  90. }
  91. func (this *user) quitPointMatch(msg, data string) {
  92. matchNo, err := strconv.Atoi(data)
  93. if err != nil {
  94. log.Release("gatesink.quitPointMatch %v", err)
  95. this.WriteMsg(msg, "invalid argument")
  96. return
  97. }
  98. ok := pointmatch.QuitPointMatch(this.getUserId(), matchNo)
  99. retData := "success"
  100. if !ok {
  101. retData = "failed"
  102. }
  103. this.WriteMsg(msg, retData)
  104. }
  105. func (this *user) getPointMatchInfo(msg, data string) {
  106. matchNo, err := strconv.Atoi(data)
  107. if err != nil {
  108. log.Release("gatesink.getPointMatchInfo %v", err)
  109. this.WriteMsg(msg, "invalid argument")
  110. return
  111. }
  112. this.WriteMsg(msg, pointmatch.GetPointMatchInfo(matchNo))
  113. }
  114. func (this *user) onPointMatchNotification(data string) {
  115. //log.Release("onPointMatchNotification [%d],%s", this.getUserId(), data)
  116. this.WriteMsg("onPointMatchNotification", data)
  117. }
  118. func (this *user) getMyPointMatches(msg string) {
  119. this.WriteMsg(msg, pointmatch.GetUserPointMatches(this.getUserId()))
  120. }
  121. func (this *user) getPointMatchConfigs(msg string) {
  122. this.WriteMsg(msg, pointmatch.GetPointMatchConfigs())
  123. }
  124. func (this *user) getEnrolledPointMatch(msg string) {
  125. this.WriteMsg(msg, pointmatch.GetEnrolledPointMatch(this.getUserId()))
  126. }
  127. func (this *user) getPointMatchHistory(msg string) {
  128. this.WriteMsg(msg, pointmatch.GetPointMatchHistory(this.getUserId()))
  129. }