private void DoTrade() { string msg = "Trade Successful!"; string failmsg = "An error occured while trading, possible exploit detected!"; var thisItems = new List <Item>(); var targetItems = new List <Item>(); // make sure trade targets are valid if (tradeTarget == null || Owner == null || tradeTarget.Owner == null || Owner != tradeTarget.Owner) { if (this != null) { psr.SendPacket(new TradeDonePacket { Result = 1, Message = failmsg }); } if (tradeTarget != null) { tradeTarget.psr.SendPacket(new TradeDonePacket { Result = 1, Message = failmsg }); } var dir = @"logs"; //start of logging code if (!System.IO.Directory.Exists(dir)) { System.IO.Directory.CreateDirectory(dir); } using (System.IO.StreamWriter writer = new System.IO.StreamWriter(@"logs\DupeLog.txt", true)) { writer.WriteLine("[" + DateTime.Now + "]" + nName + " has attempted to dupe with " + tradeTarget.nName); } //end of logging code //A good idea would to log this to a .txt or have an auto-ban checker such as my anticheat. //Just looked at it in-game... it spams you with the failmsg. Working on fix return; } //get trade items for (int i = 4; i < Inventory.Length; i++) { if (trade[i] && !Inventory[i].Soulbound) { thisItems.Add(Inventory[i]); Inventory[i] = null; UpdateCount++; //save this trade info if (itemnumber1 == 0) { items1 = items1 + " " + thisItems[itemnumber1].ObjectId; } else if (itemnumber1 > 0) { items1 = items1 + ", " + thisItems[itemnumber1].ObjectId; } itemnumber1++; } if (tradeTarget.trade[i] && !tradeTarget.Inventory[i].Soulbound) { targetItems.Add(tradeTarget.Inventory[i]); tradeTarget.Inventory[i] = null; tradeTarget.UpdateCount++; // save target trade info if (itemnumber2 == 0) { items2 = items2 + " " + targetItems[itemnumber2].ObjectId; } else if (itemnumber2 > 0) { items2 = items2 + ", " + targetItems[itemnumber2].ObjectId; } itemnumber2++; } } // move thisItems -> tradeTarget for (int j = thisItems.Count - 1; j >= 0; j--) { for (int i = 0; i < tradeTarget.Inventory.Length; i++) { if ((tradeTarget.SlotTypes[i] == 0 && tradeTarget.Inventory[i] == null) || (thisItems[j] != null && tradeTarget.SlotTypes[i] == thisItems[j].SlotType && tradeTarget.Inventory[i] == null)) { tradeTarget.Inventory[i] = thisItems[j]; thisItems.RemoveAt(j); break; } } } //move tradeItems -> this for (int j = targetItems.Count - 1; j >= 0; j--) { for (int i = 0; i < Inventory.Length; i++) { if ((SlotTypes[i] == 0 && Inventory[i] == null) || (targetItems[j] != null && SlotTypes[i] == targetItems[j].SlotType && Inventory[i] == null)) { Inventory[i] = targetItems[j]; targetItems.RemoveAt(j); break; } } } //check for lingering items if (thisItems.Count > 0 || targetItems.Count > 0) { msg = "An error occured while trading!"; } // trade successful, notify and save psr.SendPacket(new TradeDonePacket { Result = 1, Message = msg }); tradeTarget.psr.SendPacket(new TradeDonePacket { Result = 1, Message = msg }); SaveToCharacter(); psr.Save(); tradeTarget.SaveToCharacter(); tradeTarget.psr.Save(); //clean items1 = ""; items2 = ""; itemnumber1 = 0; itemnumber2 = 0; UpdateCount++; tradeTarget.UpdateCount++; tradeTarget.tradeTarget = null; tradeTarget.trade = null; tradeTarget.tradeAccepted = false; tradeTarget = null; trade = null; tradeAccepted = false; }