feat: 新增PVP匹配队列分组和暗黑门关卡前置检查
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
This commit is contained in:
@@ -21,17 +21,25 @@ type PVPMatchJoinPayload struct {
|
||||
Nick string `json:"nick"`
|
||||
FightMode uint32 `json:"fightMode"`
|
||||
Status uint32 `json:"status"`
|
||||
IsVip uint32 `json:"isVip"`
|
||||
IsDebug uint8 `json:"isDebug"`
|
||||
CatchTimes []uint32 `json:"catchTimes"`
|
||||
}
|
||||
|
||||
type pvpMatchQueueKey struct {
|
||||
FightMode uint32
|
||||
IsVip uint32
|
||||
IsDebug uint8
|
||||
}
|
||||
|
||||
type pvpMatchCoordinator struct {
|
||||
mu sync.Mutex
|
||||
queues map[uint32][]pvpwire.QueuePlayerSnapshot
|
||||
queues map[pvpMatchQueueKey][]pvpwire.QueuePlayerSnapshot
|
||||
lastSeen map[uint32]time.Time
|
||||
}
|
||||
|
||||
var defaultPVPMatchCoordinator = &pvpMatchCoordinator{
|
||||
queues: make(map[uint32][]pvpwire.QueuePlayerSnapshot),
|
||||
queues: make(map[pvpMatchQueueKey][]pvpwire.QueuePlayerSnapshot),
|
||||
lastSeen: make(map[uint32]time.Time),
|
||||
}
|
||||
|
||||
@@ -51,6 +59,8 @@ func (m *pvpMatchCoordinator) JoinOrUpdate(payload PVPMatchJoinPayload) error {
|
||||
Nick: payload.Nick,
|
||||
FightMode: payload.FightMode,
|
||||
Status: payload.Status,
|
||||
IsVip: payload.IsVip,
|
||||
IsDebug: payload.IsDebug,
|
||||
JoinedAtUnix: now.Unix(),
|
||||
CatchTimes: append([]uint32(nil), payload.CatchTimes...),
|
||||
}
|
||||
@@ -62,11 +72,12 @@ func (m *pvpMatchCoordinator) JoinOrUpdate(payload PVPMatchJoinPayload) error {
|
||||
m.removeUserLocked(payload.UserID)
|
||||
m.lastSeen[payload.UserID] = now
|
||||
|
||||
queue := m.queues[payload.FightMode]
|
||||
queueKey := newPVPMatchQueueKey(player)
|
||||
queue := m.queues[queueKey]
|
||||
if len(queue) > 0 {
|
||||
host := queue[0]
|
||||
queue = queue[1:]
|
||||
m.queues[payload.FightMode] = queue
|
||||
m.queues[queueKey] = queue
|
||||
delete(m.lastSeen, host.UserID)
|
||||
delete(m.lastSeen, payload.UserID)
|
||||
|
||||
@@ -79,7 +90,7 @@ func (m *pvpMatchCoordinator) JoinOrUpdate(payload PVPMatchJoinPayload) error {
|
||||
}
|
||||
match = &result
|
||||
} else {
|
||||
m.queues[payload.FightMode] = append(queue, player)
|
||||
m.queues[queueKey] = append(queue, player)
|
||||
}
|
||||
m.mu.Unlock()
|
||||
|
||||
@@ -109,7 +120,7 @@ func (m *pvpMatchCoordinator) Cancel(userID uint32) {
|
||||
}
|
||||
|
||||
func (m *pvpMatchCoordinator) pruneExpiredLocked(now time.Time) {
|
||||
for mode, queue := range m.queues {
|
||||
for key, queue := range m.queues {
|
||||
next := make([]pvpwire.QueuePlayerSnapshot, 0, len(queue))
|
||||
for _, queued := range queue {
|
||||
last := m.lastSeen[queued.UserID]
|
||||
@@ -119,12 +130,12 @@ func (m *pvpMatchCoordinator) pruneExpiredLocked(now time.Time) {
|
||||
}
|
||||
next = append(next, queued)
|
||||
}
|
||||
m.queues[mode] = next
|
||||
m.queues[key] = next
|
||||
}
|
||||
}
|
||||
|
||||
func (m *pvpMatchCoordinator) removeUserLocked(userID uint32) {
|
||||
for mode, queue := range m.queues {
|
||||
for key, queue := range m.queues {
|
||||
next := make([]pvpwire.QueuePlayerSnapshot, 0, len(queue))
|
||||
for _, queued := range queue {
|
||||
if queued.UserID == userID {
|
||||
@@ -132,7 +143,15 @@ func (m *pvpMatchCoordinator) removeUserLocked(userID uint32) {
|
||||
}
|
||||
next = append(next, queued)
|
||||
}
|
||||
m.queues[mode] = next
|
||||
m.queues[key] = next
|
||||
}
|
||||
}
|
||||
|
||||
func newPVPMatchQueueKey(player pvpwire.QueuePlayerSnapshot) pvpMatchQueueKey {
|
||||
return pvpMatchQueueKey{
|
||||
FightMode: player.FightMode,
|
||||
IsVip: player.IsVip,
|
||||
IsDebug: player.IsDebug,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user