服务端(Go): - GM 塞背包/带属性装备发放:在线角色推送 op14 增量物品行,背包实时刷新,无需回角色选择界面 - GM 改金币/改等级:去掉在线拒绝,落库后推送 op14 钱包/op37 等级状态,在线实时刷新 - 等级端点统一切换到新版 GMSetCharacterLevel(自带在线刷新) - 无限/锁死疲劳模式 + 燃烧疲劳:每房间消耗 2 点、打怪与通关经验双倍 - 燃烧疲劳开关时给所有在线角色推送系统提示(op12 mode 0) - 深渊史诗掉率:GM 全局倍率 + 城镇增益药剂窗口倍率,真实接入掉落结算 启动器(Python/JS): - 标题栏自绘、窗口 1204x717、禁止拖拽改大小、仅最小化/关闭 - GM 工具:疲劳与燃烧、深渊史诗掉率、拍卖行上架(单一定价对齐) - 拍卖行上架前端对齐服务端单一价格语义,修复 400 报错
62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
package httpx
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
)
|
|
|
|
// DecodeStrictJSON 读取单个 JSON 请求体,统一限制大小、拒绝未知字段并检查尾部多余 JSON。
|
|
func DecodeStrictJSON(w http.ResponseWriter, r *http.Request, maxBytes int64, out any) error {
|
|
if r == nil || r.Body == nil {
|
|
return errors.New("request body is required")
|
|
}
|
|
body := http.MaxBytesReader(w, r.Body, maxBytes)
|
|
defer func() {
|
|
_ = body.Close()
|
|
}()
|
|
decoder := json.NewDecoder(body)
|
|
decoder.DisallowUnknownFields()
|
|
if err := decoder.Decode(out); err != nil {
|
|
return err
|
|
}
|
|
var extra json.RawMessage
|
|
if err := decoder.Decode(&extra); err != nil {
|
|
if errors.Is(err, io.EOF) {
|
|
return nil
|
|
}
|
|
return fmt.Errorf("request body must contain a single JSON object: %w", err)
|
|
}
|
|
return errors.New("request body must contain a single JSON object")
|
|
}
|
|
|
|
// DecodeStrictJSONReader 从任意 reader 读取单个 JSON 对象;适合已经自行处理空 body 的 handler helper。
|
|
func DecodeStrictJSONReader(reader io.Reader, maxBytes int64, out any) error {
|
|
if reader == nil {
|
|
return errors.New("request body is required")
|
|
}
|
|
data, err := io.ReadAll(io.LimitReader(reader, maxBytes+1))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if int64(len(data)) > maxBytes {
|
|
return fmt.Errorf("request body exceeds %d bytes", maxBytes)
|
|
}
|
|
decoder := json.NewDecoder(bytes.NewReader(data))
|
|
decoder.DisallowUnknownFields()
|
|
if err := decoder.Decode(out); err != nil {
|
|
return err
|
|
}
|
|
var extra json.RawMessage
|
|
if err := decoder.Decode(&extra); err != nil {
|
|
if errors.Is(err, io.EOF) {
|
|
return nil
|
|
}
|
|
return fmt.Errorf("request body must contain a single JSON object: %w", err)
|
|
}
|
|
return errors.New("request body must contain a single JSON object")
|
|
}
|