notifyuserofflinelogic.go 1.7 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/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.CONNECT_TYPE_PLAYER:
  29. // 修改玩家在线状态
  30. if ext.Game2PlayerStatusMap.Contains(in.GameId) {
  31. // 有则取出玩家的set
  32. playerStatSet := ext.Game2PlayerStatusMap.Get(in.GameId).(*set.Set)
  33. if playerStatSet.Contains(in.Uid) {
  34. // 有则清除,代表下线
  35. playerStatSet.Erase(in.Uid)
  36. }
  37. }
  38. for n := ext.WaitingQueue.FrontNode(); n != nil; n = n.Next() {
  39. info := n.Value.(*model.PlayerWaitingInfo)
  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.WaitingQueue.Remove(nil, n)
  43. break
  44. }
  45. }
  46. case globalkey.CONNECT_TYPE_CS:
  47. // 修改客服在线状态
  48. csInfo := ext.CsInfoMap.Get(in.Uid).(*model.CsInfo)
  49. csInfo.OnlineStatus = 0
  50. default:
  51. return nil, errors.Wrap(result.NewErrMsg("no such user type"), "")
  52. }
  53. return &pb.NotifyUserStatusResp{}, nil
  54. }