用户扩展数据图鉴数据保存

This commit is contained in:
meixiongfeng 2022-08-10 15:24:47 +08:00
parent 5b9b73f76b
commit 1670917a59
5 changed files with 48 additions and 10 deletions

View File

@ -3,10 +3,12 @@ package main
import (
"fmt"
"go_dreamfactory/cmd/robot"
"go_dreamfactory/pb"
"os"
"github.com/sirupsen/logrus"
flag "github.com/spf13/pflag"
"go.mongodb.org/mongo-driver/bson/primitive"
"github.com/spf13/cobra"
)
@ -38,8 +40,14 @@ var sid = flag.Int32("sid", 0, "区服ID")
var create = flag.Bool("create", false, "是否创建新账号") //false 不创建新账号
var role = flag.Bool("role", false, "创角")
func CloneNewHero(hero *pb.DBHero) (newHero *pb.DBHero) {
newHero = &*hero
newHero.Id = primitive.NewObjectID().Hex()
return
}
func main() {
Execute()
//Execute()
}
var runCmd = &cobra.Command{

View File

@ -22,6 +22,7 @@ import (
"time"
"github.com/golang/protobuf/ptypes"
"go.mongodb.org/mongo-driver/bson/primitive"
)
var service core.IService
@ -55,8 +56,19 @@ func (this *TestService) InitSys() {
}
func TestMain(m *testing.M) {
sz := GetMap()
if len(sz) == 0 {
sz = make(map[int32]int32, 0)
}
sz[2] = 2
hero := &pb.DBHero{}
hero.Block = false
hero.Lv = 12
new := CloneNewHero(hero)
fmt.Printf("%v", new)
service = newService(
rpcx.SetConfPath("../../bin/conf/worker_2.yaml"),
rpcx.SetConfPath("../../bin/conf/worker_1.yaml"),
)
service.OnInstallComp( //装备组件
s_gateComp, //此服务需要接受用户的消息 需要装备网关组件
@ -73,7 +85,20 @@ func TestMain(m *testing.M) {
time.Sleep(time.Second * 2)
defer os.Exit(m.Run())
}
func GetMap() map[int32]int32 {
return nil
}
func CloneNewHero(hero *pb.DBHero) (newHero *pb.DBHero) {
temp := *hero
newHero = &temp
newHero.Block = true
newHero.Lv = 100
newHero.Id = primitive.NewObjectID().Hex()
return
}
func Test_Modules(t *testing.T) {
data, _ := ptypes.MarshalAny(&pb.HeroListReq{})
reply := &pb.RPCMessageReply{}
s_gateComp.ReceiveMsg(context.Background(), &pb.AgentMessage{UserId: "0_62c79d66acc7aa239b07c21e", MainType: "hero", SubType: "list", Message: data}, reply)

View File

@ -102,7 +102,8 @@ func (this *ModelHero) createOneHero(uid string, heroCfgId string) (hero *pb.DBH
// 克隆一个英雄
func (this *ModelHero) CloneNewHero(hero *pb.DBHero) (newHero *pb.DBHero) {
newHero = &*hero
temp := *hero
newHero = &temp
newHero.Id = primitive.NewObjectID().Hex()
this.AddList(newHero.Uid, newHero.Id, newHero)
return
@ -115,11 +116,12 @@ func (this *ModelHero) initHeroOverlying(uid string, heroCfgId string, count int
// 添加图鉴
go func(uid, heroCfgId string) { // 携程处理 图鉴数据
if result, err1 := this.moduleHero.ModuleUser.GetUserExpand(uid); err1 == nil {
sz := make(map[string]bool, 0)
for k := range result.GetTujian() {
sz[k] = true
}
if _, ok := result.GetTujian()[heroCfgId]; !ok {
sz := result.GetTujian()
if len(sz) == 0 {
sz = make(map[string]bool, 0)
}
sz[heroCfgId] = true
initUpdate := map[string]interface{}{
"tujian": sz,

View File

@ -4,6 +4,7 @@ import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/lego/sys/redis"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"time"
@ -33,9 +34,10 @@ func (this *ModelRecord) getUserSession(uid string) (cuser *pb.CacheUser) {
//获取用户通过扩展表
func (this *ModelRecord) GetHeroRecord(uid string) (result *pb.DBHeroRecord, err error) {
result = &pb.DBHeroRecord{}
if err = this.Get(uid, result); err != nil {
if err = this.Get(uid, result); err != nil && err != redis.RedisNil {
return
}
err = nil
return result, err
}

View File

@ -4,6 +4,7 @@ import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/lego/sys/redis"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
)
@ -34,10 +35,10 @@ func (this *ModelExpand) getUserSession(uid string) (cuser *pb.CacheUser) {
//获取用户通过扩展表
func (this *ModelExpand) GetUserExpand(uid string) (result *pb.DBUserExpand, err error) {
result = &pb.DBUserExpand{}
if err = this.moduleUser.modelExpand.Get(uid, result); err != nil {
if err = this.moduleUser.modelExpand.Get(uid, result); err != nil && redis.RedisNil != err {
return
}
err = nil
return result, err
}