Skip to content

Commit

Permalink
feat. Recruit by character name
Browse files Browse the repository at this point in the history
  • Loading branch information
pangolp committed Aug 1, 2023
1 parent b48e72f commit 339232c
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/RecruitCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ void waitToUseCommand(ChatHandler* handler, uint32 myAccountId)
}
}

static void getTargetAccountIdByName(std::string& name, uint32& accountId)
{
QueryResult result = CharacterDatabase.Query("SELECT `account` FROM `characters` WHERE `name`='{}';", name);
accountId = (*result)[0].Get<int32>();
}

using namespace Acore::ChatCommands;

class RecruitCommandscript : public CommandScript
Expand All @@ -97,7 +103,7 @@ class RecruitCommandscript : public CommandScript
return commandTable;
}

static bool HandleAddRecruitFriendCommand(ChatHandler* handler, std::string accountName)
static bool HandleAddRecruitFriendCommand(ChatHandler* handler, std::string characterName)
{

if (!recruitFriend.commandEnable)
Expand All @@ -106,11 +112,31 @@ class RecruitCommandscript : public CommandScript
return false;
}

uint32 targetAccountId = AccountMgr::GetId(accountName);
if (characterName.empty())
return false;

Player* target = nullptr;

std::string playerName;
uint32 targetAccountId;

if (!handler->extractPlayerTarget(characterName.data(), &target, nullptr, &playerName))
{
return false;
}

if (target)
{
targetAccountId = target->GetSession()->GetAccountId();
}
else
{
getTargetAccountIdByName(playerName, targetAccountId);
}

if (targetAccountId == 0)
{
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, characterName.c_str());
handler->SetSentErrorMessage(true);
return false;
}
Expand Down

0 comments on commit 339232c

Please sign in to comment.