Core/Commands: More work on commands.

This commit is contained in:
hondacrx
2022-08-25 12:04:58 -04:00
parent 56d9dc6190
commit 6b54a6384d
15 changed files with 623 additions and 317 deletions
+6 -13
View File
@@ -87,7 +87,7 @@ namespace Game.Chat
}
[Command("create", CypherStrings.CommandAccCreateHelp, RBACPermissions.CommandAccountCreate, true)]
static bool HandleAccountCreateCommand(CommandHandler handler, string accountName, string password, OptionalArg<string> email)
static bool HandleAccountCreateCommand(CommandHandler handler, string accountName, string password, [OptionalArg]string email)
{
if (accountName.Contains("@"))
{
@@ -95,7 +95,7 @@ namespace Game.Chat
return false;
}
AccountOpResult result = Global.AccountMgr.CreateAccount(accountName, password, email.ValueOr(""));
AccountOpResult result = Global.AccountMgr.CreateAccount(accountName, password, email);
switch (result)
{
case AccountOpResult.Ok:
@@ -221,7 +221,7 @@ namespace Game.Chat
}
[Command("password", CypherStrings.CommandAccPasswordHelp, RBACPermissions.CommandAccountPassword)]
static bool HandleAccountPasswordCommand(CommandHandler handler, string oldPassword, string newPassword, string confirmPassword, string confirmEmail)
static bool HandleAccountPasswordCommand(CommandHandler handler, string oldPassword, string newPassword, string confirmPassword, [OptionalArg] string confirmEmail)
{
// First, we check config. What security type (sec type) is it ? Depending on it, the command branches out
uint pwConfig = WorldConfig.GetUIntValue(WorldCfg.AccPasschangesec); // 0 - PW_NONE, 1 - PW_EMAIL, 2 - PW_RBAC
@@ -441,7 +441,7 @@ namespace Game.Chat
class AccountSetCommands
{
[Command("addon", CypherStrings.CommandAccSetAddonHelp, RBACPermissions.CommandAccountSetAddon, true)]
static bool HandleAccountSetAddonCommand(CommandHandler handler, string accountName, byte expansion)
static bool HandleAccountSetAddonCommand(CommandHandler handler, [OptionalArg] string accountName, byte expansion)
{
uint accountId;
if (!accountName.IsEmpty())
@@ -486,12 +486,6 @@ namespace Game.Chat
return true;
}
[Command("gmlevel", CypherStrings.CommandAccSetSeclevelHelp, RBACPermissions.CommandAccountSetSecLevel, true)]
static bool HandleAccountSetGmLevelCommand(CommandHandler handler, string accountName, byte securityLevel, int realmId = -1)
{
return HandleAccountSetSecLevelCommand(handler, accountName, securityLevel, realmId);
}
[Command("password", CypherStrings.CommandAccSetPasswordHelp, RBACPermissions.CommandAccountSetPassword, true)]
static bool HandleAccountSetPasswordCommand(CommandHandler handler, string accountName, string password, string confirmPassword)
{
@@ -534,7 +528,8 @@ namespace Game.Chat
}
[Command("seclevel", CypherStrings.CommandAccSetSeclevelHelp, RBACPermissions.CommandAccountSetSecLevel, true)]
static bool HandleAccountSetSecLevelCommand(CommandHandler handler, string accountName, byte securityLevel, int? realmId)
[Command("gmlevel", CypherStrings.CommandAccSetSeclevelHelp, RBACPermissions.CommandAccountSetSecLevel, true)]
static bool HandleAccountSetSecLevelCommand(CommandHandler handler, [OptionalArg] string accountName, byte securityLevel, int? realmId)
{
uint accountId;
if (!accountName.IsEmpty())
@@ -698,7 +693,5 @@ namespace Game.Chat
}
}
}
}
}
@@ -156,7 +156,7 @@ namespace Game.Chat.Commands
handler.SendSysMessage("----------------------------------------------------");
do
{
handler.SendSysMessage("| {10:0} | {1} | {2} |", accountList.Read<uint>(0), accountList.Read<string>(1), formatDisplayName(accountList.Read<string>(1)));
handler.SendSysMessage("| {0,10} | {1,16} | {2,16} |", accountList.Read<uint>(0), accountList.Read<string>(1), formatDisplayName(accountList.Read<string>(1)));
} while (accountList.NextRow());
handler.SendSysMessage("----------------------------------------------------");
}
+6 -6
View File
@@ -27,7 +27,7 @@ namespace Game.Chat
class CastCommands
{
[Command("", RBACPermissions.CommandCast)]
static bool HandleCastCommand(CommandHandler handler, uint spellId, string triggeredStr)
static bool HandleCastCommand(CommandHandler handler, uint spellId, [OptionalArg] string triggeredStr)
{
Unit target = handler.GetSelectedUnit();
if (!target)
@@ -48,7 +48,7 @@ namespace Game.Chat
}
[Command("back", RBACPermissions.CommandCastBack)]
static bool HandleCastBackCommand(CommandHandler handler, uint spellId, string triggeredStr)
static bool HandleCastBackCommand(CommandHandler handler, uint spellId, [OptionalArg] string triggeredStr)
{
Creature caster = handler.GetSelectedCreature();
if (!caster)
@@ -70,7 +70,7 @@ namespace Game.Chat
}
[Command("dist", RBACPermissions.CommandCastDist)]
static bool HandleCastDistCommand(CommandHandler handler, uint spellId, float dist, string triggeredStr)
static bool HandleCastDistCommand(CommandHandler handler, uint spellId, float dist, [OptionalArg] string triggeredStr)
{
if (CheckSpellExistsAndIsValid(handler, spellId))
return false;
@@ -88,7 +88,7 @@ namespace Game.Chat
}
[Command("self", RBACPermissions.CommandCastSelf)]
static bool HandleCastSelfCommand(CommandHandler handler, uint spellId, string triggeredStr)
static bool HandleCastSelfCommand(CommandHandler handler, uint spellId, [OptionalArg] string triggeredStr)
{
Unit target = handler.GetSelectedUnit();
if (!target)
@@ -110,7 +110,7 @@ namespace Game.Chat
}
[Command("target", RBACPermissions.CommandCastTarget)]
static bool HandleCastTargetCommad(CommandHandler handler, uint spellId, string triggeredStr)
static bool HandleCastTargetCommad(CommandHandler handler, uint spellId, [OptionalArg] string triggeredStr)
{
Creature caster = handler.GetSelectedCreature();
if (!caster)
@@ -138,7 +138,7 @@ namespace Game.Chat
}
[Command("dest", RBACPermissions.CommandCastDest)]
static bool HandleCastDestCommand(CommandHandler handler, uint spellId, float x, float y, float z, string triggeredStr)
static bool HandleCastDestCommand(CommandHandler handler, uint spellId, float x, float y, float z, [OptionalArg] string triggeredStr)
{
Unit caster = handler.GetSelectedUnit();
if (!caster)
@@ -77,7 +77,7 @@ namespace Game.Chat
//rename characters
[Command("rename", RBACPermissions.CommandCharacterRename, true)]
static bool HandleCharacterRenameCommand(CommandHandler handler, PlayerIdentifier player, string newName)
static bool HandleCharacterRenameCommand(CommandHandler handler, PlayerIdentifier player, [OptionalArg] string newName)
{
if (player == null && !newName.IsEmpty())
return false;
@@ -469,7 +469,7 @@ namespace Game.Chat
}
[Command("list", RBACPermissions.CommandCharacterDeletedList, true)]
static bool HandleCharacterDeletedListCommand(CommandHandler handler, string needle)
static bool HandleCharacterDeletedListCommand(CommandHandler handler, [OptionalArg] string needle)
{
List<DeletedInfo> foundList = new();
if (!GetDeletedCharacterInfoList(foundList, needle))
@@ -488,7 +488,7 @@ namespace Game.Chat
}
[Command("restore", RBACPermissions.CommandCharacterDeletedRestore, true)]
static bool HandleCharacterDeletedRestoreCommand(CommandHandler handler, string needle, string newCharName, AccountIdentifier newAccount)
static bool HandleCharacterDeletedRestoreCommand(CommandHandler handler, string needle, [OptionalArg] string newCharName, AccountIdentifier newAccount)
{
List<DeletedInfo> foundList = new();
if (!GetDeletedCharacterInfoList(foundList, needle))
@@ -725,7 +725,7 @@ namespace Game.Chat
class PdumpCommand
{
[Command("copy", RBACPermissions.CommandPdumpCopy, true)]
static bool HandlePDumpCopyCommand(CommandHandler handler, string playerName, string accountName, string characterName, ulong? characterGUID)
static bool HandlePDumpCopyCommand(CommandHandler handler, PlayerIdentifier player, AccountIdentifier account, [OptionalArg] string characterName, ulong? characterGUID)
{
/*
std::string name;
@@ -771,7 +771,7 @@ namespace Game.Chat
}
[Command("load", RBACPermissions.CommandPdumpLoad, true)]
static bool HandlePDumpLoadCommand(CommandHandler handler, string fileName, string accountName, string characterName, ulong? characterGuid)
static bool HandlePDumpLoadCommand(CommandHandler handler, string fileName, AccountIdentifier account, [OptionalArg] string characterName, ulong? characterGuid)
{
/*
if (!AccountMgr.normalizeString(accountName))
+1 -1
View File
@@ -149,7 +149,7 @@ namespace Game.Chat.Commands
}
[Command("recipes", CypherStrings.CommandLearnAllRecipesHelp, RBACPermissions.CommandLearnAllRecipes)]
static bool HandleLearnAllRecipesCommand(CommandHandler handler, string namePart)
static bool HandleLearnAllRecipesCommand(CommandHandler handler, Tail namePart)
{
// Learns all recipes of specified profession and sets skill to max
// Example: .learn all_recipes enchanting
+1 -1
View File
@@ -578,7 +578,7 @@ namespace Game.Chat.Commands
}
[Command("name", RBACPermissions.CommandListAuras)]
static bool HandleListAurasByNameCommand(CommandHandler handler, string namePart)
static bool HandleListAurasByNameCommand(CommandHandler handler, Tail namePart)
{
return ListAurasCommand(handler, null, namePart);
}
+33 -8
View File
@@ -28,7 +28,7 @@ namespace Game.Chat
class MessageCommands
{
[CommandNonGroup("nameannounce", RBACPermissions.CommandNameannounce, true)]
static bool HandleNameAnnounceCommand(CommandHandler handler, string message)
static bool HandleNameAnnounceCommand(CommandHandler handler, Tail message)
{
if (message.IsEmpty())
return false;
@@ -43,7 +43,7 @@ namespace Game.Chat
}
[CommandNonGroup("gmnameannounce", RBACPermissions.CommandGmnameannounce, true)]
static bool HandleGMNameAnnounceCommand(CommandHandler handler, string message)
static bool HandleGMNameAnnounceCommand(CommandHandler handler, Tail message)
{
if (message.IsEmpty())
return false;
@@ -58,7 +58,7 @@ namespace Game.Chat
}
[CommandNonGroup("announce", RBACPermissions.CommandAnnounce, true)]
static bool HandleAnnounceCommand(CommandHandler handler, string message)
static bool HandleAnnounceCommand(CommandHandler handler, Tail message)
{
if (message.IsEmpty())
return false;
@@ -68,7 +68,7 @@ namespace Game.Chat
}
[CommandNonGroup("gmannounce", RBACPermissions.CommandGmannounce, true)]
static bool HandleGMAnnounceCommand(CommandHandler handler, string message)
static bool HandleGMAnnounceCommand(CommandHandler handler, Tail message)
{
if (message.IsEmpty())
return false;
@@ -78,7 +78,7 @@ namespace Game.Chat
}
[CommandNonGroup("notify", RBACPermissions.CommandNotify, true)]
static bool HandleNotifyCommand(CommandHandler handler, string message)
static bool HandleNotifyCommand(CommandHandler handler, Tail message)
{
if (message.IsEmpty())
return false;
@@ -92,7 +92,7 @@ namespace Game.Chat
}
[CommandNonGroup("gmnotify", RBACPermissions.CommandGmnotify, true)]
static bool HandleGMNotifyCommand(CommandHandler handler, string message)
static bool HandleGMNotifyCommand(CommandHandler handler, Tail message)
{
if (message.IsEmpty())
return false;
@@ -106,7 +106,7 @@ namespace Game.Chat
}
[CommandNonGroup("whispers", RBACPermissions.CommandWhispers)]
static bool HandleWhispersCommand(CommandHandler handler, bool? operationArg)
static bool HandleWhispersCommand(CommandHandler handler, bool? operationArg, [OptionalArg] string playerNameArg)
{
if (!operationArg.HasValue)
{
@@ -118,6 +118,7 @@ namespace Game.Chat
{
handler.GetSession().GetPlayer().SetAcceptWhispers(true);
handler.SendSysMessage(CypherStrings.CommandWhisperon);
return true;
}
else
{
@@ -125,9 +126,33 @@ namespace Game.Chat
handler.GetSession().GetPlayer().ClearWhisperWhiteList();
handler.GetSession().GetPlayer().SetAcceptWhispers(false);
handler.SendSysMessage(CypherStrings.CommandWhisperoff);
return true;
}
return true;
//todo fix me
/*if (operationArg->holds_alternative < EXACT_SEQUENCE("remove") > ())
{
if (!playerNameArg)
return false;
if (normalizePlayerName(*playerNameArg))
{
if (Player * player = ObjectAccessor::FindPlayerByName(*playerNameArg))
{
handler->GetSession()->GetPlayer()->RemoveFromWhisperWhiteList(player->GetGUID());
handler->PSendSysMessage(LANG_COMMAND_WHISPEROFFPLAYER, playerNameArg->c_str());
return true;
}
else
{
handler->PSendSysMessage(LANG_PLAYER_NOT_FOUND, playerNameArg->c_str());
handler->SetSentErrorMessage(true);
return false;
}
}
}
handler.SendSysMessage(CypherStrings.UseBol);
return false;*/
}
}
+18 -17
View File
@@ -733,10 +733,10 @@ namespace Game.Chat
}
[CommandNonGroup("help", RBACPermissions.CommandHelp, true)]
static bool HandleHelpCommand(CommandHandler handler, OptionalArg<string> cmd)
static bool HandleHelpCommand(CommandHandler handler, Tail cmd)
{
ChatCommandNode.SendCommandHelpFor(handler, cmd.ValueOr(""));
if (!cmd.HasValue)
ChatCommandNode.SendCommandHelpFor(handler, cmd);
if (cmd.IsEmpty())
ChatCommandNode.SendCommandHelpFor(handler, "help");
return true;
@@ -835,7 +835,7 @@ namespace Game.Chat
}
[CommandNonGroup("linkgrave", RBACPermissions.CommandLinkgrave)]
static bool HandleLinkGraveCommand(CommandHandler handler, uint graveyardId, string teamArg)
static bool HandleLinkGraveCommand(CommandHandler handler, uint graveyardId, [OptionalArg] string teamArg)
{
Team team;
if (teamArg.IsEmpty())
@@ -1005,10 +1005,11 @@ namespace Game.Chat
// mute player for the specified duration
[CommandNonGroup("mute", RBACPermissions.CommandMute, true)]
static bool HandleMuteCommand(CommandHandler handler, PlayerIdentifier player, uint muteTime, string muteReason)
static bool HandleMuteCommand(CommandHandler handler, PlayerIdentifier player, uint muteTime, Tail muteReason)
{
string muteReasonStr = muteReason;
if (muteReason.IsEmpty())
muteReason = handler.GetCypherString(CypherStrings.NoReason);
muteReasonStr = handler.GetCypherString(CypherStrings.NoReason);
if (player == null)
player = PlayerIdentifier.FromTarget(handler);
@@ -1053,7 +1054,7 @@ namespace Game.Chat
stmt.AddValue(0, -(muteTime * Time.Minute));
}
stmt.AddValue(1, muteReason);
stmt.AddValue(1, muteReasonStr);
stmt.AddValue(2, muteBy);
stmt.AddValue(3, accountId);
DB.Login.Execute(stmt);
@@ -1062,21 +1063,21 @@ namespace Game.Chat
stmt.AddValue(0, accountId);
stmt.AddValue(1, muteTime);
stmt.AddValue(2, muteBy);
stmt.AddValue(3, muteReason);
stmt.AddValue(3, muteReasonStr);
DB.Login.Execute(stmt);
string nameLink = handler.PlayerLink(player.GetName());
if (WorldConfig.GetBoolValue(WorldCfg.ShowMuteInWorld))
Global.WorldMgr.SendWorldText(CypherStrings.CommandMutemessageWorld, muteBy, nameLink, muteTime, muteReason);
Global.WorldMgr.SendWorldText(CypherStrings.CommandMutemessageWorld, muteBy, nameLink, muteTime, muteReasonStr);
if (target)
{
target.SendSysMessage(CypherStrings.YourChatDisabled, muteTime, muteBy, muteReason);
handler.SendSysMessage(CypherStrings.YouDisableChat, nameLink, muteTime, muteReason);
target.SendSysMessage(CypherStrings.YourChatDisabled, muteTime, muteBy, muteReasonStr);
handler.SendSysMessage(CypherStrings.YouDisableChat, nameLink, muteTime, muteReasonStr);
}
else
{
handler.SendSysMessage(CypherStrings.CommandDisableChatDelayed, nameLink, muteTime, muteReason);
handler.SendSysMessage(CypherStrings.CommandDisableChatDelayed, nameLink, muteTime, muteReasonStr);
}
return true;
@@ -1119,7 +1120,7 @@ namespace Game.Chat
}
[CommandNonGroup("neargrave", RBACPermissions.CommandNeargrave)]
static bool HandleNearGraveCommand(CommandHandler handler, string teamArg)
static bool HandleNearGraveCommand(CommandHandler handler, [OptionalArg] string teamArg)
{
Team team;
if (teamArg.IsEmpty())
@@ -1890,7 +1891,7 @@ namespace Game.Chat
}
[CommandNonGroup("unfreeze", RBACPermissions.CommandUnfreeze)]
static bool HandleUnFreezeCommand(CommandHandler handler, string targetNameArg)
static bool HandleUnFreezeCommand(CommandHandler handler, [OptionalArg] string targetNameArg)
{
string name = "";
Player player;
@@ -2267,7 +2268,7 @@ namespace Game.Chat
}
[Command("set", RBACPermissions.CommandAdditemset)]
static bool HandleAddItemSetCommand(CommandHandler handler, uint itemSetId, string bonuses, string context)
static bool HandleAddItemSetCommand(CommandHandler handler, uint itemSetId, [OptionalArg] string bonuses, byte? context)
{
// prevent generation all items with itemset field value '0'
if (itemSetId == 0)
@@ -2290,8 +2291,8 @@ namespace Game.Chat
}
ItemContext itemContext = ItemContext.None;
if (!context.IsEmpty())
itemContext = context.ToEnum<ItemContext>();
if (context.HasValue)
itemContext = (ItemContext)context;
Player player = handler.GetSession().GetPlayer();
Player playerTarget = handler.GetSelectedPlayer();
+7 -7
View File
@@ -283,7 +283,7 @@ namespace Game.Chat
}
[Command("say", RBACPermissions.CommandNpcSay)]
static bool HandleNpcSayCommand(CommandHandler handler, string text)
static bool HandleNpcSayCommand(CommandHandler handler, Tail text)
{
if (text.IsEmpty())
return false;
@@ -298,7 +298,7 @@ namespace Game.Chat
creature.Say(text, Language.Universal);
// make some emotes
switch (text.LastOrDefault())
switch (((string)text).LastOrDefault())
{
case '?':
creature.HandleEmoteCommand(Emote.OneshotQuestion);
@@ -480,7 +480,7 @@ namespace Game.Chat
}
[Command("textemote", RBACPermissions.CommandNpcTextemote)]
static bool HandleNpcTextEmoteCommand(CommandHandler handler, string text)
static bool HandleNpcTextEmoteCommand(CommandHandler handler, Tail text)
{
Creature creature = handler.GetSelectedCreature();
if (!creature)
@@ -495,7 +495,7 @@ namespace Game.Chat
}
[Command("whisper", RBACPermissions.CommandNpcWhisper)]
static bool HandleNpcWhisperCommand(CommandHandler handler, string recv, string text)
static bool HandleNpcWhisperCommand(CommandHandler handler, string recv, Tail text)
{
if (text.IsEmpty())
{
@@ -520,7 +520,7 @@ namespace Game.Chat
}
[Command("yell", RBACPermissions.CommandNpcYell)]
static bool HandleNpcYellCommand(CommandHandler handler, string text)
static bool HandleNpcYellCommand(CommandHandler handler, Tail text)
{
if (text.IsEmpty())
return false;
@@ -625,7 +625,7 @@ namespace Game.Chat
}
[Command("item", RBACPermissions.CommandNpcAddItem)]
static bool HandleNpcAddVendorItemCommand(CommandHandler handler, uint itemId, uint? mc, uint? it, uint? ec, string bonusListIds)
static bool HandleNpcAddVendorItemCommand(CommandHandler handler, uint itemId, uint? mc, uint? it, uint? ec, [OptionalArg] string bonusListIds)
{
if (itemId == 0)
{
@@ -740,7 +740,7 @@ namespace Game.Chat
}
[Command("temp", RBACPermissions.CommandNpcAddTemp)]
static bool HandleNpcAddTempSpawnCommand(CommandHandler handler, string lootStr, uint id)
static bool HandleNpcAddTempSpawnCommand(CommandHandler handler, [OptionalArg] string lootStr, uint id)
{
bool loot = false;
if (!lootStr.IsEmpty())
+5 -3
View File
@@ -333,14 +333,16 @@ namespace Game.Chat
}
[Command("name", RBACPermissions.CommandTeleName, true)]
static bool HandleTeleNameNpcNameCommand(CommandHandler handler, PlayerIdentifier player, string name)
static bool HandleTeleNameNpcNameCommand(CommandHandler handler, PlayerIdentifier player, Tail name)
{
string normalizedName = name;
if (player == null)
return false;
DB.World.EscapeString(ref name);
DB.World.EscapeString(ref normalizedName);
SQLResult result = DB.World.Query($"SELECT c.position_x, c.position_y, c.position_z, c.orientation, c.map, ct.name FROM creature c INNER JOIN creature_template ct ON c.id = ct.entry WHERE ct.name LIKE '{name}'");
SQLResult result = DB.World.Query($"SELECT c.position_x, c.position_y, c.position_z, c.orientation, c.map, ct.name FROM creature c INNER JOIN creature_template ct ON c.id = ct.entry WHERE ct.name LIKE '{normalizedName}'");
if (result.IsEmpty())
{
handler.SendSysMessage(CypherStrings.CommandGocreatnotfound);