From 346462b0fb5c159c881e9c7d79db4dd65083179f Mon Sep 17 00:00:00 2001 From: flswld Date: Wed, 15 Nov 2023 19:13:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gate/net/kcp_conn_manager.go | 10 ++++----- gate/net/session.go | 34 ++++++++++++------------------ gs/game/game_command_controller.go | 11 +++++++++- gs/game/game_command_gm.go | 15 +++++++++++-- gs/game/player_reliquary.go | 2 +- gs/game/player_scene.go | 2 ++ gs/model/db_reliquary.go | 2 +- 7 files changed, 45 insertions(+), 31 deletions(-) diff --git a/gate/net/kcp_conn_manager.go b/gate/net/kcp_conn_manager.go index cdc8795b..e174d4c4 100644 --- a/gate/net/kcp_conn_manager.go +++ b/gate/net/kcp_conn_manager.go @@ -561,18 +561,18 @@ func (k *KcpConnManager) closeAllKcpConn() { logger.Info("all conn has been force close") } -// 强制关闭指定连接 -func (k *KcpConnManager) forceCloseKcpConn(sessionId uint32, reason uint32) { +// 关闭指定连接 +func (k *KcpConnManager) closeKcpConnBySessionId(sessionId uint32, reason uint32) { session := k.GetSession(sessionId) if session == nil { logger.Error("session not exist, sessionId: %v", sessionId) return } k.closeKcpConn(session, reason) - logger.Info("conn has been force close, sessionId: %v", sessionId) + logger.Info("conn has been close, sessionId: %v", sessionId) } -// 关闭指定连接 +// 关闭连接 func (k *KcpConnManager) closeKcpConn(session *Session, enetType uint32) { if session.connState == ConnClose { return @@ -608,7 +608,7 @@ func (k *KcpConnManager) closeKcpConn(session *Session, enetType uint32) { EventId: mq.UserOfflineNotify, ConnCtrlMsg: connCtrlMsg, }) - logger.Info("send to gs user offline, SessionId: %v, UserId: %v", session.sessionId, connCtrlMsg.UserId) + logger.Info("send to gs user offline, sessionId: %v, uid: %v", session.sessionId, connCtrlMsg.UserId) k.destroySessionChan <- session } else { k.messageQueue.SendToRobot(session.robotServerAppId, &mq.NetMsg{ diff --git a/gate/net/session.go b/gate/net/session.go index 4d0946b6..50fa4f35 100644 --- a/gate/net/session.go +++ b/gate/net/session.go @@ -71,16 +71,8 @@ func (k *KcpConnManager) forwardClientMsgToServerHandle(protoMsg *ProtoMsg, sess if session.connState != ConnActive { return } - // 返回数据到客户端 - rsp := new(proto.PlayerForceExitRsp) - msg := &ProtoMsg{ - SessionId: protoMsg.SessionId, - CmdId: cmd.PlayerForceExitRsp, - HeadMessage: k.getHeadMsg(protoMsg.HeadMessage.ClientSequenceId), - PayloadMessage: rsp, - } - session.sendChan <- msg - k.forceCloseKcpConn(protoMsg.SessionId, kcp.EnetClientClose) + // 关闭连接 + k.closeKcpConnBySessionId(protoMsg.SessionId, kcp.EnetClientClose) case cmd.PlayerLoginReq: // GS登录包 if session.connState != ConnWaitLogin { @@ -103,7 +95,7 @@ func (k *KcpConnManager) forwardClientMsgToServerHandle(protoMsg *ProtoMsg, sess }) default: if session.connState != ConnActive { - logger.Error("conn not active so drop packet, cmdId: %v, userId: %v, sessionId: %v", + logger.Error("conn not active so drop packet, cmdId: %v, uid: %v, sessionId: %v", protoMsg.CmdId, session.userId, protoMsg.SessionId) return } @@ -204,7 +196,7 @@ func (k *KcpConnManager) gameMsgHandle( // 分发到每个连接具体的发送协程 sessionId, exist := userIdSessionIdMap[gameMsg.UserId] if !exist { - logger.Error("can not find sessionId by userId: %v, cmdId: %v", gameMsg.UserId, gameMsg.CmdId) + logger.Error("can not find sessionId by uid: %v, cmdId: %v", gameMsg.UserId, gameMsg.CmdId) return } protoMsg := &ProtoMsg{ @@ -221,11 +213,6 @@ func (k *KcpConnManager) gameMsgHandle( if session.connState == ConnClose { return } - if len(session.sendChan) == SessionSendChanLen { - logger.Error("session send chan is full, sessionId: %v", protoMsg.SessionId) - k.forceCloseKcpConn(sessionId, kcp.EnetWaitSndMax) - return - } if protoMsg.CmdId == cmd.PlayerLoginRsp { rsp := protoMsg.PayloadMessage.(*proto.PlayerLoginRsp) if rsp.Retcode == 0 { @@ -243,6 +230,11 @@ func (k *KcpConnManager) gameMsgHandle( }) } } + if len(session.sendChan) == SessionSendChanLen { + logger.Error("session send chan is full, sessionId: %v", protoMsg.SessionId) + k.closeKcpConnBySessionId(sessionId, kcp.EnetWaitSndMax) + return + } session.sendChan <- protoMsg } } @@ -256,10 +248,10 @@ func (k *KcpConnManager) connCtrlMsgHandle( case mq.KickPlayerNotify: sessionId, exist := userIdSessionIdMap[connCtrlMsg.KickUserId] if !exist { - logger.Error("can not find sessionId by userId") + logger.Error("can not find sessionId by uid: %v", connCtrlMsg.KickUserId) return } - k.forceCloseKcpConn(sessionId, connCtrlMsg.KickReason) + k.closeKcpConnBySessionId(sessionId, connCtrlMsg.KickReason) } } @@ -273,7 +265,7 @@ func (k *KcpConnManager) serverMsgHandle( case mq.ServerUserGsChangeNotify: sessionId, exist := userIdSessionIdMap[serverMsg.UserId] if !exist { - logger.Error("can not find sessionId by userId") + logger.Error("can not find sessionId by uid: %v", serverMsg.UserId) return } session := sessionMap[sessionId] @@ -562,7 +554,7 @@ func (k *KcpConnManager) doGateLogin(req *proto.GetPlayerTokenReq, session *Sess oldSession := k.GetSessionByUserId(uid) if oldSession != nil { // 本地顶号 - k.forceCloseKcpConn(oldSession.sessionId, kcp.EnetServerRelogin) + k.closeKcpConnBySessionId(oldSession.sessionId, kcp.EnetServerRelogin) } else { // 远程顶号 connCtrlMsg := new(mq.ConnCtrlMsg) diff --git a/gs/game/game_command_controller.go b/gs/game/game_command_controller.go index bc991ca6..8981fa47 100644 --- a/gs/game/game_command_controller.go +++ b/gs/game/game_command_controller.go @@ -261,7 +261,7 @@ func (c *CommandManager) JumpCommand(content *CommandContent) bool { }) } -// 管理武器命令 +// 管理装备命令 func (c *CommandManager) NewEquipCommandController() *CommandController { return &CommandController{ @@ -270,6 +270,7 @@ func (c *CommandManager) NewEquipCommandController() *CommandController { Description: "{alias} 装备", UsageList: []string{ "{alias} add <武器ID/圣遗物ID/all> [等级] [突破] [精炼] 添加武器/圣遗物", + "{alias} clear reliquary 清除全部圣遗物", }, Perm: CommandPermNormal, Func: c.EquipCommand, @@ -330,6 +331,14 @@ func (c *CommandManager) EquipCommand(content *CommandContent) bool { default: return false } + case "clear": + switch param1 { + case "reliquary": + c.gmCmd.GMClearReliquary(content.AssignPlayer.PlayerId) + content.SendSuccMessage(content.Executor, "已清除全部圣遗物,指定UID:%v。", content.AssignPlayer.PlayerId) + default: + return false + } default: return false } diff --git a/gs/game/game_command_gm.go b/gs/game/game_command_gm.go index 77518ad2..fd45453f 100644 --- a/gs/game/game_command_gm.go +++ b/gs/game/game_command_gm.go @@ -429,7 +429,7 @@ func (g *GMCmd) GMClearPlayer(userId uint32) { GAME.LogoutPlayer(userId) } -// GMClearItem 清除道具 +// GMClearItem 清除全部道具 func (g *GMCmd) GMClearItem(userId uint32) { player := USER_MANAGER.GetOnlineUser(userId) if player == nil { @@ -440,7 +440,18 @@ func (g *GMCmd) GMClearItem(userId uint32) { GAME.LogoutPlayer(userId) } -// GMClearQuest 清除任务 +// GMClearReliquary 清除全部圣遗物 +func (g *GMCmd) GMClearReliquary(userId uint32) { + player := USER_MANAGER.GetOnlineUser(userId) + if player == nil { + logger.Error("player is nil, uid: %v", userId) + return + } + player.DbReliquary = nil + GAME.LogoutPlayer(userId) +} + +// GMClearQuest 清除全部任务 func (g *GMCmd) GMClearQuest(userId uint32) { player := USER_MANAGER.GetOnlineUser(userId) if player == nil { diff --git a/gs/game/player_reliquary.go b/gs/game/player_reliquary.go index 3e6e0f69..48eca6ac 100644 --- a/gs/game/player_reliquary.go +++ b/gs/game/player_reliquary.go @@ -57,7 +57,7 @@ func (g *Game) ReliquaryUpgradeReq(player *model.Player, payloadMsg pb.Message) // TODO 暂时先瞎鸡巴强化 reliquary.Level += 1 reliquary.Exp += 100 - if reliquary.Level%5 == 0 { + if reliquary.Level == 5 || reliquary.Level == 9 || reliquary.Level == 13 || reliquary.Level == 17 || reliquary.Level == 21 { g.AppendReliquaryProp(reliquary, 1) } diff --git a/gs/game/player_scene.go b/gs/game/player_scene.go index e2cafe00..b466feb2 100644 --- a/gs/game/player_scene.go +++ b/gs/game/player_scene.go @@ -1176,6 +1176,7 @@ func (g *Game) CreateMonster(player *model.Player, pos *model.Vector, monsterId pos = g.GetPlayerPos(player) pos.X += random.GetRandomFloat64(1.0, 10.0) pos.Y += 1.0 + pos.Y = 0.0 pos.Z += random.GetRandomFloat64(1.0, 10.0) } rot := new(model.Vector) @@ -1216,6 +1217,7 @@ func (g *Game) CreateGadget(player *model.Player, pos *model.Vector, gadgetId ui pos = g.GetPlayerPos(player) pos.X += random.GetRandomFloat64(1.0, 10.0) pos.Y += 1.0 + pos.Y = 0.0 pos.Z += random.GetRandomFloat64(1.0, 10.0) } rot := new(model.Vector) diff --git a/gs/model/db_reliquary.go b/gs/model/db_reliquary.go index 00af5b79..251aa6f2 100644 --- a/gs/model/db_reliquary.go +++ b/gs/model/db_reliquary.go @@ -89,7 +89,7 @@ func (r *DbReliquary) AddReliquary(player *Player, itemId uint32, reliquaryId ui reliquary := &Reliquary{ ReliquaryId: reliquaryId, ItemId: itemId, - Level: 0, + Level: 1, Exp: 0, Promote: 0, Lock: false,