user_combomatch.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package gatesink
  2. import (
  3. "bet24.com/log"
  4. combomatch "bet24.com/servers/micros/matches/proto"
  5. "encoding/json"
  6. "fmt"
  7. "strconv"
  8. )
  9. func (this *user) onComboMatchMsg(msg, data string) {
  10. switch msg {
  11. case "enrollComboMatch":
  12. this.enrollComboMatch(msg, data)
  13. case "quitComboMatch":
  14. this.quitComboMatch(msg, data)
  15. case "getComboMatchList":
  16. this.getComboMatchList(msg, data)
  17. case "getComboMatchHistory":
  18. this.getComboMatchHistory(msg, data)
  19. case "getUserComboMatchId":
  20. this.getUserComboMatchId(msg, data)
  21. case "getComboMatchInfo":
  22. this.getComboMatchInfo(msg, data)
  23. case "getComboMatchConfirmCount":
  24. this.getComboMatchConfirmCount(msg, data)
  25. case "confirmComboMatch":
  26. this.confirmComboMatch(msg, data)
  27. }
  28. }
  29. type enrollComboMatchReq struct {
  30. MatchId int
  31. FeeIndex int
  32. }
  33. func (this *user) enrollComboMatch(msg, data string) {
  34. var req enrollComboMatchReq
  35. if err := json.Unmarshal([]byte(data), &req); err != nil {
  36. retData := fmt.Sprintf("user.enrollComboMatch unmarshal data fail %v", err)
  37. log.Release(retData)
  38. this.WriteMsg(msg, retData)
  39. return
  40. }
  41. var retInfo struct {
  42. MatchNo int
  43. ErrMsg string
  44. }
  45. retInfo.MatchNo, retInfo.ErrMsg = combomatch.EnrollComboMatch(this.getUserId(), req.MatchId, this.getNickName(), this.getFaceId(), this.getFaceUrl(), req.FeeIndex)
  46. d, _ := json.Marshal(retInfo)
  47. this.WriteMsg(msg, string(d))
  48. }
  49. func (this *user) quitComboMatch(msg, data string) {
  50. matchId, err := strconv.Atoi(data)
  51. if err != nil {
  52. log.Release("gatesink.quitComboMatch %v", err)
  53. this.WriteMsg(msg, "invalid argument")
  54. return
  55. }
  56. ok := combomatch.QuitComboMatch(this.getUserId(), matchId)
  57. retData := "success"
  58. if !ok {
  59. retData = "failed"
  60. }
  61. this.WriteMsg(msg, retData)
  62. }
  63. func (this *user) getComboMatchList(msg, data string) {
  64. d := combomatch.GetComboMatchList(this.getUserId())
  65. //log.Release("getComboMatchHistory %d data = %s", this.getUserId(), d)
  66. this.WriteMsg(msg, d)
  67. }
  68. func (this *user) getComboMatchHistory(msg, data string) {
  69. this.WriteMsg(msg, combomatch.GetComboMatchHistory(this.getUserId()))
  70. }
  71. func (this *user) getUserComboMatchId(msg, data string) {
  72. this.WriteMsg(msg, combomatch.GetUserComboMatchId(this.getUserId()))
  73. }
  74. func (this *user) getComboMatchInfo(msg, data string) {
  75. matchId, err := strconv.Atoi(data)
  76. if err != nil {
  77. log.Release("gatesink.quitComboMatch %v", err)
  78. this.WriteMsg(msg, "invalid argument")
  79. return
  80. }
  81. d := combomatch.GetComboMatchInfo(matchId, this.getUserId())
  82. //log.Release("getComboMatchHistory %d data = %s", this.getUserId(), d)
  83. this.WriteMsg(msg, d)
  84. }
  85. func (this *user) getComboMatchConfirmCount(msg, data string) {
  86. matchId, err := strconv.Atoi(data)
  87. if err != nil {
  88. log.Release("gatesink.getComboMatchConfirmCount %v", err)
  89. this.WriteMsg(msg, "invalid argument")
  90. return
  91. }
  92. count := combomatch.GetComboMatchConfirmCount(matchId)
  93. this.WriteMsg(msg, fmt.Sprintf("%d", count))
  94. }
  95. func (this *user) confirmComboMatch(msg, data string) {
  96. matchId, err := strconv.Atoi(data)
  97. if err != nil {
  98. log.Release("gatesink.confirmComboMatch %v", err)
  99. this.WriteMsg(msg, "invalid argument")
  100. return
  101. }
  102. if combomatch.ComboMatchConfirm(matchId, this.getUserId()) {
  103. this.WriteMsg(msg, "success")
  104. } else {
  105. this.WriteMsg(msg, "failed")
  106. }
  107. }