user_sngmatch.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package gatesink
  2. import (
  3. "bet24.com/log"
  4. sngmatch "bet24.com/servers/micros/matches/proto"
  5. "encoding/json"
  6. "fmt"
  7. "strconv"
  8. )
  9. func (this *user) onSngMatchMsg(msg, data string) {
  10. switch msg {
  11. case "enrollSngMatch":
  12. this.enrollSngMatch(msg, data)
  13. case "quitSngMatch":
  14. this.quitSngMatch(msg, data)
  15. case "getSngMatchList":
  16. this.getSngMatchList(msg, data)
  17. case "getSngMatchHistory":
  18. this.getSngMatchHistory(msg, data)
  19. case "getUserSngMatchId":
  20. this.getUserSngMatchId(msg, data)
  21. }
  22. }
  23. type enrollSngMatchReq struct {
  24. MatchId int
  25. FeeIndex int
  26. }
  27. func (this *user) enrollSngMatch(msg, data string) {
  28. var req enrollSngMatchReq
  29. if err := json.Unmarshal([]byte(data), &req); err != nil {
  30. retData := fmt.Sprintf("user.enrollSngMatch unmarshal data fail %v", err)
  31. log.Release(retData)
  32. this.WriteMsg(msg, retData)
  33. return
  34. }
  35. var retInfo struct {
  36. MatchNo int
  37. ErrMsg string
  38. }
  39. retInfo.MatchNo, retInfo.ErrMsg = sngmatch.EnrollSngMatch(this.getUserId(), req.MatchId, this.getNickName(), this.getFaceId(), this.getFaceUrl(), req.FeeIndex)
  40. d, _ := json.Marshal(retInfo)
  41. this.WriteMsg(msg, string(d))
  42. }
  43. func (this *user) quitSngMatch(msg, data string) {
  44. matchId, err := strconv.Atoi(data)
  45. if err != nil {
  46. log.Release("gatesink.quitSngMatch %v", err)
  47. this.WriteMsg(msg, "invalid argument")
  48. return
  49. }
  50. ok := sngmatch.QuitSngMatch(this.getUserId(), matchId)
  51. retData := "success"
  52. if !ok {
  53. retData = "failed"
  54. }
  55. this.WriteMsg(msg, retData)
  56. }
  57. func (this *user) getSngMatchList(msg, data string) {
  58. d := sngmatch.GetSngMatchList(this.getUserId())
  59. //log.Release("getSngMatchHistory %d data = %s", this.getUserId(), d)
  60. this.WriteMsg(msg, d)
  61. }
  62. func (this *user) getSngMatchHistory(msg, data string) {
  63. this.WriteMsg(msg, sngmatch.GetSngMatchHistory(this.getUserId()))
  64. }
  65. func (this *user) getUserSngMatchId(msg, data string) {
  66. this.WriteMsg(msg, fmt.Sprintf("%d", sngmatch.GetUserSngMatchId(this.getUserId())))
  67. }