服务端(Go): - GM 塞背包/带属性装备发放:在线角色推送 op14 增量物品行,背包实时刷新,无需回角色选择界面 - GM 改金币/改等级:去掉在线拒绝,落库后推送 op14 钱包/op37 等级状态,在线实时刷新 - 等级端点统一切换到新版 GMSetCharacterLevel(自带在线刷新) - 无限/锁死疲劳模式 + 燃烧疲劳:每房间消耗 2 点、打怪与通关经验双倍 - 燃烧疲劳开关时给所有在线角色推送系统提示(op12 mode 0) - 深渊史诗掉率:GM 全局倍率 + 城镇增益药剂窗口倍率,真实接入掉落结算 启动器(Python/JS): - 标题栏自绘、窗口 1204x717、禁止拖拽改大小、仅最小化/关闭 - GM 工具:疲劳与燃烧、深渊史诗掉率、拍卖行上架(单一定价对齐) - 拍卖行上架前端对齐服务端单一价格语义,修复 400 报错
106 lines
2.6 KiB
Go
106 lines
2.6 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
|
|
"longheng.io/server/pkg/contracts"
|
|
)
|
|
|
|
type hybridRespCache struct {
|
|
redis logicResponseCache
|
|
mysql logicResponseCache
|
|
}
|
|
|
|
// Store 先写权威 MySQL 响应缓存,再尝试写 Redis 热缓存。
|
|
func (c *hybridRespCache) Store(ctx context.Context, key string, response contracts.LogicPlayerResponse) error {
|
|
var durableErr error
|
|
// MySQL 是权威响应缓存,必须先写;Redis 只是热缓存,失败不能覆盖 MySQL 写入结果。
|
|
if c != nil && c.mysql != nil {
|
|
durableErr = c.mysql.Store(ctx, key, response)
|
|
}
|
|
var redisErr error
|
|
if c != nil && c.redis != nil {
|
|
redisErr = c.redis.Store(ctx, key, response)
|
|
}
|
|
if durableErr != nil {
|
|
return durableErr
|
|
}
|
|
if c == nil || c.mysql == nil {
|
|
return redisErr
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Get 先读 Redis 热缓存,未命中时读取 MySQL 并回填 Redis。
|
|
func (c *hybridRespCache) Get(ctx context.Context, key string) (contracts.LogicPlayerResponse, bool, error) {
|
|
var redisErr error
|
|
// 读取先走 Redis,未命中再读 MySQL 并回填。Redis 错误只在没有 MySQL 兜底时才向上暴露。
|
|
if c != nil && c.redis != nil {
|
|
response, ok, err := c.redis.Get(ctx, key)
|
|
if ok {
|
|
return response, true, nil
|
|
}
|
|
if err != nil {
|
|
redisErr = err
|
|
}
|
|
}
|
|
if c != nil && c.mysql != nil {
|
|
response, ok, err := c.mysql.Get(ctx, key)
|
|
if err != nil || !ok {
|
|
if err != nil {
|
|
return contracts.LogicPlayerResponse{}, false, err
|
|
}
|
|
return contracts.LogicPlayerResponse{}, false, redisErr
|
|
}
|
|
if c.redis != nil {
|
|
_ = c.redis.Store(ctx, key, response)
|
|
}
|
|
return response, true, nil
|
|
}
|
|
return contracts.LogicPlayerResponse{}, false, redisErr
|
|
}
|
|
|
|
// Delete 同时删除 Redis 和 MySQL 中的响应缓存。
|
|
func (c *hybridRespCache) Delete(ctx context.Context, key string) error {
|
|
if c != nil && c.redis != nil {
|
|
if err := c.redis.Delete(ctx, key); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
if c != nil && c.mysql != nil {
|
|
return c.mysql.Delete(ctx, key)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Snapshot 返回混合响应缓存的后端状态快照。
|
|
func (c *hybridRespCache) Snapshot() map[string]any {
|
|
out := map[string]any{
|
|
"backend": "mysql_redis",
|
|
}
|
|
if c == nil {
|
|
return out
|
|
}
|
|
if c.redis != nil {
|
|
out["redis"] = c.redis.Snapshot()
|
|
}
|
|
if c.mysql != nil {
|
|
out["mysql"] = c.mysql.Snapshot()
|
|
}
|
|
return out
|
|
}
|
|
|
|
// Close 关闭混合响应缓存持有的后端连接。
|
|
func (c *hybridRespCache) Close(ctx context.Context) error {
|
|
var first error
|
|
if c != nil && c.redis != nil {
|
|
first = c.redis.Close(ctx)
|
|
}
|
|
if c != nil && c.mysql != nil {
|
|
if err := c.mysql.Close(ctx); first == nil {
|
|
first = err
|
|
}
|
|
}
|
|
return first
|
|
}
|