添加娃娃机服务

This commit is contained in:
sk 2024-08-08 16:03:59 +08:00
parent a51037b1e7
commit 33f0d7c8aa
9 changed files with 444 additions and 0 deletions

View File

@ -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)
}

View File

@ -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)
}
}
}

View File

@ -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)
}

78
machine/config.json Normal file
View File

@ -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
}
}

22
machine/logger.xml Normal file
View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8" ?>
<seelog type="adaptive" mininterval="2000000" maxinterval="100000000" critmsgcount="500" minlevel="info">
<exceptions>
<exception filepattern="test*" minlevel="error"/>
</exceptions>
<outputs formatid="all">
<rollingfile formatid="all" type="size" filename="./all.log" maxsize="50000000" maxrolls="5" />
<filter levels="info,trace,warn,error">
<console formatid="fmtinfo"/>
</filter>
<filter levels="error,critical" formatid="fmterror">
<console/>
<file path="errors.log"/>
</filter>
</outputs>
<formats>
<format id="fmtinfo" format="[%Date][%Time] [%Level] %Msg%n"/>
<format id="fmterror" format="[%Date][%Time] [%LEVEL] [%FuncShort @ %File.%Line] %Msg%n"/>
<format id="all" format="[%Date][%Time] [%Level] [@ %File.%Line] %Msg%n"/>
<format id="criticalemail" format="Critical error on our server!\n %Time %Date %RelFile %Func %Msg \nSent by Seelog"/>
</formats>
</seelog>

17
machine/main.go Normal file
View File

@ -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()")
}

View File

@ -5,6 +5,7 @@
- 2000~4999 client->worldsrv
- 5000~9999 client->gamesrv
- 10000~12000 client->ranksrv
- 20000~29999 gamesrv->machine
--------------------------------------
# worldsrv

View File

@ -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
}

View File

@ -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;
}