singlematch.pb.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package proto
  2. import (
  3. "bet24.com/log"
  4. "bet24.com/servers/micros/common"
  5. item "bet24.com/servers/micros/item_inventory/proto"
  6. "context"
  7. )
  8. type SingleMatchRoundInfo struct {
  9. Index int // 轮次
  10. TotalUser int // 总人数
  11. Prize []item.ItemPack // 晋级奖励
  12. }
  13. type SingleMatchInfo struct {
  14. MatchId int
  15. UserId int // 谁的比赛
  16. EndTime int64
  17. StartTime int64
  18. RoundIndex int
  19. UserScore int
  20. Revived bool
  21. Rank int
  22. RoundInfo []SingleMatchRoundInfo
  23. WinCount int
  24. LoseCount int
  25. ReviveCost item.ItemPack // 处于复活状态,复活cost
  26. ReviveSecs int // 复活剩余秒数
  27. }
  28. type SingleMatch_req struct {
  29. Request
  30. MatchId int
  31. }
  32. type SingleMatch_resp struct {
  33. Success bool
  34. ErrorMsg string
  35. MatchData *SingleMatchInfo
  36. }
  37. func CreateUserSingleMatch(userId int, matchId int) (string, *SingleMatchInfo) {
  38. var req SingleMatch_req
  39. req.UserId = userId
  40. req.MatchId = matchId
  41. reply := &SingleMatch_resp{}
  42. err := getClient().Call(context.Background(), "CreateUserSingleMatch", &req, reply)
  43. if err != nil {
  44. log.Debug("matches.CreateUserSingleMatch failed to call: %v", err)
  45. common.GetClientPool().RemoveClient(ServiceName)
  46. return "server error", nil
  47. }
  48. return reply.ErrorMsg, reply.MatchData
  49. }
  50. func GetUserSingleMatch(userId int) *SingleMatchInfo {
  51. var req SingleMatch_req
  52. req.UserId = userId
  53. reply := &SingleMatch_resp{}
  54. err := getClient().Call(context.Background(), "GetUserSingleMatch", &req, reply)
  55. if err != nil {
  56. log.Debug("matches.GetUserSingleMatch failed to call: %v", err)
  57. common.GetClientPool().RemoveClient(ServiceName)
  58. return nil
  59. }
  60. return reply.MatchData
  61. }
  62. func GetSingleMatchList() string {
  63. var req SingleMatch_req
  64. reply := &SingleMatch_resp{}
  65. err := getClient().Call(context.Background(), "GetSingleMatchList", &req, reply)
  66. if err != nil {
  67. log.Debug("matches.GetSingleMatchList failed to call: %v", err)
  68. common.GetClientPool().RemoveClient(ServiceName)
  69. return ""
  70. }
  71. return reply.ErrorMsg
  72. }
  73. func SingleMatchRevive(userId int, giveup bool) bool {
  74. var req SingleMatch_req
  75. req.UserId = userId
  76. reply := &SingleMatch_resp{}
  77. method := "SingleMatchRevive"
  78. if giveup {
  79. method = "SingleMatchNoRevive"
  80. }
  81. err := getClient().Call(context.Background(), method, &req, reply)
  82. if err != nil {
  83. log.Debug("matches.%s failed to call: %v", method, err)
  84. common.GetClientPool().RemoveClient(ServiceName)
  85. return false
  86. }
  87. return reply.Success
  88. }