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

refactor(cool): 移除Redis监听功能和用户结构体定义

移除ListenFunc函数,该函数提供Redis PubSub监听功能,
包括自动重连和心跳保活机制。同时删除User结构体定义和
相关有序集合变量,这些功能将由rpc模块替代实现。

feat(rpc): 添加对ListenFunc的调用以处理Redis监听

在login模块中
This commit is contained in:
昔念
2026-03-04 23:38:21 +08:00
parent 4751594ee8
commit aa53001982
8 changed files with 416 additions and 188 deletions

90
common/rpc/user.go Normal file
View File

@@ -0,0 +1,90 @@
package rpc
import (
"blazing/logic/service/common"
"blazing/modules/player/service"
"errors"
"strings"
"time"
"github.com/gogf/gf/v2/util/gconv"
"github.com/liwnn/zset"
csmap "github.com/mhmtszr/concurrent-swiss-map"
)
type RPCfight struct {
fightmap *csmap.CsMap[int, common.FightI]
zs *zset.ZSet[uint32, User]
}
// ExtractBetweenBrackets 提取字符串中第一个 [] 中间的文本
// 返回值:中间文本、是否成功、错误信息
func ExtractBetweenBrackets(s string) (string, bool, error) {
// 1. 找到第一个 [ 的索引
leftIdx := strings.Index(s, "[")
if leftIdx == -1 {
return "", false, errors.New("未找到左中括号 [")
}
// 2. 找到第一个 [ 之后的第一个 ] 的索引
rightIdx := strings.Index(s[leftIdx+1:], "]")
if rightIdx == -1 {
return "", false, errors.New("找到左中括号 [ 但未找到对应的右中括号 ]")
}
// 3. 计算实际的右中括号索引(加上 leftIdx+1
rightIdx += leftIdx + 1
// 4. 提取中间文本(去除前后空格,可选)
result := strings.TrimSpace(s[leftIdx+1 : rightIdx])
// 5. 检查是否为空
if result == "" {
return "", true, errors.New("中括号中间无文本")
}
return result, true, nil
}
func (r *RPCfight) ADD(s string) {
println("收到sun:join:2458", s)
t, _, _ := ExtractBetweenBrackets(s)
ret := service.NewPVPService(gconv.Uint32(t)).Get(gconv.Uint32(t))
score := 1000
if ret == nil {
score = int(ret.RankInfo.Score)
}
r.zs.Add(gconv.Uint32(t), User{ID: gconv.Uint32(t), JoinTime: time.Now().Unix(), Score: score})
if r.zs.Length() > 2 {
r.zs.FindPrev(func(i User) bool { return i.Score > score })
//找到上一个,如果区间分数少于一定,
//直接进行匹配
}
}
type User struct {
JoinTime int64
ID uint32
Score int
}
func (u User) Key() uint32 {
return uint32(u.ID)
}
// 如果分数不对的话,就按时间排序
func (u User) Less(than User) bool {
if u.Score == than.Score {
return u.JoinTime < than.JoinTime
}
return u.Score < than.Score
}
///定义map,存储用户对战斗容器的映射,便于外部传入时候进行直接操作
var fightmap = RPCfight{
fightmap: csmap.New[int, common.FightI](),
zs: zset.New[uint32, User](func(a, b User) bool {
return a.Less(b)
}),
}