Exemplo n.º 1
0
 bool IDatabase.InsertNewMailItem(Character target, MailItem item)
 {
     return InsertNewMailItem(target, item);
 }
Exemplo n.º 2
0
 public bool InsertNewMailItem(Character target, MailItem item)
 {
     return InternalDatabaseProvider.InsertNewMailItem(target, item);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Buys the specified market item.
        /// </summary>
        /// <param name="cpkt"></param>
        private void CM_MARKET_BUY(CMSG_MARKETBUY cpkt)
        {
            //HELPER VARIABLES
            AuctionArgument item;

            //ITEM ALREADY SOLD
            if (!Singleton.Database.GetItemByAuctionId(cpkt.ItemId, out item))
            {
                SMSG_MARKETBUY spkt = new SMSG_MARKETBUY();
                spkt.SessionId = this.character.id;
                spkt.Reason = 7;
                this.Send((byte[])spkt);
            }
            //NOT ENOUGH MONEY TO PURCHASE
            else if (item.zeny > this.character.ZENY)
            {
                SMSG_MARKETBUY spkt = new SMSG_MARKETBUY();
                spkt.SessionId = this.character.id;
                spkt.Reason = 2;
                this.Send((byte[])spkt);
            }
            //CHECK IF OWN INBOX IF FULL
            else if (Singleton.Database.GetInboxMailCount(this.character.Name) == 20)
            {
                SMSG_MARKETBUY spkt = new SMSG_MARKETBUY();
                spkt.SessionId = this.character.id;
                spkt.Reason = 4;
                this.Send((byte[])spkt);
            }
            //CHECK IF SENDER INBOX IS FULL
            else if (Singleton.Database.GetInboxMailCount(item.name) == 20)
            {
                SMSG_MARKETBUY spkt = new SMSG_MARKETBUY();
                spkt.SessionId = this.character.id;
                spkt.Reason = 5;
                this.Send((byte[])spkt);
            }
            //CASH ITEM DOES NOT EXISTS
            else if (!Singleton.Database.DeleteRegisteredAuctionItem(cpkt.ItemId))
            {
                SMSG_MARKETBUY spkt = new SMSG_MARKETBUY();
                spkt.SessionId = this.character.id;
                spkt.Reason = 7;
                this.Send((byte[])spkt);
            }
            //EVERYTHING OKAY
            else
            {
                //OKAY RESULT
                SMSG_MARKETBUY spkt = new SMSG_MARKETBUY();
                spkt.SessionId = this.character.id;
                this.Send((byte[])spkt);

                //UPDATE ZENY
                this.character.ZENY -= item.zeny;
                CommonFunctions.UpdateZeny(this.character);

                //Buyer get's item
                MailItem buyer = new MailItem();
                buyer.Recieptent = this.character.Name;
                buyer.item = item.item;
                buyer.Content = "Auction";
                buyer.Topic = "Auction";
                buyer.Timestamp = DateTime.Now;
                buyer.Zeny = 0;

                //Reciever get's money
                MailItem reciever = new MailItem();
                reciever.item = null;
                reciever.Recieptent = item.name;
                reciever.Zeny = item.zeny;
                reciever.Topic = "Auction";
                reciever.Timestamp = DateTime.Now;
                reciever.Content = "Auction";

                //Add mail items
                Singleton.Database.InsertNewMailItem(null, buyer);
                Singleton.Database.InsertNewMailItem(null, reciever);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Deletes a item from the market.
        /// </summary>
        /// <param name="cpkt"></param>
        private void CM_MARKET_DELETEITEM(CMSG_MARKETDELETEITEM cpkt)
        {
            //HELPER VARIABLES
            AuctionArgument item;
            byte result = 0;

            try
            {
                //Failed retrieving
                if (!Singleton.Database.GetItemByAuctionId(cpkt.ItemId, out item))
                {
                    result = 1;
                }
                //Check my outbox
                else if (Singleton.Database.GetInboxMailCount(item.name) >= 20)
                {
                    result = 1;
                }
                //Failed unregistering
                else if (Singleton.Database.UnregisterMarketItem(cpkt.ItemId) == 0)
                {
                    result = 1;
                }
                else
                {
                    //Buyer get's item
                    MailItem buyer = new MailItem();
                    buyer.Recieptent = item.name;
                    buyer.item = item.item;
                    buyer.Content = "Auction";
                    buyer.Topic = "Auction";
                    buyer.Timestamp = DateTime.Now;
                    buyer.Zeny = 0;

                    //Add mail items
                    Singleton.Database.InsertNewMailItem(null, buyer);
                }
            }
            finally
            {
                SMSG_MARKETDELETEITEM spkt = new SMSG_MARKETDELETEITEM();
                spkt.SessionId = this.character.id;
                spkt.ItemID = cpkt.ItemId;
                spkt.Reason = result;
                this.Send((byte[])spkt);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Sends a new mail message
        /// </summary>
        private void CM_NEWMAILITEM(CMSG_SENDMAIL cpkt)
        {
            //HELPER VARIABLES
            byte result = 1;
            uint req_zeny = 0;
            Rag2Item item = null;
            MailItem mailmessage = new MailItem();
            mailmessage.Content = cpkt.Content;
            mailmessage.Recieptent = cpkt.Name;
            mailmessage.Topic = cpkt.Topic;
            mailmessage.item = item;

            if ((cpkt.HasItem & 2) == 2)
            {
                item = this.character.container[cpkt.Slot];
                if (item != null)
                {
                    req_zeny = 10;
                    mailmessage.item = item.Clone(cpkt.StackCount);
                }
            }
            if ((cpkt.HasItem & 1) == 1)
            {
                req_zeny = 10 + cpkt.Zeny;
                mailmessage.Zeny = cpkt.Zeny;
            }

            try
            {
                //RECIEVER DOES NOT EXISTS
                if (!Singleton.Database.VerifyNameExists(mailmessage.Recieptent))
                {
                    result = 2;
                }
                //NOT ENOUGH MONEY
                else if (this.character.ZENY < req_zeny)
                {
                    result = 3;
                }
                //CHECK ITEM INVENTORY
                else if (item != null && cpkt.StackCount > item.count)
                {
                    result = 5;
                }
                //CHECK IF OWNER OUTBOX IF FULL
                else if (Singleton.Database.GetInboxMailCount(this.character.Name) == 20)
                {
                    result = 6;
                }
                //CHECK IF SENDER INBOX IS FULL
                else if (Singleton.Database.GetInboxMailCount(mailmessage.Recieptent) == 20)
                {
                    result = 7;
                }
                //DATABASE ERROR
                else if (!Singleton.Database.InsertNewMailItem(this.character, mailmessage))
                {
                    result = 1;
                }
                //EVERYTHING IS OKAY
                else
                {
                    if (cpkt.HasItem > 0)
                    {
                        this.character.ZENY -= req_zeny;
                        CommonFunctions.UpdateZeny(this.character);
                    }

                    //UPDATE ITEM COUNT AS FORM OF A ATTACHMENT
                    if ((cpkt.HasItem & 2) == 2)
                    {
                        item.count -= cpkt.StackCount;
                        if (item.count > 0)
                        {
                            SMSG_UPDATEITEM spkt = new SMSG_UPDATEITEM();
                            spkt.Amount = (byte)item.count;
                            spkt.UpdateReason = (byte)ItemUpdateReason.AttachmentReceived;
                            spkt.UpdateType = 4;
                            spkt.Container = 2;
                            spkt.SessionId = this.character.id;
                            spkt.Index = cpkt.Slot;
                            this.Send((byte[])spkt);
                        }
                        else
                        {
                            this.character.container.RemoveAt(cpkt.Slot);
                            SMSG_DELETEITEM spkt = new SMSG_DELETEITEM();
                            spkt.Container = 2;
                            spkt.Index = cpkt.Slot;
                            spkt.UpdateReason = (byte)ItemUpdateReason.AttachmentReceived;
                            spkt.SessionId = this.character.id;
                            this.Send((byte[])spkt);
                        }
                    }

                    //EVERYTHING OKAY
                    result = 0;
                }
            }
            finally
            {
                SMSG_MAILSENDAWNSER spkt = new SMSG_MAILSENDAWNSER();
                spkt.Result = result;
                spkt.SessionId = cpkt.SessionId;
                this.Send((byte[])spkt);
            }
        }
Exemplo n.º 6
0
        /// <Sql>
        /// INSERT INTO
        ///     list_maildata
        /// (
        ///     Sender,
        ///     Receiptent,
        ///     Date,
        ///     Topic,
        ///     Message,           
        ///     Attachment,
        ///     Zeny
        /// ) VALUES (
        ///     @Sender,
        ///     @Receiptent,
        ///     @Date,
        ///     @Topic,
        ///     @Attachment,
        ///     @Zeny
        ///  ) 
        /// </Sql>
        public bool InsertNewMailItem(Character target, MailItem item)
        {
            byte[] buffer = null;
            if (item.item != null)
            {
                buffer = new byte[67];
                Rag2Item.Serialize(item.item, buffer, 0);
            }

            MySqlConnection connection = ConnectionPool.Request();
            MySqlCommand command = new MySqlCommand(_query_45, connection);
            command.Parameters.AddWithValue("Sender", (target != null) ? target.Name : string.Empty);
            command.Parameters.AddWithValue("Receiptent", item.Recieptent);
            command.Parameters.AddWithValue("Date", item.Timestamp);
            command.Parameters.AddWithValue("Topic", item.Topic);
            command.Parameters.AddWithValue("Message", item.Content);
            command.Parameters.AddWithValue("Zeny", item.Zeny);
            command.Parameters.AddWithValue("Attachment", buffer);

            try
            {
                return command.ExecuteNonQuery() > 0;
            }
            catch (Exception e)
            {
                __dbtracelog.WriteError("Database", e.Message);
                return false;
            }
            finally
            {
                ConnectionPool.Release(connection);
            }
        }
Exemplo n.º 7
0
        /// <Sql>
        /// SELECT 
        ///     * 
        /// FROM 
        ///     list_maildata 
        /// WHERE 
        ///     InboxId=?Id 
        /// LIMIT 1;
        /// </Sql>
        public MailItem GetMailItemById(MySqlConnection connection, uint id)
        {
            MySqlCommand command = new MySqlCommand(_query_47, connection);
            command.Parameters.AddWithValue("Id", id);
            MySqlDataReader reader = null;

            try
            {
                reader = command.ExecuteReader(); // argument CommandBehavior.SingleRow removed (Darkin)
                while (reader.Read())
                {
                    MailItem item = new MailItem();
                    item.Recieptent = reader.GetString(2);
                    item.Topic = reader.GetString(6);
                    item.Content = reader.GetString(7);
                    item.Timestamp = reader.GetDateTime(3);
                    item.Zeny = reader.GetUInt32(9);
                    if (reader.IsDBNull(8) == false)
                    {
                        byte[] buffer = new byte[67];
                        reader.GetBytes(8, 0, buffer, 0, 67);
                        Rag2Item.Deserialize(out item.item, buffer, 0);
                    }

                    //Singleton.Item.TryGetItemWithCount(27, 1, out item.item);
                    return item;
                }
                return null;
            }
            catch (Exception e)
            {
                __dbtracelog.WriteError("Database", e.Message);
                return null;
            }
            finally
            {
                if (reader != null) reader.Close();
            }
        }