Core/Misc: Replace database query in WorldSession::HandleAddFriendOpcode with async version
Port From (https://github.com/TrinityCore/TrinityCore/commit/54a6e603ffc8b4913669cf0f189a966d25b620d8)
This commit is contained in:
@@ -79,8 +79,7 @@ namespace Framework.Database
|
|||||||
PrepareStatement(LoginStatements.DEL_ACCOUNT_ACCESS_BY_REALM, "DELETE FROM account_access WHERE AccountID = ? AND (RealmID = ? OR RealmID = -1)");
|
PrepareStatement(LoginStatements.DEL_ACCOUNT_ACCESS_BY_REALM, "DELETE FROM account_access WHERE AccountID = ? AND (RealmID = ? OR RealmID = -1)");
|
||||||
PrepareStatement(LoginStatements.INS_ACCOUNT_ACCESS, "INSERT INTO account_access (AccountID, SecurityLevel, RealmID) VALUES (?, ?, ?)");
|
PrepareStatement(LoginStatements.INS_ACCOUNT_ACCESS, "INSERT INTO account_access (AccountID, SecurityLevel, RealmID) VALUES (?, ?, ?)");
|
||||||
PrepareStatement(LoginStatements.GET_ACCOUNT_ID_BY_USERNAME, "SELECT id FROM account WHERE username = ?");
|
PrepareStatement(LoginStatements.GET_ACCOUNT_ID_BY_USERNAME, "SELECT id FROM account WHERE username = ?");
|
||||||
PrepareStatement(LoginStatements.GET_ACCOUNT_ACCESS_GMLEVEL, "SELECT SecurityLevel FROM account_access WHERE AccountID = ?");
|
PrepareStatement(LoginStatements.GET_GMLEVEL_BY_REALMID, "SELECT SecurityLevel FROM account_access WHERE AccountID = ? AND (RealmID = ? OR RealmID = -1) ORDER BY RealmID DESC");
|
||||||
PrepareStatement(LoginStatements.GET_GMLEVEL_BY_REALMID, "SELECT SecurityLevel FROM account_access WHERE AccountID = ? AND (RealmID = ? OR RealmID = -1)");
|
|
||||||
PrepareStatement(LoginStatements.GET_USERNAME_BY_ID, "SELECT username FROM account WHERE id = ?");
|
PrepareStatement(LoginStatements.GET_USERNAME_BY_ID, "SELECT username FROM account WHERE id = ?");
|
||||||
PrepareStatement(LoginStatements.SEL_CHECK_PASSWORD, "SELECT salt, verifier FROM account WHERE id = ? AND salt IS NOT NULL AND verifier IS NOT NULL");
|
PrepareStatement(LoginStatements.SEL_CHECK_PASSWORD, "SELECT salt, verifier FROM account WHERE id = ? AND salt IS NOT NULL AND verifier IS NOT NULL");
|
||||||
PrepareStatement(LoginStatements.SEL_CHECK_PASSWORD_BY_NAME, "SELECT salt, verifier FROM account WHERE username = ? AND salt IS NOT NULL AND verifier IS NOT NULL");
|
PrepareStatement(LoginStatements.SEL_CHECK_PASSWORD_BY_NAME, "SELECT salt, verifier FROM account WHERE username = ? AND salt IS NOT NULL AND verifier IS NOT NULL");
|
||||||
@@ -231,7 +230,6 @@ namespace Framework.Database
|
|||||||
DEL_ACCOUNT_ACCESS_BY_REALM,
|
DEL_ACCOUNT_ACCESS_BY_REALM,
|
||||||
INS_ACCOUNT_ACCESS,
|
INS_ACCOUNT_ACCESS,
|
||||||
GET_ACCOUNT_ID_BY_USERNAME,
|
GET_ACCOUNT_ID_BY_USERNAME,
|
||||||
GET_ACCOUNT_ACCESS_GMLEVEL,
|
|
||||||
GET_GMLEVEL_BY_REALMID,
|
GET_GMLEVEL_BY_REALMID,
|
||||||
GET_USERNAME_BY_ID,
|
GET_USERNAME_BY_ID,
|
||||||
SEL_CHECK_PASSWORD,
|
SEL_CHECK_PASSWORD,
|
||||||
|
|||||||
@@ -247,14 +247,6 @@ namespace Game
|
|||||||
return !result.IsEmpty() ? result.Read<uint>(0) : 0;
|
return !result.IsEmpty() ? result.Read<uint>(0) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AccountTypes GetSecurity(uint accountId)
|
|
||||||
{
|
|
||||||
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.GET_ACCOUNT_ACCESS_GMLEVEL);
|
|
||||||
stmt.AddValue(0, accountId);
|
|
||||||
SQLResult result = DB.Login.Query(stmt);
|
|
||||||
return !result.IsEmpty() ? (AccountTypes)result.Read<byte>(0) : AccountTypes.Player;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AccountTypes GetSecurity(uint accountId, int realmId)
|
public AccountTypes GetSecurity(uint accountId, int realmId)
|
||||||
{
|
{
|
||||||
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.GET_GMLEVEL_BY_REALMID);
|
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.GET_GMLEVEL_BY_REALMID);
|
||||||
@@ -264,6 +256,17 @@ namespace Game
|
|||||||
return !result.IsEmpty() ? (AccountTypes)result.Read<uint>(0) : AccountTypes.Player;
|
return !result.IsEmpty() ? (AccountTypes)result.Read<uint>(0) : AccountTypes.Player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public QueryCallback GetSecurityAsync(uint accountId, int realmId, Action<uint> callback)
|
||||||
|
{
|
||||||
|
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.GET_GMLEVEL_BY_REALMID);
|
||||||
|
stmt.AddValue(0, accountId);
|
||||||
|
stmt.AddValue(1, realmId);
|
||||||
|
return DB.Login.AsyncQuery(stmt).WithCallback(result =>
|
||||||
|
{
|
||||||
|
callback(!result.IsEmpty() ? result.Read<byte>(0) : (uint)AccountTypes.Player);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public bool GetName(uint accountId, out string name)
|
public bool GetName(uint accountId, out string name)
|
||||||
{
|
{
|
||||||
name = "";
|
name = "";
|
||||||
@@ -497,7 +500,7 @@ namespace Game
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
RBACData rbac = new(accountId, "", (int)realmId);
|
RBACData rbac = new(accountId, "", (int)realmId, (byte)GetSecurity(accountId, (int)realmId));
|
||||||
rbac.LoadFromDB();
|
rbac.LoadFromDB();
|
||||||
bool hasPermission = rbac.HasPermission(permissionId);
|
bool hasPermission = rbac.HasPermission(permissionId);
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace Game.Entities
|
|||||||
public const int FriendLimit = 50;
|
public const int FriendLimit = 50;
|
||||||
public const int IgnoreLimit = 50;
|
public const int IgnoreLimit = 50;
|
||||||
|
|
||||||
public void GetFriendInfo(Player player, ObjectGuid friendGUID, FriendInfo friendInfo)
|
public static void GetFriendInfo(Player player, ObjectGuid friendGUID, FriendInfo friendInfo)
|
||||||
{
|
{
|
||||||
if (!player)
|
if (!player)
|
||||||
return;
|
return;
|
||||||
@@ -283,7 +283,7 @@ namespace Game.Entities
|
|||||||
if (++ignoredCount > SocialManager.IgnoreLimit)
|
if (++ignoredCount > SocialManager.IgnoreLimit)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Global.SocialMgr.GetFriendInfo(player, v.Key, v.Value);
|
SocialManager.GetFriendInfo(player, v.Key, v.Value);
|
||||||
|
|
||||||
contactList.Contacts.Add(new ContactInfo(v.Key, v.Value));
|
contactList.Contacts.Add(new ContactInfo(v.Key, v.Value));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -222,19 +222,25 @@ namespace Game
|
|||||||
if (!ObjectManager.NormalizePlayerName(ref packet.Name))
|
if (!ObjectManager.NormalizePlayerName(ref packet.Name))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
CharacterCacheEntry friendCharacterInfo = Global.CharacterCacheStorage.GetCharacterCacheByName(packet.Name);
|
||||||
|
if (friendCharacterInfo == null)
|
||||||
|
{
|
||||||
|
Global.SocialMgr.SendFriendStatus(GetPlayer(), FriendsResult.NotFound, ObjectGuid.Empty);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void processFriendRequest()
|
||||||
|
{
|
||||||
|
var playerGuid = _player.GetGUID();
|
||||||
|
var friendGuid = friendCharacterInfo.Guid;
|
||||||
|
var friendAccountGuid = ObjectGuid.Create(HighGuid.WowAccount, friendCharacterInfo.AccountId);
|
||||||
|
var team = Player.TeamForRace(friendCharacterInfo.RaceId);
|
||||||
|
var friendNote = packet.Notes;
|
||||||
|
|
||||||
|
if (playerGuid.GetCounter() != m_GUIDLow)
|
||||||
|
return; // not the player initiating request, do nothing
|
||||||
|
|
||||||
FriendsResult friendResult = FriendsResult.NotFound;
|
FriendsResult friendResult = FriendsResult.NotFound;
|
||||||
ObjectGuid friendGuid = ObjectGuid.Empty;
|
|
||||||
|
|
||||||
CharacterCacheEntry characterInfo = Global.CharacterCacheStorage.GetCharacterCacheByName(packet.Name);
|
|
||||||
if (characterInfo != null)
|
|
||||||
{
|
|
||||||
friendGuid = characterInfo.Guid;
|
|
||||||
ObjectGuid friendAccountGuid = ObjectGuid.Create(HighGuid.WowAccount, characterInfo.AccountId);
|
|
||||||
Team team = Player.TeamForRace(characterInfo.RaceId);
|
|
||||||
uint friendAccountId = characterInfo.AccountId;
|
|
||||||
|
|
||||||
if (HasPermission(RBACPermissions.AllowGmFriend) || Global.AccountMgr.IsPlayerAccount(Global.AccountMgr.GetSecurity(friendAccountId, (int)Global.WorldMgr.GetRealm().Id.Index)))
|
|
||||||
{
|
|
||||||
if (friendGuid == GetPlayer().GetGUID())
|
if (friendGuid == GetPlayer().GetGUID())
|
||||||
friendResult = FriendsResult.Self;
|
friendResult = FriendsResult.Self;
|
||||||
else if (GetPlayer().GetTeam() != team && !HasPermission(RBACPermissions.TwoSideAddFriend))
|
else if (GetPlayer().GetTeam() != team && !HasPermission(RBACPermissions.TwoSideAddFriend))
|
||||||
@@ -243,21 +249,61 @@ namespace Game
|
|||||||
friendResult = FriendsResult.Already;
|
friendResult = FriendsResult.Already;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Player playerFriend = Global.ObjAccessor.FindPlayer(friendGuid);
|
Player pFriend = Global.ObjAccessor.FindPlayer(friendGuid);
|
||||||
if (playerFriend && playerFriend.IsVisibleGloballyFor(GetPlayer()))
|
if (pFriend != null && pFriend.IsVisibleGloballyFor(GetPlayer()))
|
||||||
friendResult = FriendsResult.AddedOnline;
|
friendResult = FriendsResult.Online;
|
||||||
else
|
else
|
||||||
friendResult = FriendsResult.AddedOffline;
|
friendResult = FriendsResult.AddedOnline;
|
||||||
|
|
||||||
if (GetPlayer().GetSocial().AddToSocialList(friendGuid, friendAccountGuid, SocialFlag.Friend))
|
if (GetPlayer().GetSocial().AddToSocialList(friendGuid, friendAccountGuid, SocialFlag.Friend))
|
||||||
GetPlayer().GetSocial().SetFriendNote(friendGuid, packet.Notes);
|
GetPlayer().GetSocial().SetFriendNote(friendGuid, friendNote);
|
||||||
else
|
else
|
||||||
friendResult = FriendsResult.ListFull;
|
friendResult = FriendsResult.ListFull;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Global.SocialMgr.SendFriendStatus(GetPlayer(), friendResult, friendGuid);
|
Global.SocialMgr.SendFriendStatus(GetPlayer(), friendResult, friendGuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (HasPermission(RBACPermissions.AllowGmFriend))
|
||||||
|
{
|
||||||
|
processFriendRequest();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// First try looking up friend candidate security from online object
|
||||||
|
Player friendPlayer = Global.ObjAccessor.FindPlayer(friendCharacterInfo.Guid);
|
||||||
|
if (friendPlayer != null)
|
||||||
|
{
|
||||||
|
if (!Global.AccountMgr.IsPlayerAccount(friendPlayer.GetSession().GetSecurity()))
|
||||||
|
{
|
||||||
|
Global.SocialMgr.SendFriendStatus(GetPlayer(), FriendsResult.NotFound, ObjectGuid.Empty);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
processFriendRequest();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// When not found, consult database
|
||||||
|
GetQueryProcessor().AddCallback(Global.AccountMgr.GetSecurityAsync(friendCharacterInfo.AccountId, (int)Global.WorldMgr.GetRealmId().Index, friendSecurity =>
|
||||||
|
{
|
||||||
|
if (!Global.AccountMgr.IsPlayerAccount((AccountTypes)friendSecurity))
|
||||||
|
{
|
||||||
|
Global.SocialMgr.SendFriendStatus(GetPlayer(), FriendsResult.NotFound, ObjectGuid.Empty);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
processFriendRequest();
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[WorldPacketHandler(ClientOpcodes.DelFriend)]
|
[WorldPacketHandler(ClientOpcodes.DelFriend)]
|
||||||
|
|||||||
Reference in New Issue
Block a user