feat 协议移动到Public

This commit is contained in:
2025-12-15 11:22:59 +08:00
parent 6e19d93f5e
commit 3498cf158d
45 changed files with 2730 additions and 929 deletions

View File

@@ -3,7 +3,7 @@ package ws_handler
import (
"common/log"
"common/net/socket"
"common/proto/gen/cs"
"common/proto/sc/sc_pb"
"context"
"fmt"
"go.uber.org/zap"
@@ -85,13 +85,13 @@ func (c *Client) OnEvent(event Event) {
}
// WriteMessage 向客户端发送消息
func (c *Client) WriteMessage(id cs.MessageID, data proto.Message) {
func (c *Client) WriteMessage(id sc_pb.MessageID, data proto.Message) {
d, err := proto.Marshal(data)
if err != nil {
c.logger.Errorf("WriteMessage proto.Marshal err: %v", err)
return
}
m, err := proto.Marshal(&cs.Message{
m, err := proto.Marshal(&sc_pb.Message{
ID: id,
Payload: d,
})
@@ -105,8 +105,8 @@ func (c *Client) WriteMessage(id cs.MessageID, data proto.Message) {
}
// WriteBytes 向客户端发送字节数据
func (c *Client) WriteBytes(id cs.MessageID, data []byte) {
m, err := proto.Marshal(&cs.Message{
func (c *Client) WriteBytes(id sc_pb.MessageID, data []byte) {
m, err := proto.Marshal(&sc_pb.Message{
ID: id,
Payload: data,
})

View File

@@ -2,8 +2,8 @@ package ws_handler
import (
"common/net/grpc/service"
"common/proto/gen/cs"
"common/proto/gen/grpc_pb"
"common/proto/sc/sc_pb"
"common/proto/ss/grpc_pb"
"gateway/grpc_server/stream_client"
"google.golang.org/protobuf/proto"
"time"
@@ -12,7 +12,7 @@ import (
func (c *Client) handle(event Event) {
switch e := event.(type) {
case *ClientEvent:
msg := &cs.Message{}
msg := &sc_pb.Message{}
if err := proto.Unmarshal(e.Msg, msg); err != nil {
c.logger.Errorf("handle event proto.Unmarshal err: %v", err)
c.cancel()
@@ -20,16 +20,16 @@ func (c *Client) handle(event Event) {
}
c.logger.Infof("收到客户端消息:%v", msg.ID)
switch msg.ID {
case cs.MessageID_MESSAGE_ID_ENTER_INSTANCE:
m := &cs.C2S_EnterInstance{}
case sc_pb.MessageID_MESSAGE_ID_ENTER_INSTANCE:
m := &sc_pb.C2S_EnterInstance{}
if err := proto.Unmarshal(msg.Payload, m); err != nil {
c.logger.Errorf("handle event proto.Unmarshal err: %v", err)
c.cancel()
return
}
c.onEnter(m)
case cs.MessageID_MESSAGE_ID_ACTION:
m := &cs.C2S_Action{}
case sc_pb.MessageID_MESSAGE_ID_ACTION:
m := &sc_pb.C2S_Action{}
if err := proto.Unmarshal(msg.Payload, m); err != nil {
c.logger.Errorf("handle event proto.Unmarshal err: %v", err)
c.cancel()
@@ -42,7 +42,7 @@ func (c *Client) handle(event Event) {
}
}
func (c *Client) onEnter(msg *cs.C2S_EnterInstance) {
func (c *Client) onEnter(msg *sc_pb.C2S_EnterInstance) {
client, err := service.SceneNewClient()
if err != nil {
c.logger.Errorf("SceneNewClient err: %v", err)
@@ -60,8 +60,8 @@ func (c *Client) onEnter(msg *cs.C2S_EnterInstance) {
c.SceneSID = resp.SceneSID
c.UniqueNo = resp.UniqueNo
c.InstanceID = int(msg.InstanceID)
c.WriteMessage(cs.MessageID_MESSAGE_ID_POSITION, &cs.S2C_Position{
Info: []*cs.PositionInfo{{
c.WriteMessage(sc_pb.MessageID_MESSAGE_ID_POSITION, &sc_pb.S2C_Position{
Info: []*sc_pb.PositionInfo{{
UID: int32(c.UID),
X: 1,
Y: 1,
@@ -69,7 +69,7 @@ func (c *Client) onEnter(msg *cs.C2S_EnterInstance) {
})
}
func (c *Client) onAction(msg *cs.C2S_Action) {
func (c *Client) onAction(msg *sc_pb.C2S_Action) {
if c.SceneSID == 0 {
return
}