This commit is contained in:
meixiongfeng 2022-06-30 16:16:25 +08:00
commit 810aec88cc
25 changed files with 203 additions and 106 deletions

View File

@ -28,5 +28,15 @@
"index": "task_reset", "index": "task_reset",
"var": "8", "var": "8",
"intr": "日/周常任务刷新时间8点" "intr": "日/周常任务刷新时间8点"
},
{
"index": "init_gold",
"var": "100000",
"intr": "初始金币"
},
{
"index": "init_hero",
"var": "15001, 25001",
"intr": "初始英雄"
} }
] ]

View File

@ -13,6 +13,7 @@ var (
//hero //hero
heroBuilders = []*builder{ heroBuilders = []*builder{
{ {
desc: "英雄列表",
mainType: string(comm.ModuleHero), mainType: string(comm.ModuleHero),
subType: hero.HeroSubTypeList, subType: hero.HeroSubTypeList,
req: &pb.HeroListReq{}, req: &pb.HeroListReq{},
@ -23,7 +24,7 @@ var (
fmt.Printf("%d- %v\n", (i + 1), v) fmt.Printf("%d- %v\n", (i + 1), v)
} }
}, },
// enabled: true, enabled: true,
}, { }, {
mainType: string(comm.ModuleHero), mainType: string(comm.ModuleHero),
subType: hero.HeroSubTypeInfo, subType: hero.HeroSubTypeInfo,
@ -62,7 +63,7 @@ var (
Amount: 1, Amount: 1,
}, },
rsp: &pb.HeroStrengthenUplvResp{}, rsp: &pb.HeroStrengthenUplvResp{},
enabled: true, // enabled: true,
}, },
} }
) )

View File

@ -10,7 +10,7 @@ var notify_builders = []*builder{
//create //create
mainType: comm.MainTypeNotify, mainType: comm.MainTypeNotify,
subType: comm.SubTypeErrorNotify, subType: comm.SubTypeErrorNotify,
rsp: &pb.ErrorNotify{}, rsp: &pb.NotifyErrorNotifyPush{},
enabled: true, enabled: true,
}, },
} }

View File

@ -68,6 +68,7 @@ func (r *Robot) Run() {
} }
type builder struct { type builder struct {
desc string
mainType string mainType string
subType string subType string
req proto.Message req proto.Message
@ -90,6 +91,7 @@ func (r *Robot) addBuilders(builders []*builder) {
func (r *Robot) handleReq() { func (r *Robot) handleReq() {
for _, b := range r.builders { for _, b := range r.builders {
if b.req != nil && !b.requested { if b.req != nil && !b.requested {
time.Sleep(time.Second * 1)
b.requested = true b.requested = true
b.start = time.Now() b.start = time.Now()
head := &pb.UserMessage{MainType: b.mainType, SubType: b.subType} head := &pb.UserMessage{MainType: b.mainType, SubType: b.subType}
@ -113,7 +115,7 @@ func (r *Robot) handleRsp(msg *pb.UserMessage) {
if b.print == nil { if b.print == nil {
printReply(msg, b) printReply(msg, b)
} else { } else {
fmt.Printf("===== rsp [%s.%s] =====\n", msg.MainType, msg.SubType) fmt.Printf("===== %s [%s.%s] =====\n", b.desc, msg.MainType, msg.SubType)
b.print(b.rsp) b.print(b.rsp)
fmt.Println("==============================") fmt.Println("==============================")
} }
@ -159,15 +161,14 @@ func (r *Robot) onUserLoaded() {
r.RunNotify() r.RunNotify()
//user //user
r.RunUser() r.RunUser()
//hero
r.RunHero()
//friend //friend
// r.RunFriend() // r.RunFriend()
//pack //pack
// r.RunPack() // r.RunPack()
//hero
r.RunHero()
} }
//注册账号 //注册账号
@ -198,36 +199,36 @@ func (r *Robot) AccountRegister(account string, sid int32) {
fmt.Printf("account:%s 注册成功", regRsp.Account) fmt.Printf("account:%s 注册成功", regRsp.Account)
//登录 //登录
loginReg := &pb.UserLoginReq{ var user_builders = []*builder{
{
desc: "登录",
mainType: "user",
subType: "login",
req: &pb.UserLoginReq{
Account: account, Account: account,
Sid: sid, Sid: sid,
},
rsp: &pb.UserLoginResp{},
enabled: true,
},
} }
r.addBuilders(user_builders)
head := &pb.UserMessage{ r.handleReq()
MainType: "user",
SubType: "login",
Sec: r.BuildSecStr(),
}
err = r.SendToClient(head, loginReg)
if err != nil {
log.Fatal(err)
}
} }
} }
//打印响应 //打印响应
func printReply(msg *pb.UserMessage, builder *builder) { func printReply(msg *pb.UserMessage, builder *builder) {
if m, ok := builder.rsp.(*pb.ErrorNotify); ok { if m, ok := builder.rsp.(*pb.NotifyErrorNotifyPush); ok {
var tt time.Duration var tt time.Duration
if builder.start.IsZero() { if builder.start.IsZero() {
tt = time.Duration(0) tt = time.Duration(0)
} else { } else {
tt = time.Since(builder.start) tt = time.Since(builder.start)
} }
log.Printf("rsp [%v] [%s.%s] [%v:%v]", tt, m.ReqMainType, m.ReqSubType, int32(m.Code), m.Data) log.Printf("rsp %s [%v] [%s.%s] [%v:%v]", builder.desc, tt, m.ReqMainType, m.ReqSubType, int32(m.Code), m.Data)
} else { } else {
log.Printf("rsp [%v] [%s.%s] [%v]", time.Since(builder.start), msg.MainType, msg.SubType, builder.rsp) log.Printf("rsp %s [%v] [%s.%s] [%v]", builder.desc, time.Since(builder.start), msg.MainType, msg.SubType, builder.rsp)
} }
} }

View File

@ -10,13 +10,14 @@ import (
var user_builders = []*builder{ var user_builders = []*builder{
{ {
//create //create
desc: "创角",
mainType: string(comm.ModuleUser), mainType: string(comm.ModuleUser),
subType: user.UserSubTypeCreate, subType: user.UserSubTypeCreate,
req: &pb.UserCreateReq{ //设置请求参数 req: &pb.UserCreateReq{ //设置请求参数
NickName: "乐谷6301", NickName: "乐谷6301",
}, },
rsp: &pb.UserCreateRsp{}, rsp: &pb.UserCreateRsp{},
// enabled: true, enabled: true,
}, },
} }

View File

@ -38,7 +38,7 @@ const (
ModuleEquipment core.M_Modules = "equipment" //装备模块 ModuleEquipment core.M_Modules = "equipment" //装备模块
ModuleHero core.M_Modules = "hero" //英雄模块 ModuleHero core.M_Modules = "hero" //英雄模块
ModuleForum core.M_Modules = "forum" //论坛模块 ModuleForum core.M_Modules = "forum" //论坛模块
ModuleItems core.M_Modules = "item" ModuleItems core.M_Modules = "items" //道具模块
) )
//RPC服务接口定义处 //RPC服务接口定义处

1
go.mod
View File

@ -21,6 +21,7 @@ require (
github.com/rs/xid v1.3.0 github.com/rs/xid v1.3.0
github.com/satori/go.uuid v1.2.0 github.com/satori/go.uuid v1.2.0
github.com/smallnest/rpcx v1.7.4 github.com/smallnest/rpcx v1.7.4
github.com/spf13/cast v1.3.1
github.com/spf13/cobra v1.2.1 github.com/spf13/cobra v1.2.1
github.com/spf13/pflag v1.0.5 github.com/spf13/pflag v1.0.5
github.com/tidwall/gjson v1.14.1 github.com/tidwall/gjson v1.14.1

1
go.sum
View File

@ -623,6 +623,7 @@ github.com/soheilhy/cmux v0.1.5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE
github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:UdhH50NIW0fCiwBSr0co2m7BnFLdv4fQTgdqdJTHFeE= github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:UdhH50NIW0fCiwBSr0co2m7BnFLdv4fQTgdqdJTHFeE=
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA= github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA=
github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/cobra v1.2.1 h1:+KmjbUw1hriSNMF55oPrkZcb27aECyrj8V2ytv7kWDw= github.com/spf13/cobra v1.2.1 h1:+KmjbUw1hriSNMF55oPrkZcb27aECyrj8V2ytv7kWDw=

View File

@ -6,6 +6,11 @@ import (
"go_dreamfactory/lego/core/cbase" "go_dreamfactory/lego/core/cbase"
"go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/log"
"go_dreamfactory/sys/configure" "go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
)
const (
game_global = "game_global.json"
) )
///配置管理基础组件 ///配置管理基础组件
@ -20,6 +25,7 @@ func (this *MCompConfigure) Init(service core.IService, module core.IModule, com
this.ModuleCompBase.Init(service, module, comp, options) this.ModuleCompBase.Init(service, module, comp, options)
this.S = service.(base.IRPCXService) this.S = service.(base.IRPCXService)
this.M = module.(IModule) this.M = module.(IModule)
err = this.LoadConfigure(game_global, cfg.NewGame_global)
return return
} }
@ -44,3 +50,25 @@ func (this *MCompConfigure) LoadMultiConfigure(confs map[string]interface{}) (er
func (this *MCompConfigure) GetConfigure(name string) (v interface{}, err error) { func (this *MCompConfigure) GetConfigure(name string) (v interface{}, err error) {
return configure.GetConfigure(name) return configure.GetConfigure(name)
} }
//全局配置
func (this *MCompConfigure) GetGlobalConf(key string) string {
if v, err := this.GetConfigure(game_global); err != nil {
log.Errorf("get global conf err:%v", err)
return ""
} else {
var (
configure *cfg.Game_global
ok bool
)
if configure, ok = v.(*cfg.Game_global); !ok {
log.Errorf("%T no is *cfg.Game_global", v)
return ""
}
if v, ok := configure.GetDataMap()[key]; ok {
return v.Var
}
}
return ""
}

View File

@ -81,7 +81,7 @@ locp:
break locp break locp
} }
} else { } else {
data, _ := anypb.New(&pb.ErrorNotify{ReqMainType: msg.MainType, ReqSubType: msg.SubType, Code: pb.ErrorCode_SecKeyInvalid}) data, _ := anypb.New(&pb.NotifyErrorNotifyPush{ReqMainType: msg.MainType, ReqSubType: msg.SubType, Code: pb.ErrorCode_SecKeyInvalid, Message: err.Error()})
if err = this.WriteMsg(&pb.UserMessage{ if err = this.WriteMsg(&pb.UserMessage{
MainType: comm.MainTypeNotify, MainType: comm.MainTypeNotify,
SubType: comm.SubTypeErrorNotify, SubType: comm.SubTypeErrorNotify,
@ -127,11 +127,11 @@ func (this *Agent) secAuth(msg *pb.UserMessage) error {
if !utils.ValidSecretKey(msg.Sec) { //验证失败 if !utils.ValidSecretKey(msg.Sec) { //验证失败
return fmt.Errorf("key invalid") return fmt.Errorf("key invalid")
} }
return decodeUserData(msg) return this.decodeUserData(msg)
} }
//解码 //解码
func decodeUserData(msg *pb.UserMessage) error { func (this *Agent) decodeUserData(msg *pb.UserMessage) error {
base64Str := msg.Sec base64Str := msg.Sec
dec, err := base64.StdEncoding.DecodeString(base64Str[35:]) dec, err := base64.StdEncoding.DecodeString(base64Str[35:])
if err != nil { if err != nil {
@ -159,6 +159,10 @@ func decodeUserData(msg *pb.UserMessage) error {
return err return err
} }
msg.Data = ad msg.Data = ad
} else {
if this.UserId() == "" {
return fmt.Errorf("no login")
}
} }
return nil return nil
} }
@ -211,6 +215,7 @@ func (this *Agent) Close() {
func (this *Agent) messageDistribution(msg *pb.UserMessage) (err error) { func (this *Agent) messageDistribution(msg *pb.UserMessage) (err error) {
reply := &pb.RPCMessageReply{} reply := &pb.RPCMessageReply{}
log.Debugf("agent:%s uId:%s MessageDistribution msg:%s.%s", this.sessionId, this.uId, msg.MainType, msg.SubType) log.Debugf("agent:%s uId:%s MessageDistribution msg:%s.%s", this.sessionId, this.uId, msg.MainType, msg.SubType)
servicePath := comm.Service_Worker servicePath := comm.Service_Worker
if rule, ok := this.gateway.GetMsgDistribute(msg.MainType, msg.SubType); ok { if rule, ok := this.gateway.GetMsgDistribute(msg.MainType, msg.SubType); ok {
servicePath = rule servicePath = rule
@ -232,7 +237,7 @@ func (this *Agent) messageDistribution(msg *pb.UserMessage) (err error) {
return return
} }
if reply.Code != pb.ErrorCode_Success { if reply.Code != pb.ErrorCode_Success {
data, _ := anypb.New(&pb.ErrorNotify{ReqMainType: msg.MainType, ReqSubType: msg.SubType, Code: pb.ErrorCode(reply.Code.Number())}) data, _ := anypb.New(&pb.NotifyErrorNotifyPush{ReqMainType: msg.MainType, ReqSubType: msg.SubType, Code: pb.ErrorCode(reply.Code.Number())})
err = this.WriteMsg(&pb.UserMessage{ err = this.WriteMsg(&pb.UserMessage{
MainType: comm.MainTypeNotify, MainType: comm.MainTypeNotify,
SubType: comm.SubTypeErrorNotify, SubType: comm.SubTypeErrorNotify,

View File

@ -119,14 +119,14 @@ func (this *ModelHero) getOneHero(uid, heroId string) *pb.DBHero {
} }
//消耗一张英雄卡 //消耗一张英雄卡
func (this *ModelHero) consumeOneHeroCard(hero *pb.DBHero, count int32) error { func (this *ModelHero) consumeOneHeroCard(uid, heroId string, count int32) (err error) {
if hero == nil { for i := 0; i < int(count); i++ {
return fmt.Errorf("hero no exist") if err := this.moduleHero.modelHero.DelListlds(uid, heroId); err != nil {
log.Errorf("%v", err)
break
} }
if hero.SameCount < count {
return fmt.Errorf("card no enough")
} }
return this.moduleHero.modelHero.DelListlds(hero.Uid, hero.Id) return
} }
//更新英雄数据 //更新英雄数据

View File

@ -58,7 +58,7 @@ func (this *Hero) ChangeCard(uId string, heroCfgId int32, count int32) (code pb.
} }
for _, v := range curList { for _, v := range curList {
err := this.modelHero.consumeOneHeroCard(v, count) err := this.modelHero.consumeOneHeroCard(v.Uid, v.Id, count)
if err != nil { if err != nil {
return pb.ErrorCode_DBError return pb.ErrorCode_DBError
} }

View File

@ -25,7 +25,7 @@ func (this *apiComp) Getlist(session comm.IUserSession, agrs map[string]interfac
dels []string dels []string
) )
defer func() { defer func() {
session.SendMsg(string(this.module.GetType()), GetlistResp, &pb.ItemsGetlistResp{Grids: grids}) session.SendMsg(string(this.module.GetType()), "getlist", &pb.ItemsGetlistResp{Grids: grids})
if code == pb.ErrorCode_Success { if code == pb.ErrorCode_Success {
go func() { //异步处理修改数据 go func() { //异步处理修改数据
this.module.modelItems.Pack_UpdateUserPack(session.GetUserId(), modifys...) this.module.modelItems.Pack_UpdateUserPack(session.GetUserId(), modifys...)

View File

@ -14,7 +14,7 @@ func (this *apiComp) SellItemCheck(session comm.IUserSession, req *pb.ItemsSellI
//出售道具 //出售道具
func (this *apiComp) SellItem(session comm.IUserSession, agrs map[string]interface{}, req *pb.ItemsSellItemReq) (code pb.ErrorCode) { func (this *apiComp) SellItem(session comm.IUserSession, agrs map[string]interface{}, req *pb.ItemsSellItemReq) (code pb.ErrorCode) {
defer func() { defer func() {
session.SendMsg(string(this.module.GetType()), SellItemResp, &pb.ItemsSellItemResp{}) session.SendMsg(string(this.module.GetType()), "sellitem", &pb.ItemsSellItemResp{})
}() }()
return return
} }

View File

@ -14,7 +14,7 @@ func (this *apiComp) UseitemCheck(session comm.IUserSession, req *pb.ItemsUseIte
//使用道具 //使用道具
func (this *apiComp) Useitem(session comm.IUserSession, agrs map[string]interface{}, req *pb.ItemsUseItemReq) (code pb.ErrorCode) { func (this *apiComp) Useitem(session comm.IUserSession, agrs map[string]interface{}, req *pb.ItemsUseItemReq) (code pb.ErrorCode) {
defer func() { defer func() {
session.SendMsg(string(this.module.GetType()), UseItemResp, &pb.ItemsUseItemResp{}) session.SendMsg(string(this.module.GetType()), "useitem", &pb.ItemsUseItemResp{})
}() }()
return return

View File

@ -41,6 +41,11 @@ func (this *apiComp) Create(session comm.IUserSession, result map[string]interfa
"name": req.NickName, "name": req.NickName,
} }
//设置初始金币
if val := this.module.configure.GetGlobalConf("init_gold"); val != "" {
update["gold"] = val
}
err := this.module.modelUser.Change(session.GetUserId(), update) err := this.module.modelUser.Change(session.GetUserId(), update)
if err != nil { if err != nil {
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
@ -48,12 +53,14 @@ func (this *apiComp) Create(session comm.IUserSession, result map[string]interfa
} }
//初始化英雄卡 //初始化英雄卡
defaultHero := []int32{15001, 25001} //TODO 从配置中读取 if val := this.module.configure.GetGlobalConf("init_hero"); val != "" {
defaultHero := utils.TrInt32(val)
err = this.hero.CreateHero(session.GetUserId(), defaultHero...) err = this.hero.CreateHero(session.GetUserId(), defaultHero...)
if err != nil { if err != nil {
code = pb.ErrorCode_HeroInitCreat code = pb.ErrorCode_HeroInitCreat
return return
} }
}
return return
} }

16
modules/user/configure.go Normal file
View File

@ -0,0 +1,16 @@
package user
import (
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
)
type configureComp struct {
modules.MCompConfigure
}
//组件初始化接口
func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
err = this.MCompConfigure.Init(service, module, comp, options)
return
}

View File

@ -18,6 +18,7 @@ type User struct {
api *apiComp api *apiComp
modelUser *ModelUser modelUser *ModelUser
modelSession *ModelSession modelSession *ModelSession
configure *configureComp
} }
func (this *User) GetType() core.M_Modules { func (this *User) GetType() core.M_Modules {
@ -35,6 +36,7 @@ func (this *User) OnInstallComp() {
this.api = this.RegisterComp(new(apiComp)).(*apiComp) this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.modelUser = this.RegisterComp(new(ModelUser)).(*ModelUser) this.modelUser = this.RegisterComp(new(ModelUser)).(*ModelUser)
this.modelSession = this.RegisterComp(new(ModelSession)).(*ModelSession) this.modelSession = this.RegisterComp(new(ModelSession)).(*ModelSession)
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
} }
//获取英雄列表 //获取英雄列表

View File

@ -20,8 +20,8 @@ const (
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
) )
//统一错误码返回 //统一错误码推送
type ErrorNotify struct { type NotifyErrorNotifyPush struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
@ -33,8 +33,8 @@ type ErrorNotify struct {
Data string `protobuf:"bytes,6,opt,name=Data,proto3" json:"Data"` // 错误数据 Data string `protobuf:"bytes,6,opt,name=Data,proto3" json:"Data"` // 错误数据
} }
func (x *ErrorNotify) Reset() { func (x *NotifyErrorNotifyPush) Reset() {
*x = ErrorNotify{} *x = NotifyErrorNotifyPush{}
if protoimpl.UnsafeEnabled { if protoimpl.UnsafeEnabled {
mi := &file_notify_notify_msg_proto_msgTypes[0] mi := &file_notify_notify_msg_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -42,13 +42,13 @@ func (x *ErrorNotify) Reset() {
} }
} }
func (x *ErrorNotify) String() string { func (x *NotifyErrorNotifyPush) String() string {
return protoimpl.X.MessageStringOf(x) return protoimpl.X.MessageStringOf(x)
} }
func (*ErrorNotify) ProtoMessage() {} func (*NotifyErrorNotifyPush) ProtoMessage() {}
func (x *ErrorNotify) ProtoReflect() protoreflect.Message { func (x *NotifyErrorNotifyPush) ProtoReflect() protoreflect.Message {
mi := &file_notify_notify_msg_proto_msgTypes[0] mi := &file_notify_notify_msg_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil { if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -60,40 +60,40 @@ func (x *ErrorNotify) ProtoReflect() protoreflect.Message {
return mi.MessageOf(x) return mi.MessageOf(x)
} }
// Deprecated: Use ErrorNotify.ProtoReflect.Descriptor instead. // Deprecated: Use NotifyErrorNotifyPush.ProtoReflect.Descriptor instead.
func (*ErrorNotify) Descriptor() ([]byte, []int) { func (*NotifyErrorNotifyPush) Descriptor() ([]byte, []int) {
return file_notify_notify_msg_proto_rawDescGZIP(), []int{0} return file_notify_notify_msg_proto_rawDescGZIP(), []int{0}
} }
func (x *ErrorNotify) GetReqMainType() string { func (x *NotifyErrorNotifyPush) GetReqMainType() string {
if x != nil { if x != nil {
return x.ReqMainType return x.ReqMainType
} }
return "" return ""
} }
func (x *ErrorNotify) GetReqSubType() string { func (x *NotifyErrorNotifyPush) GetReqSubType() string {
if x != nil { if x != nil {
return x.ReqSubType return x.ReqSubType
} }
return "" return ""
} }
func (x *ErrorNotify) GetCode() ErrorCode { func (x *NotifyErrorNotifyPush) GetCode() ErrorCode {
if x != nil { if x != nil {
return x.Code return x.Code
} }
return ErrorCode_Success return ErrorCode_Success
} }
func (x *ErrorNotify) GetMessage() string { func (x *NotifyErrorNotifyPush) GetMessage() string {
if x != nil { if x != nil {
return x.Message return x.Message
} }
return "" return ""
} }
func (x *ErrorNotify) GetData() string { func (x *NotifyErrorNotifyPush) GetData() string {
if x != nil { if x != nil {
return x.Data return x.Data
} }
@ -105,18 +105,19 @@ var File_notify_notify_msg_proto protoreflect.FileDescriptor
var file_notify_notify_msg_proto_rawDesc = []byte{ var file_notify_notify_msg_proto_rawDesc = []byte{
0x0a, 0x17, 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x2f, 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x5f, 0x0a, 0x17, 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x2f, 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x5f,
0x6d, 0x73, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x6d, 0x73, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72,
0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x9d, 0x01, 0x0a, 0x0b, 0x45, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xa7, 0x01, 0x0a, 0x15, 0x4e,
0x72, 0x72, 0x6f, 0x72, 0x4e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x12, 0x20, 0x0a, 0x0b, 0x52, 0x65, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x4e, 0x6f, 0x74, 0x69, 0x66, 0x79,
0x71, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x50, 0x75, 0x73, 0x68, 0x12, 0x20, 0x0a, 0x0b, 0x52, 0x65, 0x71, 0x4d, 0x61, 0x69, 0x6e, 0x54,
0x0b, 0x52, 0x65, 0x71, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x52, 0x65, 0x71, 0x4d, 0x61,
0x52, 0x65, 0x71, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x52, 0x65, 0x71, 0x53, 0x75, 0x62,
0x52, 0x0a, 0x52, 0x65, 0x71, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x52, 0x65, 0x71, 0x53,
0x43, 0x6f, 0x64, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0a, 0x2e, 0x45, 0x72, 0x72, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x03,
0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0a, 0x2e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65,
0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x4d, 0x52, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67,
0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x06, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65,
0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x12, 0x12, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04,
0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 0x44, 0x61, 0x74, 0x61, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (
@ -133,11 +134,11 @@ func file_notify_notify_msg_proto_rawDescGZIP() []byte {
var file_notify_notify_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 1) var file_notify_notify_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
var file_notify_notify_msg_proto_goTypes = []interface{}{ var file_notify_notify_msg_proto_goTypes = []interface{}{
(*ErrorNotify)(nil), // 0: ErrorNotify (*NotifyErrorNotifyPush)(nil), // 0: NotifyErrorNotifyPush
(ErrorCode)(0), // 1: ErrorCode (ErrorCode)(0), // 1: ErrorCode
} }
var file_notify_notify_msg_proto_depIdxs = []int32{ var file_notify_notify_msg_proto_depIdxs = []int32{
1, // 0: ErrorNotify.Code:type_name -> ErrorCode 1, // 0: NotifyErrorNotifyPush.Code:type_name -> ErrorCode
1, // [1:1] is the sub-list for method output_type 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 method input_type
1, // [1:1] is the sub-list for extension type_name 1, // [1:1] is the sub-list for extension type_name
@ -153,7 +154,7 @@ func file_notify_notify_msg_proto_init() {
file_errorcode_proto_init() file_errorcode_proto_init()
if !protoimpl.UnsafeEnabled { if !protoimpl.UnsafeEnabled {
file_notify_notify_msg_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { file_notify_notify_msg_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ErrorNotify); i { switch v := v.(*NotifyErrorNotifyPush); i {
case 0: case 0:
return &v.state return &v.state
case 1: case 1:

View File

@ -2,8 +2,8 @@ syntax = "proto3";
option go_package = ".;pb"; option go_package = ".;pb";
import "errorcode.proto"; import "errorcode.proto";
// //
message ErrorNotify { message NotifyErrorNotifyPush {
string ReqMainType =1; // :user user的模块 string ReqMainType =1; // :user user的模块
string ReqSubType = 2; // :login user的模块中 api_login string ReqSubType = 2; // :login user的模块中 api_login
ErrorCode Code = 3; // errorcode.proto ErrorCode Code = 3; // errorcode.proto

View File

@ -102,7 +102,6 @@ func (this *SCompGateRoute) ReceiveMsg(ctx context.Context, args *pb.AgentMessag
log.Errorf("HandleUserMsg:[%s-%s] err:%s", args.MainType, args.SubType, reply.ErrorMessage) log.Errorf("HandleUserMsg:[%s-%s] err:%s", args.MainType, args.SubType, reply.ErrorMessage)
} }
}() }()
log.Debugf("SCompGateRoute ReceiveMsg agent:%s uId:%s MessageDistribution:[%s-%s]", args.UserSessionId, args.UserId, args.MainType, args.SubType)
method := fmt.Sprintf("%s.%s", args.MainType, args.SubType) method := fmt.Sprintf("%s.%s", args.MainType, args.SubType)
//获取用户消息处理函数 //获取用户消息处理函数
this.mrlock.RLock() this.mrlock.RLock()
@ -126,7 +125,7 @@ func (this *SCompGateRoute) ReceiveMsg(ctx context.Context, args *pb.AgentMessag
log.Errorf("UserMessage:%s Unmarshal err:%v", method, err) log.Errorf("UserMessage:%s Unmarshal err:%v", method, err)
return err return err
} }
log.Debugf("ReceiveMsg Message:[%s-%s]-%v user[%s-%s]", args.MainType, args.SubType, msg, args.UserSessionId, args.UserId)
//调用校验接口 //调用校验接口
checkreturn := msghandle.check.Func.Call([]reflect.Value{msghandle.rcvr, reflect.ValueOf(session), reflect.ValueOf(msg)}) checkreturn := msghandle.check.Func.Call([]reflect.Value{msghandle.rcvr, reflect.ValueOf(session), reflect.ValueOf(msg)})
//读取校验结果 有错误直接返回错误码给用户 //读取校验结果 有错误直接返回错误码给用户
@ -159,6 +158,7 @@ func (this *SCompGateRoute) ReceiveMsg(ctx context.Context, args *pb.AgentMessag
reply.Reply = session.Polls() reply.Reply = session.Polls()
} }
} else { //未找到消息处理函数 } else { //未找到消息处理函数
log.Errorf("no found handle %s", method)
reply.Code = pb.ErrorCode_ReqParameterError reply.Code = pb.ErrorCode_ReqParameterError
} }
return nil return nil

7
sys/cache/cache.go vendored
View File

@ -19,10 +19,17 @@ type Cache struct {
//初始化 redis 对象 //初始化 redis 对象
func (this *Cache) init() (err error) { func (this *Cache) init() (err error) {
if this.options.Redis_IsCluster {
this.redis, err = redis.NewSys( this.redis, err = redis.NewSys(
redis.SetRedisType(redis.Redis_Cluster), redis.SetRedisType(redis.Redis_Cluster),
redis.SetRedis_Cluster_Addr(this.options.Redis_Addr), redis.SetRedis_Cluster_Addr(this.options.Redis_Addr),
redis.SetRedis_Cluster_Password(this.options.Redis_Password)) redis.SetRedis_Cluster_Password(this.options.Redis_Password))
} else {
this.redis, err = redis.NewSys(
redis.SetRedisType(redis.Redis_Single),
redis.SetRedis_Single_Addr(this.options.Redis_Addr[0]),
redis.SetRedis_Single_Password(this.options.Redis_Password))
}
return return
} }

View File

@ -11,10 +11,18 @@ import (
*/ */
type Option func(*Options) type Option func(*Options)
type Options struct { type Options struct {
Redis_IsCluster bool //是否是集群
Redis_Addr []string //redis 的集群地址 Redis_Addr []string //redis 的集群地址
Redis_Password string //redis的密码 Redis_Password string //redis的密码
} }
//设置系统的集群地址
func Set_Redis_IsCluster(v bool) Option {
return func(o *Options) {
o.Redis_IsCluster = v
}
}
//设置系统的集群地址 //设置系统的集群地址
func Set_Redis_Addr(v []string) Option { func Set_Redis_Addr(v []string) Option {
return func(o *Options) { return func(o *Options) {

View File

@ -3,7 +3,6 @@ package configure
import ( import (
"fmt" "fmt"
"go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/log"
cfg "go_dreamfactory/sys/configure/structs"
"io/fs" "io/fs"
"io/ioutil" "io/ioutil"
"os" "os"
@ -31,7 +30,6 @@ func newSys(options Options) (sys *Configure, err error) {
configure: make(map[string]interface{}), configure: make(map[string]interface{}),
fileinfos: make(map[string]*FileInfo), fileinfos: make(map[string]*FileInfo),
} }
err = sys.init()
return return
} }
@ -45,20 +43,6 @@ type Configure struct {
fileinfos map[string]*FileInfo fileinfos map[string]*FileInfo
} }
const (
game_com = "game_com.json"
)
func (this *Configure) init() (err error) {
this.RegisterConfigure(game_com, cfg.NewGame_com)
// _data := this.configure[game_com]
// if _da, ok := _data.(*cfg.Game_com).GetDataMap()["max_char"]; ok {
// log.Debugf("%b==%v", ok, _da.Var)
// }
return
}
func (this *Configure) Start() (err error) { func (this *Configure) Start() (err error) {
tc := time.NewTicker(time.Second * time.Duration(this.options.CheckInterval)) tc := time.NewTicker(time.Second * time.Duration(this.options.CheckInterval))
go func() { go func() {
@ -166,12 +150,12 @@ func (this *Configure) loaderConfigure(name string, handle *configurehandle) (er
fliepath = path.Join(this.options.ConfigurePath, name) fliepath = path.Join(this.options.ConfigurePath, name)
if fileInfo, err = os.Stat(fliepath); err != nil { if fileInfo, err = os.Stat(fliepath); err != nil {
err = fmt.Errorf("no fond file:%s", fliepath) err = fmt.Errorf("no found file:%s", fliepath)
return return
} }
if file, err = os.Open(fliepath); err != nil { if file, err = os.Open(fliepath); err != nil {
err = fmt.Errorf("no fond file:%s", fliepath) err = fmt.Errorf("no found file:%s", fliepath)
return return
} }
defer file.Close() defer file.Close()

View File

@ -1,9 +1,12 @@
package utils package utils
import ( import (
"strconv"
"strings" "strings"
"go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/log"
"github.com/spf13/cast"
) )
func ParseP(p string) (string, string, bool) { func ParseP(p string) (string, string, bool) {
@ -34,3 +37,24 @@ func DeleteString(list []string, ele string) []string {
} }
return result return result
} }
//转换包含数字字符串数组
//eg. "3,4,5" to []int32{3,4,5}
func TrInt32(val string) (nums []int32) {
strArr := strings.Split(val, ",")
if len(strArr) == 0 {
return
}
for _, n := range strArr {
if IsNum(strings.TrimSpace(n)) {
nums = append(nums, cast.ToInt32(strings.TrimSpace(n)))
}
}
return
}
func IsNum(s string) bool {
_, err := strconv.ParseFloat(s, 64)
return err == nil
}