Skip to content

Commit

Permalink
Update SlashCommandHandler.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiernan-Alderman committed May 16, 2024
1 parent a400e4d commit edc6ed6
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions dGame/dUtilities/SlashCommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,38 +41,6 @@ void SlashCommandHandler::RegisterCommand(Command command) {
CommandInfos[command.aliases[0]] = command;
}

void GMZeroCommands::Help(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
std::ostringstream feedback;
if (args.empty()) {
feedback << "----- Commands -----";
for (const auto& [alias, command] : CommandInfos) {
// TODO: Limit displaying commands based on GM level they require
if (command.requiredLevel > entity->GetGMLevel()) continue;
LOG("Help command: %s", alias.c_str());
feedback << "\n/" << alias << ": " << command.help;
}
} else {
auto it = CommandInfos.find(args);
if (it != CommandInfos.end() && entity->GetGMLevel() >= it->second.requiredLevel) {
feedback << "----- " << args << " -----\n";
feedback << it->second.info;
if (it->second.aliases.size() > 1) {
feedback << "\nAliases: ";
for (size_t i = 0; i < it->second.aliases.size(); i++) {
if (i > 0) feedback << ", ";
feedback << it->second.aliases[i];
}
}
} else {
if (entity->GetGMLevel() > eGameMasterLevel::CIVILIAN) {
feedback << "Command " << std::quoted(args) << " does not exist!";
}
}
}
const auto feedbackStr = feedback.str();
if (!feedbackStr.empty()) GameMessages::SendSlashCommandFeedbackText(entity, GeneralUtils::ASCIIToUTF16(feedbackStr));
}

void SlashCommandHandler::HandleChatCommand(const std::u16string& chat, Entity* entity, const SystemAddress& sysAddr) {
auto input = GeneralUtils::UTF16ToWTF8(chat);
if (input.empty() || input.front() != '/') return;
Expand Down Expand Up @@ -105,6 +73,38 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& chat, Entity*
}
}

void GMZeroCommands::Help(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
std::ostringstream feedback;
if (args.empty()) {
feedback << "----- Commands -----";
for (const auto& [alias, command] : CommandInfos) {
// TODO: Limit displaying commands based on GM level they require
if (command.requiredLevel > entity->GetGMLevel()) continue;
LOG("Help command: %s", alias.c_str());
feedback << "\n/" << alias << ": " << command.help;
}
} else {
auto it = CommandInfos.find(args);
if (it != CommandInfos.end() && entity->GetGMLevel() >= it->second.requiredLevel) {
feedback << "----- " << args << " -----\n";
feedback << it->second.info;
if (it->second.aliases.size() > 1) {
feedback << "\nAliases: ";
for (size_t i = 0; i < it->second.aliases.size(); i++) {
if (i > 0) feedback << ", ";
feedback << it->second.aliases[i];
}
}
} else {
if (entity->GetGMLevel() > eGameMasterLevel::CIVILIAN) {
feedback << "Command " << std::quoted(args) << " does not exist!";
}
}
}
const auto feedbackStr = feedback.str();
if (!feedbackStr.empty()) GameMessages::SendSlashCommandFeedbackText(entity, GeneralUtils::ASCIIToUTF16(feedbackStr));
}

void SlashCommandHandler::SendAnnouncement(const std::string& title, const std::string& message) {
AMFArrayValue args;

Expand Down

0 comments on commit edc6ed6

Please sign in to comment.