DNF90 服务端与启动器完整源码(含 GM 工具功能增强)
服务端(Go): - GM 塞背包/带属性装备发放:在线角色推送 op14 增量物品行,背包实时刷新,无需回角色选择界面 - GM 改金币/改等级:去掉在线拒绝,落库后推送 op14 钱包/op37 等级状态,在线实时刷新 - 等级端点统一切换到新版 GMSetCharacterLevel(自带在线刷新) - 无限/锁死疲劳模式 + 燃烧疲劳:每房间消耗 2 点、打怪与通关经验双倍 - 燃烧疲劳开关时给所有在线角色推送系统提示(op12 mode 0) - 深渊史诗掉率:GM 全局倍率 + 城镇增益药剂窗口倍率,真实接入掉落结算 启动器(Python/JS): - 标题栏自绘、窗口 1204x717、禁止拖拽改大小、仅最小化/关闭 - GM 工具:疲劳与燃烧、深渊史诗掉率、拍卖行上架(单一定价对齐) - 拍卖行上架前端对齐服务端单一价格语义,修复 400 报错
This commit is contained in:
commit
645b64fe21
4388 files changed
+1405457
No files matched your search
@@ -0,0 +1,139 @@
|
||||
package notice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"longheng.io/server/internal/platform/eventlog"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultPublishStream = "notice.publish"
|
||||
defaultPubEventType = "notice.published"
|
||||
)
|
||||
|
||||
type publishEventPayload struct {
|
||||
Notice Notice `json:"notice"`
|
||||
Deliveries []Delivery `json:"deliveries,omitempty"`
|
||||
IdempotencyKey string `json:"idempotency_key"`
|
||||
AdminReceiptID string `json:"admin_receipt_id,omitempty"`
|
||||
Meta map[string]string `json:"meta,omitempty"`
|
||||
PublishedAt time.Time `json:"published_at"`
|
||||
}
|
||||
|
||||
func (s Service) lookupPublishEvent(ctx context.Context, request PublishRequest) (PublishResult, bool, error) {
|
||||
if s.EventLog == nil {
|
||||
return PublishResult{}, false, nil
|
||||
}
|
||||
event, ok, err := s.EventLog.GetByIdempotencyKey(ctx, publishEventKey(request.Notice.ID, request.IdempotencyKey))
|
||||
if err != nil || !ok {
|
||||
return PublishResult{}, false, err
|
||||
}
|
||||
result, err := publishResultEvent(event)
|
||||
if err != nil {
|
||||
return PublishResult{}, false, err
|
||||
}
|
||||
if publishReplayClash(result, request) {
|
||||
return PublishResult{}, false, ErrIdempotencyConflict
|
||||
}
|
||||
result.Duplicate = true
|
||||
return result, true, nil
|
||||
}
|
||||
|
||||
func (s Service) appendPublishEvent(ctx context.Context, result PublishResult) error {
|
||||
if s.EventLog == nil {
|
||||
return nil
|
||||
}
|
||||
payload, err := json.Marshal(payloadFromResult(result))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = s.EventLog.Append(ctx, eventlog.Event{
|
||||
ID: publishEventID(result.Notice.ID, result.IdempotencyKey),
|
||||
Stream: s.publishEventStream(),
|
||||
Type: s.publishEventType(),
|
||||
AggregateID: result.Notice.ID,
|
||||
IdempotencyKey: publishEventKey(result.Notice.ID, result.IdempotencyKey),
|
||||
Payload: payload,
|
||||
Headers: map[string]string{
|
||||
"notice_id": result.Notice.ID,
|
||||
"kind": result.Notice.Kind,
|
||||
"recipient_count": strconv.Itoa(len(result.Deliveries)),
|
||||
"admin_receipt_id": result.AdminReceiptID,
|
||||
},
|
||||
})
|
||||
if errors.Is(err, eventlog.ErrIdempotencyConflict) {
|
||||
return ErrIdempotencyConflict
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s Service) publishEventStream() string {
|
||||
if stream := strings.TrimSpace(s.EventLogStream); stream != "" {
|
||||
return stream
|
||||
}
|
||||
return defaultPublishStream
|
||||
}
|
||||
|
||||
func (s Service) publishEventType() string {
|
||||
if typ := strings.TrimSpace(s.EventLogType); typ != "" {
|
||||
return typ
|
||||
}
|
||||
return defaultPubEventType
|
||||
}
|
||||
|
||||
func payloadFromResult(result PublishResult) publishEventPayload {
|
||||
return publishEventPayload{
|
||||
Notice: cloneNotice(result.Notice),
|
||||
Deliveries: cloneDeliveries(result.Deliveries),
|
||||
IdempotencyKey: result.IdempotencyKey,
|
||||
AdminReceiptID: result.AdminReceiptID,
|
||||
Meta: cloneStringMap(result.Meta),
|
||||
PublishedAt: result.PublishedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func publishResultEvent(event eventlog.Event) (PublishResult, error) {
|
||||
var payload publishEventPayload
|
||||
if err := json.Unmarshal(event.Payload, &payload); err != nil {
|
||||
return PublishResult{}, err
|
||||
}
|
||||
return PublishResult{
|
||||
Accepted: true,
|
||||
Notice: cloneNotice(payload.Notice),
|
||||
Deliveries: cloneDeliveries(payload.Deliveries),
|
||||
IdempotencyKey: firstNonEmpty(payload.IdempotencyKey, event.IdempotencyKey),
|
||||
AdminReceiptID: payload.AdminReceiptID,
|
||||
Meta: cloneStringMap(payload.Meta),
|
||||
PublishedAt: payload.PublishedAt,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func publishEventKey(noticeID, key string) string {
|
||||
noticeID = strings.TrimSpace(noticeID)
|
||||
key = strings.TrimSpace(key)
|
||||
if noticeID == "" || key == "" {
|
||||
return ""
|
||||
}
|
||||
return strings.Join([]string{"notice", "publish", "v1", encodeEventKeyPart(noticeID), encodeEventKeyPart(key)}, ":")
|
||||
}
|
||||
|
||||
func encodeEventKeyPart(value string) string {
|
||||
value = strings.TrimSpace(value)
|
||||
if value == "" {
|
||||
return "_"
|
||||
}
|
||||
return base64.RawURLEncoding.EncodeToString([]byte(value))
|
||||
}
|
||||
|
||||
func publishEventID(noticeID, key string) string {
|
||||
sum := sha256.Sum256([]byte(publishEventKey(noticeID, key)))
|
||||
return "notice-publish-" + hex.EncodeToString(sum[:8])
|
||||
}
|
||||
Reference in new issue
Block a user