diff --git a/common/rpc/user.go b/common/rpc/user.go index 26108cd69..94fa538bc 100644 --- a/common/rpc/user.go +++ b/common/rpc/user.go @@ -6,11 +6,8 @@ import ( "blazing/modules/player/model" "blazing/modules/player/service" "encoding/json" - "errors" - "strings" "time" - "github.com/gogf/gf/v2/util/gconv" "github.com/liwnn/zset" csmap "github.com/mhmtszr/concurrent-swiss-map" ) @@ -20,46 +17,46 @@ type RPCfight struct { zs *zset.ZSet[uint32, *model.PVP] } -// ExtractBetweenBrackets 提取字符串中第一个 [] 中间的文本 -// 返回值:中间文本、是否成功、错误信息 -func ExtractBetweenBrackets(s string) (string, bool, error) { - // 1. 找到第一个 [ 的索引 - leftIdx := strings.Index(s, "[") - if leftIdx == -1 { - return "", false, errors.New("未找到左中括号 [") - } +// // 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("找到左中括号 [ 但未找到对应的右中括号 ]") - } +// // 2. 找到第一个 [ 之后的第一个 ] 的索引 +// rightIdx := strings.Index(s[leftIdx+1:], "]") +// if rightIdx == -1 { +// return "", false, errors.New("找到左中括号 [ 但未找到对应的右中括号 ]") +// } - // 3. 计算实际的右中括号索引(加上 leftIdx+1) - rightIdx += leftIdx + 1 +// // 3. 计算实际的右中括号索引(加上 leftIdx+1) +// rightIdx += leftIdx + 1 - // 4. 提取中间文本(去除前后空格,可选) - result := strings.TrimSpace(s[leftIdx+1 : rightIdx]) +// // 4. 提取中间文本(去除前后空格,可选) +// result := strings.TrimSpace(s[leftIdx+1 : rightIdx]) - // 5. 检查是否为空 - if result == "" { - return "", true, errors.New("中括号中间无文本") - } +// // 5. 检查是否为空 +// if result == "" { +// return "", true, errors.New("中括号中间无文本") +// } - return result, true, nil -} +// return result, true, nil +// } func (r *RPCfight) ADD(s string) { println("收到sun:join", s) var pvp info.RPCFightinfo json.Unmarshal([]byte(s), &pvp) - t, _, _ := ExtractBetweenBrackets(s) - ret := service.NewPVPService(gconv.Uint32(t)).Get(gconv.Uint32(t)) + //t, _, _ := ExtractBetweenBrackets(s) + ret := service.NewPVPService(pvp.PlayerID).Get(pvp.PlayerID) score := 1000 if ret != nil { score = int(ret.RankInfo.Score) } - r.zs.Add(gconv.Uint32(t), + r.zs.Add(pvp.PlayerID, ret) if r.zs.Length() > 2 { u, s := r.zs.FindPrev(func(i *model.PVP) bool { return i.RankInfo.Score > score }) @@ -76,6 +73,10 @@ func (r *RPCfight) ADD(s string) { } } +func (r *RPCfight) Cancel(s string) { +r.zs.Remove() +} + ///定义map,存储用户对战斗容器的映射,便于外部传入时候进行直接操作 var fightmap = RPCfight{