Files
90CNServer/server/internal/services/dnfbridge/joust_scheduler.go
T
hanfuit 645b64fe21 DNF90 服务端与启动器完整源码(含 GM 工具功能增强)
服务端(Go):
- GM 塞背包/带属性装备发放:在线角色推送 op14 增量物品行,背包实时刷新,无需回角色选择界面
- GM 改金币/改等级:去掉在线拒绝,落库后推送 op14 钱包/op37 等级状态,在线实时刷新
- 等级端点统一切换到新版 GMSetCharacterLevel(自带在线刷新)
- 无限/锁死疲劳模式 + 燃烧疲劳:每房间消耗 2 点、打怪与通关经验双倍
- 燃烧疲劳开关时给所有在线角色推送系统提示(op12 mode 0)
- 深渊史诗掉率:GM 全局倍率 + 城镇增益药剂窗口倍率,真实接入掉落结算

启动器(Python/JS):
- 标题栏自绘、窗口 1204x717、禁止拖拽改大小、仅最小化/关闭
- GM 工具:疲劳与燃烧、深渊史诗掉率、拍卖行上架(单一定价对齐)
- 拍卖行上架前端对齐服务端单一价格语义,修复 400 报错
2026-11-04 14:31:55 +08:00

145 lines
4.6 KiB
Go

package dnfbridge
import (
"context"
"strconv"
"time"
dnfjoust "longheng.io/server/internal/modules/dnf/joust"
)
const currentJoustPhaseTimerName = "joust:phase"
func (service *Service) startCurrentJoustScheduler(ctx context.Context) {
if service == nil {
return
}
if err := service.scheduleNextCurrentJoustBoundary(ctx); err != nil {
service.logWarn("schedule joust boundary failed", "error", err)
}
}
func (service *Service) scheduleNextCurrentJoustBoundary(ctx context.Context) error {
queue := service.ensureGameplayTimeQueue()
if queue == nil {
return errGameplayTimeQueueUnavailable
}
now := queue.Now().UTC()
delay := dnfjoust.NextBoundaryAfter(now).Sub(now)
if delay < time.Millisecond {
delay = time.Millisecond
}
return queue.ScheduleAfter(currentJoustPhaseTimerName, delay, func(due time.Time) {
if ctx != nil && ctx.Err() != nil {
return
}
service.handleCurrentJoustBoundary(due.UTC())
if err := service.scheduleNextCurrentJoustBoundary(ctx); err != nil && (ctx == nil || ctx.Err() == nil) {
service.logWarn("reschedule joust boundary failed", "error", err)
}
})
}
func (service *Service) handleCurrentJoustBoundary(now time.Time) {
timeline := dnfjoust.TimelineAt(now)
sessions := service.currentJoustSessionSnapshot()
if len(sessions) == 0 {
return
}
ctx, cancel := context.WithTimeout(context.Background(), 3*createWriteTimeout)
defer cancel()
if timeline.Phase == dnfjoust.PhaseSettled {
accounts := make(map[string]struct{})
for _, session := range sessions {
accounts[service.accountIDForSession(session)] = struct{}{}
}
service.joustOperationMu.Lock()
for accountID := range accounts {
results, err := service.settleCurrentJoustAccount(ctx, accountID, now)
if err != nil {
service.logWarn("joust settlement deferred", "account", accountID, "round", timeline.Round, "error", err)
}
for _, result := range results {
if !result.Won || result.MailID == "" {
continue
}
characterID, parseErr := strconv.ParseUint(result.CharacterID, 10, 16)
if parseErr != nil {
continue
}
if session, found := service.onlineGameSession(uint16(characterID)); found {
if alarmErr := service.sendMailboxAlarmToOnlineRecipient(session.selectedCharacterID); alarmErr != nil {
service.logGameEvent(session, "game-joust-settlement-mail-alarm-deferred", "mail_id", result.MailID, "reason", alarmErr.Error())
}
}
}
}
service.joustOperationMu.Unlock()
}
for _, session := range sessions {
if err := service.pushCurrentJoustBoundarySnapshot(ctx, session, timeline); err != nil {
service.logGameEvent(session, "game-joust-boundary-push-failed", "round", timeline.Round, "phase", timeline.Phase, "reason", err.Error())
}
}
}
func (service *Service) pushCurrentJoustBoundarySnapshot(
ctx context.Context,
session *gameSession,
timeline dnfjoust.Timeline,
) error {
// A state transition is the native animation trigger. In particular, the
// semi-final still uses state 2 but needs a fresh state packet before its
// stage-1 bracket snapshot, otherwise the current EXE paints the outcome
// directly and skips its countdown/battle/horse-flash sequence.
sendState := timeline.Phase == dnfjoust.PhaseBetting ||
timeline.Phase == dnfjoust.PhaseQuarterFinal ||
timeline.Phase == dnfjoust.PhaseSemiFinal ||
(timeline.Phase == dnfjoust.PhaseFinal && timeline.Stage == 2) ||
timeline.Phase == dnfjoust.PhaseSettled
if sendState {
if err := service.sendGameUpperRawClass(session, currentJoustStatePushMsgID, buildCurrentJoustState(timeline), 0); err != nil {
return err
}
}
if timeline.Phase == dnfjoust.PhaseBetting {
return service.sendCurrentJoustOpeningRoster(session)
}
catalog, err := service.currentJoustCatalog(ctx)
if err != nil {
return err
}
tournament, err := catalog.TournamentFor(timeline.Round)
if err != nil {
return err
}
body, err := buildCurrentJoustMatchSnapshot(timeline.Round, timeline.Stage, tournament)
if err != nil {
return err
}
return service.sendGameUpperRawClass(session, currentJoustMatchPushMsgID, body, 0)
}
func (service *Service) currentJoustSessionSnapshot() []*gameSession {
if service == nil {
return nil
}
service.mu.Lock()
defer service.mu.Unlock()
sessions := make([]*gameSession, 0, len(service.gameSessions))
seen := make(map[*gameSession]struct{}, len(service.gameSessions))
for _, session := range service.gameSessions {
if session == nil || session.selectedCharacterID == 0 {
continue
}
if _, duplicate := seen[session]; duplicate {
continue
}
seen[session] = struct{}{}
sessions = append(sessions, session)
}
return sessions
}