更新说明
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

This commit is contained in:
xinian
2026-04-09 13:11:59 +08:00
parent 487ee0e726
commit d2cd601802
6 changed files with 442 additions and 24 deletions

View File

@@ -4,6 +4,7 @@
package controller
import (
"blazing/common/rpc"
"blazing/cool"
"blazing/logic/service/common"
"bytes"
@@ -29,6 +30,10 @@ type Controller struct {
Kick func(uint32) error
RegisterLogic func(uint32, uint32) error
MatchJoinOrUpdate func(rpc.PVPMatchJoinPayload) error
MatchCancel func(uint32) error
}
}

View File

@@ -1,6 +1,7 @@
package controller
import (
"blazing/common/rpc"
"blazing/common/socket/errorcode"
"blazing/logic/service/common"
"blazing/logic/service/fight"
@@ -21,11 +22,35 @@ func (h Controller) JoINtop(data *PetTOPLEVELnboundInfo, c *player.Player) (resu
if err != 0 {
return nil, err
}
if Maincontroller.RPCClient == nil || Maincontroller.RPCClient.MatchJoinOrUpdate == nil {
pvp.CancelPeakQueue(c)
return nil, errorcode.ErrorCodes.ErrSystemBusyTryLater
}
fightMode, status, err := pvp.NormalizePeakMode(data.Mode)
if err != 0 {
pvp.CancelPeakQueue(c)
return nil, err
}
joinPayload := rpc.PVPMatchJoinPayload{
RuntimeServerID: h.UID,
UserID: c.Info.UserID,
Nick: c.Info.Nick,
FightMode: fightMode,
Status: status,
CatchTimes: pvp.AvailableCatchTimes(c.GetPetInfo(0)),
}
if callErr := Maincontroller.RPCClient.MatchJoinOrUpdate(joinPayload); callErr != nil {
pvp.CancelPeakQueue(c)
return nil, errorcode.ErrorCodes.ErrSystemBusyTryLater
}
return nil, -1
}
// CancelPeakQueue 处理控制器请求。
func (h Controller) CancelPeakQueue(data *PeakQueueCancelInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
if Maincontroller.RPCClient != nil && Maincontroller.RPCClient.MatchCancel != nil {
_ = Maincontroller.RPCClient.MatchCancel(c.Info.UserID)
}
pvp.CancelPeakQueue(c)
return nil, -1
}

View File

@@ -92,28 +92,8 @@ func JoinPeakQueue(p *player.Player, requestedMode uint32) errorcode.ErrorCode {
return err
}
m := Default()
runtimeServerID := localRuntimeServerID()
ticket := &localQueueTicket{
playerID: p.Info.UserID,
runtimeServerID: runtimeServerID,
fightMode: fightMode,
status: status,
stop: make(chan struct{}),
}
m.mu.Lock()
if old := m.localQueues[p.Info.UserID]; old != nil {
old.Stop()
}
m.localQueues[p.Info.UserID] = ticket
delete(m.userSession, p.Info.UserID)
m.mu.Unlock()
p.Fightinfo.Mode = fightMode
p.Fightinfo.Status = status
go m.queueHeartbeatLoop(p, ticket)
return 0
}
@@ -129,15 +109,19 @@ func CancelPeakQueue(p *player.Player) {
m.mu.Unlock()
if ticket != nil {
ticket.Stop()
_ = publishServerMessage(pvpwire.CoordinatorTopicPrefix, pvpwire.MessageTypeQueueCancel, pvpwire.QueueCancelPayload{
RuntimeServerID: ticket.runtimeServerID,
UserID: ticket.playerID,
})
}
atomic.StoreUint32(&p.Fightinfo.Mode, 0)
atomic.StoreUint32(&p.Fightinfo.Status, 0)
}
func NormalizePeakMode(requested uint32) (fightMode uint32, status uint32, err errorcode.ErrorCode) {
return normalizePeakMode(requested)
}
func AvailableCatchTimes(pets []model.PetInfo) []uint32 {
return filterAvailableCatchTimes(pets)
}
func SubmitBanPick(p *player.Player, selected, banned []uint32) errorcode.ErrorCode {
if p == nil {
return errorcode.ErrorCodes.ErrSystemBusyTryLater