This commit is contained in:
wh_zcy 2023-01-30 11:53:00 +08:00
commit a58102ab4c
5 changed files with 51 additions and 7 deletions

View File

@ -591,6 +591,7 @@ const (
const (
MaxRankList = 50 // 赛季塔 排行榜人数
MaxMailCount = 50 // 当前邮件最大数量
)
const (

View File

@ -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,11 +178,16 @@ func (this *Agent) decodeUserData(msg *pb.UserMessage) (code pb.ErrorCode, err e
}
msg.Data = ad
} else {
if msg.MainType != string(comm.ModuleNotify) && this.UserId() == "" {
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
}

View File

@ -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 {

View File

@ -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
}

View File

@ -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