|
@@ -1,12 +1,13 @@
|
|
#include "ChatCommand.h"
|
|
#include "ChatCommand.h"
|
|
|
|
|
|
|
|
+#include <AsynchronCall.h>
|
|
|
|
+
|
|
#include "Game.h"
|
|
#include "Game.h"
|
|
#include "Player.h"
|
|
#include "Player.h"
|
|
|
|
|
|
ChatCommand::ChatCommand(
|
|
ChatCommand::ChatCommand(
|
|
Framework::Text name, Framework::Text description, int securityLevel)
|
|
Framework::Text name, Framework::Text description, int securityLevel)
|
|
- : Framework::ReferenceCounter(),
|
|
|
|
- name(name),
|
|
|
|
|
|
+ : Framework::ConsoleCommand(name),
|
|
description(description),
|
|
description(description),
|
|
securityLevel(securityLevel)
|
|
securityLevel(securityLevel)
|
|
{}
|
|
{}
|
|
@@ -16,20 +17,55 @@ void ChatCommand::addParam(ChatCommandParameter* param)
|
|
params.add(param);
|
|
params.add(param);
|
|
}
|
|
}
|
|
|
|
|
|
-const Framework::RCArray<ChatCommandParameter>& ChatCommand::getParams() const
|
|
|
|
|
|
+bool ChatCommand::execute(Framework::RCArray<Framework::Text>& params) const
|
|
{
|
|
{
|
|
- return params;
|
|
|
|
|
|
+ return execute(params, 0);
|
|
}
|
|
}
|
|
|
|
|
|
-Framework::Text ChatCommand::getName() const
|
|
|
|
|
|
+void ChatCommand::addAutocompletePossibilities(
|
|
|
|
+ const Framework::RCArray<Framework::Text>& args,
|
|
|
|
+ bool appendToLast,
|
|
|
|
+ Framework::RCArray<Framework::Text>& possibilities) const
|
|
{
|
|
{
|
|
- return name;
|
|
|
|
|
|
+ int index
|
|
|
|
+ = appendToLast ? args.getEintragAnzahl() - 1 : args.getEintragAnzahl();
|
|
|
|
+ if (index < 0 || index >= params.getEintragAnzahl()) return;
|
|
|
|
+ for (Framework::Text* possibility : params.z(index)->getAutocompleteValues(
|
|
|
|
+ appendToLast ? *args.z(args.getEintragAnzahl() - 1)
|
|
|
|
+ : Framework::Text("")))
|
|
|
|
+ {
|
|
|
|
+ possibilities.add(
|
|
|
|
+ dynamic_cast<Framework::Text*>(possibility->getThis()));
|
|
|
|
+ }
|
|
|
|
+ if (possibilities.getEintragAnzahl() == 0
|
|
|
|
+ || (possibilities.getEintragAnzahl() == 1 && appendToLast
|
|
|
|
+ && possibilities.z(0)->istGleich(
|
|
|
|
+ args.get(args.getEintragAnzahl() - 1))))
|
|
|
|
+ {
|
|
|
|
+ Framework::Text help = getHelp();
|
|
|
|
+ while (help.hat("\n"))
|
|
|
|
+ {
|
|
|
|
+ Framework::Text* line = help.getTeilText(0, help.positionVon("\n"));
|
|
|
|
+ Framework::Logging::info() << line->getText();
|
|
|
|
+ help.remove(0, line->getLength() + 1);
|
|
|
|
+ line->release();
|
|
|
|
+ }
|
|
|
|
+ if (help.getLength() > 0)
|
|
|
|
+ {
|
|
|
|
+ Framework::Logging::info() << help;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+const Framework::RCArray<ChatCommandParameter>& ChatCommand::getParams() const
|
|
|
|
+{
|
|
|
|
+ return params;
|
|
}
|
|
}
|
|
|
|
|
|
Framework::Text ChatCommand::getHelp() const
|
|
Framework::Text ChatCommand::getHelp() const
|
|
{
|
|
{
|
|
Framework::Text result = "/";
|
|
Framework::Text result = "/";
|
|
- result += name;
|
|
|
|
|
|
+ result += getName();
|
|
|
|
|
|
for (ChatCommandParameter* param : params)
|
|
for (ChatCommandParameter* param : params)
|
|
{
|
|
{
|
|
@@ -95,6 +131,12 @@ bool ChatCommandParameter::isOptional() const
|
|
return optional;
|
|
return optional;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+Framework::RCArray<Framework::Text> ChatCommandParameter::getAutocompleteValues(
|
|
|
|
+ const Framework::Text& current) const
|
|
|
|
+{
|
|
|
|
+ return Framework::RCArray<Framework::Text>();
|
|
|
|
+}
|
|
|
|
+
|
|
PlayerNameParameter::PlayerNameParameter()
|
|
PlayerNameParameter::PlayerNameParameter()
|
|
: ChatCommandParameter(
|
|
: ChatCommandParameter(
|
|
"player", "The name of the player (has to be online)", 0)
|
|
"player", "The name of the player (has to be online)", 0)
|
|
@@ -112,6 +154,23 @@ Framework::Text PlayerNameParameter::getDefaultValue(Entity* zActor) const
|
|
return "";
|
|
return "";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+Framework::RCArray<Framework::Text> PlayerNameParameter::getAutocompleteValues(
|
|
|
|
+ const Framework::Text& current) const
|
|
|
|
+{
|
|
|
|
+ Framework::RCArray<Framework::Text> result;
|
|
|
|
+ Game::INSTANCE->listPlayerNames(result);
|
|
|
|
+ for (auto iterator = result.begin(); iterator;)
|
|
|
|
+ {
|
|
|
|
+ if (iterator->hatAt(0, current))
|
|
|
|
+ {
|
|
|
|
+ iterator.remove();
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ ++iterator;
|
|
|
|
+ }
|
|
|
|
+ return result;
|
|
|
|
+}
|
|
|
|
+
|
|
IntegerParameter::IntegerParameter(Framework::Text name,
|
|
IntegerParameter::IntegerParameter(Framework::Text name,
|
|
Framework::Text description,
|
|
Framework::Text description,
|
|
bool optional,
|
|
bool optional,
|