Core/Misc: Kill another synchronous db query in packet handlers
Port From (https://github.com/TrinityCore/TrinityCore/commit/7e76e91152ed83cc5f81563db584f1f757dba063)
This commit is contained in:
@@ -299,88 +299,91 @@ namespace Game
|
|||||||
{
|
{
|
||||||
ObjectGuid playerGuid = GetPlayer().GetGUID();
|
ObjectGuid playerGuid = GetPlayer().GetGUID();
|
||||||
|
|
||||||
ObjectGuid inviteeGuid = ObjectGuid.Empty;
|
ulong? eventId = null;
|
||||||
Team inviteeTeam = 0;
|
if (!calendarInvite.Creating)
|
||||||
ulong inviteeGuildId = 0;
|
eventId = calendarInvite.EventID;
|
||||||
|
|
||||||
|
bool isSignUp = calendarInvite.IsSignUp;
|
||||||
|
|
||||||
|
string inviteeName = calendarInvite.Name;
|
||||||
|
|
||||||
if (!ObjectManager.NormalizePlayerName(ref calendarInvite.Name))
|
if (!ObjectManager.NormalizePlayerName(ref calendarInvite.Name))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Player player = Global.ObjAccessor.FindPlayerByName(calendarInvite.Name);
|
var createInvite = (ObjectGuid inviteeGuid, Team inviteeTeam, ulong inviteeGuildId, bool inviteeIsIngoring) =>
|
||||||
if (player != null)
|
|
||||||
{
|
{
|
||||||
// Invitee is online
|
if (_player == null || _player.GetGUID() != playerGuid)
|
||||||
inviteeGuid = player.GetGUID();
|
return;
|
||||||
inviteeTeam = player.GetTeam();
|
|
||||||
inviteeGuildId = player.GetGuildId();
|
if (_player.GetTeam() != inviteeTeam && !WorldConfig.GetBoolValue(WorldCfg.AllowTwoSideInteractionCalendar))
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Invitee offline, get data from database
|
|
||||||
ObjectGuid guid = Global.CharacterCacheStorage.GetCharacterGuidByName(calendarInvite.Name);
|
|
||||||
if (!guid.IsEmpty())
|
|
||||||
{
|
{
|
||||||
CharacterCacheEntry characterInfo = Global.CharacterCacheStorage.GetCharacterCacheByGuid(guid);
|
Global.CalendarMgr.SendCalendarCommandResult(playerGuid, CalendarError.NotAllied);
|
||||||
if (characterInfo != null)
|
|
||||||
{
|
|
||||||
inviteeGuid = guid;
|
|
||||||
inviteeTeam = Player.TeamForRace(characterInfo.RaceId);
|
|
||||||
inviteeGuildId = characterInfo.GuildId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inviteeGuid.IsEmpty())
|
|
||||||
{
|
|
||||||
Global.CalendarMgr.SendCalendarCommandResult(playerGuid, CalendarError.PlayerNotFound);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GetPlayer().GetTeam() != inviteeTeam && !WorldConfig.GetBoolValue(WorldCfg.AllowTwoSideInteractionCalendar))
|
|
||||||
{
|
|
||||||
Global.CalendarMgr.SendCalendarCommandResult(playerGuid, CalendarError.NotAllied);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SQLResult result1 = DB.Characters.Query("SELECT flags FROM character_social WHERE guid = {0} AND friend = {1}", inviteeGuid, playerGuid);
|
|
||||||
if (!result1.IsEmpty())
|
|
||||||
{
|
|
||||||
|
|
||||||
if (Convert.ToBoolean(result1.Read<byte>(0) & (byte)SocialFlag.Ignored))
|
|
||||||
{
|
|
||||||
Global.CalendarMgr.SendCalendarCommandResult(playerGuid, CalendarError.IgnoringYouS, calendarInvite.Name);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!calendarInvite.Creating)
|
if (inviteeIsIngoring)
|
||||||
{
|
|
||||||
CalendarEvent calendarEvent = Global.CalendarMgr.GetEvent(calendarInvite.EventID);
|
|
||||||
if (calendarEvent != null)
|
|
||||||
{
|
{
|
||||||
if (calendarEvent.IsGuildEvent() && calendarEvent.GuildId == inviteeGuildId)
|
Global.CalendarMgr.SendCalendarCommandResult(playerGuid, CalendarError.IgnoringYouS, inviteeName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (eventId.HasValue)
|
||||||
|
{
|
||||||
|
CalendarEvent calendarEvent = Global.CalendarMgr.GetEvent(eventId.Value);
|
||||||
|
if (calendarEvent != null)
|
||||||
|
{
|
||||||
|
if (calendarEvent.IsGuildEvent() && calendarEvent.GuildId == inviteeGuildId)
|
||||||
|
{
|
||||||
|
// we can't invite guild members to guild events
|
||||||
|
Global.CalendarMgr.SendCalendarCommandResult(playerGuid, CalendarError.NoGuildInvites);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CalendarInvite invite = new CalendarInvite(Global.CalendarMgr.GetFreeInviteId(), eventId.Value, inviteeGuid, playerGuid, SharedConst.CalendarDefaultResponseTime, CalendarInviteStatus.Invited, CalendarModerationRank.Player, "");
|
||||||
|
Global.CalendarMgr.AddInvite(calendarEvent, invite);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Global.CalendarMgr.SendCalendarCommandResult(playerGuid, CalendarError.EventInvalid);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (isSignUp && inviteeGuildId == _player.GetGuildId())
|
||||||
{
|
{
|
||||||
// we can't invite guild members to guild events
|
|
||||||
Global.CalendarMgr.SendCalendarCommandResult(playerGuid, CalendarError.NoGuildInvites);
|
Global.CalendarMgr.SendCalendarCommandResult(playerGuid, CalendarError.NoGuildInvites);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CalendarInvite invite = new(Global.CalendarMgr.GetFreeInviteId(), calendarInvite.EventID, inviteeGuid, playerGuid, SharedConst.CalendarDefaultResponseTime, CalendarInviteStatus.Invited, CalendarModerationRank.Player, "");
|
CalendarInvite invite = new(Global.CalendarMgr.GetFreeInviteId(), 0L, inviteeGuid, playerGuid, SharedConst.CalendarDefaultResponseTime, CalendarInviteStatus.Invited, CalendarModerationRank.Player, "");
|
||||||
Global.CalendarMgr.AddInvite(calendarEvent, invite);
|
Global.CalendarMgr.SendCalendarEventInvite(invite);
|
||||||
}
|
}
|
||||||
else
|
};
|
||||||
Global.CalendarMgr.SendCalendarCommandResult(playerGuid, CalendarError.EventInvalid);
|
|
||||||
|
Player player = Global.ObjAccessor.FindConnectedPlayerByName(calendarInvite.Name);
|
||||||
|
if (player != null)
|
||||||
|
{
|
||||||
|
// Invitee is online
|
||||||
|
createInvite(player.GetGUID(), player.GetTeam(), player.GetGuildId(), player.GetSocial().HasIgnore(playerGuid, GetAccountGUID()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (calendarInvite.IsSignUp && inviteeGuildId == GetPlayer().GetGuildId())
|
// Invitee offline, get data from storage
|
||||||
|
CharacterCacheEntry characterInfo = Global.CharacterCacheStorage.GetCharacterCacheByName(inviteeName);
|
||||||
|
if (characterInfo == null)
|
||||||
{
|
{
|
||||||
Global.CalendarMgr.SendCalendarCommandResult(playerGuid, CalendarError.NoGuildInvites);
|
Global.CalendarMgr.SendCalendarCommandResult(playerGuid, CalendarError.PlayerNotFound);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CalendarInvite invite = new(calendarInvite.EventID, 0, inviteeGuid, playerGuid, SharedConst.CalendarDefaultResponseTime, CalendarInviteStatus.Invited, CalendarModerationRank.Player, "");
|
var inviteeGuid = characterInfo.Guid;
|
||||||
Global.CalendarMgr.SendCalendarEventInvite(invite);
|
var inviteeTeam = Player.TeamForRace(characterInfo.RaceId);
|
||||||
|
var inviteeGuildId = characterInfo.GuildId;
|
||||||
|
var continuation = createInvite;
|
||||||
|
GetQueryProcessor().AddCallback(DB.Characters.AsyncQuery(new PreparedStatement($"SELECT 1 FROM character_social cs INNER JOIN characters friend_character ON cs.friend = friend_character.guid WHERE cs.guid = {characterInfo.Guid.GetCounter()} AND friend_character.account = {characterInfo.AccountId} AND (cs.flags & {(uint)SocialFlag.Ignored}) <> 0")))
|
||||||
|
.WithCallback(result =>
|
||||||
|
{
|
||||||
|
bool isIgnoring = result != null;
|
||||||
|
continuation(inviteeGuid, inviteeTeam, inviteeGuildId, isIgnoring);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user