game_sync/worldsrv/playeronline.go

73 lines
1.5 KiB
Go

package main
import (
"time"
"mongo.games.com/goserver/core/module"
"mongo.games.com/game/common"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
)
var PlayerOnlineSington = &PlayerOnlineEvent{
OnlineCh: make(map[string]map[string]int),
}
type PlayerOnlineEvent struct {
OnlineCh map[string]map[string]int
Check bool
}
func (p *PlayerOnlineEvent) ModuleName() string {
return "PlayerOnlineEvent"
}
func (p *PlayerOnlineEvent) Init() {
}
// 每五秒钟统计一次在线数据
// 没有登录,登出,掉线情况不统计
func (p *PlayerOnlineEvent) Update() {
if !p.Check {
return
}
p.Check = false
onlineCh := map[string]map[string]int{}
for _, player := range PlayerMgrSington.sidMap {
if player != nil && !player.IsRob && player.IsOnLine() && player.Platform != common.Platform_Rob && player.Channel != common.Channel_Rob {
info, ok := onlineCh[player.Platform]
if !ok {
onlineCh[player.Platform] = map[string]int{}
info = onlineCh[player.Platform]
}
info[player.Channel] += 1
}
}
if len(onlineCh) == len(p.OnlineCh) {
for k, v := range onlineCh {
if len(v) != len(p.OnlineCh[k]) {
goto here
}
for k1, v1 := range v {
if v1 != p.OnlineCh[k][k1] {
goto here
}
}
}
return
}
here:
p.OnlineCh = onlineCh
mq.Write(model.GenerateOnline(p.OnlineCh))
}
func (p *PlayerOnlineEvent) Shutdown() {
module.UnregisteModule(p)
}
func init() {
module.RegisteModule(PlayerOnlineSington, 5*time.Second, 0)
}