/// <summary> /// This updates the trade. This is called at an interval of a /// default of 800ms, not including the execution time of the /// method itself. /// </summary> /// <returns><c>true</c> if the other trade partner performed an action; otherwise <c>false</c>.</returns> public bool Poll() { bool otherDidSomething = false; if (!TradeStarted) { tradeStarted = true; // since there is no feedback to let us know that the trade // is fully initialized we assume that it is when we start polling. if (OnAfterInit != null) { OnAfterInit(); } } TradeStatus status = session.GetStatus(); if (status == null) { throw new TradeException("The web command to get the trade status failed."); } switch (status.trade_status) { // Nothing happened. i.e. trade hasn't closed yet. case 0: break; // Successful trade case 1: HasTradeCompletedOk = true; return(otherDidSomething); // All other known values (3, 4) correspond to trades closing. default: if (OnError != null) { OnError("Trade was closed by other user. Trade status: " + status.trade_status); } OtherUserCancelled = true; return(otherDidSomething); } if (status.newversion) { // handle item adding and removing session.Version = status.version; TradeEvent trdEvent = status.GetLastEvent(); TradeEventType actionType = (TradeEventType)trdEvent.action; HandleTradeVersionChange(status); return(true); } else if (status.version > session.Version) { // oh crap! we missed a version update abort so we don't get // scammed. if we could get what steam thinks what's in the // trade then this wouldn't be an issue. but we can only get // that when we see newversion == true throw new TradeException("The trade version does not match. Aborting."); } var events = status.GetAllEvents(); foreach (var tradeEvent in events) { if (eventList.Contains(tradeEvent)) { continue; } //add event to processed list, as we are taking care of this event now eventList.Add(tradeEvent); bool isBot = tradeEvent.steamid == MySteamId.ConvertToUInt64().ToString(); // dont process if this is something the bot did if (isBot) { continue; } otherDidSomething = true; /* Trade Action ID's * 0 = Add item (itemid = "assetid") * 1 = remove item (itemid = "assetid") * 2 = Toggle ready * 3 = Toggle not ready * 4 = ? * 5 = ? - maybe some sort of cancel * 6 = ? * 7 = Chat (message = "text") */ switch ((TradeEventType)tradeEvent.action) { case TradeEventType.ItemAdded: FireOnUserAddItem(tradeEvent); break; case TradeEventType.ItemRemoved: FireOnUserRemoveItem(tradeEvent); break; case TradeEventType.UserSetReady: otherIsReady = true; OnUserSetReady(true); break; case TradeEventType.UserSetUnReady: otherIsReady = false; OnUserSetReady(false); break; case TradeEventType.UserAccept: OnUserAccept(); break; case TradeEventType.UserChat: OnMessage(tradeEvent.text); break; default: // Todo: add an OnWarning or similar event if (OnError != null) { OnError("Unknown Event ID: " + tradeEvent.action); } break; } } // Update Local Variables if (status.them != null) { otherIsReady = status.them.ready == 1; meIsReady = status.me.ready == 1; } if (status.logpos != 0) { session.LogPos = status.logpos; } return(otherDidSomething); }