storm.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. package v1
  2. import (
  3. "go-common/app/interface/live/lottery-interface/internal/service"
  4. xlottery "go-common/app/service/live/xlottery/api/grpc/v1"
  5. "go-common/library/log"
  6. "go-common/library/log/infoc"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/metadata"
  9. "net/http"
  10. "time"
  11. "go-common/library/net/http/blademaster/render"
  12. )
  13. //StormJoin StormJoin
  14. func StormJoin(c *bm.Context) {
  15. p := new(xlottery.JoinStormReq)
  16. if err := c.Bind(p); err != nil {
  17. c.JSON(nil, err)
  18. return
  19. }
  20. // if p.GetRoomid() == 0 {
  21. // c.Render(http.StatusOK, render.MapJSON{
  22. // "code": 400,
  23. // "msg": "参数错误",
  24. // })
  25. // return
  26. // }
  27. mid, _ := c.Get("mid")
  28. platform := c.Request.URL.Query().Get("platform")
  29. if platform == "" {
  30. platform = "web"
  31. }
  32. if p.Platform == "" {
  33. p.Platform = platform
  34. }
  35. log.Info("mid:%s platform:%s", mid, platform)
  36. p.Mid = mid.(int64)
  37. //反作弊打点
  38. lancer(c, p)
  39. resp, err := service.ServiceInstance.StormClient.Join(c, p)
  40. if err != nil {
  41. c.Render(http.StatusOK, render.MapJSON{
  42. "code": 400,
  43. "msg": "没抢到",
  44. "data": []int{},
  45. })
  46. return
  47. }
  48. switch resp.GetCode() {
  49. case 1005002:
  50. c.Render(http.StatusOK, render.MapJSON{
  51. "code": 429,
  52. "msg": resp.GetMsg(),
  53. })
  54. return
  55. case 1005001:
  56. c.Render(http.StatusOK, render.MapJSON{
  57. "code": 401,
  58. "msg": resp.GetMsg(),
  59. })
  60. return
  61. case 1005003, 1005004, 1005005, 1005016:
  62. c.Render(http.StatusOK, render.MapJSON{
  63. "code": 400,
  64. "msg": resp.GetMsg(),
  65. })
  66. return
  67. case 0:
  68. c.JSON(resp.GetJoin(), nil)
  69. return
  70. default:
  71. c.Render(http.StatusOK, render.MapJSON{
  72. "code": int(resp.GetCode()),
  73. "msg": resp.GetMsg(),
  74. })
  75. }
  76. }
  77. // StormCheck StormCheck 检查
  78. func StormCheck(c *bm.Context) {
  79. p := new(xlottery.CheckStormReq)
  80. if err := c.Bind(p); err != nil {
  81. c.JSON(nil, err)
  82. return
  83. }
  84. mid, isexit := c.Get("mid")
  85. if isexit {
  86. p.Uid = mid.(int64)
  87. log.Info("StormCheck uid = %s", mid)
  88. }
  89. resp, err := service.ServiceInstance.StormClient.Check(c, p)
  90. if err != nil {
  91. c.JSON(nil, err)
  92. return
  93. }
  94. if resp.GetCheck() != nil {
  95. c.JSON(resp.GetCheck(), nil)
  96. return
  97. }
  98. c.Render(http.StatusOK, render.MapJSON{
  99. "code": 0,
  100. "msg": "",
  101. "data": []int{},
  102. })
  103. }
  104. var lacnertype = "rhythmic"
  105. func lancer(c *bm.Context, req *xlottery.JoinStormReq) {
  106. uid := req.GetMid()
  107. roomid := req.GetRoomid()
  108. lotteryid := req.GetId()
  109. action := "join"
  110. ip := metadata.String(c, metadata.RemoteIP)
  111. ts := time.Now().Unix()
  112. platform := req.GetPlatform()
  113. clientver := c.Request.URL.Query().Get("version")
  114. buvid := c.Request.Header.Get("Buvid")
  115. ua := c.Request.Header.Get("User-Agent")
  116. referer := c.Request.Header.Get("Referer")
  117. cookie := getCookie(c.Request)
  118. abnoormal := 0
  119. requesturi := c.Request.RequestURI
  120. err := service.ServiceInstance.Infoc.Info(
  121. uid,
  122. roomid,
  123. lacnertype,
  124. lotteryid,
  125. action,
  126. ip,
  127. ts,
  128. platform,
  129. clientver,
  130. buvid,
  131. ua,
  132. referer,
  133. cookie,
  134. abnoormal,
  135. requesturi)
  136. if err != nil {
  137. if err != infoc.ErrFull {
  138. log.Error("Infoc.Info err: %s", err.Error())
  139. }
  140. }
  141. }
  142. func getCookie(req *http.Request) string {
  143. var cookie string
  144. for _, v := range req.Cookies() {
  145. if v.Name != "SESSDATA" {
  146. cookie = cookie + v.Name + "=" + v.Value + "; "
  147. }
  148. }
  149. return cookie
  150. }