csconnectplayerlogic.go 1021 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package logic
  2. import (
  3. "context"
  4. treemap "github.com/liyue201/gostl/ds/map"
  5. "ylink/core/inner/rpc/internal/ext"
  6. "ylink/core/inner/rpc/internal/svc"
  7. "ylink/core/inner/rpc/pb"
  8. "github.com/zeromicro/go-zero/core/logx"
  9. )
  10. type CsConnectPlayerLogic struct {
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. logx.Logger
  14. }
  15. func NewCsConnectPlayerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CsConnectPlayerLogic {
  16. return &CsConnectPlayerLogic{
  17. ctx: ctx,
  18. svcCtx: svcCtx,
  19. Logger: logx.WithContext(ctx),
  20. }
  21. }
  22. func (l *CsConnectPlayerLogic) CsConnectPlayer(in *pb.InnerCsConnectPlayerReq) (*pb.InnerCsConnectPlayerResp, error) {
  23. if ext.GameConnMap.Contains(in.GameId) {
  24. playerConnMap := ext.GameConnMap.Get(in.GameId).(*treemap.Map)
  25. playerConnMap.Insert(in.PlayerId, in.CsId)
  26. } else {
  27. playerConnMap := treemap.New(treemap.WithGoroutineSafe())
  28. playerConnMap.Insert(in.PlayerId, in.CsId)
  29. ext.GameConnMap.Insert(in.GameId, playerConnMap)
  30. }
  31. return &pb.InnerCsConnectPlayerResp{}, nil
  32. }