Changeset 173 for trunk

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

Location:
trunk/src
Files:
27 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/framework/Utilities/EventProcessor.cpp

    r102 r173  
    2929EventProcessor::~EventProcessor() 
    3030{ 
    31     KillAllEvents(); 
     31    KillAllEvents(true); 
    3232} 
    3333 
     
    6161} 
    6262 
    63 void EventProcessor::KillAllEvents() 
     63void EventProcessor::KillAllEvents(bool force) 
    6464{ 
    6565    // prevent event insertions 
     
    6767 
    6868    // first, abort all existing events 
    69     for (EventList::iterator i = m_events.begin(); i != m_events.end(); ++i) 
     69    for (EventList::iterator i = m_events.begin(); i != m_events.end();) 
    7070    { 
    71         i->second->to_Abort = true; 
    72         i->second->Abort(m_time); 
    73         delete i->second; 
     71        EventList::iterator i_old = i; 
     72        ++i; 
     73         
     74        i_old->second->to_Abort = true; 
     75        i_old->second->Abort(m_time); 
     76        if(force || i_old->second->IsDeletable()) 
     77        { 
     78            delete i_old->second; 
     79             
     80            if(!force)                                      // need per-element cleanup 
     81                m_events.erase (i_old); 
     82        } 
    7483    } 
    7584 
    76     // clear event list 
    77     m_events.clear(); 
     85    // fast clear event list (in force case) 
     86    if(force) 
     87        m_events.clear(); 
    7888} 
    7989 
  • trunk/src/framework/Utilities/EventProcessor.h

    r102 r173  
    4040        // e_time is execution time, p_time is update interval 
    4141        virtual bool Execute(uint64 /*e_time*/, uint32 /*p_time*/) { return true; } 
     42         
     43        virtual bool IsDeletable() const { return true; }   // this event can be safely deleted 
    4244 
    4345        virtual void Abort(uint64 /*e_time*/) {}            // this method executes when the event is aborted 
     
    6062 
    6163        void Update(uint32 p_time); 
    62         void KillAllEvents(); 
     64        void KillAllEvents(bool force); 
    6365        void AddEvent(BasicEvent* Event, uint64 e_time, bool set_addtime = true); 
    6466        uint64 CalculateTime(uint64 t_offset); 
  • trunk/src/game/CharacterHandler.cpp

    r168 r173  
    635635 
    636636    // friend status 
    637     sSocialMgr.SendFriendStatus(pCurrChar, FRIEND_ONLINE, pCurrChar->GetGUIDLow(), "", true); 
     637    sSocialMgr.SendFriendStatus(pCurrChar, FRIEND_ONLINE, pCurrChar->GetGUIDLow(), true); 
    638638 
    639639    // Place character in world (and load zone) before some object loading 
  • trunk/src/game/Creature.cpp

    r168 r173  
    854854            return; 
    855855    } 
    856     uint32 textid=GetGossipTextId( action, zoneid); 
    857     if(textid==0) 
    858         textid=GetNpcTextId(); 
    859856 
    860857    switch (gossip->Action) 
    861858    { 
    862859        case GOSSIP_OPTION_GOSSIP: 
     860        { 
     861            uint32 textid = GetGossipTextId(action, zoneid); 
     862            if (textid == 0) 
     863                textid=GetNpcTextId(); 
     864 
    863865            player->PlayerTalkClass->CloseGossip(); 
    864866            player->PlayerTalkClass->SendTalking(textid); 
    865867            break; 
     868                } 
    866869        case GOSSIP_OPTION_OUTDOORPVP: 
    867870            sOutdoorPvPMgr.HandleGossipOption(player, GetGUID(), option); 
  • trunk/src/game/Guild.cpp

    r102 r173  
    113113bool Guild::AddMember(uint64 plGuid, uint32 plRank) 
    114114{ 
    115     if(Player::GetGuildIdFromDB(plGuid) != 0)               // player already in guild 
     115    Player* pl = objmgr.GetPlayer(plGuid); 
     116    if(pl) 
     117    { 
     118        if(pl->GetGuildId() != 0) 
    116119        return false; 
     120    } 
     121    else 
     122    { 
     123        if(Player::GetGuildIdFromDB(plGuid) != 0)           // player already in guild 
     124        return false; 
     125    } 
    117126 
    118127    // remove all player signs from another petitions 
     
    143152        Id, GUID_LOPART(plGuid), newmember.RankId, dbPnote.c_str(), dbOFFnote.c_str()); 
    144153 
    145     Player* pl = objmgr.GetPlayer(plGuid); 
    146154    if(pl) 
    147155    { 
     
    675683 
    676684    CharacterDatabase.PExecute("UPDATE guild_rank SET rights='%u' WHERE rid='%u' AND guildid='%u'", rights, (rankId+1), Id); 
     685} 
     686 
     687int32 Guild::GetRank(uint32 LowGuid) 
     688{ 
     689    MemberList::iterator itr = members.find(LowGuid); 
     690    if (itr==members.end()) 
     691        return -1; 
     692         
     693    return itr->second.RankId; 
    677694} 
    678695 
  • trunk/src/game/Guild.h

    r102 r173  
    327327            return ((GetRankRights(rankId) & right) != GR_RIGHT_EMPTY) ? true : false; 
    328328        } 
     329        int32 GetRank(uint32 LowGuid); 
    329330 
    330331        void Roster(WorldSession *session); 
  • trunk/src/game/GuildHandler.cpp

    r102 r173  
    165165        return; 
    166166 
     167    guild = objmgr.GetGuildById(GetPlayer()->GetGuildId()); 
     168    if(!guild) 
     169    { 
     170        SendGuildCommandResult(GUILD_CREATE_S, "", GUILD_PLAYER_NOT_IN_GUILD); 
     171        return; 
     172    } 
     173     
     174    if(!guild->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_REMOVE)) 
     175    { 
     176        SendGuildCommandResult(GUILD_INVITE_S, "", GUILD_PERMISSIONS); 
     177        return; 
     178    } 
     179     
    167180    player = ObjectAccessor::Instance().FindPlayerByName(plName.c_str()); 
    168     guild = objmgr.GetGuildById(GetPlayer()->GetGuildId()); 
    169  
    170181    if(player) 
    171182    { 
     
    179190    } 
    180191 
    181     if(!guild) 
    182     { 
    183         SendGuildCommandResult(GUILD_CREATE_S, "", GUILD_PLAYER_NOT_IN_GUILD); 
    184         return; 
    185     } 
    186  
    187192    if(!plGuid) 
    188193    { 
    189194        SendGuildCommandResult(GUILD_INVITE_S, plName, GUILD_PLAYER_NOT_FOUND); 
    190         return; 
    191     } 
    192  
    193     if(!guild->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_REMOVE)) 
    194     { 
    195         SendGuildCommandResult(GUILD_INVITE_S, "", GUILD_PERMISSIONS); 
    196195        return; 
    197196    } 
     
    297296 
    298297    std::string plName; 
    299     uint64 plGuid; 
    300     uint32 plGuildId; 
    301     uint32 plRankId; 
    302     Player *player; 
    303     Guild *guild; 
    304298 
    305299    //sLog.outDebug("WORLD: Received CMSG_GUILD_PROMOTE"); 
     
    309303    if(!normalizePlayerName(plName)) 
    310304        return; 
    311  
    312     player = ObjectAccessor::Instance().FindPlayerByName(plName.c_str()); 
    313     guild = objmgr.GetGuildById(GetPlayer()->GetGuildId()); 
    314     if(player) 
    315     { 
    316         plGuid = player->GetGUID(); 
    317         plGuildId = player->GetGuildId(); 
    318         plRankId = player->GetRank(); 
    319     } 
    320     else 
    321     { 
    322         plGuid = objmgr.GetPlayerGUIDByName(plName); 
    323         plGuildId = Player::GetGuildIdFromDB(plGuid); 
    324         plRankId = Player::GetRankFromDB(plGuid); 
    325     } 
    326  
     305         
     306    Guild* guild = objmgr.GetGuildById(GetPlayer()->GetGuildId()); 
    327307    if(!guild) 
    328308    { 
     
    330310        return; 
    331311    } 
    332     else if(!plGuid) 
     312    if(!guild->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_PROMOTE)) 
     313    { 
     314        SendGuildCommandResult(GUILD_INVITE_S, "", GUILD_PERMISSIONS); 
     315        return; 
     316    } 
     317     
     318    uint64 plGuid = objmgr.GetPlayerGUIDByName(plName); 
     319     
     320    if(!plGuid) 
    333321    { 
    334322        SendGuildCommandResult(GUILD_INVITE_S, plName, GUILD_PLAYER_NOT_FOUND); 
     
    340328        return; 
    341329    } 
    342     else if(GetPlayer()->GetGuildId() != plGuildId) 
     330     
     331    int32 plRankId = guild->GetRank(GUID_LOPART(plGuid)); 
     332    if(plRankId == -1) 
    343333    { 
    344334        SendGuildCommandResult(GUILD_INVITE_S, plName, GUILD_PLAYER_NOT_IN_GUILD_S); 
    345335        return; 
    346336    } 
    347     else if(!guild->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_PROMOTE)) 
    348     { 
    349         SendGuildCommandResult(GUILD_INVITE_S, "", GUILD_PERMISSIONS); 
    350         return; 
    351     } 
    352     else if((plRankId-1) == 0 || (plRankId-1) < this->GetPlayer()->GetRank()) 
    353         return; 
    354  
    355     if(plRankId < 1) 
    356     { 
    357         SendGuildCommandResult(GUILD_INVITE_S, "", GUILD_INTERNAL); 
    358         return; 
    359     } 
     337    if(plRankId < 2 || (plRankId-1) < GetPlayer()->GetRank()) 
     338        return; 
    360339 
    361340    uint32 newRankId = plRankId < guild->GetNrRanks() ? plRankId-1 : guild->GetNrRanks()-1; 
     
    379358 
    380359    std::string plName; 
    381     uint64 plGuid; 
    382     uint32 plGuildId; 
    383     uint32 plRankId; 
    384     Player *player; 
    385     Guild *guild; 
    386360 
    387361    //sLog.outDebug("WORLD: Received CMSG_GUILD_DEMOTE"); 
     
    392366        return; 
    393367 
    394     player = ObjectAccessor::Instance().FindPlayerByName(plName.c_str()); 
    395     guild = objmgr.GetGuildById(GetPlayer()->GetGuildId()); 
    396     if(player) 
    397     { 
    398         plGuid = player->GetGUID(); 
    399         plGuildId = player->GetGuildId(); 
    400         plRankId = player->GetRank(); 
    401     } 
    402     else 
    403     { 
    404         plGuid = objmgr.GetPlayerGUIDByName(plName); 
    405         plGuildId = Player::GetGuildIdFromDB(plGuid); 
    406         plRankId = Player::GetRankFromDB(plGuid); 
    407     } 
     368    Guild* guild = objmgr.GetGuildById(GetPlayer()->GetGuildId()); 
    408369 
    409370    if(!guild) 
     
    412373        return; 
    413374    } 
     375     
     376    if(!guild->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_DEMOTE)) 
     377    { 
     378        SendGuildCommandResult(GUILD_INVITE_S, "", GUILD_PERMISSIONS); 
     379        return; 
     380    } 
     381     
     382    uint64 plGuid = objmgr.GetPlayerGUIDByName(plName); 
    414383 
    415384    if( !plGuid ) 
     
    425394    } 
    426395 
    427     if(GetPlayer()->GetGuildId() != plGuildId) 
     396    int32 plRankId = guild->GetRank(GUID_LOPART(plGuid)); 
     397    if(plRankId == -1) 
    428398    { 
    429399        SendGuildCommandResult(GUILD_INVITE_S, plName, GUILD_PLAYER_NOT_IN_GUILD_S); 
    430         return; 
    431     } 
    432  
    433     if(!guild->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_DEMOTE)) 
    434     { 
    435         SendGuildCommandResult(GUILD_INVITE_S, "", GUILD_PERMISSIONS); 
    436400        return; 
    437401    } 
     
    536500    if(!normalizePlayerName(name)) 
    537501        return; 
     502         
     503    guild = objmgr.GetGuildById(oldLeader->GetGuildId()); 
     504     
     505    if(!guild) 
     506    { 
     507        SendGuildCommandResult(GUILD_CREATE_S, "", GUILD_PLAYER_NOT_IN_GUILD); 
     508        return; 
     509    } 
     510     
     511    if(oldLeader->GetGUID() != guild->GetLeader()) 
     512    { 
     513        SendGuildCommandResult(GUILD_INVITE_S, "", GUILD_PERMISSIONS); 
     514        return; 
     515    } 
    538516 
    539517    newLeader = ObjectAccessor::Instance().FindPlayerByName(name.c_str()); 
     
    548526        newLeaderGuild = Player::GetGuildIdFromDB(newLeaderGUID); 
    549527    } 
    550     guild = objmgr.GetGuildById(oldLeader->GetGuildId()); 
    551  
    552     if(!guild) 
    553     { 
    554         SendGuildCommandResult(GUILD_CREATE_S, "", GUILD_PLAYER_NOT_IN_GUILD); 
    555         return; 
    556     } 
    557     else if(!newLeaderGUID) 
     528    if(!newLeaderGUID) 
    558529    { 
    559530        SendGuildCommandResult(GUILD_INVITE_S, name, GUILD_PLAYER_NOT_FOUND); 
     
    563534    { 
    564535        SendGuildCommandResult(GUILD_INVITE_S, name, GUILD_PLAYER_NOT_IN_GUILD_S); 
    565         return; 
    566     } 
    567     if(oldLeader->GetGUID() != guild->GetLeader()) 
    568     { 
    569         SendGuildCommandResult(GUILD_INVITE_S, "", GUILD_PERMISSIONS); 
    570536        return; 
    571537    } 
     
    636602        return; 
    637603 
     604    guild = objmgr.GetGuildById(GetPlayer()->GetGuildId()); 
     605    if(!guild) 
     606    { 
     607        SendGuildCommandResult(GUILD_CREATE_S, "", GUILD_PLAYER_NOT_IN_GUILD); 
     608        return; 
     609    } 
     610     
     611    if(!guild->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_EPNOTE)) 
     612    { 
     613        SendGuildCommandResult(GUILD_INVITE_S, "", GUILD_PERMISSIONS); 
     614        return; 
     615    } 
     616     
    638617    player = ObjectAccessor::Instance().FindPlayerByName(name.c_str()); 
    639     guild = objmgr.GetGuildById(GetPlayer()->GetGuildId()); 
    640618    if(player) 
    641619    { 
     
    649627    } 
    650628 
    651     if(!guild) 
    652     { 
    653         SendGuildCommandResult(GUILD_CREATE_S, "", GUILD_PLAYER_NOT_IN_GUILD); 
    654         return; 
    655     } 
    656     else if(!plGuid) 
     629    if(!plGuid) 
    657630    { 
    658631        SendGuildCommandResult(GUILD_INVITE_S, name, GUILD_PLAYER_NOT_FOUND); 
     
    662635    { 
    663636        SendGuildCommandResult(GUILD_INVITE_S, name, GUILD_PLAYER_NOT_IN_GUILD_S); 
    664         return; 
    665     } 
    666     if(!guild->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_EPNOTE)) 
    667     { 
    668         SendGuildCommandResult(GUILD_INVITE_S, "", GUILD_PERMISSIONS); 
    669637        return; 
    670638    } 
     
    693661        return; 
    694662 
     663    guild = objmgr.GetGuildById(GetPlayer()->GetGuildId()); 
     664    if(!guild) 
     665    { 
     666        SendGuildCommandResult(GUILD_CREATE_S, "", GUILD_PLAYER_NOT_IN_GUILD); 
     667        return; 
     668    } 
     669    if(!guild->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_EOFFNOTE)) 
     670    { 
     671        SendGuildCommandResult(GUILD_INVITE_S, "", GUILD_PERMISSIONS); 
     672        return; 
     673    } 
     674     
    695675    player = ObjectAccessor::Instance().FindPlayerByName(plName.c_str()); 
    696     guild = objmgr.GetGuildById(GetPlayer()->GetGuildId()); 
    697676    if(player) 
    698677    { 
     
    706685    } 
    707686 
    708     if(!guild) 
    709     { 
    710         SendGuildCommandResult(GUILD_CREATE_S, "", GUILD_PLAYER_NOT_IN_GUILD); 
    711         return; 
    712     } 
    713     else if( !plGuid ) 
     687    if( !plGuid ) 
    714688    { 
    715689        SendGuildCommandResult(GUILD_INVITE_S, plName, GUILD_PLAYER_NOT_FOUND); 
     
    719693    { 
    720694        SendGuildCommandResult(GUILD_INVITE_S, plName, GUILD_PLAYER_NOT_IN_GUILD_S); 
    721         return; 
    722     } 
    723     if(!guild->HasRankRight(GetPlayer()->GetRank(), GR_RIGHT_EOFFNOTE)) 
    724     { 
    725         SendGuildCommandResult(GUILD_INVITE_S, "", GUILD_PERMISSIONS); 
    726695        return; 
    727696    } 
  • trunk/src/game/InstanceSaveMgr.cpp

    r102 r173  
    272272    // first, obtain total instance set 
    273273    std::set< uint32 > InstanceSet; 
    274     QueryResult *result = CharacterDatabase.PQuery("SELECT id FROM instance"); 
     274    QueryResult *result = CharacterDatabase.Query("SELECT id FROM instance"); 
    275275    if( result ) 
    276276    { 
     
    285285 
    286286    // creature_respawn 
    287     result = WorldDatabase.PQuery("SELECT DISTINCT(instance) FROM creature_respawn WHERE instance <> 0"); 
     287    result = WorldDatabase.Query("SELECT DISTINCT(instance) FROM creature_respawn WHERE instance <> 0"); 
    288288    if( result ) 
    289289    { 
     
    299299 
    300300    // gameobject_respawn 
    301     result = WorldDatabase.PQuery("SELECT DISTINCT(instance) FROM gameobject_respawn WHERE instance <> 0"); 
     301    result = WorldDatabase.Query("SELECT DISTINCT(instance) FROM gameobject_respawn WHERE instance <> 0"); 
    302302    if( result ) 
    303303    { 
     
    328328    // any associations to ids not in this table are assumed to be 
    329329    // cleaned already in CleanupInstances 
    330     QueryResult *result = CharacterDatabase.PQuery("SELECT id FROM instance"); 
     330    QueryResult *result = CharacterDatabase.Query("SELECT id FROM instance"); 
    331331    if( result ) 
    332332    { 
     
    378378    typedef std::map<uint32, std::pair<uint32, uint64> > ResetTimeMapType; 
    379379    ResetTimeMapType InstResetTime; 
    380     QueryResult *result = CharacterDatabase.PQuery("SELECT id, map, resettime FROM instance WHERE resettime > 0"); 
     380    QueryResult *result = CharacterDatabase.Query("SELECT id, map, resettime FROM instance WHERE resettime > 0"); 
    381381    if( result ) 
    382382    { 
     
    394394 
    395395        // update reset time for normal instances with the max creature respawn time + X hours 
    396         result = WorldDatabase.PQuery("SELECT MAX(respawntime), instance FROM creature_respawn WHERE instance > 0 GROUP BY instance"); 
     396        result = WorldDatabase.Query("SELECT MAX(respawntime), instance FROM creature_respawn WHERE instance > 0 GROUP BY instance"); 
    397397        if( result ) 
    398398        { 
  • trunk/src/game/Level2.cpp

    r168 r173  
    17961796    else 
    17971797    { 
     1798        QueryResult *result = CharacterDatabase.PQuery("SELECT totaltime FROM characters WHERE guid = '%u'", targetGUID); 
     1799        if (!result) 
     1800        { 
     1801            SendSysMessage(LANG_PLAYER_NOT_FOUND); 
     1802            SetSentErrorMessage(true); 
     1803            return false; 
     1804        } 
     1805        Field *fields = result->Fetch(); 
     1806        total_player_time = fields[0].GetUInt32(); 
     1807        delete result; 
     1808         
     1809        Tokens data; 
     1810        if (!Player::LoadValuesArrayFromDB(data,targetGUID)) 
     1811        { 
     1812            SendSysMessage(LANG_PLAYER_NOT_FOUND); 
     1813            SetSentErrorMessage(true); 
     1814            return false; 
     1815        } 
     1816         
     1817        money = Player::GetUInt32ValueFromArray(data, PLAYER_FIELD_COINAGE); 
     1818        level = Player::GetUInt32ValueFromArray(data, UNIT_FIELD_LEVEL); 
    17981819        accId = objmgr.GetPlayerAccountIdByGUID(targetGUID); 
    1799         WorldSession session(0,NULL,SEC_PLAYER,0,0,LOCALE_enUS); 
    1800         Player plr(&session);                               // use fake session for temporary load 
    1801         plr.MinimalLoadFromDB(NULL, targetGUID); 
    1802         money = plr.GetMoney(); 
    1803         total_player_time = plr.GetTotalPlayedTime(); 
    1804         level = plr.getLevel(); 
    18051820    } 
    18061821 
     
    33843399            getline (infile,line); 
    33853400            //cout << line << endl; 
    3386             QueryResult *result = WorldDatabase.PQuery(line.c_str()); 
     3401            QueryResult *result = WorldDatabase.Query(line.c_str()); 
    33873402            delete result; 
    33883403        } 
  • trunk/src/game/Level3.cpp

    r169 r173  
    20052005    sLog.outDetail(GetTrinityString(LANG_ADDITEMSET), itemsetId); 
    20062006 
    2007     QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE itemset = %u",itemsetId); 
    2008  
    2009     if(!result) 
     2007    bool found = false; 
     2008    for (uint32 id = 0; id < sItemStorage.MaxEntry; id++) 
     2009    { 
     2010        ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id); 
     2011        if (!pProto) 
     2012            continue; 
     2013 
     2014        if (pProto->ItemSet == itemsetId) 
     2015        { 
     2016            found = true; 
     2017            ItemPosCountVec dest; 
     2018            uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, pProto->ItemId, 1 ); 
     2019            if (msg == EQUIP_ERR_OK) 
     2020            { 
     2021                Item* item = plTarget->StoreNewItem( dest, pProto->ItemId, true); 
     2022                // remove binding (let GM give it to another player later) 
     2023                if (pl==plTarget) 
     2024                    item->SetBinding( false ); 
     2025 
     2026            pl->SendNewItem(item,1,false,true); 
     2027            if (pl!=plTarget) 
     2028                plTarget->SendNewItem(item,1,true,false); 
     2029            } 
     2030            else 
     2031            { 
     2032                pl->SendEquipError( msg, NULL, NULL ); 
     2033                PSendSysMessage(LANG_ITEM_CANNOT_CREATE, pProto->ItemId, 1); 
     2034            } 
     2035        } 
     2036    } 
     2037 
     2038    if (!found) 
    20102039    { 
    20112040        PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId); 
     
    20142043        return false; 
    20152044    } 
    2016  
    2017     do 
    2018     { 
    2019         Field *fields = result->Fetch(); 
    2020         uint32 itemId = fields[0].GetUInt32(); 
    2021  
    2022         ItemPosCountVec dest; 
    2023         uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, itemId, 1 ); 
    2024         if( msg == EQUIP_ERR_OK ) 
    2025         { 
    2026             Item* item = plTarget->StoreNewItem( dest, itemId, true); 
    2027  
    2028             // remove binding (let GM give it to another player later) 
    2029             if(pl==plTarget) 
    2030                 item->SetBinding( false ); 
    2031  
    2032             pl->SendNewItem(item,1,false,true); 
    2033             if(pl!=plTarget) 
    2034                 plTarget->SendNewItem(item,1,true,false); 
    2035         } 
    2036         else 
    2037         { 
    2038             pl->SendEquipError( msg, NULL, NULL ); 
    2039             PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, 1); 
    2040         } 
    2041  
    2042     }while( result->NextRow() ); 
    2043  
    2044     delete result; 
    2045  
    20462045    return true; 
    20472046} 
     
    47664765 
    47674766    // check item starting quest (it can work incorrectly if added without item in inventory) 
    4768     QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE startquest = '%u' LIMIT 1",entry); 
    4769     if(result) 
    4770     { 
    4771         Field* fields = result->Fetch(); 
    4772         uint32 item_id = fields[0].GetUInt32(); 
    4773         delete result; 
    4774  
    4775         PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry,item_id); 
    4776         SetSentErrorMessage(true); 
    4777         return false; 
     4767    for (uint32 id = 0; id < sItemStorage.MaxEntry; id++) 
     4768    { 
     4769        ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id); 
     4770        if (!pProto) 
     4771            continue; 
     4772 
     4773        if (pProto->StartQuest == entry) 
     4774        { 
     4775            PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry, pProto->ItemId); 
     4776            SetSentErrorMessage(true); 
     4777            return false; 
     4778        } 
    47784779    } 
    47794780 
  • trunk/src/game/Map.cpp

    r149 r173  
    13581358            break; 
    13591359        case TYPEID_UNIT: 
     1360            // in case triggred sequence some spell can continue casting after prev CleanupsBeforeDelete call 
     1361            // make sure that like sources auras/etc removed before destructor start 
     1362            ((Creature*)obj)->CleanupsBeforeDelete (); 
    13601363            Remove((Creature*)obj,true); 
    13611364            break; 
  • 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)" ); 
  • trunk/src/game/ObjectMgr.cpp

    r168 r173  
    27292729    uint32 count = 0; 
    27302730    //                                                     0         1              2           3           4              5      6      7      8      9      10     11     12     13      14          15 
    2731     QueryResult *result = CharacterDatabase.PQuery("SELECT mainTank, mainAssistant, lootMethod, looterGuid, lootThreshold, icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8, isRaid, difficulty, leaderGuid FROM groups"); 
     2731    QueryResult *result = CharacterDatabase.Query("SELECT mainTank, mainAssistant, lootMethod, looterGuid, lootThreshold, icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8, isRaid, difficulty, leaderGuid FROM groups"); 
    27322732 
    27332733    if( !result ) 
     
    27712771    leaderGuid = 0; 
    27722772    //                                        0           1          2         3 
    2773     result = CharacterDatabase.PQuery("SELECT memberGuid, assistant, subgroup, leaderGuid FROM group_member ORDER BY leaderGuid"); 
     2773    result = CharacterDatabase.Query("SELECT memberGuid, assistant, subgroup, leaderGuid FROM group_member ORDER BY leaderGuid"); 
    27742774    if(!result) 
    27752775    { 
     
    28242824    group = NULL; 
    28252825    leaderGuid = 0; 
    2826     result = CharacterDatabase.PQuery( 
     2826    result = CharacterDatabase.Query( 
    28272827        //      0           1    2         3          4           5 
    28282828        "SELECT leaderGuid, map, instance, permanent, difficulty, resettime, " 
     
    36923692void ObjectMgr::LoadPetCreateSpells() 
    36933693{ 
    3694     QueryResult *result = WorldDatabase.PQuery("SELECT entry, Spell1, Spell2, Spell3, Spell4 FROM petcreateinfo_spell"); 
     3694    QueryResult *result = WorldDatabase.Query("SELECT entry, Spell1, Spell2, Spell3, Spell4 FROM petcreateinfo_spell"); 
    36953695    if(!result) 
    36963696    { 
     
    40724072void ObjectMgr::LoadItemTexts() 
    40734073{ 
    4074     QueryResult *result = CharacterDatabase.PQuery("SELECT id, text FROM item_text"); 
     4074    QueryResult *result = CharacterDatabase.Query("SELECT id, text FROM item_text"); 
    40754075 
    40764076    uint32 count = 0; 
     
    41554155    mPageTextLocaleMap.clear(); 
    41564156     
    4157     QueryResult *result = WorldDatabase.PQuery("SELECT entry,text_loc1,text_loc2,text_loc3,text_loc4,text_loc5,text_loc6,text_loc7,text_loc8 FROM locales_page_text"); 
     4157    QueryResult *result = WorldDatabase.Query("SELECT entry,text_loc1,text_loc2,text_loc3,text_loc4,text_loc5,text_loc6,text_loc7,text_loc8 FROM locales_page_text"); 
    41584158 
    41594159    if(!result) 
     
    57115711    uint32 count = 0; 
    57125712    //                                                     0           1           2           3            4    5     6     7            8         10 
    5713     QueryResult *result = CharacterDatabase.PQuery("SELECT position_x, position_y, position_z, orientation, map, data, time, corpse_type, instance, guid FROM corpse WHERE corpse_type <> 0"); 
     5713    QueryResult *result = CharacterDatabase.Query("SELECT position_x, position_y, position_z, orientation, map, data, time, corpse_type, instance, guid FROM corpse WHERE corpse_type <> 0"); 
    57145714 
    57155715    if( !result ) 
     
    60756075    m_ReservedNames.clear();                                // need for reload case 
    60766076 
    6077     QueryResult *result = WorldDatabase.PQuery("SELECT name FROM reserved_name"); 
     6077    QueryResult *result = WorldDatabase.Query("SELECT name FROM reserved_name"); 
    60786078 
    60796079    uint32 count = 0; 
     
    69626962    std::set<uint32> skip_trainers; 
    69636963 
    6964     QueryResult *result = WorldDatabase.PQuery("SELECT entry, spell,spellcost,reqskill,reqskillvalue,reqlevel FROM npc_trainer"); 
     6964    QueryResult *result = WorldDatabase.Query("SELECT entry, spell,spellcost,reqskill,reqskillvalue,reqlevel FROM npc_trainer"); 
    69656965 
    69666966    if( !result ) 
     
    70537053    std::set<uint32> skip_vendors; 
    70547054 
    7055     QueryResult *result = WorldDatabase.PQuery("SELECT entry, item, maxcount, incrtime, ExtendedCost FROM npc_vendor"); 
     7055    QueryResult *result = WorldDatabase.Query("SELECT entry, item, maxcount, incrtime, ExtendedCost FROM npc_vendor"); 
    70567056    if( !result ) 
    70577057    { 
     
    70997099    m_mCacheNpcTextIdMap.clear(); 
    71007100 
    7101     QueryResult* result = WorldDatabase.PQuery("SELECT npc_guid, textid FROM npc_gossip"); 
     7101    QueryResult* result = WorldDatabase.Query("SELECT npc_guid, textid FROM npc_gossip"); 
    71027102    if( !result ) 
    71037103    { 
  • trunk/src/game/SkillDiscovery.cpp

    r102 r173  
    5555 
    5656    //                                                 0        1         2 
    57     QueryResult *result = WorldDatabase.PQuery("SELECT spellId, reqSpell, chance FROM skill_discovery_template"); 
     57    QueryResult *result = WorldDatabase.Query("SELECT spellId, reqSpell, chance FROM skill_discovery_template"); 
    5858 
    5959    if (result) 
  • trunk/src/game/SkillExtraItems.cpp

    r102 r173  
    6060 
    6161    //                                                 0        1                       2                       3 
    62     QueryResult *result = WorldDatabase.PQuery("SELECT spellId, requiredSpecialization, additionalCreateChance, additionalMaxNum FROM skill_extra_item_template"); 
     62    QueryResult *result = WorldDatabase.Query("SELECT spellId, requiredSpecialization, additionalCreateChance, additionalMaxNum FROM skill_extra_item_template"); 
    6363 
    6464    if (result) 
  • trunk/src/game/SocialMgr.cpp

    r139 r173  
    238238} 
    239239 
    240 void SocialMgr::SendFriendStatus(Player *player, FriendsResult result, uint32 friend_guid, std::string name, bool broadcast) 
     240void SocialMgr::SendFriendStatus(Player *player, FriendsResult result, uint32 friend_guid, bool broadcast) 
    241241{ 
    242242    FriendInfo fi; 
  • trunk/src/game/SocialMgr.h

    r139 r173  
    148148        // Packet management 
    149149        void MakeFriendStatusPacket(FriendsResult result, uint32 friend_guid, WorldPacket *data); 
    150         void SendFriendStatus(Player *player, FriendsResult result, uint32 friend_guid, std::string name, bool broadcast); 
     150        void SendFriendStatus(Player *player, FriendsResult result, uint32 friend_guid, bool broadcast); 
    151151        void BroadcastToFriendListers(Player *player, WorldPacket *packet); 
    152152        // Loading 
  • trunk/src/game/Spell.cpp

    r168 r173  
    288288    m_magnetPair.first = false; 
    289289    m_magnetPair.second = NULL; 
    290     m_deletable = true; 
     290    m_referencedFromCurrentSpell = false; 
     291    m_executedCurrently = false; 
    291292    m_delayAtDamageCount = 0; 
    292293 
     
    22022203void Spell::cast(bool skipCheck) 
    22032204{ 
     2205    SetExecutedCurrently(true); 
     2206     
    22042207    uint8 castResult = 0; 
    22052208 
     
    22112214    { 
    22122215        cancel(); 
     2216        SetExecutedCurrently(false); 
    22132217        return; 
    22142218    } 
     
    22222226        SendCastResult(castResult); 
    22232227        finish(false); 
     2228        SetExecutedCurrently(false); 
    22242229        return; 
    22252230    } 
     
    22332238            SendCastResult(castResult); 
    22342239            finish(false); 
     2240            SetExecutedCurrently(false); 
    22352241            return; 
    22362242        } 
     
    22782284 
    22792285    if(m_spellState == SPELL_STATE_FINISHED)                // stop cast if spell marked as finish somewhere in Take*/FillTargetMap 
    2280         return; 
     2286    { 
     2287        SetExecutedCurrently(false); 
     2288        return; 
     2289    } 
    22812290 
    22822291    SendCastResult(castResult); 
     
    23102319        handle_immediate(); 
    23112320    } 
     2321     
     2322    SetExecutedCurrently(false); 
    23122323} 
    23132324 
     
    51275138        m_Spell->cancel(); 
    51285139} 
     5140 
     5141bool SpellEvent::IsDeletable() const 
     5142{ 
     5143    return m_Spell->IsDeletable(); 
     5144} 
  • trunk/src/game/Spell.h

    r145 r173  
    397397        bool IsRangedAttackResetSpell() const { return !m_IsTriggeredSpell && IsRangedSpell() && (m_spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_AUTOATTACK); } 
    398398 
    399         bool IsDeletable() const { return m_deletable; } 
    400         void SetDeletable(bool deletable) { m_deletable = deletable; } 
     399        bool IsDeletable() const { return !m_referencedFromCurrentSpell && !m_executedCurrently; } 
     400        void SetReferencedFromCurrent(bool yes) { m_referencedFromCurrentSpell = yes; } 
     401        void SetExecutedCurrently(bool yes) { m_executedCurrently = yes; } 
    401402        uint64 GetDelayStart() const { return m_delayStart; } 
    402403        void SetDelayStart(uint64 m_time) { m_delayStart = m_time; } 
     
    450451 
    451452        // These vars are used in both delayed spell system and modified immediate spell system 
    452         bool m_deletable;                                   // is the spell pending deletion or must be updated till permitted to delete? 
     453        bool m_referencedFromCurrentSpell;                  // mark as references to prevent deleted and access by dead pointers 
     454        bool m_executedCurrently;                           // mark as executed to prevent deleted and access by dead pointers 
    453455        bool m_needSpellLog;                                // need to send spell log? 
    454456        uint8 m_applyMultiplierMask;                        // by effect: damage multiplier needed? 
     
    657659        virtual bool Execute(uint64 e_time, uint32 p_time); 
    658660        virtual void Abort(uint64 e_time); 
     661        virtual bool IsDeletable() const; 
    659662    protected: 
    660663        Spell* m_Spell; 
  • trunk/src/game/SpellAuras.cpp

    r162 r173  
    34833483                { 
    34843484                    currentSpell->cancel(); 
    3485                     currentSpell->SetDeletable(true); 
     3485                    currentSpell->SetReferencedFromCurrent(false); 
    34863486                    m_target->m_currentSpells[i] = NULL; 
    34873487                } 
  • trunk/src/game/SpellMgr.cpp

    r160 r173  
    14591459    mSpellChainsNext.clear();                               // need for reload case 
    14601460 
    1461     QueryResult *result = WorldDatabase.PQuery("SELECT spell_id, prev_spell, first_spell, rank, req_spell FROM spell_chain"); 
     1461    QueryResult *result = WorldDatabase.Query("SELECT spell_id, prev_spell, first_spell, rank, req_spell FROM spell_chain"); 
    14621462    if(result == NULL) 
    14631463    { 
     
    16661666    mSpellLearnSpells.clear();                              // need for reload case 
    16671667 
    1668     QueryResult *result = WorldDatabase.PQuery("SELECT entry, SpellID FROM spell_learn_spell"); 
     1668    QueryResult *result = WorldDatabase.Query("SELECT entry, SpellID FROM spell_learn_spell"); 
    16691669    if(!result) 
    16701670    { 
  • trunk/src/game/Transports.cpp

    r102 r173  
    117117 
    118118    // check transport data DB integrity 
    119     result = WorldDatabase.PQuery("SELECT gameobject.guid,gameobject.id,transports.name FROM gameobject,transports WHERE gameobject.id = transports.entry"); 
     119    result = WorldDatabase.Query("SELECT gameobject.guid,gameobject.id,transports.name FROM gameobject,transports WHERE gameobject.id = transports.entry"); 
    120120    if(result)                                              // wrong data found 
    121121    { 
  • trunk/src/game/Unit.cpp

    r172 r173  
    238238    for (uint32 i = 0; i < CURRENT_MAX_SPELL; i++) 
    239239    { 
    240                                                             // spell may be safely deleted now 
    241         if (m_currentSpells[i]) m_currentSpells[i]->SetDeletable(true); 
    242         m_currentSpells[i] = NULL; 
     240        if (m_currentSpells[i]) 
     241        { 
     242            m_currentSpells[i]->SetReferencedFromCurrent(false); 
     243            m_currentSpells[i] = NULL; 
     244        } 
    243245    } 
    244246 
     
    31643166        if (m_currentSpells[i] && m_currentSpells[i]->getState() == SPELL_STATE_FINISHED) 
    31653167        { 
    3166             m_currentSpells[i]->SetDeletable(true);         // spell may be safely deleted now 
     3168            m_currentSpells[i]->SetReferencedFromCurrent(false); 
    31673169            m_currentSpells[i] = NULL;                      // remove pointer 
    31683170        } 
     
    32773279    uint32 CSpellType = pSpell->GetCurrentContainer(); 
    32783280 
    3279     pSpell->SetDeletable(false);                            // spell will not be deleted until gone from current pointers 
    32803281    if (pSpell == m_currentSpells[CSpellType]) return;      // avoid breaking self 
    32813282 
     
    33343335    // current spell (if it is still here) may be safely deleted now 
    33353336    if (m_currentSpells[CSpellType]) 
    3336         m_currentSpells[CSpellType]->SetDeletable(true); 
     3337        m_currentSpells[CSpellType]->SetReferencedFromCurrent(false); 
    33373338 
    33383339    // set new current spell 
    33393340    m_currentSpells[CSpellType] = pSpell; 
     3341    pSpell->SetReferencedFromCurrent(true); 
    33403342} 
    33413343 
     
    33553357        if (m_currentSpells[spellType]->getState() != SPELL_STATE_FINISHED) 
    33563358            m_currentSpells[spellType]->cancel(); 
    3357         m_currentSpells[spellType]->SetDeletable(true); 
     3359        m_currentSpells[spellType]->SetReferencedFromCurrent(false); 
    33583360        m_currentSpells[spellType] = NULL; 
    33593361    } 
     
    33913393            (withDelayed || m_currentSpells[CURRENT_GENERIC_SPELL]->getState() != SPELL_STATE_DELAYED) ) 
    33923394            m_currentSpells[CURRENT_GENERIC_SPELL]->cancel(); 
    3393         m_currentSpells[CURRENT_GENERIC_SPELL]->SetDeletable(true); 
     3395        m_currentSpells[CURRENT_GENERIC_SPELL]->SetReferencedFromCurrent(false); 
    33943396        m_currentSpells[CURRENT_GENERIC_SPELL] = NULL; 
    33953397    } 
     
    34053407            (withDelayed || m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->getState() != SPELL_STATE_DELAYED) ) 
    34063408            m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->cancel(); 
    3407         m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->SetDeletable(true); 
     3409        m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->SetReferencedFromCurrent(false); 
    34083410        m_currentSpells[CURRENT_AUTOREPEAT_SPELL] = NULL; 
    34093411    } 
     
    34143416        if (m_currentSpells[CURRENT_CHANNELED_SPELL]->getState() != SPELL_STATE_FINISHED) 
    34153417            m_currentSpells[CURRENT_CHANNELED_SPELL]->cancel(); 
    3416         m_currentSpells[CURRENT_CHANNELED_SPELL]->SetDeletable(true); 
     3418        m_currentSpells[CURRENT_CHANNELED_SPELL]->SetReferencedFromCurrent(false); 
    34173419        m_currentSpells[CURRENT_CHANNELED_SPELL] = NULL; 
    34183420    } 
     
    98619863    { 
    98629864        InterruptNonMeleeSpells(true); 
    9863         m_Events.KillAllEvents(); 
     9865        m_Events.KillAllEvents(false);                      // non-delatable (currently casted spells) will not deleted ans will deleated at call in Map::RemoveAllObjectsInRemoveList 
    98649866        CombatStop(); 
    98659867        ClearComboPointHolders(); 
  • trunk/src/game/WorldSession.cpp

    r168 r173  
    380380 
    381381        ///- Broadcast a logout message to the player's friends 
    382         sSocialMgr.SendFriendStatus(_player, FRIEND_OFFLINE, _player->GetGUIDLow(), "", true); 
     382        sSocialMgr.SendFriendStatus(_player, FRIEND_OFFLINE, _player->GetGUIDLow(), true); 
    383383 
    384384        ///- Delete the player object 
  • trunk/src/game/WorldSession.h

    r152 r173  
    282282        void HandleFriendListOpcode(WorldPacket& recvPacket); 
    283283        void HandleAddFriendOpcode(WorldPacket& recvPacket); 
     284        static void HandleAddFriendOpcodeCallBack(QueryResult *result, uint32 accountId, std::string friendNote); 
    284285        void HandleDelFriendOpcode(WorldPacket& recvPacket); 
    285286        void HandleAddIgnoreOpcode(WorldPacket& recvPacket); 
     287        static void HandleAddIgnoreOpcodeCallBack(QueryResult *result, uint32 accountId); 
    286288        void HandleDelIgnoreOpcode(WorldPacket& recvPacket); 
    287289        void HandleSetFriendNoteOpcode(WorldPacket& recvPacket); 
  • trunk/src/shared/Database/Database.h

    r102 r173  
    6262        template<class Class, typename ParamType1> 
    6363            bool AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql); 
     64        template<class Class, typename ParamType1, typename ParamType2> 
     65            bool AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql); 
    6466        template<typename ParamType1> 
    6567            bool AsyncQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql); 
     68        template<typename ParamType1, typename ParamType2> 
     69            bool AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql); 
    6670        template<class Class> 
    6771            bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*), const char *format,...) ATTR_PRINTF(4,5); 
    6872        template<class Class, typename ParamType1> 
    6973            bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) ATTR_PRINTF(5,6); 
     74        template<class Class, typename ParamType1, typename ParamType2> 
     75            bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) ATTR_PRINTF(5,6); 
    7076        template<typename ParamType1> 
    7177            bool AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) ATTR_PRINTF(5,6); 
     78        template<typename ParamType1, typename ParamType2> 
     79            bool AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) ATTR_PRINTF(5,6); 
    7280        template<class Class> 
    7381            bool DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*), SqlQueryHolder *holder); 
  • trunk/src/shared/Database/DatabaseImpl.h

    r102 r173  
    4848} 
    4949 
     50template<class Class, typename ParamType1, typename ParamType2> 
     51bool 
     52Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql) 
     53{ 
     54    if (!sql) return false; 
     55    ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current(); 
     56    QueryQueues::iterator itr = m_queryQueues.find(queryThread); 
     57    if (itr == m_queryQueues.end()) return false; 
     58    m_threadBody->Delay(new SqlQuery(sql, new Trinity::QueryCallback<Class, ParamType1, ParamType2>(object, method, (QueryResult*)NULL, param1, param2), itr->second)); 
     59    return true; 
     60} 
     61 
    5062template<typename ParamType1> 
    5163bool 
     
    6072} 
    6173 
     74template<typename ParamType1, typename ParamType2> 
     75bool 
     76Database::AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql) 
     77{ 
     78    if (!sql) return false; 
     79    ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current(); 
     80    QueryQueues::iterator itr = m_queryQueues.find(queryThread); 
     81    if (itr == m_queryQueues.end()) return false; 
     82    m_threadBody->Delay(new SqlQuery(sql, new Trinity::SQueryCallback<ParamType1, ParamType2>(method, (QueryResult*)NULL, param1, param2), itr->second)); 
     83    return true; 
     84} 
     85 
    6286template<class Class> 
    6387bool 
     
    102126} 
    103127 
     128template<class Class, typename ParamType1, typename ParamType2> 
     129bool 
     130Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) 
     131{ 
     132    if(!format) return false; 
     133 
     134    va_list ap; 
     135    char szQuery [MAX_QUERY_LEN]; 
     136    va_start(ap, format); 
     137    int res = vsnprintf( szQuery, MAX_QUERY_LEN, format, ap ); 
     138    va_end(ap); 
     139 
     140    if(res==-1) 
     141    { 
     142        sLog.outError("SQL Query truncated (and not execute) for format: %s",format); 
     143        return false; 
     144    } 
     145 
     146    return AsyncQuery(object, method, param1, param2, szQuery); 
     147} 
     148 
    104149template<typename ParamType1> 
    105150bool 
     
    123168} 
    124169 
     170template<typename ParamType1, typename ParamType2> 
     171bool 
     172Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) 
     173{ 
     174    if(!format) return false; 
     175 
     176    va_list ap; 
     177    char szQuery [MAX_QUERY_LEN]; 
     178    va_start(ap, format); 
     179    int res = vsnprintf( szQuery, MAX_QUERY_LEN, format, ap ); 
     180    va_end(ap); 
     181 
     182    if(res==-1) 
     183    { 
     184        sLog.outError("SQL Query truncated (and not execute) for format: %s",format); 
     185        return false; 
     186    } 
     187 
     188    return AsyncQuery(method, param1, param2, szQuery); 
     189} 
    125190 
    126191template<class Class>