Changeset 112 for trunk/src/game/Level3.cpp
- Timestamp:
- 11/19/08 13:37:14 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/game/Level3.cpp
r102 r112 53 53 #include "InstanceSaveMgr.h" 54 54 #include "InstanceData.h" 55 #include "AccountMgr.h" 55 56 56 57 //reload commands … … 682 683 } 683 684 684 bool ChatHandler::Handle SecurityCommand(const char* args)685 bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args) 685 686 { 686 687 char* arg1 = strtok((char*)args, " "); … … 688 689 return false; 689 690 690 char* arg2 = 0;691 692 std::string target Name;691 char* arg2 = strtok(NULL, " "); 692 693 std::string targetAccountName; 693 694 uint32 targetAccountId = 0; 694 695 uint32 targetSecurity = 0; 695 696 697 /// only target player different from self allowed (if targetPlayer!=NULL then not console) 696 698 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 700 705 targetAccountId = targetPlayer->GetSession()->GetAccountId(); 701 706 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 } 703 713 } 704 714 else 705 715 { 706 target Name = arg1;707 if(! normalizePlayerName(targetName))716 targetAccountName = arg1; 717 if(!AccountMgr::normilizeString(targetAccountName)) 708 718 { 709 SendSysMessage(LANG_PLAYER_NOT_FOUND);719 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str()); 710 720 SetSentErrorMessage(true); 711 721 return false; 712 722 } 713 723 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); 734 726 } 735 727 … … 742 734 } 743 735 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 ) 746 742 { 747 743 SendSysMessage(LANG_YOURS_SECURITY_IS_LOW); … … 752 748 if(targetPlayer) 753 749 { 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); 757 751 targetPlayer->GetSession()->SetSecurity(gm); 758 752 } 759 753 760 PSendSysMessage(LANG_YOU_CHANGE_SECURITY, target Name.c_str(), gm);754 PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm); 761 755 loginDatabase.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm, targetAccountId); 762 756 763 757 return true; 758 } 759 760 /// Set password for account 761 bool 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; 764 833 } 765 834 … … 1977 2046 if(!cId) 1978 2047 return false; 2048 1979 2049 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); 1983 2058 if(!itemProto) 1984 2059 { … … 2136 2211 } 2137 2212 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) 2139 2253 { 2140 2254 SendSysMessage(LANG_COMMAND_NOITEMFOUND); … … 2143 2257 } 2144 2258 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); 2146 2260 2147 2261 return true; … … 2153 2267 return false; 2154 2268 2155 2269 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r 2156 2270 char* cId = extractKeyFromLink((char*)args,"Hgameobject_entry"); 2157 2271 if(!cId) … … 2159 2273 2160 2274 uint32 go_id = atol(cId); 2275 if(!go_id) 2276 { 2277 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id); 2278 SetSentErrorMessage(true); 2279 return false; 2280 } 2161 2281 2162 2282 GameObjectInfo const * gInfo = objmgr.GetGameObjectInfo(go_id); 2163 2164 if(!go_id || !gInfo) 2283 if(!gInfo) 2165 2284 { 2166 2285 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id); … … 2175 2294 return false; 2176 2295 2177 Player* pl = m_session->GetPlayer();2178 2296 QueryResult *result; 2179 2297 … … 2186 2304 } 2187 2305 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)); 2190 2315 2191 2316 if (result) … … 2200 2325 int mapid = fields[4].GetUInt16(); 2201 2326 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); 2203 2331 } while (result->NextRow()); 2204 2332 … … 2239 2367 continue; 2240 2368 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); 2242 2370 2243 2371 ++count; … … 2294 2422 return false; 2295 2423 2296 2424 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r 2297 2425 char* cId = extractKeyFromLink((char*)args,"Hcreature_entry"); 2298 2426 if(!cId) … … 2300 2428 2301 2429 uint32 cr_id = atol(cId); 2430 if(!cr_id) 2431 { 2432 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id); 2433 SetSentErrorMessage(true); 2434 return false; 2435 } 2302 2436 2303 2437 CreatureInfo const* cInfo = objmgr.GetCreatureTemplate(cr_id); 2304 2305 if(!cr_id || !cInfo) 2438 if(!cInfo) 2306 2439 { 2307 2440 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id); … … 2316 2449 return false; 2317 2450 2318 Player* pl = m_session->GetPlayer();2319 2451 QueryResult *result; 2320 2452 … … 2327 2459 } 2328 2460 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)); 2331 2470 2332 2471 if (result) … … 2341 2480 int mapid = fields[4].GetUInt16(); 2342 2481 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); 2344 2486 } while (result->NextRow()); 2345 2487 … … 2374 2516 continue; 2375 2517 2376 int loc_idx = m_session ->GetSessionDbLocaleIndex();2518 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex(); 2377 2519 if ( loc_idx >= 0 ) 2378 2520 { … … 2386 2528 if (Utf8FitTo(name, wnamepart)) 2387 2529 { 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()); 2389 2534 ++counter; 2390 2535 continue; … … 2400 2545 if (Utf8FitTo(name, wnamepart)) 2401 2546 { 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()); 2403 2551 ++counter; 2404 2552 } … … 2433 2581 if(set) 2434 2582 { 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]; 2437 2585 if(name.empty()) 2438 2586 continue; … … 2443 2591 for(; loc < MAX_LOCALE; ++loc) 2444 2592 { 2445 if( loc==m_session->GetSessionDbcLocale())2593 if(m_session && loc==m_session->GetSessionDbcLocale()) 2446 2594 continue; 2447 2595 2448 name = set->name[ m_session->GetSessionDbcLocale()];2596 name = set->name[loc]; 2449 2597 if(name.empty()) 2450 2598 continue; … … 2458 2606 { 2459 2607 // 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]); 2461 2612 ++counter; 2462 2613 } … … 2470 2621 bool ChatHandler::HandleLookupSkillCommand(const char* args) 2471 2622 { 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(); 2482 2628 2483 2629 std::string namepart = args; … … 2498 2644 if(skillInfo) 2499 2645 { 2500 int loc = m_session ->GetSessionDbcLocale();2646 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale(); 2501 2647 std::string name = skillInfo->name[loc]; 2502 2648 if(name.empty()) … … 2508 2654 for(; loc < MAX_LOCALE; ++loc) 2509 2655 { 2510 if( loc==m_session->GetSessionDbcLocale())2656 if(m_session && loc==m_session->GetSessionDbcLocale()) 2511 2657 continue; 2512 2658 … … 2522 2668 if(loc < MAX_LOCALE) 2523 2669 { 2670 char const* knownStr = ""; 2671 if(target && target->HasSkill(id)) 2672 knownStr = GetTrinityString(LANG_KNOWN); 2673 2524 2674 // 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); 2526 2679 2527 2680 ++counter; … … 2536 2689 bool ChatHandler::HandleLookupSpellCommand(const char* args) 2537 2690 { 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(); 2548 2696 2549 2697 std::string namepart = args; … … 2564 2712 if(spellInfo) 2565 2713 { 2566 int loc = m_session ->GetSessionDbcLocale();2714 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale(); 2567 2715 std::string name = spellInfo->SpellName[loc]; 2568 2716 if(name.empty()) … … 2574 2722 for(; loc < MAX_LOCALE; ++loc) 2575 2723 { 2576 if( loc==m_session->GetSessionDbcLocale())2724 if(m_session && loc==m_session->GetSessionDbcLocale()) 2577 2725 continue; 2578 2726 … … 2588 2736 if(loc < MAX_LOCALE) 2589 2737 { 2590 bool known = target ->HasSpell(id);2738 bool known = target && target->HasSpell(id); 2591 2739 bool learn = (spellInfo->Effect[0] == SPELL_EFFECT_LEARN_SPELL); 2592 2740 … … 2595 2743 bool talent = (telentCost > 0); 2596 2744 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)); 2598 2746 2599 2747 // unit32 used to prevent interpreting uint8 as char at output … … 2603 2751 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format 2604 2752 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; 2606 2757 2607 2758 // include rank in link name … … 2609 2760 ss << GetTrinityString(LANG_SPELL_RANK) << rank; 2610 2761 2611 ss << " " << localeNames[loc] << "]|h|r"; 2762 if (m_session) 2763 ss << " " << localeNames[loc] << "]|h|r"; 2764 else 2765 ss << " " << localeNames[loc]; 2612 2766 2613 2767 if(talent) … … 2635 2789 bool ChatHandler::HandleLookupQuestCommand(const char* args) 2636 2790 { 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(); 2647 2796 2648 2797 std::string namepart = args; … … 2662 2811 Quest * qinfo = iter->second; 2663 2812 2664 int loc_idx = m_session ->GetSessionDbLocaleIndex();2813 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex(); 2665 2814 if ( loc_idx >= 0 ) 2666 2815 { … … 2674 2823 if (Utf8FitTo(title, wnamepart)) 2675 2824 { 2676 QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());2677 2678 2825 char const* statusStr = ""; 2679 if(status == QUEST_STATUS_COMPLETE) 2826 2827 if(target) 2680 2828 { 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); 2685 2840 } 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 2690 2847 ++counter; 2691 2848 continue; … … 2701 2858 if (Utf8FitTo(title, wnamepart)) 2702 2859 { 2703 QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());2704 2705 2860 char const* statusStr = ""; 2706 if(status == QUEST_STATUS_COMPLETE) 2861 2862 if(target) 2707 2863 { 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); 2712 2875 } 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 2717 2882 ++counter; 2718 2883 } … … 2727 2892 bool ChatHandler::HandleLookupCreatureCommand(const char* args) 2728 2893 { 2729 if (!*args)2894 if (!*args) 2730 2895 return false; 2731 2896 … … 2734 2899 2735 2900 // 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); 2740 2905 2741 2906 uint32 counter = 0; 2742 2907 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); 2746 2911 if(!cInfo) 2747 2912 continue; 2748 2913 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) 2751 2916 { 2752 CreatureLocale const *cl = objmgr.GetCreatureLocale (id);2917 CreatureLocale const *cl = objmgr.GetCreatureLocale (id); 2753 2918 if (cl) 2754 2919 { 2755 if (cl->Name.size() > loc_idx && !cl->Name[loc_idx].empty ())2920 if (cl->Name.size() > loc_idx && !cl->Name[loc_idx].empty ()) 2756 2921 { 2757 2922 std::string name = cl->Name[loc_idx]; 2758 2923 2759 if (Utf8FitTo (name, wnamepart))2924 if (Utf8FitTo (name, wnamepart)) 2760 2925 { 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 2762 2931 ++counter; 2763 2932 continue; … … 2768 2937 2769 2938 std::string name = cInfo->Name; 2770 if (name.empty())2939 if (name.empty ()) 2771 2940 continue; 2772 2941 2773 2942 if (Utf8FitTo(name, wnamepart)) 2774 2943 { 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 ()); 2776 2948 ++counter; 2777 2949 } … … 2779 2951 2780 2952 if (counter==0) 2781 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND);2953 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND); 2782 2954 2783 2955 return true; … … 2806 2978 continue; 2807 2979 2808 int loc_idx = m_session ->GetSessionDbLocaleIndex();2980 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex(); 2809 2981 if ( loc_idx >= 0 ) 2810 2982 { … … 2818 2990 if (Utf8FitTo(name, wnamepart)) 2819 2991 { 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()); 2821 2996 ++counter; 2822 2997 continue; … … 2832 3007 if(Utf8FitTo(name, wnamepart)) 2833 3008 { 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()); 2835 3013 ++counter; 2836 3014 } … … 2857 3035 return false; 2858 3036 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); 2902 3076 return true; 2903 3077 } … … 2905 3079 bool ChatHandler::HandleGuildInviteCommand(const char *args) 2906 3080 { 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, " "); 2911 3085 char* par2 = strtok (NULL, ""); 2912 3086 if(!par1 || !par2) … … 2914 3088 2915 3089 std::string glName = par2; 2916 Guild* targetGuild = objmgr.GetGuildByName (glName);2917 if(!targetGuild)3090 Guild* targetGuild = objmgr.GetGuildByName (glName); 3091 if (!targetGuild) 2918 3092 return false; 2919 3093 2920 3094 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); 2925 3099 return false; 2926 3100 } 2927 3101 2928 3102 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 (); 2931 3105 else 2932 plGuid = objmgr.GetPlayerGUIDByName (plName.c_str());2933 2934 if (!plGuid)3106 plGuid = objmgr.GetPlayerGUIDByName (plName.c_str ()); 3107 3108 if (!plGuid) 2935 3109 false; 2936 3110 2937 3111 // players's guild membership checked in AddMember before add 2938 if (!targetGuild->AddMember(plGuid,targetGuild->GetLowestRank()))3112 if (!targetGuild->AddMember (plGuid,targetGuild->GetLowestRank ())) 2939 3113 return false; 2940 3114 … … 2944 3118 bool ChatHandler::HandleGuildUninviteCommand(const char *args) 2945 3119 { 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, " "); 2950 3124 if(!par1) 2951 3125 return false; 3126 2952 3127 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); 2957 3132 return false; 2958 3133 } … … 2960 3135 uint64 plGuid = 0; 2961 3136 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 (); 2966 3141 } 2967 3142 else 2968 3143 { 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); 2981 3156 2982 3157 return true; … … 2985 3160 bool ChatHandler::HandleGuildRankCommand(const char *args) 2986 3161 { 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 2994 3170 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); 2999 3175 return false; 3000 3176 } … … 3002 3178 uint64 plGuid = 0; 3003 3179 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 (); 3008 3184 } 3009 3185 else 3010 3186 { 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); 3027 3203 3028 3204 return true; … … 3031 3207 bool ChatHandler::HandleGuildDeleteCommand(const char* args) 3032 3208 { 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) 3038 3214 return false; 3039 3215 3040 3216 std::string gld = par1; 3041 3217 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 (); 3047 3223 3048 3224 return true; … … 3472 3648 } 3473 3649 3474 bool ChatHandler::HandleSpawnTransportCommand(const char* /*args*/)3475 {3476 return true;3477 }3478 3479 3650 //play npc emote 3480 3651 bool ChatHandler::HandlePlayEmoteCommand(const char* args) … … 4721 4892 } 4722 4893 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," "); 4894 bool ChatHandler::HandleBanAccountCommand(const char* args) 4895 { 4896 return HandleBanHelper(BAN_ACCOUNT,args); 4897 } 4898 4899 bool ChatHandler::HandleBanCharacterCommand(const char* args) 4900 { 4901 return HandleBanHelper(BAN_CHARACTER,args); 4902 } 4903 4904 bool ChatHandler::HandleBanIPCommand(const char* args) 4905 { 4906 return HandleBanHelper(BAN_IP,args); 4907 } 4908 4909 bool 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," "); 4738 4921 if(!duration || !atoi(duration)) 4739 4922 return false; 4740 4923 4741 char* reason = strtok (NULL,"");4924 char* reason = strtok (NULL,""); 4742 4925 if(!reason) 4743 4926 return false; 4744 4927 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() : "")) 4746 4953 { 4747 4954 case BAN_SUCCESS: 4748 4955 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); 4750 4957 else 4751 PSendSysMessage(LANG_BAN_YOUPERMBANNED,nameOrIP ,reason);4958 PSendSysMessage(LANG_BAN_YOUPERMBANNED,nameOrIP.c_str(),reason); 4752 4959 break; 4753 4960 case BAN_SYNTAX_ERROR: 4754 4961 return false; 4755 4962 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 4983 bool ChatHandler::HandleUnBanAccountCommand(const char* args) 4984 { 4985 return HandleUnBanHelper(BAN_ACCOUNT,args); 4986 } 4987 4988 bool ChatHandler::HandleUnBanCharacterCommand(const char* args) 4989 { 4990 return HandleUnBanHelper(BAN_CHARACTER,args); 4991 } 4992 4993 bool ChatHandler::HandleUnBanIPCommand(const char* args) 4994 { 4995 return HandleUnBanHelper(BAN_IP,args); 4996 } 4997 4998 bool ChatHandler::HandleUnBanHelper(BanMode mode, const char* args) 4764 4999 { 4765 5000 if(!args) 4766 5001 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) 4791 5005 return false; 4792 5006 4793 5007 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)) 4809 5012 { 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)) 4821 5020 { 4822 5021 SendSysMessage(LANG_PLAYER_NOT_FOUND); … … 4824 5023 return false; 4825 5024 } 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 5040 bool 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 5067 bool 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 5102 bool 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 5130 bool 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 5161 bool 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 5181 bool 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 5212 bool 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 5290 bool 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 4845 5335 { 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 } 4955 5358 4956 5359 delete result; … … 5013 5416 bool ChatHandler::HandleLoadPDumpCommand(const char *args) 5014 5417 { 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); 5024 5438 if(!account_id) 5025 5439 { 5026 account_id = atoi(acc );5027 if( account_id)5440 account_id = atoi(account); // use original string 5441 if(!account_id) 5028 5442 { 5029 std::string acc_name;5030 if(!accmgr.GetName(account_id,acc_name)) 5031 5443 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str()); 5444 SetSentErrorMessage(true); 5445 return false; 5032 5446 } 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); 5034 5475 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 } 5046 5523 5047 5524 return true; … … 5087 5564 guid = atoi(p2); 5088 5565 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 } 5093 5587 5094 5588 return true; … … 5574 6068 } 5575 6069 6070 /// Display the list of GMs 6071 bool 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 6098 bool 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 6106 bool 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 6159 bool 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 5576 6199 bool ChatHandler::HandleFreezeCommand(const char *args) 5577 6200 {