예제 #1
0
파일: Level0.cpp 프로젝트: chrayn/mangos-06
bool ChatHandler::ShowHelpForCommand(ChatCommand *table, const char* cmd)
{
    for(uint32 i = 0; table[i].Name != NULL; i++)
    {
        if(!hasStringAbbr(table[i].Name, cmd))
            continue;

        if(m_session->GetSecurity() < table[i].SecurityLevel)
            continue;

        if(table[i].ChildCommands != NULL)
        {
            cmd = strtok(NULL, " ");
            if(cmd && ShowHelpForCommand(table[i].ChildCommands, cmd))
                return true;
        }

        if(table[i].Help == "")
        {
            SendSysMessage(LANG_NO_HELP_CMD);
            return true;
        }

        SendSysMultilineMessage(table[i].Help.c_str());

        return true;
    }

    return false;
}
예제 #2
0
파일: Level1.cpp 프로젝트: Artea/mangos-svn
bool ChatHandler::HandleSearchTeleCommand(const char * args)
{
    QueryResult *result;
    if(!*args)
    {
        SendSysMessage("Requires search parameter.");
        return true;
    }
    char const* str = strtok((char*)args, " ");
    result = sDatabase.PQuery("SELECT `name` FROM `game_tele` WHERE `name` LIKE '%%%s%%'",str);
    if (!result)
    {
        SendSysMessage("There are no teleport locations matching your request.");
        return true;
    }
    std::string reply;
    for (uint64 i=0; i < result->GetRowCount(); i++)
    {
        Field *fields = result->Fetch();
        reply += "  ";
        reply += fields[0].GetCppString();
        reply += '\n';
        result->NextRow();
    }
    delete result;

    if(reply.empty())
        SendSysMessage("None locations found.");
    else
    {
        reply = "Locations found are:\n" + reply;
        SendSysMultilineMessage(reply.c_str());
    }
    return true;
}
예제 #3
0
파일: Chat.cpp 프로젝트: Artea/mangos-svn
void ChatHandler::PSendSysMultilineMessage(const char *format, ...)
{
    va_list ap;
    char str [1024];
    va_start(ap, format);
    vsnprintf(str,1024,format, ap );
    va_end(ap);
    SendSysMultilineMessage(m_session,str);
}
예제 #4
0
파일: Level1.cpp 프로젝트: Artea/mangos-svn
bool ChatHandler::HandleLookupTeleCommand(const char * args)
{
    QueryResult *result;
    if(!*args)
    {
        SendSysMessage(LANG_COMMAND_TELE_PARAMETER);
        return true;
    }
    char const* str = strtok((char*)args, " ");
    if(!str)
        return false;

    std::string namepart = str;
    sDatabase.escape_string(namepart);
    result = sDatabase.PQuery("SELECT `name` FROM `game_tele` WHERE `name` LIKE '%%%s%%'",namepart.c_str());
    if (!result)
    {
        SendSysMessage(LANG_COMMAND_TELE_NOREQUEST);
        return true;
    }
    std::string reply;
    for (uint64 i=0; i < result->GetRowCount(); i++)
    {
        Field *fields = result->Fetch();
        reply += "  |cffffffff|Htele:";
        reply += fields[0].GetCppString();
        reply += "|h[";
        reply += fields[0].GetCppString();
        reply += "]|h|r\n";
        result->NextRow();
    }
    delete result;

    if(reply.empty())
        SendSysMessage(LANG_COMMAND_TELE_NOLOCATION);
    else
    {
        reply = LANG_COMMAND_TELE_LOCATION + reply;
        SendSysMultilineMessage(reply.c_str());
    }
    return true;
}
예제 #5
0
파일: Chat.cpp 프로젝트: Artea/mangos-svn
bool ChatHandler::ExecuteCommandInTable(ChatCommand *table, const char* text)
{
    char const* oldtext = text;
    std::string fullcmd = text;                             // original `text` can't be used. It content destroyed in command code processing.
    std::string cmd = "";

    while (*text != ' ' && *text != '\0')
    {
        cmd += *text;
        text++;
    }

    while (*text == ' ') text++;

    if(!cmd.length())
        return false;

    for(uint32 i = 0; table[i].Name != NULL; i++)
    {
        // allow pass "" command name in table
        if(strlen(table[i].Name) && !hasStringAbbr(table[i].Name, cmd.c_str()))
            continue;

        // select subcommand from child commands list
        if(table[i].ChildCommands != NULL)
        {
            if(!ExecuteCommandInTable(table[i].ChildCommands, text))
            {
                if(table[i].Help != "")
                    SendSysMultilineMessage(table[i].Help.c_str());
                else
                    SendSysMessage(LANG_NO_SUBCMD);
            }

            return true;
        }

        // check security level only for simple  command (without child commands)
        if(m_session->GetSecurity() < table[i].SecurityLevel)
            continue;

        // table[i].Name == "" is special case: send original command to handler
        if((this->*(table[i].Handler))(strlen(table[i].Name)!=0 ? text : oldtext))
        {
            if(table[i].SecurityLevel > 0)
            {
                Player* p = m_session->GetPlayer();
                uint64 sel_guid = p->GetSelection();
                sLog.outCommand("Command: %s [Player: %s (Account: %u) X: %f Y: %f Z: %f Map: %u Selected: %s (GUID: %u)]",
                    fullcmd.c_str(),p->GetName(),m_session->GetAccountId(),p->GetPositionX(),p->GetPositionY(),p->GetPositionZ(),p->GetMapId(),
                    (GUID_HIPART(sel_guid)==HIGHGUID_UNIT ? "creature" : (sel_guid !=0 ? "player" : "none")),
                    GUID_LOPART(sel_guid));
            }
        }
        else
        {
            if(table[i].Help != "")
                SendSysMultilineMessage(table[i].Help.c_str());
            else
                SendSysMessage(LANG_CMD_SYNTAX);
        }

        return true;
    }

    return false;
}