添加proto文件
This commit is contained in:
parent
0cb4a0f8d8
commit
491e45d7cf
@ -3,6 +3,7 @@ package config
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/fox/fox/log"
|
||||
@ -10,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
ModeDev = "dev" // 开发服
|
||||
//ModeDev = "dev" // 开发服
|
||||
etcdKey = "etcd_config"
|
||||
etcdAddress = "114.132.124.145:2379"
|
||||
natsKey = "nats_config"
|
||||
@ -19,7 +20,7 @@ const (
|
||||
|
||||
func LoadSpecialConfig[T any](rd *redis.Client, specialKey string, comm *Common[T]) error {
|
||||
s, err := rd.Get(context.Background(), specialKey).Result()
|
||||
if err != nil && err != redis.Nil {
|
||||
if err != nil && !errors.Is(err, redis.Nil) {
|
||||
log.FatalF("init config:%v", err)
|
||||
return err
|
||||
}
|
||||
@ -43,7 +44,7 @@ func LoadCommonConfig[T any](rd *redis.Client) (*Common[T], error) {
|
||||
var comm Common[T]
|
||||
comm.Special = &ret.Value
|
||||
s, err := rd.Get(context.Background(), etcdKey).Result()
|
||||
if err != nil && err != redis.Nil {
|
||||
if err != nil && !errors.Is(err, redis.Nil) {
|
||||
log.FatalF("init config:%v", err)
|
||||
return nil, err
|
||||
}
|
||||
@ -61,7 +62,7 @@ func LoadCommonConfig[T any](rd *redis.Client) (*Common[T], error) {
|
||||
err = json.Unmarshal([]byte(s), &comm.Etcd)
|
||||
}
|
||||
s, err = rd.Get(context.Background(), natsKey).Result()
|
||||
if err != nil && err != redis.Nil {
|
||||
if err != nil && !errors.Is(err, redis.Nil) {
|
||||
log.FatalF("init config:%v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
7
common/internalPb/gene_proto.sh
Normal file
7
common/internalPb/gene_proto.sh
Normal file
@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
|
||||
protoc -I=. --proto_path=./ --go_out=../../ *.proto
|
||||
|
||||
echo "success"
|
11
common/pb/code.proto
Normal file
11
common/pb/code.proto
Normal file
@ -0,0 +1,11 @@
|
||||
syntax = "proto3";
|
||||
package internal;
|
||||
option go_package = "common/proto";
|
||||
|
||||
enum ErrCode
|
||||
{
|
||||
OK = 0;
|
||||
LoginFail = 1; // 登陆失败
|
||||
}
|
||||
|
||||
|
7
common/pb/gene_proto.sh
Normal file
7
common/pb/gene_proto.sh
Normal file
@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
|
||||
protoc -I=. --proto_path=./ --go_out=../../ *.proto
|
||||
|
||||
echo "success"
|
27
common/pb/login.proto
Normal file
27
common/pb/login.proto
Normal file
@ -0,0 +1,27 @@
|
||||
syntax = "proto3";
|
||||
package internal;
|
||||
option go_package = "common/proto";
|
||||
|
||||
import "code.proto";
|
||||
|
||||
enum LoginMsgId
|
||||
{
|
||||
Unknown = 0;
|
||||
C2SLogin = 1; // 玩家登陆
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 玩家登陆
|
||||
message C2SLoginMsg
|
||||
{
|
||||
string username = 1; // 用户名
|
||||
string token = 2; // 密码或token
|
||||
string version = 3; // 版本
|
||||
}
|
||||
|
||||
message S2CLoginMsg
|
||||
{
|
||||
ErrCode code = 1;
|
||||
}
|
||||
|
126
common/proto/code.pb.go
Normal file
126
common/proto/code.pb.go
Normal file
@ -0,0 +1,126 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.36.6
|
||||
// protoc v6.31.0
|
||||
// source: code.proto
|
||||
|
||||
package proto
|
||||
|
||||
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 ErrCode int32
|
||||
|
||||
const (
|
||||
ErrCode_OK ErrCode = 0
|
||||
ErrCode_LoginFail ErrCode = 1 // 登陆失败
|
||||
)
|
||||
|
||||
// Enum value maps for ErrCode.
|
||||
var (
|
||||
ErrCode_name = map[int32]string{
|
||||
0: "OK",
|
||||
1: "LoginFail",
|
||||
}
|
||||
ErrCode_value = map[string]int32{
|
||||
"OK": 0,
|
||||
"LoginFail": 1,
|
||||
}
|
||||
)
|
||||
|
||||
func (x ErrCode) Enum() *ErrCode {
|
||||
p := new(ErrCode)
|
||||
*p = x
|
||||
return p
|
||||
}
|
||||
|
||||
func (x ErrCode) String() string {
|
||||
return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
|
||||
}
|
||||
|
||||
func (ErrCode) Descriptor() protoreflect.EnumDescriptor {
|
||||
return file_code_proto_enumTypes[0].Descriptor()
|
||||
}
|
||||
|
||||
func (ErrCode) Type() protoreflect.EnumType {
|
||||
return &file_code_proto_enumTypes[0]
|
||||
}
|
||||
|
||||
func (x ErrCode) Number() protoreflect.EnumNumber {
|
||||
return protoreflect.EnumNumber(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use ErrCode.Descriptor instead.
|
||||
func (ErrCode) EnumDescriptor() ([]byte, []int) {
|
||||
return file_code_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
var File_code_proto protoreflect.FileDescriptor
|
||||
|
||||
const file_code_proto_rawDesc = "" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
"code.proto\x12\binternal* \n" +
|
||||
"\aErrCode\x12\x06\n" +
|
||||
"\x02OK\x10\x00\x12\r\n" +
|
||||
"\tLoginFail\x10\x01B\x0eZ\fcommon/protob\x06proto3"
|
||||
|
||||
var (
|
||||
file_code_proto_rawDescOnce sync.Once
|
||||
file_code_proto_rawDescData []byte
|
||||
)
|
||||
|
||||
func file_code_proto_rawDescGZIP() []byte {
|
||||
file_code_proto_rawDescOnce.Do(func() {
|
||||
file_code_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_code_proto_rawDesc), len(file_code_proto_rawDesc)))
|
||||
})
|
||||
return file_code_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_code_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
|
||||
var file_code_proto_goTypes = []any{
|
||||
(ErrCode)(0), // 0: internal.ErrCode
|
||||
}
|
||||
var file_code_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_code_proto_init() }
|
||||
func file_code_proto_init() {
|
||||
if File_code_proto != nil {
|
||||
return
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: unsafe.Slice(unsafe.StringData(file_code_proto_rawDesc), len(file_code_proto_rawDesc)),
|
||||
NumEnums: 1,
|
||||
NumMessages: 0,
|
||||
NumExtensions: 0,
|
||||
NumServices: 0,
|
||||
},
|
||||
GoTypes: file_code_proto_goTypes,
|
||||
DependencyIndexes: file_code_proto_depIdxs,
|
||||
EnumInfos: file_code_proto_enumTypes,
|
||||
}.Build()
|
||||
File_code_proto = out.File
|
||||
file_code_proto_goTypes = nil
|
||||
file_code_proto_depIdxs = nil
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.34.1
|
||||
// protoc v4.25.2
|
||||
// protoc-gen-go v1.36.6
|
||||
// protoc v6.31.0
|
||||
// source: internal.proto
|
||||
|
||||
package internal
|
||||
@ -11,6 +11,7 @@ import (
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
unsafe "unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -67,22 +68,19 @@ func (MsgId) EnumDescriptor() ([]byte, []int) {
|
||||
}
|
||||
|
||||
type InternalMsg struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
UserId int64 `protobuf:"varint,1,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"` // 玩家id
|
||||
MsgId int32 `protobuf:"varint,2,opt,name=msg_id,json=msgId,proto3" json:"msg_id,omitempty"` // 消息id
|
||||
Msg []byte `protobuf:"bytes,3,opt,name=msg,proto3" json:"msg,omitempty"` // 消息
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
UserId int64 `protobuf:"varint,1,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"` // 玩家id
|
||||
MsgId int32 `protobuf:"varint,2,opt,name=msg_id,json=msgId,proto3" json:"msg_id,omitempty"` // 消息id
|
||||
Msg []byte `protobuf:"bytes,3,opt,name=msg,proto3" json:"msg,omitempty"` // 消息
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *InternalMsg) Reset() {
|
||||
*x = InternalMsg{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_internal_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
mi := &file_internal_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *InternalMsg) String() string {
|
||||
@ -93,7 +91,7 @@ func (*InternalMsg) ProtoMessage() {}
|
||||
|
||||
func (x *InternalMsg) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_internal_proto_msgTypes[0]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
@ -131,23 +129,20 @@ func (x *InternalMsg) GetMsg() []byte {
|
||||
|
||||
// 网关解包客户端消息
|
||||
type C2SMessage struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
ServiceType int32 `protobuf:"varint,1,opt,name=service_type,json=serviceType,proto3" json:"service_type,omitempty"` // 服务类型,通过该值判断发往lobby,game,chat等内部服务
|
||||
MsgId int32 `protobuf:"varint,2,opt,name=msg_id,json=msgId,proto3" json:"msg_id,omitempty"` // 消息id
|
||||
UserId int64 `protobuf:"varint,3,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"` // 玩家id
|
||||
Msg []byte `protobuf:"bytes,4,opt,name=msg,proto3" json:"msg,omitempty"` // 消息
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
ServiceType int32 `protobuf:"varint,1,opt,name=service_type,json=serviceType,proto3" json:"service_type,omitempty"` // 服务类型,通过该值判断发往lobby,game,chat等内部服务
|
||||
MsgId int32 `protobuf:"varint,2,opt,name=msg_id,json=msgId,proto3" json:"msg_id,omitempty"` // 消息id
|
||||
UserId int64 `protobuf:"varint,3,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"` // 玩家id
|
||||
Msg []byte `protobuf:"bytes,4,opt,name=msg,proto3" json:"msg,omitempty"` // 消息
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *C2SMessage) Reset() {
|
||||
*x = C2SMessage{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_internal_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
mi := &file_internal_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *C2SMessage) String() string {
|
||||
@ -158,7 +153,7 @@ func (*C2SMessage) ProtoMessage() {}
|
||||
|
||||
func (x *C2SMessage) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_internal_proto_msgTypes[1]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
@ -203,43 +198,38 @@ func (x *C2SMessage) GetMsg() []byte {
|
||||
|
||||
var File_internal_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_internal_proto_rawDesc = []byte{
|
||||
0x0a, 0x0e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
||||
0x12, 0x08, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x22, 0x4f, 0x0a, 0x0b, 0x49, 0x6e,
|
||||
0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65,
|
||||
0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72,
|
||||
0x49, 0x64, 0x12, 0x15, 0x0a, 0x06, 0x6d, 0x73, 0x67, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01,
|
||||
0x28, 0x05, 0x52, 0x05, 0x6d, 0x73, 0x67, 0x49, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67,
|
||||
0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x22, 0x71, 0x0a, 0x0a, 0x43,
|
||||
0x32, 0x53, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x73, 0x65, 0x72,
|
||||
0x76, 0x69, 0x63, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52,
|
||||
0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x15, 0x0a, 0x06,
|
||||
0x6d, 0x73, 0x67, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x6d, 0x73,
|
||||
0x67, 0x49, 0x64, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x03,
|
||||
0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x10, 0x0a, 0x03,
|
||||
0x6d, 0x73, 0x67, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x2a, 0x2b,
|
||||
0x0a, 0x05, 0x4d, 0x73, 0x67, 0x49, 0x64, 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x6e, 0x6b, 0x6e, 0x6f,
|
||||
0x77, 0x6e, 0x10, 0x00, 0x12, 0x15, 0x0a, 0x08, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c,
|
||||
0x10, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x42, 0x17, 0x5a, 0x15, 0x63,
|
||||
0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x69, 0x6e, 0x74, 0x65,
|
||||
0x72, 0x6e, 0x61, 0x6c, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
const file_internal_proto_rawDesc = "" +
|
||||
"\n" +
|
||||
"\x0einternal.proto\x12\binternal\"O\n" +
|
||||
"\vInternalMsg\x12\x17\n" +
|
||||
"\auser_id\x18\x01 \x01(\x03R\x06userId\x12\x15\n" +
|
||||
"\x06msg_id\x18\x02 \x01(\x05R\x05msgId\x12\x10\n" +
|
||||
"\x03msg\x18\x03 \x01(\fR\x03msg\"q\n" +
|
||||
"\n" +
|
||||
"C2SMessage\x12!\n" +
|
||||
"\fservice_type\x18\x01 \x01(\x05R\vserviceType\x12\x15\n" +
|
||||
"\x06msg_id\x18\x02 \x01(\x05R\x05msgId\x12\x17\n" +
|
||||
"\auser_id\x18\x03 \x01(\x03R\x06userId\x12\x10\n" +
|
||||
"\x03msg\x18\x04 \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\x17Z\x15common/proto/internalb\x06proto3"
|
||||
|
||||
var (
|
||||
file_internal_proto_rawDescOnce sync.Once
|
||||
file_internal_proto_rawDescData = file_internal_proto_rawDesc
|
||||
file_internal_proto_rawDescData []byte
|
||||
)
|
||||
|
||||
func file_internal_proto_rawDescGZIP() []byte {
|
||||
file_internal_proto_rawDescOnce.Do(func() {
|
||||
file_internal_proto_rawDescData = protoimpl.X.CompressGZIP(file_internal_proto_rawDescData)
|
||||
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, 2)
|
||||
var file_internal_proto_goTypes = []interface{}{
|
||||
var file_internal_proto_goTypes = []any{
|
||||
(MsgId)(0), // 0: internal.MsgId
|
||||
(*InternalMsg)(nil), // 1: internal.InternalMsg
|
||||
(*C2SMessage)(nil), // 2: internal.C2SMessage
|
||||
@ -257,37 +247,11 @@ func file_internal_proto_init() {
|
||||
if File_internal_proto != nil {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_internal_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*InternalMsg); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_internal_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*C2SMessage); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_internal_proto_rawDesc,
|
||||
RawDescriptor: unsafe.Slice(unsafe.StringData(file_internal_proto_rawDesc), len(file_internal_proto_rawDesc)),
|
||||
NumEnums: 1,
|
||||
NumMessages: 2,
|
||||
NumExtensions: 0,
|
||||
@ -299,7 +263,6 @@ func file_internal_proto_init() {
|
||||
MessageInfos: file_internal_proto_msgTypes,
|
||||
}.Build()
|
||||
File_internal_proto = out.File
|
||||
file_internal_proto_rawDesc = nil
|
||||
file_internal_proto_goTypes = nil
|
||||
file_internal_proto_depIdxs = nil
|
||||
}
|
||||
|
245
common/proto/login.pb.go
Normal file
245
common/proto/login.pb.go
Normal file
@ -0,0 +1,245 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.36.6
|
||||
// protoc v6.31.0
|
||||
// source: login.proto
|
||||
|
||||
package proto
|
||||
|
||||
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 LoginMsgId int32
|
||||
|
||||
const (
|
||||
LoginMsgId_Unknown LoginMsgId = 0
|
||||
LoginMsgId_C2SLogin LoginMsgId = 1 // 玩家登陆
|
||||
)
|
||||
|
||||
// Enum value maps for LoginMsgId.
|
||||
var (
|
||||
LoginMsgId_name = map[int32]string{
|
||||
0: "Unknown",
|
||||
1: "C2SLogin",
|
||||
}
|
||||
LoginMsgId_value = map[string]int32{
|
||||
"Unknown": 0,
|
||||
"C2SLogin": 1,
|
||||
}
|
||||
)
|
||||
|
||||
func (x LoginMsgId) Enum() *LoginMsgId {
|
||||
p := new(LoginMsgId)
|
||||
*p = x
|
||||
return p
|
||||
}
|
||||
|
||||
func (x LoginMsgId) String() string {
|
||||
return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
|
||||
}
|
||||
|
||||
func (LoginMsgId) Descriptor() protoreflect.EnumDescriptor {
|
||||
return file_login_proto_enumTypes[0].Descriptor()
|
||||
}
|
||||
|
||||
func (LoginMsgId) Type() protoreflect.EnumType {
|
||||
return &file_login_proto_enumTypes[0]
|
||||
}
|
||||
|
||||
func (x LoginMsgId) Number() protoreflect.EnumNumber {
|
||||
return protoreflect.EnumNumber(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use LoginMsgId.Descriptor instead.
|
||||
func (LoginMsgId) EnumDescriptor() ([]byte, []int) {
|
||||
return file_login_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
// 玩家登陆
|
||||
type C2SLoginMsg struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"` // 用户名
|
||||
Token string `protobuf:"bytes,2,opt,name=token,proto3" json:"token,omitempty"` // 密码或token
|
||||
Version string `protobuf:"bytes,3,opt,name=version,proto3" json:"version,omitempty"` // 版本
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *C2SLoginMsg) Reset() {
|
||||
*x = C2SLoginMsg{}
|
||||
mi := &file_login_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *C2SLoginMsg) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*C2SLoginMsg) ProtoMessage() {}
|
||||
|
||||
func (x *C2SLoginMsg) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_login_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 C2SLoginMsg.ProtoReflect.Descriptor instead.
|
||||
func (*C2SLoginMsg) Descriptor() ([]byte, []int) {
|
||||
return file_login_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *C2SLoginMsg) GetUsername() string {
|
||||
if x != nil {
|
||||
return x.Username
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *C2SLoginMsg) GetToken() string {
|
||||
if x != nil {
|
||||
return x.Token
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *C2SLoginMsg) GetVersion() string {
|
||||
if x != nil {
|
||||
return x.Version
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type S2CLoginMsg struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Code ErrCode `protobuf:"varint,1,opt,name=code,proto3,enum=internal.ErrCode" json:"code,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *S2CLoginMsg) Reset() {
|
||||
*x = S2CLoginMsg{}
|
||||
mi := &file_login_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *S2CLoginMsg) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*S2CLoginMsg) ProtoMessage() {}
|
||||
|
||||
func (x *S2CLoginMsg) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_login_proto_msgTypes[1]
|
||||
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 S2CLoginMsg.ProtoReflect.Descriptor instead.
|
||||
func (*S2CLoginMsg) Descriptor() ([]byte, []int) {
|
||||
return file_login_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *S2CLoginMsg) GetCode() ErrCode {
|
||||
if x != nil {
|
||||
return x.Code
|
||||
}
|
||||
return ErrCode_OK
|
||||
}
|
||||
|
||||
var File_login_proto protoreflect.FileDescriptor
|
||||
|
||||
const file_login_proto_rawDesc = "" +
|
||||
"\n" +
|
||||
"\vlogin.proto\x12\binternal\x1a\n" +
|
||||
"code.proto\"Y\n" +
|
||||
"\vC2SLoginMsg\x12\x1a\n" +
|
||||
"\busername\x18\x01 \x01(\tR\busername\x12\x14\n" +
|
||||
"\x05token\x18\x02 \x01(\tR\x05token\x12\x18\n" +
|
||||
"\aversion\x18\x03 \x01(\tR\aversion\"4\n" +
|
||||
"\vS2CLoginMsg\x12%\n" +
|
||||
"\x04code\x18\x01 \x01(\x0e2\x11.internal.ErrCodeR\x04code*'\n" +
|
||||
"\n" +
|
||||
"LoginMsgId\x12\v\n" +
|
||||
"\aUnknown\x10\x00\x12\f\n" +
|
||||
"\bC2SLogin\x10\x01B\x0eZ\fcommon/protob\x06proto3"
|
||||
|
||||
var (
|
||||
file_login_proto_rawDescOnce sync.Once
|
||||
file_login_proto_rawDescData []byte
|
||||
)
|
||||
|
||||
func file_login_proto_rawDescGZIP() []byte {
|
||||
file_login_proto_rawDescOnce.Do(func() {
|
||||
file_login_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_login_proto_rawDesc), len(file_login_proto_rawDesc)))
|
||||
})
|
||||
return file_login_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_login_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
|
||||
var file_login_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
|
||||
var file_login_proto_goTypes = []any{
|
||||
(LoginMsgId)(0), // 0: internal.LoginMsgId
|
||||
(*C2SLoginMsg)(nil), // 1: internal.C2SLoginMsg
|
||||
(*S2CLoginMsg)(nil), // 2: internal.S2CLoginMsg
|
||||
(ErrCode)(0), // 3: internal.ErrCode
|
||||
}
|
||||
var file_login_proto_depIdxs = []int32{
|
||||
3, // 0: internal.S2CLoginMsg.code:type_name -> internal.ErrCode
|
||||
1, // [1:1] is the sub-list for method output_type
|
||||
1, // [1:1] is the sub-list for method input_type
|
||||
1, // [1:1] is the sub-list for extension type_name
|
||||
1, // [1:1] is the sub-list for extension extendee
|
||||
0, // [0:1] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_login_proto_init() }
|
||||
func file_login_proto_init() {
|
||||
if File_login_proto != nil {
|
||||
return
|
||||
}
|
||||
file_code_proto_init()
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: unsafe.Slice(unsafe.StringData(file_login_proto_rawDesc), len(file_login_proto_rawDesc)),
|
||||
NumEnums: 1,
|
||||
NumMessages: 2,
|
||||
NumExtensions: 0,
|
||||
NumServices: 0,
|
||||
},
|
||||
GoTypes: file_login_proto_goTypes,
|
||||
DependencyIndexes: file_login_proto_depIdxs,
|
||||
EnumInfos: file_login_proto_enumTypes,
|
||||
MessageInfos: file_login_proto_msgTypes,
|
||||
}.Build()
|
||||
File_login_proto = out.File
|
||||
file_login_proto_goTypes = nil
|
||||
file_login_proto_depIdxs = nil
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
|
||||
protoc -I=. --proto_path=./ --go_out=../ *.proto
|
||||
|
||||
echo "success"
|
@ -1,17 +1,28 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"game/common/config"
|
||||
"github.com/fox/fox/db"
|
||||
"github.com/fox/fox/log"
|
||||
)
|
||||
|
||||
type GateConfig struct{}
|
||||
const (
|
||||
gateKey = "gate_config"
|
||||
gateAddress = "114.132.124.145"
|
||||
gatePort = "5100"
|
||||
)
|
||||
|
||||
var Command *config.Command
|
||||
var Cfg *config.Common[GateConfig]
|
||||
|
||||
type GateConfig struct {
|
||||
Address string `json:"address"`
|
||||
Port string `json:"port"`
|
||||
}
|
||||
|
||||
func initLog() {
|
||||
log.Open(fmt.Sprintf("gate_%v.log", Command.VMod), log.DebugL)
|
||||
}
|
||||
@ -30,5 +41,15 @@ func LoadConfig() {
|
||||
log.Error(err.Error())
|
||||
return
|
||||
}
|
||||
if err = config.LoadSpecialConfig[GateConfig](rdb, gateKey, Cfg); err != nil {
|
||||
log.DebugF("load config:empty etcd key")
|
||||
Cfg.Special = &GateConfig{
|
||||
Address: gateAddress,
|
||||
Port: gatePort,
|
||||
}
|
||||
if bs, err := json.Marshal(&Cfg.Special); err == nil {
|
||||
err = rdb.Set(context.Background(), gateKey, string(bs), 0).Err()
|
||||
}
|
||||
}
|
||||
log.DebugF("load common config success")
|
||||
}
|
||||
|
@ -1,11 +1,13 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"game/common/serviceName"
|
||||
"game/server/gate/config"
|
||||
"github.com/fox/fox/etcd"
|
||||
"github.com/fox/fox/log"
|
||||
"github.com/fox/fox/service"
|
||||
"github.com/fox/fox/ws"
|
||||
)
|
||||
|
||||
var Gate *GateService
|
||||
@ -13,6 +15,7 @@ var Gate *GateService
|
||||
type GateService struct {
|
||||
*service.NatsService
|
||||
etcdService *etcd.Registry[etcd.ServiceNode]
|
||||
wss *ws.WsServer
|
||||
}
|
||||
|
||||
func Init() {
|
||||
@ -37,6 +40,8 @@ func newGateService() *GateService {
|
||||
s.NatsService.OnStop()
|
||||
return nil
|
||||
}
|
||||
wsAddress := fmt.Sprintf("%v:%v", config.Cfg.Special.Address, config.Cfg.Special.Port)
|
||||
s.wss = ws.NewWsServer(wsAddress, s.WsOnMessage, s.WsOnDisconnect)
|
||||
endpoint := &etcd.ServiceNode{
|
||||
Name: s.Name(),
|
||||
Type: s.Type(),
|
||||
@ -63,6 +68,8 @@ func (s *GateService) OnInit() {
|
||||
// if err := s.NatsService.QueueSubscribe(service.GroupTopic(s), service.GroupQueue(s)); err != nil {
|
||||
// log.Error(err.Error())
|
||||
// }
|
||||
|
||||
s.wss.Run()
|
||||
log.Debug("onInit")
|
||||
}
|
||||
|
||||
@ -78,18 +85,11 @@ func (s *GateService) OnMessage(msg []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// func TestGameService(t *testing.T) {
|
||||
// log.Open("test.log", log.DebugL)
|
||||
// s := newGameService()
|
||||
// msg := "hello world"
|
||||
// if err := s.Send(Topic(s), []byte(msg)); err != nil {
|
||||
// log.Error(err.Error())
|
||||
// }
|
||||
// for _, srv := range s.etcdService.GetNodes() {
|
||||
// log.Debug(s.Log("发现有服务:%v", srv))
|
||||
// }
|
||||
// time.Sleep(1 * time.Second)
|
||||
// s.NotifyStop()
|
||||
// s.WaitStop()
|
||||
// log.Debug("exit")
|
||||
// }
|
||||
func (s *GateService) WsOnMessage(conn ws.IConn, msg []byte) {
|
||||
|
||||
log.Debug(s.Log("on message:%v", string(msg)))
|
||||
}
|
||||
|
||||
func (s *GateService) WsOnDisconnect(conn ws.IConn) {
|
||||
log.Debug(s.Log("on message:%v", string(msg)))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user