Exemplo n.º 1
0
        public void AddMail(Mail item)
        {
            //HELPERS
            int attachments = 0;
            int pos = this.data.Length;
            Array.Resize(ref this.data, this.data.Length + 131);

            string timestamp = String.Format(CultureInfo.InvariantCulture, "{0}-{1}-{2} {3}:{4}:{5}", item.Time.Day, item.Time.Month, item.Time.Year, item.Time.Hour, item.Time.Minute, item.Time.Second);

            if (item.Zeny > 0)
            {
                attachments |= 1;
            }
            if (item.Attachment != null)
            {
                attachments |= 2;
                Array.Copy(BitConverter.GetBytes(item.Attachment.info.item), 0, this.data, pos + 5, 4);
                this.data[pos + 9] = (byte)item.Attachment.count;
            }

            Array.Copy(BitConverter.GetBytes(item.MailId), 0, this.data, pos, 4);
            this.data[pos + 4] = (byte)attachments;
            Encoding.Unicode.GetBytes(item.Sender, 0, Math.Min(item.Sender.Length, 16), this.data, pos + 13);
            Encoding.Unicode.GetBytes(timestamp, 0, Math.Min(timestamp.Length, 19), this.data, pos + 45);
            this.data[pos + 87] = item.Valid;
            Encoding.Unicode.GetBytes(item.Topic, 0, Math.Min(item.Topic.Length, 19), this.data, pos + 88);
            this.data[pos + 130] = item.IsRead;
            this.Count++;
        }
Exemplo n.º 2
0
        /// <Sql>
        /// SELECT 
        ///     * 
        /// FROM 
        ///     list_maildata
        /// WHERE 
        ///     Sender=?Sender
        /// AND 
        ///     IsOutbox=1;
        /// </Sql>
        public IEnumerable<Mail> GetOutboxMail(Character target)
        {
            MySqlConnection connection = ConnectionPool.Request();
            MySqlCommand command = new MySqlCommand(_query_37, connection);
            command.Parameters.AddWithValue("Sender", target.Name);
            MySqlDataReader reader = null;

            try
            {
                reader = command.ExecuteReader();
                while (reader.Read())
                {
                    // 0 - MailId
                    // 1 - Sender
                    // 2 - Receiptent
                    // 3 - Date
                    // 4 - IsRead
                    // 5 - IsChecked
                    // 6 - Topic
                    // 7 - Message
                    // 8 - Attachment
                    // 9 - Zeny

                    Mail mailsubject = new Mail();
                    mailsubject.MailId = reader.GetUInt32(0);
                    mailsubject.Sender = reader.GetString(1);
                    mailsubject.Time = reader.GetDateTime(3);
                    mailsubject.IsRead = reader.GetByte(4);
                    mailsubject.Topic = reader.GetString(6);
                    mailsubject.Message = reader.GetString(7);
                    mailsubject.Zeny = (int)reader.GetUInt32(9);

                    if (reader.IsDBNull(8) == false)
                    {
                        byte[] buffer = new byte[67];
                        reader.GetBytes(8, 0, buffer, 0, 67);
                        Rag2Item.Deserialize(out mailsubject.Attachment, buffer, 0);
                    }
                    if (mailsubject.IsRead == 0)
                    {
                        mailsubject.Valid = (byte)(30 - Math.Min(30, (int)((DateTime.Now - mailsubject.Time).TotalDays)));
                    }
                    yield return mailsubject;
                }
            }
            finally
            {
                if (reader != null) reader.Close();
                ConnectionPool.Release(connection);
            }
        }
Exemplo n.º 3
0
        /// <Sql>
        /// SELECT 
        ///     * 
        /// FROM 
        ///     list_maildata
        /// WHERE 
        ///     Receiptent=?Receiptent
        /// AND 
        ///     IsInbox=1;
        /// </Sql>
        public IEnumerable<Mail> GetInboxMail(MySqlConnection connection, Character target)
        {
            MySqlCommand command = new MySqlCommand(_query_35, connection);
            MySqlCommand command2 = new MySqlCommand(_query_36, connection);
            command.Parameters.AddWithValue("Receiptent", target.Name);
            command2.Parameters.AddWithValue("Receiptent", target.Name);
            MySqlDataReader reader = null;
            List<Mail> list = new List<Mail>();

            try
            {
                command2.ExecuteNonQuery();
                reader = command.ExecuteReader();
                while (reader.Read())
                {

                    Mail mailsubject = new Mail();
                    mailsubject.MailId = reader.GetUInt32(0);
                    mailsubject.MailId = reader.GetUInt32(0);
                    mailsubject.Sender = reader.GetString(2);
                    mailsubject.Time = reader.GetDateTime(3);
                    mailsubject.IsRead = reader.GetByte(4);
                    mailsubject.Topic = reader.GetString(6);
                    mailsubject.Message = reader.GetString(7);
                    mailsubject.Zeny = (int)reader.GetUInt32(9);

                    if (reader.IsDBNull(8) == false)
                    {
                        byte[] buffer = new byte[67];
                        reader.GetBytes(8, 0, buffer, 0, 67);
                        Rag2Item.Deserialize(out mailsubject.Attachment, buffer, 0);
                    }
                    if (mailsubject.IsRead == 0)
                    {
                        mailsubject.Valid = (byte)(30 - Math.Min(30, (int)((DateTime.Now - mailsubject.Time).TotalDays)));
                    }
                    else
                    {
                        DateTime dateread = reader.GetDateTime(10);
                        mailsubject.Valid = (byte)(7 - Math.Min(7, (int)((DateTime.Now - dateread).TotalDays)));
                    }

                    list.Add(mailsubject);
                }

                return list;
            }
            catch (Exception e)
            {
                __dbtracelog.WriteError("Database", e.Message);
                return list;
            }
            finally
            {
                if (reader != null) reader.Close();
            }
        }