[Commands] Cleanup #who Command. (#1924)

* [Commands] Cleanup #who Command.
- Cleanup messages and logic.
- Add GetAccountStatusMap() and GetAccountStatusName() helpers for account status stuff.
- Use Chat::Who instead of Chat::Magenta so you can more easily see saylinks.
- Add a summon saylink to the list of saylinks so you can summon the player.

* New line.
This commit is contained in:
Kinglykrab 2022-01-11 06:09:29 -05:00 committed by GitHub
parent 59c373bcff
commit f3002d9656
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 233 additions and 153 deletions

View File

@ -298,4 +298,42 @@ std::string EQ::constants::GetBodyTypeName(bodyType bodytype_id)
return bodytypes[bodytype_id]; return bodytypes[bodytype_id];
} }
return std::string(); return std::string();
} }
const std::map<uint8, std::string>& EQ::constants::GetAccountStatusMap()
{
static const std::map<uint8, std::string> account_status_map = {
{ AccountStatus::Player, "Player" },
{ AccountStatus::Steward, "Steward" },
{ AccountStatus::ApprenticeGuide, "Apprentice Guide" },
{ AccountStatus::Guide, "Guide" },
{ AccountStatus::QuestTroupe, "Quest Troupe" },
{ AccountStatus::SeniorGuide, "Senior Guide" },
{ AccountStatus::GMTester, "GM Tester" },
{ AccountStatus::EQSupport, "EQ Support" },
{ AccountStatus::GMStaff, "GM Staff" },
{ AccountStatus::GMAdmin, "GM Admin" },
{ AccountStatus::GMLeadAdmin, "GM Lead Admin" },
{ AccountStatus::QuestMaster, "Quest Master" },
{ AccountStatus::GMAreas, "GM Areas" },
{ AccountStatus::GMCoder, "GM Coder" },
{ AccountStatus::GMMgmt, "GM Mgmt" },
{ AccountStatus::GMImpossible, "GM Impossible" },
{ AccountStatus::Max, "GM Max" }
};
return account_status_map;
}
std::string EQ::constants::GetAccountStatusName(uint8 account_status)
{
auto account_statuses = EQ::constants::GetAccountStatusMap();
std::string status_name;
for (auto status_level = account_statuses.rbegin(); status_level != account_statuses.rend(); ++status_level) {
if (account_status >= status_level->first) {
status_name = status_level->second;
break;
}
}
return status_name;
}

View File

@ -245,6 +245,9 @@ namespace EQ
extern const std::map<bodyType, std::string>& GetBodyTypeMap(); extern const std::map<bodyType, std::string>& GetBodyTypeMap();
std::string GetBodyTypeName(bodyType bodytype_id); std::string GetBodyTypeName(bodyType bodytype_id);
extern const std::map<uint8, std::string>& GetAccountStatusMap();
std::string GetAccountStatusName(uint8 account_status);
const int STANCE_TYPE_FIRST = stancePassive; const int STANCE_TYPE_FIRST = stancePassive;
const int STANCE_TYPE_LAST = stanceBurnAE; const int STANCE_TYPE_LAST = stanceBurnAE;
const int STANCE_TYPE_COUNT = stanceBurnAE; const int STANCE_TYPE_COUNT = stanceBurnAE;

View File

@ -2,91 +2,53 @@
void command_who(Client *c, const Seperator *sep) void command_who(Client *c, const Seperator *sep)
{ {
std::string query = std::string query = SQL(
SQL ( SELECT
SELECT character_data.account_id,
character_data.account_id, character_data.name,
character_data.name, character_data.zone_id,
character_data.zone_id, character_data.zone_instance,
character_data.zone_instance, COALESCE(
COALESCE( (
( SELECT guilds.name FROM guilds WHERE id = (
select
guilds.name
from
guilds
where
id = (
( (
select SELECT guild_id FROM guild_members WHERE char_id = character_data.id
guild_id )
from )
guild_members ),
where ""
char_id = character_data.id ) AS guild_name,
) character_data.level,
) character_data.race,
), character_data.class,
"" COALESCE(
) as guild_name, (
character_data.level, SELECT account.status FROM account WHERE account.id = character_data.account_id LIMIT 1
character_data.race, ),
character_data.class, 0
COALESCE( ) AS account_status,
( COALESCE(
select (
account.status SELECT account.name FROM account WHERE account.id = character_data.account_id LIMIT 1
from ),
account 0
where ) AS account_name,
account.id = character_data.account_id COALESCE(
LIMIT (
1 SELECT account_ip.ip FROM account_ip WHERE account_ip.accid = character_data.account_id ORDER BY account_ip.lastused DESC LIMIT 1
), 0 ),
) as account_status, ""
COALESCE( ) AS account_ip
( FROM
select character_data
account.name WHERE
from last_login > (UNIX_TIMESTAMP() - 600)
account ORDER BY
where character_data.name;
account.id = character_data.account_id );
LIMIT
1
),
0
) as account_name,
COALESCE(
(
select
account_ip.ip
from
account_ip
where
account_ip.accid = character_data.account_id
ORDER BY
account_ip.lastused DESC
LIMIT
1
),
""
) as account_ip
FROM
character_data
WHERE
last_login > (UNIX_TIMESTAMP() - 600)
ORDER BY
character_data.name;
);
auto results = database.QueryDatabase(query); auto results = database.QueryDatabase(query);
if (!results.Success()) { if (!results.Success() || !results.RowCount()) {
return;
}
if (results.RowCount() == 0) {
c->Message(Chat::Yellow, "No results found");
return; return;
} }
@ -98,36 +60,36 @@ void command_who(Client *c, const Seperator *sep)
int found_count = 0; int found_count = 0;
c->Message(Chat::Magenta, "Players in EverQuest"); c->Message(Chat::Who, "Players in EverQuest:");
c->Message(Chat::Magenta, "--------------------"); c->Message(Chat::Who, "------------------------------");
for (auto row = results.begin(); row != results.end(); ++row) { for (auto row : results) {
auto account_id = static_cast<uint32>(atoi(row[0])); auto account_id = std::stoul(row[0]);
std::string player_name = row[1]; std::string player_name = row[1];
auto zone_id = static_cast<uint32>(atoi(row[2])); auto zone_id = std::stoul(row[2]);
std::string zone_short_name = ZoneName(zone_id); std::string zone_short_name = ZoneName(zone_id);
auto zone_instance = static_cast<uint32>(atoi(row[3])); std::string zone_long_name = ZoneLongName(zone_id);
std::string guild_name = row[4]; auto zone_instance = std::stoul(row[3]);
auto player_level = static_cast<uint32>(atoi(row[5])); std::string guild_name = row[4];
auto player_race = static_cast<uint32>(atoi(row[6])); auto player_level = std::stoul(row[5]);
auto player_class = static_cast<uint32>(atoi(row[7])); auto player_race = std::stoul(row[6]);
auto account_status = static_cast<uint32>(atoi(row[8])); auto player_class = std::stoul(row[7]);
std::string account_name = row[9]; auto account_status = std::stoul(row[8]);
std::string account_ip = row[10]; std::string account_name = row[9];
std::string base_class_name = GetClassIDName(static_cast<uint8>(player_class), 1); std::string account_ip = row[10];
std::string base_class_name = GetClassIDName(static_cast<uint8>(player_class));
std::string displayed_race_name = GetRaceIDName(static_cast<uint16>(player_race)); std::string displayed_race_name = GetRaceIDName(static_cast<uint16>(player_race));
if (search_string.length() > 0) { if (search_string.length()) {
bool found_search_term = bool found_search_term = (
( str_tolower(player_name).find(search_string) != std::string::npos ||
str_tolower(player_name).find(search_string) != std::string::npos || str_tolower(zone_short_name).find(search_string) != std::string::npos ||
str_tolower(zone_short_name).find(search_string) != std::string::npos || str_tolower(displayed_race_name).find(search_string) != std::string::npos ||
str_tolower(displayed_race_name).find(search_string) != std::string::npos || str_tolower(base_class_name).find(search_string) != std::string::npos ||
str_tolower(base_class_name).find(search_string) != std::string::npos || str_tolower(guild_name).find(search_string) != std::string::npos ||
str_tolower(guild_name).find(search_string) != std::string::npos || str_tolower(account_name).find(search_string) != std::string::npos ||
str_tolower(account_name).find(search_string) != std::string::npos || str_tolower(account_ip).find(search_string) != std::string::npos
str_tolower(account_ip).find(search_string) != std::string::npos );
);
if (!found_search_term) { if (!found_search_term) {
continue; continue;
@ -135,68 +97,145 @@ void command_who(Client *c, const Seperator *sep)
} }
std::string displayed_guild_name; std::string displayed_guild_name;
if (guild_name.length() > 0) { if (guild_name.length()) {
displayed_guild_name = EQ::SayLinkEngine::GenerateQuestSaylink( displayed_guild_name = EQ::SayLinkEngine::GenerateQuestSaylink(
StringFormat( fmt::format(
"#who \"%s\"", "#who \"{}\"",
guild_name.c_str()), guild_name
),
false, false,
StringFormat("<%s>", guild_name.c_str()) fmt::format(
"<{}>",
guild_name
)
); );
} }
std::string goto_saylink = EQ::SayLinkEngine::GenerateQuestSaylink( auto goto_saylink = EQ::SayLinkEngine::GenerateQuestSaylink(
StringFormat("#goto %s", player_name.c_str()), false, "Goto" fmt::format(
"#goto {}",
player_name
),
false,
"Goto"
);
auto summon_saylink = EQ::SayLinkEngine::GenerateQuestSaylink(
fmt::format(
"#summon {}",
player_name
),
false,
"Summon"
); );
std::string display_class_name = GetClassIDName( std::string display_class_name = GetClassIDName(
static_cast<uint8>(player_class), static_cast<uint8>(player_class),
static_cast<uint8>(player_level)); static_cast<uint8>(player_level)
);
auto class_saylink = EQ::SayLinkEngine::GenerateQuestSaylink(
fmt::format(
"#who {}",
base_class_name
),
false,
display_class_name
);
auto race_saylink = EQ::SayLinkEngine::GenerateQuestSaylink(
fmt::format(
"#who %s",
displayed_race_name
),
false,
displayed_race_name
);
auto zone_saylink = EQ::SayLinkEngine::GenerateQuestSaylink(
fmt::format(
"#who {}",
zone_short_name
),
false,
zone_long_name
);
auto account_saylink = EQ::SayLinkEngine::GenerateQuestSaylink(
fmt::format(
"#who {}",
account_name
),
false,
account_name
);
auto account_ip_saylink = EQ::SayLinkEngine::GenerateQuestSaylink(
fmt::format(
"#who {}",
account_ip
),
false,
account_ip
);
auto status_level = (
account_status ?
fmt::format(
"* {} * ",
EQ::constants::GetAccountStatusName(account_status)
) :
""
);
auto version_string = (
zone_instance ?
fmt::format(
" ({})",
zone_instance
) :
""
);
c->Message( c->Message(
5, "%s[%u %s] %s (%s) %s ZONE: %s (%u) (%s) (%s) (%s)", Chat::Who,
(account_status > 0 ? "* GM * " : ""), fmt::format(
player_level, "{}[{} {} ({})] {} ({}) ({}) ({}) {} ZONE: {}{} ({} | {})",
EQ::SayLinkEngine::GenerateQuestSaylink( status_level,
StringFormat("#who %s", base_class_name.c_str()), player_level,
false, class_saylink,
display_class_name base_class_name,
).c_str(), player_name,
player_name.c_str(), race_saylink,
EQ::SayLinkEngine::GenerateQuestSaylink( account_saylink,
StringFormat("#who %s", displayed_race_name.c_str()), account_ip_saylink,
false, displayed_guild_name,
displayed_race_name zone_saylink,
).c_str(), version_string,
displayed_guild_name.c_str(), goto_saylink,
EQ::SayLinkEngine::GenerateQuestSaylink( summon_saylink
StringFormat("#who %s", zone_short_name.c_str()),
false,
zone_short_name
).c_str(),
zone_instance,
goto_saylink.c_str(),
EQ::SayLinkEngine::GenerateQuestSaylink(
StringFormat("#who %s", account_name.c_str()),
false,
account_name
).c_str(),
EQ::SayLinkEngine::GenerateQuestSaylink(
StringFormat("#who %s", account_ip.c_str()),
false,
account_ip
).c_str() ).c_str()
); );
found_count++; found_count++;
} }
std::string count_string = found_count == 1 ? "is" : "are";
std::string message = ( std::string message = (
found_count > 0 ? found_count ?
StringFormat("There is %i player(s) in EverQuest", found_count).c_str() : fmt::format(
"There are no players in EverQuest that match those who filters." "There {} {} player{} in EverQuest.",
count_string,
found_count,
found_count > 1 ? "s" : ""
) :
"There are no players in EverQuest that match those filters."
); );
c->Message(Chat::Magenta, message.c_str()); c->Message(
Chat::Who,
message.c_str()
);
} }