user_simplematch.go 4.0 KB

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