From 5b7455160555670aefde14253411ba6f2c85b18b Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Sun, 29 Jan 2023 18:11:50 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=B8=8A=E4=BC=A0wocket=20=E6=B8=85?= =?UTF-8?q?=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/gateway/agent.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/gateway/agent.go b/modules/gateway/agent.go index 3b9b6100e..6ebd23dd7 100644 --- a/modules/gateway/agent.go +++ b/modules/gateway/agent.go @@ -70,6 +70,7 @@ locp: go this.Close() break locp } + this.wsConn.SetReadDeadline(time.Now().Add(time.Second * 30)) if err = proto.Unmarshal(data, msg); err != nil { this.gateway.Errorf("agent:%s uId:%s Unmarshal err:%v", this.sessionId, this.uId, err) go this.Close() @@ -177,9 +178,14 @@ func (this *Agent) decodeUserData(msg *pb.UserMessage) (code pb.ErrorCode, err e } msg.Data = ad } else { - if msg.MainType != string(comm.ModuleNotify) && this.UserId() == "" { - this.gateway.Errorf("[%v.%v] Agent UId empty", msg.MainType, msg.SubType) - return pb.ErrorCode_AgentUidEmpty, fmt.Errorf("no login") + switch msg.MainType { + case string(comm.ModuleNotify), string(comm.ModuleGate): + return pb.ErrorCode_Success, nil + default: + if this.UserId() == "" { + this.gateway.Errorf("[%v.%v] Agent UId empty", msg.MainType, msg.SubType) + return pb.ErrorCode_AgentUidEmpty, fmt.Errorf("no login") + } } } return pb.ErrorCode_Success, nil From da2b2d4ced6e9acb9b4bbaa48c372ee54264102a Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Sun, 29 Jan 2023 18:37:40 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E4=B8=8A=E9=99=90?= =?UTF-8?q?=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/const.go | 3 ++- modules/mail/model_mail.go | 32 ++++++++++++++++++++++++-- modules/mail/module.go | 9 ++++++++ modules/sociaty/api_cross_recommend.go | 2 +- 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/comm/const.go b/comm/const.go index bc24d46b0..9488ad007 100644 --- a/comm/const.go +++ b/comm/const.go @@ -590,7 +590,8 @@ const ( ) const ( - MaxRankList = 50 // 赛季塔 排行榜人数 + MaxRankList = 50 // 赛季塔 排行榜人数 + MaxMailCount = 50 // 当前邮件最大数量 ) const ( diff --git a/modules/mail/model_mail.go b/modules/mail/model_mail.go index 6a057f216..5a655e2f4 100644 --- a/modules/mail/model_mail.go +++ b/modules/mail/model_mail.go @@ -31,11 +31,16 @@ func (this *modelMail) Init(service core.IService, module core.IModule, comp cor } func (this *modelMail) MailQueryUserMail(uId string) (mail []*pb.DBMailData, err error) { - - if _data, err := this.DB.Find(comm.TableMail, bson.M{"uid": uId}, options.Find().SetSort(bson.M{"createtime": -1})); err == nil { + var index int32 + if _data, err := this.DB.Find(comm.TableMail, bson.M{"uid": uId}); err == nil { for _data.Next(context.TODO()) { + index++ temp := &pb.DBMailData{} if err = _data.Decode(temp); err == nil { + if index > comm.MaxMailCount { // 删除超标的邮件 + this.DB.DeleteOne(comm.TableMail, bson.M{"_id": temp.ObjId}, options.Delete()) + continue + } mail = append(mail, temp) } } @@ -90,6 +95,29 @@ func (this *modelMail) MailGetMailAttachmentState(objId string) (*pb.DBMailData, return nd, err } +func (this *modelMail) GetMailCountByUid(uid string) (int32, error) { + var count int64 + count, err := this.DB.CountDocuments(comm.TableMail, bson.M{"uid": uid}) + + return int32(count), err +} + +// 删除超过最大邮件数量的邮件 +func (this *modelMail) DelOtherMail(uid string) { + if _data, err := this.DB.Find(comm.TableMail, bson.M{"uid": uid}); err == nil { + var index int32 + for _data.Next(context.TODO()) { + index++ + temp := &pb.DBMailData{} + if err = _data.Decode(temp); err == nil { + if index >= comm.MaxMailCount { // 删除超标的邮件 + this.DB.DeleteOne(comm.TableMail, bson.M{"_id": temp.ObjId}, options.Delete()) + continue + } + } + } + } +} // 更新领取附件状态 func (this *modelMail) MailUpdateMailAttachmentState(objId string) bool { diff --git a/modules/mail/module.go b/modules/mail/module.go index 341e59978..dd8d8a9d0 100644 --- a/modules/mail/module.go +++ b/modules/mail/module.go @@ -187,3 +187,12 @@ func (this *Mail) SendMailByCid(session comm.IUserSession, cid string, res []*pb return true } + +// 创建邮件之前检测邮件是否达到上限 +func (this *Mail) CheckMaxMail(session comm.IUserSession) bool { + count, err := this.modelMail.GetMailCountByUid(session.GetUserId()) + if err == nil && count >= comm.MaxMailCount { + this.modelMail.DelOtherMail(session.GetUserId()) + } + return true +} diff --git a/modules/sociaty/api_cross_recommend.go b/modules/sociaty/api_cross_recommend.go index 2dc382594..92b5785ed 100644 --- a/modules/sociaty/api_cross_recommend.go +++ b/modules/sociaty/api_cross_recommend.go @@ -9,7 +9,7 @@ import ( // 公会BOSS 推荐 func (this *apiComp) RecommendCheck(session comm.IUserSession, req *pb.SociatyRecommendReq) (code pb.ErrorCode) { - if req.Cate != 1 || req.Cate != 2 { + if req.Cate != 1 && req.Cate != 2 { code = pb.ErrorCode_ReqParameterError } return