GrantCommand.cpp 1.0 KB

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