notifyuserofflinelogic.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. switch in.Type {
  28. case globalkey.ConnectTypePlayer:
  29. // 修改玩家在线状态
  30. if ext.GameOnlinePlayerMap.Contains(in.GameId) {
  31. // 有则取出玩家
  32. onlinePlayerMap := ext.GameOnlinePlayerMap.Get(in.GameId).(*treemap.Map)
  33. if onlinePlayerMap.Contains(in.Uid) {
  34. // 有则清除,代表下线
  35. onlinePlayerMap.Erase(in.Uid)
  36. }
  37. }
  38. for n := ext.WaitingList.FrontNode(); n != nil; n = n.Next() {
  39. info := n.Value.(*model.PlayerInfo)
  40. if info.GameId == in.GameId && info.PlayerId == in.Uid {
  41. l.Logger.Infof("remove the player from the queue, game_id: %s, player_id: %s", in.GameId, in.Uid)
  42. ext.WaitingList.Remove(nil, n)
  43. break
  44. }
  45. }
  46. case globalkey.ConnectTypeCs:
  47. // 修改客服在线状态
  48. if csInfo := ext.GetCsInfo(in.Uid); csInfo != nil {
  49. csInfo.OnlineStatus = 0
  50. } else {
  51. return nil, errors.Wrap(result.NewErrMsg("no such user"), "")
  52. }
  53. default:
  54. return nil, errors.Wrap(result.NewErrMsg("no such user type"), "")
  55. }
  56. return &pb.NotifyUserStatusResp{}, nil
  57. }