playerfetchcsinfologic.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package logic
  2. import (
  3. "context"
  4. treemap "github.com/liyue201/gostl/ds/map"
  5. "github.com/pkg/errors"
  6. "ylink/comm/model"
  7. "ylink/comm/result"
  8. "ylink/core/inner/rpc/internal/ext"
  9. "ylink/core/inner/rpc/internal/svc"
  10. "ylink/core/inner/rpc/pb"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. )
  13. type PlayerFetchCsInfoLogic struct {
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. logx.Logger
  17. }
  18. func NewPlayerFetchCsInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PlayerFetchCsInfoLogic {
  19. return &PlayerFetchCsInfoLogic{
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. Logger: logx.WithContext(ctx),
  23. }
  24. }
  25. func (l *PlayerFetchCsInfoLogic) PlayerFetchCsInfo(in *pb.InnerPlayerFetchCsInfoReq) (*pb.InnerPlayerFetchCsInfoResp, error) {
  26. if ext.GameConnectedMap.Contains(in.GameId) {
  27. playerConnMap := ext.GameConnectedMap.Get(in.GameId).(*treemap.Map)
  28. csId := playerConnMap.Get(in.PlayerId).(string)
  29. if ext.CsInfoMap.Contains(csId) {
  30. csInfo := ext.CsInfoMap.Get(csId).(model.CsInfo)
  31. return &pb.InnerPlayerFetchCsInfoResp{
  32. CsId: csInfo.CsId,
  33. CsNickname: csInfo.CsNickname,
  34. CsAvatarUrl: csInfo.CsAvatarUrl,
  35. CsSignature: csInfo.CsSignature,
  36. OnlineStatus: csInfo.OnlineStatus,
  37. }, nil
  38. }
  39. }
  40. return nil, errors.Wrap(result.NewErrMsg("Customer service information does not exist"), "")
  41. }