diff --git a/.gitignore b/.gitignore index cfbc91300..7d55a4ad9 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,5 @@ bin/conf ./bin/gateway ./bin/worker ~$*.xlsx +*.pid cmd/luban/ \ No newline at end of file diff --git a/bin/dbservice b/bin/dbservice new file mode 100755 index 000000000..cc4ee108e Binary files /dev/null and b/bin/dbservice differ diff --git a/bin/docker_dreamfactory/docker-compose.yml b/bin/docker_dreamfactory/docker-compose.yml index c044fd657..12db05765 100644 --- a/bin/docker_dreamfactory/docker-compose.yml +++ b/bin/docker_dreamfactory/docker-compose.yml @@ -7,17 +7,17 @@ networks: # 游戏数据卷 volumes: - consuldata: - name: consuldata - redisdata: - name: redisdata - mongodata: - name: mongodata + dreamfactory_consuldata: + name: dreamfactory_consuldata + dreamfactory_redisdata: + name: dreamfactory_redisdata + dreamfactory_mongodata: + name: dreamfactory_mongodata # 服务 services: redis: image: redis:latest - container_name: redis + container_name: dreamfactory_redis ports: - '10011:6379' networks: @@ -28,14 +28,14 @@ services: command: /etc/redis/redis.conf volumes: # 持久存储redis的数据 - - redisdata:/data + - dreamfactory_redisdata:/data # 挂载本地配置文件 - ./redis.conf:/etc/redis/redis.conf # 时间同步 # - /etc/localtime:/etc/localtime consul: image: consul:latest - container_name: consul + container_name: dreamfactory_consul ports: - '10012:8500' command: consul agent -server -bootstrap -data-dir /consul/data -node=ylconsul -bind=0.0.0.0 -config-dir=/consul/config/ -client=0.0.0.0 -ui @@ -45,10 +45,10 @@ services: aliases: - discovery volumes: - - consuldata:/consul/data + - dreamfactory_consuldata:/consul/data mongo: image: mongo:latest - container_name: mongo + container_name: dreamfactory_mongo ports: - '10013:27017' networks: @@ -62,7 +62,7 @@ services: # MONGO_INITDB_ROOT_PASSWORD: li13451234 volumes: # 持久存储mongodb的数据 - - mongodata:/data/db:rw - - mongodata:/data/configdb:rw + - dreamfactory_mongodata:/data/db:rw + - dreamfactory_mongodata:/data/configdb:rw # 挂载本地配置文件 - ./mongod.conf:/etc/mongo/mongod.conf:rw \ No newline at end of file diff --git a/bin/gateway b/bin/gateway new file mode 100755 index 000000000..5690b2c4f Binary files /dev/null and b/bin/gateway differ diff --git a/bin/stup.sh b/bin/stup.sh new file mode 100755 index 000000000..08bcd3127 --- /dev/null +++ b/bin/stup.sh @@ -0,0 +1,50 @@ + #!/bin/sh + SERVICE=$2 + CMD="./$2 -conf $3" + + start(){ + echo "starting..." + nohup $CMD > /dev/null 2>&1 & + # nohup $CMD >output.log 2>&1 & + if [ $? -ne 0 ] + then + echo "start failed, please check the log!" + exit $? + else + echo $! > $SERVICE.pid + echo "start success" + fi + } + stop(){ + echo "stopping..." + kill -9 `cat $SERVICE.pid` + if [ $? -ne 0 ] + then + echo "stop failed, may be $SERVICE isn't running" + exit $? + else + rm -rf $SERVICE.pid + echo "stop success" + fi + } + restart(){ + stop&&start + } + status(){ + num=`ps -ef | grep $SERVICE | grep -v grep | wc -l` + if [ $num -eq 0 ] + then + echo "$SERVICE isn't running" + else + echo "$SERVICE is running" + fi + } + case $1 in + start) start ;; + stop) stop ;; + restart) restart ;; + status) status ;; + *) echo "Usage: $0 {start|stop|restart|status}" ;; + esac + + exit 0 \ No newline at end of file diff --git a/bin/worker b/bin/worker new file mode 100755 index 000000000..1e392f822 Binary files /dev/null and b/bin/worker differ diff --git a/cmd/bench/base.go b/cmd/bench/base.go new file mode 100644 index 000000000..37bd83a3c --- /dev/null +++ b/cmd/bench/base.go @@ -0,0 +1,72 @@ +package bench + +import ( + "fmt" + "testing" +) + +type Target struct { + //这里定义需要测试的方法 +} + +//测试基准 +type Benchmark struct { + Parallelism int //并行数目 + Data interface{} //bench 参数数据 + TargetBuilder TargetBuilder +} + +//构建基准目标 +type TargetBuilder struct { + Name string + Make func(bench Benchmark) (Target, error) +} + +func compose(parallelisms, dataSize []int, numKeys int, builders []TargetBuilder) []Benchmark { + benchmarks := make([]Benchmark, 0, len(parallelisms)*len(dataSize)*len(builders)) + + for _, p := range parallelisms { + for _, _ = range dataSize { + + for _, builder := range builders { + benchmarks = append(benchmarks, Benchmark{ + Parallelism: p, + // Data: d, + TargetBuilder: builder, + }) + } + + } + } + + return benchmarks +} + +func RunBenchmark(b *testing.B, benchmarks []Benchmark) { + for _, bench := range benchmarks { + bench := bench + b.Run(fmt.Sprintf("%s-parallelism(%d)- ", bench.TargetBuilder.Name, bench.Parallelism), func(b *testing.B) { + // target, err := bench.TargetBuilder.Make(bench) + // if err != nil { + // b.Fatalf("%s setup fail: %v", bench.TargetBuilder.Name, err) + // } + if bench.Parallelism == 0 { + b.ResetTimer() + for i := 0; i < b.N; i++ { + //执行测试方法 + + } + + } else { + b.SetParallelism(bench.Parallelism) //指定并行数目 + b.ResetTimer() + b.RunParallel(func(pb *testing.PB) { //并行执行 + for pb.Next() { + //执行测试方法 + } + }) + } + b.StopTimer() + }) + } +} diff --git a/cmd/bench/main_test.go b/cmd/bench/main_test.go new file mode 100644 index 000000000..076576295 --- /dev/null +++ b/cmd/bench/main_test.go @@ -0,0 +1,31 @@ +package bench + +import ( + "testing" +) + +func BenchmarkMarsh(b *testing.B) { + var ( + // ncpu = runtime.NumCPU() + parallelisms = []int{4, 16, 64} + dataSizes = []int{100, 1000, 10000} + numKeys = 1024 + builders = []TargetBuilder{ + { + Name: "测试名1", + Make: func(bench Benchmark) (Target, error) { + + return Target{}, nil + }, + }, + { + Name: "测试名2", + Make: func(bench Benchmark) (Target, error) { + return Target{}, nil + }, + }, + } + ) + + RunBenchmark(b, compose(parallelisms, dataSizes, numKeys, builders)) +} diff --git a/comm/imodule.go b/comm/imodule.go index 723d9ad94..95b25e01f 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -35,8 +35,6 @@ type ( IHero interface { //查询用户卡片数量 QueryHeroAmount(uId string, heroCfgId int32) (amount uint32) - //消耗卡片 - ConsumeCard(uId string, heroCfgId int32, count int32) (code pb.ErrorCode) //创建新英雄 CreateHero(uid string, heroCfgId ...int32) error diff --git a/lego/base/rpcx/service.go b/lego/base/rpcx/service.go index 4d7d22abe..63677ed99 100644 --- a/lego/base/rpcx/service.go +++ b/lego/base/rpcx/service.go @@ -12,7 +12,6 @@ import ( "go_dreamfactory/lego/sys/event" "go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/rpcx" - "github.com/smallnest/rpcx/client" ) diff --git a/linux_bulid.sh b/linux_bulid.sh old mode 100644 new mode 100755 diff --git a/modules/hero/configure_comp.go b/modules/hero/configure_comp.go index 686e45aad..b870ccc67 100644 --- a/modules/hero/configure_comp.go +++ b/modules/hero/configure_comp.go @@ -306,7 +306,7 @@ func (this *configureComp) GetHeroResonanceConfig(cardConfigID int32) (data *cfg data = configure.Get(cardConfigID) } } else { - err = fmt.Errorf("%T no is *cfg.Game_hero", v) + err = fmt.Errorf("%T no is *cfg.Game_heroResonance", v) } return @@ -318,13 +318,13 @@ func (this *configureComp) GetHeroResonanceRestConfig() (data *cfg.Game_comAtnDa ) if v, err = this.GetConfigure(hero_comatn); err == nil { if configure, ok := v.(*cfg.Game_comAtn); !ok { - err = fmt.Errorf("%T no is *cfg.Game_heroResonance", v) + err = fmt.Errorf("%T no is *cfg.Game_comAtn", v) return } else { data = configure.Get("hero_reset") } } else { - err = fmt.Errorf("%T no is *cfg.Game_hero", v) + err = fmt.Errorf("%T no is *cfg.game_comatn", v) } return @@ -336,11 +336,11 @@ func (this *configureComp) GetHeroAwakenConfig() (configure *cfg.Game_heroAwaken ) if v, err = this.GetConfigure(hero_awaken); err == nil { if configure, ok = v.(*cfg.Game_heroAwaken); !ok { - err = fmt.Errorf("%T no is *cfg.Game_heroResonance", v) + err = fmt.Errorf("%T no is *cfg.Game_heroAwaken", v) return } } else { - err = fmt.Errorf("%T no is *cfg.Game_hero", v) + err = fmt.Errorf("%T no is *cfg.Game_heroAwaken", v) } return diff --git a/modules/hero/module.go b/modules/hero/module.go index 98029e9dd..83683f0dc 100644 --- a/modules/hero/module.go +++ b/modules/hero/module.go @@ -43,40 +43,6 @@ func (this *Hero) CreateHero(uid string, heroCfgId ...int32) error { return this.modelHero.createMultiHero(uid, heroCfgId...) } -//消耗英雄卡 -// func (this *Hero) ConsumeCard(uId string, heroCfgId int32, count int32) (code pb.ErrorCode) { -// if count <= 0 { -// log.Errorf("attr no changed,uid: %s heroCfgId: %s count: %d", uId, heroCfgId, count) -// code = pb.ErrorCode_ReqParameterError -// return -// } - -// heroCfg := this.configure.GetHero(heroCfgId) -// if heroCfg != nil { - -// } - -// heroes := this.GetHeroList(uId) -// var curList []*pb.DBHero -// for _, v := range heroes { -// if heroCfgId == v.HeroID { -// curList = append(curList, v) -// } -// } -// if int32(len(curList)) < count { -// return pb.ErrorCode_HeroNoEnough -// } - -// for _, v := range curList { -// err := this.modelHero.consumeOneHeroCard(v.Uid, v.Id, count) -// if err != nil { -// return pb.ErrorCode_DBError -// } -// } - -// return pb.ErrorCode_Success -// } - //获取英雄 func (this *Hero) GetHero(uid, heroId string) (*pb.DBHero, pb.ErrorCode) { hero := this.modelHero.getOneHero(uid, heroId) @@ -115,12 +81,10 @@ func (this *Hero) UpdateEquipment(hero *pb.DBHero, equip []*pb.DB_Equipment) (co //英雄列表 func (this *Hero) GetHeroList(uid string) []*pb.DBHero { - // data := []*pb.DBHero{} heroes := this.modelHero.getHeroList(uid) - // for _, h := range heroes { - // h.Property = this.modelHero.PropertyCompute(uid, h.Id) - // data = append(data, h) - // } + for _, h := range heroes { + h.Property = this.modelHero.PropertyCompute(uid, h.Id) + } return heroes } diff --git a/modules/story/api_challenge.go b/modules/story/api_challenge.go index 4623a129f..18ba35b79 100644 --- a/modules/story/api_challenge.go +++ b/modules/story/api_challenge.go @@ -24,10 +24,6 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.StoryChallenge bBranch bool // 当前挑战关卡是不是分支 ) bBranch = false - defer func() { - session.SendMsg(string(this.module.GetType()), StoryChallengeResp, &pb.StoryChallengeResp{Data: curChapter}) - - }() code = this.ChallengeCheck(session, req) if code != pb.ErrorCode_Success { return // 参数校验失败直接返回 @@ -81,6 +77,6 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.StoryChallenge err = this.module.modelStory.modifyStoryData(session.GetUserId(), curChapter.Id, update) } // 发奖 (奖励数据还没配置,后续补充) - + session.SendMsg(string(this.module.GetType()), StoryChallengeResp, &pb.StoryChallengeResp{Data: curChapter}) return } diff --git a/modules/story/api_getlist.go b/modules/story/api_getlist.go index e4a30ae51..e7e45d6c2 100644 --- a/modules/story/api_getlist.go +++ b/modules/story/api_getlist.go @@ -16,10 +16,7 @@ func (this *apiComp) GetListCheck(session comm.IUserSession, req *pb.StoryGetLis ///获取主线关卡信息 func (this *apiComp) GetList(session comm.IUserSession, req *pb.StoryGetListReq) (code pb.ErrorCode, data proto.Message) { rsp := &pb.StoryGetListResp{} - defer func() { - session.SendMsg(string(this.module.GetType()), StoryGetListResp, &pb.StoryGetListResp{Data: rsp.Data}) - }() code = this.GetListCheck(session, req) if code != pb.ErrorCode_Success { return // 参数校验失败直接返回 @@ -31,5 +28,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.StoryGetListReq) return } rsp.Data = list + + session.SendMsg(string(this.module.GetType()), StoryGetListResp, &pb.StoryGetListResp{Data: rsp.Data}) return } diff --git a/pb/mail_msg.pb.go b/pb/mail_msg.pb.go index 891d49526..6be82fa19 100644 --- a/pb/mail_msg.pb.go +++ b/pb/mail_msg.pb.go @@ -391,6 +391,54 @@ func (x *MailDelMailResp) GetMail() []*DBMailData { return nil } +// 推送邮件 +type MailGetNewMailPush struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Mail *DBMailData `protobuf:"bytes,1,opt,name=Mail,proto3" json:"Mail"` // 推送新的邮件信息 +} + +func (x *MailGetNewMailPush) Reset() { + *x = MailGetNewMailPush{} + if protoimpl.UnsafeEnabled { + mi := &file_mail_mail_msg_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MailGetNewMailPush) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MailGetNewMailPush) ProtoMessage() {} + +func (x *MailGetNewMailPush) ProtoReflect() protoreflect.Message { + mi := &file_mail_mail_msg_proto_msgTypes[8] + 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 MailGetNewMailPush.ProtoReflect.Descriptor instead. +func (*MailGetNewMailPush) Descriptor() ([]byte, []int) { + return file_mail_mail_msg_proto_rawDescGZIP(), []int{8} +} + +func (x *MailGetNewMailPush) GetMail() *DBMailData { + if x != nil { + return x.Mail + } + return nil +} + var File_mail_mail_msg_proto protoreflect.FileDescriptor var file_mail_mail_msg_proto_rawDesc = []byte{ @@ -420,8 +468,11 @@ var file_mail_mail_msg_proto_rawDesc = []byte{ 0x32, 0x0a, 0x0f, 0x4d, 0x61, 0x69, 0x6c, 0x44, 0x65, 0x6c, 0x4d, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1f, 0x0a, 0x04, 0x4d, 0x61, 0x69, 0x6c, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x44, 0x42, 0x4d, 0x61, 0x69, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x4d, - 0x61, 0x69, 0x6c, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, + 0x61, 0x69, 0x6c, 0x22, 0x35, 0x0a, 0x12, 0x4d, 0x61, 0x69, 0x6c, 0x47, 0x65, 0x74, 0x4e, 0x65, + 0x77, 0x4d, 0x61, 0x69, 0x6c, 0x50, 0x75, 0x73, 0x68, 0x12, 0x1f, 0x0a, 0x04, 0x4d, 0x61, 0x69, + 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x44, 0x42, 0x4d, 0x61, 0x69, 0x6c, + 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x4d, 0x61, 0x69, 0x6c, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, + 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -436,7 +487,7 @@ func file_mail_mail_msg_proto_rawDescGZIP() []byte { return file_mail_mail_msg_proto_rawDescData } -var file_mail_mail_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 8) +var file_mail_mail_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 9) var file_mail_mail_msg_proto_goTypes = []interface{}{ (*MailGetListReq)(nil), // 0: MailGetListReq (*MailGetListResp)(nil), // 1: MailGetListResp @@ -446,18 +497,20 @@ var file_mail_mail_msg_proto_goTypes = []interface{}{ (*MailGetUserMailAttachmentResp)(nil), // 5: MailGetUserMailAttachmentResp (*MailDelMailReq)(nil), // 6: MailDelMailReq (*MailDelMailResp)(nil), // 7: MailDelMailResp - (*DBMailData)(nil), // 8: DBMailData + (*MailGetNewMailPush)(nil), // 8: MailGetNewMailPush + (*DBMailData)(nil), // 9: DBMailData } var file_mail_mail_msg_proto_depIdxs = []int32{ - 8, // 0: MailGetListResp.Mails:type_name -> DBMailData - 8, // 1: MailReadMailResp.Mail:type_name -> DBMailData - 8, // 2: MailGetUserMailAttachmentResp.Mail:type_name -> DBMailData - 8, // 3: MailDelMailResp.Mail:type_name -> DBMailData - 4, // [4:4] is the sub-list for method output_type - 4, // [4:4] is the sub-list for method input_type - 4, // [4:4] is the sub-list for extension type_name - 4, // [4:4] is the sub-list for extension extendee - 0, // [0:4] is the sub-list for field type_name + 9, // 0: MailGetListResp.Mails:type_name -> DBMailData + 9, // 1: MailReadMailResp.Mail:type_name -> DBMailData + 9, // 2: MailGetUserMailAttachmentResp.Mail:type_name -> DBMailData + 9, // 3: MailDelMailResp.Mail:type_name -> DBMailData + 9, // 4: MailGetNewMailPush.Mail:type_name -> DBMailData + 5, // [5:5] is the sub-list for method output_type + 5, // [5:5] is the sub-list for method input_type + 5, // [5:5] is the sub-list for extension type_name + 5, // [5:5] is the sub-list for extension extendee + 0, // [0:5] is the sub-list for field type_name } func init() { file_mail_mail_msg_proto_init() } @@ -563,6 +616,18 @@ func file_mail_mail_msg_proto_init() { return nil } } + file_mail_mail_msg_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*MailGetNewMailPush); 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{ @@ -570,7 +635,7 @@ func file_mail_mail_msg_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_mail_mail_msg_proto_rawDesc, NumEnums: 0, - NumMessages: 8, + NumMessages: 9, NumExtensions: 0, NumServices: 0, },