Example #1
0
        public void Process(MessageType type, byte[] data)
        {
            switch (type)
            {
            // This is generally called when adding an item by clicking on the stash tab
            case MessageType.TYPE_InventorySack_AddItem:
            {
                int pos   = 2;
                var items = GetPlayerItemFromInventorySack(data, pos);
                playerItemDao.Save(items);
                logger.InfoFormat("A gnome has delivered {0} new items to IA.", items.Count);
                searchWindow?.UpdateListviewDelayed();
                stashManager.CancelQueuedLoot();
                //logger.Debug("TYPE_InventorySack_AddItem ignored");
            }
            break;

            // This is generally called when adding an item to a specific position in the bag
            case MessageType.TYPE_InventorySack_AddItem_Vec2:
            {
                int   pos = 0;
                float x   = IOHelper.GetFloat(data, 0); pos += 4;
                float y   = IOHelper.GetFloat(data, 4); pos += 4;
                bool  b   = data[pos] > 0; pos++;

                var items = GetPlayerItemFromInventorySack(data, pos);
                playerItemDao.Save(items);
                logger.InfoFormat("A helpful goblin has delivered {0} new items to IA.", items.Count);
                searchWindow?.UpdateListviewDelayed();
                stashManager.CancelQueuedLoot();
            }
            break;
            }
        }
Example #2
0
        public void TestDeleteItem()
        {
            int n    = new Random().Next();
            var item = GetBasicItem(n);

            dao.Save(item);
            item.Id.Should().Be.GreaterThan(0);
            Executing.This(() => { dao.Remove(item); }).Should().NotThrow();
        }
Example #3
0
        private void buttonImport_Click(object sender, EventArgs e)
        {
            if (buttonImport.Enabled)
            {
                FileExporter io;

                if (radioIAStash.Checked)
                {
                    io = new IAFileExporter(_filename);
                }
                else if (radioGDStash.Checked)
                {
                    GDTransferFile settings = cbItemSelection.SelectedItem as GDTransferFile;
                    if (settings == null)
                    {
                        io = new GDFileExporter(_filename, false, string.Empty);
                    }
                    else
                    {
                        io = new GDFileExporter(_filename, settings.IsExpansion1, settings.Mod);
                    }
                }
                else
                {
                    _playerItemDao.Save(_sm.EmptyStash(_filename));
                    MessageBox.Show("Items imported", "Items imported!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                var items = io.Read();
                _playerItemDao.Import(items);

                MessageBox.Show("Items imported\nIf you already had items, you may have gotten duplicates.", "Items imported!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #4
0
        private void buttonImport_Click(object sender, EventArgs e)
        {
            if (buttonImport.Enabled)
            {
                FileExporter io;

                if (radioIAStash.Checked)
                {
                    io = new IAFileExporter(_filename);
                }
                else if (radioGDStash.Checked)
                {
                    GDTransferFile settings = cbItemSelection.SelectedItem as GDTransferFile;
                    io = new GDFileExporter(_filename, settings?.Mod ?? string.Empty);
                }
                else
                {
                    _playerItemDao.Save(_sm.EmptyStash(_filename));

                    MessageBox.Show(
                        RuntimeSettings.Language.GetTag("iatag_ui_importexport_import_success"),
                        RuntimeSettings.Language.GetTag("iatag_ui_importexport_import_success"),
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information
                        );
                    return;
                }

                var items = io.Read(Read(_filename));
                Logger.Debug($"Storing {items.Count} items to db");
                progressBar1.Maximum = items.Count;
                buttonImport.Enabled = false;
                Thread t = new Thread(() => {
                    ExceptionReporter.EnableLogUnhandledOnThread();
                    isLocked = true;

                    var batches = BatchUtil.ToBatches <PlayerItem>(items);
                    foreach (var batch in batches)
                    {
                        _playerItemDao.Import(batch);
                        Invoke((MethodInvoker) delegate { progressBar1.Value += batch.Count; });
                    }

                    isLocked = false;
                    MessageBox.Show(
                        RuntimeSettings.Language.GetTag("iatag_ui_importexport_import_success_body"),
                        RuntimeSettings.Language.GetTag("iatag_ui_importexport_import_success"),
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information
                        );
                });

                t.Start();
            }
        }
Example #5
0
        private void Download()
        {
            var result = Post($"token={_token}&lastUpdate={Properties.Settings.Default.LastOnlineBackup}", DownloadUrl);

            if (string.IsNullOrEmpty(result))
            {
                Logger.Warn("Error downloading items from remote backup server");
                _nextDownload = DateTime.UtcNow.AddMinutes(30);
                return;
            }

            var obj = JsonConvert.DeserializeObject <PlayerItemBackupDownload>(result);

            if (obj.Success)
            {
                var existingItems = _playerItemDao.ListAll()
                                    .Where(m => m.OnlineId.HasValue)
                                    .Select(m => m.OnlineId.Value)
                                    .ToList();

                var newItems = obj.Items.Where(onlineItem => !existingItems.Contains(onlineItem.OnlineId)).ToList();
                foreach (var simplified in newItems)
                {
                    var item = Map(simplified);
                    // TODO: Get timestamp from server [on upload]
                    _playerItemDao.Save(item);
                }
                foreach (var deleted in obj.Deleted)
                {
                    var item = _playerItemDao.GetByOnlineId(deleted);
                    if (item != null)
                    {
                        _playerItemDao.Remove(item);
                    }
                }

                Logger.Info($"Added {obj.Items.Count} items after online sync");
                Logger.Info($"Removed {obj.Deleted.Count} items after online sync");

                // TODO: This is very low for every-day usage, and very high for frequent pc switch usage
                _nextDownload = DateTime.UtcNow.AddHours(1);

                if (obj.Items.Count > 0)
                {
                    Properties.Settings.Default.LastOnlineBackup = obj.Items.Max(m => m.ModifiedDate);
                    Properties.Settings.Default.Save();
                }
            }
            else
            {
                HandleAuthenticationIssues(obj.ErrorCode);
                Logger.Warn($"Could not synchronize items from online backup. Error code {obj.ErrorCode}");
            }
        }
Example #6
0
        private bool StoreItemsToDatabase(ICollection <Item> items, string mod, bool isHardcore)
        {
            // Convert the items
            var playerItems = items.Select(item => TransferStashService.Map(item, mod, isHardcore)).ToList();

            try {
                _playerItemDao.Save(playerItems);
            }
            catch (Exception ex) {
                Logger.Warn(ex.Message);
                Logger.Warn(ex.StackTrace);
                ExceptionReporter.ReportException(ex, "StoreItems");
                return(false);
            }

            return(true);
        }
Example #7
0
        private void buttonImport_Click(object sender, EventArgs e)
        {
            if (buttonImport.Enabled)
            {
                FileExporter io;

                if (radioIAStash.Checked)
                {
                    io = new IAFileExporter(_filename);
                }
                else if (radioGDStash.Checked)
                {
                    GDTransferFile settings = cbItemSelection.SelectedItem as GDTransferFile;
                    io = new GDFileExporter(_filename, settings?.Mod ?? string.Empty);
                }
                else
                {
                    _playerItemDao.Save(_sm.EmptyStash(_filename));

                    MessageBox.Show(
                        RuntimeSettings.Language.GetTag("iatag_ui_importexport_import_success"),
                        RuntimeSettings.Language.GetTag("iatag_ui_importexport_import_success"),
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information
                        );
                    return;
                }

                var items = io.Read(Read(_filename));
                _playerItemDao.Import(items);

                MessageBox.Show(
                    RuntimeSettings.Language.GetTag("iatag_ui_importexport_import_success_body"),
                    RuntimeSettings.Language.GetTag("iatag_ui_importexport_import_success"),
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information
                    );
            }
        }
Example #8
0
        /// <summary>
        ///     Store all the items
        ///     ----UNTRUE?: If an item cannot be stored (missing record), it is returned so it can be re-written to stash.
        /// </summary>
        /// <param name="items"></param>
        /// <returns></returns>
        private List <PlayerItem> StoreItemsToDatabase(ICollection <Item> items, string mod, bool isHardcore, bool isExpansion1)
        {
            List <PlayerItem> playerItems = new List <PlayerItem>();

            foreach (Item item in items)
            {
                PlayerItem newItem = Map(item, mod, isHardcore, isExpansion1);
                playerItems.Add(newItem);
            }

            try {
                _playerItemDao.Save(playerItems);
            }
            catch (Exception ex) {
                Logger.Warn(ex.Message);
                Logger.Warn(ex.StackTrace);
                ExceptionReporter.ReportException(ex, "StoreItems");
                return(null);
            }

            return(playerItems);
        }
Example #9
0
        private bool StoreItemsToDatabase(ICollection <Item> items, string mod, bool isHardcore)
        {
            // Convert the items
            var playerItems = items.Select(item => TransferStashService.Map(item, mod, isHardcore)).ToList();

            try {
                _playerItemDao.Save(playerItems);

                foreach (var item in playerItems)
                {
                    var hash = ItemReplicaService.GetHash(item);
                    _replicaItemDao.UpdatePlayerItemId(hash, item.Id);
                }
            }
            catch (Exception ex) {
                Logger.Warn(ex.Message);
                Logger.Warn(ex.StackTrace);
                return(false);
            }

            return(true);
        }
Example #10
0
        public void Process(MessageType type, byte[] data)
        {
            switch (type)
            {
            case MessageType.TYPE_Custom_AddItemSucceeded:
                logger.Info("Hook reports item injection successful.");
                break;

            case MessageType.TYPE_Custom_AddItem:
                logger.DebugFormat("TYPE_Custom_AddItem: {0}", IOHelper.GetInt(data, 0));
                break;

            case MessageType.TYPE_Custom_AddItemFailed:
                logger.Info("Hook reports item injection failed.");
                {
                    PlayerItem pi = Deserialize(data);
                    playerItemDao.Save(pi);
                    logger.Info("Item stored back in IA database.");
                    UpdateItemView();
                }
                break;
            }
        }
Example #11
0
 public new void Save(IEnumerable <PlayerItem> items)
 {
     ThreadExecuter.Execute(
         () => repo.Save(items)
         );
 }
Example #12
0
        public void Start()
        {
            // Queue any existing files
            foreach (var file in Directory.EnumerateFiles(GlobalPaths.CsvLocation))
            {
                _queue.Enqueue(new QueuedCsv {
                    Filename = file,
                    Cooldown = new ActionCooldown(0)
                });
            }


            // Process any newly added files. Threaded to ensure a proper delay between write and read.
            var t = new Thread(() => {
                ExceptionReporter.EnableLogUnhandledOnThread();

                while (!_isCancelled)
                {
                    Thread.Sleep(500);
                    if (!_queue.TryDequeue(out var entry))
                    {
                        continue;
                    }
                    try {
                        if (entry.Cooldown.IsReady)
                        {
                            PlayerItem item = Parse(File.ReadAllText(entry.Filename));
                            if (item == null)
                            {
                                continue;
                            }

                            // CSV probably wont have stackcount
                            item.StackCount   = Math.Max(item.StackCount, 1);
                            item.CreationDate = DateTime.UtcNow.ToTimestamp();

                            var classificationService = new ItemClassificationService(_cache, _playerItemDao);
                            classificationService.Add(item);

                            // Items to loot
                            if (classificationService.Remaining.Count > 0)
                            {
                                _playerItemDao.Save(item);
                                File.Delete(entry.Filename);

                                // Update replica reference
                                var hash = ItemReplicaService.GetHash(item);
                                _replicaItemDao.UpdatePlayerItemId(hash, item.Id);
                            }
                            else if (classificationService.Duplicates.Count > 0 && _settings.GetPersistent().DeleteDuplicates)
                            {
                                Logger.Info("Deleting duplicate item file");
                                File.Delete(entry.Filename);
                            }
                            else
                            {
                                // Transfer back in-game, should never have been looted.
                                // TODO: Separate transfer logic.. no delete-from-db etc..
                                if (RuntimeSettings.StashStatus == StashAvailability.CLOSED)
                                {
                                    string stashfile = _itemTransferController.GetTransferFile();
                                    _transferStashService.Deposit(stashfile, new List <PlayerItem> {
                                        item
                                    }, out string error);
                                    if (string.IsNullOrEmpty(error))
                                    {
                                        Logger.Info("Deposited item back in-game, did not pass item classification.");
                                        File.Delete(entry.Filename);
                                    }
                                    else
                                    {
                                        Logger.Warn("Failed re-depositing back into GD");
                                        _queue.Enqueue(entry);
                                    }
                                }
                                else
                                {
                                    _queue.Enqueue(entry);
                                }
                            }
                        }
                        else
                        {
                            _queue.Enqueue(entry);
                        }
                    }
                    catch (Exception ex) {
                        Logger.Warn("Error handling CSV item file", ex);
                    }
                }
            });

            t.Start();
        }