public override void OnResponse(NetState state, RelayInfo info) { if (state == null || state.Mobile == null) return; m_Result.DataItems = GetUnclaimed(m_Result.DataItems); if (m_Result.Status == ResultStatus.OK && m_Result.DataItems.Count == 0) { m_Result.Status = ResultStatus.NoUndeliveredDonationsFound; } if (info.ButtonID == (int)Buttons.Previous && m_Page > 0) { state.Mobile.SendGump(new ClaimDonationsGump(m_Page - 1, this.X, this.Y, m_Result)); } else if (info.ButtonID == (int)Buttons.Next) { state.Mobile.SendGump(new ClaimDonationsGump(m_Page + 1, this.X, this.Y, m_Result)); } else if (info.ButtonID == (int)Buttons.OK && m_Result.Status == ResultStatus.OK) { state.Mobile.CloseAllGumps(); if (state.Mobile != null && !state.Mobile.Deleted && state.Mobile.NetState != null) { if (state.Mobile.BankBox == null) { state.Mobile.SendMessage("You don't seem to have a bankbox, contact a GM."); } else { ArrayList temp = new ArrayList(); Bag bag = new Bag(); bag.Hue = 33; bag.Name = "a donation claim bag"; foreach (DataItem item in m_Result.DataItems) { //Make sure we check amount for (int i = 0; i < item.Amount; i++) { Item toGive = GetItem(item.ProductID); if (toGive != null) { bag.DropItem(toGive); } else { state.Mobile.SendMessage("An error ocurred claiming an item in order number: {0}. An errorlog has been created, please contact an administrator."); string error = String.Format("An error ocurred trying to fetch item for product number: {0} in order: {1} for {2}({3}).", item.ProductID, item.OrderID, state.Mobile.RawName, (state.Mobile.Account as Account).Username); Log(error); } } // Register claim. We only register each order one time if (!temp.Contains(item.OrderID)) { temp.Add(item.OrderID); ClaimedOrder claim = new ClaimedOrder(item.OrderID, state.Mobile); m_ClaimedOrders.Add(claim); } } state.Mobile.BankBox.DropItem(bag); state.Mobile.SendMessage("Your have claimed your donations. They have been added to your bankbox. Thank you for donating!"); } } } else { //state.Mobile.SendMessage("You could not claim the donations, because you claimed them wile this gump was open"); } }
public static void Load() { log.Info("Loading..."); //Console.Write("Donation: Loading..."); ms_ClaimDonationsBlocked = false; if (File.Exists(idxPath) && File.Exists(binPath)) { // Declare and initialize reader objects. FileStream idx = new FileStream(idxPath, FileMode.Open, FileAccess.Read, FileShare.Read); FileStream bin = new FileStream(binPath, FileMode.Open, FileAccess.Read, FileShare.Read); BinaryReader idxReader = new BinaryReader(idx); BinaryFileReader binReader = new BinaryFileReader(new BinaryReader(bin)); // Start by reading the number of orders from an index file int orderCount = idxReader.ReadInt32(); if (orderCount == 0) { log.Warn("Donations save does not contain any entries, [claimdonations deactivated."); //Console.WriteLine("Donations save does not contain any entries, [claimdonations deactivated."); ms_ClaimDonationsBlocked = true; } for (int i = 0; i < orderCount; ++i) { ClaimedOrder c = new ClaimedOrder(); // Read start-position and length of current order from index file long startPos = idxReader.ReadInt64(); int length = idxReader.ReadInt32(); // Point the reading stream to the proper position binReader.Seek(startPos, SeekOrigin.Begin); try { c.Deserialize(binReader); if (binReader.Position != (startPos + length)) throw new Exception(String.Format("***** Bad serialize on ClaimedOrder[{0}] *****", i)); } catch (Exception e) { log.Fatal("Error deserializing donations, [claimdonations deactivated.", e); //Console.WriteLine("Error deserializing donations, [claimdonations deactivated: {0}", e.Message); ms_ClaimDonationsBlocked = true; } m_ClaimedOrders.Add(c); } // Remember to close the streams idxReader.Close(); binReader.Close(); } else { log.Error("Error deserializing donations: idx/bin doesn't exist, [claimdonations deactivated."); //Console.WriteLine("Error deserializing donations: idx/bin doesn't exist, [claimdonations deactivated."); ms_ClaimDonationsBlocked = true; } //Console.WriteLine("done"); log.Info("done."); }