Exemplo n.º 1
0
void Chat::sendHelp(User* user, std::deque<std::string> args)
{
  // TODO: Add paging support, since not all commands will fit into
  // the screen at once.

  CommandList* commandList = &m_guestCommands; // defaults
  std::string commandColor = MC_COLOR_BLUE;

  if(IS_ADMIN(user->permissions))
  {
    commandList = &m_adminCommands;
    commandColor = MC_COLOR_RED; // different color for admin commands
  }
  else if(IS_OP(user->permissions))
  {
    commandList = &m_opCommands;
    commandColor = MC_COLOR_GREEN;
  }
  else if(IS_MEMBER(user->permissions))
  {
    commandList = &m_memberCommands;
  }

  if(args.size() == 0)
  {
    for(CommandList::iterator it = commandList->begin();
        it != commandList->end();
        it++)
    {
      std::string args = it->second->arguments;
      std::string description = it->second->description;
      sendMsg(user, commandColor + CHATCMDPREFIX + it->first + " " + args + " : " + MC_COLOR_YELLOW + description, Chat::USER);
    }
  }
  else
  {
    CommandList::iterator iter;
    if((iter = commandList->find(args.front())) != commandList->end())
    {
      std::string args = iter->second->arguments;
      std::string description = iter->second->description;
      sendMsg(user, commandColor + CHATCMDPREFIX + iter->first + " " + args, Chat::USER);
      sendMsg(user, MC_COLOR_YELLOW + CHATCMDPREFIX + description, Chat::USER);
    }
    else
    {
      sendMsg(user, MC_COLOR_RED + "Unknown Command: " + args.front(), Chat::USER);
    }
  }
}
Exemplo n.º 2
0
bool chatCommandFunction(const char* userIn,const char* cmdIn, int argc, char** argv)
{
  std::string user(userIn);
  std::string command(cmdIn);
  std::deque<std::string> cmd(argv, argv+argc);

  if(command.size() == 0)
  {
    return false;
  }


  std::string logMsg = user + ": " + command;
  mineserver->logger.log(LOG_INFO, "plugin.commands", logMsg.c_str());

  // User commands
  CommandList::iterator iter;
  if((iter = m_Commands.find(command)) != m_Commands.end())
  {
    iter->second->callback(user, command, cmd);
    return true;
  }
  return false;
}