From ea069c705c4bcc2d261eb4e166fe4c16a5fb3298 Mon Sep 17 00:00:00 2001 From: flswld Date: Sun, 12 Mar 2023 16:36:10 +0800 Subject: [PATCH] =?UTF-8?q?GM=E5=AE=A2=E6=88=B7=E7=AB=AFXLUA=E8=B0=83?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gs/game/command_controller.go | 30 +++++------------- gs/game/command_gm.go | 46 ++++++++++++++++++++++++++++ gs/game/command_manager.go | 19 +++++++++--- gs/game/user_manager.go | 2 +- gs/model/player.go | 3 +- protocol/cmd/cmd_id_proto_obj_map.go | 1 + 6 files changed, 71 insertions(+), 30 deletions(-) diff --git a/gs/game/command_controller.go b/gs/game/command_controller.go index 5284dd4c..9d071837 100644 --- a/gs/game/command_controller.go +++ b/gs/game/command_controller.go @@ -18,18 +18,6 @@ func (c *CommandManager) HelpCommand(cmd *CommandMessage) { ) } -// OpCommand 给予权限命令 -func (c *CommandManager) OpCommand(cmd *CommandMessage) { - player, ok := cmd.Executor.(*model.Player) - if !ok { - c.SendMessage(cmd.Executor, "只有玩家才能执行此命令。") - return - } - - player.IsGM = 1 - c.SendMessage(cmd.Executor, "权限修改完毕,现在你是GM啦~") -} - // TeleportCommand 传送玩家命令 // tp [--u ] [--s ] {--t --x | --y | --z } func (c *CommandManager) TeleportCommand(cmd *CommandMessage) { @@ -336,20 +324,16 @@ func (c *CommandManager) GiveCommand(cmd *CommandMessage) { } } -// ReloadConfigCommand 帮助命令 -func (c *CommandManager) ReloadConfigCommand(cmd *CommandMessage) { - LOCAL_EVENT_MANAGER.GetLocalEventChan() <- &LocalEvent{ - EventId: ReloadGameDataConfig, - } - - c.SendMessage(cmd.Executor, "成功发送重载配置请求。") -} - // GcgCommand Gcg测试命令 func (c *CommandManager) GcgCommand(cmd *CommandMessage) { player := cmd.Executor.(*model.Player) - GAME_MANAGER.GCGStartChallenge(player) - c.SendMessage(cmd.Executor, "收到命令") } + +// XLuaDebugCommand 主动开启客户端XLUA调试命令 +func (c *CommandManager) XLuaDebugCommand(cmd *CommandMessage) { + player := cmd.Executor.(*model.Player) + player.XLuaDebug = true + c.SendMessage(cmd.Executor, "XLua Debug Enable") +} diff --git a/gs/game/command_gm.go b/gs/game/command_gm.go index f193046f..6dd04383 100644 --- a/gs/game/command_gm.go +++ b/gs/game/command_gm.go @@ -1,9 +1,12 @@ package game import ( + "encoding/base64" + "hk4e/gdconf" "hk4e/gs/model" "hk4e/pkg/logger" + "hk4e/protocol/cmd" "hk4e/protocol/proto" ) @@ -135,3 +138,46 @@ func (c *CommandManager) GMAddUserAllEvery(userId uint32, itemCount uint32, weap // 给予玩家所有风之翼 c.GMAddUserAllFlycloak(userId) } + +func (c *CommandManager) ChangePlayerCmdPerm(userId uint32, cmdPerm uint8) { + player := USER_MANAGER.GetOnlineUser(userId) + if player == nil { + logger.Error("player is nil, uid: %v", userId) + return + } + player.CmdPerm = cmdPerm +} + +func (c *CommandManager) ReloadGameDataConfig() { + LOCAL_EVENT_MANAGER.GetLocalEventChan() <- &LocalEvent{ + EventId: ReloadGameDataConfig, + } +} + +func (c *CommandManager) XLuaDebug(userId uint32, luacBase64 string) { + logger.Debug("xlua debug, uid: %v, luac: %v", userId, luacBase64) + player := USER_MANAGER.GetOnlineUser(userId) + if player == nil { + logger.Error("player is nil, uid: %v", userId) + return + } + // 只有在线玩家主动开启之后才能发送 + if !player.XLuaDebug { + logger.Error("player xlua debug not enable, uid: %v", userId) + return + } + luac, err := base64.StdEncoding.DecodeString(luacBase64) + if err != nil { + logger.Error("decode luac error: %v", err) + return + } + GAME_MANAGER.SendMsg(cmd.WindSeedClientNotify, player.PlayerID, 0, &proto.WindSeedClientNotify{ + Notify: &proto.WindSeedClientNotify_AreaNotify_{ + AreaNotify: &proto.WindSeedClientNotify_AreaNotify{ + AreaCode: luac, + AreaId: 1, + AreaType: 1, + }, + }, + }) +} diff --git a/gs/game/command_manager.go b/gs/game/command_manager.go index 844c6464..72ee46eb 100644 --- a/gs/game/command_manager.go +++ b/gs/game/command_manager.go @@ -2,6 +2,7 @@ package game import ( "fmt" + "strconv" "strings" "hk4e/gs/model" @@ -68,15 +69,14 @@ func (c *CommandManager) InitRouter() { { // 权限等级 0: 普通玩家 c.RegisterRouter(CommandPermNormal, c.HelpCommand, "help") - c.RegisterRouter(CommandPermNormal, c.OpCommand, "op") c.RegisterRouter(CommandPermNormal, c.TeleportCommand, "teleport", "tp") c.RegisterRouter(CommandPermNormal, c.GiveCommand, "give", "item") // c.RegisterRouter(CommandPermNormal, c.GcgCommand, "gcg") + c.RegisterRouter(CommandPermNormal, c.XLuaDebugCommand, "xluadebug") } // GM命令 { // 权限等级 1: GM 1级 - c.RegisterRouter(CommandPermGM, c.ReloadConfigCommand, "reloadconfig") } } @@ -134,6 +134,15 @@ func (c *CommandManager) HandleCommand(cmd *CommandMessage) { if cmd.FuncName != "" { logger.Info("run gm cmd, FuncName: %v, Param: %v", cmd.FuncName, cmd.Param) // TODO 反射调用command_gm.go中的函数并反射解析传入参数类型 + if cmd.FuncName == "ReloadGameDataConfig" && len(cmd.Param) == 0 { + c.ReloadGameDataConfig() + } else if cmd.FuncName == "XLuaDebug" && len(cmd.Param) == 2 { + uid, err := strconv.Atoi(cmd.Param[0]) + if err != nil { + return + } + c.XLuaDebug(uint32(uid), cmd.Param[1]) + } return } @@ -217,9 +226,9 @@ func (c *CommandManager) ExecCommand(cmd *CommandMessage) { // 判断玩家的权限是否符合要求 player, ok := executor.(*model.Player) - if ok && player.IsGM < uint8(cmdPerm) { - logger.Debug("exec command permission denied, uid: %v, isGM: %v", player.PlayerID, player.IsGM) - c.SendMessage(player, "权限不足,该命令需要%v级权限。\n你目前的权限等级:%v", cmdPerm, player.IsGM) + if ok && player.CmdPerm < uint8(cmdPerm) { + logger.Debug("exec command permission denied, uid: %v, CmdPerm: %v", player.PlayerID, player.CmdPerm) + c.SendMessage(player, "权限不足,该命令需要%v级权限。\n你目前的权限等级:%v", cmdPerm, player.CmdPerm) return } diff --git a/gs/game/user_manager.go b/gs/game/user_manager.go index 0a874fec..b306b531 100644 --- a/gs/game/user_manager.go +++ b/gs/game/user_manager.go @@ -149,7 +149,7 @@ func (u *UserManager) OnlineUser(userId uint32, clientSeq uint32, gateAppId stri u.SaveUserToRedisSync(player) } // 解离线玩家数据分布式锁 - u.dao.DistUnlock(player.PlayerID) + u.dao.DistUnlock(userId) if player != nil { u.ChangeUserDbState(player, model.DbNormal) player.ChatMsgMap = u.LoadUserChatMsgFromDbSync(userId) diff --git a/gs/model/player.go b/gs/model/player.go index e9842af5..6db3414a 100644 --- a/gs/model/player.go +++ b/gs/model/player.go @@ -42,7 +42,7 @@ type Player struct { FlyCloakList []uint32 // 风之翼列表 CostumeList []uint32 // 角色衣装列表 SceneId uint32 // 场景 - IsGM uint8 // 管理员权限等级 + CmdPerm uint8 // 玩家命令权限等级 SafePos *Vector // 在陆地时的坐标 Pos *Vector // 坐标 Rot *Vector // 朝向 @@ -78,6 +78,7 @@ type Player struct { FightAppId string `bson:"-" msgpack:"-"` // 战斗服务器的appid GCGCurGameGuid uint32 `bson:"-" msgpack:"-"` // GCG玩家所在的游戏guid GCGInfo *GCGInfo `bson:"-" msgpack:"-"` // 七圣召唤信息 + XLuaDebug bool `bson:"-" msgpack:"-"` // 是否开启客户端XLUA调试 // 特殊数据 ChatMsgMap map[uint32][]*ChatMsg `bson:"-" msgpack:"-"` // 聊天信息 数据量偏大 只从db读写 不保存到redis } diff --git a/protocol/cmd/cmd_id_proto_obj_map.go b/protocol/cmd/cmd_id_proto_obj_map.go index b258ad34..85979018 100644 --- a/protocol/cmd/cmd_id_proto_obj_map.go +++ b/protocol/cmd/cmd_id_proto_obj_map.go @@ -52,6 +52,7 @@ func (c *CmdProtoMap) registerAllMessage() { c.registerMessage(OpenStateUpdateNotify, &proto.OpenStateUpdateNotify{}) // 游戏功能模块开放状态更新通知 c.registerMessage(PlayerTimeNotify, &proto.PlayerTimeNotify{}) // 玩家累计在线时长通知 c.registerMessage(ServerTimeNotify, &proto.ServerTimeNotify{}) // 服务器时间通知 + c.registerMessage(WindSeedClientNotify, &proto.WindSeedClientNotify{}) // 客户端XLUA调试通知 // 场景 c.registerMessage(PlayerSetPauseReq, &proto.PlayerSetPauseReq{}) // 玩家暂停请求