|
@@ -10,6 +10,7 @@ import (
|
|
|
"github.com/mhaya/game/game_cluster/internal/mdb"
|
|
|
"github.com/mhaya/game/game_cluster/internal/mdb/models"
|
|
|
"github.com/mhaya/game/game_cluster/internal/param"
|
|
|
+ "github.com/mhaya/game/game_cluster/internal/third"
|
|
|
cactor "github.com/mhaya/net/actor"
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
@@ -33,19 +34,23 @@ func (p *ActorAccount) AliasID() string {
|
|
|
// OnInit center为后端节点,不直接与客户端通信,所以注册了一些remote函数,供RPC调用
|
|
|
func (p *ActorAccount) OnInit() {
|
|
|
p.Remote().Register("registerAccount", p.registerOrLoinAccount)
|
|
|
+ p.Timer().Add(5*time.Second, p.load)
|
|
|
p.Timer().Add(time.Minute, p.Stat)
|
|
|
+ p.Timer().Add(1*time.Minute, p.PlayerIpStat)
|
|
|
p.Timer().Add(time.Minute, p.playerLevelStat)
|
|
|
p.Timer().AddFixedHour(23, 59, 59, p.Stat)
|
|
|
}
|
|
|
|
|
|
func (p *ActorAccount) Stat() {
|
|
|
daily := mhayaTime.Now().DailyTOTimeStamp()
|
|
|
+
|
|
|
+ var dailyRecord models.DailyRecord
|
|
|
+ dailyRecord.Daily = daily
|
|
|
platformConfig := data.PlatformConfig.GatMap()
|
|
|
channelConfig := data.ChannelConfig.GatMap()
|
|
|
for _, v := range platformConfig {
|
|
|
for _, v2 := range channelConfig {
|
|
|
p.dailyStat(v.Name, v2.Name, daily)
|
|
|
- time.Sleep(time.Second)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -60,6 +65,64 @@ func (p *ActorAccount) playerLevelStat() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func (p *ActorAccount) PlayerIpStat() {
|
|
|
+ daily := mhayaTime.Now().DailyTOTimeStamp()
|
|
|
+ platformConfig := data.PlatformConfig.GatMap()
|
|
|
+ channelConfig := data.ChannelConfig.GatMap()
|
|
|
+ for _, v := range platformConfig {
|
|
|
+ for _, v2 := range channelConfig {
|
|
|
+ p.ipStat(v.Name, v2.Name, daily)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func (p *ActorAccount) load() {
|
|
|
+ m, err := mdb.RDB.HGetAll(context.Background(), constant.ServerLoadHKey).Result()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var stat models.PlayerServerLoadStat
|
|
|
+ stat.Name = "load"
|
|
|
+ stat.Load = m
|
|
|
+ stat.TotalUser = p.userStat()
|
|
|
+ stat.UpdateTime = mhayaTime.Now().Unix()
|
|
|
+ mdb.MDB.Collection(constant.CNameServerLoadStat).UpdateOne(context.Background(), bson.M{"name": "load"}, bson.M{"$set": &stat}, options.Update().SetUpsert(true))
|
|
|
+}
|
|
|
+
|
|
|
+func (p *ActorAccount) userStat() int64 {
|
|
|
+ var num int64
|
|
|
+
|
|
|
+ platformConfig := data.PlatformConfig.GatMap()
|
|
|
+ channelConfig := data.ChannelConfig.GatMap()
|
|
|
+
|
|
|
+ for _, v := range platformConfig {
|
|
|
+ for _, v2 := range channelConfig {
|
|
|
+ num += models.GetTotalPlayerRecordLen(v.Name, v2.Name)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return num
|
|
|
+}
|
|
|
+
|
|
|
+func (p *ActorAccount) ipStat(platform, channel string, daily int64) {
|
|
|
+ var ipMap = make(map[string]int)
|
|
|
+ ret, err := models.GetAllDailyRecordNewUserRegister(platform, channel, models.DailyRecordNewRegistered)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range ret {
|
|
|
+ c, _ := third.GetCountryByIP(v)
|
|
|
+ ipMap[c] += 1
|
|
|
+ }
|
|
|
+ var stat models.PlayerCountryStat
|
|
|
+ stat.Daily = daily
|
|
|
+ stat.Platform = platform
|
|
|
+ stat.Channel = channel
|
|
|
+ stat.PlayerRegisterCountry = ipMap
|
|
|
+ stat.UpdateTime = mhayaTime.Now().Unix()
|
|
|
+ mdb.MDB.Collection(constant.CNamePlayerCountryByIPStat).UpdateOne(context.Background(), bson.M{"platform": platform, "channel": channel, "daily": daily}, bson.M{"$set": &stat}, options.Update().SetUpsert(true))
|
|
|
+}
|
|
|
+
|
|
|
func (p *ActorAccount) levelStat(platform, channel string) {
|
|
|
level := make(map[string]int)
|
|
|
ret, err := models.GetAllTotalPlayerRecord(platform, channel)
|
|
@@ -73,10 +136,11 @@ func (p *ActorAccount) levelStat(platform, channel string) {
|
|
|
stat.Platform = platform
|
|
|
stat.Channel = channel
|
|
|
stat.ServerLevel = level
|
|
|
+ stat.UpdateTime = mhayaTime.Now().Unix()
|
|
|
mdb.MDB.Collection(constant.CNamePlayerLevelStat).UpdateOne(context.Background(), bson.M{"platform": platform, "channel": channel}, bson.M{"$set": &stat}, options.Update().SetUpsert(true))
|
|
|
}
|
|
|
|
|
|
-func (p *ActorAccount) dailyStat(platform, channel string, daily int64) {
|
|
|
+func (p *ActorAccount) dailyStat(platform, channel string, daily int64) *models.DailyRecord {
|
|
|
|
|
|
var dailyRecord models.DailyRecord
|
|
|
dailyRecord.Daily = daily
|
|
@@ -109,6 +173,7 @@ func (p *ActorAccount) dailyStat(platform, channel string, daily int64) {
|
|
|
dailyRecord.UpdatedAt = mhayaTime.Now().Unix()
|
|
|
|
|
|
mdb.MDB.Collection(constant.CNamePlayerDailyRecord).UpdateOne(context.Background(), bson.M{"platform": platform, "channel": channel, "daily": daily}, bson.M{"$set": &dailyRecord}, options.Update().SetUpsert(true))
|
|
|
+ return &dailyRecord
|
|
|
}
|
|
|
|
|
|
// registerDevAccount 注册开发者帐号
|