This commit is contained in:
zhaocy 2022-07-18 13:39:04 +08:00
commit e82097fa14
6 changed files with 46 additions and 51 deletions

View File

@ -163,8 +163,9 @@ func ReadUint32ForString(buf []byte) (ret uint32, n int, err error) {
return
}
ret = uint32(ind)
n = 1
if len(buf) > 10 {
i := 0
i := 1
ind2 := intDigits[buf[i]]
if ind2 == invalidCharForNumber {
n = i
@ -228,7 +229,7 @@ func ReadUint32ForString(buf []byte) (ret uint32, n int, err error) {
return
}
}
for i := 1; i < len(buf); i++ {
for i := n; i < len(buf); i++ {
ind = intDigits[buf[i]]
if ind == invalidCharForNumber {
n = i
@ -260,6 +261,7 @@ func ReadUint64ForString(buf []byte) (ret uint64, n int, err error) {
return
}
ret = uint64(ind)
n = 1
if len(buf) > 10 {
i := 0
ind2 := intDigits[buf[i]]
@ -325,7 +327,7 @@ func ReadUint64ForString(buf []byte) (ret uint64, n int, err error) {
return
}
}
for i := 1; i < len(buf); i++ {
for i := n; i < len(buf); i++ {
ind = intDigits[buf[i]]
if ind == invalidCharForNumber {
n = i

View File

@ -411,7 +411,10 @@ func (this *MCompModel) GetList(uid string, data interface{}) (err error) {
elemPtr = sliceType.UnsafeGetIndex(dptr, n)
if *((*unsafe.Pointer)(elemPtr)) == nil {
newPtr := sliceelemType.UnsafeNew()
decoder.DecodeForMapJson(newPtr, v)
if err = decoder.DecodeForMapJson(newPtr, v); err != nil {
log.Errorf("err:%v", err)
return
}
*((*unsafe.Pointer)(elemPtr)) = newPtr
} else {
decoder.DecodeForMapJson(*((*unsafe.Pointer)(elemPtr)), v)

View File

@ -33,6 +33,7 @@ func (this *apiComp) Awaken(session comm.IUserSession, req *pb.HeroAwakenReq) (c
if code != pb.ErrorCode_Success {
return
}
AwakenConfig, err1 := this.module.configure.GetHeroAwakenConfig()
if err1 != nil {
code = pb.ErrorCode_ConfigNoFound

View File

@ -1,12 +1,19 @@
package hero
package hero_test
import (
"context"
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/lego"
"go_dreamfactory/lego/base/rpcx"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules/equipment"
"go_dreamfactory/modules/hero"
"go_dreamfactory/modules/items"
"go_dreamfactory/modules/task"
"go_dreamfactory/modules/user"
"go_dreamfactory/pb"
"go_dreamfactory/services"
"go_dreamfactory/sys/cache"
"go_dreamfactory/sys/configure"
@ -14,12 +21,14 @@ import (
"os"
"testing"
"time"
"github.com/golang/protobuf/ptypes"
)
var service core.IService
var s_gateComp comm.ISC_GateRouteComp = services.NewGateRouteComp()
var module = new(Hero)
var module = new(hero.Hero)
type TestService struct {
rpcx.RPCXService
@ -34,7 +43,7 @@ func newService(ops ...rpcx.Option) core.IService {
//初始化相关系统
func (this *TestService) InitSys() {
this.RPCXService.InitSys()
if err := cache.OnInit(this.GetSettings().Sys["cache"]); err != nil {
if err := cache.OnInit(this.GetSettings().Sys["cache"], cache.Set_Redis_Addr([]string{"10.0.0.9:10011"}), cache.Set_Redis_Password("li13451234"), cache.Set_Redis_DB(1)); err != nil {
panic(fmt.Sprintf("init sys.cache err: %s", err.Error()))
} else {
log.Infof("init sys.cache success!")
@ -44,7 +53,7 @@ func (this *TestService) InitSys() {
} else {
log.Infof("init sys.db success!")
}
if err := configure.OnInit(this.GetSettings().Sys["configure"], configure.SetConfigPath("E:\\projects\\workspace\\go_dreamfactory\\bin\\json")); err != nil {
if err := configure.OnInit(this.GetSettings().Sys["configure"], configure.SetConfigPath("F:/work/go/go_dreamfactory/bin/json")); err != nil {
panic(fmt.Sprintf("init sys.configure err: %s", err.Error()))
} else {
log.Infof("init sys.configure success!")
@ -61,40 +70,18 @@ func TestMain(m *testing.M) {
go func() {
lego.Run(service, //运行模块
module,
//
items.NewModule(),
user.NewModule(),
equipment.NewModule(),
task.NewModule(),
)
}()
time.Sleep(time.Second * 2)
defer os.Exit(m.Run())
}
//创建一个英雄s
func TestCreateOneHero(t *testing.T) {
err := module.modelHero.createOneHero("u1", 25001, true)
fmt.Println(err)
}
//获取玩家英雄
func TestGetOneHero(t *testing.T) {
d := module.modelHero.getOneHero("u1", "62b534bebf4745d4117acabe")
fmt.Printf("%v", d)
}
func TestPropertyCompute(t *testing.T) {
m := module.modelHero.PropertyCompute("u1", "62b534bebf4745d4117acabe")
fmt.Println(m)
}
func TestHeroList(t *testing.T) {
heroes := module.modelHero.getHeroList("u1")
fmt.Printf("%v", heroes)
}
func TestModify(t *testing.T) {
data := map[string]interface{}{
"lv": 2,
"exp": 1000,
}
err := module.modelHero.modifyHeroData("u1", "62b534bebf4745d4117acabe", data)
fmt.Printf("%v ", err)
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)
log.Debugf("reply:%v", reply)
}

View File

@ -20,13 +20,13 @@ func (this *apiComp) Getlist(session comm.IUserSession, req *pb.ItemsGetlistReq)
err error
items []*pb.DB_UserItemData
nt int64
tempgrids []*pb.DB_UserItemData
// tempgrids []*pb.DB_UserItemData
grids []*pb.DB_UserItemData
modifys []*pb.DB_UserItemData
dels []*pb.DB_UserItemData
)
defer func() {
session.SendMsg(string(this.module.GetType()), "getlist", &pb.ItemsGetlistResp{Grids: grids})
session.SendMsg(string(this.module.GetType()), "getlist", &pb.ItemsGetlistResp{Grids: items})
if code == pb.ErrorCode_Success {
go func() { //异步处理修改数据
if len(modifys) > 0 {
@ -44,12 +44,12 @@ func (this *apiComp) Getlist(session comm.IUserSession, req *pb.ItemsGetlistReq)
code = pb.ErrorCode_CacheReadError
return
} else {
tempgrids = this.module.configure.GetPackItemByType(items, req.IType)
modifys = make([]*pb.DB_UserItemData, 0, len(tempgrids))
dels = make([]*pb.DB_UserItemData, 0, len(tempgrids))
// tempgrids = this.module.configure.GetPackItemByType(items, req.IType)
modifys = make([]*pb.DB_UserItemData, 0, len(items))
dels = make([]*pb.DB_UserItemData, 0, len(items))
grids = make([]*pb.DB_UserItemData, 0, len(items))
nt = time.Now().Unix()
for _, v := range tempgrids {
for _, v := range items {
if v.ETime > 0 && v.ETime < nt { //已经过期
dels = append(dels, v)
} else {

View File

@ -155,6 +155,7 @@ func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn, bPush b
if v.A == comm.AttrType { //用户属性资源
if amount = this.ModuleUser.QueryAttributeValue(uid, v.T); amount < v.N {
code = pb.ErrorCode_ResNoEnough
this.Errorf("道具不足:A:%s,T:%s,N:%d", v.A, v.T, v.N)
return
}
} else if v.A == comm.ItemType { //道具资源
@ -164,6 +165,7 @@ func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn, bPush b
}
if amount = int32(this.ModuleItems.QueryItemAmount(source, uid, int32(resID))); amount < v.N {
code = pb.ErrorCode_ResNoEnough
this.Errorf("道具不足:A:%s,T:%s,N:%d", v.A, v.T, v.N)
return
}
}