根据框架调整
This commit is contained in:
parent
0143d8a0ad
commit
89557ad9e4
@ -1,7 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
|
||||
protoc -I=. --proto_path=./ --go_out=../../ *.proto
|
||||
|
||||
echo "success"
|
@ -1,21 +0,0 @@
|
||||
syntax = "proto3";
|
||||
package ipb;
|
||||
option go_package = "common/proto/ipb";
|
||||
|
||||
enum MsgId
|
||||
{
|
||||
Unknown = 0;
|
||||
Internal = -1; // 内部消息id
|
||||
}
|
||||
|
||||
|
||||
message InternalMsg
|
||||
{
|
||||
string service_name = 1; // 该服务类型下的具体的服务节点名,需要保证该消息是该服务节点发的。否则可能会导致客户端出现路由错误
|
||||
uint32 conn_id = 2; // 刚登陆时没有user_id,只有conn_id
|
||||
int64 user_id = 3; // 玩家id
|
||||
int32 msg_id = 4; // 消息id
|
||||
bytes msg = 5; // 消息
|
||||
}
|
||||
|
||||
|
@ -1,210 +0,0 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.36.6
|
||||
// protoc v6.31.0
|
||||
// source: internal.proto
|
||||
|
||||
package ipb
|
||||
|
||||
import (
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
unsafe "unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
type MsgId int32
|
||||
|
||||
const (
|
||||
MsgId_Unknown MsgId = 0
|
||||
MsgId_Internal MsgId = -1 // 内部消息id
|
||||
)
|
||||
|
||||
// Enum value maps for MsgId.
|
||||
var (
|
||||
MsgId_name = map[int32]string{
|
||||
0: "Unknown",
|
||||
-1: "Internal",
|
||||
}
|
||||
MsgId_value = map[string]int32{
|
||||
"Unknown": 0,
|
||||
"Internal": -1,
|
||||
}
|
||||
)
|
||||
|
||||
func (x MsgId) Enum() *MsgId {
|
||||
p := new(MsgId)
|
||||
*p = x
|
||||
return p
|
||||
}
|
||||
|
||||
func (x MsgId) String() string {
|
||||
return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
|
||||
}
|
||||
|
||||
func (MsgId) Descriptor() protoreflect.EnumDescriptor {
|
||||
return file_internal_proto_enumTypes[0].Descriptor()
|
||||
}
|
||||
|
||||
func (MsgId) Type() protoreflect.EnumType {
|
||||
return &file_internal_proto_enumTypes[0]
|
||||
}
|
||||
|
||||
func (x MsgId) Number() protoreflect.EnumNumber {
|
||||
return protoreflect.EnumNumber(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use MsgId.Descriptor instead.
|
||||
func (MsgId) EnumDescriptor() ([]byte, []int) {
|
||||
return file_internal_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
type InternalMsg struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
ServiceName string `protobuf:"bytes,1,opt,name=service_name,json=serviceName,proto3" json:"service_name,omitempty"` // 该服务类型下的具体的服务节点名,需要保证该消息是该服务节点发的。否则可能会导致客户端出现路由错误
|
||||
ConnId uint32 `protobuf:"varint,2,opt,name=conn_id,json=connId,proto3" json:"conn_id,omitempty"` // 刚登陆时没有user_id,只有conn_id
|
||||
UserId int64 `protobuf:"varint,3,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"` // 玩家id
|
||||
MsgId int32 `protobuf:"varint,4,opt,name=msg_id,json=msgId,proto3" json:"msg_id,omitempty"` // 消息id
|
||||
Msg []byte `protobuf:"bytes,5,opt,name=msg,proto3" json:"msg,omitempty"` // 消息
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *InternalMsg) Reset() {
|
||||
*x = InternalMsg{}
|
||||
mi := &file_internal_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *InternalMsg) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*InternalMsg) ProtoMessage() {}
|
||||
|
||||
func (x *InternalMsg) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_internal_proto_msgTypes[0]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use InternalMsg.ProtoReflect.Descriptor instead.
|
||||
func (*InternalMsg) Descriptor() ([]byte, []int) {
|
||||
return file_internal_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *InternalMsg) GetServiceName() string {
|
||||
if x != nil {
|
||||
return x.ServiceName
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *InternalMsg) GetConnId() uint32 {
|
||||
if x != nil {
|
||||
return x.ConnId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *InternalMsg) GetUserId() int64 {
|
||||
if x != nil {
|
||||
return x.UserId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *InternalMsg) GetMsgId() int32 {
|
||||
if x != nil {
|
||||
return x.MsgId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *InternalMsg) GetMsg() []byte {
|
||||
if x != nil {
|
||||
return x.Msg
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var File_internal_proto protoreflect.FileDescriptor
|
||||
|
||||
const file_internal_proto_rawDesc = "" +
|
||||
"\n" +
|
||||
"\x0einternal.proto\x12\x03ipb\"\x8b\x01\n" +
|
||||
"\vInternalMsg\x12!\n" +
|
||||
"\fservice_name\x18\x01 \x01(\tR\vserviceName\x12\x17\n" +
|
||||
"\aconn_id\x18\x02 \x01(\rR\x06connId\x12\x17\n" +
|
||||
"\auser_id\x18\x03 \x01(\x03R\x06userId\x12\x15\n" +
|
||||
"\x06msg_id\x18\x04 \x01(\x05R\x05msgId\x12\x10\n" +
|
||||
"\x03msg\x18\x05 \x01(\fR\x03msg*+\n" +
|
||||
"\x05MsgId\x12\v\n" +
|
||||
"\aUnknown\x10\x00\x12\x15\n" +
|
||||
"\bInternal\x10\xff\xff\xff\xff\xff\xff\xff\xff\xff\x01B\x12Z\x10common/proto/ipbb\x06proto3"
|
||||
|
||||
var (
|
||||
file_internal_proto_rawDescOnce sync.Once
|
||||
file_internal_proto_rawDescData []byte
|
||||
)
|
||||
|
||||
func file_internal_proto_rawDescGZIP() []byte {
|
||||
file_internal_proto_rawDescOnce.Do(func() {
|
||||
file_internal_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_internal_proto_rawDesc), len(file_internal_proto_rawDesc)))
|
||||
})
|
||||
return file_internal_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_internal_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
|
||||
var file_internal_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
|
||||
var file_internal_proto_goTypes = []any{
|
||||
(MsgId)(0), // 0: ipb.MsgId
|
||||
(*InternalMsg)(nil), // 1: ipb.InternalMsg
|
||||
}
|
||||
var file_internal_proto_depIdxs = []int32{
|
||||
0, // [0:0] is the sub-list for method output_type
|
||||
0, // [0:0] is the sub-list for method input_type
|
||||
0, // [0:0] is the sub-list for extension type_name
|
||||
0, // [0:0] is the sub-list for extension extendee
|
||||
0, // [0:0] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_internal_proto_init() }
|
||||
func file_internal_proto_init() {
|
||||
if File_internal_proto != nil {
|
||||
return
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: unsafe.Slice(unsafe.StringData(file_internal_proto_rawDesc), len(file_internal_proto_rawDesc)),
|
||||
NumEnums: 1,
|
||||
NumMessages: 1,
|
||||
NumExtensions: 0,
|
||||
NumServices: 0,
|
||||
},
|
||||
GoTypes: file_internal_proto_goTypes,
|
||||
DependencyIndexes: file_internal_proto_depIdxs,
|
||||
EnumInfos: file_internal_proto_enumTypes,
|
||||
MessageInfos: file_internal_proto_msgTypes,
|
||||
}.Build()
|
||||
File_internal_proto = out.File
|
||||
file_internal_proto_goTypes = nil
|
||||
file_internal_proto_depIdxs = nil
|
||||
}
|
@ -2,12 +2,12 @@ package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"game/common/proto/ipb"
|
||||
"game/common/proto/pb"
|
||||
"game/common/serviceName"
|
||||
"game/common/userBindService"
|
||||
"game/server/chat/config"
|
||||
"game/server/chat/model"
|
||||
"github.com/fox/fox/ipb"
|
||||
"github.com/fox/fox/log"
|
||||
"github.com/fox/fox/processor"
|
||||
"github.com/fox/fox/service"
|
||||
@ -101,15 +101,12 @@ func (s *ChatService) OnMessage(data []byte) error {
|
||||
|
||||
// 向内部服务发送消息
|
||||
func (s *ChatService) SendServiceData(topic string, userId int64, msgId int32, data []byte) {
|
||||
iMsg := &ipb.InternalMsg{ConnId: 0, UserId: userId, MsgId: msgId, Msg: data}
|
||||
dMsg, _ := proto.Marshal(iMsg)
|
||||
_ = s.Send(topic, dMsg)
|
||||
iMsg := ipb.MakeMsg(s.Name(), 0, userId, msgId, data)
|
||||
_ = s.Send(topic, iMsg)
|
||||
}
|
||||
|
||||
// 向内部服务发送消息
|
||||
func (s *ChatService) SendServiceMsg(topic string, userId int64, msgId int32, msg proto.Message) {
|
||||
iMsg := &ipb.InternalMsg{ConnId: 0, UserId: userId, MsgId: msgId}
|
||||
iMsg.Msg, _ = proto.Marshal(msg)
|
||||
dMsg, _ := proto.Marshal(iMsg)
|
||||
_ = s.Send(topic, dMsg)
|
||||
data, _ := proto.Marshal(msg)
|
||||
s.SendServiceData(topic, userId, msgId, data)
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"game/common/proto/ipb"
|
||||
"game/common/proto/pb"
|
||||
"game/common/topicName"
|
||||
"github.com/fox/fox/ipb"
|
||||
"github.com/fox/fox/processor"
|
||||
"github.com/fox/fox/service"
|
||||
"github.com/fox/fox/ws"
|
||||
|
@ -2,7 +2,6 @@ package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"game/common/proto/ipb"
|
||||
"game/common/proto/pb"
|
||||
"game/common/serviceName"
|
||||
"game/common/topicName"
|
||||
@ -10,6 +9,7 @@ import (
|
||||
"game/common/utils"
|
||||
"game/server/gate/config"
|
||||
"game/server/gate/model"
|
||||
"github.com/fox/fox/ipb"
|
||||
"github.com/fox/fox/log"
|
||||
"github.com/fox/fox/processor"
|
||||
"github.com/fox/fox/service"
|
||||
@ -185,9 +185,8 @@ func (s *GateService) WsOnMessage(conn ws.IConn, data []byte) {
|
||||
|
||||
// 向内部服务发送消息
|
||||
func (s *GateService) SendServiceData(topic string, conn ws.IConn, msgId int32, data []byte) {
|
||||
iMsg := &ipb.InternalMsg{ServiceName: s.Name(), ConnId: conn.Id(), UserId: conn.UserId(), MsgId: msgId, Msg: data}
|
||||
dMsg, _ := proto.Marshal(iMsg)
|
||||
_ = s.Send(topic, dMsg)
|
||||
iMsg := ipb.MakeMsg(s.Name(), conn.Id(), conn.UserId(), msgId, data)
|
||||
_ = s.Send(topic, iMsg)
|
||||
}
|
||||
|
||||
// 向内部服务发送消息
|
||||
|
@ -2,12 +2,12 @@ package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"game/common/proto/ipb"
|
||||
"game/common/proto/pb"
|
||||
"game/common/serviceName"
|
||||
"game/common/userBindService"
|
||||
"game/server/login/config"
|
||||
"game/server/login/model"
|
||||
"github.com/fox/fox/ipb"
|
||||
"github.com/fox/fox/log"
|
||||
"github.com/fox/fox/processor"
|
||||
"github.com/fox/fox/service"
|
||||
@ -101,15 +101,12 @@ func (s *LoginService) OnMessage(data []byte) error {
|
||||
|
||||
// 向内部服务发送消息
|
||||
func (s *LoginService) SendServiceData(topic string, connId uint32, userId int64, msgId int32, data []byte) {
|
||||
iMsg := &ipb.InternalMsg{ConnId: connId, UserId: userId, MsgId: msgId, Msg: data}
|
||||
dMsg, _ := proto.Marshal(iMsg)
|
||||
_ = s.Send(topic, dMsg)
|
||||
iMsg := ipb.MakeMsg(s.Name(), connId, userId, msgId, data)
|
||||
_ = s.Send(topic, iMsg)
|
||||
}
|
||||
|
||||
// 向内部服务发送消息
|
||||
func (s *LoginService) SendServiceMsg(topic string, connId uint32, userId int64, msgId int32, msg proto.Message) {
|
||||
iMsg := &ipb.InternalMsg{ConnId: connId, UserId: userId, MsgId: msgId}
|
||||
iMsg.Msg, _ = proto.Marshal(msg)
|
||||
dMsg, _ := proto.Marshal(iMsg)
|
||||
_ = s.Send(topic, dMsg)
|
||||
data, _ := proto.Marshal(msg)
|
||||
s.SendServiceData(topic, connId, userId, msgId, data)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user