feat 包命名规范
This commit is contained in:
2
go.mod
2
go.mod
@@ -3,7 +3,7 @@ module git.hlsq.asia/mmorpg/service-robot
|
|||||||
go 1.24.0
|
go 1.24.0
|
||||||
|
|
||||||
require (
|
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/gorilla/websocket v1.5.3
|
||||||
github.com/judwhite/go-svc v1.2.1
|
github.com/judwhite/go-svc v1.2.1
|
||||||
google.golang.org/protobuf v1.36.10
|
google.golang.org/protobuf v1.36.10
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -1,7 +1,7 @@
|
|||||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
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-20260211064821-558677bc3a2e h1:MNVS1NXNVn4DeTZPcvvA8YFM8afCzZedLPUYMffNgZs=
|
||||||
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/go.mod h1:mMhZcumphj6gaVTppVYsMTkd+5HupmQgAc53Pd4MH9I=
|
||||||
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
|
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
|
||||||
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||||
github.com/IBM/sarama v1.46.3 h1:njRsX6jNlnR+ClJ8XmkO+CM4unbrNr/2vB5KK6UA+IE=
|
github.com/IBM/sarama v1.46.3 h1:njRsX6jNlnR+ClJ8XmkO+CM4unbrNr/2vB5KK6UA+IE=
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.hlsq.asia/mmorpg/service-common/log"
|
"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"
|
"git.hlsq.asia/mmorpg/service-common/utils"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
@@ -100,7 +100,7 @@ func (c *Client) startReader() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := &ss_pb.Message{}
|
msg := &sspb.Message{}
|
||||||
if err = proto.Unmarshal(msgByte, msg); err != nil {
|
if err = proto.Unmarshal(msgByte, msg); err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -132,12 +132,12 @@ func (c *Client) startWriter() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WriteMessage 发送消息给服务器
|
// 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)
|
d, err := proto.Marshal(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
p := &ss_pb.Message{
|
p := &sspb.Message{
|
||||||
ID: msgID,
|
ID: msgID,
|
||||||
Payload: d,
|
Payload: d,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package ws
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"git.hlsq.asia/mmorpg/service-common/log"
|
"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"
|
"google.golang.org/protobuf/proto"
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
@@ -14,14 +14,14 @@ type LoginSuccess struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (_ *LoginSuccess) Handle(data []byte, client *Client) {
|
func (_ *LoginSuccess) Handle(data []byte, client *Client) {
|
||||||
msg := &ss_pb.S2C_LoginSuccess{}
|
msg := &sspb.S2C_LoginSuccess{}
|
||||||
if err := proto.Unmarshal(data, msg); err != nil {
|
if err := proto.Unmarshal(data, msg); err != nil {
|
||||||
log.Errorf("handle msg error")
|
log.Errorf("handle msg error")
|
||||||
client.Stop()
|
client.Stop()
|
||||||
return
|
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,
|
InstanceID: msg.InstanceID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,7 @@ type QueueUp struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (_ *QueueUp) Handle(data []byte, client *Client) {
|
func (_ *QueueUp) Handle(data []byte, client *Client) {
|
||||||
msg := &ss_pb.S2C_QueueUp{}
|
msg := &sspb.S2C_QueueUp{}
|
||||||
if err := proto.Unmarshal(data, msg); err != nil {
|
if err := proto.Unmarshal(data, msg); err != nil {
|
||||||
log.Errorf("handle msg error")
|
log.Errorf("handle msg error")
|
||||||
client.Stop()
|
client.Stop()
|
||||||
@@ -42,7 +42,7 @@ type EnterInstance struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (_ *EnterInstance) Handle(data []byte, client *Client) {
|
func (_ *EnterInstance) Handle(data []byte, client *Client) {
|
||||||
msg := &ss_pb.S2C_EnterInstance{}
|
msg := &sspb.S2C_EnterInstance{}
|
||||||
if err := proto.Unmarshal(data, msg); err != nil {
|
if err := proto.Unmarshal(data, msg); err != nil {
|
||||||
log.Errorf("handle msg error")
|
log.Errorf("handle msg error")
|
||||||
client.Stop()
|
client.Stop()
|
||||||
@@ -65,10 +65,10 @@ func (_ *EnterInstance) Handle(data []byte, client *Client) {
|
|||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
x, y := randDir()
|
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,
|
Sequence: 0,
|
||||||
Timestamp: 0,
|
Timestamp: 0,
|
||||||
Action: ss_pb.ActionID_ACTION_ID_MOVE,
|
Action: sspb.ActionID_ACTION_ID_MOVE,
|
||||||
DirX: int32(x * 100),
|
DirX: int32(x * 100),
|
||||||
DirY: int32(y * 100),
|
DirY: int32(y * 100),
|
||||||
SkillID: 0,
|
SkillID: 0,
|
||||||
@@ -80,7 +80,7 @@ func (_ *EnterInstance) Handle(data []byte, client *Client) {
|
|||||||
|
|
||||||
var s2cPositionPool = sync.Pool{
|
var s2cPositionPool = sync.Pool{
|
||||||
New: func() interface{} {
|
New: func() interface{} {
|
||||||
return &ss_pb.Message{}
|
return &sspb.Message{}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
package ws
|
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 {
|
type BaseRouter interface {
|
||||||
Handle(data []byte, client *Client)
|
Handle(data []byte, client *Client)
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
router = make(map[ss_pb.MessageID]BaseRouter)
|
router = make(map[sspb.MessageID]BaseRouter)
|
||||||
router[ss_pb.MessageID_MESSAGE_ID_LOGIN_SUCCESS] = &LoginSuccess{}
|
router[sspb.MessageID_MESSAGE_ID_LOGIN_SUCCESS] = &LoginSuccess{}
|
||||||
router[ss_pb.MessageID_MESSAGE_ID_QUEUE_UP] = &QueueUp{}
|
router[sspb.MessageID_MESSAGE_ID_QUEUE_UP] = &QueueUp{}
|
||||||
router[ss_pb.MessageID_MESSAGE_ID_ENTER_INSTANCE] = &EnterInstance{}
|
router[sspb.MessageID_MESSAGE_ID_ENTER_INSTANCE] = &EnterInstance{}
|
||||||
router[ss_pb.MessageID_MESSAGE_ID_POSITION] = &Position{}
|
router[sspb.MessageID_MESSAGE_ID_POSITION] = &Position{}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user