v1进行时:UpsertUserAll回归基础包体(附加数据一律走extra_data)、解锁位串默认0、适配2026-10服务器维护(token一次性、上传冷却50s、买票冷却40s写入config)、新增落盘与日志开关

This commit is contained in:
Txiaochen committed 2026-11-07 20:34:24 +08:00
1 parent 1d365cc948
commit ed7d463519
12 files changed
+552 -271

No files matched your search

+24 -173
View File
@@ -1894,117 +1894,6 @@ def apply_play_effects(
# 十二、组装 upsertUserAll
# =============================================================================
# -----------------------------------------------------------------------------
# ★ 歌曲解锁(解禁):MusicUnlock* 不是独立节点,而是并入 userItemList 的 UserItem
# -----------------------------------------------------------------------------
# 依据 source/Assembly-CSharp/Manager/UserData.cs:132-138 —— 客户端有四个解锁列表:
# MusicUnlockList / MusicUnlockMasterList / MusicUnlockReMasterList / MusicUnlockStrongList
# 它们**没有**对应的 userXxxList 节点,导出时统一并进 userItemList:
# source/Assembly-CSharp/Net.VO.Mai2/VOExtensions.cs:981-1008
# MusicUnlockList -> itemKind = 5
# MusicUnlockMasterList -> itemKind = 6
# MusicUnlockReMasterList -> itemKind = 7
# MusicUnlockStrongList -> itemKind = 8
# 条目形如 {"itemKind":5,"itemId":1085,"stock":1,"isValid":true}
# (真机 data/12570152.json 的 userItemList 里 kind5=77 条、kind6=446 条、kind7=34 条)
#
# ★ 难度解锁的「天生免费」规则:
# source/Assembly-CSharp/Manager/NotesListManager.cs:415-453 IsUnlockMaster
# source/Assembly-CSharp/Manager/NotesListManager.cs:455-494 IsUnlockReMaster
# 两个函数开头都有 `if (id < 10000) return true;`
# -> musicId < 10000(标准谱)的 Master / Re:Master **天生解锁**,不必写 kind6/7;
# 只有 musicId >= 10000(DX 谱)才需要额外解锁。
# ★ 另外 Re:Master 还受活动开关约束(IsUnlockReMaster 里的
# `if (!instance.IsOpenEvent(subEventId)) return false;`),
# 那是机台/服务端侧的开关,脚本改不了 —— 写了 kind7 也可能进游戏仍是灰的。
#
# ★ 写 kind5 只是「把这首歌标记为已解锁」,不携带任何成绩;
# 成绩另由 userMusicDetailList 承载,纯解锁不需要打歌。
#: UserItem.itemKind 取值(source/Assembly-CSharp/Manager/UserData.cs:132-138)
ITEM_KIND_MUSIC_UNLOCK = 5
ITEM_KIND_MUSIC_UNLOCK_MASTER = 6
ITEM_KIND_MUSIC_UNLOCK_REMASTER = 7
ITEM_KIND_MUSIC_UNLOCK_STRONG = 8
#: 小于这个 musicId 的谱面 Master / Re:Master 天生解锁(NotesListManager.cs:415/455)
UNLOCK_MASTER_MIN_MUSIC_ID = 10000
def build_unlock_items(
music_ids: Sequence[int],
existing: Optional[Sequence[Any]] = None,
*,
master: bool = True,
remaster: bool = True,
unlock_base: bool = True,
) -> Tuple[List[Dict[str, Any]], List[str]]:
"""
构造「解锁歌曲 / 解禁难度」要追加的 userItemList 条目。
★ 只返回**服务器上还没有**的条目;已存在的跳过(重复插入会让服务端报错)。
参数:
music_ids: 要解锁的 musicId 列表(重复的自动去掉)
existing: 服务器现有的 userItemList(GetUserData 里的那份),
用来判断哪些条目已经存在
master: True = 同时解锁 Master 难度(仅 musicId >= 10000 才写 kind6)
remaster: True = 同时解锁 Re:Master 难度(仅 musicId >= 10000 才写 kind7)
unlock_base: True = 解锁歌曲本体(kind5)
返回:
(条目列表, 说明文字列表)
条目形如 {"itemKind":5,"itemId":1085,"stock":1,"isValid":true}
"""
have: set = set()
for it in existing or []:
if isinstance(it, dict):
try:
have.add((int(it.get("itemKind")), int(it.get("itemId"))))
except (TypeError, ValueError):
continue
ids: List[int] = []
for raw in music_ids or []:
try:
mid = int(raw)
except (TypeError, ValueError):
continue
if mid <= 0 or mid in ids:
continue
ids.append(mid)
items: List[Dict[str, Any]] = []
notes: List[str] = []
def _add(kind: int, mid: int, what: str) -> None:
if (kind, mid) in have:
notes.append("解锁检查:musicId=" + str(mid) + " 的" + what
+ "已经解锁(itemKind=" + str(kind) + "),跳过")
return
have.add((kind, mid))
items.append({"itemKind": kind, "itemId": mid, "stock": 1, "isValid": True})
notes.append("解锁:musicId=" + str(mid) + " " + what
+ "(itemKind=" + str(kind) + ")")
for mid in ids:
if unlock_base:
_add(ITEM_KIND_MUSIC_UNLOCK, mid, "歌曲本体")
if mid < UNLOCK_MASTER_MIN_MUSIC_ID:
# ★ 标准谱(musicId < 10000)Master/Re:Master 天生解锁,不需要条目
if master or remaster:
notes.append("解锁检查:musicId=" + str(mid)
+ " 是标准谱(< " + str(UNLOCK_MASTER_MIN_MUSIC_ID)
+ "),Master/Re:Master 天生解锁,跳过")
continue
if master:
_add(ITEM_KIND_MUSIC_UNLOCK_MASTER, mid, "Master 难度")
if remaster:
_add(ITEM_KIND_MUSIC_UNLOCK_REMASTER, mid, "Re:Master 难度")
return items, notes
def build_user_all(
snapshot: Optional[Any] = None,
play: Optional[PlayData] = None,
@@ -2020,10 +1909,6 @@ def build_user_all(
playlog_id: int = 0,
play_date_time: Optional[int] = None,
extra_data: Optional[Any] = None,
unlock_music_ids: Optional[Sequence[int]] = None,
unlock_master: bool = True,
unlock_remaster: bool = True,
unlock_base: bool = True,
) -> Dict[str, Any]:
"""
组装 upsertUserAll 的 36 个节点。
@@ -2045,15 +1930,15 @@ def build_user_all(
用于 lastPlayDate / userGamePlaylogList.playDate。
不传则退回 login_date_time。
playlog_id: UserLoginApi 的 loginId(用于 userGamePlaylogList)
extra_data: ★ 额外 JSON(dict / JSON 字符串 / 文件路径),
自动匹配插入 36 节点,**优先级高于 patch**。见 merge_extra_data。
unlock_music_ids: ★ 要解锁(解禁)的 musicId 列表。见 build_unlock_items。
写进 userItemList:kind5=歌曲本体、kind6=Master、kind7=Re:Master。
unlock_master: 解锁时是否一并解禁 Master(仅 DX 谱 musicId >= 10000 生效)
unlock_remaster: 解锁时是否一并解禁 Re:Master(同上)
unlock_base: False = **不解锁歌曲本体**(不写 kind5),只解禁难度。
注意:歌曲本体没解锁时,游戏里可能连谱面都进不去,
所以这个开关是「只补难度」的场景用的。
extra_data: ★ 额外 JSON,自动匹配到 36 节点并**整体覆盖**,
**优先级高于 patch**。见 merge_extra_data。支持四种形态:
dict 直接合并
JSON 字符串 json.loads 后合并
文件路径(.json / .txt) 读文件后合并
callable(snapshot, user_all) -> dict
★ 需要「按服务器现状现算」时用(例如只插入还不存在的
条目):拿到**归一化后的快照**(dict,键=节点名)与
当前已组装好的 user_all 后再产出要覆盖的节点字典。
返回:
36 节点的 dict
@@ -2157,39 +2042,19 @@ def build_user_all(
user_all[node] = coerce_node_value(node, value)
# ---- extra_data 覆盖(★ 最高优先级)----
if load_extra_data(extra_data):
for note in merge_extra_data(user_all, extra_data):
# ★ 这是「附加功能」的唯一入口:本函数只负责组装**基础包体**,
# 任何额外内容(解锁歌曲、点灯、自定义节点…)都由调用方通过 extra_data 传入,
# 这里自动匹配到 36 节点并整体覆盖,不需要改本文件。
_extra = extra_data
if callable(_extra):
# 允许按快照现算:callable(snapshot, user_all) -> dict
_extra = _extra(base, user_all)
log_debug("extra_data 由 callable 现算,产出 "
+ str(len(_extra or {})) + " 个节点")
if load_extra_data(_extra):
for note in merge_extra_data(user_all, _extra):
log_info(note)
# ---- ★ 歌曲解锁(解禁)----
# 放在 extra_data 之后:extra_data 可能整体替换了 userItemList,
# 解锁条目追加到最终列表末尾,位串补 "1"(= 服务端侧新增该 item)。
# 依据见本文件「歌曲解锁」注释块。
if unlock_music_ids:
unlock_items, unlock_notes = build_unlock_items(
unlock_music_ids,
existing=user_all.get("userItemList") or [],
master=unlock_master,
remaster=unlock_remaster,
unlock_base=unlock_base,
)
for note in unlock_notes:
log_info(note)
if unlock_items:
old_items = list(user_all.get("userItemList") or [])
old_bits = user_all.get("isNewItemList")
if not isinstance(old_bits, str):
old_bits = ""
if len(old_bits) != len(old_items):
# 先对齐到旧列表长度,避免新条目被 sync_bits_to_arrays 补成 "0"
old_bits = (old_bits + "0" * len(old_items))[:len(old_items)]
user_all["userItemList"] = old_items + unlock_items
user_all["isNewItemList"] = old_bits + "1" * len(unlock_items)
log_info("★ 本次解锁共新增 " + str(len(unlock_items))
+ " 个 userItem 条目(位串补 " + "1" * len(unlock_items) + ")")
else:
log_info("解锁检查:指定的歌曲/难度在服务器上都已经解锁,无需改动")
# ---- 清理内部字段 ----
for key in list(user_all.keys()):
if key.startswith("_"):
@@ -2629,10 +2494,6 @@ def UpsertUserAll(
auto_characters: bool = True,
play: Optional[PlayData] = None,
extra_data: Optional[Any] = None,
unlock_music_ids: Optional[Sequence[int]] = None,
unlock_master: bool = True,
unlock_remaster: bool = True,
unlock_base: bool = True,
patch: Optional[Dict[str, Any]] = None,
user_playlog_list: Optional[List[Any]] = None,
pre_new_item_list: bool = True,
@@ -2682,21 +2543,14 @@ def UpsertUserAll(
userCharacterList 推出本局 5 只角色(**游玩前**等级)。
这样 PLAY_CHARACTERS(现在 selftest.py 里) 过期也不影响。
play: 本局数据(可选,默认按 config.PLAY_*)
extra_data: ★ 额外 JSON,自动匹配插入 upsertUserAll 的 36 个节点。
接受 dict / JSON 字符串 / JSON 文件路径,例如:
extra_data: ★ 额外 JSON,自动匹配到 upsertUserAll 的 36 个节点并覆盖。
接受 dict / JSON 字符串 / JSON 文件路径 /
callable(snapshot, user_all) -> dict,例如:
extra_data={"userKaleidxScopeList": [{...}],
"isNewKaleidxScopeList": "1"}
优先级最高(覆盖快照演算出的同名字段)。
没给位串时会按数组长度补 "0" 并给出提示。
unlock_music_ids: ★ 要解锁(解禁)的 musicId 列表,例如 [1085, 11414]。
写进 userItemList:kind5=歌曲本体、kind6=Master、kind7=Re:Master。
★ musicId < 10000(标准谱)的 Master/Re:Master 天生解锁,
只写 kind5;只有 DX 谱(>= 10000)才写 kind6/7。
★ 已存在的条目自动跳过(重复插入服务端会报错)。
见 build_unlock_items 上方的源码依据。
unlock_master: 解锁时是否一并解禁 Master 难度(默认 True)
unlock_remaster: 解锁时是否一并解禁 Re:Master 难度(默认 True)
unlock_base: False = 只解禁难度,**不解锁歌曲本体**(不写 kind5)
★ 本接口只产「基础包体」,所有附加功能都走这个入口。
patch: 同 extra_data 的旧接口(只收 dict,不补位串提示)。
user_playlog_list: 本局成绩明细(可选;不传则用 play 自动构造一条)
pre_new_item_list: True(默认)= 发包前先调 GetUserNewItemListApi
@@ -2788,9 +2642,6 @@ def UpsertUserAll(
# ---------- 阶段 5:组装 upsertUserAll(快照基线 + 本局演算 + 差分)----------
user_all = build_user_all(
snapshot=snapshot, play=p, patch=patch, extra_data=extra_data,
unlock_music_ids=unlock_music_ids,
unlock_master=unlock_master, unlock_remaster=unlock_remaster,
unlock_base=unlock_base,
login_date_time=login_date_time, auth_date_time=auth_date_time,
place_id=place_id, place_name=place_name,
region_id=region_id, region_name=region_name, client_id=client_id,