From 33f0d7c8aa77d24f849b53d8dce1e036c4eccf76 Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Thu, 8 Aug 2024 16:03:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=A8=83=E5=A8=83=E6=9C=BA?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gamesrv/action/action_machine.go | 17 ++ gamesrv/base/srvsessmgr.go | 11 ++ machine/action/action_server.go | 26 ++++ machine/config.json | 78 ++++++++++ machine/logger.xml | 22 +++ machine/main.go | 17 ++ protocol/doc.md | 1 + protocol/machine/machine.pb.go | 256 +++++++++++++++++++++++++++++++ protocol/machine/machine.proto | 16 ++ 9 files changed, 444 insertions(+) create mode 100644 gamesrv/action/action_machine.go create mode 100644 machine/action/action_server.go create mode 100644 machine/config.json create mode 100644 machine/logger.xml create mode 100644 machine/main.go create mode 100644 protocol/machine/machine.pb.go create mode 100644 protocol/machine/machine.proto diff --git a/gamesrv/action/action_machine.go b/gamesrv/action/action_machine.go new file mode 100644 index 0000000..da91b62 --- /dev/null +++ b/gamesrv/action/action_machine.go @@ -0,0 +1,17 @@ +package action + +import ( + "mongo.games.com/game/protocol/machine" + "mongo.games.com/goserver/core/logger" + "mongo.games.com/goserver/core/netlib" +) + +func TestHandler(session *netlib.Session, packetId int, data interface{}) error { + logger.Logger.Tracef("TestHandler %v", data) + return nil +} + +func init() { + // 修改皮肤 + netlib.Register(int(machine.PacketID_Test), &machine.SCTest{}, TestHandler) +} diff --git a/gamesrv/base/srvsessmgr.go b/gamesrv/base/srvsessmgr.go index 335ee56..fa1510d 100644 --- a/gamesrv/base/srvsessmgr.go +++ b/gamesrv/base/srvsessmgr.go @@ -2,10 +2,13 @@ package base import ( "mongo.games.com/game/common" + "mongo.games.com/game/protocol/machine" "mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/netlib" + "mongo.games.com/goserver/core/timer" "mongo.games.com/goserver/srvlib" "mongo.games.com/goserver/srvlib/protocol" + "time" ) var SrvSessMgrSington = &SrvSessMgr{} @@ -27,6 +30,14 @@ func (this *SrvSessMgr) OnRegiste(s *netlib.Session) { } else if srvInfo.GetType() == int32(common.RobotServerType) { logger.Logger.Warn("(this *SrvSessMgr) OnRegiste (RobotSrv):", s) NpcServerAgentSingleton.OnConnected() + } else if srvInfo.GetType() == 10 { + logger.Logger.Warn("(this *SrvSessMgr) OnRegiste (Machine):", s) + timer.StartTimer(timer.TimerActionWrapper(func(h timer.TimerHandle, ud interface{}) bool { + s.Send(int(machine.PacketID_Test), &machine.CSTest{ + Ts: time.Now().Unix(), + }) + return true + }), nil, 3*time.Second, 100) } } } diff --git a/machine/action/action_server.go b/machine/action/action_server.go new file mode 100644 index 0000000..a628803 --- /dev/null +++ b/machine/action/action_server.go @@ -0,0 +1,26 @@ +package action + +import ( + "mongo.games.com/game/protocol/machine" + "mongo.games.com/goserver/core/logger" + "mongo.games.com/goserver/core/netlib" + "time" +) + +func TestHandler(session *netlib.Session, packetId int, data interface{}) error { + logger.Logger.Tracef("TestHandler %v", data) + msg, ok := data.(*machine.CSTest) + if !ok { + return nil + } + session.Send(int(machine.PacketID_Test), &machine.SCTest{ + Ts: time.Now().Unix(), + }) + logger.Logger.Tracef("PacketID_Test: %v", msg) + return nil +} + +func init() { + // 修改皮肤 + netlib.Register(int(machine.PacketID_Test), &machine.CSTest{}, TestHandler) +} diff --git a/machine/config.json b/machine/config.json new file mode 100644 index 0000000..533c38f --- /dev/null +++ b/machine/config.json @@ -0,0 +1,78 @@ +{ + "netlib": { + "SrvInfo": { + "Name": "MachineServer", + "Type": 10, + "Id": 1001, + "AreaID": 1, + "Banner": [ + "=================", + "machine server", + "=================" + ] + }, + "IoServices": [ + { + "Id": 1001, + "Type": 10, + "AreaId": 1, + "Name": "Gamesrv", + "Ip": "127.0.0.1", + "Port": 7001, + "Protocol":"tcp", + "Path":"/", + "MaxDone": 20000, + "MaxPend": 20000, + "MaxPacket": 65535, + "MaxConn": 1, + "RcvBuff": 819200, + "SndBuff": 819200, + "WriteTimeout": 300, + "ReadTimeout": 300, + "IsClient": true, + "IsAutoReconn": true, + "IsInnerLink": true, + "NoDelay": true, + "SupportFragment": true, + "AuthKey": "1234567890", + "FilterChain": ["session-filter-auth"], + "HandlerChain": ["session-srv-registe","handler-game-close"] + } + ] + }, + "module": { + "Options": { + "QueueBacklog": 1024, + "MaxDone": 1024, + "Interval": 100 + } + }, + "executor": { + "Options": { + "QueueBacklog": 1024, + "MaxDone": 1024, + "Interval": 0 + }, + "Worker": { + "WorkerCnt": 8, + "Options": { + "QueueBacklog": 1024, + "MaxDone": 1024, + "Interval": 0 + } + } + }, + "timer": { + "Options": { + "QueueBacklog": 1024, + "MaxDone": 1024, + "Interval": 100 + } + }, + "cmdline": { + "SupportCmdLine": true + }, + "signal": { + "SupportSignal": true + } +} \ No newline at end of file diff --git a/machine/logger.xml b/machine/logger.xml new file mode 100644 index 0000000..e859e4e --- /dev/null +++ b/machine/logger.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/machine/main.go b/machine/main.go new file mode 100644 index 0000000..e2f28a5 --- /dev/null +++ b/machine/main.go @@ -0,0 +1,17 @@ +package main + +import ( + "mongo.games.com/goserver/core" + "mongo.games.com/goserver/core/module" + + _ "mongo.games.com/game" + _ "mongo.games.com/game/machine/action" +) + +func main() { + defer core.ClosePackages() + core.LoadPackages("config.json") + + w := module.Start() + w.Wait("main()") +} diff --git a/protocol/doc.md b/protocol/doc.md index 01bc184..2f86c0b 100644 --- a/protocol/doc.md +++ b/protocol/doc.md @@ -5,6 +5,7 @@ - 2000~4999 client->worldsrv - 5000~9999 client->gamesrv - 10000~12000 client->ranksrv +- 20000~29999 gamesrv->machine -------------------------------------- # worldsrv diff --git a/protocol/machine/machine.pb.go b/protocol/machine/machine.pb.go new file mode 100644 index 0000000..9c90207 --- /dev/null +++ b/protocol/machine/machine.pb.go @@ -0,0 +1,256 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.1-devel +// protoc v3.19.4 +// source: machine.proto + +package machine + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +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 PacketID int32 + +const ( + PacketID_Zero PacketID = 0 // 弃用消息号 + PacketID_Test PacketID = 20000 // 测试 +) + +// Enum value maps for PacketID. +var ( + PacketID_name = map[int32]string{ + 0: "Zero", + 20000: "Test", + } + PacketID_value = map[string]int32{ + "Zero": 0, + "Test": 20000, + } +) + +func (x PacketID) Enum() *PacketID { + p := new(PacketID) + *p = x + return p +} + +func (x PacketID) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (PacketID) Descriptor() protoreflect.EnumDescriptor { + return file_machine_proto_enumTypes[0].Descriptor() +} + +func (PacketID) Type() protoreflect.EnumType { + return &file_machine_proto_enumTypes[0] +} + +func (x PacketID) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use PacketID.Descriptor instead. +func (PacketID) EnumDescriptor() ([]byte, []int) { + return file_machine_proto_rawDescGZIP(), []int{0} +} + +// Test +type CSTest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Ts int64 `protobuf:"varint,1,opt,name=Ts,proto3" json:"Ts,omitempty"` +} + +func (x *CSTest) Reset() { + *x = CSTest{} + if protoimpl.UnsafeEnabled { + mi := &file_machine_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CSTest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CSTest) ProtoMessage() {} + +func (x *CSTest) ProtoReflect() protoreflect.Message { + mi := &file_machine_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CSTest.ProtoReflect.Descriptor instead. +func (*CSTest) Descriptor() ([]byte, []int) { + return file_machine_proto_rawDescGZIP(), []int{0} +} + +func (x *CSTest) GetTs() int64 { + if x != nil { + return x.Ts + } + return 0 +} + +type SCTest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Ts int64 `protobuf:"varint,1,opt,name=Ts,proto3" json:"Ts,omitempty"` +} + +func (x *SCTest) Reset() { + *x = SCTest{} + if protoimpl.UnsafeEnabled { + mi := &file_machine_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SCTest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SCTest) ProtoMessage() {} + +func (x *SCTest) ProtoReflect() protoreflect.Message { + mi := &file_machine_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SCTest.ProtoReflect.Descriptor instead. +func (*SCTest) Descriptor() ([]byte, []int) { + return file_machine_proto_rawDescGZIP(), []int{1} +} + +func (x *SCTest) GetTs() int64 { + if x != nil { + return x.Ts + } + return 0 +} + +var File_machine_proto protoreflect.FileDescriptor + +var file_machine_proto_rawDesc = []byte{ + 0x0a, 0x0d, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, + 0x07, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x22, 0x18, 0x0a, 0x06, 0x43, 0x53, 0x54, 0x65, + 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x54, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, + 0x54, 0x73, 0x22, 0x18, 0x0a, 0x06, 0x53, 0x43, 0x54, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, + 0x54, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x54, 0x73, 0x2a, 0x20, 0x0a, 0x08, + 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x49, 0x44, 0x12, 0x08, 0x0a, 0x04, 0x5a, 0x65, 0x72, 0x6f, + 0x10, 0x00, 0x12, 0x0a, 0x0a, 0x04, 0x54, 0x65, 0x73, 0x74, 0x10, 0xa0, 0x9c, 0x01, 0x42, 0x27, + 0x5a, 0x25, 0x6d, 0x6f, 0x6e, 0x67, 0x6f, 0x2e, 0x67, 0x61, 0x6d, 0x65, 0x73, 0x2e, 0x63, 0x6f, + 0x6d, 0x2f, 0x67, 0x61, 0x6d, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x2f, + 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_machine_proto_rawDescOnce sync.Once + file_machine_proto_rawDescData = file_machine_proto_rawDesc +) + +func file_machine_proto_rawDescGZIP() []byte { + file_machine_proto_rawDescOnce.Do(func() { + file_machine_proto_rawDescData = protoimpl.X.CompressGZIP(file_machine_proto_rawDescData) + }) + return file_machine_proto_rawDescData +} + +var file_machine_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_machine_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_machine_proto_goTypes = []interface{}{ + (PacketID)(0), // 0: machine.PacketID + (*CSTest)(nil), // 1: machine.CSTest + (*SCTest)(nil), // 2: machine.SCTest +} +var file_machine_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_machine_proto_init() } +func file_machine_proto_init() { + if File_machine_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_machine_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CSTest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_machine_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SCTest); 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_machine_proto_rawDesc, + NumEnums: 1, + NumMessages: 2, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_machine_proto_goTypes, + DependencyIndexes: file_machine_proto_depIdxs, + EnumInfos: file_machine_proto_enumTypes, + MessageInfos: file_machine_proto_msgTypes, + }.Build() + File_machine_proto = out.File + file_machine_proto_rawDesc = nil + file_machine_proto_goTypes = nil + file_machine_proto_depIdxs = nil +} diff --git a/protocol/machine/machine.proto b/protocol/machine/machine.proto new file mode 100644 index 0000000..5e74e0b --- /dev/null +++ b/protocol/machine/machine.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; +package machine; +option go_package = "mongo.games.com/game/protocol/machine"; + +enum PacketID { + Zero = 0;// 弃用消息号 + Test = 20000; // 测试 +} + +// Test +message CSTest { + int64 Ts = 1; +} +message SCTest { + int64 Ts = 1; +} \ No newline at end of file