private StatusObj getStatus() { string res = null; //POST Variables byte[] data = Encoding.ASCII.GetBytes("sessionid=" + Uri.UnescapeDataString(sessionid) + "&logpos=" + logpos + "&version=" + version); //Init var request = CreateSteamRequest(baseTradeURL + "tradestatus", "POST"); //Headers request.ContentLength = data.Length; //Write it Stream poot = request.GetRequestStream(); poot.Write(data, 0, data.Length); HttpWebResponse response = request.GetResponse() as HttpWebResponse; Stream str = response.GetResponseStream(); StreamReader reader = new StreamReader(str); res = reader.ReadToEnd(); StatusObj statusJSON = JsonConvert.DeserializeObject <StatusObj>(res); return(statusJSON); }
/** * * Trade Action ID's * * 0 = Add item (itemid = "assetid") * 1 = remove item (itemid = "assetid") * 2 = Toggle ready * 3 = Toggle not ready * 4 * 5 * 6 * 7 = Chat (message = "text") * */ public void poll() { StatusObj status = getStatus(); try{ if (NumEvents != status.events.Length) { NumLoops = status.events.Length - NumEvents; NumEvents = status.events.Length; for (int i = NumLoops; i > 0; i--) { int EventID; if (NumLoops == 1) { EventID = NumEvents - 1; } else { EventID = NumEvents - i; } bool isBot = status.events[EventID].steamid != otherSID.ConvertToUInt64().ToString(); var person = (status.events[EventID].steamid == otherSID.ConvertToUInt64().ToString()) ? ("Them") : ("Me"); //Print Statuses to console switch (status.events[EventID].action) { case 0: Console.WriteLine("[TradeSystem][" + person + "] Added Item: " + status.events[EventID].assetid); break; case 1: Console.WriteLine("[TradeSystem][" + person + "] Removed Item: " + status.events[EventID].assetid); break; case 2: Console.WriteLine("[TradeSystem][" + person + "] set ready."); if (!isBot) { Console.WriteLine("[TradeSystem] Accepting Trade."); setReady(true); } break; case 3: Console.WriteLine("[TradeSystem][" + person + "] set not ready."); if (!isBot) { Console.WriteLine("[TradeSystem] Refusing Trade."); setReady(false); } break; case 4: Console.WriteLine("[TradeSystem][" + person + "] Accepting"); if (!isBot) { //Accept It dynamic js = acceptTrade(); if (js.success == true) { printConsole("[TradeSystem] Trade was successfull! Resetting System...", ConsoleColor.Green); } else { printConsole("[TradeSystem] Poo! Trade might of Failed :C Well, resetting anyway...", ConsoleColor.Red); } cleanTrade(); } break; case 7: Console.WriteLine("[TradeSystem][" + person + "] Chat: " + status.events[EventID].text); if (!isBot) { if (status.events[EventID].text == "/dump") { doAdump(); } } break; default: Console.WriteLine("[TradeSystem][" + person + "] Unknown Event ID: " + status.events[EventID].action); break; } } } }catch (Exception) { exc++; printConsole("Exception while getting status. Count: " + exc, ConsoleColor.DarkYellow); if (exc == 5) { printConsole("[TradeSystem] 5th Exception, Disconnecting.", ConsoleColor.Red); cleanTrade(); exc = 0; } return; } //Update Local Variables OtherReady = status.them.ready == 1 ? true : false; MeReady = status.me.ready == 1 ? true : false; //Update version if (status.newversion) { this.version = status.version; this.logpos = status.logpos; } }