Scripts/Commands: New argument parsing methodology (PR #22363)

- Detect the arguments accepted by the command handler
- Tokenize out those arguments automatically and feed them to the handler
- Unmatched rest of the string can be accepted by trailing char const* or CommandArgs*
This commit is contained in:
Aokromes committed 2018-09-09 14:31:14 +02:00
1 parent 88e1b344cb
commit 6815c24be1
14 files changed
+1043 -405

No files matched your search

+12 -32
View File
@@ -36,6 +36,8 @@ EndScriptData */
#include "RBAC.h"
#include "WorldSession.h"
using namespace Trinity::ChatCommands;
class tele_commandscript : public CommandScript
{
public:
@@ -58,17 +60,12 @@ public:
return commandTable;
}
static bool HandleTeleAddCommand(ChatHandler* handler, char const* args)
static bool HandleTeleAddCommand(ChatHandler* handler, std::string const& name)
{
if (!*args)
return false;
Player* player = handler->GetSession()->GetPlayer();
if (!player)
return false;
std::string name = args;
if (sObjectMgr->GetGameTeleExactName(name))
{
handler->SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST);
@@ -98,13 +95,8 @@ public:
return true;
}
static bool HandleTeleDelCommand(ChatHandler* handler, char const* args)
static bool HandleTeleDelCommand(ChatHandler* handler, GameTele const* tele)
{
if (!*args)
return false;
// id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
GameTele const* tele = handler->extractGameTeleFromLink((char*)args);
if (!tele)
{
handler->SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
@@ -215,10 +207,14 @@ public:
}
//Teleport group to given game_tele.entry
static bool HandleTeleGroupCommand(ChatHandler* handler, char const* args)
static bool HandleTeleGroupCommand(ChatHandler* handler, GameTele const* tele)
{
if (!*args)
if (!tele)
{
handler->SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
handler->SetSentErrorMessage(true);
return false;
}
Player* target = handler->getSelectedPlayer();
if (!target)
@@ -232,15 +228,6 @@ public:
if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
return false;
// id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
GameTele const* tele = handler->extractGameTeleFromLink((char*)args);
if (!tele)
{
handler->SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
handler->SetSentErrorMessage(true);
return false;
}
MapEntry const* map = sMapStore.LookupEntry(tele->mapId);
if (!map || map->IsBattlegroundOrArena())
{
@@ -298,16 +285,8 @@ public:
return true;
}
static bool HandleTeleCommand(ChatHandler* handler, char const* args)
static bool HandleTeleCommand(ChatHandler* handler, GameTele const* tele)
{
if (!*args)
return false;
Player* me = handler->GetSession()->GetPlayer();
// id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
GameTele const* tele = handler->extractGameTeleFromLink((char*)args);
if (!tele)
{
handler->SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
@@ -315,6 +294,7 @@ public:
return false;
}
Player* me = handler->GetSession()->GetPlayer();
if (me->IsInCombat())
{
handler->SendSysMessage(LANG_YOU_IN_COMBAT);