Changeset 173 for trunk/src/game/MiscHandler.cpp
- Timestamp:
- 11/19/08 13:43:02 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/game/MiscHandler.cpp
r139 r173 22 22 #include "Language.h" 23 23 #include "Database/DatabaseEnv.h" 24 #include "Database/DatabaseImpl.h" 24 25 #include "WorldPacket.h" 25 26 #include "Opcodes.h" … … 650 651 sLog.outDebug( "WORLD: Received CMSG_ADD_FRIEND" ); 651 652 652 std::string friendName 653 std::string friendName = GetTrinityString(LANG_FRIEND_IGNORE_UNKNOWN); 653 654 std::string friendNote; 654 FriendsResult friendResult = FRIEND_NOT_FOUND; 655 Player *pFriend = NULL; 656 uint64 friendGuid = 0; 657 655 658 656 recv_data >> friendName; 659 657 … … 671 669 GetPlayer()->GetName(), friendName.c_str() ); 672 670 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 674 void 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; 675 689 if(friendGuid) 676 690 { 677 pFriend = ObjectAccessor::FindPlayer(friendGuid); 678 if(pFriend==GetPlayer()) 691 if(friendGuid==session->GetPlayer()->GetGUID()) 679 692 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) 681 694 friendResult = FRIEND_ENEMY; 682 else if( GetPlayer()->GetSocial()->HasFriend(GUID_LOPART(friendGuid)))695 else if(session->GetPlayer()->GetSocial()->HasFriend(GUID_LOPART(friendGuid))) 683 696 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;690 697 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)) 694 706 { 695 707 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); 717 716 718 717 sLog.outDebug( "WORLD: Sent (SMSG_FRIEND_STATUS)" ); … … 731 730 _player->GetSocial()->RemoveFromSocialList(GUID_LOPART(FriendGUID), false); 732 731 733 sSocialMgr.SendFriendStatus(GetPlayer(), FRIEND_REMOVED, GUID_LOPART(FriendGUID), "",false);732 sSocialMgr.SendFriendStatus(GetPlayer(), FRIEND_REMOVED, GUID_LOPART(FriendGUID), false); 734 733 735 734 sLog.outDebug( "WORLD: Sent motd (SMSG_FRIEND_STATUS)" ); … … 743 742 744 743 std::string IgnoreName = GetTrinityString(LANG_FRIEND_IGNORE_UNKNOWN); 745 FriendsResult ignoreResult = FRIEND_IGNORE_NOT_FOUND;746 uint64 IgnoreGuid = 0;747 744 748 745 recv_data >> IgnoreName; … … 756 753 GetPlayer()->GetName(), IgnoreName.c_str() ); 757 754 758 IgnoreGuid = objmgr.GetPlayerGUIDByName(IgnoreName); 759 755 CharacterDatabase.AsyncPQuery(&WorldSession::HandleAddIgnoreOpcodeCallBack, GetAccountId(), "SELECT guid FROM characters WHERE name = '%s'", IgnoreName.c_str()); 756 } 757 758 void 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; 760 772 if(IgnoreGuid) 761 773 { 762 if(IgnoreGuid== GetPlayer()->GetGUID())774 if(IgnoreGuid==session->GetPlayer()->GetGUID()) //not add yourself 763 775 ignoreResult = FRIEND_IGNORE_SELF; 776 else if( session->GetPlayer()->GetSocial()->HasIgnore(GUID_LOPART(IgnoreGuid)) ) 777 ignoreResult = FRIEND_IGNORE_ALREADY; 764 778 else 765 779 { 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)) 776 784 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); 792 789 793 790 sLog.outDebug( "WORLD: Sent (SMSG_FRIEND_STATUS)" ); … … 806 803 _player->GetSocial()->RemoveFromSocialList(GUID_LOPART(IgnoreGUID), true); 807 804 808 sSocialMgr.SendFriendStatus(GetPlayer(), FRIEND_IGNORE_REMOVED, GUID_LOPART(IgnoreGUID), "",false);805 sSocialMgr.SendFriendStatus(GetPlayer(), FRIEND_IGNORE_REMOVED, GUID_LOPART(IgnoreGUID), false); 809 806 810 807 sLog.outDebug( "WORLD: Sent motd (SMSG_FRIEND_STATUS)" );