notifyuserofflinelogic.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package logic
  2. import (
  3. "context"
  4. treemap "github.com/liyue201/gostl/ds/map"
  5. "github.com/pkg/errors"
  6. "ylink/comm/globalkey"
  7. "ylink/comm/model"
  8. "ylink/comm/result"
  9. "ylink/core/inner/rpc/internal/ext"
  10. "ylink/core/inner/rpc/internal/svc"
  11. "ylink/core/inner/rpc/pb"
  12. "github.com/zeromicro/go-zero/core/logx"
  13. )
  14. type NotifyUserOfflineLogic struct {
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. logx.Logger
  18. }
  19. func NewNotifyUserOfflineLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NotifyUserOfflineLogic {
  20. return &NotifyUserOfflineLogic{
  21. ctx: ctx,
  22. svcCtx: svcCtx,
  23. Logger: logx.WithContext(ctx),
  24. }
  25. }
  26. func (l *NotifyUserOfflineLogic) NotifyUserOffline(in *pb.NotifyUserStatusReq) (*pb.NotifyUserStatusResp, error) {
  27. l.Logger.Infof("NotifyUserOffline")
  28. switch in.Type {
  29. case globalkey.ConnectTypePlayer:
  30. // 修改玩家在线状态
  31. if ext.GameOnlinePlayerMap.Contains(in.GameId) {
  32. // 有则取出玩家
  33. onlinePlayerMap := ext.GameOnlinePlayerMap.Get(in.GameId).(*treemap.Map)
  34. if onlinePlayerMap.Contains(in.Uid) {
  35. // 有则清除,代表下线
  36. onlinePlayerMap.Erase(in.Uid)
  37. l.Logger.Infof("清除玩家在线状态")
  38. }
  39. }
  40. go func() {
  41. for n := ext.WaitingList.FrontNode(); n != nil; n = n.Next() {
  42. info := n.Value.(*model.PlayerInfo)
  43. if info.GameId == in.GameId && info.PlayerId == in.Uid {
  44. l.Logger.Infof("remove the player from the queue, game_id: %s, player_id: %s", in.GameId, in.Uid)
  45. ext.WaitingList.Remove(nil, n)
  46. break
  47. }
  48. }
  49. }()
  50. case globalkey.ConnectTypeCs:
  51. // 修改客服在线状态
  52. if csInfo := ext.GetCsInfo(in.Uid); csInfo != nil {
  53. csInfo.OnlineStatus = 0
  54. } else {
  55. return nil, errors.Wrap(result.NewErrMsg("no such user"), "")
  56. }
  57. default:
  58. return nil, errors.Wrap(result.NewErrMsg("no such user type"), "")
  59. }
  60. return &pb.NotifyUserStatusResp{}, nil
  61. }