From f901ae60b915e0a4954567fa80b3c3a9fcf627c9 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Thu, 24 Nov 2022 16:01:53 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=B4=AD=E4=B9=B0=E6=8E=A8=E9=80=81=20?= =?UTF-8?q?=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/robot/options.go | 4 ++-- comm/imodule.go | 4 ++-- modules/modulebase.go | 4 ++-- modules/privilege/api_buyyueka.go | 2 +- modules/privilege/module.go | 25 ++++--------------------- 5 files changed, 11 insertions(+), 28 deletions(-) diff --git a/cmd/robot/options.go b/cmd/robot/options.go index c9abbd542..b42161034 100644 --- a/cmd/robot/options.go +++ b/cmd/robot/options.go @@ -12,8 +12,8 @@ type Options struct { func DefaultOpts() *Options { return &Options{ - WsUrl: "ws://localhost:7891/gateway", - RegUrl: "http://localhost:8000/register", + WsUrl: "ws://10.0.5.73:7891/gateway", + RegUrl: "http://10.0.5.73:8000/register", Create: false, ServerId: "1", } diff --git a/comm/imodule.go b/comm/imodule.go index 4ba88f88b..fcc615092 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -169,7 +169,7 @@ type ( // 远程任务条件校验 RemoteCheckCondi(uid string, condiId int32, rsp *pb.DBRtaskRecord) error // 删除任务条件数据 - RemoveCondi(uid string ,condiId int32) error + RemoveCondi(uid string, condiId int32) error //任务触发 SendToRtask(session IUserSession, rtaskType TaskType, params ...int32) (code pb.ErrorCode) // 初始化条件数据 @@ -270,7 +270,7 @@ type ( } IPrivilege interface { // 创建一个新的特权卡 - CreatePrivilegeCard(session IUserSession, cId string) (res []*pb.UserAssets, code pb.ErrorCode) + CreatePrivilegeCard(session IUserSession, cId string) (code pb.ErrorCode) // 续费特权卡 RenewPrivilegeCard(session IUserSession, cId string) (res []*pb.UserAssets, code pb.ErrorCode) // 检查特权 diff --git a/modules/modulebase.go b/modules/modulebase.go index e3b4bb115..2af64780c 100644 --- a/modules/modulebase.go +++ b/modules/modulebase.go @@ -302,7 +302,7 @@ func (this *ModuleBase) ConsumeRes(session comm.IUserSession, res []*cfg.Gameatn return } this.Debugf("消耗玩家资源: %v", attrs) - if count,ok:= attrs[comm.ResDiamond];ok{ + if count, ok := attrs[comm.ResDiamond]; ok { this.ModuleRtask.SendToRtask(session, comm.Rtype104, count) } } @@ -369,7 +369,7 @@ func (this *ModuleBase) DispenseRes(session comm.IUserSession, res []*cfg.Gameat } if len(vip) > 0 { //卡片资源 for k := range vip { - _, code = this.ModulePrivilege.CreatePrivilegeCard(session, k) + code = this.ModulePrivilege.CreatePrivilegeCard(session, k) this.Debugf("发放月卡资源: %v [%v]", k, code) } diff --git a/modules/privilege/api_buyyueka.go b/modules/privilege/api_buyyueka.go index a6df9f237..cf9eed6ea 100644 --- a/modules/privilege/api_buyyueka.go +++ b/modules/privilege/api_buyyueka.go @@ -21,6 +21,6 @@ func (this *apiComp) BuyYueka(session comm.IUserSession, req *pb.PrivilegeBuyYue if code = this.BuyYuekaCheck(session, req); code != pb.ErrorCode_Success { return } - _, code = this.module.CreatePrivilegeCard(session, req.CID) + code = this.module.CreatePrivilegeCard(session, req.CID) return } diff --git a/modules/privilege/module.go b/modules/privilege/module.go index 2dd275097..eb3aa4768 100644 --- a/modules/privilege/module.go +++ b/modules/privilege/module.go @@ -64,21 +64,14 @@ func (this *Privilege) EventUserOffline(session comm.IUserSession) { } // 购买了一个新的特权 -func (this *Privilege) CreatePrivilegeCard(session comm.IUserSession, cId string) (res []*pb.UserAssets, code pb.ErrorCode) { +func (this *Privilege) CreatePrivilegeCard(session comm.IUserSession, cId string) (code pb.ErrorCode) { var ( - data *pb.DBPrivilege bFind bool ) - atn := &pb.UserAssets{ - A: "vip", - T: "", - N: 1, - } conf, err := this.configure.GetPrivilegeCard(cId) if err != nil { - code = pb.ErrorCode_ConfigNoFound - return nil, code + return pb.ErrorCode_ConfigNoFound } // 是不是购买过 list, err := this.modelPrivilege.getPrivilegeList(session.GetUserId()) @@ -105,14 +98,13 @@ func (this *Privilege) CreatePrivilegeCard(session comm.IUserSession, cId string this.Errorf("err:%v", err) return } - data = v bFind = true break } } if !bFind { - data = &pb.DBPrivilege{ + data := &pb.DBPrivilege{ Id: primitive.NewObjectID().Hex(), Uid: session.GetUserId(), CId: cId, @@ -125,6 +117,7 @@ func (this *Privilege) CreatePrivilegeCard(session comm.IUserSession, cId string for _, v := range conf.PrivilegeId { data.PrivilegeID = append(data.PrivilegeID, v) } + list = append(list, data) this.modelPrivilege.addNewPrivilegeData(session.GetUserId(), data) this.SendDailyMail(session, cId, 1, conf.PType) } @@ -132,16 +125,6 @@ func (this *Privilege) CreatePrivilegeCard(session comm.IUserSession, cId string if code = this.DispenseRes(session, conf.DisposableReward, true); code != pb.ErrorCode_Success { return } - atn.T = conf.Id - res = append(res, atn) // 加资源 - for _, v := range conf.DisposableReward { - res = append(res, &pb.UserAssets{ - A: v.A, - T: v.T, - N: v.N, - }) - } - // 推送 session.SendMsg(string(this.GetType()), PrivilegeBuyYuekaResp, &pb.PrivilegeGetListResp{Data: list}) return From defde13dda8c3989476fda448488d11224812963 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Thu, 24 Nov 2022 16:16:42 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E7=89=B9=E6=9D=83=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/json/game_worldbattle.json | 42 ++-- bin/json/game_worldtask.json | 400 +++++++++------------------------ comm/imodule.go | 2 +- modules/privilege/module.go | 23 +- 4 files changed, 133 insertions(+), 334 deletions(-) diff --git a/bin/json/game_worldbattle.json b/bin/json/game_worldbattle.json index d7fb8d0f8..626966804 100644 --- a/bin/json/game_worldbattle.json +++ b/bin/json/game_worldbattle.json @@ -9,7 +9,8 @@ "LockSlots": [], "AssistTeam": 0, "EventList": [], - "playexp": 1000 + "playexp": 1000, + "NoMidwayExit": 0 }, { "id": 102, @@ -21,7 +22,8 @@ "LockSlots": [], "AssistTeam": 0, "EventList": [], - "playexp": 1000 + "playexp": 1000, + "NoMidwayExit": 0 }, { "id": 103, @@ -33,7 +35,8 @@ "LockSlots": [], "AssistTeam": 0, "EventList": [], - "playexp": 1000 + "playexp": 1000, + "NoMidwayExit": 0 }, { "id": 104, @@ -45,7 +48,8 @@ "LockSlots": [], "AssistTeam": 0, "EventList": [], - "playexp": 1000 + "playexp": 1000, + "NoMidwayExit": 0 }, { "id": 105, @@ -57,7 +61,8 @@ "LockSlots": [], "AssistTeam": 0, "EventList": [], - "playexp": 1000 + "playexp": 1000, + "NoMidwayExit": 0 }, { "id": 106, @@ -69,7 +74,8 @@ "LockSlots": [], "AssistTeam": 0, "EventList": [], - "playexp": 1000 + "playexp": 1000, + "NoMidwayExit": 0 }, { "id": 107, @@ -81,7 +87,8 @@ "LockSlots": [], "AssistTeam": 0, "EventList": [], - "playexp": 1000 + "playexp": 1000, + "NoMidwayExit": 0 }, { "id": 108, @@ -93,7 +100,8 @@ "LockSlots": [], "AssistTeam": 0, "EventList": [], - "playexp": 1000 + "playexp": 1000, + "NoMidwayExit": 0 }, { "id": 109, @@ -105,7 +113,8 @@ "LockSlots": [], "AssistTeam": 0, "EventList": [], - "playexp": 1000 + "playexp": 1000, + "NoMidwayExit": 0 }, { "id": 110, @@ -117,7 +126,8 @@ "LockSlots": [], "AssistTeam": 0, "EventList": [], - "playexp": 1000 + "playexp": 1000, + "NoMidwayExit": 0 }, { "id": 111, @@ -129,7 +139,8 @@ "LockSlots": [], "AssistTeam": 0, "EventList": [], - "playexp": 1000 + "playexp": 1000, + "NoMidwayExit": 0 }, { "id": 112, @@ -141,7 +152,8 @@ "LockSlots": [], "AssistTeam": 0, "EventList": [], - "playexp": 1000 + "playexp": 1000, + "NoMidwayExit": 0 }, { "id": 113, @@ -153,7 +165,8 @@ "LockSlots": [], "AssistTeam": 0, "EventList": [], - "playexp": 1000 + "playexp": 1000, + "NoMidwayExit": 0 }, { "id": 114, @@ -165,6 +178,7 @@ "LockSlots": [], "AssistTeam": 0, "EventList": [], - "playexp": 1000 + "playexp": 1000, + "NoMidwayExit": 0 } ] \ No newline at end of file diff --git a/bin/json/game_worldtask.json b/bin/json/game_worldtask.json index 4f31ca4e3..f3913f79a 100644 --- a/bin/json/game_worldtask.json +++ b/bin/json/game_worldtask.json @@ -18,7 +18,7 @@ 2, 100001 ], - "completetask": 183, + "completetask": 0, "auto_accept": 0, "overtips": 1, "reword": [ @@ -32,9 +32,7 @@ "t": "25001", "n": 1 } - ], - "day": "", - "weather": 0 + ] }, { "key": 10101, @@ -58,9 +56,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10102, @@ -84,9 +80,7 @@ "completetask": 171, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10103, @@ -110,9 +104,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10104, @@ -147,9 +139,7 @@ "t": "30001", "n": 1 } - ], - "day": "", - "weather": 0 + ] }, { "key": 10105, @@ -173,9 +163,7 @@ "completetask": 118, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10106, @@ -199,9 +187,7 @@ "completetask": 174, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10107, @@ -225,9 +211,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10108, @@ -251,9 +235,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10109, @@ -277,9 +259,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10110, @@ -300,12 +280,10 @@ 2, 100011 ], - "completetask": 0, + "completetask": 183, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10111, @@ -329,9 +307,7 @@ "completetask": 175, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10112, @@ -355,9 +331,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10113, @@ -381,9 +355,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10114, @@ -407,9 +379,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10115, @@ -433,9 +403,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10116, @@ -459,9 +427,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10117, @@ -485,9 +451,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10118, @@ -511,9 +475,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10119, @@ -537,9 +499,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10120, @@ -563,9 +523,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10121, @@ -589,9 +547,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10122, @@ -615,9 +571,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10123, @@ -641,9 +595,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10124, @@ -667,9 +619,7 @@ "completetask": 176, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10125, @@ -693,9 +643,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10126, @@ -719,9 +667,7 @@ "completetask": 177, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10127, @@ -745,9 +691,7 @@ "completetask": 178, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10128, @@ -771,9 +715,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10129, @@ -797,9 +739,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10130, @@ -823,9 +763,7 @@ "completetask": 158, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10131, @@ -849,9 +787,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10132, @@ -875,9 +811,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10133, @@ -901,9 +835,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10134, @@ -927,9 +859,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10135, @@ -953,9 +883,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10136, @@ -979,9 +907,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10137, @@ -1005,9 +931,7 @@ "completetask": 179, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10138, @@ -1031,9 +955,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10139, @@ -1057,9 +979,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10140, @@ -1083,9 +1003,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10141, @@ -1109,9 +1027,7 @@ "completetask": 180, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10142, @@ -1135,9 +1051,7 @@ "completetask": 181, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10143, @@ -1161,9 +1075,7 @@ "completetask": 182, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10144, @@ -1187,9 +1099,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10145, @@ -1213,9 +1123,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10146, @@ -1239,9 +1147,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10147, @@ -1265,9 +1171,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10148, @@ -1291,9 +1195,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10149, @@ -1317,9 +1219,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10150, @@ -1343,9 +1243,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10151, @@ -1369,9 +1267,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10152, @@ -1395,9 +1291,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10153, @@ -1421,9 +1315,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10154, @@ -1447,9 +1339,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10155, @@ -1473,9 +1363,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10156, @@ -1499,9 +1387,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10157, @@ -1525,9 +1411,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10158, @@ -1551,9 +1435,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10159, @@ -1577,9 +1459,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10160, @@ -1603,9 +1483,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10161, @@ -1629,9 +1507,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10162, @@ -1655,9 +1531,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10163, @@ -1681,9 +1555,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10164, @@ -1707,9 +1579,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 10165, @@ -1733,9 +1603,7 @@ "completetask": 0, "auto_accept": 1, "overtips": 1, - "reword": [], - "day": "", - "weather": 0 + "reword": [] }, { "key": 20001, @@ -1770,9 +1638,7 @@ "t": "25001", "n": 1 } - ], - "day": "night", - "weather": 2 + ] }, { "key": 20002, @@ -1802,9 +1668,7 @@ "t": "diamond", "n": 100 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20003, @@ -1834,9 +1698,7 @@ "t": "diamond", "n": 100 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20004, @@ -1866,9 +1728,7 @@ "t": "diamond", "n": 100 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20005, @@ -1903,9 +1763,7 @@ "t": "30001", "n": 10 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20006, @@ -1935,9 +1793,7 @@ "t": "diamond", "n": 100 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20007, @@ -1967,9 +1823,7 @@ "t": "diamond", "n": 100 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20008, @@ -1999,9 +1853,7 @@ "t": "diamond", "n": 100 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20009, @@ -2031,9 +1883,7 @@ "t": "diamond", "n": 100 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20010, @@ -2063,9 +1913,7 @@ "t": "diamond", "n": 100 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20011, @@ -2100,9 +1948,7 @@ "t": "25001", "n": 1 } - ], - "day": "night", - "weather": 2 + ] }, { "key": 20012, @@ -2132,9 +1978,7 @@ "t": "diamond", "n": 100 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20013, @@ -2164,9 +2008,7 @@ "t": "diamond", "n": 100 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20014, @@ -2196,9 +2038,7 @@ "t": "diamond", "n": 100 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20015, @@ -2233,9 +2073,7 @@ "t": "30001", "n": 10 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20016, @@ -2265,9 +2103,7 @@ "t": "diamond", "n": 100 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20017, @@ -2297,9 +2133,7 @@ "t": "diamond", "n": 100 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20018, @@ -2329,9 +2163,7 @@ "t": "diamond", "n": 100 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20019, @@ -2361,9 +2193,7 @@ "t": "diamond", "n": 100 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20020, @@ -2393,9 +2223,7 @@ "t": "diamond", "n": 100 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20100, @@ -2425,9 +2253,7 @@ "t": "diamond", "n": 100 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20101, @@ -2457,9 +2283,7 @@ "t": "diamond", "n": 100 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20102, @@ -2489,9 +2313,7 @@ "t": "diamond", "n": 100 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20103, @@ -2521,9 +2343,7 @@ "t": "diamond", "n": 100 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20104, @@ -2553,9 +2373,7 @@ "t": "diamond", "n": 100 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20105, @@ -2585,9 +2403,7 @@ "t": "diamond", "n": 100 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20106, @@ -2617,9 +2433,7 @@ "t": "diamond", "n": 100 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20107, @@ -2649,9 +2463,7 @@ "t": "diamond", "n": 100 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20108, @@ -2681,9 +2493,7 @@ "t": "diamond", "n": 100 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20109, @@ -2713,9 +2523,7 @@ "t": "diamond", "n": 100 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20110, @@ -2745,9 +2553,7 @@ "t": "diamond", "n": 100 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20111, @@ -2777,9 +2583,7 @@ "t": "diamond", "n": 100 } - ], - "day": "", - "weather": 0 + ] }, { "key": 20112, @@ -2809,8 +2613,6 @@ "t": "diamond", "n": 100 } - ], - "day": "", - "weather": 0 + ] } ] \ No newline at end of file diff --git a/comm/imodule.go b/comm/imodule.go index fcc615092..6f7fc69d3 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -272,7 +272,7 @@ type ( // 创建一个新的特权卡 CreatePrivilegeCard(session IUserSession, cId string) (code pb.ErrorCode) // 续费特权卡 - RenewPrivilegeCard(session IUserSession, cId string) (res []*pb.UserAssets, code pb.ErrorCode) + RenewPrivilegeCard(session IUserSession, cId string) (code pb.ErrorCode) // 检查特权 CheckPrivilege(session IUserSession, cId string) (privilege *pb.DBPrivilege) // 查询玩家当前所有特权 返回特权id diff --git a/modules/privilege/module.go b/modules/privilege/module.go index eb3aa4768..97b53f7c8 100644 --- a/modules/privilege/module.go +++ b/modules/privilege/module.go @@ -131,13 +131,7 @@ func (this *Privilege) CreatePrivilegeCard(session comm.IUserSession, cId string } // 续费特权 -func (this *Privilege) RenewPrivilegeCard(session comm.IUserSession, cId string) (res []*pb.UserAssets, code pb.ErrorCode) { - - atn := &pb.UserAssets{ - A: "vip", - T: "", - N: 1, // 暂时只支持一次续费一次 - } +func (this *Privilege) RenewPrivilegeCard(session comm.IUserSession, cId string) (code pb.ErrorCode) { list, err := this.modelPrivilege.getPrivilegeList(session.GetUserId()) if err != nil { return @@ -146,8 +140,8 @@ func (this *Privilege) RenewPrivilegeCard(session comm.IUserSession, cId string) if v.CId == cId { conf, err := this.configure.GetPrivilegeCard(cId) if err != nil { - code = pb.ErrorCode_ConfigNoFound - return nil, code + return pb.ErrorCode_ConfigNoFound + } if conf.RenewDay >= int32(configure.Now().Unix()-v.ETime)/(24*3600) { v.ETime += int64(conf.AssertDay) * 24 * 3600 @@ -158,18 +152,7 @@ func (this *Privilege) RenewPrivilegeCard(session comm.IUserSession, cId string) if code = this.DispenseRes(session, conf.DisposableReward, true); code != pb.ErrorCode_Success { break } - session.SendMsg(string(this.GetType()), PrivilegeBuyYuekaResp, &pb.PrivilegeGetListResp{Data: list}) - atn.T = conf.Id - res = append(res, atn) // 加资源 - for _, v := range conf.DisposableReward { - res = append(res, &pb.UserAssets{ - A: v.A, - T: v.T, - N: v.N, - }) - } - } else { code = pb.ErrorCode_PrivilegeRenewTime } From 679e79abdd5200dd4a15e4f4b122328dc29fc1c6 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Thu, 24 Nov 2022 16:30:14 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=88=98=E6=96=97rpc?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E7=9F=BF=E8=AE=BE=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/battle/call.go | 22 ++++++++++++-- modules/battle/client.go | 65 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 78 insertions(+), 9 deletions(-) diff --git a/modules/battle/call.go b/modules/battle/call.go index 5f310a06f..fb8d99eae 100644 --- a/modules/battle/call.go +++ b/modules/battle/call.go @@ -1,12 +1,28 @@ package battle +import ( + "go_dreamfactory/lego/sys/log" + + "google.golang.org/protobuf/proto" +) + //异步返回结构 type MessageCall struct { Method string Metadata map[string]string ResMetadata map[string]string - Args interface{} //请求参数 - Reply interface{} //返回参数 - Error error //错误信息 + Args proto.Message //请求参数 + Reply proto.Message //返回参数 + Error error //错误信息 Done chan *MessageCall } + +func (call *MessageCall) done(log log.Ilogf) { + select { + case call.Done <- call: + // ok + default: + log.Debugf("rpc: discarding Call reply due to insufficient Done chan capacity") + + } +} diff --git a/modules/battle/client.go b/modules/battle/client.go index e58bdbd01..d9905a80d 100644 --- a/modules/battle/client.go +++ b/modules/battle/client.go @@ -1,13 +1,16 @@ package battle import ( + "context" "go_dreamfactory/modules" "go_dreamfactory/pb" + "sync" "go_dreamfactory/lego/core" "github.com/gorilla/websocket" "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/types/known/anypb" ) /* @@ -15,10 +18,13 @@ import ( */ type clientComp struct { modules.MCompGate - options *Options - service core.IService - module *Battle - conn *websocket.Conn + options *Options + service core.IService + module *Battle + conn *websocket.Conn + seq uint64 + pendingmutex sync.Mutex + pending map[uint64]*MessageCall //高并发回调 } //组件初始化接口 @@ -26,6 +32,7 @@ func (this *clientComp) Init(service core.IService, module core.IModule, comp co this.MCompGate.Init(service, module, comp, options) this.options = options.(*Options) this.module = module.(*Battle) + this.pending = make(map[uint64]*MessageCall) return } @@ -37,8 +44,43 @@ func (this *clientComp) Start() (err error) { } //校验战斗过程 -func (this *clientComp) CheckBattle() { - +func (this *clientComp) callBattle(ctx context.Context, method string, req proto.Message, reply proto.Message) (err error) { + call := new(MessageCall) + call.Done = make(chan *MessageCall, 10) + call.Args = req + call.Reply = reply + this.pendingmutex.Lock() + seq := this.seq + this.seq++ + this.pending[seq] = call + this.pendingmutex.Unlock() + msg := &pb.BattleRpcMessage{ + Rid: seq, + Method: method, + } + msg.Data, _ = anypb.New(req) + data, _ := proto.Marshal(msg) + if err = this.conn.WriteMessage(websocket.BinaryMessage, data); err != nil { + this.pendingmutex.Lock() + delete(this.pending, seq) + this.pendingmutex.Unlock() + return + } + select { + case <-ctx.Done(): // cancel by context + this.pendingmutex.Lock() + call := this.pending[seq] + delete(this.pending, seq) + this.pendingmutex.Unlock() + if call != nil { + call.Error = ctx.Err() + call.done(this.options.Log) + } + return ctx.Err() + case call := <-call.Done: + err = call.Error + } + return } func (this *clientComp) run() { @@ -57,5 +99,16 @@ locp: this.module.Errorf("client Unmarshal err:%v", err) break locp } + go this.handleresponse(msg) } } + +func (this *clientComp) handleresponse(resp *pb.BattleRpcMessage) { + var call *MessageCall + this.pendingmutex.Lock() + call = this.pending[resp.Rid] + delete(this.pending, resp.Rid) + this.pendingmutex.Unlock() + call.Error = resp.Data.UnmarshalTo(call.Reply) + call.done(this.options.Log) +}