feat 包命名规范

This commit is contained in:
2026-02-11 14:49:47 +08:00
parent 3b8378cc72
commit 1b7da8d93b
5 changed files with 22 additions and 22 deletions

2
go.mod
View File

@@ -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

4
go.sum
View File

@@ -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=

View File

@@ -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,
}

View File

@@ -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{}
},
}

View File

@@ -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{}
}