diff --git a/go.mod b/go.mod index 3500873..54de4e6 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module git.hlsq.asia/mmorpg/service-robot go 1.24.0 require ( - git.hlsq.asia/mmorpg/service-common v0.0.0-20260207051302-0ca8a0ccbb14 + git.hlsq.asia/mmorpg/service-common v0.0.0-20260211064821-558677bc3a2e github.com/gorilla/websocket v1.5.3 github.com/judwhite/go-svc v1.2.1 google.golang.org/protobuf v1.36.10 diff --git a/go.sum b/go.sum index 05e00c8..aaf43e1 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +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-20260207051302-0ca8a0ccbb14 h1:4r3tNWRzGVY3Xx6UiGjJJnwoMoWlVqbyGrljxl5d/nQ= -git.hlsq.asia/mmorpg/service-common v0.0.0-20260207051302-0ca8a0ccbb14/go.mod h1:mMhZcumphj6gaVTppVYsMTkd+5HupmQgAc53Pd4MH9I= +git.hlsq.asia/mmorpg/service-common v0.0.0-20260211064821-558677bc3a2e h1:MNVS1NXNVn4DeTZPcvvA8YFM8afCzZedLPUYMffNgZs= +git.hlsq.asia/mmorpg/service-common v0.0.0-20260211064821-558677bc3a2e/go.mod h1:mMhZcumphj6gaVTppVYsMTkd+5HupmQgAc53Pd4MH9I= github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0= github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/IBM/sarama v1.46.3 h1:njRsX6jNlnR+ClJ8XmkO+CM4unbrNr/2vB5KK6UA+IE= diff --git a/internal/ws/client.go b/internal/ws/client.go index 503b053..ea88b43 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/ss/ss_pb" + "git.hlsq.asia/mmorpg/service-common/proto/ss/sspb" "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 := &ss_pb.Message{} + msg := &sspb.Message{} if err = proto.Unmarshal(msgByte, msg); err != nil { continue } @@ -132,12 +132,12 @@ func (c *Client) startWriter() { } // WriteMessage 发送消息给服务器 -func (c *Client) WriteMessage(msgID ss_pb.MessageID, data proto.Message) error { +func (c *Client) WriteMessage(msgID sspb.MessageID, data proto.Message) error { d, err := proto.Marshal(data) if err != nil { return err } - p := &ss_pb.Message{ + p := &sspb.Message{ ID: msgID, Payload: d, } diff --git a/internal/ws/handler.go b/internal/ws/handler.go index dd256fc..9ea1626 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/ss/ss_pb" + "git.hlsq.asia/mmorpg/service-common/proto/ss/sspb" "google.golang.org/protobuf/proto" "math" "math/rand" @@ -14,14 +14,14 @@ type LoginSuccess struct { } func (_ *LoginSuccess) Handle(data []byte, client *Client) { - msg := &ss_pb.S2C_LoginSuccess{} + msg := &sspb.S2C_LoginSuccess{} if err := proto.Unmarshal(data, msg); err != nil { log.Errorf("handle msg error") client.Stop() return } - _ = client.WriteMessage(ss_pb.MessageID_MESSAGE_ID_ENTER_INSTANCE, &ss_pb.C2S_EnterInstance{ + _ = client.WriteMessage(sspb.MessageID_MESSAGE_ID_ENTER_INSTANCE, &sspb.C2S_EnterInstance{ InstanceID: msg.InstanceID, }) } @@ -30,7 +30,7 @@ type QueueUp struct { } func (_ *QueueUp) Handle(data []byte, client *Client) { - msg := &ss_pb.S2C_QueueUp{} + msg := &sspb.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 := &ss_pb.S2C_EnterInstance{} + msg := &sspb.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(ss_pb.MessageID_MESSAGE_ID_ACTION, &ss_pb.C2S_Action{ + _ = client.WriteMessage(sspb.MessageID_MESSAGE_ID_ACTION, &sspb.C2S_Action{ Sequence: 0, Timestamp: 0, - Action: ss_pb.ActionID_ACTION_ID_MOVE, + Action: sspb.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 &ss_pb.Message{} + return &sspb.Message{} }, } diff --git a/internal/ws/router.go b/internal/ws/router.go index 26a0dd5..4e017b7 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/ss/ss_pb" +import "git.hlsq.asia/mmorpg/service-common/proto/ss/sspb" -var router map[ss_pb.MessageID]BaseRouter +var router map[sspb.MessageID]BaseRouter type BaseRouter interface { Handle(data []byte, client *Client) } func init() { - 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{} + router = make(map[sspb.MessageID]BaseRouter) + router[sspb.MessageID_MESSAGE_ID_LOGIN_SUCCESS] = &LoginSuccess{} + router[sspb.MessageID_MESSAGE_ID_QUEUE_UP] = &QueueUp{} + router[sspb.MessageID_MESSAGE_ID_ENTER_INSTANCE] = &EnterInstance{} + router[sspb.MessageID_MESSAGE_ID_POSITION] = &Position{} }