diff --git a/go.mod b/go.mod index 2ef5605..5592849 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module git.hlsq.asia/mmorpg/service-scene go 1.23.1 require ( - git.hlsq.asia/mmorpg/service-common v0.0.0-20260108144540-69e82ec0fe77 + git.hlsq.asia/mmorpg/service-common v0.0.0-20260110081319-015e333b88c0 github.com/judwhite/go-svc v1.2.1 go.uber.org/zap v1.27.0 google.golang.org/grpc v1.71.1 diff --git a/go.sum b/go.sum index 914c4d6..7c9df8d 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,7 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= -git.hlsq.asia/mmorpg/service-common v0.0.0-20260107061047-e02e56781e78 h1:4CP8w5jHDOdN7hym8YrtioxNDd7PS2WcZDrO6dtY344= -git.hlsq.asia/mmorpg/service-common v0.0.0-20260107061047-e02e56781e78/go.mod h1:xv6m1I2jUA6mudKVznygpnzMoshBQarthHD1QnkW4qc= -git.hlsq.asia/mmorpg/service-common v0.0.0-20260108144540-69e82ec0fe77 h1:39SVfV3+uysM25P+dSnJMvtJJI9l2aZ+/n/ooTdHqxk= -git.hlsq.asia/mmorpg/service-common v0.0.0-20260108144540-69e82ec0fe77/go.mod h1:xv6m1I2jUA6mudKVznygpnzMoshBQarthHD1QnkW4qc= +git.hlsq.asia/mmorpg/service-common v0.0.0-20260110081319-015e333b88c0 h1:GWd3ipi7UveYBAxe+UnTplqiKxOt25NVC5CC634lbuI= +git.hlsq.asia/mmorpg/service-common v0.0.0-20260110081319-015e333b88c0/go.mod h1:xv6m1I2jUA6mudKVznygpnzMoshBQarthHD1QnkW4qc= github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0= github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= diff --git a/internal/grpc_server/stream_client/gateway.go b/internal/grpc_server/stream_client/gateway.go index 2fc85ed..c43e22b 100644 --- a/internal/grpc_server/stream_client/gateway.go +++ b/internal/grpc_server/stream_client/gateway.go @@ -23,7 +23,7 @@ type gatewayStream struct { stream grpc.ClientStream } -func findGatewayBySID(sid int64, fun GatewayFun) (*gatewayStream, error) { +func findGatewayBySID(sid string, fun GatewayFun) (*gatewayStream, error) { key := gatewayKey(sid, fun) if v, ok := gatewayServer.Load(key); ok { @@ -54,7 +54,7 @@ func findGatewayBySID(sid int64, fun GatewayFun) (*gatewayStream, error) { return ss, nil } -func SendMessageToGateway(sid int64, fun GatewayFun, msg proto.Message, re ...bool) error { +func SendMessageToGateway(sid string, fun GatewayFun, msg proto.Message, re ...bool) error { ss, err := findGatewayBySID(sid, fun) if err != nil { return err @@ -79,6 +79,6 @@ func SendMessageToGateway(sid int64, fun GatewayFun, msg proto.Message, re ...bo return nil } -func gatewayKey(sid int64, fun GatewayFun) string { - return strconv.FormatInt(sid, 10) + "-" + strconv.Itoa(int(fun)) +func gatewayKey(sid string, fun GatewayFun) string { + return sid + "-" + strconv.Itoa(int(fun)) } diff --git a/internal/instance/instance.go b/internal/instance/instance.go index 9b14e4d..f0ad1bd 100644 --- a/internal/instance/instance.go +++ b/internal/instance/instance.go @@ -20,25 +20,25 @@ import ( // Instance 场景类 type Instance struct { wg sync.WaitGroup - players map[int64]*npc.PlayerNode // 存储所有玩家节点 [usn] - ctx context.Context // 停止指令 - cancel context.CancelFunc // 停止函数 - logger *zap.SugaredLogger // 日志 - lastLogicTime int64 // 上次逻辑帧执行时间(毫秒时间戳) + players map[string]*npc.PlayerNode // 存储所有玩家节点 [usn] + ctx context.Context // 停止指令 + cancel context.CancelFunc // 停止函数 + logger *zap.SugaredLogger // 日志 + lastLogicTime int64 // 上次逻辑帧执行时间(毫秒时间戳) - SID int64 // 服务ID + SID string // 服务ID InstanceID int32 // 副本ID - UniqueNo int64 // 唯一编号 + UniqueNo string // 唯一编号 EventIn chan proto.Message // 消息入口 } // NewScene 初始化场景 -func NewScene(sid int64, instanceID int32) *Instance { +func NewScene(sid string, instanceID int32) *Instance { s := &Instance{ - players: make(map[int64]*npc.PlayerNode), + players: make(map[string]*npc.PlayerNode), SID: sid, InstanceID: instanceID, - UniqueNo: utils.SnowflakeInstance().Generate().Int64(), + UniqueNo: utils.SnowflakeInstance().Generate().String(), EventIn: make(chan proto.Message, 1024), } s.logger = log.GetLogger().Named(fmt.Sprintf("instance %v:%v", s.InstanceID, s.UniqueNo)) @@ -104,7 +104,7 @@ func (i *Instance) onEvent(e proto.Message) { // 逻辑帧 func (i *Instance) onLogic(delta int64) { positionUpdate := make([]*sc_pb.PositionInfo, 0) - sid := int64(0) + sid := "" // 处理玩家指令 for _, node := range i.players { if node.LogicAction(delta) { @@ -121,7 +121,7 @@ func (i *Instance) onLogic(delta int64) { Info: positionUpdate, }) if err := stream_client.SendMessageToGateway(sid, stream_client.FunToClient, &grpc_pb.ToClientReq{ - USN: -1, + USN: "", MessageID: int32(sc_pb.MessageID_MESSAGE_ID_POSITION), Payload: payload, }); err != nil { diff --git a/internal/instance/manager.go b/internal/instance/manager.go index e515fdc..fcc1a1b 100644 --- a/internal/instance/manager.go +++ b/internal/instance/manager.go @@ -8,34 +8,34 @@ var Mgr *insManager type insManager struct { sync.RWMutex - insMap map[int64]*Instance // [uniqueNo] + insMap map[string]*Instance // [uniqueNo] } func init() { Mgr = &insManager{ - insMap: make(map[int64]*Instance), + insMap: make(map[string]*Instance), } } -func (m *insManager) Add(uniqueNo int64, ins *Instance) { +func (m *insManager) Add(uniqueNo string, ins *Instance) { m.Lock() defer m.Unlock() m.insMap[uniqueNo] = ins } -func (m *insManager) Delete(uniqueNo int64) { +func (m *insManager) Delete(uniqueNo string) { m.Lock() defer m.Unlock() delete(m.insMap, uniqueNo) } -func (m *insManager) GetAll() map[int64]*Instance { +func (m *insManager) GetAll() map[string]*Instance { m.RLock() defer m.RUnlock() return m.insMap } -func (m *insManager) GetByUniqueNo(uniqueNo int64) *Instance { +func (m *insManager) GetByUniqueNo(uniqueNo string) *Instance { m.RLock() defer m.RUnlock() return m.insMap[uniqueNo] diff --git a/internal/npc/player.go b/internal/npc/player.go index 637c8ca..5dbdbf7 100644 --- a/internal/npc/player.go +++ b/internal/npc/player.go @@ -7,8 +7,8 @@ import ( // PlayerNode 定义玩家节点结构体 type PlayerNode struct { - USN int64 // 用户ID - GatewaySID int64 // 网关服务ID + USN string // 用户ID + GatewaySID string // 网关服务ID MoveSpeed float32 // 移动速度 Position [2]float32 // 二维坐标 [x, y] @@ -17,7 +17,7 @@ type PlayerNode struct { Action []*grpc_pb.ActionReq // 其他操作 } -func NewPlayerNode(gatewaySID int64, usn int64) *PlayerNode { +func NewPlayerNode(gatewaySID string, usn string) *PlayerNode { return &PlayerNode{ USN: usn, GatewaySID: gatewaySID,