updateuserstatuslogic.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package logic
  2. import (
  3. "context"
  4. "github.com/liyue201/gostl/ds/set"
  5. "github.com/pkg/errors"
  6. "ylink/comm/globalkey"
  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 UpdateUserStatusLogic struct {
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. logx.Logger
  17. }
  18. func NewUpdateUserStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserStatusLogic {
  19. return &UpdateUserStatusLogic{
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. Logger: logx.WithContext(ctx),
  23. }
  24. }
  25. func (l *UpdateUserStatusLogic) UpdateUserStatus(in *pb.UpdateUserStatusReq) (*pb.UpdateUserStatusResp, error) {
  26. switch in.Type {
  27. case globalkey.CONNECT_TYPE_PLAYER:
  28. // 修改玩家在线状态
  29. if ext.Game2PlayerStatMap.Contains(in.GameId) {
  30. // 有则取出玩家的set
  31. playerStatSet := ext.Game2PlayerStatMap.Get(in.GameId).(*set.Set)
  32. if playerStatSet.Contains(in.Uid) {
  33. // 有则清除,代表下线
  34. playerStatSet.Erase(in.Uid)
  35. } else {
  36. playerStatSet.Insert(in.Uid)
  37. }
  38. } else {
  39. playerStatSet := set.New()
  40. playerStatSet.Insert(in.Uid)
  41. ext.Game2PlayerStatMap.Insert(in.GameId, playerStatSet)
  42. }
  43. case globalkey.CONNECT_TYPE_CS:
  44. // 修改客服在线状态
  45. if ext.CsStatSet.Contains(in.Uid) {
  46. // 有则清除,代表下线
  47. ext.CsStatSet.Erase(in.Uid)
  48. } else {
  49. ext.CsStatSet.Insert(in.Uid)
  50. }
  51. default:
  52. return nil, errors.Wrap(result.NewErrMsg("no such user type"), "")
  53. }
  54. return &pb.UpdateUserStatusResp{}, nil
  55. }