GrantCommand.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. bool 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. return true;
  30. }
  31. return false;
  32. }
  33. int CrantCommand::getSecurityLevel(
  34. Framework::RCArray<Framework::Text> params) const
  35. {
  36. return (int)*params.z(1);
  37. }