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

[svn] * Avoid access to bag item prototype for getting bag size, use related item update field instead as more fast source.
* Better check client inventory pos data received in some client packets to skip invalid cases.
* Removed some unnecessary database queries.
* Make guid lookup for adding ignore async.
* Added two parameter versions of the AsyncQuery? function
* Make queries for adding friends async. - Hunuza
* Replace some PQuery() calls with more simple Query() - Hunuza
* Mark spell as executed instead of deleteable to solve crash.
*** Source mangos.

**Its a big commit. so test with care... or without care.... whatever floats your boat.

Original author: KingPin?
Date: 2008-11-05 20:10:19-06:00

Files:
1 modified

Legend:

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

    r139 r173  
    2222#include "Language.h" 
    2323#include "Database/DatabaseEnv.h" 
     24#include "Database/DatabaseImpl.h" 
    2425#include "WorldPacket.h" 
    2526#include "Opcodes.h" 
     
    650651    sLog.outDebug( "WORLD: Received CMSG_ADD_FRIEND" ); 
    651652 
    652     std::string friendName  = GetTrinityString(LANG_FRIEND_IGNORE_UNKNOWN); 
     653    std::string friendName = GetTrinityString(LANG_FRIEND_IGNORE_UNKNOWN); 
    653654    std::string friendNote; 
    654     FriendsResult friendResult = FRIEND_NOT_FOUND; 
    655     Player *pFriend     = NULL; 
    656     uint64 friendGuid   = 0; 
    657  
     655     
    658656    recv_data >> friendName; 
    659657 
     
    671669        GetPlayer()->GetName(), friendName.c_str() ); 
    672670 
    673     friendGuid = objmgr.GetPlayerGUIDByName(friendName); 
    674  
     671    CharacterDatabase.AsyncPQuery(&WorldSession::HandleAddFriendOpcodeCallBack, GetAccountId(), friendNote, "SELECT guid, race FROM characters WHERE name = '%s'", friendName.c_str()); 
     672} 
     673 
     674void WorldSession::HandleAddFriendOpcodeCallBack(QueryResult *result, uint32 accountId, std::string friendNote) 
     675{ 
     676    if(!result) 
     677        return; 
     678         
     679    uint64 friendGuid = MAKE_NEW_GUID((*result)[0].GetUInt32(), 0, HIGHGUID_PLAYER); 
     680    uint32 team = Player::TeamForRace((*result)[1].GetUInt8()); 
     681     
     682    delete result; 
     683     
     684    WorldSession * session = sWorld.FindSession(accountId); 
     685    if(!session) 
     686        return; 
     687         
     688    FriendsResult friendResult = FRIEND_NOT_FOUND; 
    675689    if(friendGuid) 
    676690    { 
    677         pFriend = ObjectAccessor::FindPlayer(friendGuid); 
    678         if(pFriend==GetPlayer()) 
     691        if(friendGuid==session->GetPlayer()->GetGUID()) 
    679692            friendResult = FRIEND_SELF; 
    680         else if(GetPlayer()->GetTeam()!=objmgr.GetPlayerTeamByGUID(friendGuid) && !sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_ADD_FRIEND) && GetSecurity() < SEC_MODERATOR) 
     693        else if(session->GetPlayer()->GetTeam() != team && !sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_ADD_FRIEND) && session->GetSecurity() < SEC_MODERATOR) 
    681694            friendResult = FRIEND_ENEMY; 
    682         else if(GetPlayer()->GetSocial()->HasFriend(GUID_LOPART(friendGuid))) 
     695        else if(session->GetPlayer()->GetSocial()->HasFriend(GUID_LOPART(friendGuid))) 
    683696            friendResult = FRIEND_ALREADY; 
    684     } 
    685  
    686     if (friendGuid && friendResult==FRIEND_NOT_FOUND) 
    687     { 
    688         if( pFriend && pFriend->IsInWorld() && pFriend->IsVisibleGloballyFor(GetPlayer())) 
    689             friendResult = FRIEND_ADDED_ONLINE; 
    690697        else 
    691             friendResult = FRIEND_ADDED_OFFLINE; 
    692  
    693         if(!_player->GetSocial()->AddToSocialList(GUID_LOPART(friendGuid), false)) 
     698        { 
     699            Player* pFriend = ObjectAccessor::FindPlayer(friendGuid); 
     700            if( pFriend && pFriend->IsInWorld() && pFriend->IsVisibleGloballyFor(session->GetPlayer())) 
     701                friendResult = FRIEND_ADDED_ONLINE; 
     702            else 
     703                friendResult = FRIEND_ADDED_OFFLINE; 
     704                 
     705        if(!session->GetPlayer()->GetSocial()->AddToSocialList(GUID_LOPART(friendGuid), false)) 
    694706        { 
    695707            friendResult = FRIEND_LIST_FULL; 
    696             sLog.outDebug( "WORLD: %s's friend list is full.", GetPlayer()->GetName()); 
    697         } 
    698  
    699         _player->GetSocial()->SetFriendNote(GUID_LOPART(friendGuid), friendNote); 
    700  
    701         sLog.outDebug( "WORLD: %s Guid found '%u'.", friendName.c_str(), GUID_LOPART(friendGuid)); 
    702     } 
    703     else if(friendResult==FRIEND_ALREADY) 
    704     { 
    705         sLog.outDebug( "WORLD: %s Guid Already a Friend.", friendName.c_str() ); 
    706     } 
    707     else if(friendResult==FRIEND_SELF) 
    708     { 
    709         sLog.outDebug( "WORLD: %s Guid can't add himself.", friendName.c_str() ); 
    710     } 
    711     else 
    712     { 
    713         sLog.outDebug( "WORLD: %s Guid not found.", friendName.c_str() ); 
    714     } 
    715  
    716     sSocialMgr.SendFriendStatus(GetPlayer(), friendResult, GUID_LOPART(friendGuid), friendName, false); 
     708            sLog.outDebug( "WORLD: %s's friend list is full.", session->GetPlayer()->GetName()); 
     709        } 
     710 
     711            session->GetPlayer()->GetSocial()->SetFriendNote(GUID_LOPART(friendGuid), friendNote); 
     712        } 
     713    } 
     714 
     715    sSocialMgr.SendFriendStatus(session->GetPlayer(), friendResult, GUID_LOPART(friendGuid), false); 
    717716 
    718717    sLog.outDebug( "WORLD: Sent (SMSG_FRIEND_STATUS)" ); 
     
    731730    _player->GetSocial()->RemoveFromSocialList(GUID_LOPART(FriendGUID), false); 
    732731 
    733     sSocialMgr.SendFriendStatus(GetPlayer(), FRIEND_REMOVED, GUID_LOPART(FriendGUID), "", false); 
     732    sSocialMgr.SendFriendStatus(GetPlayer(), FRIEND_REMOVED, GUID_LOPART(FriendGUID), false); 
    734733 
    735734    sLog.outDebug( "WORLD: Sent motd (SMSG_FRIEND_STATUS)" ); 
     
    743742 
    744743    std::string IgnoreName = GetTrinityString(LANG_FRIEND_IGNORE_UNKNOWN); 
    745     FriendsResult ignoreResult = FRIEND_IGNORE_NOT_FOUND; 
    746     uint64 IgnoreGuid = 0; 
    747744 
    748745    recv_data >> IgnoreName; 
     
    756753        GetPlayer()->GetName(), IgnoreName.c_str() ); 
    757754 
    758     IgnoreGuid = objmgr.GetPlayerGUIDByName(IgnoreName); 
    759  
     755    CharacterDatabase.AsyncPQuery(&WorldSession::HandleAddIgnoreOpcodeCallBack, GetAccountId(), "SELECT guid FROM characters WHERE name = '%s'", IgnoreName.c_str()); 
     756} 
     757 
     758void WorldSession::HandleAddIgnoreOpcodeCallBack(QueryResult *result, uint32 accountId) 
     759{ 
     760    if(!result) 
     761        return; 
     762     
     763    uint64 IgnoreGuid = MAKE_NEW_GUID((*result)[0].GetUInt32(), 0, HIGHGUID_PLAYER); 
     764     
     765    delete result; 
     766     
     767    WorldSession * session = sWorld.FindSession(accountId); 
     768    if(!session) 
     769        return; 
     770         
     771    FriendsResult ignoreResult = FRIEND_IGNORE_NOT_FOUND; 
    760772    if(IgnoreGuid) 
    761773    { 
    762         if(IgnoreGuid==GetPlayer()->GetGUID()) 
     774        if(IgnoreGuid==session->GetPlayer()->GetGUID())              //not add yourself 
    763775            ignoreResult = FRIEND_IGNORE_SELF; 
     776            else if( session->GetPlayer()->GetSocial()->HasIgnore(GUID_LOPART(IgnoreGuid)) ) 
     777                ignoreResult = FRIEND_IGNORE_ALREADY; 
    764778        else 
    765779        { 
    766             if( GetPlayer()->GetSocial()->HasIgnore(GUID_LOPART(IgnoreGuid)) ) 
    767                 ignoreResult = FRIEND_IGNORE_ALREADY; 
    768         } 
    769     } 
    770  
    771     if (IgnoreGuid && ignoreResult == FRIEND_IGNORE_NOT_FOUND) 
    772     { 
    773         ignoreResult = FRIEND_IGNORE_ADDED; 
    774  
    775         if(!_player->GetSocial()->AddToSocialList(GUID_LOPART(IgnoreGuid), true)) 
     780            ignoreResult = FRIEND_IGNORE_ADDED; 
     781 
     782        // ignore list full 
     783        if(!session->GetPlayer()->GetSocial()->AddToSocialList(GUID_LOPART(IgnoreGuid), true)) 
    776784            ignoreResult = FRIEND_IGNORE_FULL; 
    777     } 
    778     else if(ignoreResult==FRIEND_IGNORE_ALREADY) 
    779     { 
    780         sLog.outDebug( "WORLD: %s Guid Already Ignored.", IgnoreName.c_str() ); 
    781     } 
    782     else if(ignoreResult==FRIEND_IGNORE_SELF) 
    783     { 
    784         sLog.outDebug( "WORLD: %s Guid can't add himself.", IgnoreName.c_str() ); 
    785     } 
    786     else 
    787     { 
    788         sLog.outDebug( "WORLD: %s Guid not found.", IgnoreName.c_str() ); 
    789     } 
    790  
    791     sSocialMgr.SendFriendStatus(GetPlayer(), ignoreResult, GUID_LOPART(IgnoreGuid), "", false); 
     785        } 
     786    } 
     787 
     788    sSocialMgr.SendFriendStatus(session->GetPlayer(), ignoreResult, GUID_LOPART(IgnoreGuid), false); 
    792789 
    793790    sLog.outDebug( "WORLD: Sent (SMSG_FRIEND_STATUS)" ); 
     
    806803    _player->GetSocial()->RemoveFromSocialList(GUID_LOPART(IgnoreGUID), true); 
    807804 
    808     sSocialMgr.SendFriendStatus(GetPlayer(), FRIEND_IGNORE_REMOVED, GUID_LOPART(IgnoreGUID), "", false); 
     805    sSocialMgr.SendFriendStatus(GetPlayer(), FRIEND_IGNORE_REMOVED, GUID_LOPART(IgnoreGUID), false); 
    809806 
    810807    sLog.outDebug( "WORLD: Sent motd (SMSG_FRIEND_STATUS)" );