public void On_CMSG_MAIL_TAKE_ITEM(ref Packets.PacketClass packet, ref WS_Network.ClientClass client) { checked { if (packet.Data.Length - 1 < 17) { return; } packet.GetInt16(); ulong GameObjectGUID = packet.GetUInt64(); int MailID = packet.GetInt32(); WorldServiceLocator._WorldServer.Log.WriteLine(LogType.DEBUG, "[{0}:{1}] CMSG_MAIL_TAKE_ITEM [MailID={2}]", client.IP, client.Port, MailID); try { DataTable MySQLQuery = new(); WorldServiceLocator._WorldServer.CharacterDatabase.Query($"SELECT mail_cod, mail_sender, item_guid FROM characters_mail WHERE mail_id = {MailID} AND mail_receiver = {client.Character.GUID};", ref MySQLQuery); if (MySQLQuery.Rows.Count == 0) { Packets.PacketClass response4 = new(Opcodes.SMSG_SEND_MAIL_RESULT); response4.AddInt32(MailID); response4.AddInt32(2); response4.AddInt32(6); client.Send(ref response4); response4.Dispose(); return; } if (!Operators.ConditionalCompareObjectNotEqual(MySQLQuery.Rows[0]["mail_cod"], 0, TextCompare: false)) { goto IL_02b9; } if (Operators.ConditionalCompareObjectLess(client.Character.Copper, MySQLQuery.Rows[0]["mail_cod"], TextCompare: false)) { Packets.PacketClass noMoney = new(Opcodes.SMSG_SEND_MAIL_RESULT); noMoney.AddInt32(MailID); noMoney.AddInt32(0); noMoney.AddInt32(3); client.Send(ref noMoney); noMoney.Dispose(); return; } ref uint copper = ref client.Character.Copper; copper = Conversions.ToUInteger(Operators.SubtractObject(copper, MySQLQuery.Rows[0]["mail_cod"])); WorldServiceLocator._WorldServer.CharacterDatabase.Update($"UPDATE characters_mail SET mail_cod = 0 WHERE mail_id = {MailID};"); int MailTime = (int)(WorldServiceLocator._Functions.GetTimestamp(DateAndTime.Now) + 2592000L); WorldServiceLocator._WorldServer.CharacterDatabase.Update(string.Format("INSERT INTO characters_mail (mail_sender, mail_receiver, mail_subject, mail_body, mail_item_guid, mail_money, mail_COD, mail_time, mail_read, mail_type) VALUES \r\n ({0},{1},'{2}','{3}',{4},{5},{6},{7},{8},{9});", client.Character.GUID, MySQLQuery.Rows[0]["mail_sender"], "", "", 0, MySQLQuery.Rows[0]["mail_cod"], 0, MailTime, MailReadInfo.COD, 0)); IL_02b9: if (Operators.ConditionalCompareObjectEqual(MySQLQuery.Rows[0]["item_guid"], 0, TextCompare: false)) { Packets.PacketClass response3 = new(Opcodes.SMSG_SEND_MAIL_RESULT); response3.AddInt32(MailID); response3.AddInt32(2); response3.AddInt32(6); client.Send(ref response3); response3.Dispose(); return; } ItemObject tmpItem = WorldServiceLocator._WS_Items.LoadItemByGUID(MySQLQuery.Rows[0].As <ulong>("item_guid")); tmpItem.OwnerGUID = client.Character.GUID; tmpItem.Save(); if (client.Character.ItemADD(ref tmpItem)) { WorldServiceLocator._WorldServer.CharacterDatabase.Update($"UPDATE characters_mail SET item_guid = 0 WHERE mail_id = {MailID};"); WorldServiceLocator._WorldServer.CharacterDatabase.Update($"DELETE FROM mail_items WHERE mail_id = {MailID};"); Packets.PacketClass response2 = new(Opcodes.SMSG_SEND_MAIL_RESULT); response2.AddInt32(MailID); response2.AddInt32(2); response2.AddInt32(0); client.Send(ref response2); response2.Dispose(); } else { tmpItem.Dispose(); Packets.PacketClass response = new(Opcodes.SMSG_SEND_MAIL_RESULT); response.AddInt32(MailID); response.AddInt32(2); response.AddInt32(1); client.Send(ref response); response.Dispose(); } client.Character.Save(); }