[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.

--HG--
branch : trunk
This commit is contained in:
KingPin
2008-11-05 20:10:19 -06:00
parent 404f72c7a2
commit 8d331f2b10
27 changed files with 394 additions and 280 deletions

View File

@@ -21,6 +21,7 @@
#include "Common.h"
#include "Language.h"
#include "Database/DatabaseEnv.h"
#include "Database/DatabaseImpl.h"
#include "WorldPacket.h"
#include "Opcodes.h"
#include "Log.h"
@@ -649,12 +650,9 @@ void WorldSession::HandleAddFriendOpcode( WorldPacket & recv_data )
sLog.outDebug( "WORLD: Received CMSG_ADD_FRIEND" );
std::string friendName = GetTrinityString(LANG_FRIEND_IGNORE_UNKNOWN);
std::string friendName = GetTrinityString(LANG_FRIEND_IGNORE_UNKNOWN);
std::string friendNote;
FriendsResult friendResult = FRIEND_NOT_FOUND;
Player *pFriend = NULL;
uint64 friendGuid = 0;
recv_data >> friendName;
// recheck
@@ -670,50 +668,51 @@ void WorldSession::HandleAddFriendOpcode( WorldPacket & recv_data )
sLog.outDebug( "WORLD: %s asked to add friend : '%s'",
GetPlayer()->GetName(), friendName.c_str() );
friendGuid = objmgr.GetPlayerGUIDByName(friendName);
CharacterDatabase.AsyncPQuery(&WorldSession::HandleAddFriendOpcodeCallBack, GetAccountId(), friendNote, "SELECT guid, race FROM characters WHERE name = '%s'", friendName.c_str());
}
void WorldSession::HandleAddFriendOpcodeCallBack(QueryResult *result, uint32 accountId, std::string friendNote)
{
if(!result)
return;
uint64 friendGuid = MAKE_NEW_GUID((*result)[0].GetUInt32(), 0, HIGHGUID_PLAYER);
uint32 team = Player::TeamForRace((*result)[1].GetUInt8());
delete result;
WorldSession * session = sWorld.FindSession(accountId);
if(!session)
return;
FriendsResult friendResult = FRIEND_NOT_FOUND;
if(friendGuid)
{
pFriend = ObjectAccessor::FindPlayer(friendGuid);
if(pFriend==GetPlayer())
if(friendGuid==session->GetPlayer()->GetGUID())
friendResult = FRIEND_SELF;
else if(GetPlayer()->GetTeam()!=objmgr.GetPlayerTeamByGUID(friendGuid) && !sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_ADD_FRIEND) && GetSecurity() < SEC_MODERATOR)
else if(session->GetPlayer()->GetTeam() != team && !sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_ADD_FRIEND) && session->GetSecurity() < SEC_MODERATOR)
friendResult = FRIEND_ENEMY;
else if(GetPlayer()->GetSocial()->HasFriend(GUID_LOPART(friendGuid)))
else if(session->GetPlayer()->GetSocial()->HasFriend(GUID_LOPART(friendGuid)))
friendResult = FRIEND_ALREADY;
}
if (friendGuid && friendResult==FRIEND_NOT_FOUND)
{
if( pFriend && pFriend->IsInWorld() && pFriend->IsVisibleGloballyFor(GetPlayer()))
friendResult = FRIEND_ADDED_ONLINE;
else
friendResult = FRIEND_ADDED_OFFLINE;
if(!_player->GetSocial()->AddToSocialList(GUID_LOPART(friendGuid), false))
{
Player* pFriend = ObjectAccessor::FindPlayer(friendGuid);
if( pFriend && pFriend->IsInWorld() && pFriend->IsVisibleGloballyFor(session->GetPlayer()))
friendResult = FRIEND_ADDED_ONLINE;
else
friendResult = FRIEND_ADDED_OFFLINE;
if(!session->GetPlayer()->GetSocial()->AddToSocialList(GUID_LOPART(friendGuid), false))
{
friendResult = FRIEND_LIST_FULL;
sLog.outDebug( "WORLD: %s's friend list is full.", GetPlayer()->GetName());
sLog.outDebug( "WORLD: %s's friend list is full.", session->GetPlayer()->GetName());
}
_player->GetSocial()->SetFriendNote(GUID_LOPART(friendGuid), friendNote);
sLog.outDebug( "WORLD: %s Guid found '%u'.", friendName.c_str(), GUID_LOPART(friendGuid));
}
else if(friendResult==FRIEND_ALREADY)
{
sLog.outDebug( "WORLD: %s Guid Already a Friend.", friendName.c_str() );
}
else if(friendResult==FRIEND_SELF)
{
sLog.outDebug( "WORLD: %s Guid can't add himself.", friendName.c_str() );
}
else
{
sLog.outDebug( "WORLD: %s Guid not found.", friendName.c_str() );
session->GetPlayer()->GetSocial()->SetFriendNote(GUID_LOPART(friendGuid), friendNote);
}
}
sSocialMgr.SendFriendStatus(GetPlayer(), friendResult, GUID_LOPART(friendGuid), friendName, false);
sSocialMgr.SendFriendStatus(session->GetPlayer(), friendResult, GUID_LOPART(friendGuid), false);
sLog.outDebug( "WORLD: Sent (SMSG_FRIEND_STATUS)" );
}
@@ -730,7 +729,7 @@ void WorldSession::HandleDelFriendOpcode( WorldPacket & recv_data )
_player->GetSocial()->RemoveFromSocialList(GUID_LOPART(FriendGUID), false);
sSocialMgr.SendFriendStatus(GetPlayer(), FRIEND_REMOVED, GUID_LOPART(FriendGUID), "", false);
sSocialMgr.SendFriendStatus(GetPlayer(), FRIEND_REMOVED, GUID_LOPART(FriendGUID), false);
sLog.outDebug( "WORLD: Sent motd (SMSG_FRIEND_STATUS)" );
}
@@ -742,8 +741,6 @@ void WorldSession::HandleAddIgnoreOpcode( WorldPacket & recv_data )
sLog.outDebug( "WORLD: Received CMSG_ADD_IGNORE" );
std::string IgnoreName = GetTrinityString(LANG_FRIEND_IGNORE_UNKNOWN);
FriendsResult ignoreResult = FRIEND_IGNORE_NOT_FOUND;
uint64 IgnoreGuid = 0;
recv_data >> IgnoreName;
@@ -755,40 +752,40 @@ void WorldSession::HandleAddIgnoreOpcode( WorldPacket & recv_data )
sLog.outDebug( "WORLD: %s asked to Ignore: '%s'",
GetPlayer()->GetName(), IgnoreName.c_str() );
IgnoreGuid = objmgr.GetPlayerGUIDByName(IgnoreName);
CharacterDatabase.AsyncPQuery(&WorldSession::HandleAddIgnoreOpcodeCallBack, GetAccountId(), "SELECT guid FROM characters WHERE name = '%s'", IgnoreName.c_str());
}
void WorldSession::HandleAddIgnoreOpcodeCallBack(QueryResult *result, uint32 accountId)
{
if(!result)
return;
uint64 IgnoreGuid = MAKE_NEW_GUID((*result)[0].GetUInt32(), 0, HIGHGUID_PLAYER);
delete result;
WorldSession * session = sWorld.FindSession(accountId);
if(!session)
return;
FriendsResult ignoreResult = FRIEND_IGNORE_NOT_FOUND;
if(IgnoreGuid)
{
if(IgnoreGuid==GetPlayer()->GetGUID())
if(IgnoreGuid==session->GetPlayer()->GetGUID()) //not add yourself
ignoreResult = FRIEND_IGNORE_SELF;
else if( session->GetPlayer()->GetSocial()->HasIgnore(GUID_LOPART(IgnoreGuid)) )
ignoreResult = FRIEND_IGNORE_ALREADY;
else
{
if( GetPlayer()->GetSocial()->HasIgnore(GUID_LOPART(IgnoreGuid)) )
ignoreResult = FRIEND_IGNORE_ALREADY;
ignoreResult = FRIEND_IGNORE_ADDED;
// ignore list full
if(!session->GetPlayer()->GetSocial()->AddToSocialList(GUID_LOPART(IgnoreGuid), true))
ignoreResult = FRIEND_IGNORE_FULL;
}
}
if (IgnoreGuid && ignoreResult == FRIEND_IGNORE_NOT_FOUND)
{
ignoreResult = FRIEND_IGNORE_ADDED;
if(!_player->GetSocial()->AddToSocialList(GUID_LOPART(IgnoreGuid), true))
ignoreResult = FRIEND_IGNORE_FULL;
}
else if(ignoreResult==FRIEND_IGNORE_ALREADY)
{
sLog.outDebug( "WORLD: %s Guid Already Ignored.", IgnoreName.c_str() );
}
else if(ignoreResult==FRIEND_IGNORE_SELF)
{
sLog.outDebug( "WORLD: %s Guid can't add himself.", IgnoreName.c_str() );
}
else
{
sLog.outDebug( "WORLD: %s Guid not found.", IgnoreName.c_str() );
}
sSocialMgr.SendFriendStatus(GetPlayer(), ignoreResult, GUID_LOPART(IgnoreGuid), "", false);
sSocialMgr.SendFriendStatus(session->GetPlayer(), ignoreResult, GUID_LOPART(IgnoreGuid), false);
sLog.outDebug( "WORLD: Sent (SMSG_FRIEND_STATUS)" );
}
@@ -805,7 +802,7 @@ void WorldSession::HandleDelIgnoreOpcode( WorldPacket & recv_data )
_player->GetSocial()->RemoveFromSocialList(GUID_LOPART(IgnoreGUID), true);
sSocialMgr.SendFriendStatus(GetPlayer(), FRIEND_IGNORE_REMOVED, GUID_LOPART(IgnoreGUID), "", false);
sSocialMgr.SendFriendStatus(GetPlayer(), FRIEND_IGNORE_REMOVED, GUID_LOPART(IgnoreGUID), false);
sLog.outDebug( "WORLD: Sent motd (SMSG_FRIEND_STATUS)" );
}