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",
"var": "8",
"intr": "日/周常任务刷新时间8点"
},
{
"index": "init_gold",
"var": "100000",
"intr": "初始金币"
},
{
"index": "init_hero",
"var": "15001, 25001",
"intr": "初始英雄"
}
]

View File

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

View File

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

View File

@ -68,6 +68,7 @@ func (r *Robot) Run() {
}
type builder struct {
desc string
mainType string
subType string
req proto.Message
@ -90,6 +91,7 @@ func (r *Robot) addBuilders(builders []*builder) {
func (r *Robot) handleReq() {
for _, b := range r.builders {
if b.req != nil && !b.requested {
time.Sleep(time.Second * 1)
b.requested = true
b.start = time.Now()
head := &pb.UserMessage{MainType: b.mainType, SubType: b.subType}
@ -113,7 +115,7 @@ func (r *Robot) handleRsp(msg *pb.UserMessage) {
if b.print == nil {
printReply(msg, b)
} 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)
fmt.Println("==============================")
}
@ -159,15 +161,14 @@ func (r *Robot) onUserLoaded() {
r.RunNotify()
//user
r.RunUser()
//hero
r.RunHero()
//friend
// r.RunFriend()
//pack
// r.RunPack()
//hero
r.RunHero()
}
//注册账号
@ -198,36 +199,36 @@ func (r *Robot) AccountRegister(account string, sid int32) {
fmt.Printf("account:%s 注册成功", regRsp.Account)
//登录
loginReg := &pb.UserLoginReq{
Account: account,
Sid: sid,
var user_builders = []*builder{
{
desc: "登录",
mainType: "user",
subType: "login",
req: &pb.UserLoginReq{
Account: account,
Sid: sid,
},
rsp: &pb.UserLoginResp{},
enabled: true,
},
}
head := &pb.UserMessage{
MainType: "user",
SubType: "login",
Sec: r.BuildSecStr(),
}
err = r.SendToClient(head, loginReg)
if err != nil {
log.Fatal(err)
}
r.addBuilders(user_builders)
r.handleReq()
}
}
//打印响应
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
if builder.start.IsZero() {
tt = time.Duration(0)
} else {
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 {
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{
{
//create
desc: "创角",
mainType: string(comm.ModuleUser),
subType: user.UserSubTypeCreate,
req: &pb.UserCreateReq{ //设置请求参数
NickName: "乐谷6301",
},
rsp: &pb.UserCreateRsp{},
// enabled: true,
rsp: &pb.UserCreateRsp{},
enabled: true,
},
}

View File

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

1
go.mod
View File

@ -21,6 +21,7 @@ require (
github.com/rs/xid v1.3.0
github.com/satori/go.uuid v1.2.0
github.com/smallnest/rpcx v1.7.4
github.com/spf13/cast v1.3.1
github.com/spf13/cobra v1.2.1
github.com/spf13/pflag v1.0.5
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/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/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
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 v1.2.1 h1:+KmjbUw1hriSNMF55oPrkZcb27aECyrj8V2ytv7kWDw=

View File

@ -6,6 +6,11 @@ import (
"go_dreamfactory/lego/core/cbase"
"go_dreamfactory/lego/sys/log"
"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.S = service.(base.IRPCXService)
this.M = module.(IModule)
err = this.LoadConfigure(game_global, cfg.NewGame_global)
return
}
@ -44,3 +50,25 @@ func (this *MCompConfigure) LoadMultiConfigure(confs map[string]interface{}) (er
func (this *MCompConfigure) GetConfigure(name string) (v interface{}, err error) {
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
}
} 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{
MainType: comm.MainTypeNotify,
SubType: comm.SubTypeErrorNotify,
@ -127,11 +127,11 @@ func (this *Agent) secAuth(msg *pb.UserMessage) error {
if !utils.ValidSecretKey(msg.Sec) { //验证失败
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
dec, err := base64.StdEncoding.DecodeString(base64Str[35:])
if err != nil {
@ -159,6 +159,10 @@ func decodeUserData(msg *pb.UserMessage) error {
return err
}
msg.Data = ad
} else {
if this.UserId() == "" {
return fmt.Errorf("no login")
}
}
return nil
}
@ -211,6 +215,7 @@ func (this *Agent) Close() {
func (this *Agent) messageDistribution(msg *pb.UserMessage) (err error) {
reply := &pb.RPCMessageReply{}
log.Debugf("agent:%s uId:%s MessageDistribution msg:%s.%s", this.sessionId, this.uId, msg.MainType, msg.SubType)
servicePath := comm.Service_Worker
if rule, ok := this.gateway.GetMsgDistribute(msg.MainType, msg.SubType); ok {
servicePath = rule
@ -232,7 +237,7 @@ func (this *Agent) messageDistribution(msg *pb.UserMessage) (err error) {
return
}
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{
MainType: comm.MainTypeNotify,
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 {
if hero == nil {
return fmt.Errorf("hero no exist")
func (this *ModelHero) consumeOneHeroCard(uid, heroId string, count int32) (err error) {
for i := 0; i < int(count); i++ {
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 {
err := this.modelHero.consumeOneHeroCard(v, count)
err := this.modelHero.consumeOneHeroCard(v.Uid, v.Id, count)
if err != nil {
return pb.ErrorCode_DBError
}

View File

@ -25,7 +25,7 @@ func (this *apiComp) Getlist(session comm.IUserSession, agrs map[string]interfac
dels []string
)
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 {
go func() { //异步处理修改数据
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) {
defer func() {
session.SendMsg(string(this.module.GetType()), SellItemResp, &pb.ItemsSellItemResp{})
session.SendMsg(string(this.module.GetType()), "sellitem", &pb.ItemsSellItemResp{})
}()
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) {
defer func() {
session.SendMsg(string(this.module.GetType()), UseItemResp, &pb.ItemsUseItemResp{})
session.SendMsg(string(this.module.GetType()), "useitem", &pb.ItemsUseItemResp{})
}()
return

View File

@ -41,6 +41,11 @@ func (this *apiComp) Create(session comm.IUserSession, result map[string]interfa
"name": req.NickName,
}
//设置初始金币
if val := this.module.configure.GetGlobalConf("init_gold"); val != "" {
update["gold"] = val
}
err := this.module.modelUser.Change(session.GetUserId(), update)
if err != nil {
code = pb.ErrorCode_DBError
@ -48,11 +53,13 @@ func (this *apiComp) Create(session comm.IUserSession, result map[string]interfa
}
//初始化英雄卡
defaultHero := []int32{15001, 25001} //TODO 从配置中读取
err = this.hero.CreateHero(session.GetUserId(), defaultHero...)
if err != nil {
code = pb.ErrorCode_HeroInitCreat
return
if val := this.module.configure.GetGlobalConf("init_hero"); val != "" {
defaultHero := utils.TrInt32(val)
err = this.hero.CreateHero(session.GetUserId(), defaultHero...)
if err != nil {
code = pb.ErrorCode_HeroInitCreat
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
modelUser *ModelUser
modelSession *ModelSession
configure *configureComp
}
func (this *User) GetType() core.M_Modules {
@ -35,6 +36,7 @@ func (this *User) OnInstallComp() {
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.modelUser = this.RegisterComp(new(ModelUser)).(*ModelUser)
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)
)
//统一错误码返回
type ErrorNotify struct {
//统一错误码推送
type NotifyErrorNotifyPush struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
@ -33,8 +33,8 @@ type ErrorNotify struct {
Data string `protobuf:"bytes,6,opt,name=Data,proto3" json:"Data"` // 错误数据
}
func (x *ErrorNotify) Reset() {
*x = ErrorNotify{}
func (x *NotifyErrorNotifyPush) Reset() {
*x = NotifyErrorNotifyPush{}
if protoimpl.UnsafeEnabled {
mi := &file_notify_notify_msg_proto_msgTypes[0]
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)
}
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]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -60,40 +60,40 @@ func (x *ErrorNotify) ProtoReflect() protoreflect.Message {
return mi.MessageOf(x)
}
// Deprecated: Use ErrorNotify.ProtoReflect.Descriptor instead.
func (*ErrorNotify) Descriptor() ([]byte, []int) {
// Deprecated: Use NotifyErrorNotifyPush.ProtoReflect.Descriptor instead.
func (*NotifyErrorNotifyPush) Descriptor() ([]byte, []int) {
return file_notify_notify_msg_proto_rawDescGZIP(), []int{0}
}
func (x *ErrorNotify) GetReqMainType() string {
func (x *NotifyErrorNotifyPush) GetReqMainType() string {
if x != nil {
return x.ReqMainType
}
return ""
}
func (x *ErrorNotify) GetReqSubType() string {
func (x *NotifyErrorNotifyPush) GetReqSubType() string {
if x != nil {
return x.ReqSubType
}
return ""
}
func (x *ErrorNotify) GetCode() ErrorCode {
func (x *NotifyErrorNotifyPush) GetCode() ErrorCode {
if x != nil {
return x.Code
}
return ErrorCode_Success
}
func (x *ErrorNotify) GetMessage() string {
func (x *NotifyErrorNotifyPush) GetMessage() string {
if x != nil {
return x.Message
}
return ""
}
func (x *ErrorNotify) GetData() string {
func (x *NotifyErrorNotifyPush) GetData() string {
if x != nil {
return x.Data
}
@ -105,18 +105,19 @@ var File_notify_notify_msg_proto protoreflect.FileDescriptor
var file_notify_notify_msg_proto_rawDesc = []byte{
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,
0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x9d, 0x01, 0x0a, 0x0b, 0x45,
0x72, 0x72, 0x6f, 0x72, 0x4e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x12, 0x20, 0x0a, 0x0b, 0x52, 0x65,
0x71, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
0x0b, 0x52, 0x65, 0x71, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a,
0x52, 0x65, 0x71, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
0x52, 0x0a, 0x52, 0x65, 0x71, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x04,
0x43, 0x6f, 0x64, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0a, 0x2e, 0x45, 0x72, 0x72,
0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07,
0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x4d,
0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x06,
0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b,
0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xa7, 0x01, 0x0a, 0x15, 0x4e,
0x6f, 0x74, 0x69, 0x66, 0x79, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x4e, 0x6f, 0x74, 0x69, 0x66, 0x79,
0x50, 0x75, 0x73, 0x68, 0x12, 0x20, 0x0a, 0x0b, 0x52, 0x65, 0x71, 0x4d, 0x61, 0x69, 0x6e, 0x54,
0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x52, 0x65, 0x71, 0x4d, 0x61,
0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x52, 0x65, 0x71, 0x53, 0x75, 0x62,
0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x52, 0x65, 0x71, 0x53,
0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x03,
0x20, 0x01, 0x28, 0x0e, 0x32, 0x0a, 0x2e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65,
0x52, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67,
0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65,
0x12, 0x12, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04,
0x44, 0x61, 0x74, 0x61, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x33,
}
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_goTypes = []interface{}{
(*ErrorNotify)(nil), // 0: ErrorNotify
(ErrorCode)(0), // 1: ErrorCode
(*NotifyErrorNotifyPush)(nil), // 0: NotifyErrorNotifyPush
(ErrorCode)(0), // 1: ErrorCode
}
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 input_type
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()
if !protoimpl.UnsafeEnabled {
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:
return &v.state
case 1:

View File

@ -2,8 +2,8 @@ syntax = "proto3";
option go_package = ".;pb";
import "errorcode.proto";
//
message ErrorNotify {
//
message NotifyErrorNotifyPush {
string ReqMainType =1; // :user user的模块
string ReqSubType = 2; // :login user的模块中 api_login
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.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)
//获取用户消息处理函数
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)
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)})
//读取校验结果 有错误直接返回错误码给用户
@ -159,6 +158,7 @@ func (this *SCompGateRoute) ReceiveMsg(ctx context.Context, args *pb.AgentMessag
reply.Reply = session.Polls()
}
} else { //未找到消息处理函数
log.Errorf("no found handle %s", method)
reply.Code = pb.ErrorCode_ReqParameterError
}
return nil

15
sys/cache/cache.go vendored
View File

@ -19,10 +19,17 @@ type Cache struct {
//初始化 redis 对象
func (this *Cache) init() (err error) {
this.redis, err = redis.NewSys(
redis.SetRedisType(redis.Redis_Cluster),
redis.SetRedis_Cluster_Addr(this.options.Redis_Addr),
redis.SetRedis_Cluster_Password(this.options.Redis_Password))
if this.options.Redis_IsCluster {
this.redis, err = redis.NewSys(
redis.SetRedisType(redis.Redis_Cluster),
redis.SetRedis_Cluster_Addr(this.options.Redis_Addr),
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
}

12
sys/cache/options.go vendored
View File

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

View File

@ -3,7 +3,6 @@ package configure
import (
"fmt"
"go_dreamfactory/lego/sys/log"
cfg "go_dreamfactory/sys/configure/structs"
"io/fs"
"io/ioutil"
"os"
@ -31,7 +30,6 @@ func newSys(options Options) (sys *Configure, err error) {
configure: make(map[string]interface{}),
fileinfos: make(map[string]*FileInfo),
}
err = sys.init()
return
}
@ -45,20 +43,6 @@ type Configure struct {
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) {
tc := time.NewTicker(time.Second * time.Duration(this.options.CheckInterval))
go func() {
@ -166,12 +150,12 @@ func (this *Configure) loaderConfigure(name string, handle *configurehandle) (er
fliepath = path.Join(this.options.ConfigurePath, name)
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
}
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
}
defer file.Close()

View File

@ -1,9 +1,12 @@
package utils
import (
"strconv"
"strings"
"go_dreamfactory/lego/sys/log"
"github.com/spf13/cast"
)
func ParseP(p string) (string, string, bool) {
@ -34,3 +37,24 @@ func DeleteString(list []string, ele string) []string {
}
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
}