testing and making it compile again

This commit is contained in:
Aaron Kimbre 2024-03-31 01:11:01 -05:00
parent 4acdc8f354
commit 868a511c1e
2 changed files with 77 additions and 63 deletions

View File

@ -90,12 +90,13 @@
#include "dNavMesh.h" #include "dNavMesh.h"
namespace { namespace {
std::map<std::string, Command> RegisteredCommands; std::vector<Command> RegisteredCommands;
} }
void SlashCommandHandler::RegisterCommand(Command info, std::string command) { void SlashCommandHandler::RegisterCommand(Command command) {
LOG_DEBUG("Registering SlashCommand: %s", command.c_str()); LOG_DEBUG("Registering SlashCommand: %s", command.aliases[0].c_str());
RegisteredCommands.emplace(std::make_pair(command, info)); // TODO: duplicate alias check
RegisteredCommands.push_back(command);
}; };
// DEV Commands // DEV Commands
@ -173,24 +174,26 @@ void GMZeroCommands::Help(Entity* entity, const std::string args) {
if (args.empty()) { if (args.empty()) {
std::ostringstream helpMessage; std::ostringstream helpMessage;
helpMessage << "Commands:\n*"; helpMessage << "Commands:\n*";
for (auto& [commandCall, command] : RegisteredCommands) { for (auto& command: RegisteredCommands) {
// TODO: Limit dispplaying commands based on GM level they require // TODO: Limit displaying commands based on GM level they require
// if (RegisteredCommands[args].requiredLevel > entity->GetGMLevel()) continue; // if (RegisteredCommands[args].requiredLevel > entity->GetGMLevel()) continue;
helpMessage << "\t" << commandCall << ": " << command.description << "\n*"; helpMessage << "\t" << command.aliases[0] << ": " << command.info << "\n*";
} }
GameMessages::SendSlashCommandFeedbackText(entity, GeneralUtils::ASCIIToUTF16(helpMessage.str().substr(0, helpMessage.str().size() - 3))); GameMessages::SendSlashCommandFeedbackText(entity, GeneralUtils::ASCIIToUTF16(helpMessage.str().substr(0, helpMessage.str().size() - 3)));
} else { } else {
if (RegisteredCommands.contains(args)) { for (auto& command: RegisteredCommands) {
if (entity->GetGMLevel() >= RegisteredCommands[args].requiredLevel) { if (std::find(command.aliases.begin(), command.aliases.end(), args) != command.aliases.end()) {
RegisteredCommands[args].help; if (entity->GetGMLevel() >= command.requiredLevel) {
GameMessages::SendSlashCommandFeedbackText(entity, GeneralUtils::ASCIIToUTF16(RegisteredCommands[args].help)); command.help;
GameMessages::SendSlashCommandFeedbackText(entity, GeneralUtils::ASCIIToUTF16(command.help));
}
} else {
// We don't need to tell normies commands don't exist
if (entity->GetGMLevel() == eGameMasterLevel::CIVILIAN) return;
std::ostringstream feedback;
feedback << "Command " << std::quoted(args) << " does not exist!";
GameMessages::SendSlashCommandFeedbackText(entity, GeneralUtils::ASCIIToUTF16(feedback.str()));
} }
} else {
// We don't need to tell normies commands don't exist
if (entity->GetGMLevel() == eGameMasterLevel::CIVILIAN) return;
std::ostringstream feedback;
feedback << "Command " << std::quoted(args) << " does not exist!";
GameMessages::SendSlashCommandFeedbackText(entity, GeneralUtils::ASCIIToUTF16(feedback.str()));
} }
} }
} }
@ -198,41 +201,44 @@ void GMZeroCommands::Help(Entity* entity, const std::string args) {
void SlashCommandHandler::Startup() { void SlashCommandHandler::Startup() {
// Register Dev Commands // Register Dev Commands
Command SetGMLevelCommand; Command SetGMLevelCommand(
SetGMLevelCommand.description = "Set the players GM Level"; "",
SetGMLevelCommand.help = "Within the authorized range of levels for the current account, changes the character's game master level to the specified value. This is required to use certain commands."; "",
SetGMLevelCommand.requiredLevel = eGameMasterLevel::CIVILIAN; {"setgmlevel", "makegm", "gmlevel"},
SetGMLevelCommand.handle = DEVGMCommands::SetGMLevel; DEVGMCommands::SetGMLevel,
RegisterCommand(SetGMLevelCommand, "setgmlevel"); eGameMasterLevel::CIVILIAN
RegisterCommand(SetGMLevelCommand, "makegm"); );
RegisterCommand(SetGMLevelCommand, "gmlevel"); RegisterCommand(SetGMLevelCommand);
Command ToggleNameplateCommand; Command ToggleNameplateCommand(
ToggleNameplateCommand.description = "Toggles the visibility of a players nameplate"; "",
ToggleNameplateCommand.help = "Turns the nameplate above your head that is visible to other players off and on."; "",
ToggleNameplateCommand.requiredLevel = eGameMasterLevel::CIVILIAN; {"togglenameplate", "tnp"},
ToggleNameplateCommand.handle = DEVGMCommands::ToggleNameplate; DEVGMCommands::ToggleNameplate,
RegisterCommand(ToggleNameplateCommand, "togglenameplate"); eGameMasterLevel::CIVILIAN
RegisterCommand(ToggleNameplateCommand, "tnp"); );
RegisterCommand(ToggleNameplateCommand);
Command ToggleSkipCinematicsCommand; Command ToggleSkipCinematicsCommand(
ToggleSkipCinematicsCommand.description = "Toggles skipping cinematics"; "",
ToggleSkipCinematicsCommand.help = "Skips mission and world load related cinematics."; "",
ToggleSkipCinematicsCommand.requiredLevel = eGameMasterLevel::CIVILIAN; {"toggleskipcinematics", "tsc"},
ToggleSkipCinematicsCommand.handle = DEVGMCommands::ToggleSkipCinematics; DEVGMCommands::ToggleSkipCinematics,
RegisterCommand(ToggleSkipCinematicsCommand, "toggleskipcinematics"); eGameMasterLevel::CIVILIAN
RegisterCommand(ToggleSkipCinematicsCommand, "tsc"); );
RegisterCommand(ToggleSkipCinematicsCommand);
// Register Greater Than Zero Commands // Register Greater Than Zero Commands
// Register GM Zero Commands // Register GM Zero Commands
Command HelpCommand; Command HelpCommand(
HelpCommand.description = "Display command help"; "Display command info",
HelpCommand.help = "Displays a list of commands and their descriptions if no command are given. If an command is given, displays detailed info about that command."; "If a command is given, display detailed info on that command. Otherwise display a list of commands with short desctiptions.",
HelpCommand.requiredLevel = eGameMasterLevel::CIVILIAN; {"help", "h"},
HelpCommand.handle = GMZeroCommands::Help; GMZeroCommands::Help,
RegisterCommand(HelpCommand, "help"); eGameMasterLevel::CIVILIAN
RegisterCommand(HelpCommand, "h"); );
RegisterCommand(HelpCommand);
} }
void SlashCommandHandler::HandleChatCommand(const std::u16string& chat, Entity* entity, const SystemAddress& sysAddr) { void SlashCommandHandler::HandleChatCommand(const std::u16string& chat, Entity* entity, const SystemAddress& sysAddr) {
@ -244,23 +250,25 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& chat, Entity*
if (args.front() == '/') args.clear(); if (args.front() == '/') args.clear();
LOG("Handling command \"%s\" with args \"%s\"", command.c_str(), args.c_str()); LOG("Handling command \"%s\" with args \"%s\"", command.c_str(), args.c_str());
if (RegisteredCommands.contains(command)) { for (auto& registeredCommand : RegisteredCommands) {
if (entity->GetGMLevel() >= RegisteredCommands[command].requiredLevel) { if (std::find(registeredCommand.aliases.begin(), registeredCommand.aliases.end(), args) != registeredCommand.aliases.end()) {
RegisteredCommands[command].handle(entity, args); if (entity->GetGMLevel() >= registeredCommand.requiredLevel) {
registeredCommand.handle(entity, args);
} else {
// We don't need to tell normies they aren't high enough level
if (entity->GetGMLevel() == eGameMasterLevel::CIVILIAN) return;
std::ostringstream feedback;
feedback << "You are not high enough GM level to use " << std::quoted(command) << "";
GameMessages::SendSlashCommandFeedbackText(entity, GeneralUtils::ASCIIToUTF16(feedback.str()));
}
} else { } else {
// We don't need to tell normies they aren't high enough level // We don't need to tell normies commands don't exist
if (entity->GetGMLevel() == eGameMasterLevel::CIVILIAN) return; if (entity->GetGMLevel() == eGameMasterLevel::CIVILIAN) return;
std::ostringstream feedback; std::ostringstream feedback;
feedback << "You are not high enough GM level to use " << std::quoted(command) << ""; feedback << "Command " << std::quoted(command) << " does not exist!";
GameMessages::SendSlashCommandFeedbackText(entity, GeneralUtils::ASCIIToUTF16(feedback.str())); GameMessages::SendSlashCommandFeedbackText(entity, GeneralUtils::ASCIIToUTF16(feedback.str()));
} }
} else {
// We don't need to tell normies commands don't exist
if (entity->GetGMLevel() == eGameMasterLevel::CIVILIAN) return;
std::ostringstream feedback;
feedback << "Command " << std::quoted(command) << " does not exist!";
GameMessages::SendSlashCommandFeedbackText(entity, GeneralUtils::ASCIIToUTF16(feedback.str()));
} }
return; return;

View File

@ -13,19 +13,25 @@
class Entity; class Entity;
struct Command { struct Command {
Command(std::string description, std::string help, std::vector<std::string> commands, std::function<void(Entity*,const std::string)> handle); Command(std::string help, std::string info, std::vector<std::string> aliases, std::function<void(Entity*,const std::string)> handle, eGameMasterLevel requiredLevel = eGameMasterLevel::DEVELOPER) {
std::string description; this->help = help;
this->info = info;
this->aliases = aliases;
this->handle = handle;
this->requiredLevel = requiredLevel;
}
std::string help; std::string help;
std::vector<std::string> commands; std::string info;
eGameMasterLevel requiredLevel = eGameMasterLevel::DEVELOPER; std::vector<std::string> aliases;
std::function<void(Entity*,const std::string)> handle; std::function<void(Entity*,const std::string)> handle;
eGameMasterLevel requiredLevel = eGameMasterLevel::DEVELOPER;
}; };
namespace SlashCommandHandler { namespace SlashCommandHandler {
void Startup(); void Startup();
void HandleChatCommand(const std::u16string& command, Entity* entity, const SystemAddress& sysAddr); void HandleChatCommand(const std::u16string& command, Entity* entity, const SystemAddress& sysAddr);
void SendAnnouncement(const std::string& title, const std::string& message); void SendAnnouncement(const std::string& title, const std::string& message);
void RegisterCommand(Command info, std::string command); void RegisterCommand(Command info);
}; };
namespace DEVGMCommands { namespace DEVGMCommands {