From 6c44a4632ec01ebc502cd28856dbb73dfd979332 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Wed, 8 Mar 2023 09:41:29 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E5=8D=8F=E8=AE=AE=E5=8A=A0=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/gateway/agent.go | 42 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/modules/gateway/agent.go b/modules/gateway/agent.go index cfea8d01b..411a0bae5 100644 --- a/modules/gateway/agent.go +++ b/modules/gateway/agent.go @@ -37,6 +37,7 @@ func newAgent(gateway IGateway, conn *websocket.Conn) *Agent { writeChan: make(chan []byte, 2), closeSignal: make(chan bool), state: 1, + protoMsg: map[string]int64{}, } agent.wg.Add(2) go agent.readLoop() @@ -55,6 +56,8 @@ type Agent struct { closeSignal chan bool state int32 //状态 0 关闭 1 运行 2 关闭中 wg sync.WaitGroup + hlock sync.RWMutex + protoMsg map[string]int64 } func (this *Agent) readLoop() { @@ -111,6 +114,14 @@ locp: break locp } } + if this.uId != "" { + key := this.uId + msg.MainType + msg.SubType + this.hlock.Lock() + if v, ok := this.protoMsg[key]; ok && v != 0 { + v = 0 + } + this.hlock.Unlock() + } } } this.gateway.Debugf("agent:%s uId:%s readLoop end!", this.sessionId, this.uId) @@ -129,11 +140,12 @@ locp: break locp case msg, ok := <-this.writeChan: if ok { - // data, err = proto.Marshal(msg) + //data, err = proto.Marshal(msg) if err = this.wsConn.WriteMessage(websocket.BinaryMessage, msg); err != nil { this.gateway.Errorf("agent:%s uId:%d WriteMessage err:%v", this.sessionId, this.uId, err) go this.Close() } + } else { go this.Close() } @@ -340,6 +352,34 @@ func (this *Agent) messageDistribution(msg *pb.UserMessage) (err error) { log.Field{Key: "req", Value: fmt.Sprintf("%s:%s %v", req.MainType, req.SubType, req.Message.String())}, log.Field{Key: "reply", Value: reply.String()}, ) + if this.uId != "" { + key := this.uId + msg.MainType + msg.SubType // 加锁 + if v, ok := this.protoMsg[key]; ok { + if v != 0 && configure.Now().Unix()-v < 2 { + // 返回错误码 + this.hlock.Lock() + this.protoMsg[key] = configure.Now().Unix() + this.hlock.Unlock() + + data, _ := anypb.New(&pb.NotifyErrorNotifyPush{ + ReqMainType: msg.MainType, + ReqSubType: msg.SubType, + Arg: msg.Data, + Code: pb.ErrorCode_InsufficientPermissions}) + err = this.WriteMsg(&pb.UserMessage{ + MainType: comm.MainTypeNotify, + SubType: comm.SubTypeErrorNotify, + Data: data, + }) + return + } + } + this.hlock.Lock() + this.protoMsg[key] = configure.Now().Unix() + this.hlock.Unlock() + + } + if reply.Code != pb.ErrorCode_Success { data, _ := anypb.New(&pb.NotifyErrorNotifyPush{ ReqMainType: msg.MainType, From 27d02a32cc03e89809c38e6038da8c92c9138409 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Wed, 8 Mar 2023 10:52:18 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E9=99=84=E9=AD=94=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E4=B8=8D=E9=9C=80=E8=A6=81=E7=9A=84=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/enchant/api_challenge.go | 1 + modules/enchant/api_getlist.go | 4 ---- modules/enchant/comp_configure.go | 19 ------------------- 3 files changed, 1 insertion(+), 23 deletions(-) diff --git a/modules/enchant/api_challenge.go b/modules/enchant/api_challenge.go index 544019ec5..4fa003d1f 100644 --- a/modules/enchant/api_challenge.go +++ b/modules/enchant/api_challenge.go @@ -44,6 +44,7 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.EnchantChallen code = pb.ErrorCode_ItemsNoEnough return } + _, ok := enchant.Boss[req.BossType] if !ok { // 类型校验 enchant.Boss[req.BossType] = 0 diff --git a/modules/enchant/api_getlist.go b/modules/enchant/api_getlist.go index 2c28f8228..bbc176f38 100644 --- a/modules/enchant/api_getlist.go +++ b/modules/enchant/api_getlist.go @@ -30,10 +30,6 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.EnchantGetListRe list.Boss = make(map[int32]int64) list.BossTime = make(map[int32]int32) - _cfg := this.module.configure.GetEnchantBossTypeConfigData() - for k := range _cfg { - list.BossTime[k] = 0 - } this.module.modelEnchant.Add(session.GetUserId(), list) } if session.GetUserId() != "" { // 恢复时间 diff --git a/modules/enchant/comp_configure.go b/modules/enchant/comp_configure.go index 3a8299874..59132ec37 100644 --- a/modules/enchant/comp_configure.go +++ b/modules/enchant/comp_configure.go @@ -68,25 +68,6 @@ func (this *configureComp) GetConfigure(name string) (v interface{}, err error) return configure.GetConfigure(name) } -// get boss Type -func (this *configureComp) GetEnchantBossTypeConfigData() (mapType map[int32]struct{}) { - - mapType = make(map[int32]struct{}, 0) - if v, err := this.GetConfigure(game_enchantboss); err == nil { - if configure, ok := v.(*cfg.GameEnchantBoss); ok { - this.hlock.Lock() - defer this.hlock.Unlock() - for _, value := range configure.GetDataList() { - if _, ok := mapType[value.Bossid]; !ok { - mapType[value.Bossid] = struct{}{} - } - } - - } - } - return -} - func (this *configureComp) GetBuyChallengeCount(index int32) (data *cfg.GameEnchantShopData) { if v, err := this.GetConfigure(game_enchantshop); err == nil { if configure, ok := v.(*cfg.GameEnchantShop); ok { From e8896712acfe13fc981a1c32b5bb3bd7dc47df47 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Wed, 8 Mar 2023 14:51:46 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/arena/module.go | 2 +- modules/battle/module.go | 6 ++++-- modules/items/modelitems.go | 2 +- modules/practice/modelPandata.go | 2 ++ pb/battle_db.pb.go | 2 +- pb/practice_db.pb.go | 2 +- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/modules/arena/module.go b/modules/arena/module.go index f0feb677d..b046245e2 100644 --- a/modules/arena/module.go +++ b/modules/arena/module.go @@ -157,7 +157,7 @@ func (this *Arena) GetMatcheBattleRoles(uid string) (captain int32, rules []*pb. if ais, err = this.modelArena.matcheAI(info.Dan, 1); err != nil && err != mgo.MongodbNil { return } - if len(players) > 0 { + if len(ais) > 0 { captain = ais[0].Defend.Leadpos if rules, code = this.battle.CreateRolesByHeros(ais[0].Defend.Formt); code != pb.ErrorCode_Success { err = fmt.Errorf("AI CreateRolesByHeros fail:%d", code) diff --git a/modules/battle/module.go b/modules/battle/module.go index 1aa348cb7..3f5568b90 100644 --- a/modules/battle/module.go +++ b/modules/battle/module.go @@ -268,8 +268,10 @@ func (this *Battle) CreateRolesByFormat(fid int32) (captain int32, roles []*pb.B func (this *Battle) CreateRolesByHeros(heros []*pb.DBHero) (roles []*pb.BattleRole, code pb.ErrorCode) { roles = make([]*pb.BattleRole, len(heros)) for i, v := range heros { - if roles[i], code = this.modelBattle.createBattleRole(v, 100+i, i); code != pb.ErrorCode_Success { - return + if v != nil { + if roles[i], code = this.modelBattle.createBattleRole(v, 100+i, i); code != pb.ErrorCode_Success { + return + } } } return diff --git a/modules/items/modelitems.go b/modules/items/modelitems.go index f54cb2c3b..b63b62892 100644 --- a/modules/items/modelitems.go +++ b/modules/items/modelitems.go @@ -541,7 +541,7 @@ func (this *ModelItemsComp) recoverTicket(session comm.IUserSession) (code pb.Er } global := this.module.configure.GetGlobalConf() playerlv := this.module.configure.GetPlayerlvConf(user.Lv) - ticket = int32(this.module.ModuleItems.QueryItemAmount(info.Uid, comm.UnifiedTicket)) + ticket = int32(this.module.ModuleItems.QueryItemAmount(session.GetUserId(), comm.UnifiedTicket)) if ticket < global.DreamlandFightnum && info.Recovertimeunifiedticket > 0 { duration = configure.Now().Sub(time.Unix(info.Recovertimeunifiedticket, 0)) ticketNum = int32(math.Floor(duration.Seconds() / float64(global.CopsRecoveryTime))) diff --git a/modules/practice/modelPandata.go b/modules/practice/modelPandata.go index 5a7ad0300..45192627a 100644 --- a/modules/practice/modelPandata.go +++ b/modules/practice/modelPandata.go @@ -35,6 +35,7 @@ func (this *modelPandata) queryUserMartialhall(uid string) (result *pb.DBPractic result = &pb.DBPracticeRoom{} if err = this.Get(uid, result); err != nil && err != mgo.MongodbNil { this.module.Errorln(err) + return } if err == mgo.MongodbNil { result = &pb.DBPracticeRoom{ @@ -51,6 +52,7 @@ func (this *modelPandata) queryUserMartialhall(uid string) (result *pb.DBPractic Statuers: make([]*pb.DBPracticeStatuer, 0), } if err = this.refreshnpc(result); err != nil { + this.module.Errorln(err) return } if err = this.Add(uid, result); err != nil { diff --git a/pb/battle_db.pb.go b/pb/battle_db.pb.go index 155ade751..7fbee8928 100644 --- a/pb/battle_db.pb.go +++ b/pb/battle_db.pb.go @@ -279,7 +279,7 @@ type BattleRole struct { MainSuitSkill int32 `protobuf:"varint,8,opt,name=mainSuitSkill,proto3" json:"mainSuitSkill" bson:"mainSuitSkill"` /// 主套装技能 SubSuitSkill int32 `protobuf:"varint,9,opt,name=subSuitSkill,proto3" json:"subSuitSkill" bson:"subSuitSkill"` /// 副套装技能 NormalSkill []*SkillData `protobuf:"bytes,10,rep,name=normalSkill,proto3" json:"normalSkill" bson:"normalSkill"` //普通技能 - EquipSkill []*SkillData `protobuf:"bytes,11,rep,name=equipSkill,proto3" json:"equipSkill" bson:"normalSkill"` //普通技能 + EquipSkill []*SkillData `protobuf:"bytes,11,rep,name=equipSkill,proto3" json:"equipSkill" bson:"equipSkill"` //普通技能 PandaBuff int32 `protobuf:"varint,12,opt,name=PandaBuff,proto3" json:"PandaBuff"` //熊猫buff技能id Property map[string]int32 `protobuf:"bytes,13,rep,name=property,proto3" json:"property" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` // 属性相关 Ishelp bool `protobuf:"varint,14,opt,name=ishelp,proto3" json:"ishelp"` //是否是助战英雄 diff --git a/pb/practice_db.pb.go b/pb/practice_db.pb.go index a8f3597b7..5c4e25323 100644 --- a/pb/practice_db.pb.go +++ b/pb/practice_db.pb.go @@ -287,7 +287,7 @@ type DBPracticeRoom struct { Pillarf *DBPracticePillar `protobuf:"bytes,11,opt,name=pillarf,proto3" json:"pillarf"` //好友柱子 Statuers []*DBPracticeStatuer `protobuf:"bytes,12,rep,name=statuers,proto3" json:"statuers"` //武馆雕像 Currnpc int32 `protobuf:"varint,13,opt,name=currnpc,proto3" json:"currnpc"` //当前npc - Npcstate int32 `protobuf:"varint,14,opt,name=npcstate,proto3" json:"npcstate"` //npc状态 0 未挑战 1 挑战失败 2挑战成功 + Npcstate int32 `protobuf:"varint,14,opt,name=npcstate,proto3" json:"npcstate"` //npc状态 0 未挑战 1 挑战失败 2挑战成功 3 CD中 Refresh int64 `protobuf:"varint,15,opt,name=refresh,proto3" json:"refresh"` //刷新时间 Battlenum int32 `protobuf:"varint,16,opt,name=battlenum,proto3" json:"battlenum"` //战斗次数 Captain int32 `protobuf:"varint,17,opt,name=captain,proto3" json:"captain"` //战斗征信队长位 From eb9f2bb1ecb759fb8ac72eb4958a9c1cdd8f989c Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Wed, 8 Mar 2023 14:55:05 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E5=8D=8F=E8=AE=AE=E8=A7=A3=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/gateway/agent.go | 68 +++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/modules/gateway/agent.go b/modules/gateway/agent.go index 411a0bae5..049b5d86e 100644 --- a/modules/gateway/agent.go +++ b/modules/gateway/agent.go @@ -37,7 +37,7 @@ func newAgent(gateway IGateway, conn *websocket.Conn) *Agent { writeChan: make(chan []byte, 2), closeSignal: make(chan bool), state: 1, - protoMsg: map[string]int64{}, + protoMsg: make(map[string]int64, 0), } agent.wg.Add(2) go agent.readLoop() @@ -97,11 +97,39 @@ locp: code, err = this.secAuth(msg) if err == nil { this.gateway.Debugf("----------2 agent:%s uId:%s MainType:%s SubType:%s ", this.sessionId, this.uId, msg.MainType, msg.SubType) + if err := this.messageDistribution(msg); err != nil { this.gateway.Errorf("messageDistribution err:%v", err) go this.Close() break locp } + if this.uId != "" { + key := this.uId + msg.MainType + msg.SubType // 加锁 + if v, ok := this.protoMsg[key]; ok { + if v != 0 && configure.Now().Unix()-v < 2 { + // 返回错误码 + this.hlock.Lock() + this.protoMsg[key] = configure.Now().Unix() + this.hlock.Unlock() + + data, _ := anypb.New(&pb.NotifyErrorNotifyPush{ + ReqMainType: msg.MainType, + ReqSubType: msg.SubType, + Arg: msg.Data, + Code: pb.ErrorCode_InsufficientPermissions}) + err = this.WriteMsg(&pb.UserMessage{ + MainType: comm.MainTypeNotify, + SubType: comm.SubTypeErrorNotify, + Data: data, + }) + return + } + } + this.hlock.Lock() + this.protoMsg[key] = configure.Now().Unix() + this.hlock.Unlock() + + } } else { this.gateway.Errorf("agent:%s uId:%s 密钥无效 err:%v", this.sessionId, this.uId, err) data, _ := anypb.New(&pb.NotifyErrorNotifyPush{ReqMainType: msg.MainType, ReqSubType: msg.SubType, Code: code, Message: err.Error()}) @@ -114,14 +142,7 @@ locp: break locp } } - if this.uId != "" { - key := this.uId + msg.MainType + msg.SubType - this.hlock.Lock() - if v, ok := this.protoMsg[key]; ok && v != 0 { - v = 0 - } - this.hlock.Unlock() - } + } } this.gateway.Debugf("agent:%s uId:%s readLoop end!", this.sessionId, this.uId) @@ -352,34 +373,15 @@ func (this *Agent) messageDistribution(msg *pb.UserMessage) (err error) { log.Field{Key: "req", Value: fmt.Sprintf("%s:%s %v", req.MainType, req.SubType, req.Message.String())}, log.Field{Key: "reply", Value: reply.String()}, ) + if this.uId != "" { - key := this.uId + msg.MainType + msg.SubType // 加锁 - if v, ok := this.protoMsg[key]; ok { - if v != 0 && configure.Now().Unix()-v < 2 { - // 返回错误码 - this.hlock.Lock() - this.protoMsg[key] = configure.Now().Unix() - this.hlock.Unlock() - - data, _ := anypb.New(&pb.NotifyErrorNotifyPush{ - ReqMainType: msg.MainType, - ReqSubType: msg.SubType, - Arg: msg.Data, - Code: pb.ErrorCode_InsufficientPermissions}) - err = this.WriteMsg(&pb.UserMessage{ - MainType: comm.MainTypeNotify, - SubType: comm.SubTypeErrorNotify, - Data: data, - }) - return - } - } + key := this.uId + msg.MainType + msg.SubType this.hlock.Lock() - this.protoMsg[key] = configure.Now().Unix() + if v, ok := this.protoMsg[key]; ok && v != 0 { // 发送消息 协议解锁 + v = 0 + } this.hlock.Unlock() - } - if reply.Code != pb.ErrorCode_Success { data, _ := anypb.New(&pb.NotifyErrorNotifyPush{ ReqMainType: msg.MainType, From 7b79fd7d78625e7ee525e7d2bb176ffc2c776876 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Wed, 8 Mar 2023 15:10:56 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E6=89=A9=E5=B1=95=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/user/api_create.go | 16 ---------------- modules/user/model_expand.go | 20 +++++++++++++++++++- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/modules/user/api_create.go b/modules/user/api_create.go index 43292a705..444ec8dd1 100644 --- a/modules/user/api_create.go +++ b/modules/user/api_create.go @@ -81,22 +81,6 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (c return } - //初始化用户扩展 - initUpdate := map[string]interface{}{ - "modifynameCount": 1, //修改名称1次 - "sociatyTicket": globalConf.GuildBossInitialNum, //公会BOSS挑战券 - "expitem": make(map[string]int32, 0), // 初始化 - "mline": make(map[string]int32, 0), - } - if err := this.module.modelExpand.ChangeUserExpand(session.GetUserId(), initUpdate); err != nil { - code = pb.ErrorCode_DBError - this.module.Error("创建初始修改名称次数", - log.Field{Key: "uid", Value: uid}, - log.Field{Key: "params", Value: initUpdate}, - log.Field{Key: "err", Value: err.Error()}, - ) - return - } var ( res []*cfg.Gameatn ) diff --git a/modules/user/model_expand.go b/modules/user/model_expand.go index a2af40519..edcdcafac 100644 --- a/modules/user/model_expand.go +++ b/modules/user/model_expand.go @@ -43,7 +43,25 @@ func (this *ModelExpand) GetUserExpand(uid string) (result *pb.DBUserExpand, err } } } else { - if err = this.Get(uid, result); err != nil && mongo.ErrNoDocuments != err { + if err = this.Get(uid, result); err != nil && mongo.ErrNoDocuments == err { + globalConf := this.module.configure.GetGlobalConf() + initUpdate := map[string]interface{}{ + "uid": uid, + "modifynameCount": 1, //修改名称1次 + "sociatyTicket": globalConf.GuildBossInitialNum, //公会BOSS挑战券 + "expitem": make(map[string]int32, 0), // 初始化 + "mline": make(map[string]int32, 0), + } + result.SociatyTicket = globalConf.GuildBossInitialNum + if err = this.module.modelExpand.ChangeUserExpand(uid, initUpdate); err != nil { + + this.module.Error("创建初始修改名称次数", + log.Field{Key: "uid", Value: uid}, + log.Field{Key: "params", Value: initUpdate}, + log.Field{Key: "err", Value: err.Error()}, + ) + return + } this.module.Error("Get", log.Field{Key: "uid", Value: uid}) return result, err } From 6fe3d364b87dc792d1829a00ae1906135f22f320 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Wed, 8 Mar 2023 16:08:23 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E5=A5=BD=E5=8F=8B=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E5=BC=80=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/json/game_opencond.json | 6 +++--- modules/gateway/agent.go | 15 +++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/bin/json/game_opencond.json b/bin/json/game_opencond.json index f8415a0a6..84b104f5e 100644 --- a/bin/json/game_opencond.json +++ b/bin/json/game_opencond.json @@ -74,11 +74,11 @@ "main": [ { "key": 1, - "param": 1 + "param": 30 } ], "optional": "", - "wkqbx": 0, + "wkqbx": 2, "kqbx": 0, "img": "zc_icon_01", "prompt": { @@ -844,7 +844,7 @@ "main": [ { "key": 1, - "param": 1 + "param": 100 } ], "optional": "", diff --git a/modules/gateway/agent.go b/modules/gateway/agent.go index 600707451..ef6f7f6e0 100644 --- a/modules/gateway/agent.go +++ b/modules/gateway/agent.go @@ -97,12 +97,6 @@ locp: code, err = this.secAuth(msg) if err == nil { this.gateway.Debugf("----------2 agent:%s uId:%s MainType:%s SubType:%s ", this.sessionId, this.uId, msg.MainType, msg.SubType) - - if err := this.messageDistribution(msg); err != nil { - this.gateway.Errorf("messageDistribution err:%v", err) - go this.Close() - break locp - } if this.uId != "" { key := this.uId + msg.MainType + msg.SubType // 加锁 if v, ok := this.protoMsg[key]; ok { @@ -111,7 +105,6 @@ locp: this.hlock.Lock() this.protoMsg[key] = configure.Now().Unix() this.hlock.Unlock() - data, _ := anypb.New(&pb.NotifyErrorNotifyPush{ ReqMainType: msg.MainType, ReqSubType: msg.SubType, @@ -122,7 +115,7 @@ locp: SubType: comm.SubTypeErrorNotify, Data: data, }) - return + continue } } this.hlock.Lock() @@ -130,6 +123,12 @@ locp: this.hlock.Unlock() } + if err := this.messageDistribution(msg); err != nil { + this.gateway.Errorf("messageDistribution err:%v", err) + go this.Close() + break locp + } + } else { this.gateway.Errorf("agent:%s uId:%s 密钥无效 err:%v", this.sessionId, this.uId, err) data, _ := anypb.New(&pb.NotifyErrorNotifyPush{ReqMainType: msg.MainType, ReqSubType: msg.SubType, Code: code, Message: err.Error()})