Browse Source

HelpGameCommand now outputs in a format similar to HelpIRCCommand.

pull/3/head
JustinAJ 10 years ago
parent
commit
bb2b0e8c4e
  1. 54
      RenX.Commands/RenX_Commands.cpp

54
RenX.Commands/RenX_Commands.cpp

@ -1251,26 +1251,58 @@ void HelpGameCommand::create()
void HelpGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString &parameters) void HelpGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, const Jupiter::ReadableString &parameters)
{ {
Jupiter::StringL output = "Available Commands: "; RenX::GameCommand *cmd;
parameters.println(stdout); unsigned int cmdCount = 0;
auto getAccessCommands = [&](int accessLevel)
{
Jupiter::String list;
unsigned int i = 0;
while (i != source->getCommandCount())
{
cmd = source->getCommand(i++);
if (cmd->getAccessLevel() == accessLevel)
{
cmdCount++;
list.format("Access level %d commands: %.*s", accessLevel, cmd->getTrigger().size(), cmd->getTrigger().ptr());
break;
}
}
while (i != source->getCommandCount())
{
cmd = source->getCommand(i++);
if (cmd->getAccessLevel() == accessLevel)
{
cmdCount++;
list += ", ";
list += cmd->getTrigger();
}
}
return list;
};
if (parameters.wordCount(WHITESPACE) == 0) if (parameters.wordCount(WHITESPACE) == 0)
{ {
// We know there's at least one command, because of this command! for (int i = 0; i <= player->access; i++)
output += source->getCommand(0)->getTrigger();
for (unsigned int i = 1; i != source->getCommandCount(); i++)
{ {
output += ", "; Jupiter::ReadableString &msg = getAccessCommands(i);
output += source->getCommand(i)->getTrigger(); if (msg.isEmpty() == false)
source->sendMessage(player, getAccessCommands(i));
} }
if (cmdCount == 0)
source->sendMessage(player, STRING_LITERAL_AS_REFERENCE("No listed commands available."));
} }
else else
{ {
RenX::GameCommand *cmd = source->getCommand(Jupiter::ReferenceString::getWord(parameters, 0, WHITESPACE)); cmd = source->getCommand(Jupiter::ReferenceString::getWord(parameters, 0, WHITESPACE));
if (cmd != nullptr) if (cmd != nullptr)
output += cmd->getHelp(Jupiter::ReferenceString::gotoWord(parameters, 1, WHITESPACE)); {
else output += "Error: Command not found."; if (player->access >= cmd->getAccessLevel())
source->sendMessage(player, cmd->getHelp(Jupiter::ReferenceString::gotoWord(parameters, 1, WHITESPACE)));
else
source->sendMessage(player, STRING_LITERAL_AS_REFERENCE("Access Denied."));
}
else
source->sendMessage(player, STRING_LITERAL_AS_REFERENCE("Error: Command not found."));
} }
source->sendMessage(player, output);
} }
const Jupiter::ReadableString &HelpGameCommand::getHelp(const Jupiter::ReadableString &) const Jupiter::ReadableString &HelpGameCommand::getHelp(const Jupiter::ReadableString &)

Loading…
Cancel
Save