From aa3a713699a786fd1f35186d62bd642da2df9b12 Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Thu, 25 Apr 2024 09:46:57 +0800 Subject: [PATCH] =?UTF-8?q?evt=5Fonline=E6=B7=BB=E5=8A=A0=E6=B8=A0?= =?UTF-8?q?=E9=81=93=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/rabbit_mq.go | 11 +++++++---- worldsrv/playeronline.go | 32 +++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/model/rabbit_mq.go b/model/rabbit_mq.go index 0a8ad2c..d42ca2a 100644 --- a/model/rabbit_mq.go +++ b/model/rabbit_mq.go @@ -8,11 +8,14 @@ import ( ) // GenerateOnline 在线统计 -func GenerateOnline(online map[string]int) *RabbitMQData { - m := map[int]int{} // 平台:真人数 +func GenerateOnline(online map[string]map[string]int) *RabbitMQData { + m := map[string]map[int]int{} // 渠道:平台:真人数 for k, v := range online { - i, _ := strconv.Atoi(k) - m[i] = v + m[k] = map[int]int{} + for k1, v1 := range v { + pf, _ := strconv.Atoi(k1) + m[k][pf] = v1 + } } params := make(map[string]interface{}) params["Online"] = m diff --git a/worldsrv/playeronline.go b/worldsrv/playeronline.go index 61e1ad3..6db8d03 100644 --- a/worldsrv/playeronline.go +++ b/worldsrv/playeronline.go @@ -7,12 +7,12 @@ import ( ) var PlayerOnlineSington = &PlayerOnlineEvent{ - Online: make(map[string]int), + OnlineCh: make(map[string]map[string]int), } type PlayerOnlineEvent struct { - Online map[string]int - Check bool + OnlineCh map[string]map[string]int + Check bool } func (p *PlayerOnlineEvent) ModuleName() string { @@ -23,30 +23,40 @@ func (p *PlayerOnlineEvent) Init() { } // 每五秒钟统计一次在线数据 -// 没有登录,登出,掉线情况直接不统计 +// 没有登录,登出,掉线情况不统计 func (p *PlayerOnlineEvent) Update() { if !p.Check { return } p.Check = false - m := map[string]int{} + onlineCh := map[string]map[string]int{} for _, player := range PlayerMgrSington.sidMap { if player != nil && !player.IsRob && player.IsOnLine() { - m[player.Platform] = m[player.Platform] + 1 + info, ok := onlineCh[player.Channel] + if !ok { + onlineCh[player.Channel] = map[string]int{} + info = onlineCh[player.Channel] + } + info[player.Platform] += 1 } } - if len(m) == len(p.Online) { - for k, v := range m { - if p.Online[k] != v { + 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.Online = m - LogChannelSingleton.WriteMQData(model.GenerateOnline(p.Online)) + p.OnlineCh = onlineCh + LogChannelSingleton.WriteMQData(model.GenerateOnline(p.OnlineCh)) } func (p *PlayerOnlineEvent) Shutdown() {