一个在线也没有 那么 就去随机取指定数量的玩家
This commit is contained in:
parent
6ef841ed72
commit
fe17144107
@ -1,10 +1,16 @@
|
||||
package gourmet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/db"
|
||||
"go_dreamfactory/utils"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
@ -28,7 +34,7 @@ func (this *apiComp) GetRandUser(session comm.IUserSession, req *pb.GourmetGetRa
|
||||
return // 参数校验失败直接返回
|
||||
}
|
||||
// 获取在线玩家信息
|
||||
onlineList, err := this.module.ModuleUser.UserOnlineList()
|
||||
onlineList, err := this.module.ModuleUser.CrossUserOnlineList()
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
@ -54,6 +60,21 @@ func (this *apiComp) GetRandUser(session comm.IUserSession, req *pb.GourmetGetRa
|
||||
for _, v := range szUid {
|
||||
randOnlineUsers = append(randOnlineUsers, v)
|
||||
}
|
||||
if len(randOnlineUsers) == 0 { // 一个人也没有 那就从db 中随机取
|
||||
tag := session.GetServiecTag()
|
||||
if conn, err := db.ServerDBConn(tag); err == nil {
|
||||
dbModel := db.NewDBModel(comm.TableUser, time.Hour, conn)
|
||||
if _data, err1 := dbModel.DB.Find(core.SqlTable(comm.TableUser), bson.M{}, options.Find().SetSort(bson.M{"lv": -1}).SetLimit(int64(req.People))); err1 == nil {
|
||||
for _data.Next(context.TODO()) {
|
||||
temp := &pb.DBUser{}
|
||||
if err = _data.Decode(temp); err == nil {
|
||||
randOnlineUsers = append(randOnlineUsers, temp.Uid)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, v := range randOnlineUsers {
|
||||
szDbUser = append(szDbUser, this.module.ModuleUser.GetUser(v)) // 转成user对象
|
||||
|
@ -44,7 +44,7 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp
|
||||
}
|
||||
|
||||
func (this *configureComp) SetLibraryFavor() {
|
||||
if v, err := this.GetConfigure(game_favornum); err == nil {
|
||||
if v, err := this.GetConfigure(game_libraryfavor); err == nil {
|
||||
if _configure, ok := v.(*cfg.GameLibraryFavor); ok {
|
||||
for _, v1 := range _configure.GetDataList() {
|
||||
this.favor[int64(v1.Star<<8)+int64(v1.Favorlv)] = v1
|
||||
|
Loading…
Reference in New Issue
Block a user