Scripts/Commands: Convert argument parsing of gm commands to new system

Port From (https://github.com/TrinityCore/TrinityCore/commit/3ba767c438f2def1d619eda34c6b843c29ebc518)
This commit is contained in:
hondacrx
2022-06-04 10:20:41 -04:00
parent 611afb43a7
commit a3ced0dc9c
+33 -55
View File
@@ -26,43 +26,39 @@ namespace Game.Chat
class GMCommands class GMCommands
{ {
[Command("", RBACPermissions.CommandGm)] [Command("", RBACPermissions.CommandGm)]
static bool HandleGMCommand(CommandHandler handler, StringArguments args) static bool HandleGMCommand(CommandHandler handler, bool? enableArg)
{ {
Player _player = handler.GetSession().GetPlayer(); Player _player = handler.GetSession().GetPlayer();
if (args.Empty()) if (!enableArg.HasValue)
{ {
handler.SendNotification(_player.IsGameMaster() ? CypherStrings.GmOn : CypherStrings.GmOff); handler.SendNotification(_player.IsGameMaster() ? CypherStrings.GmOn : CypherStrings.GmOff);
return true; return true;
} }
string param = args.NextString(); if (enableArg.Value)
if (param == "on")
{ {
_player.SetGameMaster(true); _player.SetGameMaster(true);
handler.SendNotification(CypherStrings.GmOn); handler.SendNotification(CypherStrings.GmOn);
_player.UpdateTriggerVisibility(); _player.UpdateTriggerVisibility();
return true;
} }
if (param == "off") else
{ {
_player.SetGameMaster(false); _player.SetGameMaster(false);
handler.SendNotification(CypherStrings.GmOff); handler.SendNotification(CypherStrings.GmOff);
_player.UpdateTriggerVisibility(); _player.UpdateTriggerVisibility();
return true;
} }
handler.SendSysMessage(CypherStrings.UseBol); return true;
return false;
} }
[Command("chat", RBACPermissions.CommandGmChat)] [Command("chat", RBACPermissions.CommandGmChat)]
static bool HandleGMChatCommand(CommandHandler handler, StringArguments args) static bool HandleGMChatCommand(CommandHandler handler, bool? enableArg)
{ {
WorldSession session = handler.GetSession(); WorldSession session = handler.GetSession();
if (session != null) if (session != null)
{ {
if (args.Empty()) if (!enableArg.HasValue)
{ {
if (session.HasPermission(RBACPermissions.ChatUseStaffBadge) && session.GetPlayer().IsGMChat()) if (session.HasPermission(RBACPermissions.ChatUseStaffBadge) && session.GetPlayer().IsGMChat())
session.SendNotification(CypherStrings.GmChatOn); session.SendNotification(CypherStrings.GmChatOn);
@@ -71,21 +67,18 @@ namespace Game.Chat
return true; return true;
} }
string param = args.NextString(); if (enableArg.HasValue)
if (param == "on")
{ {
session.GetPlayer().SetGMChat(true); session.GetPlayer().SetGMChat(true);
session.SendNotification(CypherStrings.GmChatOn); session.SendNotification(CypherStrings.GmChatOn);
return true;
} }
else
if (param == "off")
{ {
session.GetPlayer().SetGMChat(false); session.GetPlayer().SetGMChat(false);
session.SendNotification(CypherStrings.GmChatOff); session.SendNotification(CypherStrings.GmChatOff);
return true;
} }
return true;
} }
handler.SendSysMessage(CypherStrings.UseBol); handler.SendSysMessage(CypherStrings.UseBol);
@@ -93,50 +86,40 @@ namespace Game.Chat
} }
[Command("fly", RBACPermissions.CommandGmFly)] [Command("fly", RBACPermissions.CommandGmFly)]
static bool HandleGMFlyCommand(CommandHandler handler, StringArguments args) static bool HandleGMFlyCommand(CommandHandler handler, bool enable)
{ {
if (args.Empty())
return false;
Player target = handler.GetSelectedPlayer(); Player target = handler.GetSelectedPlayer();
if (target == null) if (target == null)
target = handler.GetPlayer(); target = handler.GetPlayer();
string arg = args.NextString().ToLower(); if (enable)
if (arg == "on")
{ {
target.SetCanFly(true); target.SetCanFly(true);
target.SetCanTransitionBetweenSwimAndFly(true); target.SetCanTransitionBetweenSwimAndFly(true);
} }
else if (arg == "off") else
{ {
target.SetCanFly(false); target.SetCanFly(false);
target.SetCanTransitionBetweenSwimAndFly(false); target.SetCanTransitionBetweenSwimAndFly(false);
} }
else
{ handler.SendSysMessage(CypherStrings.CommandFlymodeStatus, handler.GetNameLink(target), enable ? "on" : "off");
handler.SendSysMessage(CypherStrings.UseBol);
return false;
}
handler.SendSysMessage(CypherStrings.CommandFlymodeStatus, handler.GetNameLink(target), arg);
return true; return true;
} }
[Command("ingame", RBACPermissions.CommandGmIngame, true)] [Command("ingame", RBACPermissions.CommandGmIngame, true)]
static bool HandleGMListIngameCommand(CommandHandler handler, StringArguments args) static bool HandleGMListIngameCommand(CommandHandler handler)
{ {
bool first = true; bool first = true;
bool footer = false; bool footer = false;
var m = Global.ObjAccessor.GetPlayers(); foreach (var player in Global.ObjAccessor.GetPlayers())
foreach (var pl in m)
{ {
AccountTypes accountType = pl.GetSession().GetSecurity(); AccountTypes playerSec = player.GetSession().GetSecurity();
if ((pl.IsGameMaster() || if ((player.IsGameMaster() ||
(pl.GetSession().HasPermission(RBACPermissions.CommandsAppearInGmList) && (player.GetSession().HasPermission(RBACPermissions.CommandsAppearInGmList) &&
accountType <= (AccountTypes)WorldConfig.GetIntValue(WorldCfg.GmLevelInGmList))) && playerSec <= (AccountTypes)WorldConfig.GetIntValue(WorldCfg.GmLevelInGmList))) &&
(handler.GetSession() == null || pl.IsVisibleGloballyFor(handler.GetSession().GetPlayer()))) (handler.GetSession() == null || player.IsVisibleGloballyFor(handler.GetSession().GetPlayer())))
{ {
if (first) if (first)
{ {
@@ -145,16 +128,16 @@ namespace Game.Chat
handler.SendSysMessage(CypherStrings.GmsOnSrv); handler.SendSysMessage(CypherStrings.GmsOnSrv);
handler.SendSysMessage("========================"); handler.SendSysMessage("========================");
} }
int size = pl.GetName().Length; int size = player.GetName().Length;
byte security = (byte)accountType; byte security = (byte)playerSec;
int max = ((16 - size) / 2); int max = ((16 - size) / 2);
int max2 = max; int max2 = max;
if ((max + max2 + size) == 16) if ((max + max2 + size) == 16)
max2 = max - 1; max2 = max - 1;
if (handler.GetSession() != null) if (handler.GetSession() != null)
handler.SendSysMessage("| {0} GMLevel {1}", pl.GetName(), security); handler.SendSysMessage("| {0} GMLevel {1}", player.GetName(), security);
else else
handler.SendSysMessage("|{0}{1}{2}| {3} |", max, " ", pl.GetName(), max2, " ", security); handler.SendSysMessage("|{0}{1}{2}| {3} |", max, " ", player.GetName(), max2, " ", security);
} }
} }
if (footer) if (footer)
@@ -165,7 +148,7 @@ namespace Game.Chat
} }
[Command("list", RBACPermissions.CommandGmList, true)] [Command("list", RBACPermissions.CommandGmList, true)]
static bool HandleGMListFullCommand(CommandHandler handler, StringArguments args) static bool HandleGMListFullCommand(CommandHandler handler)
{ {
// Get the accounts with GM Level >0 // Get the accounts with GM Level >0
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_GM_ACCOUNTS); PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_GM_ACCOUNTS);
@@ -200,20 +183,19 @@ namespace Game.Chat
} }
[Command("visible", RBACPermissions.CommandGmVisible)] [Command("visible", RBACPermissions.CommandGmVisible)]
static bool HandleGMVisibleCommand(CommandHandler handler, StringArguments args) static bool HandleGMVisibleCommand(CommandHandler handler, bool? visibleArg)
{ {
Player _player = handler.GetSession().GetPlayer(); Player _player = handler.GetSession().GetPlayer();
if (args.Empty()) if (!visibleArg.HasValue)
{ {
handler.SendSysMessage(CypherStrings.YouAre, _player.IsGMVisible() ? Global.ObjectMgr.GetCypherString(CypherStrings.Visible) : Global.ObjectMgr.GetCypherString(CypherStrings.Invisible)); handler.SendSysMessage(CypherStrings.YouAre, _player.IsGMVisible() ? Global.ObjectMgr.GetCypherString(CypherStrings.Visible) : Global.ObjectMgr.GetCypherString(CypherStrings.Invisible));
return true; return true;
} }
uint VISUAL_AURA = 37800; uint VISUAL_AURA = 37800;
string param = args.NextString();
if (param == "on") if (visibleArg.Value)
{ {
if (_player.HasAura(VISUAL_AURA, ObjectGuid.Empty)) if (_player.HasAura(VISUAL_AURA, ObjectGuid.Empty))
_player.RemoveAurasDueToSpell(VISUAL_AURA); _player.RemoveAurasDueToSpell(VISUAL_AURA);
@@ -221,20 +203,16 @@ namespace Game.Chat
_player.SetGMVisible(true); _player.SetGMVisible(true);
_player.UpdateObjectVisibility(); _player.UpdateObjectVisibility();
handler.GetSession().SendNotification(CypherStrings.InvisibleVisible); handler.GetSession().SendNotification(CypherStrings.InvisibleVisible);
return true;
} }
else
if (param == "off")
{ {
_player.AddAura(VISUAL_AURA, _player); _player.AddAura(VISUAL_AURA, _player);
_player.SetGMVisible(false); _player.SetGMVisible(false);
_player.UpdateObjectVisibility(); _player.UpdateObjectVisibility();
handler.GetSession().SendNotification(CypherStrings.InvisibleInvisible); handler.GetSession().SendNotification(CypherStrings.InvisibleInvisible);
return true;
} }
handler.SendSysMessage(CypherStrings.UseBol); return true;
return false;
} }
} }
} }