GM客户端XLUA调试

This commit is contained in:
flswld
2023-03-12 16:36:10 +08:00
parent 8c1dedc472
commit ea069c705c
6 changed files with 71 additions and 30 deletions

View File

@@ -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 <uid>] [--s <sceneId>] {--t <targetUid> --x <posX> | --y <posY> | --z <posZ>}
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")
}

View File

@@ -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,
},
},
})
}

View File

@@ -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
}

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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{}) // 玩家暂停请求