notifyuserofflinelogic.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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/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 NotifyUserOfflineLogic struct {
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. logx.Logger
  17. }
  18. func NewNotifyUserOfflineLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NotifyUserOfflineLogic {
  19. return &NotifyUserOfflineLogic{
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. Logger: logx.WithContext(ctx),
  23. }
  24. }
  25. func (l *NotifyUserOfflineLogic) NotifyUserOffline(in *pb.NotifyUserStatusReq) (*pb.NotifyUserStatusResp, error) {
  26. l.Logger.Infof("NotifyUserOffline")
  27. switch in.Type {
  28. case globalkey.ConnectTypeNormalPlayer:
  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. l.Logger.Infof("清除玩家在线状态")
  37. }
  38. }
  39. key := in.GameId + "_" + in.Uid
  40. if ext.WaitingQueue.Contains(key) {
  41. l.Logger.Infof("remove the player from the queue, game_id: %s, player_id: %s", in.GameId, in.Uid)
  42. ext.WaitingQueue.Erase(key)
  43. }
  44. //for n := ext.WaitingList.FrontNode(); n != nil; n = n.Next() {
  45. // info := n.Value.(*model.PlayerInfo)
  46. // l.Logger.Infof("playerInfo: %v", info)
  47. // if info.GameId == in.GameId && info.PlayerId == in.Uid {
  48. // l.Logger.Infof("remove the player from the queue, game_id: %s, player_id: %s", in.GameId, in.Uid)
  49. // ext.WaitingList.Remove(nil, n)
  50. // //TODO 广播客户端更新等待队列信息
  51. // //queueInfo, _ := sonic.MarshalString(map[string]interface{}{
  52. // // "queue_size": 10,
  53. // //})
  54. // //message, _ := sonic.MarshalString(&model.KqCmdMessage{
  55. // // Opt: model.CMD_UPDATE_WAITING_QUEUE,
  56. // // ReceiverId: "all",
  57. // // GameId: in.GameId,
  58. // // Uid: in.Uid,
  59. // // Ext: queueInfo,
  60. // //})
  61. // break
  62. // }
  63. //}
  64. case globalkey.ConnectTypeVipPlayer:
  65. // 修改玩家在线状态
  66. if ext.GameOnlinePlayerMap.Contains(in.GameId) {
  67. // 有则取出玩家
  68. onlinePlayerMap := ext.GameOnlinePlayerMap.Get(in.GameId).(*treemap.Map)
  69. if onlinePlayerMap.Contains(in.Uid) {
  70. // 有则清除,代表下线
  71. onlinePlayerMap.Erase(in.Uid)
  72. l.Logger.Infof("清除玩家在线状态")
  73. }
  74. }
  75. case globalkey.ConnectTypeCs:
  76. // 修改客服在线状态
  77. if csInfo := ext.GetCsInfo(in.Uid); csInfo != nil {
  78. csInfo.OnlineStatus = 0
  79. } else {
  80. return nil, errors.Wrap(result.NewErrMsg("用户不存在"), "")
  81. }
  82. default:
  83. return nil, errors.Wrap(result.NewErrMsg("用户不存在"), "")
  84. }
  85. return &pb.NotifyUserStatusResp{}, nil
  86. }