Advertisement
Guest User

SteamBot - Internal Server Error

a guest
Mar 28th, 2015
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.09 KB | None | 0 0
  1. using Newtonsoft.Json;
  2. using SteamKit2;
  3. using SteamTrade;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11.  
  12. namespace SteamBot
  13. {
  14.     public class FileWatcher
  15.     {
  16.         private FileSystemWatcher fileSystemWatcher;
  17.         private string FileToWatch = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "TradeRequests";
  18.  
  19.         private Bot Bot;
  20.         private Log Log;
  21.         private SteamWeb SteamWeb;
  22.  
  23.         public FileWatcher(Bot Bot, Log Log, SteamWeb SteamWeb)
  24.         {
  25.             this.Bot = Bot;
  26.             this.Log = Log;
  27.             this.SteamWeb = SteamWeb;
  28.             fileSystemWatcher = new FileSystemWatcher(FileToWatch);
  29.             fileSystemWatcher.EnableRaisingEvents = true;
  30.  
  31.             // Instruct the file system watcher to call the FileCreated method
  32.             // when there are files created at the folder.
  33.             fileSystemWatcher.Created += new FileSystemEventHandler(FileCreated);
  34.         }
  35.  
  36.         public void FileCreated(Object Sender, FileSystemEventArgs Event)
  37.         {
  38.  
  39.             if (Event.Name.StartsWith("Trade-Request-"))
  40.             {
  41.                 SteamBot.TradeRequest.TradeRequestOffer Trade = JsonConvert.DeserializeObject<SteamBot.TradeRequest.TradeRequestOffer>(File.ReadAllText(Event.FullPath));
  42.                 Console.WriteLine(Trade.SteamID);
  43.  
  44.                 // creating a new trade offer with token
  45.                 SteamID TradeUser = new SteamID(Trade.SteamID);
  46.                 var TradeOffer = Bot.NewTradeOffer(TradeUser);
  47.                 //offer.Items.AddMyItem(0, 0, 0);
  48.  
  49.                 List<long> contextId = new List<long>();
  50.                 contextId.Add(2);
  51.                 GenericInventory TradeInventory = new GenericInventory(SteamWeb);
  52.                 TradeInventory.load(730, contextId, Trade.SteamID);
  53.                 List<ulong> itemsWanted = new List<ulong>();
  54.                 foreach (int assetId in Trade.ItemIDs)
  55.                 {
  56.                     itemsWanted.Add(Convert.ToUInt64(assetId));
  57.                 }
  58.  
  59.                 foreach (GenericInventory.Item Item in TradeInventory.items.Values)
  60.                 {
  61.                     if (itemsWanted.Contains(Item.assetid)) {
  62.                         TradeOffer.Items.AddTheirItem(730, 2, Convert.ToInt64(Item.assetid));
  63.                         Log.Warn("Added item: " + TradeInventory.getDescription(Item.assetid).name);
  64.                     }
  65.                 }
  66.                 Log.Warn("Finished adding items...");
  67.                 if (TradeOffer.Items.NewVersion)
  68.                 {
  69.                     string newOfferId;
  70.                     Log.Warn("Created offer id.");
  71.                     // "token" should be replaced with the actual token from the other user
  72.                     if (TradeOffer.SendWithToken(out newOfferId, Trade.SteamToken))
  73.                     {
  74.                         Log.Success("Trade offer sent : Offer ID " + newOfferId);
  75.                     }
  76.                 }
  77.  
  78.  
  79.             }
  80.  
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement