diff --git a/cmd/v2/service/connService.go b/cmd/v2/service/connService.go index 61aa5fb00..c10826543 100644 --- a/cmd/v2/service/connService.go +++ b/cmd/v2/service/connService.go @@ -104,9 +104,9 @@ func (c *ConnServiceImpl) ListenerPush() { DataTime: time.Now().Format(time.RFC3339), Msg: msg, } - logrus.WithFields( - logrus.Fields{"MainType": msg.MainType, "SubType": msg.SubType}, - ).Debug(methodName) + // logrus.WithFields( + // logrus.Fields{"MainType": msg.MainType, "SubType": msg.SubType}, + // ).Debug(methodName) renderRespPanel := func(p *model.PushModel) { c.obs.Notify(observer.EVENT_REQ_RSP, p.Msg) diff --git a/cmd/v2/service/pttService.go b/cmd/v2/service/pttService.go index d03dd5b8a..18c192385 100644 --- a/cmd/v2/service/pttService.go +++ b/cmd/v2/service/pttService.go @@ -22,6 +22,8 @@ type PttService interface { GetUser() *UserInfo SetUser(dbUser *pb.DBUser, dbUserExpand *pb.DBUserExpand) SendToClient(mainType, subType string, rsp proto.Message) error + + Ping(sid, account string) } type PttServiceImpl struct { @@ -85,6 +87,15 @@ func (p *PttServiceImpl) Login(sid, account string) (code pb.ErrorCode) { return } +func (p *PttServiceImpl) Ping(sid, account string) { + head := &pb.UserMessage{MainType: string(comm.ModuleGate), SubType: "heartbeat"} + head.Sec = common.BuildSecStr(sid, account) + if err := p.connService.SendMsg(head, &pb.GatewayHeartbeatReq{}); err != nil { + return + } + return +} + // create role func (p *PttServiceImpl) CreateRole(nickName string, gender, figure int32) (code pb.ErrorCode) { head := &pb.UserMessage{MainType: string(comm.ModuleUser), SubType: user.UserSubTypeCreate} diff --git a/cmd/v2/ui/mainwindow.go b/cmd/v2/ui/mainwindow.go index 7cc1d1c54..26a6a6652 100644 --- a/cmd/v2/ui/mainwindow.go +++ b/cmd/v2/ui/mainwindow.go @@ -10,6 +10,7 @@ import ( "go_dreamfactory/modules/user" "go_dreamfactory/pb" "strings" + "time" "fyne.io/fyne/v2" "fyne.io/fyne/v2/container" @@ -312,6 +313,14 @@ func (ui *MainWindowImpl) createLoginWin(sid, sname string) { return } + go func() { + timer := time.NewTimer(10 * time.Second) + for { + timer.Reset(10 * time.Second) + <-timer.C + ui.pttService.Ping(sid, account.Text) + } + }() // reset main window title subTitle := fmt.Sprintf("%s[%s]", sname, sid) ui.w.SetTitle(fmt.Sprintf(common.APP_WIN_TITLE, subTitle, ui.app.Metadata().Version, ui.app.Metadata().Build, common.APP_NAME)) diff --git a/comm/const.go b/comm/const.go index bc24d46b0..5ba030703 100644 --- a/comm/const.go +++ b/comm/const.go @@ -163,7 +163,7 @@ const ( TableCrossSession = "crosssession" - TableServerData = "serverdata" // 跨服服务器相关数据 + TableSeasonData = "seasondata" // 跨服服务器相关数据 ///竞技场 TableArena = "arena" @@ -590,7 +590,8 @@ const ( ) const ( - MaxRankList = 50 // 赛季塔 排行榜人数 + MaxRankList = 50 // 赛季塔 排行榜人数 + MaxMailCount = 50 // 当前邮件最大数量 ) const ( diff --git a/modules/gateway/agent.go b/modules/gateway/agent.go index a3dbcd4db..b0de4c975 100644 --- a/modules/gateway/agent.go +++ b/modules/gateway/agent.go @@ -71,7 +71,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() @@ -89,9 +89,11 @@ locp: SubType: "heartbeat", Data: data, }) + //this.wsConn.SetReadDeadline(time.Now().Add(time.Second * 30)) continue } if err := this.messageDistribution(msg); err != nil { + this.gateway.Errorf("messageDistribution err:%v", err) go this.Close() break locp } diff --git a/modules/hero/api_fusion.go b/modules/hero/api_fusion.go index 665c8bce2..f7f3bac29 100644 --- a/modules/hero/api_fusion.go +++ b/modules/hero/api_fusion.go @@ -48,7 +48,7 @@ func (this *apiComp) Fusion(session comm.IUserSession, req *pb.HeroFusionReq) (c if c != pb.ErrorCode_Success || _obj.SameCount < v { code = pb.ErrorCode_HeroNoExist } - mapHero[_obj.HeroID] = v + mapHero[_obj.HeroID] += v _costMaphero[k] = _obj } for _, v := range conf.Pointhero { 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/pagoda/api_activate.go b/modules/pagoda/api_activate.go index 8ea7d0eb6..b5782cb3e 100644 --- a/modules/pagoda/api_activate.go +++ b/modules/pagoda/api_activate.go @@ -41,7 +41,7 @@ func (this *apiComp) Activate(session comm.IUserSession, req *pb.PagodaActivateR season.Uid = session.GetUserId() season.PagodaId = 0 // 初始数据0层 if conn, err := db.Cross(); err == nil { - rst := conn.Mgo.FindOne(comm.TableServerData, bson.M{}) + rst := conn.Mgo.FindOne(comm.TableSeasonData, bson.M{}) server := &pb.DBServerData{} rst.Decode(server) season.Type = server.SeasonType diff --git a/modules/pagoda/module.go b/modules/pagoda/module.go index 90d123717..d62c6914a 100644 --- a/modules/pagoda/module.go +++ b/modules/pagoda/module.go @@ -242,7 +242,7 @@ func (this *Pagoda) ModifySeasonPagodaFloor(session comm.IUserSession, level int list.Uid = session.GetUserId() list.PagodaId = level if conn, err := db.Cross(); err == nil { - rst := conn.Mgo.FindOne(comm.TableServerData, bson.M{}) + rst := conn.Mgo.FindOne(comm.TableSeasonData, bson.M{}) server := &pb.DBServerData{} rst.Decode(server) list.Type = server.SeasonType diff --git a/modules/rtask/module.go b/modules/rtask/module.go index fa141a490..0ea8e434b 100644 --- a/modules/rtask/module.go +++ b/modules/rtask/module.go @@ -279,13 +279,14 @@ func (this *ModuleRtask) SendToRtask(session comm.IUserSession, rtaskType comm.T for _, v := range condis { conf, err := this.configure.getRtaskTypeById(v.condId) if err != nil { - this.Errorln(err) + log.Errorf("get condId conf err:%v", err) code = pb.ErrorCode_RtaskCondiNoFound return } if v.update != nil { if err := v.update(uid, conf, params...); err != nil { + log.Errorf("update task:%v", err) code = pb.ErrorCode_DBError } } 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 diff --git a/modules/timer/season.go b/modules/timer/season.go index 33e3238cb..8d38a1664 100644 --- a/modules/timer/season.go +++ b/modules/timer/season.go @@ -71,9 +71,9 @@ func (this *SeasonPagoda) Start() (err error) { conn, err := db.Cross() if err == nil { //this.DbTest() - model := db.NewDBModel(comm.TableServerData, 0, conn) + model := db.NewDBModel(comm.TableSeasonData, 0, conn) - _len, err1 := model.DB.CountDocuments(comm.TableServerData, bson.M{}) + _len, err1 := model.DB.CountDocuments(comm.TableSeasonData, bson.M{}) if err1 == nil && _len == 0 { fmt.Printf("%v,%v", _len, err1) server := &pb.DBServerData{ @@ -89,7 +89,7 @@ func (this *SeasonPagoda) Start() (err error) { server.SeasonType = conf.DisposableLoop[0] } - model.DB.InsertOne(comm.TableServerData, server) + model.DB.InsertOne(comm.TableSeasonData, server) } } return @@ -129,7 +129,7 @@ func (this *SeasonPagoda) TimerSeasonOver() { this.module.Debugf("TimerSeasonOver:%d", configure.Now().Unix()) if db.IsCross() { if conn, err := db.Cross(); err == nil { - if rst := conn.Mgo.FindOne(comm.TableServerData, bson.M{}); rst != nil { + if rst := conn.Mgo.FindOne(comm.TableSeasonData, bson.M{}); rst != nil { serverData := &pb.DBServerData{} rst.Decode(serverData) conf := this.GetSeasonLoop(comm.SeasonType) // 获取赛季塔重置配置 @@ -151,7 +151,7 @@ func (this *SeasonPagoda) TimerSeasonOver() { } serverData.SeasonType = conf.FixedLoop[int(serverData.FixedLoop)-1] } - this.DB.UpdateOne(comm.TableServerData, bson.M{}, serverData) + this.DB.UpdateOne(comm.TableSeasonData, bson.M{}, serverData) fmt.Printf("%v", serverData) } } @@ -174,7 +174,7 @@ func (this *SeasonPagoda) TimerSeasonStar() { if !db.IsCross() { // 删除本服的赛季塔数据 conn, err := db.Cross() // 获取跨服的链接对象 if err == nil { - model := db.NewDBModel(comm.TableServerData, 0, conn) + model := db.NewDBModel(comm.TableSeasonData, 0, conn) model.DB.DeleteMany(comm.TableSeasonPagoda, bson.M{}, options.Delete()) model.DB.DeleteMany(comm.TableSeasonRecord, bson.M{}, options.Delete()) for pos := 0; pos < comm.MaxRankNum; pos++ {