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

refactor(common): 统一Redis连接方式并优化代码结构

- 将 g.Redis("cool").Conn(ctx) 统一改为 Redis.Conn(ctx) 的调用方式
- 在coolconfig中添加ServerList.GetID()方法用于生成服务器唯一标识
- 引入gconv包用于类型转换操作

feat(rpc): 完善ListenFight函数实现集群消息监听

- 新增ListenFight函数,完全对齐ListenFunc
This commit is contained in:
昔念
2026-03-20 04:58:23 +08:00
parent 5657f1e673
commit 90b62b44e4
13 changed files with 119 additions and 60 deletions

View File

@@ -21,6 +21,7 @@ func (h Controller) JoINtop(data *PetTOPLEVELnboundInfo, c *player.Player) (resu
cool.RedisDo(context.TODO(), "sun:join", info.RPCFightinfo{
PlayerID: c.Info.UserID,
Mode: data.Mode,
Type: 1,
})
// // 类型断言为 UniversalClient

View File

@@ -72,6 +72,7 @@ func (h Controller) Login(data *user.MAIN_LOGIN_IN, c gnet.Conn) (result *user.L
// }
// currentPlayer.Info.SetTask(314, model.Completed)
// currentPlayer.Info.SetTask(315, model.Completed)
//fmt.Println("任务", 291, currentPlayer.Info.GetTask(145))
currentPlayer.IsLogin = true
return result, 0

View File

@@ -5,6 +5,7 @@ import (
"blazing/common/rpc"
"blazing/common/socket"
"blazing/cool"
"context"
"blazing/logic/controller"
@@ -60,7 +61,7 @@ func Start() {
// if cool.Config.ServerInfo.IsVip != 0 {
// g.DB().GetCache().SetAdapter(gcache.NewAdapterRedis(cool.Redis)) //设置数据库
// }
go rpc.ListenFight(context.Background())
if cool.Config.ServerInfo.IsDebug == 1 {
g.DB().SetDebug(true)
@@ -81,7 +82,7 @@ func Start() {
controller.Maincontroller.RPCClient = rpcClient //将RPC赋值Start
controller.Maincontroller.UID = uint32(100000*serverID + uint32(port)) //赋值服务器ID
controller.Maincontroller.UID = gconv.Uint32(cool.Config.ServerInfo.GetID()) //赋值服务器ID
controller.Init(true)
xmlres.Initfile()

View File

@@ -52,7 +52,7 @@ type Fightinfo struct {
FightType uint32
}
type RPCFightinfo struct {
Type int
Type int //加入还是退出
PlayerID uint32
// 战斗模式 1 = 1v1 2 = 6v6 3大乱斗 0 什么都不做
Mode uint32
@@ -62,8 +62,8 @@ type RPCFightinfo struct {
// FightType uint32
}
type RPCFightStartinfo struct {
Servierid int // 非0表示rpc跨服
PlayerID uint32
Serverid int // 非0表示rpc跨服
PlayerID uint32
// 战斗模式 1 = 1v1 2 = 6v6 3大乱斗 0 什么都不做
Mode uint32
//Type uint32 //战斗类型

View File

@@ -1,9 +1,8 @@
package player
import (
"blazing/cool"
"context"
"github.com/gogf/gf/v2/frame/g"
)
// rpc,跨服匹配的玩家,只做数据的传输
@@ -15,7 +14,7 @@ type RPC_player struct {
func (f *RPC_player) SendPackCmd(cmd uint32, data any) {
conn, _ := g.Redis("cool").Conn(context.TODO())
conn, _ := cool.Redis.Conn(context.TODO())
defer conn.Close(context.TODO())
conn.Do(context.TODO(), "publish", "sun:send", cmd, data)