Merge branch 'dev' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev
This commit is contained in:
commit
875285034f
@ -108,22 +108,36 @@ func (this *mapEncoder) Encode(ptr unsafe.Pointer, stream core.IStream) {
|
||||
|
||||
func (this *mapEncoder) EncodeToMapJson(ptr unsafe.Pointer) (ret map[string]string, err error) {
|
||||
ret = make(map[string]string)
|
||||
var (
|
||||
k, v string
|
||||
)
|
||||
|
||||
keystream := this.codec.BorrowStream()
|
||||
elemstream := this.codec.BorrowStream()
|
||||
iter := this.mapType.UnsafeIterate(ptr)
|
||||
for i := 0; iter.HasNext(); i++ {
|
||||
key, elem := iter.UnsafeNext()
|
||||
this.keyEncoder.Encode(key, keystream)
|
||||
if keystream.Error() != nil && keystream.Error() != io.EOF {
|
||||
err = keystream.Error()
|
||||
return
|
||||
if this.keyEncoder.GetType() != reflect.String {
|
||||
this.keyEncoder.Encode(key, keystream)
|
||||
if keystream.Error() != nil && keystream.Error() != io.EOF {
|
||||
err = keystream.Error()
|
||||
return
|
||||
}
|
||||
k = BytesToString(keystream.Buffer())
|
||||
} else {
|
||||
k = *((*string)(key))
|
||||
}
|
||||
this.elemEncoder.Encode(elem, elemstream)
|
||||
if elemstream.Error() != nil && elemstream.Error() != io.EOF {
|
||||
err = elemstream.Error()
|
||||
return
|
||||
if this.elemEncoder.GetType() != reflect.String {
|
||||
this.elemEncoder.Encode(elem, elemstream)
|
||||
if elemstream.Error() != nil && elemstream.Error() != io.EOF {
|
||||
err = elemstream.Error()
|
||||
return
|
||||
}
|
||||
v = BytesToString(elemstream.Buffer())
|
||||
} else {
|
||||
v = *((*string)(elem))
|
||||
}
|
||||
ret[BytesToString(keystream.Buffer())] = BytesToString(elemstream.Buffer())
|
||||
ret[k] = v
|
||||
keystream.Reset(512)
|
||||
elemstream.Reset(512)
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
func newOptions(config map[string]interface{}, opts ...core.Option) core.Options {
|
||||
options := core.Options{
|
||||
IndentionStep: 2,
|
||||
TagKey: "json",
|
||||
}
|
||||
if config != nil {
|
||||
mapstructure.Decode(config, &options)
|
||||
@ -25,6 +26,7 @@ func newOptions(config map[string]interface{}, opts ...core.Option) core.Options
|
||||
func newOptionsByOption(opts ...core.Option) core.Options {
|
||||
options := core.Options{
|
||||
IndentionStep: 2,
|
||||
TagKey: "json",
|
||||
}
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
|
@ -67,26 +67,37 @@ func (this *MCompGate) suitableMethods() {
|
||||
typ := reflect.TypeOf(this.comp)
|
||||
for m := 0; m < typ.NumMethod(); m++ {
|
||||
method := typ.Method(m)
|
||||
mname := method.Name
|
||||
if mname == "Start" ||
|
||||
mname == "Init" ||
|
||||
mname == "Destroy" ||
|
||||
strings.HasSuffix(mname, "Check") {
|
||||
continue
|
||||
}
|
||||
this.reflectionRouteHandle(typ, method)
|
||||
}
|
||||
}
|
||||
|
||||
//反射注册路由处理函数
|
||||
func (this *MCompGate) reflectionRouteHandle(typ reflect.Type, method reflect.Method) {
|
||||
func (this *MCompGate) reflectionRouteHandle(typ reflect.Type, method reflect.Method) (ret bool) {
|
||||
mtype := method.Type
|
||||
mname := method.Name
|
||||
if method.PkgPath != "" {
|
||||
log.Panicf("反射注册用户处理函数错误 [%s-%s] Api接口格式错误", this.module.GetType(), mname)
|
||||
return
|
||||
}
|
||||
if mtype.NumIn() != 3 {
|
||||
log.Panicf("反射注册用户处理函数错误 [%s-%s] Api接口格式错误", this.module.GetType(), mname)
|
||||
return
|
||||
}
|
||||
sessionType := mtype.In(1)
|
||||
if !sessionType.Implements(typeOfSession) {
|
||||
log.Panicf("反射注册用户处理函数错误 [%s-%s] Api接口格式错误", this.module.GetType(), mname)
|
||||
return
|
||||
}
|
||||
agrType := mtype.In(2)
|
||||
if !agrType.Implements(typeOfMessage) {
|
||||
log.Panicf("反射注册用户处理函数错误 [%s-%s] Api接口格式错误", this.module.GetType(), mname)
|
||||
return
|
||||
}
|
||||
// if agrType.Kind() != reflect.Ptr {
|
||||
@ -97,14 +108,17 @@ func (this *MCompGate) reflectionRouteHandle(typ reflect.Type, method reflect.Me
|
||||
// }
|
||||
|
||||
if mtype.NumOut() != 2 {
|
||||
log.Panicf("反射注册用户处理函数错误 [%s-%s] Api接口格式错误", this.module.GetType(), mname)
|
||||
return
|
||||
}
|
||||
returnCodeType := mtype.Out(0)
|
||||
if returnCodeType != typeOfErrorCode {
|
||||
log.Panicf("反射注册用户处理函数错误 [%s-%s] Api接口格式错误", this.module.GetType(), mname)
|
||||
return
|
||||
}
|
||||
returnDataType := mtype.Out(1)
|
||||
if !returnDataType.Implements(typeOfMessage) {
|
||||
log.Panicf("反射注册用户处理函数错误 [%s-%s] Api接口格式错误", this.module.GetType(), mname)
|
||||
return
|
||||
}
|
||||
//寻找校验函数
|
||||
@ -119,6 +133,7 @@ func (this *MCompGate) reflectionRouteHandle(typ reflect.Type, method reflect.Me
|
||||
log.Panicf("反射注册用户处理函数错误 [%s-%s]校验函数格式异常:%v", this.module.GetType(), mname, err)
|
||||
return
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
//反射注册路由校验函数
|
||||
|
@ -15,7 +15,7 @@ func (this *apiComp) DelCheck(session comm.IUserSession, req *pb.FriendDelReq) (
|
||||
}
|
||||
|
||||
//删除好友
|
||||
func (this *apiComp) Del(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendDelReq) (code pb.ErrorCode, data proto.Message) {
|
||||
func (this *apiComp) Del(session comm.IUserSession, req *pb.FriendDelReq) (code pb.ErrorCode, data proto.Message) {
|
||||
if code = this.DelCheck(session, req); code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ func (this *Agent) decodeUserData(msg *pb.UserMessage) error {
|
||||
}
|
||||
|
||||
//只有login的时候才需要设置Data
|
||||
if msg.MainType == "user" && msg.SubType == "login" {
|
||||
if msg.MainType == string(comm.ModuleUser) && msg.SubType == "login" {
|
||||
serverId := jsonRet.Get("serverId").Int()
|
||||
account := jsonRet.Get("account").String()
|
||||
req := &pb.UserLoginReq{
|
||||
@ -160,7 +160,7 @@ func (this *Agent) decodeUserData(msg *pb.UserMessage) error {
|
||||
}
|
||||
msg.Data = ad
|
||||
} else {
|
||||
if this.UserId() == "" {
|
||||
if msg.MainType != string(comm.ModuleNotify) && this.UserId() == "" {
|
||||
return fmt.Errorf("no login")
|
||||
}
|
||||
}
|
||||
|
@ -24,5 +24,6 @@ func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core
|
||||
this.gin, err = gin.NewSys(gin.SetListenPort(this.options.Port))
|
||||
this.gin.POST("/register", this.Register)
|
||||
this.gin.GET("/serverlist", this.ServerList)
|
||||
this.gin.GET("/createnotify", this.CreateNotify)
|
||||
return
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"go_dreamfactory/lego/sys/gin/engine"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/pb"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type CreateNotifyReq struct {
|
||||
@ -16,31 +15,31 @@ type CreateNotifyReq struct {
|
||||
//服务列表
|
||||
func (this *Api_Comp) CreateNotify(c *engine.Context) {
|
||||
req := &CreateNotifyReq{}
|
||||
c.BindJSON(&req)
|
||||
defer log.Debugf("CreateNotify:%+v", req)
|
||||
err := c.BindJSON(&req)
|
||||
log.Debugf("CreateNotify:%+v err:%v", req, err)
|
||||
var (
|
||||
code pb.ErrorCode
|
||||
msg string
|
||||
data interface{}
|
||||
err error
|
||||
// code pb.ErrorCode
|
||||
// msg string
|
||||
// data interface{}
|
||||
// err error
|
||||
)
|
||||
c.JSON(http.StatusOK, &Respond{Code: code, Message: msg, Data: data})
|
||||
// defer c.JSON(http.StatusOK, &Respond{Code: code, Message: msg, Data: data})
|
||||
if sign := gin.ParamSign(this.options.Key, map[string]interface{}{"Title": req.Title, "Ctime": req.Ctime, "Rtime": req.Rtime}); sign != req.Sign {
|
||||
log.Errorf("LoginByCaptchaReq SignError sgin:%s", sign)
|
||||
code = pb.ErrorCode_SignError
|
||||
msg = pb.GetErrorCodeMsg(code)
|
||||
// code = pb.ErrorCode_SignError
|
||||
// msg = pb.GetErrorCodeMsg(code)
|
||||
return
|
||||
}
|
||||
if len(req.Title) == 0 {
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
msg = pb.GetErrorCodeMsg(code)
|
||||
// code = pb.ErrorCode_ReqParameterError
|
||||
// msg = pb.GetErrorCodeMsg(code)
|
||||
return
|
||||
}
|
||||
if err = this.module.modelNotify.CreateSystemNotify(&req.DBSystemNotify); err != nil {
|
||||
log.Errorf("LoginByCaptchaReq CreateSystemNotify err:%v", err)
|
||||
code = pb.ErrorCode_DBError
|
||||
msg = pb.GetErrorCodeMsg(code)
|
||||
// code = pb.ErrorCode_DBError
|
||||
// msg = pb.GetErrorCodeMsg(code)
|
||||
return
|
||||
}
|
||||
msg = pb.GetErrorCodeMsg(code)
|
||||
// msg = pb.GetErrorCodeMsg(code)
|
||||
}
|
||||
|
21
modules/gm/gm_test.http
Normal file
21
modules/gm/gm_test.http
Normal file
@ -0,0 +1,21 @@
|
||||
package gm_test
|
||||
|
||||
###
|
||||
GET http://127.0.0.1:8000/createnotify HTTP/2.0
|
||||
Content-Type:application/json
|
||||
|
||||
{
|
||||
"title": "游戏公告",
|
||||
"content":"hello",
|
||||
"sign": "f5c3fddfe9002563082f61838154c890",
|
||||
}
|
||||
|
||||
### 注册账号测试
|
||||
POST http://127.0.0.1:8000/register HTTP/1.1
|
||||
Content-Type:application/json
|
||||
|
||||
{
|
||||
"register": "liwei2",
|
||||
"content":0,
|
||||
"sign": "f5c3fddfe9002563082f61838154c890",
|
||||
}
|
@ -2,7 +2,6 @@ package hero
|
||||
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/pb"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
"strconv"
|
||||
@ -77,7 +76,7 @@ func (this *apiComp) Awaken(session comm.IUserSession, req *pb.HeroAwakenReq) (c
|
||||
err1 = this.module.modelHero.modifyHeroData(session.GetUserId(), _hero.Id, _heroMap)
|
||||
if err1 != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
log.Errorf("update hero skill failed:%v", err1)
|
||||
this.module.Errorf("update hero skill failed:%v", err1)
|
||||
return
|
||||
}
|
||||
} else { // 加属性
|
||||
@ -91,7 +90,7 @@ func (this *apiComp) Awaken(session comm.IUserSession, req *pb.HeroAwakenReq) (c
|
||||
|
||||
err1 = this.module.modelHero.PushHeroProperty(session, _hero.Id) // 推送属性变化
|
||||
if err1 != nil {
|
||||
log.Errorf("PushHeroProperty err!")
|
||||
this.module.Errorf("PushHeroProperty err!")
|
||||
}
|
||||
session.SendMsg(string(this.module.GetType()), StrengthenUplv, &pb.HeroAwakenResp{Hero: _hero})
|
||||
return
|
||||
|
@ -2,7 +2,6 @@ package hero
|
||||
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/pb"
|
||||
"strconv"
|
||||
|
||||
@ -105,7 +104,7 @@ func (this *apiComp) Resonance(session comm.IUserSession, req *pb.HeroResonanceR
|
||||
}
|
||||
err1 = this.module.modelHero.modifyHeroData(session.GetUserId(), req.HeroObjID, _heroMap) // 修改英雄信息
|
||||
if err1 != nil {
|
||||
log.Errorf("update hero skill failed:%v", err1)
|
||||
this.module.Errorf("update hero skill failed:%v", err1)
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
}
|
||||
@ -124,7 +123,7 @@ func (this *apiComp) Resonance(session comm.IUserSession, req *pb.HeroResonanceR
|
||||
}
|
||||
err1 = this.module.modelHero.PushHeroProperty(session, _hero.Id) // 推送属性变化
|
||||
if err1 != nil {
|
||||
log.Errorf("PushHeroProperty err!")
|
||||
this.module.Errorf("PushHeroProperty err!")
|
||||
}
|
||||
session.SendMsg(string(this.module.GetType()), Resonance, &pb.HeroResonanceResp{Hero: _hero})
|
||||
return
|
||||
|
@ -2,7 +2,6 @@ package hero
|
||||
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/pb"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
@ -76,13 +75,13 @@ func (this *apiComp) ResonanceReset(session comm.IUserSession, req *pb.HeroReson
|
||||
|
||||
err1 = this.module.modelHero.modifyHeroData(session.GetUserId(), req.HeroObjID, _heroMap) // 修改英雄信息
|
||||
if err1 != nil {
|
||||
log.Errorf("update hero skill failed:%v", err1)
|
||||
this.module.Errorf("update hero skill failed:%v", err1)
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
}
|
||||
err1 = this.module.modelHero.PushHeroProperty(session, _hero.Id) // 推送属性变化
|
||||
if err1 != nil {
|
||||
log.Errorf("PushHeroProperty err!")
|
||||
this.module.Errorf("PushHeroProperty err!")
|
||||
}
|
||||
session.SendMsg(string(this.module.GetType()), ResonanceReset, &pb.HeroResonanceResetResp{Hero: _hero, Energy: _hero.ResonateNum})
|
||||
return
|
||||
|
@ -2,7 +2,6 @@ package hero
|
||||
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/pb"
|
||||
"math"
|
||||
|
||||
@ -46,7 +45,7 @@ func (this *apiComp) ResonanceUseEnergy(session comm.IUserSession, req *pb.HeroR
|
||||
err1 := this.module.modelHero.modifyHeroData(session.GetUserId(), req.HeroObjID, _heroMap) // 修改英雄信息
|
||||
if err1 != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
log.Errorf("update hero skill failed:%v", err1)
|
||||
this.module.Errorf("update hero skill failed:%v", err1)
|
||||
return
|
||||
}
|
||||
// 计算属性
|
||||
@ -69,7 +68,7 @@ func (this *apiComp) ResonanceUseEnergy(session comm.IUserSession, req *pb.HeroR
|
||||
|
||||
err1 = this.module.modelHero.PushHeroProperty(session, _hero.Id) // 推送属性变化
|
||||
if err1 != nil {
|
||||
log.Errorf("PushHeroProperty err!")
|
||||
this.module.Errorf("PushHeroProperty err!")
|
||||
}
|
||||
session.SendMsg(string(this.module.GetType()), ResonanceUseEnergy, &pb.HeroResonanceUseEnergyResp{Hero: _hero})
|
||||
return
|
||||
|
@ -3,7 +3,6 @@ package hero
|
||||
import (
|
||||
"crypto/rand"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/pb"
|
||||
"math/big"
|
||||
|
||||
@ -120,7 +119,7 @@ func (this *apiComp) StrengthenUpSkill(session comm.IUserSession, req *pb.HeroSt
|
||||
}
|
||||
err1 = this.module.modelHero.modifyHeroData(session.GetUserId(), req.HeroObjID, _heroMap) // 修改英雄信息
|
||||
if err1 != nil {
|
||||
log.Errorf("update hero skill failed:%v", err1)
|
||||
this.module.Errorf("update hero skill failed:%v", err1)
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
}
|
||||
@ -132,7 +131,7 @@ func (this *apiComp) StrengthenUpSkill(session comm.IUserSession, req *pb.HeroSt
|
||||
}
|
||||
err1 = this.module.modelHero.PushHeroProperty(session, _hero.Id) // 推送属性变化
|
||||
if err1 != nil {
|
||||
log.Errorf("PushHeroProperty err!")
|
||||
this.module.Errorf("PushHeroProperty err!")
|
||||
}
|
||||
|
||||
session.SendMsg(string(this.module.GetType()), StrengthenUpSkill, &pb.HeroStrengthenUpSkillResp{Hero: _hero})
|
||||
|
@ -2,7 +2,6 @@ package hero
|
||||
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/pb"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
|
||||
@ -116,7 +115,7 @@ func (this *apiComp) StrengthenUpStar(session comm.IUserSession, req *pb.HeroStr
|
||||
// 消耗道具
|
||||
code = this.module.ModuleUser.AddAttributeValue(session.GetUserId(), "gold", -target.Gold) // 减少金币
|
||||
if code != pb.ErrorCode_Success {
|
||||
log.Errorf("cost gold failed ,count = %d", target.Gold)
|
||||
this.module.Errorf("cost gold failed ,count = %d", target.Gold)
|
||||
code = pb.ErrorCode_GoldNoEnough
|
||||
return
|
||||
}
|
||||
@ -125,7 +124,7 @@ func (this *apiComp) StrengthenUpStar(session comm.IUserSession, req *pb.HeroStr
|
||||
code = this.module.DelCard(session.GetUserId(), v.CostCardObj, v.Amount)
|
||||
if code != pb.ErrorCode_Success {
|
||||
code = pb.ErrorCode_DBError
|
||||
log.Errorf("del hero err card:%s,count = %d", v.CostCardObj, v.Amount)
|
||||
this.module.Errorf("del hero err card:%s,count = %d", v.CostCardObj, v.Amount)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package hero
|
||||
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/pb"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
|
||||
@ -122,7 +121,7 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStren
|
||||
return
|
||||
}
|
||||
|
||||
log.Debugf("升级后当前等级: %d,经验: %d,需要消耗的金币: %d,增加的经验: %d", curLv, curExp, costRes["gold"], addExp)
|
||||
this.module.Debugf("升级后当前等级: %d,经验: %d,需要消耗的金币: %d,增加的经验: %d", curLv, curExp, costRes["gold"], addExp)
|
||||
// 执行升级逻辑
|
||||
code = this.module.AddCardExp(session.GetUserId(), req.HeroObjID, addExp) // 加经验
|
||||
if code != pb.ErrorCode_Success {
|
||||
@ -140,13 +139,13 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStren
|
||||
err1 := this.module.modelHero.consumeOneHeroCard(session.GetUserId(), req.ExpCardID, req.Amount)
|
||||
if err1 != nil {
|
||||
code = pb.ErrorCode_HeroNoEnough
|
||||
log.Errorf("delete err failed err:%T!", err1)
|
||||
this.module.Errorf("delete err failed err:%T!", err1)
|
||||
return
|
||||
}
|
||||
|
||||
err1 = this.module.modelHero.PushHeroProperty(session, _hero.Id) // 推送属性变化
|
||||
if err1 != nil {
|
||||
log.Errorf("PushHeroProperty err!")
|
||||
this.module.Errorf("PushHeroProperty err!")
|
||||
}
|
||||
|
||||
session.SendMsg(string(this.module.GetType()), StrengthenUplv, &pb.HeroStrengthenUplvResp{Hero: _hero})
|
||||
|
@ -87,7 +87,7 @@ func TestPropertyCompute(t *testing.T) {
|
||||
|
||||
func TestHeroList(t *testing.T) {
|
||||
heroes := module.modelHero.getHeroList("u1")
|
||||
fmt.Printf("%v", heroes,)
|
||||
fmt.Printf("%v", heroes)
|
||||
}
|
||||
|
||||
func TestModify(t *testing.T) {
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/modules"
|
||||
"go_dreamfactory/pb"
|
||||
"math"
|
||||
@ -35,7 +34,7 @@ func (this *ModelHero) Init(service core.IService, module core.IModule, comp cor
|
||||
func (this *ModelHero) initHero(uid string, heroCfgId int32) *pb.DBHero {
|
||||
heroCfg := this.moduleHero.configure.GetHero(heroCfgId)
|
||||
if heroCfg == nil {
|
||||
log.Errorf("%v hero not found from config %v", heroCfgId)
|
||||
this.moduleHero.Errorf("%v hero not found from config %v", heroCfgId)
|
||||
return nil
|
||||
}
|
||||
objId := primitive.NewObjectID().Hex()
|
||||
@ -90,7 +89,7 @@ func (this *ModelHero) createOneHero(uid string, heroCfgId int32) (err error) {
|
||||
hero := this.initHero(uid, heroCfgId)
|
||||
if hero != nil {
|
||||
if err = this.moduleHero.modelHero.AddList(uid, hero.Id, hero); err != nil {
|
||||
log.Errorf("%v", err)
|
||||
this.moduleHero.Errorf("%v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -151,7 +150,7 @@ func (this *ModelHero) getOneHero(uid, heroId string) *pb.DBHero {
|
||||
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)
|
||||
this.moduleHero.Errorf("%v", err)
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -200,7 +199,7 @@ func (this *ModelHero) mergeMainProperty(uid, heroId string, data map[string]int
|
||||
comm.Def: hero.Property[comm.Def],
|
||||
}
|
||||
if err := this.modifyHeroData(uid, heroId, update); err != nil {
|
||||
log.Errorf("mergeMainProperty err %v", err)
|
||||
this.moduleHero.Errorf("mergeMainProperty err %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -219,7 +218,7 @@ func (this *ModelHero) mergeAddProperty(uid, heroId string, data map[string]int3
|
||||
comm.DefPro: hero.AddProperty[comm.DefPro],
|
||||
}
|
||||
if err := this.modifyHeroData(uid, heroId, update); err != nil {
|
||||
log.Errorf("mergeAddProperty err %v", err)
|
||||
this.moduleHero.Errorf("mergeAddProperty err %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -291,7 +290,7 @@ func (this *ModelHero) PushHeroProperty(session comm.IUserSession, heroId string
|
||||
}
|
||||
|
||||
if err = this.ChangeList(session.GetUserId(), heroId, update); err != nil {
|
||||
log.Errorf("PushHeroProperty err:%v", err)
|
||||
this.moduleHero.Errorf("PushHeroProperty err:%v", err)
|
||||
return
|
||||
}
|
||||
return session.SendMsg("push", "property", &pb.HeroProperty{Property: m})
|
||||
@ -307,7 +306,7 @@ func (this *ModelHero) HeroStarUp(session comm.IUserSession, hero *pb.DBHero) (c
|
||||
err1 := this.modifyHeroData(session.GetUserId(), hero.Id, _heroMap)
|
||||
if err1 != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
log.Errorf("update hero skill failed:%v", err1)
|
||||
this.moduleHero.Errorf("update hero skill failed:%v", err1)
|
||||
}
|
||||
// 计算属性
|
||||
data := make(map[string]int32, 0)
|
||||
@ -327,7 +326,7 @@ func (this *ModelHero) HeroStarUp(session comm.IUserSession, hero *pb.DBHero) (c
|
||||
err1 = this.PushHeroProperty(session, hero.Id) // 推送属性变化
|
||||
if err1 != nil {
|
||||
code = pb.ErrorCode_Unknown
|
||||
log.Errorf("PushHeroProperty err!")
|
||||
this.moduleHero.Errorf("PushHeroProperty err!")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package mail
|
||||
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/pb"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
@ -36,7 +35,7 @@ func (this *apiComp) DelMail(session comm.IUserSession, req *pb.MailDelMailReq)
|
||||
}
|
||||
|
||||
if mailinfo, err = this.module.modelMail.Mail_QueryUserMail(session.GetUserId()); err != nil {
|
||||
log.Errorf("QueryUserMailResp err:%v", err)
|
||||
this.module.Errorf("QueryUserMailResp err:%v", err)
|
||||
code = pb.ErrorCode_CacheReadError
|
||||
return
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package mail
|
||||
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/pb"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
@ -25,7 +24,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.MailGetListReq)
|
||||
return
|
||||
}
|
||||
if mailinfo, err = this.module.modelMail.Mail_QueryUserMail(session.GetUserId()); err != nil {
|
||||
log.Errorf("Mail_GetList_Resp err:%v", err)
|
||||
this.module.Errorf("Mail_GetList_Resp err:%v", err)
|
||||
code = pb.ErrorCode_CacheReadError
|
||||
return
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"go_dreamfactory/pb"
|
||||
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
)
|
||||
|
||||
/*
|
||||
@ -53,7 +52,7 @@ func (this *Mail) CreateNewMail(uId string, mail *pb.DBMailData) bool {
|
||||
}
|
||||
err := this.modelMail.Mail_InsertUserMail(mail)
|
||||
if err != nil {
|
||||
log.Error("create mail failed")
|
||||
this.ModuleBase.Errorf("create mail failed")
|
||||
}
|
||||
// 通知玩家
|
||||
var _cache = &pb.CacheUser{}
|
||||
|
@ -12,13 +12,13 @@ API
|
||||
type apiComp struct {
|
||||
modules.MCompGate
|
||||
service core.IService
|
||||
module *Notification
|
||||
module *Notify
|
||||
}
|
||||
|
||||
//组件初始化接口
|
||||
func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||
this.MCompGate.Init(service, module, comp, options)
|
||||
this.module = module.(*Notification)
|
||||
this.module = module.(*Notify)
|
||||
this.service = service
|
||||
return
|
||||
}
|
||||
|
@ -4,17 +4,17 @@ import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
//参数校验
|
||||
func (this *apiComp) GetlistCheck(session comm.IUserSession, req *pb.NotifyGetListReq) (code pb.ErrorCode) {
|
||||
func (this *apiComp) GetListCheck(session comm.IUserSession, req *pb.NotifyGetListReq) (code pb.ErrorCode) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
///获取系统公告
|
||||
func (this *apiComp) Getlist(session comm.IUserSession, req *pb.NotifyGetListReq) (code pb.ErrorCode, data proto.Message) {
|
||||
func (this *apiComp) GetList(session comm.IUserSession, req *pb.NotifyGetListReq) (code pb.ErrorCode, data proto.Message) {
|
||||
var (
|
||||
err error
|
||||
userexpand *pb.DBUserExpand
|
||||
|
@ -16,13 +16,13 @@ import (
|
||||
///论坛 数据组件
|
||||
type modelNotifyComp struct {
|
||||
modules.MCompModel
|
||||
module *Notification
|
||||
module *Notify
|
||||
}
|
||||
|
||||
//组件初始化接口
|
||||
func (this *modelNotifyComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
|
||||
this.MCompModel.Init(service, module, comp, opt)
|
||||
this.module = module.(*Notification)
|
||||
this.module = module.(*Notify)
|
||||
this.TableName = "notify"
|
||||
//创建uid索引
|
||||
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
||||
|
@ -13,29 +13,29 @@ import (
|
||||
开发:李伟
|
||||
*/
|
||||
func NewModule() core.IModule {
|
||||
m := new(Notification)
|
||||
m := new(Notify)
|
||||
return m
|
||||
}
|
||||
|
||||
type Notification struct {
|
||||
type Notify struct {
|
||||
modules.ModuleBase
|
||||
api_comp *apiComp
|
||||
modelNotify *modelNotifyComp
|
||||
}
|
||||
|
||||
//模块名
|
||||
func (this *Notification) GetType() core.M_Modules {
|
||||
return comm.ModuleEquipment
|
||||
func (this *Notify) GetType() core.M_Modules {
|
||||
return comm.ModuleNotify
|
||||
}
|
||||
|
||||
//模块初始化接口 注册用户创建角色事件
|
||||
func (this *Notification) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
||||
func (this *Notify) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
||||
err = this.ModuleBase.Init(service, module, options)
|
||||
return
|
||||
}
|
||||
|
||||
//装备组件
|
||||
func (this *Notification) OnInstallComp() {
|
||||
func (this *Notify) OnInstallComp() {
|
||||
this.ModuleBase.OnInstallComp()
|
||||
this.api_comp = this.RegisterComp(new(apiComp)).(*apiComp)
|
||||
this.modelNotify = this.RegisterComp(new(modelNotifyComp)).(*modelNotifyComp)
|
||||
|
@ -1,4 +1,4 @@
|
||||
package notify
|
||||
package notify_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -7,6 +7,7 @@ import (
|
||||
"go_dreamfactory/lego/base/rpcx"
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/modules/notify"
|
||||
"go_dreamfactory/services"
|
||||
"go_dreamfactory/sys/cache"
|
||||
"go_dreamfactory/sys/configure"
|
||||
@ -49,7 +50,7 @@ func (this *TestService) InitSys() {
|
||||
|
||||
var service core.IService
|
||||
var s_gateComp comm.ISC_GateRouteComp = services.NewGateRouteComp()
|
||||
var module = new(Notification)
|
||||
var module = new(notify.Notify)
|
||||
|
||||
//测试环境下初始化db和cache 系统
|
||||
func TestMain(m *testing.M) {
|
||||
|
@ -2,7 +2,6 @@ package story
|
||||
|
||||
import (
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/modules"
|
||||
"go_dreamfactory/pb"
|
||||
)
|
||||
@ -13,12 +12,12 @@ const ( //Redis
|
||||
|
||||
type ModelStory struct {
|
||||
modules.MCompModel
|
||||
moduleStory *Story
|
||||
module *Story
|
||||
}
|
||||
|
||||
func (this *ModelStory) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||
err = this.MCompModel.Init(service, module, comp, options)
|
||||
this.moduleStory = module.(*Story)
|
||||
this.module = module.(*Story)
|
||||
this.TableName = string(TableStory)
|
||||
return
|
||||
}
|
||||
@ -32,14 +31,14 @@ func (this *ModelStory) getStoryList(uid string) (storys []*pb.DBStory, err erro
|
||||
|
||||
// 修改章节信息
|
||||
func (this *ModelStory) modifyStoryData(uid string, objid string, data map[string]interface{}) error {
|
||||
return this.moduleStory.modelStory.ChangeList(uid, objid, data)
|
||||
return this.module.modelStory.ChangeList(uid, objid, data)
|
||||
}
|
||||
|
||||
// 增加新的章节数据
|
||||
func (this *ModelStory) addNewChapter(uId string, data map[string]interface{}) (err error) {
|
||||
|
||||
if err = this.AddLists(uId, data); err != nil {
|
||||
log.Errorf("err:%v", err)
|
||||
this.module.Errorf("err:%v", err)
|
||||
return
|
||||
}
|
||||
return nil
|
||||
|
@ -4,14 +4,16 @@ import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/pb"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
func (this *apiComp) LogoutCheck(session comm.IUserSession, req *pb.UserLoginReq) (result map[string]interface{}, code comm.ErrorCode) {
|
||||
func (this *apiComp) LogoutCheck(session comm.IUserSession, req *pb.UserLoginReq) (code pb.ErrorCode) {
|
||||
return
|
||||
}
|
||||
|
||||
//注销
|
||||
func (this *apiComp) Logout(session comm.IUserSession, result map[string]interface{}, rsp *pb.UserLoginReq) (code pb.ErrorCode) {
|
||||
func (this *apiComp) Logout(session comm.IUserSession, rsp *pb.UserLoginReq) (code pb.ErrorCode, data proto.Message) {
|
||||
log.Debugf("User - Logout: session:%v rsp:%v", session.ToString(), rsp)
|
||||
|
||||
return
|
||||
|
@ -112,16 +112,16 @@ func (this *SCompGateRoute) RegisterRoute(methodName string, comp reflect.Value,
|
||||
|
||||
//Rpc_GatewayRoute服务接口的接收函数
|
||||
func (this *SCompGateRoute) ReceiveMsg(ctx context.Context, args *pb.AgentMessage, reply *pb.RPCMessageReply) (err error) {
|
||||
method := fmt.Sprintf("%s.%s", args.MainType, args.SubType)
|
||||
defer func() { //程序异常 收集异常信息传递给前端显示
|
||||
if r := recover(); r != nil {
|
||||
buf := make([]byte, 4096)
|
||||
l := runtime.Stack(buf, false)
|
||||
reply.Code = pb.ErrorCode_Exception
|
||||
reply.ErrorMessage = fmt.Sprintf("%v: %s", r, buf[:l])
|
||||
log.Errorf("[Handle Api]:[%s-%s] err:%s", args.MainType, args.SubType, reply.ErrorMessage)
|
||||
log.Errorf("[Handle Api] m:%s reply:%s", method, reply)
|
||||
}
|
||||
}()
|
||||
method := fmt.Sprintf("%s.%s", args.MainType, args.SubType)
|
||||
//获取用户消息处理函数
|
||||
this.mrlock.RLock()
|
||||
msghandle, ok := this.msghandles[method]
|
||||
@ -148,17 +148,17 @@ func (this *SCompGateRoute) ReceiveMsg(ctx context.Context, args *pb.AgentMessag
|
||||
errcode := pb.ErrorCode(handlereturn[0].Int())
|
||||
errdata := handlereturn[1].Interface()
|
||||
if errcode != pb.ErrorCode_Success { //处理返货错误码 返回用户错误信息
|
||||
log.Errorf("[Handle Api] method:%s msg:%v code:%d", method, msg, errcode)
|
||||
reply.Code = errcode
|
||||
reply.ErrorMessage = pb.GetErrorCodeMsg(errcode)
|
||||
if errdata != nil {
|
||||
data, _ := anypb.New(errdata.(proto.Message))
|
||||
reply.ErrorData = data
|
||||
}
|
||||
log.Errorf("[Handle Api] t:%v m:%s req:%v reply:%v", time.Since(stime), method, msg, reply)
|
||||
} else {
|
||||
reply.Reply = session.Polls()
|
||||
if this.options.Debug {
|
||||
log.Debugf("[Handle Api] consumetime:%v method:%s uid:%s msg:%v reply:%#v", time.Since(stime), method, args.UserId, msg, reply)
|
||||
log.Debugf("[Handle Api] t:%v m:%s uid:%s req:%v reply:%v", time.Since(stime), method, args.UserId, msg, reply)
|
||||
}
|
||||
}
|
||||
} else { //未找到消息处理函数
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"go_dreamfactory/modules/hero"
|
||||
"go_dreamfactory/modules/items"
|
||||
"go_dreamfactory/modules/mail"
|
||||
"go_dreamfactory/modules/notify"
|
||||
"go_dreamfactory/modules/shop"
|
||||
"go_dreamfactory/modules/story"
|
||||
"go_dreamfactory/modules/task"
|
||||
@ -50,6 +51,7 @@ func main() {
|
||||
task.NewModule(),
|
||||
story.NewModule(),
|
||||
shop.NewModule(),
|
||||
notify.NewModule(),
|
||||
)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user