From a2ca2343584034a092a4254df9a7289b34cdcd8a Mon Sep 17 00:00:00 2001 From: "DESKTOP-V763RJ7\\Administrator" <835606593@qq.com> Date: Mon, 12 Jan 2026 12:20:10 +0800 Subject: [PATCH] =?UTF-8?q?feat=20sc=E6=94=B9=E5=90=8Dss?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 2 +- go.sum | 2 ++ internal/ws/client.go | 8 ++++---- internal/ws/handler.go | 18 +++++++++--------- internal/ws/router.go | 14 +++++++------- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/go.mod b/go.mod index cfeb42d..0c4738e 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module git.hlsq.asia/mmorpg/service-robot go 1.23.1 require ( - git.hlsq.asia/mmorpg/service-common v0.0.0-20260112035311-ec291d4332e5 + git.hlsq.asia/mmorpg/service-common v0.0.0-20260112040622-d433cd03a956 github.com/gorilla/websocket v1.5.3 github.com/judwhite/go-svc v1.2.1 google.golang.org/protobuf v1.36.9 diff --git a/go.sum b/go.sum index 4c90eca..2a5b3b8 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ git.hlsq.asia/mmorpg/service-common v0.0.0-20260112035311-ec291d4332e5 h1:SauhRmcRxeQj/luQRyIt9iHORp/U9cpm2I5o65rUeGg= git.hlsq.asia/mmorpg/service-common v0.0.0-20260112035311-ec291d4332e5/go.mod h1:xv6m1I2jUA6mudKVznygpnzMoshBQarthHD1QnkW4qc= +git.hlsq.asia/mmorpg/service-common v0.0.0-20260112040622-d433cd03a956 h1:UfdH/8hH1MOnWzsMEvI8e31O7u5IJO5NaJjgK+BR1iY= +git.hlsq.asia/mmorpg/service-common v0.0.0-20260112040622-d433cd03a956/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/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0= diff --git a/internal/ws/client.go b/internal/ws/client.go index f9f566d..de116f0 100644 --- a/internal/ws/client.go +++ b/internal/ws/client.go @@ -8,7 +8,7 @@ import ( "errors" "fmt" "git.hlsq.asia/mmorpg/service-common/log" - "git.hlsq.asia/mmorpg/service-common/proto/sc/sc_pb" + "git.hlsq.asia/mmorpg/service-common/proto/ss/ss_pb" "git.hlsq.asia/mmorpg/service-common/utils" "github.com/gorilla/websocket" "google.golang.org/protobuf/proto" @@ -100,7 +100,7 @@ func (c *Client) startReader() { return } - msg := &sc_pb.Message{} + msg := &ss_pb.Message{} if err = proto.Unmarshal(msgByte, msg); err != nil { continue } @@ -132,12 +132,12 @@ func (c *Client) startWriter() { } // WriteMessage 发送消息给服务器 -func (c *Client) WriteMessage(msgID sc_pb.MessageID, data proto.Message) error { +func (c *Client) WriteMessage(msgID ss_pb.MessageID, data proto.Message) error { d, err := proto.Marshal(data) if err != nil { return err } - p := &sc_pb.Message{ + p := &ss_pb.Message{ ID: msgID, Payload: d, } diff --git a/internal/ws/handler.go b/internal/ws/handler.go index a2bdf48..dd256fc 100644 --- a/internal/ws/handler.go +++ b/internal/ws/handler.go @@ -2,7 +2,7 @@ package ws import ( "git.hlsq.asia/mmorpg/service-common/log" - "git.hlsq.asia/mmorpg/service-common/proto/sc/sc_pb" + "git.hlsq.asia/mmorpg/service-common/proto/ss/ss_pb" "google.golang.org/protobuf/proto" "math" "math/rand" @@ -14,14 +14,14 @@ type LoginSuccess struct { } func (_ *LoginSuccess) Handle(data []byte, client *Client) { - msg := &sc_pb.S2C_LoginSuccess{} + msg := &ss_pb.S2C_LoginSuccess{} if err := proto.Unmarshal(data, msg); err != nil { log.Errorf("handle msg error") client.Stop() return } - _ = client.WriteMessage(sc_pb.MessageID_MESSAGE_ID_ENTER_INSTANCE, &sc_pb.C2S_EnterInstance{ + _ = client.WriteMessage(ss_pb.MessageID_MESSAGE_ID_ENTER_INSTANCE, &ss_pb.C2S_EnterInstance{ InstanceID: msg.InstanceID, }) } @@ -30,7 +30,7 @@ type QueueUp struct { } func (_ *QueueUp) Handle(data []byte, client *Client) { - msg := &sc_pb.S2C_QueueUp{} + msg := &ss_pb.S2C_QueueUp{} if err := proto.Unmarshal(data, msg); err != nil { log.Errorf("handle msg error") client.Stop() @@ -42,7 +42,7 @@ type EnterInstance struct { } func (_ *EnterInstance) Handle(data []byte, client *Client) { - msg := &sc_pb.S2C_EnterInstance{} + msg := &ss_pb.S2C_EnterInstance{} if err := proto.Unmarshal(data, msg); err != nil { log.Errorf("handle msg error") client.Stop() @@ -65,10 +65,10 @@ func (_ *EnterInstance) Handle(data []byte, client *Client) { go func() { for { x, y := randDir() - _ = client.WriteMessage(sc_pb.MessageID_MESSAGE_ID_ACTION, &sc_pb.C2S_Action{ + _ = client.WriteMessage(ss_pb.MessageID_MESSAGE_ID_ACTION, &ss_pb.C2S_Action{ Sequence: 0, Timestamp: 0, - Action: sc_pb.ActionID_ACTION_ID_MOVE, + Action: ss_pb.ActionID_ACTION_ID_MOVE, DirX: int32(x * 100), DirY: int32(y * 100), SkillID: 0, @@ -80,7 +80,7 @@ func (_ *EnterInstance) Handle(data []byte, client *Client) { var s2cPositionPool = sync.Pool{ New: func() interface{} { - return &sc_pb.Message{} + return &ss_pb.Message{} }, } @@ -88,7 +88,7 @@ type Position struct { } func (_ *Position) Handle(data []byte, client *Client) { - //msg := s2cPositionPool.Get().(*sc_pb.Message) + //msg := s2cPositionPool.Get().(*ss_pb.Message) //if err := proto.Unmarshal(data, msg); err != nil { // log.Errorf("handle msg error") // client.Stop() diff --git a/internal/ws/router.go b/internal/ws/router.go index 8b352ec..26a0dd5 100644 --- a/internal/ws/router.go +++ b/internal/ws/router.go @@ -1,17 +1,17 @@ package ws -import "git.hlsq.asia/mmorpg/service-common/proto/sc/sc_pb" +import "git.hlsq.asia/mmorpg/service-common/proto/ss/ss_pb" -var router map[sc_pb.MessageID]BaseRouter +var router map[ss_pb.MessageID]BaseRouter type BaseRouter interface { Handle(data []byte, client *Client) } func init() { - router = make(map[sc_pb.MessageID]BaseRouter) - router[sc_pb.MessageID_MESSAGE_ID_LOGIN_SUCCESS] = &LoginSuccess{} - router[sc_pb.MessageID_MESSAGE_ID_QUEUE_UP] = &QueueUp{} - router[sc_pb.MessageID_MESSAGE_ID_ENTER_INSTANCE] = &EnterInstance{} - router[sc_pb.MessageID_MESSAGE_ID_POSITION] = &Position{} + router = make(map[ss_pb.MessageID]BaseRouter) + router[ss_pb.MessageID_MESSAGE_ID_LOGIN_SUCCESS] = &LoginSuccess{} + router[ss_pb.MessageID_MESSAGE_ID_QUEUE_UP] = &QueueUp{} + router[ss_pb.MessageID_MESSAGE_ID_ENTER_INSTANCE] = &EnterInstance{} + router[ss_pb.MessageID_MESSAGE_ID_POSITION] = &Position{} }