```
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

feat(cool): 添加Redis发布功能并实现巅峰赛匹配加入逻辑

新增RedisDo函数用于向Redis频道发布消息,并在巅峰赛场匹配
中添加玩家加入队列的功能。同时修复了socket连接关闭时资源
泄露问题,确保MsgChan正确关闭。

BREAKING CHANGE: 新增的RedisDo函数会直接panic处理错误,
需要调用方注意
This commit is contained in:
昔念
2026-03-04 03:22:43 +08:00
parent 10af34fdad
commit fb78147035
6 changed files with 210 additions and 0 deletions

View File

@@ -1 +1,30 @@
package controller
import (
"blazing/common/socket/errorcode"
"blazing/cool"
"blazing/logic/service/common"
"blazing/logic/service/fight"
"blazing/logic/service/fight/top/repo"
"blazing/logic/service/player"
"context"
goredis "github.com/redis/go-redis/v9"
)
// 表示"宠物王加入"的入站消息数据
type PetTOPLEVELnboundInfo struct {
Head common.TomeeHeader `cmd:"2458" struc:"skip"`
Mode uint32 //巅峰赛对战模式 19 = 普通模式单精灵 20 = 普通模式多精灵
}
func (h Controller) JoINtop(data *PetTOPLEVELnboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
cool.RedisDo(context.TODO(), "sun:join:2458", data.Head.UserID, data.Mode)
client := cool.Redis.Client()
// 类型断言为 UniversalClient
universalClient, _ := client.(goredis.UniversalClient)
repo.NewPlayerRepository(universalClient).AddPlayerToPool(context.TODO(), data.Head.UserID, 1)
return nil, -1
}