playerfetchcsinfologic.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package logic
  2. import (
  3. "context"
  4. "github.com/pkg/errors"
  5. "ylink/comm/result"
  6. "ylink/core/inner/rpc/internal/ext"
  7. "ylink/core/inner/rpc/internal/svc"
  8. "ylink/core/inner/rpc/pb"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type PlayerFetchCsInfoLogic struct {
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. logx.Logger
  15. }
  16. func NewPlayerFetchCsInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PlayerFetchCsInfoLogic {
  17. return &PlayerFetchCsInfoLogic{
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. Logger: logx.WithContext(ctx),
  21. }
  22. }
  23. func (l *PlayerFetchCsInfoLogic) PlayerFetchCsInfo(in *pb.InnerPlayerFetchCsInfoReq) (*pb.InnerPlayerFetchCsInfoResp, error) {
  24. if playerInfo := ext.GetConnectedPlayerInfo(in.GameId, in.PlayerId); playerInfo != nil {
  25. // 玩家已连接
  26. if csInfo := ext.GetCsInfo(playerInfo.CsId); csInfo != nil {
  27. return &pb.InnerPlayerFetchCsInfoResp{
  28. CsId: csInfo.CsId,
  29. CsNickname: csInfo.CsNickname,
  30. CsAvatarUrl: csInfo.CsAvatarUrl,
  31. CsSignature: csInfo.CsSignature,
  32. OnlineStatus: csInfo.OnlineStatus,
  33. }, nil
  34. }
  35. return nil, errors.Wrap(result.NewErrMsg("Customer service information does not exist"), "")
  36. }
  37. return nil, errors.Wrap(result.NewErrMsg("The player is not connected"), "")
  38. }