|
@@ -11,6 +11,7 @@ import (
|
|
|
jsoniter "github.com/json-iterator/go"
|
|
|
mhayaString "github.com/mhaya/extend/string"
|
|
|
mhayaTime "github.com/mhaya/extend/time"
|
|
|
+ cfacade "github.com/mhaya/facade"
|
|
|
"github.com/mhaya/game/game_cluster/internal/code"
|
|
|
"github.com/mhaya/game/game_cluster/internal/constant"
|
|
|
"github.com/mhaya/game/game_cluster/internal/data"
|
|
@@ -52,7 +53,7 @@ type (
|
|
|
)
|
|
|
|
|
|
func (p *actorPlayer) OnInit() {
|
|
|
- p.exitTime = time.Duration(rand.Int63n(1200)) + time.Minute*5
|
|
|
+ p.exitTime = time.Duration(rand.Int63n(1200)) + time.Minute*10
|
|
|
clog.Debugf("[actorPlayer] path = %s init!", p.PathString())
|
|
|
|
|
|
// 注册 session关闭的remote函数(网关触发连接断开后,会调用RPC发送该消息)
|
|
@@ -100,6 +101,8 @@ func (p *actorPlayer) OnInit() {
|
|
|
|
|
|
p.Remote().Register("unitTest", p.unitTest)
|
|
|
|
|
|
+ p.Remote().Register("setAvatar", p.setAvatar)
|
|
|
+
|
|
|
//p.Timer().Add(10*time.Second, p.refreshRoll)
|
|
|
// p.Timer().Add(60*time.Second, p.SetRewardToDB)
|
|
|
p.Timer().Add(1*time.Minute, p.setRedis)
|
|
@@ -118,7 +121,7 @@ func (p *actorPlayer) OnInit() {
|
|
|
|
|
|
//p.Timer().Add(5*time.Second, p.initHourly)
|
|
|
|
|
|
- p.Timer().AddOnce(5*time.Second, p.getAndUpdateAvatar) //排行榜头像
|
|
|
+ //p.Timer().AddOnce(5*time.Second, p.getAndUpdateAvatar) //排行榜头像
|
|
|
|
|
|
//p.Timer().Add(30*time.Second, p.updPassWordTime)
|
|
|
|
|
@@ -133,6 +136,13 @@ func (p *actorPlayer) updCashOut() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func (p *actorPlayer) setAvatar(req *UserAvatar) {
|
|
|
+ if p.isOnline && p.Player != nil {
|
|
|
+ p.Player.Avatar = req.avatar
|
|
|
+ p.dirty = true
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func (p *actorPlayer) updPassWordTime() {
|
|
|
if p.isOnline && p.Player != nil {
|
|
|
if p.Player.PwdErrRefreshTime > 0 && p.Player.PwdErrRefreshTime < mhayaTime.Now().Unix() {
|
|
@@ -185,6 +195,7 @@ func (p *actorPlayer) upatePlayerLevelStat() {
|
|
|
}
|
|
|
|
|
|
func (p *actorPlayer) OnStop() {
|
|
|
+ p.Timer().RemoveAll()
|
|
|
clog.Debugf("[actorPlayer] path = %s exit!", p.PathString())
|
|
|
}
|
|
|
|
|
@@ -257,6 +268,7 @@ func (p *actorPlayer) getAndUpdateAvatar() {
|
|
|
go p.getAvatar()
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
func (p *actorPlayer) getAvatar() {
|
|
|
openid, _ := mhayaString.ToInt64(p.Player.OpenId)
|
|
|
|
|
@@ -423,38 +435,42 @@ func (p *actorPlayer) playerSessionClose() {
|
|
|
|
|
|
// sessionClose 接收角色session关闭处理
|
|
|
func (p *actorPlayer) sessionClose() {
|
|
|
- if p.Player != nil {
|
|
|
+ if p.Player != nil && p.isOnline {
|
|
|
online.UnBindPlayer(p.uid)
|
|
|
- p.setDb()
|
|
|
+ //p.setDb()
|
|
|
//p.SetRewardToDB()
|
|
|
p.setRedisAll()
|
|
|
//logoutEvent := event.NewPlayerLogout(p.ActorID(), p.playerId, p.targetPath)
|
|
|
p.isOnline = false
|
|
|
p.Exit()
|
|
|
- models.SetServerRecord(p.App().NodeId(), online.Count())
|
|
|
+ //models.SetServerRecord(p.App().NodeId(), online.Count())
|
|
|
}
|
|
|
//p.PostEvent(&logoutEvent)
|
|
|
}
|
|
|
|
|
|
-func (p *actorPlayer) Init(req *token.Token) {
|
|
|
+func (p *actorPlayer) Init(req *token.Token) bool {
|
|
|
clog.Debugf("[actorPlayer] init token = %s", req)
|
|
|
|
|
|
ctx := context.Background()
|
|
|
acc, err := mdb.RDB.Get(ctx, fmt.Sprintf("%v:%v", constant.CNameAccount, req.OpenID)).Bytes()
|
|
|
if err != nil && err != redis.Nil {
|
|
|
clog.Debugf("[actorPlayer] initUser error: %v", err)
|
|
|
- return
|
|
|
+ return false
|
|
|
}
|
|
|
var account models.Account
|
|
|
if len(acc) > 0 {
|
|
|
err = jsoniter.Unmarshal(acc, &account)
|
|
|
if err != nil {
|
|
|
clog.Debugf("[actorPlayer] unmarshal account data error: %v", err)
|
|
|
- return
|
|
|
+ return false
|
|
|
}
|
|
|
p.Account = &account
|
|
|
} else {
|
|
|
- mdb.MDB.Collection(constant.CNameAccount).FindOne(context.Background(), bson.M{"openId": req.OpenID}).Decode(&account)
|
|
|
+ dbErr := mdb.MDB.Collection(constant.CNameAccount).FindOne(context.Background(), bson.M{"openId": req.OpenID}).Decode(&account).Error()
|
|
|
+ if dbErr != "" {
|
|
|
+ clog.Debugf("[actorPlayer] read account data by db error: %v", err)
|
|
|
+ return false
|
|
|
+ }
|
|
|
p.Account = &account
|
|
|
}
|
|
|
|
|
@@ -462,17 +478,22 @@ func (p *actorPlayer) Init(req *token.Token) {
|
|
|
play, err := mdb.RDB.Get(ctx, fmt.Sprintf("%v:%v", constant.CNamePlayer, req.OpenID)).Bytes()
|
|
|
if err != nil && err != redis.Nil {
|
|
|
clog.Debugf("[actorPlayer] initUser error: %v", err)
|
|
|
- return
|
|
|
+ return false
|
|
|
}
|
|
|
if len(play) > 0 {
|
|
|
err = jsoniter.Unmarshal(play, &player)
|
|
|
if err != nil {
|
|
|
clog.Debugf("[actorPlayer] unmarshal player data error: %v", err)
|
|
|
- return
|
|
|
+ return false
|
|
|
}
|
|
|
p.Player = &player
|
|
|
} else {
|
|
|
- mdb.MDB.Collection(constant.CNamePlayer).FindOne(context.Background(), bson.M{"userName": req.PlayerID}).Decode(&player)
|
|
|
+ dbErr := mdb.MDB.Collection(constant.CNamePlayer).FindOne(context.Background(), bson.M{"userName": req.PlayerID}).Decode(&player).Error()
|
|
|
+ if dbErr != "" {
|
|
|
+ clog.Debugf("[actorPlayer] read player data by db error: %v", err)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ p.Player = &player
|
|
|
}
|
|
|
if player.IsNew {
|
|
|
// go mdb.MDB.Collection(constant.CNamePlayer).InsertOne(context.Background(), user)
|
|
@@ -481,7 +502,7 @@ func (p *actorPlayer) Init(req *token.Token) {
|
|
|
clog.Debugf("[Init] newUser userName = %s openId = %s", p.Player.UserName, p.Player.OpenId)
|
|
|
p.botInvite()
|
|
|
}
|
|
|
-
|
|
|
+ return true
|
|
|
}
|
|
|
|
|
|
func (p *actorPlayer) InitBase(uid string) int32 {
|
|
@@ -500,9 +521,15 @@ func (p *actorPlayer) InitBase(uid string) int32 {
|
|
|
}
|
|
|
|
|
|
func (p *actorPlayer) login(req *token.Token) (*models.Player, int32) {
|
|
|
+ clog.Infof("[actorPlayer] init token = %v", req)
|
|
|
+
|
|
|
if !p.isOnline {
|
|
|
- p.Init(req)
|
|
|
+ if !p.Init(req) {
|
|
|
+ clog.Infof("[login] PlayerNotLogin err node=%v", p.App().NodeId())
|
|
|
+ return nil, code.PlayerNotLogin
|
|
|
+ }
|
|
|
}
|
|
|
+ clog.Infof("[actorPlayer] init suss token = %v", req)
|
|
|
|
|
|
p.isOnline = true
|
|
|
p.dirty = true
|
|
@@ -549,9 +576,13 @@ func (p *actorPlayer) login(req *token.Token) (*models.Player, int32) {
|
|
|
|
|
|
//p.getAndUpdateAvatar()
|
|
|
//检查提现
|
|
|
- go p.updCashOutStatusByOld(0)
|
|
|
+ //go p.updCashOutStatusByOld(0)
|
|
|
//统计相关
|
|
|
p.loginStat()
|
|
|
+ //更新头像
|
|
|
+ targetPath := cfacade.NewChildPath(p.App().NodeId(), "avatar"+p.App().NodeId(), p.Player.UserName)
|
|
|
+ p.Call(targetPath, "setAvatar", &UserAvatar{avatar: p.Player.Avatar, openId: p.Player.OpenId, userName: p.Player.UserName})
|
|
|
+
|
|
|
// 保存进入游戏的玩家对应的agentPath
|
|
|
online.BindPlayer(p.Player.UserName, p.uid, req.TargetPath)
|
|
|
|