优化炸档情况的登录错误提示
This commit is contained in:
1 parent
1b27b54237
commit
0cab0d95c2
11 files changed
+102
-43
No files matched your search
+3
-3
@@ -510,12 +510,12 @@ func (k *KcpConnManager) doGateLogin(req *proto.GetPlayerTokenReq, session *Sess
|
||||
}
|
||||
if tokenVerifyRsp.RetCode != 0 {
|
||||
logger.Error("verify token error, openId: %v", req.AccountUid)
|
||||
return k.loginFailRsp(0, proto.Retcode_RET_TOKEN_ERROR, false, 0)
|
||||
return k.loginFailRsp(0, proto.Retcode_RET_ACCOUNT_VEIRFY_ERROR, false, 0)
|
||||
}
|
||||
account, err := k.db.QueryAccountByOpenId(req.AccountUid)
|
||||
if err != nil {
|
||||
logger.Error("query account error: %v, openId: %v", err, req.AccountUid)
|
||||
return k.loginFailRsp(0, proto.Retcode_RET_LOGIN_DB_FAIL, false, 0)
|
||||
return k.loginFailRsp(0, proto.Retcode_RET_SVR_ERROR, false, 0)
|
||||
}
|
||||
if account == nil {
|
||||
// 注册账号与uid关联
|
||||
@@ -533,7 +533,7 @@ func (k *KcpConnManager) doGateLogin(req *proto.GetPlayerTokenReq, session *Sess
|
||||
_, err = k.db.InsertAccount(account)
|
||||
if err != nil {
|
||||
logger.Error("insert account error: %v, openId: %v", err, req.AccountUid)
|
||||
return k.loginFailRsp(0, proto.Retcode_RET_LOGIN_DB_FAIL, false, 0)
|
||||
return k.loginFailRsp(0, proto.Retcode_RET_SVR_ERROR, false, 0)
|
||||
}
|
||||
}
|
||||
uid := account.Uid
|
||||
|
||||
@@ -2,6 +2,7 @@ package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"hk4e/gs/model"
|
||||
|
||||
@@ -188,7 +189,7 @@ func (d *Dao) QueryPlayerById(playerId uint32) (*model.Player, error) {
|
||||
player := new(model.Player)
|
||||
err := result.Decode(player)
|
||||
if err != nil {
|
||||
if err == mongo.ErrNoDocuments {
|
||||
if errors.Is(err, mongo.ErrNoDocuments) {
|
||||
return nil, nil
|
||||
} else {
|
||||
return nil, err
|
||||
@@ -206,7 +207,7 @@ func (d *Dao) QueryChatMsgById(id primitive.ObjectID) (*model.ChatMsg, error) {
|
||||
chatMsg := new(model.ChatMsg)
|
||||
err := result.Decode(chatMsg)
|
||||
if err != nil {
|
||||
if err == mongo.ErrNoDocuments {
|
||||
if errors.Is(err, mongo.ErrNoDocuments) {
|
||||
return nil, nil
|
||||
} else {
|
||||
return nil, err
|
||||
|
||||
+1
-1
@@ -105,7 +105,7 @@ func (g *Game) GetAi() *model.Player {
|
||||
}
|
||||
|
||||
func (g *Game) CreateRobot(uid uint32, name string, sign string) *model.Player {
|
||||
g.OnLogin(uid, 0, "", nil, 0)
|
||||
g.OnLogin(uid, 0, "", nil, 0, true)
|
||||
robot := USER_MANAGER.GetOnlineUser(uid)
|
||||
robot.DbState = model.DbNormal
|
||||
g.SetPlayerBornDataReq(robot, &proto.SetPlayerBornDataReq{AvatarId: 10000007, NickName: name})
|
||||
|
||||
@@ -432,14 +432,11 @@ func (g *GMCmd) XLuaDebug(userId uint32, luacBase64 string) {
|
||||
logger.Error("decode luac error: %v", err)
|
||||
return
|
||||
}
|
||||
GAME.SendMsg(cmd.WindSeedClientNotify, player.PlayerId, 0, &proto.WindSeedClientNotify{
|
||||
Notify: &proto.WindSeedClientNotify_AreaNotify_{
|
||||
AreaNotify: &proto.WindSeedClientNotify_AreaNotify{
|
||||
AreaCode: luac,
|
||||
AreaId: 1,
|
||||
AreaType: 1,
|
||||
},
|
||||
},
|
||||
GAME.SendMsg(cmd.PlayerLuaShellNotify, player.PlayerId, 0, &proto.PlayerLuaShellNotify{
|
||||
ShellType: proto.LuaShellType_LUASHELL_NORMAL,
|
||||
Id: 1,
|
||||
LuaShell: luac,
|
||||
UseType: 1,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -545,7 +542,7 @@ func (g *GMCmd) SendMsgToPlayer(cmdName string, userId uint32, msgJson string) {
|
||||
logger.Error("cmd name not found")
|
||||
return
|
||||
}
|
||||
if cmdId == cmd.WindSeedClientNotify {
|
||||
if cmdId == cmd.WindSeedClientNotify || cmdId == cmd.PlayerLuaShellNotify {
|
||||
logger.Error("what are you doing ???")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ func (l *LocalEventManager) LocalEventHandle(localEvent *LocalEvent) {
|
||||
switch localEvent.EventId {
|
||||
case LoadLoginUserFromDbFinish:
|
||||
playerLoginInfo := localEvent.Msg.(*PlayerLoginInfo)
|
||||
GAME.OnLogin(playerLoginInfo.UserId, playerLoginInfo.ClientSeq, playerLoginInfo.GateAppId, playerLoginInfo.Player, playerLoginInfo.JoinHostUserId)
|
||||
GAME.OnLogin(playerLoginInfo.UserId, playerLoginInfo.ClientSeq, playerLoginInfo.GateAppId, playerLoginInfo.Player, playerLoginInfo.JoinHostUserId, playerLoginInfo.Ok)
|
||||
case ExitRunUserCopyAndSave:
|
||||
fallthrough
|
||||
case RunUserCopyAndSave:
|
||||
|
||||
@@ -10,6 +10,8 @@ import (
|
||||
"hk4e/pkg/logger"
|
||||
"hk4e/protocol/cmd"
|
||||
"hk4e/protocol/proto"
|
||||
|
||||
pb "google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
// 游戏服务器定时帧管理器
|
||||
@@ -375,6 +377,28 @@ func (t *TickManager) onTick100MilliSecond(now int64) {
|
||||
Damage: 100,
|
||||
},
|
||||
})
|
||||
if attackResultTemplate != nil {
|
||||
evtBeingHitInfo := &proto.EvtBeingHitInfo{
|
||||
PeerId: 0,
|
||||
AttackResult: attackResultTemplate,
|
||||
FrameNum: 0,
|
||||
}
|
||||
evtBeingHitInfo.AttackResult.AttackerId = rigidBody.avatarEntityId
|
||||
evtBeingHitInfo.AttackResult.DefenseId = rigidBody.hitAvatarEntityId
|
||||
evtBeingHitInfo.AttackResult.Damage = 100
|
||||
evtBeingHitInfo.AttackResult.HitCollision.HitPoint = &proto.Vector{X: float32(defPlayer.Pos.X), Y: float32(defPlayer.Pos.Y), Z: float32(defPlayer.Pos.Z)}
|
||||
combatData, err := pb.Marshal(evtBeingHitInfo)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
GAME.SendToSceneA(scene, cmd.CombatInvocationsNotify, 0, &proto.CombatInvocationsNotify{
|
||||
InvokeList: []*proto.CombatInvokeEntry{{
|
||||
CombatData: combatData,
|
||||
ForwardType: proto.ForwardType_FORWARD_TO_ALL,
|
||||
ArgumentType: proto.CombatTypeArgument_COMBAT_EVT_BEING_HIT,
|
||||
}},
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -95,6 +95,7 @@ type PlayerLoginInfo struct {
|
||||
ClientSeq uint32
|
||||
GateAppId string
|
||||
JoinHostUserId uint32
|
||||
Ok bool
|
||||
}
|
||||
|
||||
// OnlineUser 玩家上线
|
||||
@@ -110,19 +111,39 @@ func (u *UserManager) OnlineUser(userId uint32, clientSeq uint32, gateAppId stri
|
||||
ok := u.db.DistLockSync(userId)
|
||||
if !ok {
|
||||
logger.Error("lock redis offline player data error, uid: %v", userId)
|
||||
LOCAL_EVENT_MANAGER.GetLocalEventChan() <- &LocalEvent{
|
||||
EventId: LoadLoginUserFromDbFinish,
|
||||
Msg: &PlayerLoginInfo{
|
||||
UserId: userId,
|
||||
ClientSeq: clientSeq,
|
||||
GateAppId: gateAppId,
|
||||
Ok: false,
|
||||
},
|
||||
}
|
||||
return
|
||||
}
|
||||
player, err := u.LoadUserFromDbSync(userId)
|
||||
if err != nil {
|
||||
logger.Error("can not load user from db, uid: %v", userId)
|
||||
LOCAL_EVENT_MANAGER.GetLocalEventChan() <- &LocalEvent{
|
||||
EventId: LoadLoginUserFromDbFinish,
|
||||
Msg: &PlayerLoginInfo{
|
||||
UserId: userId,
|
||||
ClientSeq: clientSeq,
|
||||
GateAppId: gateAppId,
|
||||
Ok: false,
|
||||
},
|
||||
}
|
||||
// 解离线玩家数据分布式锁
|
||||
u.db.DistUnlock(userId)
|
||||
return
|
||||
}
|
||||
player := u.LoadUserFromDbSync(userId)
|
||||
if player != nil {
|
||||
u.SaveUserToRedisSync(player)
|
||||
}
|
||||
// 解离线玩家数据分布式锁
|
||||
u.db.DistUnlock(userId)
|
||||
if player != nil {
|
||||
u.ChangeUserDbState(player, model.DbNormal)
|
||||
player.ChatMsgMap = u.LoadUserChatMsgFromDbSync(userId)
|
||||
} else {
|
||||
logger.Error("can not find user from db, uid: %v", userId)
|
||||
logger.Info("reg new player, uid: %v", userId)
|
||||
}
|
||||
LOCAL_EVENT_MANAGER.GetLocalEventChan() <- &LocalEvent{
|
||||
EventId: LoadLoginUserFromDbFinish,
|
||||
@@ -132,8 +153,11 @@ func (u *UserManager) OnlineUser(userId uint32, clientSeq uint32, gateAppId stri
|
||||
ClientSeq: clientSeq,
|
||||
GateAppId: gateAppId,
|
||||
JoinHostUserId: joinHostUserId,
|
||||
Ok: true,
|
||||
},
|
||||
}
|
||||
// 解离线玩家数据分布式锁
|
||||
u.db.DistUnlock(userId)
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -375,7 +399,7 @@ func (u *UserManager) LoadTempOfflineUser(userId uint32, lock bool) *model.Playe
|
||||
// 大多数情况下活跃玩家都在redis 所以不会走到下面
|
||||
// TODO 防止恶意攻击造成redis缓存穿透
|
||||
startTime := time.Now().UnixNano()
|
||||
player = u.LoadUserFromDbSync(userId)
|
||||
player, _ = u.LoadUserFromDbSync(userId)
|
||||
endTime := time.Now().UnixNano()
|
||||
costTime := endTime - startTime
|
||||
logger.Info("try to load player from db sync in game main loop, cost time: %v ns", costTime)
|
||||
@@ -483,13 +507,13 @@ func (u *UserManager) saveUserHandle() {
|
||||
}()
|
||||
}
|
||||
|
||||
func (u *UserManager) LoadUserFromDbSync(userId uint32) *model.Player {
|
||||
func (u *UserManager) LoadUserFromDbSync(userId uint32) (*model.Player, error) {
|
||||
player, err := u.db.QueryPlayerById(userId)
|
||||
if err != nil {
|
||||
logger.Error("query player error: %v", err)
|
||||
return nil
|
||||
return nil, err
|
||||
}
|
||||
return player
|
||||
return player, nil
|
||||
}
|
||||
|
||||
func (u *UserManager) SaveUserToDbSync(player *model.Player) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
)
|
||||
|
||||
var cmdProtoMap *cmd.CmdProtoMap = nil
|
||||
var attackResultTemplate *proto.AttackResult = nil
|
||||
|
||||
func DoForward[IET model.InvokeEntryType](player *model.Player, invokeHandler *model.InvokeHandler[IET],
|
||||
cmdId uint16, newNtf pb.Message, forwardField string,
|
||||
@@ -142,6 +143,9 @@ func (g *Game) handleEvtBeingHit(player *model.Player, scene *Scene, hitInfo *pr
|
||||
logger.Error("attackResult is nil")
|
||||
return
|
||||
}
|
||||
if attackResultTemplate == nil {
|
||||
attackResultTemplate = attackResult
|
||||
}
|
||||
defEntity := scene.GetEntity(attackResult.DefenseId)
|
||||
if defEntity == nil {
|
||||
logger.Error("not found def entity, DefenseId: %v", attackResult.DefenseId)
|
||||
|
||||
@@ -75,7 +75,12 @@ func (g *Game) SetPlayerBornDataReq(player *model.Player, payloadMsg pb.Message)
|
||||
g.SendMsg(cmd.SetPlayerBornDataRsp, player.PlayerId, player.ClientSeq, new(proto.SetPlayerBornDataRsp))
|
||||
}
|
||||
|
||||
func (g *Game) OnLogin(userId uint32, clientSeq uint32, gateAppId string, player *model.Player, joinHostUserId uint32) {
|
||||
func (g *Game) OnLogin(userId uint32, clientSeq uint32, gateAppId string, player *model.Player, joinHostUserId uint32, ok bool) {
|
||||
if !ok {
|
||||
g.SendMsgToGate(cmd.PlayerLoginRsp, userId, clientSeq, gateAppId, &proto.PlayerLoginRsp{Retcode: int32(proto.Retcode_RET_LOGIN_INIT_FAIL)})
|
||||
return
|
||||
}
|
||||
|
||||
if player == nil {
|
||||
player = g.CreatePlayer(userId)
|
||||
USER_MANAGER.ChangeUserDbState(player, model.DbInsert)
|
||||
|
||||
+19
-16
@@ -410,23 +410,26 @@ func (g *Game) PostEnterSceneReq(player *model.Player, payloadMsg pb.Message) {
|
||||
}
|
||||
g.SendMsg(cmd.PostEnterSceneRsp, player.PlayerId, player.ClientSeq, postEnterSceneRsp)
|
||||
|
||||
// 开启live版本客户端的GM按钮 虽然没什么卵用
|
||||
// local btnGm = CS.UnityEngine.GameObject.Find("/Canvas/Pages/InLevelMainPage/GrpMainPage/GrpMainBtn/GrpMainToggle/GrpTopPanel/BtnGm")
|
||||
// btnGm:SetActive(true)
|
||||
luac, err := base64.StdEncoding.DecodeString("G0x1YVMBGZMNChoKBAQICHhWAAAAAAAAAAAAAAAod0ABCEBnbS5sdWEAAAAAAAAAAAABBAoAAAAkAEAAKUBAACmAQAApwEAAVgABACyAAAFdQEEA2ACAAGxAgAEZAIAABgAAAAQDQ1MEDFVuaXR5RW5naW5lBAtHYW1lT2JqZWN0BAVGaW5kFFUvQ2FudmFzL1BhZ2VzL0luTGV2ZWxNYWluUGFnZS9HcnBNYWluUGFnZS9HcnBNYWluQnRuL0dycE1haW5Ub2dnbGUvR3JwVG9wUGFuZWwvQnRuR20EClNldEFjdGl2ZQEAAAABAAAAAAAKAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAgAAAAIAAAACAAAAAgAAAAEAAAAGYnRuR20GAAAACgAAAAEAAAAFX0VOVg==")
|
||||
if err != nil {
|
||||
logger.Error("decode luac error: %v", err)
|
||||
return
|
||||
if WORLD_MANAGER.IsAiWorld(world) {
|
||||
// 开启GM按钮 隐藏多人世界玩家位置地图标记
|
||||
// local btnGm = CS.UnityEngine.GameObject.Find("/Canvas/Pages/InLevelMainPage/GrpMainPage/GrpMainBtn/GrpMainToggle/GrpTopPanel/BtnGm")
|
||||
// btnGm:SetActive(true)
|
||||
// local miniMapMarkLayer3 = CS.UnityEngine.GameObject.Find("/Canvas/Pages/InLevelMainPage/GrpMainPage/MapInfo/GrpMiniMap/GrpMap/MarkContainer/Layer3")
|
||||
// miniMapMarkLayer3:SetActive(false)
|
||||
// local mapMarkLayer3 = CS.UnityEngine.GameObject.Find("/Canvas/Pages/InLevelMapPage/GrpMap/MarkContainer/Layer3")
|
||||
// mapMarkLayer3:SetActive(false)
|
||||
luac, err := base64.StdEncoding.DecodeString("G0x1YVMBGZMNChoKBAQICHhWAAAAAAAAAAAAAAAod0ABDkBhaV93b3JsZC5sdWEAAAAAAAAAAAABBhwAAAAkAEAAKUBAACmAQAApwEAAVgABACyAAAFdQEEA2ACAAGxAgAFkAEAAaUDAAGmAwABpwMAAloABAGyAAAGdQMEAGAEAAKxAgAGkAEAAqUBAAamAQAGpwEAB1sABAKyAAAHdQEEBWAEAAOxAgAEZAIAACAAAAAQDQ1MEDFVuaXR5RW5naW5lBAtHYW1lT2JqZWN0BAVGaW5kFFUvQ2FudmFzL1BhZ2VzL0luTGV2ZWxNYWluUGFnZS9HcnBNYWluUGFnZS9HcnBNYWluQnRuL0dycE1haW5Ub2dnbGUvR3JwVG9wUGFuZWwvQnRuR20EClNldEFjdGl2ZRRZL0NhbnZhcy9QYWdlcy9JbkxldmVsTWFpblBhZ2UvR3JwTWFpblBhZ2UvTWFwSW5mby9HcnBNaW5pTWFwL0dycE1hcC9NYXJrQ29udGFpbmVyL0xheWVyMxQ5L0NhbnZhcy9QYWdlcy9JbkxldmVsTWFwUGFnZS9HcnBNYXAvTWFya0NvbnRhaW5lci9MYXllcjMBAAAAAQAAAAAAHAAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAIAAAACAAAAAgAAAAMAAAADAAAAAwAAAAMAAAADAAAAAwAAAAQAAAAEAAAABAAAAAUAAAAFAAAABQAAAAUAAAAFAAAABQAAAAYAAAAGAAAABgAAAAYAAAADAAAABmJ0bkdtBgAAABwAAAASbWluaU1hcE1hcmtMYXllcjMPAAAAHAAAAA5tYXBNYXJrTGF5ZXIzGAAAABwAAAABAAAABV9FTlY=")
|
||||
if err != nil {
|
||||
logger.Error("decode luac error: %v", err)
|
||||
return
|
||||
}
|
||||
g.SendMsg(cmd.PlayerLuaShellNotify, player.PlayerId, 0, &proto.PlayerLuaShellNotify{
|
||||
ShellType: proto.LuaShellType_LUASHELL_NORMAL,
|
||||
Id: 1,
|
||||
LuaShell: luac,
|
||||
UseType: 1,
|
||||
})
|
||||
}
|
||||
GAME.SendMsg(cmd.WindSeedClientNotify, player.PlayerId, 0, &proto.WindSeedClientNotify{
|
||||
Notify: &proto.WindSeedClientNotify_AreaNotify_{
|
||||
AreaNotify: &proto.WindSeedClientNotify_AreaNotify{
|
||||
AreaCode: luac,
|
||||
AreaId: 1,
|
||||
AreaType: 1,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (g *Game) SceneEntityDrownReq(player *model.Player, payloadMsg pb.Message) {
|
||||
|
||||
@@ -64,6 +64,7 @@ func (c *CmdProtoMap) registerMessage() {
|
||||
c.regMsg(PlayerTimeNotify, func() any { return new(proto.PlayerTimeNotify) }) // 玩家累计在线时长通知
|
||||
c.regMsg(ServerTimeNotify, func() any { return new(proto.ServerTimeNotify) }) // 服务器时间通知
|
||||
c.regMsg(WindSeedClientNotify, func() any { return new(proto.WindSeedClientNotify) }) // 客户端XLUA调试通知
|
||||
c.regMsg(PlayerLuaShellNotify, func() any { return new(proto.PlayerLuaShellNotify) }) // 客户端XLUA调试通知
|
||||
c.regMsg(ServerAnnounceNotify, func() any { return new(proto.ServerAnnounceNotify) }) // 服务器公告通知
|
||||
c.regMsg(ServerAnnounceRevokeNotify, func() any { return new(proto.ServerAnnounceRevokeNotify) }) // 服务器公告撤销通知
|
||||
c.regMsg(TowerAllDataReq, func() any { return new(proto.TowerAllDataReq) }) // 深渊数据请求
|
||||
|
||||
Reference in new issue
Block a user