Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions apps/matchmakingserver/service/battleground-queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ type PVPQueue interface {
QueuedGroupByPlayer(player guid.PlayerUnwrapped) *QueuedGroup

GetQueueTypeID() battleground.QueueTypeID

// ProcessBackfill re-runs the queue pass (backfill running battlegrounds,
// then create new ones): without it a slot freed by
// PlayerLeftBattleground is only filled on the next enqueue.
ProcessBackfill(ctx context.Context) error
}

type GenericBattlegroundQueue struct {
Expand All @@ -59,6 +64,12 @@ type GenericBattlegroundQueue struct {
mut sync.RWMutex
queuedGroups map[ /*leaderGUID*/ guid.PlayerUnwrapped]QueuedGroup
playersGroupLeaderByPlayer map[ /*playerGUID*/ guid.PlayerUnwrapped] /*leaderGUID*/ guid.PlayerUnwrapped

// processMut serializes process() runs: group selection happens under a
// read lock and removal only after the invite, so two overlapping runs
// (concurrent enqueues, or a backfill pass racing an enqueue) could
// invite the same queued group twice.
processMut sync.Mutex
}

func NewGenericBattlegroundQueue(service BattleGroundService, battleGroundCreator BattlegroundCreator, template repo.BattlegroundTemplate, realmID, battlegroupID uint32, bracketID uint8) *GenericBattlegroundQueue {
Expand Down Expand Up @@ -144,7 +155,14 @@ func (q *GenericBattlegroundQueue) QueuedGroupByPlayer(player guid.PlayerUnwrapp
return &group
}

func (q *GenericBattlegroundQueue) ProcessBackfill(ctx context.Context) error {
return q.process(ctx)
}
Comment on lines +158 to +160

func (q *GenericBattlegroundQueue) process(ctx context.Context) error {
q.processMut.Lock()
defer q.processMut.Unlock()

battlegroundToFillIn, err := q.battleGroundService.BattlegroundsThatNeedPlayers(
ctx,
q.QueueTypeID,
Expand Down
4 changes: 4 additions & 0 deletions apps/matchmakingserver/service/battleground-random-queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func (b BattlegroundRandomQueue) QueuedGroupByPlayer(player guid.PlayerUnwrapped
return b.realQ.QueuedGroupByPlayer(player)
}

func (b BattlegroundRandomQueue) ProcessBackfill(ctx context.Context) error {
return b.realQ.ProcessBackfill(ctx)
}

func (b BattlegroundRandomQueue) GetQueueTypeID() battleground.QueueTypeID {
return battleground.QueueTypeIDRandomBattleground
}
Expand Down
28 changes: 28 additions & 0 deletions apps/matchmakingserver/service/battleground_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,16 @@ func (s *battleGroundService) PlayerLeftBattleground(ctx context.Context, player
realmKey.RealmID = 0
}

var queueTypeID battleground.QueueTypeID
var bracketID uint8
var battlegroupID uint32
found := false
err := s.battlegroundsRepo.UpdateBattleground(ctx, instanceID, realmKey, func(b *battleground.Battleground) error {
b.RemovePlayer(playerGUID, realmID)
queueTypeID = b.QueueTypeID
bracketID = b.BracketID
battlegroupID = b.BattleGroupID
found = true
return nil
})
if err != nil {
Expand All @@ -636,6 +644,26 @@ func (s *battleGroundService) PlayerLeftBattleground(ctx context.Context, player
BattlegroupID: 0,
}, playerGUID, realmID)

// The freed slot would otherwise only be backfilled on the next enqueue
// into this queue: kick the queue pass so a waiting group is invited
// right away. Async: the caller is the gameserver's leave path.
if found {
if bracketsMap, ok := s.queues[QueueByRealmOrBattlegroupKey{
BattlegroupID: battlegroupID,
RealmID: realmKey.RealmID,
}][queueTypeID]; ok {
if queue, ok := bracketsMap[BracketID(bracketID)]; ok {
go func() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
if err := queue.ProcessBackfill(ctx); err != nil {
log.Err(err).Msg("backfill pass after player left battleground failed")
}
}()
}
}
}

return nil
}

Expand Down
Loading