Show
Ignore:
Timestamp:
11/19/08 13:37:14 (17 years ago)
Author:
yumileroy
Message:

[svn] * Merge CLI Commands with regular commands and give them level4 access. sec_console. Source mangos - thanks to ogeraisi for the amalgamated patch.
* Redid/Fixed/Added some lang strings.
* As usual remember this is a trunk rev so stability only guaranteed on northern countries of Mars and western parts of Pluto. No warranties outside the solar system, sorry :( . Check with your local government or dictator on regulations regarding export.

Original author: KingPin?
Date: 2008-10-26 13:32:42-05:00

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/game/Level3.cpp

    r102 r112  
    5353#include "InstanceSaveMgr.h" 
    5454#include "InstanceData.h" 
     55#include "AccountMgr.h" 
    5556 
    5657//reload commands 
     
    682683} 
    683684 
    684 bool ChatHandler::HandleSecurityCommand(const char* args) 
     685bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args) 
    685686{ 
    686687    char* arg1 = strtok((char*)args, " "); 
     
    688689        return false; 
    689690 
    690     char* arg2 = 0; 
    691  
    692     std::string targetName; 
     691    char* arg2 = strtok(NULL, " "); 
     692 
     693    std::string targetAccountName; 
    693694    uint32 targetAccountId = 0; 
    694695    uint32 targetSecurity = 0; 
    695696 
     697        /// only target player different from self allowed (if targetPlayer!=NULL then not console) 
    696698    Player* targetPlayer = getSelectedPlayer(); 
    697     if(targetPlayer) 
    698     { 
    699         targetName = targetPlayer->GetName(); 
     699    if(targetPlayer && m_session->GetPlayer()!=targetPlayer) 
     700    { 
     701        /// wrong command syntax or unexpected targeting 
     702                if(arg2) 
     703                        return false; 
     704 
    700705        targetAccountId = targetPlayer->GetSession()->GetAccountId(); 
    701706        targetSecurity = targetPlayer->GetSession()->GetSecurity(); 
    702         arg2 = arg1; 
     707        if(!accmgr.GetName(targetAccountId,targetAccountName)) 
     708                { 
     709                        PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str()); 
     710                        SetSentErrorMessage(true); 
     711                        return false; 
     712                } 
    703713    } 
    704714    else 
    705715    { 
    706         targetName = arg1; 
    707         if(!normalizePlayerName(targetName)) 
     716        targetAccountName = arg1; 
     717        if(!AccountMgr::normilizeString(targetAccountName)) 
    708718        { 
    709             SendSysMessage(LANG_PLAYER_NOT_FOUND); 
     719            PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str()); 
    710720            SetSentErrorMessage(true); 
    711721            return false; 
    712722        } 
    713723 
    714         targetPlayer = ObjectAccessor::Instance().FindPlayerByName(targetName.c_str()); 
    715         if(targetPlayer) 
    716         { 
    717             targetAccountId = targetPlayer->GetSession()->GetAccountId(); 
    718             targetSecurity = targetPlayer->GetSession()->GetSecurity(); 
    719         } 
    720         else 
    721         { 
    722             uint64 targetGUID = objmgr.GetPlayerGUIDByName(targetName.c_str()); 
    723             if(!targetGUID) 
    724             { 
    725                 SendSysMessage(LANG_PLAYER_NOT_FOUND); 
    726                 SetSentErrorMessage(true); 
    727                 return false; 
    728             } 
    729             targetAccountId = objmgr.GetPlayerAccountIdByGUID(targetGUID); 
    730             targetSecurity = accmgr.GetSecurity(targetAccountId); 
    731         } 
    732  
    733         arg2 = strtok(NULL, " "); 
     724        targetAccountId = accmgr.GetId(targetAccountName); 
     725                targetSecurity = accmgr.GetSecurity(targetAccountId); 
    734726    } 
    735727 
     
    742734    } 
    743735 
    744     // can set security level only for target with less security and to less security that we have 
    745     if(targetSecurity >= m_session->GetSecurity() || uint32(gm) >= m_session->GetSecurity() ) 
     736    /// m_session==NULL only for console 
     737        uint32 plSecurity = m_session ? m_session->GetSecurity() : SEC_CONSOLE; 
     738 
     739        /// can set security level only for target with less security and to less security that we have 
     740        /// This is also reject self apply in fact 
     741        if(targetSecurity >= plSecurity || uint32(gm) >= plSecurity ) 
    746742    { 
    747743        SendSysMessage(LANG_YOURS_SECURITY_IS_LOW); 
     
    752748    if(targetPlayer) 
    753749    { 
    754         if( targetPlayer != m_session->GetPlayer() ) 
    755             ChatHandler(targetPlayer).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED,m_session->GetPlayer()->GetName(), gm); 
    756  
     750        ChatHandler(targetPlayer).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED,m_session->GetPlayer()->GetName(), gm); 
    757751        targetPlayer->GetSession()->SetSecurity(gm); 
    758752    } 
    759753 
    760     PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetName.c_str(), gm); 
     754    PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm); 
    761755    loginDatabase.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm, targetAccountId); 
    762756 
    763757    return true; 
     758} 
     759 
     760/// Set password for account 
     761bool ChatHandler::HandleAccountSetPasswordCommand(const char* args) 
     762{ 
     763        if(!*args) 
     764                return false; 
     765 
     766        ///- Get the command line arguments 
     767        char *szAccount = strtok ((char*)args," "); 
     768        char *szPassword1 =  strtok (NULL," "); 
     769        char *szPassword2 =  strtok (NULL," "); 
     770 
     771        if (!szAccount||!szPassword1 || !szPassword2) 
     772                return false; 
     773 
     774        std::string account_name = szAccount; 
     775        if(!AccountMgr::normilizeString(account_name)) 
     776        { 
     777                PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str()); 
     778                SetSentErrorMessage(true); 
     779                return false; 
     780        } 
     781 
     782        uint32 targetAccountId = accmgr.GetId(account_name); 
     783        if (!targetAccountId) 
     784        { 
     785                PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str()); 
     786                SetSentErrorMessage(true); 
     787                return false; 
     788        } 
     789 
     790        uint32 targetSecurity = accmgr.GetSecurity(targetAccountId); 
     791 
     792        /// m_session==NULL only for console 
     793        uint32 plSecurity = m_session ? m_session->GetSecurity() : SEC_CONSOLE; 
     794 
     795        /// can set password only for target with less security 
     796        /// This is also reject self apply in fact 
     797        if (targetSecurity >= plSecurity) 
     798        { 
     799                SendSysMessage (LANG_YOURS_SECURITY_IS_LOW); 
     800                SetSentErrorMessage (true); 
     801                return false; 
     802        } 
     803 
     804        if (strcmp(szPassword1,szPassword2)) 
     805        { 
     806                SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH); 
     807                SetSentErrorMessage (true); 
     808                return false; 
     809        } 
     810 
     811        AccountOpResult result = accmgr.ChangePassword(targetAccountId, szPassword1); 
     812 
     813        switch(result) 
     814        { 
     815                case AOR_OK: 
     816                        SendSysMessage(LANG_COMMAND_PASSWORD); 
     817                        break; 
     818                case AOR_NAME_NOT_EXIST: 
     819                        PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str()); 
     820                        SetSentErrorMessage(true); 
     821                        return false; 
     822                case AOR_PASS_TOO_LONG: 
     823                        SendSysMessage(LANG_PASSWORD_TOO_LONG); 
     824                        SetSentErrorMessage(true); 
     825                        return false; 
     826                default: 
     827                        SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD); 
     828                        SetSentErrorMessage(true); 
     829                        return false; 
     830        } 
     831 
     832        return true; 
    764833} 
    765834 
     
    19772046    if(!cId) 
    19782047        return false; 
     2048 
    19792049    uint32 item_id = atol(cId); 
    1980  
    1981     ItemPrototype const* itemProto = item_id ? itemProto = objmgr.GetItemPrototype(item_id) : NULL; 
    1982  
     2050        if(!item_id) 
     2051        { 
     2052                PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id); 
     2053                SetSentErrorMessage(true); 
     2054                return false; 
     2055        } 
     2056 
     2057        ItemPrototype const* itemProto = objmgr.GetItemPrototype(item_id); 
    19832058    if(!itemProto) 
    19842059    { 
     
    21362211    } 
    21372212 
    2138     if(inv_count+mail_count+auc_count == 0) 
     2213    // guild bank case 
     2214        uint32 guild_count = 0; 
     2215        result=CharacterDatabase.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id); 
     2216        if(result) 
     2217        { 
     2218                guild_count = (*result)[0].GetUInt32(); 
     2219                delete result; 
     2220        } 
     2221 
     2222        result=CharacterDatabase.PQuery( 
     2223                //      0             1           2 
     2224                "SELECT gi.item_guid, gi.guildid, guild.name " 
     2225                "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ", 
     2226                item_id,uint32(count)); 
     2227 
     2228        if(result) 
     2229        { 
     2230                do 
     2231                { 
     2232                        Field *fields = result->Fetch(); 
     2233                        uint32 item_guid = fields[0].GetUInt32(); 
     2234                        uint32 guild_guid = fields[1].GetUInt32(); 
     2235                        std::string guild_name = fields[2].GetCppString(); 
     2236 
     2237                        char const* item_pos = "[in guild bank]"; 
     2238 
     2239                        PSendSysMessage(LANG_ITEMLIST_GUILD,item_guid,guild_name.c_str(),guild_guid,item_pos); 
     2240                } while (result->NextRow()); 
     2241 
     2242                int64 res_count = result->GetRowCount(); 
     2243 
     2244                delete result; 
     2245 
     2246                if(count > res_count) 
     2247                        count-=res_count; 
     2248                else if(count) 
     2249                        count = 0; 
     2250        } 
     2251 
     2252        if(inv_count+mail_count+auc_count+guild_count == 0) 
    21392253    { 
    21402254        SendSysMessage(LANG_COMMAND_NOITEMFOUND); 
     
    21432257    } 
    21442258 
    2145     PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE,item_id,inv_count+mail_count+auc_count,inv_count,mail_count,auc_count); 
     2259    PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE,item_id,inv_count+mail_count+auc_count+guild_count,inv_count,mail_count,auc_count,guild_count); 
    21462260 
    21472261    return true; 
     
    21532267        return false; 
    21542268 
    2155                                                             // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r 
     2269    // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r 
    21562270    char* cId = extractKeyFromLink((char*)args,"Hgameobject_entry"); 
    21572271    if(!cId) 
     
    21592273 
    21602274    uint32 go_id = atol(cId); 
     2275        if(!go_id) 
     2276        { 
     2277                PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id); 
     2278                SetSentErrorMessage(true); 
     2279                return false; 
     2280        } 
    21612281 
    21622282    GameObjectInfo const * gInfo = objmgr.GetGameObjectInfo(go_id); 
    2163  
    2164     if(!go_id || !gInfo) 
     2283        if(!gInfo) 
    21652284    { 
    21662285        PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id); 
     
    21752294        return false; 
    21762295 
    2177     Player* pl = m_session->GetPlayer(); 
    21782296    QueryResult *result; 
    21792297 
     
    21862304    } 
    21872305 
    2188     result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM gameobject WHERE id = '%u' ORDER BY order_ ASC LIMIT %u", 
    2189         pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),go_id,uint32(count)); 
     2306    if(m_session) 
     2307        { 
     2308                Player* pl = m_session->GetPlayer(); 
     2309                result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM gameobject WHERE id = '%u' ORDER BY order_ ASC LIMIT %u", 
     2310                        pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),go_id,uint32(count)); 
     2311        } 
     2312        else 
     2313                result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u", 
     2314                go_id,uint32(count)); 
    21902315 
    21912316    if (result) 
     
    22002325            int mapid = fields[4].GetUInt16(); 
    22012326 
    2202             PSendSysMessage(LANG_GO_LIST, guid, guid, gInfo->name, x, y, z, mapid); 
     2327            if (m_session) 
     2328                                PSendSysMessage(LANG_GO_LIST_CHAT, guid, guid, gInfo->name, x, y, z, mapid); 
     2329                        else 
     2330                                PSendSysMessage(LANG_GO_LIST_CONSOLE, guid, gInfo->name, x, y, z, mapid); 
    22032331        } while (result->NextRow()); 
    22042332 
     
    22392367                continue; 
    22402368 
    2241             PSendSysMessage(LANG_GO_LIST, guid, guid, gInfo->name, x, y, z, mapid); 
     2369            PSendSysMessage(LANG_GO_LIST_CHAT, guid, guid, gInfo->name, x, y, z, mapid); 
    22422370 
    22432371            ++count; 
     
    22942422        return false; 
    22952423 
    2296                                                             // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r 
     2424    // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r 
    22972425    char* cId = extractKeyFromLink((char*)args,"Hcreature_entry"); 
    22982426    if(!cId) 
     
    23002428 
    23012429    uint32 cr_id = atol(cId); 
     2430        if(!cr_id) 
     2431        { 
     2432                PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id); 
     2433                SetSentErrorMessage(true); 
     2434                return false; 
     2435        } 
    23022436 
    23032437    CreatureInfo const* cInfo = objmgr.GetCreatureTemplate(cr_id); 
    2304  
    2305     if(!cr_id || !cInfo) 
     2438        if(!cInfo) 
    23062439    { 
    23072440        PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id); 
     
    23162449        return false; 
    23172450 
    2318     Player* pl = m_session->GetPlayer(); 
    23192451    QueryResult *result; 
    23202452 
     
    23272459    } 
    23282460 
    2329     result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM creature WHERE id = '%u' ORDER BY order_ ASC LIMIT %u", 
    2330         pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(), cr_id,uint32(count)); 
     2461    if(m_session) 
     2462        { 
     2463                Player* pl = m_session->GetPlayer(); 
     2464                result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM creature WHERE id = '%u' ORDER BY order_ ASC LIMIT %u", 
     2465                        pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(), cr_id,uint32(count)); 
     2466        } 
     2467        else 
     2468                result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u", 
     2469                        cr_id,uint32(count)); 
    23312470 
    23322471    if (result) 
     
    23412480            int mapid = fields[4].GetUInt16(); 
    23422481 
    2343             PSendSysMessage(LANG_CREATURE_LIST, guid, guid, cInfo->Name, x, y, z, mapid); 
     2482            if  (m_session) 
     2483                                PSendSysMessage(LANG_CREATURE_LIST_CHAT, guid, guid, cInfo->Name, x, y, z, mapid); 
     2484                        else 
     2485                                PSendSysMessage(LANG_CREATURE_LIST_CONSOLE, guid, cInfo->Name, x, y, z, mapid); 
    23442486        } while (result->NextRow()); 
    23452487 
     
    23742516            continue; 
    23752517 
    2376         int loc_idx = m_session->GetSessionDbLocaleIndex(); 
     2518        int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex(); 
    23772519        if ( loc_idx >= 0 ) 
    23782520        { 
     
    23862528                    if (Utf8FitTo(name, wnamepart)) 
    23872529                    { 
    2388                         PSendSysMessage(LANG_ITEM_LIST, id, id, name.c_str()); 
     2530                        if (m_session) 
     2531                                                        PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str()); 
     2532                                                else 
     2533                                                        PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str()); 
    23892534                        ++counter; 
    23902535                        continue; 
     
    24002545        if (Utf8FitTo(name, wnamepart)) 
    24012546        { 
    2402             PSendSysMessage(LANG_ITEM_LIST, id, id, name.c_str()); 
     2547            if (m_session) 
     2548                                PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str()); 
     2549                        else 
     2550                                PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str()); 
    24032551            ++counter; 
    24042552        } 
     
    24332581        if(set) 
    24342582        { 
    2435             int loc = m_session->GetSessionDbcLocale(); 
    2436             std::string name = set->name[m_session->GetSessionDbcLocale()]; 
     2583            int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale(); 
     2584                        std::string name = set->name[loc]; 
    24372585            if(name.empty()) 
    24382586                continue; 
     
    24432591                for(; loc < MAX_LOCALE; ++loc) 
    24442592                { 
    2445                     if(loc==m_session->GetSessionDbcLocale()) 
     2593                    if(m_session && loc==m_session->GetSessionDbcLocale()) 
    24462594                        continue; 
    24472595 
    2448                     name = set->name[m_session->GetSessionDbcLocale()]; 
     2596                    name = set->name[loc]; 
    24492597                    if(name.empty()) 
    24502598                        continue; 
     
    24582606            { 
    24592607                // send item set in "id - [namedlink locale]" format 
    2460                 PSendSysMessage(LANG_ITEMSET_LIST,id,id,name.c_str(),localeNames[loc]); 
     2608                if (m_session) 
     2609                                        PSendSysMessage(LANG_ITEMSET_LIST_CHAT,id,id,name.c_str(),localeNames[loc]); 
     2610                                else 
     2611                                        PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE,id,name.c_str(),localeNames[loc]); 
    24612612                ++counter; 
    24622613            } 
     
    24702621bool ChatHandler::HandleLookupSkillCommand(const char* args) 
    24712622{ 
    2472     Player* target = getSelectedPlayer(); 
    2473     if(!target) 
    2474     { 
    2475         SendSysMessage(LANG_PLAYER_NOT_FOUND); 
    2476         SetSentErrorMessage(true); 
    2477         return false; 
    2478     } 
    2479  
    2480     if(!*args) 
    2481         return false; 
     2623        if (!*args) 
     2624        return false; 
     2625 
     2626        // can be NULL in console call 
     2627        Player* target = getSelectedPlayer(); 
    24822628 
    24832629    std::string namepart = args; 
     
    24982644        if(skillInfo) 
    24992645        { 
    2500             int loc = m_session->GetSessionDbcLocale(); 
     2646            int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale(); 
    25012647            std::string name = skillInfo->name[loc]; 
    25022648            if(name.empty()) 
     
    25082654                for(; loc < MAX_LOCALE; ++loc) 
    25092655                { 
    2510                     if(loc==m_session->GetSessionDbcLocale()) 
     2656                    if(m_session && loc==m_session->GetSessionDbcLocale()) 
    25112657                        continue; 
    25122658 
     
    25222668            if(loc < MAX_LOCALE) 
    25232669            { 
     2670                                char const* knownStr = ""; 
     2671                                if(target && target->HasSkill(id)) 
     2672                                        knownStr = GetTrinityString(LANG_KNOWN); 
     2673 
    25242674                // send skill in "id - [namedlink locale]" format 
    2525                 PSendSysMessage(LANG_SKILL_LIST,id,id,name.c_str(),localeNames[loc],(target->HasSkill(id) ? m_session->GetTrinityString(LANG_KNOWN) : "")); 
     2675                if (m_session) 
     2676                                        PSendSysMessage(LANG_SKILL_LIST_CHAT,id,id,name.c_str(),localeNames[loc],knownStr); 
     2677                                else 
     2678                                        PSendSysMessage(LANG_SKILL_LIST_CONSOLE,id,name.c_str(),localeNames[loc],knownStr); 
    25262679 
    25272680                ++counter; 
     
    25362689bool ChatHandler::HandleLookupSpellCommand(const char* args) 
    25372690{ 
    2538     Player* target = getSelectedPlayer(); 
    2539     if( !target ) 
    2540     { 
    2541         SendSysMessage(LANG_PLAYER_NOT_FOUND); 
    2542         SetSentErrorMessage(true); 
    2543         return false; 
    2544     } 
    2545  
    2546     if(!*args) 
    2547         return false; 
     2691        if (!*args) 
     2692        return false; 
     2693 
     2694        // can be NULL at console call 
     2695        Player* target = getSelectedPlayer(); 
    25482696 
    25492697    std::string namepart = args; 
     
    25642712        if(spellInfo) 
    25652713        { 
    2566             int loc = m_session->GetSessionDbcLocale(); 
     2714            int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale(); 
    25672715            std::string name = spellInfo->SpellName[loc]; 
    25682716            if(name.empty()) 
     
    25742722                for(; loc < MAX_LOCALE; ++loc) 
    25752723                { 
    2576                     if(loc==m_session->GetSessionDbcLocale()) 
     2724                    if(m_session && loc==m_session->GetSessionDbcLocale()) 
    25772725                        continue; 
    25782726 
     
    25882736            if(loc < MAX_LOCALE) 
    25892737            { 
    2590                 bool known = target->HasSpell(id); 
     2738                bool known = target && target->HasSpell(id); 
    25912739                bool learn = (spellInfo->Effect[0] == SPELL_EFFECT_LEARN_SPELL); 
    25922740 
     
    25952743                bool talent = (telentCost > 0); 
    25962744                bool passive = IsPassiveSpell(id); 
    2597                 bool active = target->HasAura(id,0) || target->HasAura(id,1) || target->HasAura(id,2); 
     2745                bool active = target && (target->HasAura(id,0) || target->HasAura(id,1) || target->HasAura(id,2)); 
    25982746 
    25992747                // unit32 used to prevent interpreting uint8 as char at output 
     
    26032751                // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format 
    26042752                std::ostringstream ss; 
    2605                 ss << id << " - |cffffffff|Hspell:" << id << "|h[" << name; 
     2753                if (m_session) 
     2754                                        ss << id << " - |cffffffff|Hspell:" << id << "|h[" << name; 
     2755                                else 
     2756                                        ss << id << " - " << name; 
    26062757 
    26072758                // include rank in link name 
     
    26092760                    ss << GetTrinityString(LANG_SPELL_RANK) << rank; 
    26102761 
    2611                 ss << " " << localeNames[loc] << "]|h|r"; 
     2762                if (m_session) 
     2763                                        ss << " " << localeNames[loc] << "]|h|r"; 
     2764                                else 
     2765                                        ss << " " << localeNames[loc]; 
    26122766 
    26132767                if(talent) 
     
    26352789bool ChatHandler::HandleLookupQuestCommand(const char* args) 
    26362790{ 
    2637     Player* target = getSelectedPlayer(); 
    2638     if( !target ) 
    2639     { 
    2640         SendSysMessage(LANG_PLAYER_NOT_FOUND); 
    2641         SetSentErrorMessage(true); 
    2642         return false; 
    2643     } 
    2644  
    2645     if(!*args) 
    2646         return false; 
     2791        if (!*args) 
     2792        return false; 
     2793 
     2794        // can be NULL at console call 
     2795        Player* target = getSelectedPlayer(); 
    26472796 
    26482797    std::string namepart = args; 
     
    26622811        Quest * qinfo = iter->second; 
    26632812 
    2664         int loc_idx = m_session->GetSessionDbLocaleIndex(); 
     2813        int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex(); 
    26652814        if ( loc_idx >= 0 ) 
    26662815        { 
     
    26742823                    if (Utf8FitTo(title, wnamepart)) 
    26752824                    { 
    2676                         QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId()); 
    2677  
    26782825                        char const* statusStr = ""; 
    2679                         if(status == QUEST_STATUS_COMPLETE) 
     2826 
     2827                                                if(target) 
    26802828                        { 
    2681                             if(target->GetQuestRewardStatus(qinfo->GetQuestId())) 
    2682                                 statusStr = GetTrinityString(LANG_COMMAND_QUEST_REWARDED); 
    2683                             else 
    2684                                 statusStr = GetTrinityString(LANG_COMMAND_QUEST_COMPLETE); 
     2829                            QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId()); 
     2830 
     2831                                                        if(status == QUEST_STATUS_COMPLETE) 
     2832                                                        { 
     2833                                                                if(target->GetQuestRewardStatus(qinfo->GetQuestId())) 
     2834                                                                        statusStr = GetTrinityString(LANG_COMMAND_QUEST_REWARDED); 
     2835                                                                else 
     2836                                                                        statusStr = GetTrinityString(LANG_COMMAND_QUEST_COMPLETE); 
     2837                                                        } 
     2838                                                        else if(status == QUEST_STATUS_INCOMPLETE) 
     2839                                                                statusStr = GetTrinityString(LANG_COMMAND_QUEST_ACTIVE); 
    26852840                        } 
    2686                         else if(status == QUEST_STATUS_INCOMPLETE) 
    2687                             statusStr = GetTrinityString(LANG_COMMAND_QUEST_ACTIVE); 
    2688  
    2689                         PSendSysMessage(LANG_QUEST_LIST,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),(status == QUEST_STATUS_COMPLETE ? GetTrinityString(LANG_COMPLETE) : (status == QUEST_STATUS_INCOMPLETE ? GetTrinityString(LANG_ACTIVE) : "") )); 
     2841                         
     2842                                                if (m_session) 
     2843                                                        PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),statusStr); 
     2844                                                else 
     2845                                                        PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr); 
     2846 
    26902847                        ++counter; 
    26912848                        continue; 
     
    27012858        if (Utf8FitTo(title, wnamepart)) 
    27022859        { 
    2703             QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId()); 
    2704  
    27052860            char const* statusStr = ""; 
    2706             if(status == QUEST_STATUS_COMPLETE) 
     2861             
     2862                        if(target) 
    27072863            { 
    2708                 if(target->GetQuestRewardStatus(qinfo->GetQuestId())) 
    2709                     statusStr = GetTrinityString(LANG_COMMAND_QUEST_REWARDED); 
    2710                 else 
    2711                     statusStr = GetTrinityString(LANG_COMMAND_QUEST_COMPLETE); 
     2864                QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId()); 
     2865 
     2866                                if(status == QUEST_STATUS_COMPLETE) 
     2867                                { 
     2868                                        if(target->GetQuestRewardStatus(qinfo->GetQuestId())) 
     2869                                                statusStr = GetTrinityString(LANG_COMMAND_QUEST_REWARDED); 
     2870                                        else 
     2871                                                statusStr = GetTrinityString(LANG_COMMAND_QUEST_COMPLETE); 
     2872                                } 
     2873                                else if(status == QUEST_STATUS_INCOMPLETE) 
     2874                                        statusStr = GetTrinityString(LANG_COMMAND_QUEST_ACTIVE); 
    27122875            } 
    2713             else if(status == QUEST_STATUS_INCOMPLETE) 
    2714                 statusStr = GetTrinityString(LANG_COMMAND_QUEST_ACTIVE); 
    2715  
    2716             PSendSysMessage(LANG_QUEST_LIST,qinfo->GetQuestId(),qinfo->GetQuestId(), title.c_str(),(status == QUEST_STATUS_COMPLETE ? GetTrinityString(LANG_COMPLETE) : (status == QUEST_STATUS_INCOMPLETE ? GetTrinityString(LANG_ACTIVE) : "") )); 
     2876             
     2877                        if (m_session) 
     2878                                PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),statusStr); 
     2879                        else 
     2880                                PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr); 
     2881 
    27172882            ++counter; 
    27182883        } 
     
    27272892bool ChatHandler::HandleLookupCreatureCommand(const char* args) 
    27282893{ 
    2729     if(!*args) 
     2894    if (!*args) 
    27302895        return false; 
    27312896 
     
    27342899 
    27352900    // converting string that we try to find to lower case 
    2736     if(!Utf8toWStr(namepart,wnamepart)) 
    2737         return false; 
    2738  
    2739     wstrToLower(wnamepart); 
     2901    if (!Utf8toWStr (namepart,wnamepart)) 
     2902        return false; 
     2903 
     2904    wstrToLower (wnamepart); 
    27402905 
    27412906    uint32 counter = 0; 
    27422907 
    2743     for (uint32 id = 0; id< sCreatureStorage.MaxEntry; id++ ) 
    2744     { 
    2745         CreatureInfo const* cInfo = sCreatureStorage.LookupEntry<CreatureInfo>(id); 
     2908    for (uint32 id = 0; id< sCreatureStorage.MaxEntry; ++id) 
     2909    { 
     2910        CreatureInfo const* cInfo = sCreatureStorage.LookupEntry<CreatureInfo> (id); 
    27462911        if(!cInfo) 
    27472912            continue; 
    27482913 
    2749         int loc_idx = m_session->GetSessionDbLocaleIndex(); 
    2750         if ( loc_idx >= 0 ) 
     2914        int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex(); 
     2915                if (loc_idx >= 0) 
    27512916        { 
    2752             CreatureLocale const *cl = objmgr.GetCreatureLocale(id); 
     2917            CreatureLocale const *cl = objmgr.GetCreatureLocale (id); 
    27532918            if (cl) 
    27542919            { 
    2755                 if (cl->Name.size() > loc_idx && !cl->Name[loc_idx].empty()) 
     2920                if (cl->Name.size() > loc_idx && !cl->Name[loc_idx].empty ()) 
    27562921                { 
    27572922                    std::string name = cl->Name[loc_idx]; 
    27582923 
    2759                     if (Utf8FitTo(name, wnamepart)) 
     2924                    if (Utf8FitTo (name, wnamepart)) 
    27602925                    { 
    2761                         PSendSysMessage(LANG_CREATURE_ENTRY_LIST, id, id, name.c_str()); 
     2926                        if (m_session) 
     2927                                                        PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ()); 
     2928                                                else 
     2929                                                        PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ()); 
     2930 
    27622931                        ++counter; 
    27632932                        continue; 
     
    27682937 
    27692938        std::string name = cInfo->Name; 
    2770         if(name.empty()) 
     2939        if (name.empty ()) 
    27712940            continue; 
    27722941 
    27732942        if (Utf8FitTo(name, wnamepart)) 
    27742943        { 
    2775             PSendSysMessage(LANG_CREATURE_ENTRY_LIST,id,id,name.c_str()); 
     2944            if (m_session) 
     2945                                PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ()); 
     2946                        else 
     2947                                PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ()); 
    27762948            ++counter; 
    27772949        } 
     
    27792951 
    27802952    if (counter==0) 
    2781         SendSysMessage(LANG_COMMAND_NOCREATUREFOUND); 
     2953        SendSysMessage (LANG_COMMAND_NOCREATUREFOUND); 
    27822954 
    27832955    return true; 
     
    28062978            continue; 
    28072979 
    2808         int loc_idx = m_session->GetSessionDbLocaleIndex(); 
     2980        int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex(); 
    28092981        if ( loc_idx >= 0 ) 
    28102982        { 
     
    28182990                    if (Utf8FitTo(name, wnamepart)) 
    28192991                    { 
    2820                         PSendSysMessage(LANG_GO_ENTRY_LIST, id, id, name.c_str()); 
     2992                        if (m_session) 
     2993                                                        PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str()); 
     2994                                                else 
     2995                                                        PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str()); 
    28212996                        ++counter; 
    28222997                        continue; 
     
    28323007        if(Utf8FitTo(name, wnamepart)) 
    28333008        { 
    2834             PSendSysMessage(LANG_GO_ENTRY_LIST, id, id, name.c_str()); 
     3009            if (m_session) 
     3010                                PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str()); 
     3011                        else 
     3012                                PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str()); 
    28353013            ++counter; 
    28363014        } 
     
    28573035        return false; 
    28583036 
    2859     Guild *guild; 
    2860     Player * player; 
    2861     char *lname,*gname; 
    2862     std::string guildname; 
    2863  
    2864     lname = strtok((char*)args, " "); 
    2865     gname = strtok(NULL, ""); 
    2866  
    2867     if(!lname) 
    2868         return false; 
    2869     else if(!gname) 
    2870     { 
    2871         SendSysMessage(LANG_INSERT_GUILD_NAME); 
    2872         SetSentErrorMessage(true); 
    2873         return false; 
    2874     } 
    2875  
    2876     guildname = gname; 
    2877     player = ObjectAccessor::Instance().FindPlayerByName(lname); 
    2878  
    2879     if(!player) 
    2880     { 
    2881         SendSysMessage(LANG_PLAYER_NOT_FOUND); 
    2882         SetSentErrorMessage(true); 
    2883         return false; 
    2884     } 
    2885  
    2886     if(!player->GetGuildId()) 
    2887     { 
    2888         guild = new Guild; 
    2889         if(!guild->create(player->GetGUID(),guildname)) 
    2890         { 
    2891             delete guild; 
    2892             SendSysMessage(LANG_GUILD_NOT_CREATED); 
    2893             SetSentErrorMessage(true); 
    2894             return false; 
    2895         } 
    2896  
    2897         objmgr.AddGuild(guild); 
    2898     } 
    2899     else 
    2900         SendSysMessage(LANG_PLAYER_IN_GUILD); 
    2901  
     3037    char *lname = strtok ((char*)args, " "); 
     3038        char *gname = strtok (NULL, ""); 
     3039 
     3040    if (!lname) 
     3041        return false; 
     3042     
     3043        if (!gname) 
     3044    { 
     3045        SendSysMessage (LANG_INSERT_GUILD_NAME); 
     3046                SetSentErrorMessage (true); 
     3047        return false; 
     3048    } 
     3049 
     3050    std::string guildname = gname; 
     3051 
     3052    Player* player = ObjectAccessor::Instance ().FindPlayerByName (lname); 
     3053        if (!player) 
     3054    { 
     3055        SendSysMessage (LANG_PLAYER_NOT_FOUND); 
     3056                SetSentErrorMessage (true); 
     3057        return false; 
     3058    } 
     3059 
     3060    if (player->GetGuildId()) 
     3061    { 
     3062        SendSysMessage (LANG_PLAYER_IN_GUILD); 
     3063                return true; 
     3064        } 
     3065 
     3066        Guild *guild = new Guild; 
     3067        if (!guild->create (player->GetGUID (),guildname)) 
     3068        { 
     3069                delete guild; 
     3070                SendSysMessage (LANG_GUILD_NOT_CREATED); 
     3071                SetSentErrorMessage (true); 
     3072                return false; 
     3073    } 
     3074     
     3075        objmgr.AddGuild (guild); 
    29023076    return true; 
    29033077} 
     
    29053079bool ChatHandler::HandleGuildInviteCommand(const char *args) 
    29063080{ 
    2907     if(!*args) 
    2908         return false; 
    2909  
    2910     char* par1 = strtok((char*)args, " "); 
     3081    if (!*args) 
     3082        return false; 
     3083 
     3084    char* par1 = strtok ((char*)args, " "); 
    29113085    char* par2 = strtok (NULL, ""); 
    29123086    if(!par1 || !par2) 
     
    29143088 
    29153089    std::string glName = par2; 
    2916     Guild* targetGuild = objmgr.GetGuildByName(glName); 
    2917     if(!targetGuild) 
     3090    Guild* targetGuild = objmgr.GetGuildByName (glName); 
     3091        if (!targetGuild) 
    29183092        return false; 
    29193093 
    29203094    std::string plName = par1; 
    2921     if(!normalizePlayerName(plName)) 
    2922     { 
    2923         SendSysMessage(LANG_PLAYER_NOT_FOUND); 
    2924         SetSentErrorMessage(true); 
     3095    if (!normalizePlayerName (plName)) 
     3096    { 
     3097        SendSysMessage (LANG_PLAYER_NOT_FOUND); 
     3098                SetSentErrorMessage (true); 
    29253099        return false; 
    29263100    } 
    29273101 
    29283102    uint64 plGuid = 0; 
    2929     if(Player* targetPlayer = ObjectAccessor::Instance().FindPlayerByName(plName.c_str())) 
    2930         plGuid = targetPlayer->GetGUID(); 
     3103    if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ())) 
     3104                plGuid = targetPlayer->GetGUID (); 
    29313105    else 
    2932         plGuid = objmgr.GetPlayerGUIDByName(plName.c_str()); 
    2933  
    2934     if(!plGuid) 
     3106        plGuid = objmgr.GetPlayerGUIDByName (plName.c_str ()); 
     3107 
     3108    if (!plGuid) 
    29353109        false; 
    29363110 
    29373111    // players's guild membership checked in AddMember before add 
    2938     if(!targetGuild->AddMember(plGuid,targetGuild->GetLowestRank())) 
     3112    if (!targetGuild->AddMember (plGuid,targetGuild->GetLowestRank ())) 
    29393113        return false; 
    29403114 
     
    29443118bool ChatHandler::HandleGuildUninviteCommand(const char *args) 
    29453119{ 
    2946     if(!*args) 
    2947         return false; 
    2948  
    2949     char* par1 = strtok((char*)args, " "); 
     3120    if (!*args) 
     3121        return false; 
     3122 
     3123    char* par1 = strtok ((char*)args, " "); 
    29503124    if(!par1) 
    29513125        return false; 
     3126 
    29523127    std::string plName = par1; 
    2953     if(!normalizePlayerName(plName)) 
    2954     { 
    2955         SendSysMessage(LANG_PLAYER_NOT_FOUND); 
    2956         SetSentErrorMessage(true); 
     3128    if (!normalizePlayerName (plName)) 
     3129    { 
     3130        SendSysMessage (LANG_PLAYER_NOT_FOUND); 
     3131                SetSentErrorMessage (true); 
    29573132        return false; 
    29583133    } 
     
    29603135    uint64 plGuid = 0; 
    29613136    uint32 glId   = 0; 
    2962     if(Player* targetPlayer = ObjectAccessor::Instance().FindPlayerByName(plName.c_str())) 
    2963     { 
    2964         plGuid = targetPlayer->GetGUID(); 
    2965         glId   = targetPlayer->GetGuildId(); 
     3137    if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ())) 
     3138    { 
     3139        plGuid = targetPlayer->GetGUID (); 
     3140                glId   = targetPlayer->GetGuildId (); 
    29663141    } 
    29673142    else 
    29683143    { 
    2969         plGuid = objmgr.GetPlayerGUIDByName(plName.c_str()); 
    2970         glId = Player::GetGuildIdFromDB(plGuid); 
    2971     } 
    2972  
    2973     if(!plGuid || !glId) 
    2974         return false; 
    2975  
    2976     Guild* targetGuild = objmgr.GetGuildById(glId); 
    2977     if(!targetGuild) 
    2978         return false; 
    2979  
    2980     targetGuild->DelMember(plGuid); 
     3144        plGuid = objmgr.GetPlayerGUIDByName (plName.c_str ()); 
     3145                glId = Player::GetGuildIdFromDB (plGuid); 
     3146    } 
     3147 
     3148    if (!plGuid || !glId) 
     3149        return false; 
     3150 
     3151    Guild* targetGuild = objmgr.GetGuildById (glId); 
     3152        if (!targetGuild) 
     3153        return false; 
     3154 
     3155    targetGuild->DelMember (plGuid); 
    29813156 
    29823157    return true; 
     
    29853160bool ChatHandler::HandleGuildRankCommand(const char *args) 
    29863161{ 
    2987     if(!*args) 
    2988         return false; 
    2989  
    2990     char* par1 = strtok((char*)args, " "); 
    2991     char* par2 = strtok(NULL, " "); 
    2992     if(!par1 || !par2) 
    2993         return false; 
     3162    if (!*args) 
     3163        return false; 
     3164 
     3165    char* par1 = strtok ((char*)args, " "); 
     3166        char* par2 = strtok (NULL, " "); 
     3167        if (!par1 || !par2) 
     3168        return false; 
     3169 
    29943170    std::string plName = par1; 
    2995     if(!normalizePlayerName(plName)) 
    2996     { 
    2997         SendSysMessage(LANG_PLAYER_NOT_FOUND); 
    2998         SetSentErrorMessage(true); 
     3171    if (!normalizePlayerName (plName)) 
     3172    { 
     3173        SendSysMessage (LANG_PLAYER_NOT_FOUND); 
     3174                SetSentErrorMessage (true); 
    29993175        return false; 
    30003176    } 
     
    30023178    uint64 plGuid = 0; 
    30033179    uint32 glId   = 0; 
    3004     if(Player* targetPlayer = ObjectAccessor::Instance().FindPlayerByName(plName.c_str())) 
    3005     { 
    3006         plGuid = targetPlayer->GetGUID(); 
    3007         glId   = targetPlayer->GetGuildId(); 
     3180    if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ())) 
     3181    { 
     3182        plGuid = targetPlayer->GetGUID (); 
     3183                glId   = targetPlayer->GetGuildId (); 
    30083184    } 
    30093185    else 
    30103186    { 
    3011         plGuid = objmgr.GetPlayerGUIDByName(plName.c_str()); 
    3012         glId = Player::GetGuildIdFromDB(plGuid); 
    3013     } 
    3014  
    3015     if(!plGuid || !glId) 
    3016         return false; 
    3017  
    3018     Guild* targetGuild = objmgr.GetGuildById(glId); 
    3019     if(!targetGuild) 
    3020         return false; 
    3021  
    3022     uint32 newrank = uint32(atoi(par2)); 
    3023     if(newrank > targetGuild->GetLowestRank()) 
    3024         return false; 
    3025  
    3026     targetGuild->ChangeRank(plGuid,newrank); 
     3187        plGuid = objmgr.GetPlayerGUIDByName (plName.c_str ()); 
     3188                glId = Player::GetGuildIdFromDB (plGuid); 
     3189    } 
     3190 
     3191    if (!plGuid || !glId) 
     3192        return false; 
     3193 
     3194    Guild* targetGuild = objmgr.GetGuildById (glId); 
     3195        if (!targetGuild) 
     3196        return false; 
     3197 
     3198    uint32 newrank = uint32 (atoi (par2)); 
     3199        if (newrank > targetGuild->GetLowestRank ()) 
     3200        return false; 
     3201 
     3202    targetGuild->ChangeRank (plGuid,newrank); 
    30273203 
    30283204    return true; 
     
    30313207bool ChatHandler::HandleGuildDeleteCommand(const char* args) 
    30323208{ 
    3033     if(!*args) 
    3034         return false; 
    3035  
    3036     char* par1 = strtok((char*)args, " "); 
    3037     if(!par1) 
     3209    if (!*args) 
     3210        return false; 
     3211 
     3212    char* par1 = strtok ((char*)args, " "); 
     3213        if (!par1) 
    30383214        return false; 
    30393215 
    30403216    std::string gld = par1; 
    30413217 
    3042     Guild* targetGuild = objmgr.GetGuildByName(gld); 
    3043     if(!targetGuild) 
    3044         return false; 
    3045  
    3046     targetGuild->Disband(); 
     3218    Guild* targetGuild = objmgr.GetGuildByName (gld); 
     3219        if (!targetGuild) 
     3220        return false; 
     3221 
     3222    targetGuild->Disband (); 
    30473223 
    30483224    return true; 
     
    34723648} 
    34733649 
    3474 bool ChatHandler::HandleSpawnTransportCommand(const char* /*args*/) 
    3475 { 
    3476     return true; 
    3477 } 
    3478  
    34793650//play npc emote 
    34803651bool ChatHandler::HandlePlayEmoteCommand(const char* args) 
     
    47214892} 
    47224893 
    4723 bool ChatHandler::HandleBanCommand(const char* args) 
    4724 { 
    4725     if(!args) 
    4726         return false; 
    4727  
    4728     char* type = strtok((char*)args, " "); 
    4729  
    4730     if(!type) 
    4731         return false; 
    4732     char* nameOrIP = strtok(NULL, " "); 
    4733  
    4734     if(!nameOrIP) 
    4735         return false; 
    4736  
    4737     char* duration = strtok(NULL," "); 
     4894bool ChatHandler::HandleBanAccountCommand(const char* args) 
     4895{ 
     4896    return HandleBanHelper(BAN_ACCOUNT,args); 
     4897} 
     4898 
     4899bool ChatHandler::HandleBanCharacterCommand(const char* args) 
     4900{ 
     4901        return HandleBanHelper(BAN_CHARACTER,args); 
     4902} 
     4903 
     4904bool ChatHandler::HandleBanIPCommand(const char* args) 
     4905{ 
     4906        return HandleBanHelper(BAN_IP,args); 
     4907} 
     4908 
     4909bool ChatHandler::HandleBanHelper(BanMode mode, const char* args) 
     4910{ 
     4911        if(!args) 
     4912        return false; 
     4913 
     4914    char* cnameOrIP = strtok ((char*)args, " "); 
     4915        if (!cnameOrIP) 
     4916        return false; 
     4917 
     4918    std::string nameOrIP = cnameOrIP; 
     4919 
     4920        char* duration = strtok (NULL," "); 
    47384921    if(!duration || !atoi(duration)) 
    47394922        return false; 
    47404923 
    4741     char* reason = strtok(NULL,""); 
     4924    char* reason = strtok (NULL,""); 
    47424925    if(!reason) 
    47434926        return false; 
    47444927 
    4745     switch(sWorld.BanAccount(type, nameOrIP, duration, reason,m_session->GetPlayerName())) 
     4928    switch(mode) 
     4929        { 
     4930                case BAN_ACCOUNT: 
     4931                        if(!AccountMgr::normilizeString(nameOrIP)) 
     4932                        { 
     4933                                PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str()); 
     4934                                SetSentErrorMessage(true); 
     4935                                return false; 
     4936                        } 
     4937                        break; 
     4938                case BAN_CHARACTER: 
     4939                        if(!normalizePlayerName(nameOrIP)) 
     4940                        { 
     4941                                SendSysMessage(LANG_PLAYER_NOT_FOUND); 
     4942                                SetSentErrorMessage(true); 
     4943                                return false; 
     4944                        } 
     4945                        break; 
     4946                case BAN_IP: 
     4947                        if(!IsIPAddress(nameOrIP.c_str())) 
     4948                                return false; 
     4949                        break; 
     4950        } 
     4951 
     4952        switch(sWorld.BanAccount(mode, nameOrIP, duration, reason,m_session ? m_session->GetPlayerName() : "")) 
    47464953    { 
    47474954        case BAN_SUCCESS: 
    47484955            if(atoi(duration)>0) 
    4749                 PSendSysMessage(LANG_BAN_YOUBANNED,nameOrIP,secsToTimeString(TimeStringToSecs(duration),true).c_str(),reason); 
     4956                PSendSysMessage(LANG_BAN_YOUBANNED,nameOrIP.c_str(),secsToTimeString(TimeStringToSecs(duration),true).c_str(),reason); 
    47504957            else 
    4751                 PSendSysMessage(LANG_BAN_YOUPERMBANNED,nameOrIP,reason); 
     4958                PSendSysMessage(LANG_BAN_YOUPERMBANNED,nameOrIP.c_str(),reason); 
    47524959            break; 
    47534960        case BAN_SYNTAX_ERROR: 
    47544961            return false; 
    47554962        case BAN_NOTFOUND: 
    4756             PSendSysMessage(LANG_BAN_NOTFOUND,type,nameOrIP); 
    4757             break; 
    4758     } 
    4759  
    4760     return true; 
    4761 } 
    4762  
    4763 bool ChatHandler::HandleUnBanCommand(const char* args) 
     4963           switch(mode) 
     4964                   { 
     4965                           default: 
     4966                                   PSendSysMessage(LANG_BAN_NOTFOUND,"account",nameOrIP.c_str()); 
     4967                                   break; 
     4968                           case BAN_CHARACTER: 
     4969                                   PSendSysMessage(LANG_BAN_NOTFOUND,"character",nameOrIP.c_str()); 
     4970                                   break; 
     4971                           case BAN_IP: 
     4972                                   PSendSysMessage(LANG_BAN_NOTFOUND,"ip",nameOrIP.c_str()); 
     4973                                   break; 
     4974 
     4975                   } 
     4976                   SetSentErrorMessage(true); 
     4977                   return false; 
     4978    } 
     4979 
     4980    return true; 
     4981} 
     4982 
     4983bool ChatHandler::HandleUnBanAccountCommand(const char* args) 
     4984{ 
     4985    return HandleUnBanHelper(BAN_ACCOUNT,args); 
     4986} 
     4987 
     4988bool ChatHandler::HandleUnBanCharacterCommand(const char* args) 
     4989{ 
     4990        return HandleUnBanHelper(BAN_CHARACTER,args); 
     4991} 
     4992 
     4993bool ChatHandler::HandleUnBanIPCommand(const char* args) 
     4994{ 
     4995        return HandleUnBanHelper(BAN_IP,args); 
     4996} 
     4997 
     4998bool ChatHandler::HandleUnBanHelper(BanMode mode, const char* args) 
    47644999{ 
    47655000    if(!args) 
    47665001        return false; 
    4767     char* type = strtok((char*)args, " "); 
    4768     if(!type) 
    4769         return false; 
    4770     char* nameOrIP = strtok(NULL, " "); 
    4771  
    4772     if(!nameOrIP) 
    4773         return false; 
    4774  
    4775     if(sWorld.RemoveBanAccount(type,nameOrIP)) 
    4776         PSendSysMessage(LANG_UNBAN_UNBANNED,nameOrIP); 
    4777     else 
    4778         PSendSysMessage(LANG_UNBAN_ERROR,nameOrIP); 
    4779  
    4780     return true; 
    4781 } 
    4782  
    4783 bool ChatHandler::HandleBanInfoCommand(const char* args) 
    4784 { 
    4785     if(!args) 
    4786         return false; 
    4787  
    4788     char* cType = strtok((char*)args, " "); 
    4789     char* cnameOrIP = strtok(NULL, ""); 
    4790     if(!cType || !cnameOrIP) 
     5002 
     5003    char* cnameOrIP = strtok ((char*)args, " "); 
     5004        if(!cnameOrIP) 
    47915005        return false; 
    47925006 
    47935007    std::string nameOrIP = cnameOrIP; 
    4794     std::string type = cType; 
    4795     if (!IsIPAddress(cnameOrIP) && type=="ip") 
    4796         return false; 
    4797  
    4798     Field *fields; 
    4799     if(type != "ip") 
    4800     { 
    4801         //look the accountid up 
    4802         uint32 accountid; 
    4803         std::string accountname; 
    4804         if(type == "account") 
    4805         { 
    4806             loginDatabase.escape_string(nameOrIP); 
    4807             QueryResult *result = loginDatabase.PQuery("SELECT id, username FROM account WHERE username = '%s'",nameOrIP.c_str()); 
    4808             if (!result) 
     5008    switch(mode) 
     5009    { 
     5010        case BAN_ACCOUNT: 
     5011                        if(!AccountMgr::normilizeString(nameOrIP)) 
    48095012            { 
    4810                 PSendSysMessage(LANG_BANINFO_NOACCOUNT); 
    4811                 return true; 
    4812             } 
    4813             fields = result->Fetch(); 
    4814             accountid = fields[0].GetUInt32(); 
    4815             accountname = fields[1].GetCppString(); 
    4816             delete result; 
    4817         } 
    4818         else if(type == "character") 
    4819         { 
    4820             if(!normalizePlayerName(nameOrIP)) 
     5013                PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str()); 
     5014                                SetSentErrorMessage(true); 
     5015                                return false; 
     5016                        } 
     5017                        break; 
     5018                case BAN_CHARACTER: 
     5019                        if(!normalizePlayerName(nameOrIP)) 
    48215020            { 
    48225021                SendSysMessage(LANG_PLAYER_NOT_FOUND); 
     
    48245023                return false; 
    48255024            } 
    4826  
    4827             accountid = objmgr.GetPlayerAccountIdByPlayerName (nameOrIP); 
    4828             if (!accountid) 
    4829             { 
    4830                 PSendSysMessage(LANG_BANINFO_NOCHARACTER); 
    4831                 return true; 
    4832             } 
    4833              
    4834             if (!accmgr.GetName (accountid,accountname)) 
    4835             { 
    4836                 PSendSysMessage(LANG_BANINFO_NOCHARACTER); 
    4837                 return true; 
    4838             } 
    4839         } 
    4840         else 
    4841             return false; 
    4842  
    4843         QueryResult *result = loginDatabase.PQuery("SELECT FROM_UNIXTIME(bandate), unbandate-bandate, active, unbandate,banreason,bannedby FROM account_banned WHERE id = '%u' ORDER BY bandate ASC",accountid); 
    4844         if(!result) 
     5025                        break; 
     5026                case BAN_IP: 
     5027                        if(!IsIPAddress(nameOrIP.c_str())) 
     5028                                return false; 
     5029                        break; 
     5030        } 
     5031 
     5032        if(sWorld.RemoveBanAccount(mode,nameOrIP)) 
     5033                PSendSysMessage(LANG_UNBAN_UNBANNED,nameOrIP.c_str()); 
     5034        else 
     5035                PSendSysMessage(LANG_UNBAN_ERROR,nameOrIP.c_str()); 
     5036 
     5037        return true; 
     5038} 
     5039 
     5040bool ChatHandler::HandleBanInfoAccountCommand(const char* args) 
     5041{ 
     5042        if(!args) 
     5043                return false; 
     5044 
     5045        char* cname = strtok((char*)args, ""); 
     5046        if(!cname) 
     5047                return false; 
     5048 
     5049        std::string account_name = cname; 
     5050        if(!AccountMgr::normilizeString(account_name)) 
     5051        { 
     5052                PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str()); 
     5053                SetSentErrorMessage(true); 
     5054                return false; 
     5055    } 
     5056     
     5057        uint32 accountid = accmgr.GetId(account_name); 
     5058        if(!accountid) 
     5059    { 
     5060        PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str()); 
     5061                return true; 
     5062    } 
     5063     
     5064        return HandleBanInfoHelper(accountid,account_name.c_str()); 
     5065} 
     5066 
     5067bool ChatHandler::HandleBanInfoCharacterCommand(const char* args) 
     5068{ 
     5069    if(!args) 
     5070        return false; 
     5071 
     5072    char* cname = strtok ((char*)args, ""); 
     5073        if(!cname) 
     5074        return false; 
     5075 
     5076    std::string name = cname; 
     5077        if(!normalizePlayerName(name)) 
     5078        { 
     5079                SendSysMessage(LANG_PLAYER_NOT_FOUND); 
     5080                SetSentErrorMessage(true); 
     5081                return false; 
     5082        } 
     5083 
     5084    uint32 accountid = objmgr.GetPlayerAccountIdByPlayerName(name); 
     5085        if(!accountid) 
     5086    { 
     5087        SendSysMessage(LANG_PLAYER_NOT_FOUND); 
     5088                SetSentErrorMessage(true); 
     5089                return false; 
     5090        } 
     5091 
     5092        std::string accountname; 
     5093        if(!accmgr.GetName(accountid,accountname)) 
     5094        { 
     5095                PSendSysMessage(LANG_BANINFO_NOCHARACTER); 
     5096        return true; 
     5097    } 
     5098     
     5099        return HandleBanInfoHelper(accountid,accountname.c_str()); 
     5100} 
     5101 
     5102bool ChatHandler::HandleBanInfoHelper(uint32 accountid, char const* accountname) 
     5103{ 
     5104        QueryResult *result = loginDatabase.PQuery("SELECT FROM_UNIXTIME(bandate), unbandate-bandate, active, unbandate,banreason,bannedby FROM account_banned WHERE id = '%u' ORDER BY bandate ASC",accountid); 
     5105        if(!result) 
     5106    { 
     5107        PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountname); 
     5108                return true; 
     5109    } 
     5110     
     5111        PSendSysMessage(LANG_BANINFO_BANHISTORY,accountname); 
     5112        do 
     5113    { 
     5114        Field* fields = result->Fetch(); 
     5115 
     5116                time_t unbandate = time_t(fields[3].GetUInt64()); 
     5117                bool active = false; 
     5118                if(fields[2].GetBool() && (fields[1].GetUInt64() == (uint64)0 ||unbandate >= time(NULL)) ) 
     5119                        active = true; 
     5120                bool permanent = (fields[1].GetUInt64() == (uint64)0); 
     5121                std::string bantime = permanent?GetTrinityString(LANG_BANINFO_INFINITE):secsToTimeString(fields[1].GetUInt64(), true); 
     5122                PSendSysMessage(LANG_BANINFO_HISTORYENTRY, 
     5123                        fields[0].GetString(), bantime.c_str(), active ? GetTrinityString(LANG_BANINFO_YES):GetTrinityString(LANG_BANINFO_NO), fields[4].GetString(), fields[5].GetString()); 
     5124        }while (result->NextRow()); 
     5125 
     5126        delete result; 
     5127        return true; 
     5128} 
     5129 
     5130bool ChatHandler::HandleBanInfoIPCommand(const char* args) 
     5131{ 
     5132        if(!args) 
     5133                return false; 
     5134 
     5135        char* cIP = strtok ((char*)args, ""); 
     5136        if(!cIP) 
     5137                return false; 
     5138 
     5139        if (!IsIPAddress(cIP)) 
     5140                return false; 
     5141 
     5142        std::string IP = cIP; 
     5143 
     5144        loginDatabase.escape_string(IP); 
     5145        QueryResult *result = loginDatabase.PQuery("SELECT ip, FROM_UNIXTIME(bandate), FROM_UNIXTIME(unbandate), unbandate-UNIX_TIMESTAMP(), banreason,bannedby,unbandate-bandate FROM ip_banned WHERE ip = '%s'",IP.c_str()); 
     5146        if(!result) 
     5147        { 
     5148                PSendSysMessage(LANG_BANINFO_NOIP); 
     5149                return true; 
     5150    } 
     5151     
     5152        Field *fields = result->Fetch(); 
     5153        bool permanent = !fields[6].GetUInt64(); 
     5154        PSendSysMessage(LANG_BANINFO_IPENTRY, 
     5155                fields[0].GetString(), fields[1].GetString(), permanent ? GetTrinityString(LANG_BANINFO_NEVER):fields[2].GetString(), 
     5156                permanent ? GetTrinityString(LANG_BANINFO_INFINITE):secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetString(), fields[5].GetString()); 
     5157        delete result; 
     5158        return true; 
     5159} 
     5160 
     5161bool ChatHandler::HandleBanListCharacterCommand(const char* args) 
     5162{ 
     5163        loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate"); 
     5164 
     5165        char* cFilter = strtok ((char*)args, " "); 
     5166        if(!cFilter) 
     5167        return false; 
     5168 
     5169        std::string filter = cFilter; 
     5170        loginDatabase.escape_string(filter); 
     5171        QueryResult* result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),filter.c_str()); 
     5172        if (!result) 
     5173        { 
     5174                PSendSysMessage(LANG_BANLIST_NOCHARACTER); 
     5175                return true; 
     5176        } 
     5177 
     5178        return HandleBanListHelper(result); 
     5179} 
     5180 
     5181bool ChatHandler::HandleBanListAccountCommand(const char* args) 
     5182{ 
     5183        loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate"); 
     5184 
     5185        char* cFilter = strtok((char*)args, " "); 
     5186        std::string filter = cFilter ? cFilter : ""; 
     5187        loginDatabase.escape_string(filter); 
     5188 
     5189        QueryResult* result; 
     5190 
     5191        if(filter.empty()) 
     5192        { 
     5193                 result = loginDatabase.Query("SELECT account.id, username FROM account, account_banned" 
     5194                         " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id"); 
     5195        } 
     5196        else 
     5197        { 
     5198                result = loginDatabase.PQuery("SELECT account.id, username FROM account, account_banned" 
     5199                        " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id", 
     5200                        filter.c_str()); 
     5201        } 
     5202 
     5203        if (!result) 
     5204        { 
     5205                PSendSysMessage(LANG_BANLIST_NOACCOUNT); 
     5206                return true; 
     5207        } 
     5208 
     5209        return HandleBanListHelper(result); 
     5210} 
     5211 
     5212bool ChatHandler::HandleBanListHelper(QueryResult* result) 
     5213{ 
     5214    PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT); 
     5215     
     5216        // Chat short output 
     5217        if(m_session) 
     5218    { 
     5219        do 
     5220                { 
     5221                        Field* fields = result->Fetch(); 
     5222                        uint32 accountid = fields[0].GetUInt32(); 
     5223 
     5224                        QueryResult* banresult = loginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid); 
     5225                        if(banresult) 
     5226                        { 
     5227                                Field* fields2 = banresult->Fetch(); 
     5228                                PSendSysMessage("%s",fields2[0].GetString()); 
     5229                                delete banresult; 
     5230                        } 
     5231                } while (result->NextRow()); 
     5232        } 
     5233        // Console wide output 
     5234        else 
     5235        { 
     5236                SendSysMessage(LANG_BANLIST_ACCOUNTS); 
     5237                SendSysMessage("==============================================================================="); 
     5238                SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER); 
     5239                do 
     5240                { 
     5241                        SendSysMessage("-------------------------------------------------------------------------------"); 
     5242                        Field *fields = result->Fetch(); 
     5243                        uint32 account_id = fields[0].GetUInt32 (); 
     5244 
     5245                        std::string account_name; 
     5246 
     5247                        // "account" case, name can be get in same quary 
     5248                        if(result->GetFieldCount() > 1) 
     5249                                account_name = fields[1].GetCppString(); 
     5250                        // "character" case, name need extract from another DB 
     5251                        else 
     5252                                accmgr.GetName (account_id,account_name); 
     5253 
     5254                        // No SQL injection. id is uint32. 
     5255                        QueryResult *banInfo = loginDatabase.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id); 
     5256                        if (banInfo) 
     5257                        { 
     5258                                Field *fields2 = banInfo->Fetch(); 
     5259                                do 
     5260                                { 
     5261                                        time_t t_ban = fields2[0].GetUInt64(); 
     5262                                        tm* aTm_ban = localtime(&t_ban); 
     5263 
     5264                                        if (fields2[0].GetUInt64() == fields2[1].GetUInt64()) 
     5265                                        { 
     5266                                                PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|   permanent  |%-15.15s|%-15.15s|", 
     5267                                                        account_name.c_str(),aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min, 
     5268                                                        fields2[2].GetString(),fields2[3].GetString()); 
     5269                                        } 
     5270                                        else 
     5271                                        { 
     5272                                                time_t t_unban = fields2[1].GetUInt64(); 
     5273                                                tm* aTm_unban = localtime(&t_unban); 
     5274                                                PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|", 
     5275                                                        account_name.c_str(),aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min, 
     5276                                                        aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min, 
     5277                                                        fields2[2].GetString(),fields2[3].GetString()); 
     5278                                        } 
     5279                                }while ( banInfo->NextRow() ); 
     5280                                delete banInfo; 
     5281                        } 
     5282                }while( result->NextRow() ); 
     5283                SendSysMessage("==============================================================================="); 
     5284        } 
     5285 
     5286        delete result; 
     5287        return true; 
     5288} 
     5289 
     5290bool ChatHandler::HandleBanListIPCommand(const char* args) 
     5291{ 
     5292        loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate"); 
     5293 
     5294        char* cFilter = strtok((char*)args, " "); 
     5295        std::string filter = cFilter ? cFilter : ""; 
     5296        loginDatabase.escape_string(filter); 
     5297 
     5298        QueryResult* result; 
     5299 
     5300        if(filter.empty()) 
     5301        { 
     5302                result = loginDatabase.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned" 
     5303                        " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())" 
     5304                        " ORDER BY unbandate" ); 
     5305        } 
     5306        else 
     5307        { 
     5308                result = loginDatabase.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned" 
     5309                        " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'") 
     5310                        " ORDER BY unbandate",filter.c_str() ); 
     5311        } 
     5312 
     5313        if(!result) 
     5314        { 
     5315                PSendSysMessage(LANG_BANLIST_NOIP); 
     5316                return true; 
     5317        } 
     5318 
     5319        PSendSysMessage(LANG_BANLIST_MATCHINGIP); 
     5320        // Chat short output 
     5321        if(m_session) 
     5322        { 
     5323                do 
     5324                { 
     5325                        Field* fields = result->Fetch(); 
     5326                        PSendSysMessage("%s",fields[0].GetString()); 
     5327                }while (result->NextRow()); 
     5328        } 
     5329        // Console wide output 
     5330        else 
     5331        { 
     5332                SendSysMessage(LANG_BANLIST_IPS);SendSysMessage("==============================================================================="); 
     5333                SendSysMessage(LANG_BANLIST_IPS_HEADER); 
     5334                do 
    48455335        { 
    4846             PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountname.c_str()); 
    4847             return true; 
    4848         } 
    4849  
    4850         PSendSysMessage(LANG_BANINFO_BANHISTORY,accountname.c_str()); 
    4851         do 
    4852         { 
    4853             fields = result->Fetch(); 
    4854  
    4855             time_t unbandate = time_t(fields[3].GetUInt64()); 
    4856             bool active = false; 
    4857             if(fields[2].GetBool() && (fields[1].GetUInt64() == (uint64)0 ||unbandate >= time(NULL)) ) 
    4858                 active = true; 
    4859             bool permanent = (fields[1].GetUInt64() == (uint64)0); 
    4860             std::string bantime = permanent?GetTrinityString(LANG_BANINFO_INFINITE):secsToTimeString(fields[1].GetUInt64(), true); 
    4861             PSendSysMessage(LANG_BANINFO_HISTORYENTRY, 
    4862                 fields[0].GetString(), bantime.c_str(), active ? GetTrinityString(LANG_BANINFO_YES):GetTrinityString(LANG_BANINFO_NO), fields[4].GetString(), fields[5].GetString()); 
    4863         }while (result->NextRow()); 
    4864  
    4865         delete result; 
    4866     } 
    4867     else 
    4868     { 
    4869         loginDatabase.escape_string(nameOrIP); 
    4870         QueryResult *result = loginDatabase.PQuery("SELECT ip, FROM_UNIXTIME(bandate), FROM_UNIXTIME(unbandate), unbandate-UNIX_TIMESTAMP(), banreason,bannedby,unbandate-bandate FROM ip_banned WHERE ip = '%s'",nameOrIP.c_str()); 
    4871         if(!result) 
    4872         { 
    4873             PSendSysMessage(LANG_BANINFO_NOIP); 
    4874             return true; 
    4875         } 
    4876         fields = result->Fetch(); 
    4877         bool permanent = (fields[6].GetUInt64()==(uint64)0); 
    4878         PSendSysMessage(LANG_BANINFO_IPENTRY, 
    4879             fields[0].GetString(), fields[1].GetString(), permanent ? GetTrinityString(LANG_BANINFO_NEVER):fields[2].GetString(), 
    4880             permanent ? GetTrinityString(LANG_BANINFO_INFINITE):secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetString(), fields[5].GetString()); 
    4881         delete result; 
    4882     } 
    4883     return true; 
    4884 } 
    4885  
    4886 bool ChatHandler::HandleBanListCommand(const char* args) 
    4887 { 
    4888     loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate"); 
    4889     if(!*args) 
    4890         return false; 
    4891     char* cType = strtok((char*)args, " "); 
    4892     char* cFilter = strtok(NULL, ""); 
    4893     if(!cType || !cFilter) 
    4894         return false; 
    4895     std::string Filter = cFilter; 
    4896     std::string Type = cType; 
    4897     loginDatabase.escape_string(Filter); 
    4898  
    4899     QueryResult* result  = NULL; 
    4900     Field *fields = NULL; 
    4901     if(Type == "ip") 
    4902     { 
    4903         result = loginDatabase.PQuery("SELECT ip FROM ip_banned WHERE ip "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),Filter.c_str()); 
    4904         if(!result) 
    4905         { 
    4906             PSendSysMessage(LANG_BANLIST_NOIP); 
    4907             return true; 
    4908         } 
    4909         PSendSysMessage(LANG_BANLIST_MATCHINGIP); 
    4910         do 
    4911         { 
    4912             fields = result->Fetch(); 
    4913             PSendSysMessage("%s",fields[0].GetString()); 
    4914         } while (result->NextRow()); 
    4915  
    4916         delete result; 
    4917         return true; 
    4918     } 
    4919     //lookup accountid 
    4920     if(Type == "account") 
    4921     { 
    4922         result = loginDatabase.PQuery("SELECT id FROM account WHERE username "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),Filter.c_str()); 
    4923         if (!result) 
    4924         { 
    4925             PSendSysMessage(LANG_BANLIST_NOACCOUNT); 
    4926             return true; 
    4927         } 
    4928         //do not delete result 
    4929     } 
    4930     else if(Type == "characters") 
    4931     { 
    4932         result = CharacterDatabase.PQuery("SELECT account FROM characters, WHERE name "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),Filter.c_str()); 
    4933         if (!result) 
    4934         { 
    4935             PSendSysMessage(LANG_BANLIST_NOCHARACTER); 
    4936             return true; 
    4937         } 
    4938     } 
    4939     else 
    4940         return false; 
    4941  
    4942     PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT); 
    4943     do 
    4944     { 
    4945         fields = result->Fetch(); 
    4946         uint32 accountid = fields[0].GetUInt32(); 
    4947         QueryResult* banresult = loginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.active = '1' AND account_banned.id=account.id",accountid); 
    4948         if(banresult) 
    4949         { 
    4950             Field* fields2 = banresult->Fetch(); 
    4951             PSendSysMessage("%s",fields2[0].GetString()); 
    4952             delete banresult; 
    4953         } 
    4954     } while (result->NextRow()); 
     5336            SendSysMessage("-------------------------------------------------------------------------------"); 
     5337                        Field *fields = result->Fetch(); 
     5338                        time_t t_ban = fields[1].GetUInt64(); 
     5339                        tm* aTm_ban = localtime(&t_ban); 
     5340                        if ( fields[1].GetUInt64() == fields[2].GetUInt64() ) 
     5341                        { 
     5342                                PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|   permanent  |%-15.15s|%-15.15s|", 
     5343                                        fields[0].GetString(), aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min, 
     5344                                        fields[3].GetString(), fields[4].GetString()); 
     5345                        } 
     5346                        else 
     5347                        { 
     5348                                time_t t_unban = fields[2].GetUInt64(); 
     5349                                tm* aTm_unban = localtime(&t_unban); 
     5350                                PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|", 
     5351                                        fields[0].GetString(), aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min, 
     5352                                        aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min, 
     5353                                        fields[3].GetString(), fields[4].GetString()); 
     5354                        } 
     5355                }while( result->NextRow() ); 
     5356                SendSysMessage("==============================================================================="); 
     5357    } 
    49555358 
    49565359    delete result; 
     
    50135416bool ChatHandler::HandleLoadPDumpCommand(const char *args) 
    50145417{ 
    5015     if(!args) 
    5016         return false; 
    5017  
    5018     char * file = strtok((char*)args, " "); if(!file) return false; 
    5019     char * acc = strtok(NULL, " "); if(!acc) return false; 
    5020     if(!file || !acc) 
    5021         return false; 
    5022  
    5023     uint32 account_id = accmgr.GetId(acc); 
     5418    if (!args) 
     5419        return false; 
     5420 
     5421    char * file = strtok((char*)args, " "); 
     5422        if(!file) 
     5423                return false; 
     5424 
     5425        char * account = strtok(NULL, " "); 
     5426        if(!account) 
     5427                return false; 
     5428 
     5429        std::string account_name = account; 
     5430        if(!AccountMgr::normilizeString(account_name)) 
     5431        { 
     5432                PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str()); 
     5433                SetSentErrorMessage(true); 
     5434        return false; 
     5435        } 
     5436 
     5437    uint32 account_id = accmgr.GetId(account_name); 
    50245438    if(!account_id) 
    50255439    { 
    5026         account_id = atoi(acc); 
    5027         if(account_id) 
     5440        account_id = atoi(account);                             // use original string 
     5441        if(!account_id) 
    50285442        { 
    5029             std::string acc_name; 
    5030             if(!accmgr.GetName(account_id,acc_name)) 
    5031                 return false; 
     5443            PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str()); 
     5444                        SetSentErrorMessage(true); 
     5445                        return false; 
    50325446        } 
    5033         else 
     5447        } 
     5448 
     5449        if(!accmgr.GetName(account_id,account_name)) 
     5450        { 
     5451                PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str()); 
     5452                SetSentErrorMessage(true); 
     5453                return false; 
     5454        } 
     5455 
     5456        char* guid_str = NULL; 
     5457        char* name_str = strtok(NULL, " "); 
     5458 
     5459        std::string name; 
     5460        if(name_str) 
     5461        { 
     5462                name = name_str; 
     5463                // normalize the name if specified and check if it exists 
     5464                if(!normalizePlayerName(name)) 
     5465                { 
     5466                        PSendSysMessage(LANG_INVALID_CHARACTER_NAME); 
     5467                        SetSentErrorMessage(true); 
     5468                        return false; 
     5469                } 
     5470 
     5471                if(!ObjectMgr::IsValidName(name,true)) 
     5472                { 
     5473                        PSendSysMessage(LANG_INVALID_CHARACTER_NAME); 
     5474                        SetSentErrorMessage(true); 
    50345475            return false; 
    5035     } 
    5036  
    5037     char * name = strtok(NULL, " "); 
    5038     char * guid_str = name ? strtok(NULL, " ") : NULL; 
    5039  
    5040     uint32 guid = guid_str ? atoi(guid_str) : 0; 
    5041  
    5042     if(PlayerDumpReader().LoadDump(file, account_id, name ? name : "", guid)) 
    5043         PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS); 
    5044     else 
    5045         PSendSysMessage(LANG_COMMAND_IMPORT_FAILED); 
     5476                } 
     5477 
     5478                guid_str = strtok(NULL, " "); 
     5479    } 
     5480 
     5481    uint32 guid = 0; 
     5482 
     5483    if(guid_str) 
     5484        { 
     5485                guid = atoi(guid_str); 
     5486                if(!guid) 
     5487                { 
     5488                        PSendSysMessage(LANG_INVALID_CHARACTER_GUID); 
     5489                        SetSentErrorMessage(true); 
     5490                        return false; 
     5491                } 
     5492                 
     5493                if(objmgr.GetPlayerAccountIdByGUID(guid)) 
     5494                { 
     5495                        PSendSysMessage(LANG_CHARACTER_GUID_IN_USE,guid); 
     5496                        SetSentErrorMessage(true); 
     5497                        return false; 
     5498                } 
     5499        } 
     5500 
     5501        switch(PlayerDumpReader().LoadDump(file, account_id, name, guid)) 
     5502        { 
     5503                case DUMP_SUCCESS: 
     5504                        PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS); 
     5505                        break; 
     5506                case DUMP_FILE_OPEN_ERROR: 
     5507                        PSendSysMessage(LANG_FILE_OPEN_FAIL,file); 
     5508                        SetSentErrorMessage(true); 
     5509                        return false; 
     5510                case DUMP_FILE_BROKEN: 
     5511                        PSendSysMessage(LANG_DUMP_BROKEN,file); 
     5512                        SetSentErrorMessage(true); 
     5513                        return false; 
     5514                case DUMP_TOO_MANY_CHARS: 
     5515                        PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL,account_name,account_id); 
     5516                        SetSentErrorMessage(true); 
     5517                        return false; 
     5518                default: 
     5519                        PSendSysMessage(LANG_COMMAND_IMPORT_FAILED); 
     5520                        SetSentErrorMessage(true); 
     5521                        return false; 
     5522        } 
    50465523 
    50475524    return true; 
     
    50875564        guid = atoi(p2); 
    50885565 
    5089     if (PlayerDumpWriter().WriteDump(file, guid)) 
    5090         PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS); 
    5091     else 
    5092         PSendSysMessage(LANG_COMMAND_EXPORT_FAILED); 
     5566    if(!objmgr.GetPlayerAccountIdByGUID(guid)) 
     5567        { 
     5568                PSendSysMessage(LANG_PLAYER_NOT_FOUND); 
     5569                SetSentErrorMessage(true); 
     5570                return false; 
     5571        } 
     5572 
     5573        switch(PlayerDumpWriter().WriteDump(file, guid)) 
     5574        { 
     5575                case DUMP_SUCCESS: 
     5576                        PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS); 
     5577                        break; 
     5578                case DUMP_FILE_OPEN_ERROR: 
     5579                        PSendSysMessage(LANG_FILE_OPEN_FAIL,file); 
     5580                        SetSentErrorMessage(true); 
     5581                        return false; 
     5582                default: 
     5583                        PSendSysMessage(LANG_COMMAND_EXPORT_FAILED); 
     5584                        SetSentErrorMessage(true); 
     5585                        return false; 
     5586        } 
    50935587 
    50945588    return true; 
     
    55746068} 
    55756069 
     6070/// Display the list of GMs 
     6071bool ChatHandler::HandleGMListFullCommand(const char* /*args*/) 
     6072{ 
     6073        ///- Get the accounts with GM Level >0 
     6074        QueryResult *result = loginDatabase.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" ); 
     6075        if(result) 
     6076        { 
     6077                SendSysMessage(LANG_GMLIST); 
     6078                SendSysMessage("========================"); 
     6079                SendSysMessage(LANG_GMLIST_HEADER); 
     6080                SendSysMessage("========================"); 
     6081 
     6082                ///- Circle through them. Display username and GM level 
     6083                do 
     6084                { 
     6085                        Field *fields = result->Fetch(); 
     6086                        PSendSysMessage("|%15s|%6s|", fields[0].GetString(),fields[1].GetString()); 
     6087                } while( result->NextRow() ); 
     6088 
     6089                PSendSysMessage("========================"); 
     6090                delete result; 
     6091        } 
     6092        else 
     6093                PSendSysMessage(LANG_GMLIST_EMPTY); 
     6094        return true; 
     6095} 
     6096 
     6097/// Define the 'Message of the day' for the realm 
     6098bool ChatHandler::HandleServerSetMotdCommand(const char* args) 
     6099{ 
     6100        sWorld.SetMotd(args); 
     6101        PSendSysMessage(LANG_MOTD_NEW, args); 
     6102        return true; 
     6103} 
     6104 
     6105/// Set/Unset the expansion level for an account 
     6106bool ChatHandler::HandleAccountSetAddonCommand(const char* args) 
     6107{ 
     6108        ///- Get the command line arguments 
     6109        char *szAcc = strtok((char*)args," "); 
     6110        char *szExp = strtok(NULL," "); 
     6111 
     6112        if(!szAcc) 
     6113                return false; 
     6114 
     6115        std::string account_name; 
     6116        uint32 account_id; 
     6117 
     6118        if(!szExp) 
     6119        { 
     6120                Player* player = getSelectedPlayer(); 
     6121                if(!player) 
     6122                        return false; 
     6123 
     6124                account_id = player->GetSession()->GetAccountId(); 
     6125                accmgr.GetName(account_id,account_name); 
     6126                szExp = szAcc; 
     6127        } 
     6128        else 
     6129        { 
     6130                ///- Convert Account name to Upper Format 
     6131                account_name = szAcc; 
     6132                if(!AccountMgr::normilizeString(account_name)) 
     6133                { 
     6134                        PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str()); 
     6135                        SetSentErrorMessage(true); 
     6136                        return false; 
     6137                } 
     6138 
     6139                account_id = accmgr.GetId(account_name); 
     6140                if(!account_id) 
     6141                { 
     6142                        PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str()); 
     6143                        SetSentErrorMessage(true); 
     6144                        return false; 
     6145                } 
     6146        } 
     6147 
     6148        int lev=atoi(szExp);                                    //get int anyway (0 if error) 
     6149        if(lev < 0) 
     6150                return false; 
     6151 
     6152        // No SQL injection 
     6153        loginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev,account_id); 
     6154        PSendSysMessage(LANG_ACCOUNT_SETADDON,account_name.c_str(),account_id,lev); 
     6155        return true; 
     6156} 
     6157 
     6158/// Send a message to a player in game 
     6159bool ChatHandler::HandleSendMessageCommand(const char* args) 
     6160{ 
     6161        ///- Get the command line arguments 
     6162        char* name_str = strtok((char*)args, " "); 
     6163        char* msg_str = strtok(NULL, ""); 
     6164 
     6165        if(!name_str || !msg_str) 
     6166                return false; 
     6167 
     6168        std::string name = name_str; 
     6169 
     6170        if(!normalizePlayerName(name)) 
     6171                return false; 
     6172 
     6173        ///- Find the player and check that he is not logging out. 
     6174        Player *rPlayer = objmgr.GetPlayer(name.c_str()); 
     6175        if(!rPlayer) 
     6176        { 
     6177                SendSysMessage(LANG_PLAYER_NOT_FOUND); 
     6178                SetSentErrorMessage(true); 
     6179                return false; 
     6180        } 
     6181 
     6182        if(rPlayer->GetSession()->isLogingOut()) 
     6183        { 
     6184                SendSysMessage(LANG_PLAYER_NOT_FOUND); 
     6185                SetSentErrorMessage(true); 
     6186                return false; 
     6187        } 
     6188 
     6189        ///- Send the message 
     6190        //Use SendAreaTriggerMessage for fastest delivery. 
     6191        rPlayer->GetSession()->SendAreaTriggerMessage("%s", msg_str); 
     6192        rPlayer->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r"); 
     6193 
     6194        //Confirmation message 
     6195        PSendSysMessage(LANG_SENDMESSAGE,name.c_str(),msg_str); 
     6196        return true; 
     6197} 
     6198 
    55766199bool ChatHandler::HandleFreezeCommand(const char *args) 
    55776200{