|
@@ -2,12 +2,14 @@
|
|
|
|
|
|
#include "Game.h"
|
|
|
#include "SaveCommand.h"
|
|
|
+#include "GrantCommand.h"
|
|
|
|
|
|
ChatCommandExecutor::ChatCommandExecutor()
|
|
|
: ReferenceCounter()
|
|
|
{
|
|
|
knownCommands.add(new SaveCommand());
|
|
|
-}
|
|
|
+ knownCommands.add(new CrantCommand());
|
|
|
+}
|
|
|
|
|
|
bool ChatCommandExecutor::execute(Framework::Text line, Entity* zActor)
|
|
|
{
|
|
@@ -22,7 +24,6 @@ bool ChatCommandExecutor::execute(Framework::Text line, Entity* zActor)
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
- // TODO: check security level
|
|
|
Framework::RCArray<Framework::Text> params;
|
|
|
int start = command->getName().getLength() + 2;
|
|
|
bool escaped = 0;
|
|
@@ -51,22 +52,49 @@ bool ChatCommandExecutor::execute(Framework::Text line, Entity* zActor)
|
|
|
escaped = !escaped;
|
|
|
}
|
|
|
}
|
|
|
+ if (start < line.getLength())
|
|
|
+ {
|
|
|
+ if (line.hatAt(start, "'")
|
|
|
+ && line.hatAt(line.getLength() - 1, "'"))
|
|
|
+ {
|
|
|
+ params.add(
|
|
|
+ line.getTeilText(start + 1, line.getLength() - 1));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ params.add(line.getTeilText(start, line.getLength()));
|
|
|
+ }
|
|
|
+ }
|
|
|
int index = 0;
|
|
|
for (ChatCommandParameter* param : command->getParams())
|
|
|
{
|
|
|
- if (params.getEintragAnzahl() > index && param->isLegalValue(*params.z(index)))
|
|
|
+ if (params.getEintragAnzahl() > index
|
|
|
+ && param->isLegalValue(*params.z(index)))
|
|
|
{
|
|
|
index++;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
+ bool isError = 0;
|
|
|
if (param->isOptional() && zActor)
|
|
|
{
|
|
|
- params.add(new Framework::Text(
|
|
|
- param->getDefaultValue(zActor)),
|
|
|
- index++);
|
|
|
+ Framework::Text defaultValue
|
|
|
+ = param->getDefaultValue(zActor);
|
|
|
+ if (!param->isLegalValue(defaultValue))
|
|
|
+ {
|
|
|
+ isError = 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ params.add(
|
|
|
+ new Framework::Text(defaultValue), index++);
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
+ {
|
|
|
+ isError = 1;
|
|
|
+ }
|
|
|
+ if (isError)
|
|
|
{
|
|
|
Framework::Text error
|
|
|
= "Illegal parameter at position ";
|
|
@@ -82,15 +110,8 @@ bool ChatCommandExecutor::execute(Framework::Text line, Entity* zActor)
|
|
|
}
|
|
|
error += "\n";
|
|
|
error += command->getHelp();
|
|
|
- if (zActor)
|
|
|
- {
|
|
|
- Game::INSTANCE->zChat()->sendMessageTo(
|
|
|
- error, zActor, Chat::CHANNEL_ERROR);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- std::cout << error << std::endl;
|
|
|
- }
|
|
|
+ Game::INSTANCE->zChat()->sendMessageTo(
|
|
|
+ error, zActor, Chat::CHANNEL_ERROR);
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
@@ -102,15 +123,24 @@ bool ChatCommandExecutor::execute(Framework::Text line, Entity* zActor)
|
|
|
error += *params.z(index);
|
|
|
error += "\n";
|
|
|
error += command->getHelp();
|
|
|
- if (zActor)
|
|
|
- {
|
|
|
- Game::INSTANCE->zChat()->sendMessageTo(
|
|
|
- error, zActor, Chat::CHANNEL_ERROR);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- std::cout << error << std::endl;
|
|
|
- }
|
|
|
+ Game::INSTANCE->zChat()->sendMessageTo(
|
|
|
+ error, zActor, Chat::CHANNEL_ERROR);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (zActor
|
|
|
+ && command->getSecurityLevel(params)
|
|
|
+ > zActor->getChatSecurityLevel())
|
|
|
+ {
|
|
|
+ Framework::Text error
|
|
|
+ = "This command requires a security level of at least ";
|
|
|
+ error += command->getSecurityLevel(params);
|
|
|
+ error += ". You have currently a security level of ";
|
|
|
+ error += zActor->getChatSecurityLevel();
|
|
|
+ error += ". Ask someone with the required security lavel "
|
|
|
+ "to grant you the same level.";
|
|
|
+ Game::INSTANCE->zChat()->sendMessageTo(
|
|
|
+ error, zActor, Chat::CHANNEL_ERROR);
|
|
|
+ return true;
|
|
|
}
|
|
|
command->execute(params, zActor);
|
|
|
return true;
|