feat sc改名ss
This commit is contained in:
2
go.mod
2
go.mod
@@ -3,7 +3,7 @@ module git.hlsq.asia/mmorpg/service-robot
|
|||||||
go 1.23.1
|
go 1.23.1
|
||||||
|
|
||||||
require (
|
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/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.9
|
google.golang.org/protobuf v1.36.9
|
||||||
|
|||||||
2
go.sum
2
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 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-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 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/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
|
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
|
||||||
|
|||||||
@@ -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/sc/sc_pb"
|
"git.hlsq.asia/mmorpg/service-common/proto/ss/ss_pb"
|
||||||
"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 := &sc_pb.Message{}
|
msg := &ss_pb.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 sc_pb.MessageID, data proto.Message) error {
|
func (c *Client) WriteMessage(msgID ss_pb.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 := &sc_pb.Message{
|
p := &ss_pb.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/sc/sc_pb"
|
"git.hlsq.asia/mmorpg/service-common/proto/ss/ss_pb"
|
||||||
"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 := &sc_pb.S2C_LoginSuccess{}
|
msg := &ss_pb.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(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,
|
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 := &sc_pb.S2C_QueueUp{}
|
msg := &ss_pb.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 := &sc_pb.S2C_EnterInstance{}
|
msg := &ss_pb.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(sc_pb.MessageID_MESSAGE_ID_ACTION, &sc_pb.C2S_Action{
|
_ = client.WriteMessage(ss_pb.MessageID_MESSAGE_ID_ACTION, &ss_pb.C2S_Action{
|
||||||
Sequence: 0,
|
Sequence: 0,
|
||||||
Timestamp: 0,
|
Timestamp: 0,
|
||||||
Action: sc_pb.ActionID_ACTION_ID_MOVE,
|
Action: ss_pb.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 &sc_pb.Message{}
|
return &ss_pb.Message{}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ type Position struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (_ *Position) Handle(data []byte, client *Client) {
|
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 {
|
//if err := proto.Unmarshal(data, msg); err != nil {
|
||||||
// log.Errorf("handle msg error")
|
// log.Errorf("handle msg error")
|
||||||
// client.Stop()
|
// client.Stop()
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
package ws
|
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 {
|
type BaseRouter interface {
|
||||||
Handle(data []byte, client *Client)
|
Handle(data []byte, client *Client)
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
router = make(map[sc_pb.MessageID]BaseRouter)
|
router = make(map[ss_pb.MessageID]BaseRouter)
|
||||||
router[sc_pb.MessageID_MESSAGE_ID_LOGIN_SUCCESS] = &LoginSuccess{}
|
router[ss_pb.MessageID_MESSAGE_ID_LOGIN_SUCCESS] = &LoginSuccess{}
|
||||||
router[sc_pb.MessageID_MESSAGE_ID_QUEUE_UP] = &QueueUp{}
|
router[ss_pb.MessageID_MESSAGE_ID_QUEUE_UP] = &QueueUp{}
|
||||||
router[sc_pb.MessageID_MESSAGE_ID_ENTER_INSTANCE] = &EnterInstance{}
|
router[ss_pb.MessageID_MESSAGE_ID_ENTER_INSTANCE] = &EnterInstance{}
|
||||||
router[sc_pb.MessageID_MESSAGE_ID_POSITION] = &Position{}
|
router[ss_pb.MessageID_MESSAGE_ID_POSITION] = &Position{}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user