Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- case "tr":
- {
- string playersItemsPath = Program.ServerConfig.DbLocation + "\\PlayersItems\\";
- string backupPath = Program.ServerConfig.DbLocation + "BackupPlayersItems\\";
- string removedItemsPath = Program.ServerConfig.DbLocation + "RemovedItems\\";
- if (!Directory.Exists(backupPath))
- {
- Directory.CreateDirectory(backupPath);
- }
- if (!Directory.Exists(removedItemsPath))
- {
- Directory.CreateDirectory(removedItemsPath);
- }
- HashSet<uint> removedItemIds = new HashSet<uint>();
- List<Task> tasks = new List<Task>();
- foreach (string fname in System.IO.Directory.GetFiles(playersItemsPath))
- {
- tasks.Add(Task.Run(() =>
- {
- string fileName = Path.GetFileName(fname);
- string destPath = Path.Combine(backupPath, fileName);
- File.Copy(fname, destPath, true);
- uint clientUID = uint.Parse(System.IO.Path.GetFileName(fname).Replace(".bin", ""));
- Client.GameClient client = new Client.GameClient(null);
- client.Player.UID = clientUID;
- client.Inventory = new Role.Instance.Inventory(client);
- client.Equipment = new Role.Instance.Equip(client);
- client.Warehouse = new Role.Instance.Warehouse(client);
- Database.ServerDatabase.LoadClientItems(client);
- var clientItemIds = client.Equipment.ClientItems.Values.Select(item => item.ITEM_ID)
- .Concat(client.Warehouse.ClientItems.SelectMany(warehouse => warehouse.Value.Values.Select(item => item.ITEM_ID)))
- .Concat(client.Inventory.ClientItems.Values.Select(item => item.ITEM_ID))
- .ToList();
- List<uint> allowedItemIds = File.ReadAllLines(Program.ServerConfig.DbLocation + "itemtype.txt")
- .Select(l => uint.Parse(l.Split(new string[] { "@@" }, StringSplitOptions.None)[0]))
- .ToList();
- var itemsToRemove = clientItemIds.Except(allowedItemIds).ToList();
- lock (removedItemIds)
- {
- removedItemIds.UnionWith(itemsToRemove);
- }
- foreach (var item in client.Equipment.ClientItems.Values.ToList())
- {
- if (itemsToRemove.Contains(item.ITEM_ID))
- {
- client.Equipment.ClientItems.Remove(item.UID);
- Console.WriteLine($"Removed item Equipment with ID: {item.ITEM_ID}", ConsoleColor.DarkRed);
- }
- }
- foreach (var warehouse in client.Warehouse.ClientItems)
- {
- foreach (var wItem in warehouse.Value.Values.ToList())
- {
- if (itemsToRemove.Contains(wItem.ITEM_ID))
- {
- client.Warehouse.ClientItems[warehouse.Key].Remove(wItem.UID);
- Console.WriteLine($"Removed item warehouse With ID: {wItem.ITEM_ID}", ConsoleColor.DarkRed);
- }
- }
- }
- foreach (var invItem in client.Inventory.ClientItems.Values.ToList())
- {
- if (itemsToRemove.Contains(invItem.ITEM_ID))
- {
- client.Inventory.ClientItems.Remove(invItem.UID);
- Console.WriteLine($"Removed item Inventory with ID: {invItem.ITEM_ID}", ConsoleColor.DarkRed);
- }
- }
- Database.ServerDatabase.SaveClientItems(client);
- Console.WriteLine("Done Restart Items", ConsoleColor.DarkRed);
- }));
- }
- Task.WaitAll(tasks.ToArray());
- string removedItemsFilePath = Path.Combine(removedItemsPath, "removed_item_ids.txt");
- using (StreamWriter writer = new StreamWriter(removedItemsFilePath))
- {
- foreach (var id in removedItemIds)
- {
- writer.WriteLine(id);
- }
- }
- break;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement