void HandleCalendarStatus(CalendarStatus calendarStatus) { ObjectGuid guid = GetPlayer().GetGUID(); CalendarEvent calendarEvent = Global.CalendarMgr.GetEvent(calendarStatus.EventID); if (calendarEvent != null) { CalendarInvite invite = Global.CalendarMgr.GetInvite(calendarStatus.InviteID); if (invite != null) { invite.Status = (CalendarInviteStatus)calendarStatus.Status; Global.CalendarMgr.UpdateInvite(invite); Global.CalendarMgr.SendCalendarEventStatus(calendarEvent, invite); Global.CalendarMgr.SendCalendarClearPendingAction(calendarStatus.Guid); } else { Global.CalendarMgr.SendCalendarCommandResult(guid, CalendarError.NoInvite); // correct? } } else { Global.CalendarMgr.SendCalendarCommandResult(guid, CalendarError.EventInvalid); } }
void HandleCalendarRsvp(HandleCalendarRsvp calendarRSVP) { ObjectGuid guid = GetPlayer().GetGUID(); CalendarEvent calendarEvent = Global.CalendarMgr.GetEvent(calendarRSVP.EventID); if (calendarEvent != null) { // i think we still should be able to remove self from locked events if (calendarRSVP.Status != CalendarInviteStatus.Removed && calendarEvent.IsLocked()) { Global.CalendarMgr.SendCalendarCommandResult(guid, CalendarError.EventLocked); return; } CalendarInvite invite = Global.CalendarMgr.GetInvite(calendarRSVP.InviteID); if (invite != null) { invite.Status = calendarRSVP.Status; invite.ResponseTime = GameTime.GetGameTime(); Global.CalendarMgr.UpdateInvite(invite); Global.CalendarMgr.SendCalendarEventStatus(calendarEvent, invite); Global.CalendarMgr.SendCalendarClearPendingAction(guid); } else { Global.CalendarMgr.SendCalendarCommandResult(guid, CalendarError.NoInvite); // correct? } } else { Global.CalendarMgr.SendCalendarCommandResult(guid, CalendarError.EventInvalid); } }
void HandleCalendarModeratorStatus(CalendarModeratorStatusQuery calendarModeratorStatus) { ObjectGuid guid = GetPlayer().GetGUID(); CalendarEvent calendarEvent = Global.CalendarMgr.GetEvent(calendarModeratorStatus.EventID); if (calendarEvent != null) { CalendarInvite invite = Global.CalendarMgr.GetInvite(calendarModeratorStatus.InviteID); if (invite != null) { invite.Rank = (CalendarModerationRank)calendarModeratorStatus.Status; Global.CalendarMgr.UpdateInvite(invite); Global.CalendarMgr.SendCalendarEventModeratorStatusAlert(calendarEvent, invite); } else { Global.CalendarMgr.SendCalendarCommandResult(guid, CalendarError.NoInvite); // correct? } } else { Global.CalendarMgr.SendCalendarCommandResult(guid, CalendarError.EventInvalid); } }
public CalendarInvite(CalendarInvite calendarInvite, ulong inviteId, ulong eventId) { InviteId = inviteId; EventId = eventId; InviteeGuid = calendarInvite.InviteeGuid; SenderGuid = calendarInvite.SenderGuid; ResponseTime = calendarInvite.ResponseTime; Status = calendarInvite.Status; Rank = calendarInvite.Rank; Note = calendarInvite.Note; }
void SendCalendarEventInviteRemove(CalendarEvent calendarEvent, CalendarInvite invite, uint flags) { CalendarEventInviteRemoved packet = new CalendarEventInviteRemoved(); packet.ClearPending = true; // FIXME packet.EventID = calendarEvent.EventId; packet.Flags = flags; packet.InviteGuid = invite.InviteeGuid; SendPacketToAllEventRelatives(packet, calendarEvent); }
void HandleCalendarAddEvent(CalendarAddEvent calendarAddEvent) { ObjectGuid guid = GetPlayer().GetGUID(); // prevent events in the past // To Do: properly handle timezones and remove the "- time_t(86400L)" hack if (calendarAddEvent.EventInfo.Time < (Time.UnixTime - 86400L)) { return; } CalendarEvent calendarEvent = new CalendarEvent(Global.CalendarMgr.GetFreeEventId(), guid, 0, (CalendarEventType)calendarAddEvent.EventInfo.EventType, calendarAddEvent.EventInfo.TextureID, calendarAddEvent.EventInfo.Time, (CalendarFlags)calendarAddEvent.EventInfo.Flags, calendarAddEvent.EventInfo.Title, calendarAddEvent.EventInfo.Description, 0); if (calendarEvent.IsGuildEvent() || calendarEvent.IsGuildAnnouncement()) { Player creator = Global.ObjAccessor.FindPlayer(guid); if (creator) { calendarEvent.GuildId = creator.GetGuildId(); } } if (calendarEvent.IsGuildAnnouncement()) { CalendarInvite invite = new CalendarInvite(0, calendarEvent.EventId, ObjectGuid.Empty, guid, SharedConst.CalendarDefaultResponseTime, CalendarInviteStatus.NotSignedUp, CalendarModerationRank.Player, ""); // WARNING: By passing pointer to a local variable, the underlying method(s) must NOT perform any kind // of storage of the pointer as it will lead to memory corruption Global.CalendarMgr.AddInvite(calendarEvent, invite); } else { SQLTransaction trans = null; if (calendarAddEvent.EventInfo.Invites.Length > 1) { trans = new SQLTransaction(); } for (int i = 0; i < calendarAddEvent.EventInfo.Invites.Length; ++i) { CalendarInvite invite = new CalendarInvite(Global.CalendarMgr.GetFreeInviteId(), calendarEvent.EventId, calendarAddEvent.EventInfo.Invites[i].Guid, guid, SharedConst.CalendarDefaultResponseTime, (CalendarInviteStatus)calendarAddEvent.EventInfo.Invites[i].Status, (CalendarModerationRank)calendarAddEvent.EventInfo.Invites[i].Moderator, ""); Global.CalendarMgr.AddInvite(calendarEvent, invite, trans); } if (calendarAddEvent.EventInfo.Invites.Length > 1) { DB.Characters.CommitTransaction(trans); } } Global.CalendarMgr.AddEvent(calendarEvent, CalendarSendEventType.Add); }
public void SendCalendarEventStatus(CalendarEvent calendarEvent, CalendarInvite invite) { CalendarEventInviteStatus packet = new CalendarEventInviteStatus(); packet.ClearPending = true; // FIXME packet.Date = calendarEvent.Date; packet.EventID = calendarEvent.EventId; packet.Flags = calendarEvent.Flags; packet.InviteGuid = invite.InviteeGuid; packet.ResponseTime = invite.ResponseTime; packet.Status = invite.Status; SendPacketToAllEventRelatives(packet, calendarEvent); }
public void UpdateInvite(CalendarInvite invite, SQLTransaction trans = null) { PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.REP_CALENDAR_INVITE); stmt.AddValue(0, invite.InviteId); stmt.AddValue(1, invite.EventId); stmt.AddValue(2, invite.InviteeGuid.GetCounter()); stmt.AddValue(3, invite.SenderGuid.GetCounter()); stmt.AddValue(4, invite.Status); stmt.AddValue(5, invite.ResponseTime); stmt.AddValue(6, invite.Rank); stmt.AddValue(7, invite.Note); DB.Characters.ExecuteOrAppend(trans, stmt); }
public void RemoveInvite(ulong inviteId, ulong eventId, ObjectGuid remover) { CalendarEvent calendarEvent = GetEvent(eventId); if (calendarEvent == null) { return; } CalendarInvite calendarInvite = null; foreach (var invite in _invites[eventId]) { if (invite.InviteId == inviteId) { calendarInvite = invite; break; } } if (calendarInvite == null) { return; } SQLTransaction trans = new SQLTransaction(); PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_CALENDAR_INVITE); stmt.AddValue(0, calendarInvite.InviteId); trans.Append(stmt); DB.Characters.CommitTransaction(trans); if (!calendarEvent.IsGuildEvent()) { SendCalendarEventInviteRemoveAlert(calendarInvite.InviteeGuid, calendarEvent, CalendarInviteStatus.Removed); } SendCalendarEventInviteRemove(calendarEvent, calendarInvite, (uint)calendarEvent.Flags); // we need to find out how to use CALENDAR_INVITE_REMOVED_MAIL_SUBJECT to force client to display different mail //if (itr._invitee != remover) // MailDraft(calendarEvent.BuildCalendarMailSubject(remover), calendarEvent.BuildCalendarMailBody()) // .SendMailTo(trans, MailReceiver(itr.GetInvitee()), calendarEvent, MAIL_CHECK_MASK_COPIED); _invites.Remove(eventId, calendarInvite); }
public void AddInvite(CalendarEvent calendarEvent, CalendarInvite invite, SQLTransaction trans = null) { if (!calendarEvent.IsGuildAnnouncement() && calendarEvent.OwnerGuid != invite.InviteeGuid) { SendCalendarEventInvite(invite); } if (!calendarEvent.IsGuildEvent() || invite.InviteeGuid == calendarEvent.OwnerGuid) { SendCalendarEventInviteAlert(calendarEvent, invite); } if (!calendarEvent.IsGuildAnnouncement()) { _invites.Add(invite.EventId, invite); UpdateInvite(invite, trans); } }
public void RemoveEvent(ulong eventId, ObjectGuid remover) { CalendarEvent calendarEvent = GetEvent(eventId); if (calendarEvent == null) { SendCalendarCommandResult(remover, CalendarError.EventInvalid); return; } SendCalendarEventRemovedAlert(calendarEvent); SQLTransaction trans = new SQLTransaction(); PreparedStatement stmt; MailDraft mail = new MailDraft(calendarEvent.BuildCalendarMailSubject(remover), calendarEvent.BuildCalendarMailBody()); var eventInvites = _invites[eventId]; for (int i = 0; i < eventInvites.Count; ++i) { CalendarInvite invite = eventInvites[i]; stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_CALENDAR_INVITE); stmt.AddValue(0, invite.InviteId); trans.Append(stmt); // guild events only? check invite status here? // When an event is deleted, all invited (accepted/declined? - verify) guildies are notified via in-game mail. (wowwiki) if (!remover.IsEmpty() && invite.InviteeGuid != remover) { mail.SendMailTo(trans, new MailReceiver(invite.InviteeGuid.GetCounter()), new MailSender(calendarEvent), MailCheckMask.Copied); } } _invites.Remove(eventId); stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_CALENDAR_EVENT); stmt.AddValue(0, eventId); trans.Append(stmt); DB.Characters.CommitTransaction(trans); _events.Remove(calendarEvent); }
void SendCalendarEventInviteAlert(CalendarEvent calendarEvent, CalendarInvite invite) { CalendarEventInviteAlert packet = new CalendarEventInviteAlert(); packet.Date = calendarEvent.Date; packet.EventID = calendarEvent.EventId; packet.EventName = calendarEvent.Title; packet.EventType = calendarEvent.EventType; packet.Flags = calendarEvent.Flags; packet.InviteID = invite.InviteId; packet.InvitedByGuid = invite.SenderGuid; packet.ModeratorStatus = invite.Rank; packet.OwnerGuid = calendarEvent.OwnerGuid; packet.Status = invite.Status; packet.TextureID = calendarEvent.TextureId; Guild guild = Global.GuildMgr.GetGuildById(calendarEvent.GuildId); packet.EventGuildID = guild ? guild.GetGUID() : ObjectGuid.Empty; if (calendarEvent.IsGuildEvent() || calendarEvent.IsGuildAnnouncement()) { guild = Global.GuildMgr.GetGuildById(calendarEvent.GuildId); if (guild) { guild.BroadcastPacket(packet); } } else { Player player = Global.ObjAccessor.FindPlayer(invite.InviteeGuid); if (player) { player.SendPacket(packet); } } }
void HandleCalendarEventSignup(CalendarEventSignUp calendarEventSignUp) { ObjectGuid guid = GetPlayer().GetGUID(); CalendarEvent calendarEvent = Global.CalendarMgr.GetEvent(calendarEventSignUp.EventID); if (calendarEvent != null) { if (calendarEvent.IsGuildEvent() && calendarEvent.GuildId != GetPlayer().GetGuildId()) { Global.CalendarMgr.SendCalendarCommandResult(guid, CalendarError.GuildPlayerNotInGuild); return; } CalendarInviteStatus status = calendarEventSignUp.Tentative ? CalendarInviteStatus.Tentative : CalendarInviteStatus.SignedUp; CalendarInvite invite = new CalendarInvite(Global.CalendarMgr.GetFreeInviteId(), calendarEventSignUp.EventID, guid, guid, Time.UnixTime, status, CalendarModerationRank.Player, ""); Global.CalendarMgr.AddInvite(calendarEvent, invite); Global.CalendarMgr.SendCalendarClearPendingAction(guid); } else { Global.CalendarMgr.SendCalendarCommandResult(guid, CalendarError.EventInvalid); } }
public void SendCalendarEventInvite(CalendarInvite invite) { CalendarEvent calendarEvent = GetEvent(invite.EventId); ObjectGuid invitee = invite.InviteeGuid; Player player = Global.ObjAccessor.FindPlayer(invitee); uint level = player ? player.GetLevel() : Global.CharacterCacheStorage.GetCharacterLevelByGuid(invitee); SCalendarEventInvite packet = new SCalendarEventInvite(); packet.EventID = calendarEvent != null ? calendarEvent.EventId : 0; packet.InviteGuid = invitee; packet.InviteID = calendarEvent != null ? invite.InviteId : 0; packet.Level = (byte)level; packet.ResponseTime = invite.ResponseTime; packet.Status = invite.Status; packet.Type = (byte)(calendarEvent != null ? calendarEvent.IsGuildEvent() ? 1 : 0 : 0); // Correct ? packet.ClearPending = calendarEvent != null ? !calendarEvent.IsGuildEvent() : true; // Correct ? if (calendarEvent == null) // Pre-invite { player = Global.ObjAccessor.FindPlayer(invite.SenderGuid); if (player) { player.SendPacket(packet); } } else { if (calendarEvent.OwnerGuid != invite.InviteeGuid) // correct? { SendPacketToAllEventRelatives(packet, calendarEvent); } } }
void HandleCalendarEventInvite(CalendarEventInvite calendarEventInvite) { ObjectGuid playerGuid = GetPlayer().GetGUID(); ObjectGuid inviteeGuid = ObjectGuid.Empty; Team inviteeTeam = 0; ulong inviteeGuildId = 0; Player player = Global.ObjAccessor.FindPlayerByName(calendarEventInvite.Name); if (player) { // Invitee is online inviteeGuid = player.GetGUID(); inviteeTeam = player.GetTeam(); inviteeGuildId = player.GetGuildId(); } else { // Invitee offline, get data from database PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_GUID_RACE_ACC_BY_NAME); stmt.AddValue(0, calendarEventInvite.Name); SQLResult result = DB.Characters.Query(stmt); if (!result.IsEmpty()) { inviteeGuid = ObjectGuid.Create(HighGuid.Player, result.Read <ulong>(0)); inviteeTeam = Player.TeamForRace((Race)result.Read <byte>(1)); inviteeGuildId = Player.GetGuildIdFromDB(inviteeGuid); } } 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, calendarEventInvite.Name); return; } } if (!calendarEventInvite.Creating) { CalendarEvent calendarEvent = Global.CalendarMgr.GetEvent(calendarEventInvite.EventID); 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(), calendarEventInvite.EventID, inviteeGuid, playerGuid, SharedConst.CalendarDefaultResponseTime, CalendarInviteStatus.Invited, CalendarModerationRank.Player, ""); Global.CalendarMgr.AddInvite(calendarEvent, invite); } else { Global.CalendarMgr.SendCalendarCommandResult(playerGuid, CalendarError.EventInvalid); } } else { if (calendarEventInvite.IsSignUp && inviteeGuildId == GetPlayer().GetGuildId()) { Global.CalendarMgr.SendCalendarCommandResult(playerGuid, CalendarError.NoGuildInvites); return; } CalendarInvite invite = new CalendarInvite(calendarEventInvite.EventID, 0, inviteeGuid, playerGuid, SharedConst.CalendarDefaultResponseTime, CalendarInviteStatus.Invited, CalendarModerationRank.Player, ""); Global.CalendarMgr.SendCalendarEventInvite(invite); } }
public void LoadFromDB() { uint count = 0; _maxEventId = 0; _maxInviteId = 0; // 0 1 2 3 4 5 6 7 8 SQLResult result = DB.Characters.Query("SELECT EventID, Owner, Title, Description, EventType, TextureID, Date, Flags, LockDate FROM calendar_events"); if (!result.IsEmpty()) { do { ulong eventID = result.Read <ulong>(0); ObjectGuid ownerGUID = ObjectGuid.Create(HighGuid.Player, result.Read <ulong>(1)); string title = result.Read <string>(2); string description = result.Read <string>(3); CalendarEventType type = (CalendarEventType)result.Read <byte>(4); int textureID = result.Read <int>(5); uint date = result.Read <uint>(6); CalendarFlags flags = (CalendarFlags)result.Read <uint>(7); uint lockDate = result.Read <uint>(8); ulong guildID = 0; if (flags.HasAnyFlag(CalendarFlags.GuildEvent) || flags.HasAnyFlag(CalendarFlags.WithoutInvites)) { guildID = Global.CharacterCacheStorage.GetCharacterGuildIdByGuid(ownerGUID); } CalendarEvent calendarEvent = new CalendarEvent(eventID, ownerGUID, guildID, type, textureID, date, flags, title, description, lockDate); _events.Add(calendarEvent); _maxEventId = Math.Max(_maxEventId, eventID); ++count; }while (result.NextRow()); } Log.outInfo(LogFilter.ServerLoading, "Loaded {0} calendar events", count); count = 0; // 0 1 2 3 4 5 6 7 result = DB.Characters.Query("SELECT InviteID, EventID, Invitee, Sender, Status, ResponseTime, ModerationRank, Note FROM calendar_invites"); if (!result.IsEmpty()) { do { ulong inviteId = result.Read <ulong>(0); ulong eventId = result.Read <ulong>(1); ObjectGuid invitee = ObjectGuid.Create(HighGuid.Player, result.Read <ulong>(2)); ObjectGuid senderGUID = ObjectGuid.Create(HighGuid.Player, result.Read <ulong>(3)); CalendarInviteStatus status = (CalendarInviteStatus)result.Read <byte>(4); uint responseTime = result.Read <uint>(5); CalendarModerationRank rank = (CalendarModerationRank)result.Read <byte>(6); string note = result.Read <string>(7); CalendarInvite invite = new CalendarInvite(inviteId, eventId, invitee, senderGUID, responseTime, status, rank, note); _invites.Add(eventId, invite); _maxInviteId = Math.Max(_maxInviteId, inviteId); ++count; }while (result.NextRow()); } Log.outInfo(LogFilter.ServerLoading, "Loaded {0} calendar invites", count); for (ulong i = 1; i < _maxEventId; ++i) { if (GetEvent(i) == null) { _freeEventIds.Add(i); } } for (ulong i = 1; i < _maxInviteId; ++i) { if (GetInvite(i) == null) { _freeInviteIds.Add(i); } } }
void HandleCalendarEventInvite(CalendarEventInvite calendarEventInvite) { ObjectGuid playerGuid = GetPlayer().GetGUID(); ObjectGuid inviteeGuid = ObjectGuid.Empty; Team inviteeTeam = 0; ulong inviteeGuildId = 0; if (!ObjectManager.NormalizePlayerName(ref calendarEventInvite.Name)) { return; } Player player = Global.ObjAccessor.FindPlayerByName(calendarEventInvite.Name); if (player) { // Invitee is online inviteeGuid = player.GetGUID(); inviteeTeam = player.GetTeam(); inviteeGuildId = player.GetGuildId(); } else { // Invitee offline, get data from database ObjectGuid guid = Global.CharacterCacheStorage.GetCharacterGuidByName(calendarEventInvite.Name); if (!guid.IsEmpty()) { CharacterCacheEntry characterInfo = Global.CharacterCacheStorage.GetCharacterCacheByGuid(guid); 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, calendarEventInvite.Name); return; } } if (!calendarEventInvite.Creating) { CalendarEvent calendarEvent = Global.CalendarMgr.GetEvent(calendarEventInvite.EventID); 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(), calendarEventInvite.EventID, inviteeGuid, playerGuid, SharedConst.CalendarDefaultResponseTime, CalendarInviteStatus.Invited, CalendarModerationRank.Player, ""); Global.CalendarMgr.AddInvite(calendarEvent, invite); } else { Global.CalendarMgr.SendCalendarCommandResult(playerGuid, CalendarError.EventInvalid); } } else { if (calendarEventInvite.IsSignUp && inviteeGuildId == GetPlayer().GetGuildId()) { Global.CalendarMgr.SendCalendarCommandResult(playerGuid, CalendarError.NoGuildInvites); return; } CalendarInvite invite = new CalendarInvite(calendarEventInvite.EventID, 0, inviteeGuid, playerGuid, SharedConst.CalendarDefaultResponseTime, CalendarInviteStatus.Invited, CalendarModerationRank.Player, ""); Global.CalendarMgr.SendCalendarEventInvite(invite); } }
public void SendCalendarEventModeratorStatusAlert(CalendarEvent calendarEvent, CalendarInvite invite) { CalendarEventInviteModeratorStatus packet = new CalendarEventInviteModeratorStatus(); packet.ClearPending = true; // FIXME packet.EventID = calendarEvent.EventId; packet.InviteGuid = invite.InviteeGuid; packet.Status = invite.Status; SendPacketToAllEventRelatives(packet, calendarEvent); }