印度包网
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.
 
 
 

51 lines
1.0 KiB

package game
import (
"server/call"
"server/common"
"server/util"
"time"
)
// GetOnline 获取在线人数的func
func GetOnline() []*common.ESNewOnline {
data := map[int]int{}
AllPlayers.Range(func(k, v interface{}) bool {
p := v.(*Player)
if !p.IsLeave {
data[p.PlayerDBInfo.ChannelID]++
}
return true
})
ret := []*common.ESNewOnline{}
for i, v := range data {
one := &common.ESNewOnline{Channel: i, Total: v, GameID: ThisGameID}
ret = append(ret, one)
}
return ret
}
func GetRealOnline() map[int]*common.RedisRealOnline {
rooms := map[int]*common.RedisRealOnline{}
for _, v := range call.GetConfigGameRoom(ThisGameID) {
rooms[v.RoomID] = new(common.RedisRealOnline)
}
zero := util.GetZeroTime(time.Now()).Unix()
AllPlayers.Range(func(k, v interface{}) bool {
p := v.(*Player)
if !p.IsLeave {
id := p.T.Room.RoomId()
ro, ok := rooms[id]
if !ok {
ro = new(common.RedisRealOnline)
}
ro.Total++
if p.Birth >= zero {
ro.New++
}
rooms[id] = ro
}
return true
})
return rooms
}