You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.7 KiB
70 lines
1.7 KiB
|
1 year ago
|
package hall
|
||
|
|
|
||
|
|
import (
|
||
|
|
"server/call"
|
||
|
|
"server/common"
|
||
|
|
"server/util"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/liangdas/mqant/log"
|
||
|
|
)
|
||
|
|
|
||
|
|
// GetOnline 获取在线人数的func
|
||
|
|
func GetOnline() []*common.ESNewOnline {
|
||
|
|
total := map[int]int{}
|
||
|
|
recharge := map[int]int{}
|
||
|
|
newPlayer := map[int]int{}
|
||
|
|
oldPlayer := map[int]int{}
|
||
|
|
all := []int{}
|
||
|
|
now := time.Now().Unix()
|
||
|
|
offlines := []*player{} // 判断为已掉线玩家
|
||
|
|
playerIdMap.Range(func(k, v interface{}) bool {
|
||
|
|
p := v.(*player)
|
||
|
|
total[p.db.ChannelID]++
|
||
|
|
if p.isRecharge {
|
||
|
|
recharge[p.db.ChannelID]++
|
||
|
|
}
|
||
|
|
if !util.IsSameDayTimeStamp(time.Now().Unix(), p.db.Birth) {
|
||
|
|
newPlayer[p.db.ChannelID]++
|
||
|
|
} else {
|
||
|
|
oldPlayer[p.db.ChannelID]++
|
||
|
|
}
|
||
|
|
// 上次登录在一天前,判定为掉线玩家
|
||
|
|
if now-p.lastLogin > 24*60*60 {
|
||
|
|
offlines = append(offlines, p)
|
||
|
|
}
|
||
|
|
all = append(all, p.db.Id)
|
||
|
|
return true
|
||
|
|
})
|
||
|
|
log.Debug("onlines:%v", all)
|
||
|
|
ret := []*common.ESNewOnline{}
|
||
|
|
for i, v := range total {
|
||
|
|
one := &common.ESNewOnline{Channel: i, Total: v, Recharge: recharge[i], New: newPlayer[i], Old: oldPlayer[i]}
|
||
|
|
ret = append(ret, one)
|
||
|
|
}
|
||
|
|
util.Go(func() {
|
||
|
|
for _, v := range offlines {
|
||
|
|
log.Debug("player %v offline", v.db.Id)
|
||
|
|
delPlayerBySession(v.session.GetSessionID())
|
||
|
|
delPlayerByID(v.db.Id)
|
||
|
|
call.UpdateUserXInfo(&common.PlayerDBInfo{Id: v.db.Id}, map[string]interface{}{"online": 2})
|
||
|
|
}
|
||
|
|
})
|
||
|
|
return ret
|
||
|
|
}
|
||
|
|
|
||
|
|
func GetRealOnline() map[int]*common.RedisRealOnline {
|
||
|
|
rooms := map[int]*common.RedisRealOnline{}
|
||
|
|
rooms[0] = new(common.RedisRealOnline)
|
||
|
|
zero := util.GetZeroTime(time.Now()).Unix()
|
||
|
|
playerIdMap.Range(func(k, v interface{}) bool {
|
||
|
|
p := v.(*player)
|
||
|
|
rooms[0].Total++
|
||
|
|
if p.db.Birth >= zero {
|
||
|
|
rooms[0].New++
|
||
|
|
}
|
||
|
|
return true
|
||
|
|
})
|
||
|
|
return rooms
|
||
|
|
}
|