From 7ecebe62e670565c4470bd87a648157fef42797e Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Tue, 23 Apr 2024 14:28:13 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=B4=A6=E5=8F=B7=E8=A1=A8=E8=A1=A5?= =?UTF-8?q?=E5=85=85=E6=B8=A0=E9=81=93=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbproxy/svc/u_account.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/dbproxy/svc/u_account.go b/dbproxy/svc/u_account.go index ae8cdab..6529d4c 100644 --- a/dbproxy/svc/u_account.go +++ b/dbproxy/svc/u_account.go @@ -59,6 +59,11 @@ func (svc *AccountSvc) AccountIsExist(args *model.AccIsExistArg, ret *model.AccR } acc := &model.Account{} + defer func() { + // 修改旧数据 + // 补充渠道信息 + svc.setParam(acc) + }() switch args.LoginType { case common.LoginTypeGuest: @@ -229,6 +234,35 @@ func (svc *AccountSvc) AccountIsExist(args *model.AccIsExistArg, ret *model.AccR return nil } +func (svc *AccountSvc) setParam(acc *model.Account) { + if acc == nil || (acc.Channel != "" && acc.Channel != "0") { + return + } + + c := PlayerDataCollection(acc.Platform) + if c == nil { + return + } + p := new(model.PlayerData) + err := c.Find(bson.M{"snid": acc.SnId}).One(p) + if err != nil { + logger.Logger.Errorf("setChannel error:%v", err) + return + } + + c = AccountCollection(acc.Platform) + if c == nil { + return + } + acc.Channel = p.Channel + if acc.Channel != "" { + err = c.Update(bson.M{"_id": acc.AccountId}, bson.D{{"$set", bson.D{{"channel", acc.Channel}}}}) + if err != nil { + logger.Logger.Errorf("setChannel error:%v", err) + } + } +} + func (svc *AccountSvc) AccountTelIsRegiste(args *model.AccIsExistArg, exist *bool) error { caccounts := AccountCollection(args.Platform) if caccounts != nil { From 3a5039727bde9f16e90b0005a988b4cfbf13b2fa Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Tue, 23 Apr 2024 15:10:48 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbproxy/svc/u_account.go | 34 ++++----- dbproxy/svc/u_player.go | 17 +++-- model/account.go | 73 ++++++++----------- model/player.go | 147 ++++++++++++++++++--------------------- 4 files changed, 123 insertions(+), 148 deletions(-) diff --git a/dbproxy/svc/u_account.go b/dbproxy/svc/u_account.go index 6529d4c..c168c91 100644 --- a/dbproxy/svc/u_account.go +++ b/dbproxy/svc/u_account.go @@ -480,22 +480,22 @@ func (svc *AccountSvc) EditAccountPwd(acc *model.Account, ret *model.AccRet) err return caccounts.Update(bson.M{"_id": acc.AccountId}, bson.D{{"$set", bson.D{{"backpassword", acc.TelPassWord}, {"telpassword", hashsum}}}}) } -func (svc *AccountSvc) ResetBackAccountPwd(args *model.AccIdArg, ret *model.AccRet) error { - caccounts := AccountCollection(args.Platform) - if caccounts == nil { - return ErrAccDBNotOpen - } - - var acc model.Account - err := caccounts.Find(bson.M{"_id": bson.ObjectIdHex(args.AccId)}).One(&acc) - if err != nil { - return err - } - if len(acc.BackPassWord) > 0 { - return caccounts.Update(bson.M{"_id": acc.AccountId}, bson.D{{"$set", bson.D{{"telpassword", acc.BackPassWord}}}}) - } - return nil -} +//func (svc *AccountSvc) ResetBackAccountPwd(args *model.AccIdArg, ret *model.AccRet) error { +// caccounts := AccountCollection(args.Platform) +// if caccounts == nil { +// return ErrAccDBNotOpen +// } +// +// var acc model.Account +// err := caccounts.Find(bson.M{"_id": bson.ObjectIdHex(args.AccId)}).One(&acc) +// if err != nil { +// return err +// } +// if len(acc.BackPassWord) > 0 { +// return caccounts.Update(bson.M{"_id": acc.AccountId}, bson.D{{"$set", bson.D{{"telpassword", acc.BackPassWord}}}}) +// } +// return nil +//} /* * 修改帐号密码 @@ -540,7 +540,7 @@ func (svc *AccountSvc) UpdateAccountPlatformInfo(acc *model.Account, ret *model. return caccounts.Update(bson.M{"_id": acc.AccountId}, bson.D{{"$set", bson.M{"platform": acc.Platform, - "channel": acc.Channel, "promoter": acc.Promoter, "inviterid": acc.InviterId, "packegetag": acc.PackegeTag, "promotertree": acc.PromoterTree}}}) + "channel": acc.Channel, "packegetag": acc.PackegeTag}}}) } func (svc *AccountSvc) GetRobotAccounts(limit int, accs *[]model.Account) error { diff --git a/dbproxy/svc/u_player.go b/dbproxy/svc/u_player.go index b0ca506..4d001ad 100644 --- a/dbproxy/svc/u_player.go +++ b/dbproxy/svc/u_player.go @@ -147,8 +147,8 @@ func (svc *PlayerDataSvc) GetPlayerData(args *model.GetPlayerDataArgs, ret *mode name = "Guest" } - pd = model.NewPlayerData(args.Acc, name, id, a.Channel, a.Platform, a.Promoter, a.InviterId, a.PromoterTree, a.Params, - a.Tel, a.PackegeTag, dataParams.Ip, 0, dataParams.UnionId, a.DeviceInfo, a.SubPromoter, a.TagKey, a.AccountType) + pd = model.NewPlayerData(args.Acc, name, id, a.Channel, a.Platform, a.Params, + a.Tel, a.PackegeTag, dataParams.Ip, 0, dataParams.UnionId, a.DeviceInfo, a.TagKey, a.AccountType) if pd != nil { err = cplayerdata.Insert(pd) if err != nil { @@ -222,8 +222,8 @@ func (svc *PlayerDataSvc) CreatePlayerDataByThird(args *model.CreatePlayer, ret } var dataParams model.PlayerParams json.Unmarshal([]byte(a.Params), &dataParams) - pd = model.NewPlayerDataThird(acc, name, args.HeadUrl, id, a.Channel, a.Platform, a.Promoter, a.InviterId, - a.PromoterTree, a.Params, a.Tel, a.PackegeTag, dataParams.Ip, a.SubPromoter, a.TagKey, a.AccountType, a.DeviceOs) + pd = model.NewPlayerDataThird(acc, name, args.HeadUrl, id, a.Channel, a.Platform, a.Params, + a.Tel, a.PackegeTag, dataParams.Ip, a.TagKey, a.AccountType, a.DeviceOs) if pd != nil { err = cplayerdata.Insert(pd) if err != nil { @@ -292,9 +292,8 @@ func (svc *PlayerDataSvc) CreatePlayerDataOnRegister(args *model.PlayerDataArg, } var dataParams model.PlayerParams json.Unmarshal([]byte(a.Params), &dataParams) - pd = model.NewPlayerData(acc, name, id, a.Channel, a.Platform, a.Promoter, a.InviterId, - a.PromoterTree, a.Params, a.Tel, a.PackegeTag, dataParams.Ip, int64(args.AddCoin), - "", a.DeviceInfo, a.SubPromoter, a.TagKey, a.AccountType) + pd = model.NewPlayerData(acc, name, id, a.Channel, a.Platform, a.Params, a.Tel, a.PackegeTag, + dataParams.Ip, int64(args.AddCoin), "", a.DeviceInfo, a.TagKey, a.AccountType) pd.HeadUrl = args.HeadUrl if pd != nil { err = cplayerdata.Insert(pd) @@ -342,8 +341,8 @@ func (svc *PlayerDataSvc) GetPlayerDataBySnId(args *model.GetPlayerDataBySnIdArg name = "Guest" } - pd := model.NewPlayerData(a.AccountId.Hex(), name, a.SnId, a.Channel, a.Platform, a.Promoter, a.InviterId, a.PromoterTree, a.Params, - a.Tel, a.PackegeTag, dataParams.Ip, 0, dataParams.UnionId, a.DeviceInfo, a.SubPromoter, a.TagKey, a.AccountType) + pd := model.NewPlayerData(a.AccountId.Hex(), name, a.SnId, a.Channel, a.Platform, a.Params, + a.Tel, a.PackegeTag, dataParams.Ip, 0, dataParams.UnionId, a.DeviceInfo, a.TagKey, a.AccountType) if pd != nil { err = cplayerdata.Insert(pd) if err != nil { diff --git a/model/account.go b/model/account.go index c5fd3f8..e2410fd 100644 --- a/model/account.go +++ b/model/account.go @@ -17,36 +17,31 @@ import ( // 登录次数,最后登录最后登出时间并不准确 type Account struct { - AccountId bson.ObjectId `bson:"_id"` - SnId int32 //玩家账号直接在这里生成 - UserName string //Service Provider AccountId - PassWord string //昵称密码 - TelPassWord string //帐号密码 - BackPassWord string //备份账号密码 - //VIP int32 //VIP帐号 等级 - Platform string //平台 - Channel string //渠道 - Promoter string //推广员 - SubPromoter string //子推广员 - InviterId int32 //邀请人ID - PromoterTree int32 //推广树ID - Tel string //电话号码 - Params string //其他参数 - DeviceOs string //系统 - PackegeTag string //包标识 - Package string //包名 android:包名 ios:bundleid - DeviceInfo string //设备信息 - LoginTimes int //登录次数 - State int64 //冻结到期时间戳 - RegisteTime time.Time //注册时间 - LastLoginTime time.Time //最后一次登录时间 - LastLogoutTime time.Time //最后一次登出时间 - Flag int32 //二次推广用户标记 - Remark string //备注信息 - TagKey int32 //包标识关键字 - AccountType int32 //1.google 2.facebook - RegisterTs int64 // 注册时间戳 - TelPassWordExpire int64 // 手机验证码登录过期时间戳 + AccountId bson.ObjectId `bson:"_id"` + SnId int32 //玩家账号直接在这里生成 + UserName string //Service Provider AccountId + PassWord string //昵称密码 + TelPassWord string //帐号密码 + BackPassWord string //备份账号密码 + Platform string //平台 + Channel string //渠道 + Tel string //电话号码 + Params string //其他参数 + DeviceOs string //系统 + PackegeTag string //包标识 + Package string //包名 android:包名 ios:bundleid + DeviceInfo string //设备信息 + LoginTimes int //登录次数 + State int64 //冻结到期时间戳 + RegisteTime time.Time //注册时间 + LastLoginTime time.Time //最后一次登录时间 + LastLogoutTime time.Time //最后一次登出时间 + Flag int32 //二次推广用户标记 + Remark string //备注信息 + TagKey int32 //包标识关键字 + AccountType int32 //1.google 2.facebook + RegisterTs int64 // 注册时间戳 + TelPassWordExpire int64 // 手机验证码登录过期时间戳 } func NewAccount() *Account { @@ -128,11 +123,7 @@ func InsertAccount(userName, passWord, platform, channel, promoter, params, devi acc.Platform = platform acc.Channel = channel acc.Params = params - acc.SubPromoter = subPromoter acc.DeviceOs = deviceOs - acc.Promoter = promoter - acc.InviterId = inviterId - acc.PromoterTree = promoterTree acc.LastLoginTime = tCur acc.RegisteTime = tCur acc.LoginTimes = 1 @@ -166,10 +157,7 @@ func InsertTelAccount(userName, passWord, platform, channel, promoter, params st acc.TelPassWord = telpassword acc.Platform = platform acc.Channel = channel - acc.Promoter = promoter acc.Params = params - acc.InviterId = inviterId - acc.PromoterTree = promoterTree acc.LastLoginTime = tCur acc.RegisteTime = tCur acc.LoginTimes = 1 @@ -493,13 +481,10 @@ func UpdateAccountPlatformInfo(account string, platform, channel, promoter, invi return ErrRPClientNoConn } args := &Account{ - AccountId: bson.ObjectIdHex(account), - Platform: strconv.Itoa(int(platform)), - Channel: strconv.Itoa(int(channel)), - Promoter: strconv.Itoa(int(promoter)), - PromoterTree: promoterTree, - InviterId: inviterid, - PackegeTag: packTag, + AccountId: bson.ObjectIdHex(account), + Platform: strconv.Itoa(int(platform)), + Channel: strconv.Itoa(int(channel)), + PackegeTag: packTag, } ret := &AccRet{} err := rpcCli.CallWithTimeout("AccountSvc.UpdateAccountPlatformInfo", args, ret, time.Second*30) diff --git a/model/player.go b/model/player.go index 0e44609..b110ccc 100644 --- a/model/player.go +++ b/model/player.go @@ -709,9 +709,9 @@ func (this *PlayerData) GetPlayerDataEncoder() (bytes.Buffer, error) { return buf, err } -func NewPlayerData(acc string, name string, id int32, channel, platform, promoter string, inviterId, - promoterTree int32, params, tel string, packTag, ip string, addCoin int64, unionid, deviceInfo string, - subPromoter string, tagkey, accountType int32) *PlayerData { +func NewPlayerData(acc string, name string, id int32, channel, platform string, params, tel string, + packTag, ip string, addCoin int64, unionid, deviceInfo string, + tagkey, accountType int32) *PlayerData { if len(name) == 0 { logger.Logger.Trace("New player name is empty.") return nil @@ -726,47 +726,42 @@ func NewPlayerData(acc string, name string, id int32, channel, platform, promote isRobot := channel == common.Channel_Rob pd := &PlayerData{ - Id: bson.NewObjectId(), - AccountId: acc, - AccountType: accountType, - Name: name, - Channel: channel, - Platform: platform, - SnId: id, - InviterId: inviterId, - PromoterTree: promoterTree, - Head: rand.Int31n(common.HeadRange), - //Coin: int64(GameParamData.NewPlayerCoin) + addCoin, - SafeBoxPassword: pwd, - Ip: ip, - RegIp: ip, - Params: params, - Tel: tel, - SubBeUnderAgentCode: subPromoter, - AgentType: 0, - LastLoginTime: tNow.Local(), - LastLogoutTime: tNow.AddDate(0, 0, -1).Local(), - CreateTime: tNow.Local(), - Ver: VER_PLAYER_MAX - 1, - HeadOutLine: 1, - VIP: 0, - CoinPayTotal: 0, - MoneyPayTotal: 0, - IsRob: isRobot, - BeUnderAgentCode: promoter, - PackageID: packTag, - WBLevel: 0, - WBCoinTotalOut: 0, - WBCoinTotalIn: 0, - WBCoinLimit: 0, - YesterdayGameData: NewPlayerGameCtrlData(), - TodayGameData: NewPlayerGameCtrlData(), - TotalGameData: make(map[int][]*PlayerGameTotal), - GDatas: make(map[string]*PlayerGameInfo), - TagKey: tagkey, - ShopTotal: make(map[int32]*ShopTotal), - ShopLastLookTime: make(map[int32]int64), - IsFoolPlayer: make(map[string]bool), + Id: bson.NewObjectId(), + AccountId: acc, + AccountType: accountType, + Name: name, + Channel: channel, + Platform: platform, + SnId: id, + Head: rand.Int31n(common.HeadRange), + SafeBoxPassword: pwd, + Ip: ip, + RegIp: ip, + Params: params, + Tel: tel, + AgentType: 0, + LastLoginTime: tNow.Local(), + LastLogoutTime: tNow.AddDate(0, 0, -1).Local(), + CreateTime: tNow.Local(), + Ver: VER_PLAYER_MAX - 1, + HeadOutLine: 1, + VIP: 0, + CoinPayTotal: 0, + MoneyPayTotal: 0, + IsRob: isRobot, + PackageID: packTag, + WBLevel: 0, + WBCoinTotalOut: 0, + WBCoinTotalIn: 0, + WBCoinLimit: 0, + YesterdayGameData: NewPlayerGameCtrlData(), + TodayGameData: NewPlayerGameCtrlData(), + TotalGameData: make(map[int][]*PlayerGameTotal), + GDatas: make(map[string]*PlayerGameInfo), + TagKey: tagkey, + ShopTotal: make(map[int32]*ShopTotal), + ShopLastLookTime: make(map[int32]int64), + IsFoolPlayer: make(map[string]bool), //测试数据 PowerList: []int32{1}, //默认炮台 UnMaxPower: 10, //初始化炮倍最小倍数 @@ -781,47 +776,43 @@ func NewPlayerData(acc string, name string, id int32, channel, platform, promote return pd } -func NewPlayerDataThird(acc string, name, headUrl string, id int32, channel, platform, promoter string, inviterId, - promoterTree int32, params, tel string, packTag, ip string, subPromoter string, tagkey, accountType int32, deviceOS string) *PlayerData { +func NewPlayerDataThird(acc string, name, headUrl string, id int32, channel, platform string, params, tel string, + packTag, ip string, tagkey, accountType int32, deviceOS string) *PlayerData { if len(name) == 0 { logger.Logger.Trace("New player name is empty.") return nil } tNow := time.Now() pd := &PlayerData{ - Id: bson.NewObjectId(), - AccountId: acc, - Name: name, - Channel: channel, - Platform: platform, - SnId: id, - InviterId: inviterId, - PromoterTree: promoterTree, - Head: rand.Int31n(common.HeadRange), - HeadUrl: headUrl, + Id: bson.NewObjectId(), + AccountId: acc, + Name: name, + Channel: channel, + Platform: platform, + SnId: id, + Head: rand.Int31n(common.HeadRange), + HeadUrl: headUrl, //Coin: int64(GameParamData.NewPlayerCoin), - Ip: ip, - RegIp: ip, - Params: params, - Tel: tel, - SubBeUnderAgentCode: subPromoter, - LastLoginTime: tNow.Local(), - LastLogoutTime: tNow.AddDate(0, 0, -1).Local(), - CreateTime: tNow.Local(), - Ver: VER_PLAYER_MAX - 1, - HeadOutLine: 1, - IsRob: false, - BeUnderAgentCode: promoter, - PackageID: packTag, - YesterdayGameData: NewPlayerGameCtrlData(), - TodayGameData: NewPlayerGameCtrlData(), - TotalGameData: make(map[int][]*PlayerGameTotal), - GDatas: make(map[string]*PlayerGameInfo), - TagKey: tagkey, - ShopTotal: make(map[int32]*ShopTotal), - ShopLastLookTime: make(map[int32]int64), - AccountType: accountType, - DeviceOS: deviceOS, + Ip: ip, + RegIp: ip, + Params: params, + Tel: tel, + LastLoginTime: tNow.Local(), + LastLogoutTime: tNow.AddDate(0, 0, -1).Local(), + CreateTime: tNow.Local(), + Ver: VER_PLAYER_MAX - 1, + HeadOutLine: 1, + IsRob: false, + PackageID: packTag, + YesterdayGameData: NewPlayerGameCtrlData(), + TodayGameData: NewPlayerGameCtrlData(), + TotalGameData: make(map[int][]*PlayerGameTotal), + GDatas: make(map[string]*PlayerGameInfo), + TagKey: tagkey, + ShopTotal: make(map[int32]*ShopTotal), + ShopLastLookTime: make(map[int32]int64), + AccountType: accountType, + DeviceOS: deviceOS, } pd.InitNewData(params) 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 3/3] =?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() {