This commit is contained in:
liwei1dao 2022-07-12 11:03:56 +08:00
commit e2ee6c421e
16 changed files with 257 additions and 82 deletions

1
.gitignore vendored
View File

@ -18,4 +18,5 @@ bin/conf
./bin/gateway ./bin/gateway
./bin/worker ./bin/worker
~$*.xlsx ~$*.xlsx
*.pid
cmd/luban/ cmd/luban/

BIN
bin/dbservice Executable file

Binary file not shown.

View File

@ -7,17 +7,17 @@ networks:
# 游戏数据卷 # 游戏数据卷
volumes: volumes:
consuldata: dreamfactory_consuldata:
name: consuldata name: dreamfactory_consuldata
redisdata: dreamfactory_redisdata:
name: redisdata name: dreamfactory_redisdata
mongodata: dreamfactory_mongodata:
name: mongodata name: dreamfactory_mongodata
# 服务 # 服务
services: services:
redis: redis:
image: redis:latest image: redis:latest
container_name: redis container_name: dreamfactory_redis
ports: ports:
- '10011:6379' - '10011:6379'
networks: networks:
@ -28,14 +28,14 @@ services:
command: /etc/redis/redis.conf command: /etc/redis/redis.conf
volumes: volumes:
# 持久存储redis的数据 # 持久存储redis的数据
- redisdata:/data - dreamfactory_redisdata:/data
# 挂载本地配置文件 # 挂载本地配置文件
- ./redis.conf:/etc/redis/redis.conf - ./redis.conf:/etc/redis/redis.conf
# 时间同步 # 时间同步
# - /etc/localtime:/etc/localtime # - /etc/localtime:/etc/localtime
consul: consul:
image: consul:latest image: consul:latest
container_name: consul container_name: dreamfactory_consul
ports: ports:
- '10012:8500' - '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 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: aliases:
- discovery - discovery
volumes: volumes:
- consuldata:/consul/data - dreamfactory_consuldata:/consul/data
mongo: mongo:
image: mongo:latest image: mongo:latest
container_name: mongo container_name: dreamfactory_mongo
ports: ports:
- '10013:27017' - '10013:27017'
networks: networks:
@ -62,7 +62,7 @@ services:
# MONGO_INITDB_ROOT_PASSWORD: li13451234 # MONGO_INITDB_ROOT_PASSWORD: li13451234
volumes: volumes:
# 持久存储mongodb的数据 # 持久存储mongodb的数据
- mongodata:/data/db:rw - dreamfactory_mongodata:/data/db:rw
- mongodata:/data/configdb:rw - dreamfactory_mongodata:/data/configdb:rw
# 挂载本地配置文件 # 挂载本地配置文件
- ./mongod.conf:/etc/mongo/mongod.conf:rw - ./mongod.conf:/etc/mongo/mongod.conf:rw

BIN
bin/gateway Executable file

Binary file not shown.

50
bin/stup.sh Executable file
View File

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

BIN
bin/worker Executable file

Binary file not shown.

72
cmd/bench/base.go Normal file
View File

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

31
cmd/bench/main_test.go Normal file
View File

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

View File

@ -35,8 +35,6 @@ type (
IHero interface { IHero interface {
//查询用户卡片数量 //查询用户卡片数量
QueryHeroAmount(uId string, heroCfgId int32) (amount uint32) QueryHeroAmount(uId string, heroCfgId int32) (amount uint32)
//消耗卡片
ConsumeCard(uId string, heroCfgId int32, count int32) (code pb.ErrorCode)
//创建新英雄 //创建新英雄
CreateHero(uid string, heroCfgId ...int32) error CreateHero(uid string, heroCfgId ...int32) error

View File

@ -12,7 +12,6 @@ import (
"go_dreamfactory/lego/sys/event" "go_dreamfactory/lego/sys/event"
"go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/log"
"go_dreamfactory/lego/sys/rpcx" "go_dreamfactory/lego/sys/rpcx"
"github.com/smallnest/rpcx/client" "github.com/smallnest/rpcx/client"
) )

0
linux_bulid.sh Normal file → Executable file
View File

View File

@ -306,7 +306,7 @@ func (this *configureComp) GetHeroResonanceConfig(cardConfigID int32) (data *cfg
data = configure.Get(cardConfigID) data = configure.Get(cardConfigID)
} }
} else { } else {
err = fmt.Errorf("%T no is *cfg.Game_hero", v) err = fmt.Errorf("%T no is *cfg.Game_heroResonance", v)
} }
return return
@ -318,13 +318,13 @@ func (this *configureComp) GetHeroResonanceRestConfig() (data *cfg.Game_comAtnDa
) )
if v, err = this.GetConfigure(hero_comatn); err == nil { if v, err = this.GetConfigure(hero_comatn); err == nil {
if configure, ok := v.(*cfg.Game_comAtn); !ok { 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 return
} else { } else {
data = configure.Get("hero_reset") data = configure.Get("hero_reset")
} }
} else { } else {
err = fmt.Errorf("%T no is *cfg.Game_hero", v) err = fmt.Errorf("%T no is *cfg.game_comatn", v)
} }
return return
@ -336,11 +336,11 @@ func (this *configureComp) GetHeroAwakenConfig() (configure *cfg.Game_heroAwaken
) )
if v, err = this.GetConfigure(hero_awaken); err == nil { if v, err = this.GetConfigure(hero_awaken); err == nil {
if configure, ok = v.(*cfg.Game_heroAwaken); !ok { 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 return
} }
} else { } else {
err = fmt.Errorf("%T no is *cfg.Game_hero", v) err = fmt.Errorf("%T no is *cfg.Game_heroAwaken", v)
} }
return return

View File

@ -43,40 +43,6 @@ func (this *Hero) CreateHero(uid string, heroCfgId ...int32) error {
return this.modelHero.createMultiHero(uid, heroCfgId...) 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) { func (this *Hero) GetHero(uid, heroId string) (*pb.DBHero, pb.ErrorCode) {
hero := this.modelHero.getOneHero(uid, heroId) 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 { func (this *Hero) GetHeroList(uid string) []*pb.DBHero {
// data := []*pb.DBHero{}
heroes := this.modelHero.getHeroList(uid) heroes := this.modelHero.getHeroList(uid)
// for _, h := range heroes { for _, h := range heroes {
// h.Property = this.modelHero.PropertyCompute(uid, h.Id) h.Property = this.modelHero.PropertyCompute(uid, h.Id)
// data = append(data, h) }
// }
return heroes return heroes
} }

View File

@ -24,10 +24,6 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.StoryChallenge
bBranch bool // 当前挑战关卡是不是分支 bBranch bool // 当前挑战关卡是不是分支
) )
bBranch = false bBranch = false
defer func() {
session.SendMsg(string(this.module.GetType()), StoryChallengeResp, &pb.StoryChallengeResp{Data: curChapter})
}()
code = this.ChallengeCheck(session, req) code = this.ChallengeCheck(session, req)
if code != pb.ErrorCode_Success { if code != pb.ErrorCode_Success {
return // 参数校验失败直接返回 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) err = this.module.modelStory.modifyStoryData(session.GetUserId(), curChapter.Id, update)
} }
// 发奖 (奖励数据还没配置,后续补充) // 发奖 (奖励数据还没配置,后续补充)
session.SendMsg(string(this.module.GetType()), StoryChallengeResp, &pb.StoryChallengeResp{Data: curChapter})
return return
} }

View File

@ -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) { func (this *apiComp) GetList(session comm.IUserSession, req *pb.StoryGetListReq) (code pb.ErrorCode, data proto.Message) {
rsp := &pb.StoryGetListResp{} rsp := &pb.StoryGetListResp{}
defer func() {
session.SendMsg(string(this.module.GetType()), StoryGetListResp, &pb.StoryGetListResp{Data: rsp.Data})
}()
code = this.GetListCheck(session, req) code = this.GetListCheck(session, req)
if code != pb.ErrorCode_Success { if code != pb.ErrorCode_Success {
return // 参数校验失败直接返回 return // 参数校验失败直接返回
@ -31,5 +28,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.StoryGetListReq)
return return
} }
rsp.Data = list rsp.Data = list
session.SendMsg(string(this.module.GetType()), StoryGetListResp, &pb.StoryGetListResp{Data: rsp.Data})
return return
} }

View File

@ -391,6 +391,54 @@ func (x *MailDelMailResp) GetMail() []*DBMailData {
return nil 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 protoreflect.FileDescriptor
var file_mail_mail_msg_proto_rawDesc = []byte{ 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, 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, 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, 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, 0x61, 0x69, 0x6c, 0x22, 0x35, 0x0a, 0x12, 0x4d, 0x61, 0x69, 0x6c, 0x47, 0x65, 0x74, 0x4e, 0x65,
0x74, 0x6f, 0x33, 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 ( var (
@ -436,7 +487,7 @@ func file_mail_mail_msg_proto_rawDescGZIP() []byte {
return file_mail_mail_msg_proto_rawDescData 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{}{ var file_mail_mail_msg_proto_goTypes = []interface{}{
(*MailGetListReq)(nil), // 0: MailGetListReq (*MailGetListReq)(nil), // 0: MailGetListReq
(*MailGetListResp)(nil), // 1: MailGetListResp (*MailGetListResp)(nil), // 1: MailGetListResp
@ -446,18 +497,20 @@ var file_mail_mail_msg_proto_goTypes = []interface{}{
(*MailGetUserMailAttachmentResp)(nil), // 5: MailGetUserMailAttachmentResp (*MailGetUserMailAttachmentResp)(nil), // 5: MailGetUserMailAttachmentResp
(*MailDelMailReq)(nil), // 6: MailDelMailReq (*MailDelMailReq)(nil), // 6: MailDelMailReq
(*MailDelMailResp)(nil), // 7: MailDelMailResp (*MailDelMailResp)(nil), // 7: MailDelMailResp
(*DBMailData)(nil), // 8: DBMailData (*MailGetNewMailPush)(nil), // 8: MailGetNewMailPush
(*DBMailData)(nil), // 9: DBMailData
} }
var file_mail_mail_msg_proto_depIdxs = []int32{ var file_mail_mail_msg_proto_depIdxs = []int32{
8, // 0: MailGetListResp.Mails:type_name -> DBMailData 9, // 0: MailGetListResp.Mails:type_name -> DBMailData
8, // 1: MailReadMailResp.Mail:type_name -> DBMailData 9, // 1: MailReadMailResp.Mail:type_name -> DBMailData
8, // 2: MailGetUserMailAttachmentResp.Mail:type_name -> DBMailData 9, // 2: MailGetUserMailAttachmentResp.Mail:type_name -> DBMailData
8, // 3: MailDelMailResp.Mail:type_name -> DBMailData 9, // 3: MailDelMailResp.Mail:type_name -> DBMailData
4, // [4:4] is the sub-list for method output_type 9, // 4: MailGetNewMailPush.Mail:type_name -> DBMailData
4, // [4:4] is the sub-list for method input_type 5, // [5:5] is the sub-list for method output_type
4, // [4:4] is the sub-list for extension type_name 5, // [5:5] is the sub-list for method input_type
4, // [4:4] is the sub-list for extension extendee 5, // [5:5] is the sub-list for extension type_name
0, // [0:4] is the sub-list for field 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() } func init() { file_mail_mail_msg_proto_init() }
@ -563,6 +616,18 @@ func file_mail_mail_msg_proto_init() {
return nil 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{} type x struct{}
out := protoimpl.TypeBuilder{ out := protoimpl.TypeBuilder{
@ -570,7 +635,7 @@ func file_mail_mail_msg_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_mail_mail_msg_proto_rawDesc, RawDescriptor: file_mail_mail_msg_proto_rawDesc,
NumEnums: 0, NumEnums: 0,
NumMessages: 8, NumMessages: 9,
NumExtensions: 0, NumExtensions: 0,
NumServices: 0, NumServices: 0,
}, },