获取在线玩家数据
This commit is contained in:
parent
a26f05416f
commit
0f247ee161
@ -160,5 +160,11 @@
|
|||||||
"open": true,
|
"open": true,
|
||||||
"routrules": "~/worker",
|
"routrules": "~/worker",
|
||||||
"describe": "好友助战英雄列表"
|
"describe": "好友助战英雄列表"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"msgid": "gourmet.getranduser",
|
||||||
|
"open": true,
|
||||||
|
"routrules": "~/worker",
|
||||||
|
"describe": "获取在线玩家数据"
|
||||||
}
|
}
|
||||||
]
|
]
|
@ -5,7 +5,9 @@ import (
|
|||||||
"go_dreamfactory/comm"
|
"go_dreamfactory/comm"
|
||||||
"go_dreamfactory/lego/core"
|
"go_dreamfactory/lego/core"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
|
"go_dreamfactory/sys/db"
|
||||||
"go_dreamfactory/utils"
|
"go_dreamfactory/utils"
|
||||||
|
"time"
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
@ -32,8 +34,9 @@ func (this *apiComp) GetRandUser(session comm.IUserSession, req *pb.GourmetGetRa
|
|||||||
if code != pb.ErrorCode_Success {
|
if code != pb.ErrorCode_Success {
|
||||||
return // 参数校验失败直接返回
|
return // 参数校验失败直接返回
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取在线玩家信息
|
// 获取在线玩家信息
|
||||||
onlineList, err := this.module.ModuleUser.CrossUserOnlineList()
|
onlineList, err := this.module.ModuleUser.UserOnlineList()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
code = pb.ErrorCode_DBError
|
code = pb.ErrorCode_DBError
|
||||||
return
|
return
|
||||||
@ -61,7 +64,11 @@ func (this *apiComp) GetRandUser(session comm.IUserSession, req *pb.GourmetGetRa
|
|||||||
}
|
}
|
||||||
left := int(req.People) - len(mapUser)
|
left := int(req.People) - len(mapUser)
|
||||||
if left > 0 { // 一个人也没有 那就从db 中随机取
|
if left > 0 { // 一个人也没有 那就从db 中随机取
|
||||||
if _data, err1 := this.module.modelGourmet.DB.Find(core.SqlTable(comm.TableUser), bson.M{}, options.Find().SetSort(bson.M{"lv": -1}).SetLimit(int64(req.People))); err1 == nil {
|
tag, _, b := utils.UIdSplit(session.GetUserId())
|
||||||
|
if b {
|
||||||
|
if conn, err := db.ServerDBConn(tag); err == nil {
|
||||||
|
dbModel := db.NewDBModel(comm.TableHero, 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()) {
|
for _data.Next(context.TODO()) {
|
||||||
temp := &pb.DBUser{}
|
temp := &pb.DBUser{}
|
||||||
if err = _data.Decode(temp); err == nil {
|
if err = _data.Decode(temp); err == nil {
|
||||||
@ -76,6 +83,8 @@ func (this *apiComp) GetRandUser(session comm.IUserSession, req *pb.GourmetGetRa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
for k := range mapUser {
|
for k := range mapUser {
|
||||||
if user, err := this.module.ModuleUser.GetRmoteUser(k); err == nil && user.Uid != "" {
|
if user, err := this.module.ModuleUser.GetRmoteUser(k); err == nil && user.Uid != "" {
|
||||||
szDbUser = append(szDbUser, user) // 转成user对象
|
szDbUser = append(szDbUser, user) // 转成user对象
|
||||||
|
@ -111,7 +111,9 @@ func (this *User) GetUserSession(uid string) *pb.CacheUser {
|
|||||||
|
|
||||||
// 清除session
|
// 清除session
|
||||||
func (this *User) CleanSession(session comm.IUserSession) {
|
func (this *User) CleanSession(session comm.IUserSession) {
|
||||||
|
if !this.IsCross() {
|
||||||
this.modelUser.updateOfflineTime(session.GetUserId())
|
this.modelUser.updateOfflineTime(session.GetUserId())
|
||||||
|
}
|
||||||
sId := fmt.Sprintf("%s-%s", comm.RDS_SESSION, session.GetUserId())
|
sId := fmt.Sprintf("%s-%s", comm.RDS_SESSION, session.GetUserId())
|
||||||
this.modelSession.Del(sId, db.SetDBMgoLog(false))
|
this.modelSession.Del(sId, db.SetDBMgoLog(false))
|
||||||
this.modelSession.DelListlds(comm.RDS_SESSION, session.GetUserId())
|
this.modelSession.DelListlds(comm.RDS_SESSION, session.GetUserId())
|
||||||
|
Loading…
Reference in New Issue
Block a user