Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        void SendPacketToAllEventRelatives(ServerPacket packet, CalendarEvent calendarEvent)
        {
            // Send packet to all guild members
            if (calendarEvent.IsGuildEvent() || calendarEvent.IsGuildAnnouncement())
            {
                Guild guild = Global.GuildMgr.GetGuildById(calendarEvent.GuildId);
                if (guild)
                {
                    guild.BroadcastPacket(packet);
                }
            }

            // Send packet to all invitees if event is non-guild, in other case only to non-guild invitees (packet was broadcasted for them)
            List <CalendarInvite> invites = _invites[calendarEvent.EventId];

            foreach (var playerCalendarEvent in invites)
            {
                Player player = Global.ObjAccessor.FindPlayer(playerCalendarEvent.InviteeGuid);
                if (player)
                {
                    if (!calendarEvent.IsGuildEvent() || (calendarEvent.IsGuildEvent() && player.GetGuildId() != calendarEvent.GuildId))
                    {
                        player.SendPacket(packet);
                    }
                }
            }
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
        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);
                }
            }
        }
Esempio n. 5
0
        void HandleCalendarCopyEvent(CalendarCopyEvent calendarCopyEvent)
        {
            ObjectGuid guid = GetPlayer().GetGUID();

            // prevent events in the past
            // To Do: properly handle timezones and remove the "- time_t(86400L)" hack
            if (calendarCopyEvent.Date < (GameTime.GetGameTime() - 86400L))
            {
                Global.CalendarMgr.SendCalendarCommandResult(guid, CalendarError.EventPassed);
                return;
            }

            CalendarEvent oldEvent = Global.CalendarMgr.GetEvent(calendarCopyEvent.EventID);

            if (oldEvent != null)
            {
                // Ensure that the player has access to the event
                if (oldEvent.IsGuildEvent() || oldEvent.IsGuildAnnouncement())
                {
                    if (oldEvent.GuildId != _player.GetGuildId())
                    {
                        Global.CalendarMgr.SendCalendarCommandResult(guid, CalendarError.EventInvalid);
                        return;
                    }
                }
                else
                {
                    if (oldEvent.OwnerGuid != guid)
                    {
                        Global.CalendarMgr.SendCalendarCommandResult(guid, CalendarError.EventInvalid);
                        return;
                    }
                }

                // Check if the player reached the max number of events allowed to create
                if (oldEvent.IsGuildEvent() || oldEvent.IsGuildAnnouncement())
                {
                    if (Global.CalendarMgr.GetGuildEvents(_player.GetGuildId()).Count >= SharedConst.CalendarMaxGuildEvents)
                    {
                        Global.CalendarMgr.SendCalendarCommandResult(guid, CalendarError.GuildEventsExceeded);
                        return;
                    }
                }
                else
                {
                    if (Global.CalendarMgr.GetEventsCreatedBy(guid).Count >= SharedConst.CalendarMaxEvents)
                    {
                        Global.CalendarMgr.SendCalendarCommandResult(guid, CalendarError.EventsExceeded);
                        return;
                    }
                }

                if (GetCalendarEventCreationCooldown() > GameTime.GetGameTime())
                {
                    Global.CalendarMgr.SendCalendarCommandResult(guid, CalendarError.Internal);
                    return;
                }
                SetCalendarEventCreationCooldown(GameTime.GetGameTime() + SharedConst.CalendarCreateEventCooldown);

                CalendarEvent newEvent = new(oldEvent, Global.CalendarMgr.GetFreeEventId());
                newEvent.Date = calendarCopyEvent.Date;
                Global.CalendarMgr.AddEvent(newEvent, CalendarSendEventType.Copy);

                var            invites = Global.CalendarMgr.GetEventInvites(calendarCopyEvent.EventID);
                SQLTransaction trans   = null;
                if (invites.Count > 1)
                {
                    trans = new SQLTransaction();
                }

                foreach (var invite in invites)
                {
                    Global.CalendarMgr.AddInvite(newEvent, new CalendarInvite(invite, Global.CalendarMgr.GetFreeInviteId(), newEvent.EventId), trans);
                }

                if (invites.Count > 1)
                {
                    DB.Characters.CommitTransaction(trans);
                }
                // should we change owner when somebody makes a copy of event owned by another person?
            }
            else
            {
                Global.CalendarMgr.SendCalendarCommandResult(guid, CalendarError.EventInvalid);
            }
        }
Esempio n. 6
0
        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 < (GameTime.GetGameTime() - 86400L))
            {
                Global.CalendarMgr.SendCalendarCommandResult(guid, CalendarError.EventPassed);
                return;
            }

            // If the event is a guild event, check if the player is in a guild
            if (CalendarEvent.IsGuildEvent(calendarAddEvent.EventInfo.Flags) || CalendarEvent.IsGuildAnnouncement(calendarAddEvent.EventInfo.Flags))
            {
                if (_player.GetGuildId() == 0)
                {
                    Global.CalendarMgr.SendCalendarCommandResult(guid, CalendarError.GuildPlayerNotInGuild);
                    return;
                }
            }

            // Check if the player reached the max number of events allowed to create
            if (CalendarEvent.IsGuildEvent(calendarAddEvent.EventInfo.Flags) || CalendarEvent.IsGuildAnnouncement(calendarAddEvent.EventInfo.Flags))
            {
                if (Global.CalendarMgr.GetGuildEvents(_player.GetGuildId()).Count >= SharedConst.CalendarMaxGuildEvents)
                {
                    Global.CalendarMgr.SendCalendarCommandResult(guid, CalendarError.GuildEventsExceeded);
                    return;
                }
            }
            else
            {
                if (Global.CalendarMgr.GetEventsCreatedBy(guid).Count >= SharedConst.CalendarMaxEvents)
                {
                    Global.CalendarMgr.SendCalendarCommandResult(guid, CalendarError.EventsExceeded);
                    return;
                }
            }

            if (GetCalendarEventCreationCooldown() > GameTime.GetGameTime())
            {
                Global.CalendarMgr.SendCalendarCommandResult(guid, CalendarError.Internal);
                return;
            }
            SetCalendarEventCreationCooldown(GameTime.GetGameTime() + SharedConst.CalendarCreateEventCooldown);

            CalendarEvent calendarEvent = new(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())
            {
                calendarEvent.GuildId = _player.GetGuildId();
            }

            if (calendarEvent.IsGuildAnnouncement())
            {
                CalendarInvite invite = new(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(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);
        }