mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-22 05:27:19 +00:00
feat: Command Sorting (#1580)
* Update SlashCommandHandler.cpp * Update SlashCommandHandler.cpp * Update SlashCommandHandler.cpp * Update SlashCommandHandler.cpp * Update dGame/dUtilities/SlashCommandHandler.cpp Co-authored-by: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> * Update SlashCommandHandler.cpp * Update SlashCommandHandler.cpp * Update SlashCommandHandler.cpp * Update dGame/dUtilities/SlashCommandHandler.cpp Co-authored-by: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> * Update SlashCommandHandler.cpp * Update SlashCommandHandler.cpp * Update dGame/dUtilities/SlashCommandHandler.cpp Co-authored-by: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> * Update dGame/dUtilities/SlashCommandHandler.cpp Co-authored-by: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> * Update dGame/dUtilities/SlashCommandHandler.cpp Co-authored-by: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> * Update dGame/dUtilities/SlashCommandHandler.cpp Co-authored-by: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> * Update dGame/dUtilities/SlashCommandHandler.cpp Co-authored-by: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> * Update dGame/dUtilities/SlashCommandHandler.cpp Co-authored-by: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> * Update SlashCommandHandler.cpp * Update dGame/dUtilities/SlashCommandHandler.cpp Co-authored-by: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> * Update SlashCommandHandler.cpp * Update SlashCommandHandler.cpp --------- Co-authored-by: David Markowitz <39972741+EmosewaMC@users.noreply.github.com>
This commit is contained in:
parent
d9d262d3f1
commit
c8e0bb0db0
@ -19,7 +19,7 @@
|
|||||||
#include "dServer.h"
|
#include "dServer.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
std::vector<Command> CommandInfos;
|
std::map<std::string, Command> CommandInfos;
|
||||||
std::map<std::string, Command> RegisteredCommands;
|
std::map<std::string, Command> RegisteredCommands;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,9 +38,8 @@ void SlashCommandHandler::RegisterCommand(Command command) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
CommandInfos[command.aliases[0]] = command;
|
||||||
CommandInfos.push_back(command);
|
}
|
||||||
};
|
|
||||||
|
|
||||||
void SlashCommandHandler::HandleChatCommand(const std::u16string& chat, Entity* entity, const SystemAddress& sysAddr) {
|
void SlashCommandHandler::HandleChatCommand(const std::u16string& chat, Entity* entity, const SystemAddress& sysAddr) {
|
||||||
auto input = GeneralUtils::UTF16ToWTF8(chat);
|
auto input = GeneralUtils::UTF16ToWTF8(chat);
|
||||||
@ -74,38 +73,31 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& chat, Entity*
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This commands in here so we can access the CommandInfos to display info
|
|
||||||
void GMZeroCommands::Help(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
void GMZeroCommands::Help(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||||
std::ostringstream feedback;
|
std::ostringstream feedback;
|
||||||
if (args.empty()) {
|
if (args.empty()) {
|
||||||
feedback << "----- Commands -----";
|
feedback << "----- Commands -----";
|
||||||
for (const auto& command : CommandInfos) {
|
for (const auto& [alias, command] : CommandInfos) {
|
||||||
// TODO: Limit displaying commands based on GM level they require
|
// TODO: Limit displaying commands based on GM level they require
|
||||||
if (command.requiredLevel > entity->GetGMLevel()) continue;
|
if (command.requiredLevel > entity->GetGMLevel()) continue;
|
||||||
LOG("Help command: %s", command.aliases[0].c_str());
|
LOG("Help command: %s", alias.c_str());
|
||||||
feedback << "\n/" << command.aliases[0] << ": " << command.help;
|
feedback << "\n/" << alias << ": " << command.help;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bool foundCommand = false;
|
auto it = CommandInfos.find(args);
|
||||||
for (const auto& command : CommandInfos) {
|
if (it != CommandInfos.end() && entity->GetGMLevel() >= it->second.requiredLevel) {
|
||||||
if (std::ranges::find(command.aliases, args) == command.aliases.end()) continue;
|
feedback << "----- " << args << " -----\n";
|
||||||
|
feedback << it->second.info;
|
||||||
if (entity->GetGMLevel() < command.requiredLevel) break;
|
if (it->second.aliases.size() > 1) {
|
||||||
foundCommand = true;
|
feedback << "\nAliases: ";
|
||||||
feedback << "----- " << command.aliases.at(0) << " -----\n";
|
for (size_t i = 0; i < it->second.aliases.size(); i++) {
|
||||||
// info can be a localizable string
|
if (i > 0) feedback << ", ";
|
||||||
feedback << command.info;
|
feedback << it->second.aliases[i];
|
||||||
if (command.aliases.size() == 1) break;
|
}
|
||||||
|
|
||||||
feedback << "\nAliases: ";
|
|
||||||
for (size_t i = 0; i < command.aliases.size(); i++) {
|
|
||||||
if (i > 0) feedback << ", ";
|
|
||||||
feedback << command.aliases[i];
|
|
||||||
}
|
}
|
||||||
|
} else if (entity->GetGMLevel() > eGameMasterLevel::CIVILIAN) {
|
||||||
|
feedback << "Command " << std::quoted(args) << " does not exist!";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let GameMasters know if the command doesn't exist
|
|
||||||
if (!foundCommand && entity->GetGMLevel() > eGameMasterLevel::CIVILIAN) feedback << "Command " << std::quoted(args) << " does not exist!";
|
|
||||||
}
|
}
|
||||||
const auto feedbackStr = feedback.str();
|
const auto feedbackStr = feedback.str();
|
||||||
if (!feedbackStr.empty()) GameMessages::SendSlashCommandFeedbackText(entity, GeneralUtils::ASCIIToUTF16(feedbackStr));
|
if (!feedbackStr.empty()) GameMessages::SendSlashCommandFeedbackText(entity, GeneralUtils::ASCIIToUTF16(feedbackStr));
|
||||||
@ -900,7 +892,7 @@ void SlashCommandHandler::Startup() {
|
|||||||
|
|
||||||
Command HelpCommand{
|
Command HelpCommand{
|
||||||
.help = "Display command info",
|
.help = "Display command info",
|
||||||
.info = "If a command is given, display detailed info on that command. Otherwise display a list of commands with short desctiptions.",
|
.info = "If a command is given, display detailed info on that command. Otherwise display a list of commands with short descriptions.",
|
||||||
.aliases = { "help", "h"},
|
.aliases = { "help", "h"},
|
||||||
.handle = GMZeroCommands::Help,
|
.handle = GMZeroCommands::Help,
|
||||||
.requiredLevel = eGameMasterLevel::CIVILIAN
|
.requiredLevel = eGameMasterLevel::CIVILIAN
|
||||||
|
Loading…
Reference in New Issue
Block a user