Beispiel #1
0
        public static MailError SendMail(string recipientName,
                                         string subject,
                                         string body,
                                         MailStationary stationary,
                                         ICollection <ItemRecord> items,
                                         uint money,
                                         uint cod,
                                         IPacketReceiver sender)
        {
            var id = CharacterRecord.GetIdByName(recipientName);

            if (id <= 0)
            {
                return(MailError.RECIPIENT_NOT_FOUND);
            }
            return(SendMail(id, subject, body, stationary, items, money, cod, sender));
        }
Beispiel #2
0
        public static MailError SendMail(uint recipientLowId,
                                         string subject,
                                         string body,
                                         MailStationary stationary,
                                         ICollection <ItemRecord> items,
                                         uint money,
                                         uint cod,
                                         IPacketReceiver sender)
        {
            // All good, send an ok message
            if (sender != null)
            {
                MailHandler.SendResult(sender, 0u, MailResult.MailSent, MailError.OK);
            }

            var deliveryDelay = 0u;

            // Create a new letter object
            var letter = new MailMessage(subject, body)
            {
                LastModifiedOn    = null,
                SenderId          = sender is IEntity ? ((IEntity)sender).EntityId.Low : 0,
                ReceiverId        = recipientLowId,
                MessageStationary = stationary,
                MessageType       = MailType.Normal,
                CashOnDelivery    = cod,
                IncludedMoney     = money,
                SendTime          = DateTime.Now,
                DeliveryTime      = DateTime.Now.AddSeconds(deliveryDelay)
            };

            // Attach items to the new letter
            if (items != null && items.Count > 0)
            {
                // remove the item from the sender's inventory and add them to the list
                letter.SetItems(items);
            }

            SendMail(letter);
            return(MailError.OK);
        }
Beispiel #3
0
		public MailError SendMail(string recipientName,
			string subject,
			string body,
			MailStationary stationary,
			ICollection<Item> items,
			uint money,
			uint cod)
		{
			FactionGroup recipientFaction;
			int recipientMailCount;

			// Find and verify the recipient
			var normalizedName = recipientName;
			var recipient = World.GetCharacter(normalizedName, false);
			CharacterRecord recipientRecord;
			if (recipient != null)
			{
				// receiving character is online, get info from the character object
				recipientFaction = recipient.Faction.Group;
				recipientMailCount = recipient.MailAccount.AllMail.Count;
				recipientRecord = recipient.Record;
			}
			else
			{
				// no character online with that name, get info from the CharacterRecord
				var charRecord = CharacterRecord.GetRecordByName(normalizedName);
				if (charRecord == null)
				{
					MailHandler.SendResult(m_chr.Client, 0, MailResult.MailSent, MailError.RECIPIENT_NOT_FOUND);
					return MailError.RECIPIENT_NOT_FOUND;
				}

				recipientFaction = FactionMgr.GetFactionGroup(charRecord.Race);
				recipientMailCount = charRecord.MailCount;
				recipientRecord = charRecord;
			}

			if (!m_chr.GodMode)
			{
                if (stationary == MailStationary.GM)
                {
                    MailHandler.SendResult(m_chr.Client, 0, MailResult.MailSent, MailError.INTERNAL_ERROR);
                    return MailError.INTERNAL_ERROR;
                }

				// Can't send to people who ignore you
				if (RelationMgr.IsIgnoring(recipientRecord.EntityLowId, m_chr.EntityId.Low))
				{
					MailHandler.SendResult(m_chr.Client, 0, MailResult.MailSent, MailError.RECIPIENT_NOT_FOUND);
					return MailError.RECIPIENT_NOT_FOUND;
				}

				// Can't send mail to people on the other team
				if (!MailMgr.AllowInterFactionMail && !m_chr.GodMode)
				{
					if (recipientFaction != m_chr.Faction.Group)
					{
						MailHandler.SendResult(m_chr, 0u, MailResult.MailSent, MailError.NOT_YOUR_ALLIANCE);
						return MailError.NOT_YOUR_ALLIANCE;
					}
				}

				// Check that the recipient can recieve more mail.
				if (recipientMailCount > MailMgr.MaxMailCount)
				{
					MailHandler.SendResult(m_chr, 0u, MailResult.MailSent, MailError.RECIPIENT_CAP_REACHED);
					return MailError.RECIPIENT_CAP_REACHED;
				}
			}

			return SendMail(recipientRecord, subject, body, stationary, items, money, cod);
		}
Beispiel #4
0
		/// <summary>
		/// Creates and sends a new Mail with the given parameters
		/// </summary>
		public MailError SendMail(CharacterRecord recipient,
			string subject,
			string body,
			MailStationary stationary,
			ICollection<Item> items,
			uint money,
			uint cod)
		{
			if (subject.Length > MailMgr.MaxMailSubjectLength ||
				body.Length > MailMgr.MaxMailBodyLength)
			{
				// Player cannot send mails this long through the mail dialog
				return MailError.INTERNAL_ERROR;
			}

			// Can't send mail to yourself.
			if (recipient.EntityLowId == m_chr.EntityId.Low)
			{
				MailHandler.SendResult(m_chr.Client, 0, MailResult.MailSent, MailError.CANNOT_SEND_TO_SELF);
				return MailError.CANNOT_SEND_TO_SELF;
			}

		    var requiredCash = money;

			// Check that sender is good for the money.
			if (MailMgr.ChargePostage)
			{
                if (!m_chr.GodMode)
                {
                    requiredCash += MailMgr.PostagePrice;

                    var count = (items == null) ? 0u : (uint) items.Count;
                    if (count > 0)
                    {
                        requiredCash += ((count - 1)*MailMgr.PostagePrice);
                    }
                }
			}

            if (requiredCash > m_chr.Money)
            {
                MailHandler.SendResult(m_chr.Client, 0u, MailResult.MailSent, MailError.NOT_ENOUGH_MONEY);
                return MailError.NOT_ENOUGH_MONEY;
            }

            // Charge for the letter (already checked, Character has enough)
            m_chr.Money -= requiredCash;

			// All good, send an ok message
			MailHandler.SendResult(m_chr.Client, 0u, MailResult.MailSent, MailError.OK);
            m_chr.Achievements.CheckPossibleAchievementUpdates(AchievementCriteriaType.GoldSpentForMail, requiredCash);

			var deliveryDelay = 0u;
			if (!m_chr.GodMode)
			{
				if ((money > 0 || (items != null && items.Count > 0)) && (m_chr.Account.AccountId != recipient.AccountId))
				{
					deliveryDelay = MailMgr.MaxPacketDeliveryDelay;
				}
			}

			// Create a new letter object
			var letter = new MailMessage(subject, body)
			{
				LastModifiedOn = null,
				SenderId = m_chr.EntityId.Low,
				ReceiverId = recipient.EntityLowId,
				MessageStationary = stationary,
				MessageType = MailType.Normal,
				CashOnDelivery = cod,
				IncludedMoney = money,
				SendTime = DateTime.Now,
				DeliveryTime = DateTime.Now.AddSeconds(deliveryDelay)
			};

			// Attach items to the new letter
			if (items != null && items.Count > 0)
			{
				// remove the item from the sender's inventory and add them to the list
				letter.SetItems(items);
			}

			MailMgr.SendMail(letter);
			return MailError.OK;
		}
Beispiel #5
0
        public MailError SendMail(string recipientName,
                                  string subject,
                                  string body,
                                  MailStationary stationary,
                                  ICollection <Item> items,
                                  uint money,
                                  uint cod)
        {
            FactionGroup recipientFaction;
            int          recipientMailCount;

            // Find and verify the recipient
            var             normalizedName = recipientName;
            var             recipient      = World.GetCharacter(normalizedName, false);
            CharacterRecord recipientRecord;

            if (recipient != null)
            {
                // receiving character is online, get info from the character object
                recipientFaction   = recipient.Faction.Group;
                recipientMailCount = recipient.MailAccount.AllMail.Count;
                recipientRecord    = recipient.Record;
            }
            else
            {
                // no character online with that name, get info from the CharacterRecord
                var charRecord = CharacterRecord.GetRecordByName(normalizedName);
                if (charRecord == null)
                {
                    MailHandler.SendResult(m_chr.Client, 0, MailResult.MailSent, MailError.RECIPIENT_NOT_FOUND);
                    return(MailError.RECIPIENT_NOT_FOUND);
                }

                recipientFaction   = FactionMgr.GetFactionGroup(charRecord.Race);
                recipientMailCount = charRecord.MailCount;
                recipientRecord    = charRecord;
            }

            if (!m_chr.GodMode)
            {
                if (stationary == MailStationary.GM)
                {
                    MailHandler.SendResult(m_chr.Client, 0, MailResult.MailSent, MailError.INTERNAL_ERROR);
                    return(MailError.INTERNAL_ERROR);
                }

                // Can't send to people who ignore you
                if (RelationMgr.IsIgnoring(recipientRecord.EntityLowId, m_chr.EntityId.Low))
                {
                    MailHandler.SendResult(m_chr.Client, 0, MailResult.MailSent, MailError.RECIPIENT_NOT_FOUND);
                    return(MailError.RECIPIENT_NOT_FOUND);
                }

                // Can't send mail to people on the other team
                if (!MailMgr.AllowInterFactionMail && !m_chr.GodMode)
                {
                    if (recipientFaction != m_chr.Faction.Group)
                    {
                        MailHandler.SendResult(m_chr, 0u, MailResult.MailSent, MailError.NOT_YOUR_ALLIANCE);
                        return(MailError.NOT_YOUR_ALLIANCE);
                    }
                }

                // Check that the recipient can recieve more mail.
                if (recipientMailCount > MailMgr.MaxMailCount)
                {
                    MailHandler.SendResult(m_chr, 0u, MailResult.MailSent, MailError.RECIPIENT_CAP_REACHED);
                    return(MailError.RECIPIENT_CAP_REACHED);
                }
            }

            return(SendMail(recipientRecord, subject, body, stationary, items, money, cod));
        }
Beispiel #6
0
        /// <summary>
        /// Creates and sends a new Mail with the given parameters
        /// </summary>
        public MailError SendMail(CharacterRecord recipient,
                                  string subject,
                                  string body,
                                  MailStationary stationary,
                                  ICollection <Item> items,
                                  uint money,
                                  uint cod)
        {
            if (subject.Length > MailMgr.MaxMailSubjectLength ||
                body.Length > MailMgr.MaxMailBodyLength)
            {
                // Player cannot send mails this long through the mail dialog
                return(MailError.INTERNAL_ERROR);
            }

            // Can't send mail to yourself.
            if (recipient.EntityLowId == m_chr.EntityId.Low)
            {
                MailHandler.SendResult(m_chr.Client, 0, MailResult.MailSent, MailError.CANNOT_SEND_TO_SELF);
                return(MailError.CANNOT_SEND_TO_SELF);
            }

            var requiredCash = money;

            // Check that sender is good for the money.
            if (MailMgr.ChargePostage)
            {
                if (!m_chr.GodMode)
                {
                    requiredCash += MailMgr.PostagePrice;

                    var count = (items == null) ? 0u : (uint)items.Count;
                    if (count > 0)
                    {
                        requiredCash += ((count - 1) * MailMgr.PostagePrice);
                    }
                }
            }

            if (requiredCash > m_chr.Money)
            {
                MailHandler.SendResult(m_chr.Client, 0u, MailResult.MailSent, MailError.NOT_ENOUGH_MONEY);
                return(MailError.NOT_ENOUGH_MONEY);
            }

            // Charge for the letter (already checked, Character has enough)
            m_chr.Money -= requiredCash;

            // All good, send an ok message
            MailHandler.SendResult(m_chr.Client, 0u, MailResult.MailSent, MailError.OK);
            m_chr.Achievements.CheckPossibleAchievementUpdates(AchievementCriteriaType.GoldSpentForMail, requiredCash);

            var deliveryDelay = 0u;

            if (!m_chr.GodMode)
            {
                if ((money > 0 || (items != null && items.Count > 0)) && (m_chr.Account.AccountId != recipient.AccountId))
                {
                    deliveryDelay = MailMgr.MaxPacketDeliveryDelay;
                }
            }

            // Create a new letter object
            var letter = new MailMessage(subject, body)
            {
                LastModifiedOn    = null,
                SenderId          = m_chr.EntityId.Low,
                ReceiverId        = recipient.EntityLowId,
                MessageStationary = stationary,
                MessageType       = MailType.Normal,
                CashOnDelivery    = cod,
                IncludedMoney     = money,
                SendTime          = DateTime.Now,
                DeliveryTime      = DateTime.Now.AddSeconds(deliveryDelay)
            };

            // Attach items to the new letter
            if (items != null && items.Count > 0)
            {
                // remove the item from the sender's inventory and add them to the list
                letter.SetItems(items);
            }

            MailMgr.SendMail(letter);
            return(MailError.OK);
        }
Beispiel #7
0
        public static MailError SendMail(uint recipientLowId, string subject, string body, MailStationary stationary,
                                         ICollection <ItemRecord> items, uint money, uint cod, IPacketReceiver sender)
        {
            if (sender != null)
            {
                MailHandler.SendResult(sender, 0U, MailResult.MailSent, MailError.OK);
            }
            uint        num    = 0;
            MailMessage letter = new MailMessage(subject, body)
            {
                LastModifiedOn    = new DateTime?(),
                SenderId          = sender is IEntity ? ((IEntity)sender).EntityId.Low : 0U,
                ReceiverId        = recipientLowId,
                MessageStationary = stationary,
                MessageType       = MailType.Normal,
                CashOnDelivery    = cod,
                IncludedMoney     = money,
                SendTime          = DateTime.Now,
                DeliveryTime      = DateTime.Now.AddSeconds((double)num)
            };

            if (items != null && items.Count > 0)
            {
                letter.SetItems(items);
            }
            MailMgr.SendMail(letter);
            return(MailError.OK);
        }
Beispiel #8
0
        public MailError SendMail(string recipientName, string subject, string body, MailStationary stationary,
                                  ICollection <Item> items, uint money, uint cod)
        {
            string          name      = recipientName;
            Character       character = World.GetCharacter(name, false);
            FactionGroup    factionGroup;
            int             num;
            CharacterRecord recipient;

            if (character != null)
            {
                factionGroup = character.Faction.Group;
                num          = character.MailAccount.AllMail.Count;
                recipient    = character.Record;
            }
            else
            {
                CharacterRecord recordByName = CharacterRecord.GetRecordByName(name);
                if (recordByName == null)
                {
                    MailHandler.SendResult(m_chr.Client, 0U, MailResult.MailSent,
                                           MailError.RECIPIENT_NOT_FOUND);
                    return(MailError.RECIPIENT_NOT_FOUND);
                }

                factionGroup = FactionMgr.GetFactionGroup(recordByName.Race);
                num          = recordByName.MailCount;
                recipient    = recordByName;
            }

            if (!m_chr.GodMode)
            {
                if (stationary == MailStationary.GM)
                {
                    MailHandler.SendResult(m_chr.Client, 0U, MailResult.MailSent,
                                           MailError.INTERNAL_ERROR);
                    return(MailError.INTERNAL_ERROR);
                }

                if (RelationMgr.IsIgnoring(recipient.EntityLowId, m_chr.EntityId.Low))
                {
                    MailHandler.SendResult(m_chr.Client, 0U, MailResult.MailSent,
                                           MailError.RECIPIENT_NOT_FOUND);
                    return(MailError.RECIPIENT_NOT_FOUND);
                }

                if (!MailMgr.AllowInterFactionMail && !m_chr.GodMode && factionGroup != m_chr.Faction.Group)
                {
                    MailHandler.SendResult(m_chr, 0U, MailResult.MailSent,
                                           MailError.NOT_YOUR_ALLIANCE);
                    return(MailError.NOT_YOUR_ALLIANCE);
                }

                if (num > MailMgr.MaxMailCount)
                {
                    MailHandler.SendResult(m_chr, 0U, MailResult.MailSent,
                                           MailError.RECIPIENT_CAP_REACHED);
                    return(MailError.RECIPIENT_CAP_REACHED);
                }
            }

            return(SendMail(recipient, subject, body, stationary, items, money, cod));
        }
Beispiel #9
0
        /// <summary>
        /// Creates and sends a new Mail with the given parameters
        /// </summary>
        public MailError SendMail(CharacterRecord recipient, string subject, string body, MailStationary stationary,
                                  ICollection <Item> items, uint money, uint cod)
        {
            if (subject.Length > 128 || body.Length > 512)
            {
                return(MailError.INTERNAL_ERROR);
            }
            if ((int)recipient.EntityLowId == (int)m_chr.EntityId.Low)
            {
                MailHandler.SendResult(m_chr.Client, 0U, MailResult.MailSent,
                                       MailError.CANNOT_SEND_TO_SELF);
                return(MailError.CANNOT_SEND_TO_SELF);
            }

            uint amount = money;

            if (MailMgr.ChargePostage && !m_chr.GodMode)
            {
                amount += MailMgr.PostagePrice;
                uint num = items == null ? 0U : (uint)items.Count;
                if (num > 0U)
                {
                    amount += (num - 1U) * MailMgr.PostagePrice;
                }
            }

            if (amount > m_chr.Money)
            {
                MailHandler.SendResult(m_chr.Client, 0U, MailResult.MailSent,
                                       MailError.NOT_ENOUGH_MONEY);
                return(MailError.NOT_ENOUGH_MONEY);
            }

            m_chr.SubtractMoney(amount);
            MailHandler.SendResult(m_chr.Client, 0U, MailResult.MailSent, MailError.OK);
            m_chr.Achievements.CheckPossibleAchievementUpdates(AchievementCriteriaType.GoldSpentForMail, amount,
                                                               0U, null);
            uint num1 = 0;

            if (!m_chr.GodMode && (money > 0U || items != null && items.Count > 0) &&
                m_chr.Account.AccountId != recipient.AccountId)
            {
                num1 = MailMgr.MaxPacketDeliveryDelay;
            }
            MailMessage letter = new MailMessage(subject, body)
            {
                LastModifiedOn    = new DateTime?(),
                SenderId          = m_chr.EntityId.Low,
                ReceiverId        = recipient.EntityLowId,
                MessageStationary = stationary,
                MessageType       = MailType.Normal,
                CashOnDelivery    = cod,
                IncludedMoney     = money,
                SendTime          = DateTime.Now,
                DeliveryTime      = DateTime.Now.AddSeconds(num1)
            };

            if (items != null && items.Count > 0)
            {
                letter.SetItems(items);
            }
            MailMgr.SendMail(letter);
            return(MailError.OK);
        }