GrantCommand.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include "GrantCommand.h"
  2. #include "Chat.h"
  3. #include "Game.h"
  4. #include "Player.h"
  5. CrantCommand::CrantCommand()
  6. : ChatCommand("grant", "Grants a player a permission", 0)
  7. {
  8. addParam(new PlayerNameParameter());
  9. addParam(new IntegerParameter("securityLavel",
  10. "The security level to grant",
  11. true,
  12. [](Entity* actor) {
  13. if (actor) return actor->getChatSecurityLevel();
  14. return INT32_MAX;
  15. }));
  16. }
  17. void CrantCommand::execute(
  18. Framework::RCArray<Framework::Text> params, Entity* zActor) const
  19. {
  20. int securityLevel = (int)*params.z(1);
  21. Entity* zTarget = Game::INSTANCE->zPlayerByName(*params.z(0));
  22. if (zTarget)
  23. {
  24. zTarget->setChatSecurityLevel(securityLevel);
  25. Framework::Text message = "The security level of player ";
  26. message.append() << *params.z(0) << " is now set to " << securityLevel;
  27. Game::INSTANCE->zChat()->sendMessageTo(
  28. message, zActor, Chat::CHANNEL_INFO);
  29. }
  30. }
  31. int CrantCommand::getSecurityLevel(
  32. Framework::RCArray<Framework::Text> params) const
  33. {
  34. return (int)*params.z(1);
  35. }