SteamBot.Trade.Poll C# (CSharp) Method

Poll() public method

public Poll ( ) : void
return void
		public void Poll () {
			lock (pollLock2) {
				if (!tradeStarted) {
					tradeStarted = true;
					TradeStart = DateTime.Now;
					LastAction = DateTime.Now;
				}


				StatusObj status = GetStatus();
				bool isBot = true;

				if (status != null && status.events != null) {
					if (lastEvent < status.events.Length) {
						for (; lastEvent < status.events.Length; lastEvent++) {
							TradeEvent evt = status.events[lastEvent];
							isBot = evt.steamid != otherSID.ConvertToUInt64().ToString();

							switch (evt.action) {
								case 0:
									trades[isBot ? 0 : 1].Add(evt.assetid);
									Inventory.Item item = inventories[isBot ? 0 : 1].GetItem(evt.assetid);
									Otrades[isBot ? 0 : 1].Add(item.OriginalId);
									if (!isBot) {
										ItemInfo schemaItem = Util.getItemInfo(item.Defindex);
										OnUserAddItem(schemaItem, item);
									}
									break;
								case 1:
									trades[isBot ? 0 : 1].Remove(evt.assetid);
									Inventory.Item item2 = inventories[isBot ? 0 : 1].GetItem(evt.assetid);
									Otrades[isBot ? 0 : 1].Add(item2.OriginalId);
									if (!isBot) {
										ItemInfo schemaItem = Util.getItemInfo(item2.Defindex);
										OnUserRemoveItem(schemaItem, item2);
									}
									break;
								case 2:
									if (!isBot) {
										OtherReady = true;
										OnUserSetReady(true);
									} else {
										MeReady = true;
									}
									break;
								case 3:
									if (!isBot) {
										OtherReady = false;
										OnUserSetReady(false);
									} else {
										MeReady = false;
									}
									break;
								case 4:
									if (!isBot) {
										OnUserAccept();
									}
									break;
								case 7:
									if (!isBot) {
										OnMessage(evt.text);
									}
									break;
								default:
									PrintConsole("Unknown Event ID: " + evt.action, ConsoleColor.Red);
									break;
							}

							if (!isBot)
								LastAction = DateTime.Now;
						}

					} else {
						// check if the user is AFK
						var now = DateTime.Now;

						DateTime actionTimeout = LastAction.AddSeconds(MaximumActionGap);
						int untilActionTimeout = (int) Math.Round((actionTimeout - now).TotalSeconds);

						DateTime tradeTimeout = TradeStart.AddSeconds(MaximumTradeTime);
						int untilTradeTimeout = (int) Math.Round((tradeTimeout - now).TotalSeconds);

						if (untilActionTimeout <= 0 || untilTradeTimeout <= 0) {
							if (OnTimeout != null)
								OnTimeout();
						} else if (untilActionTimeout <= 20 && untilActionTimeout % 5 == 0) {
							SendMessage("Are You AFK? The trade will be canceled in " + untilActionTimeout + " seconds if you don't do something.");
						}
					}
				} else {
					if (status.trade_status == 3) {
						//Other user cancelled
						OnError(2);
					} else if (status.trade_status == 4) {
						//Other user timed out, unlikely as we have a built-in timeout
						OnError(4);
					} else if (status.trade_status == 5) {
						//Trade failed
						OnError(5);
					} else if (status.trade_status == 1) {
						//Success
						OnComplete();
					} else if (exc++ > 3) {
						//More than 3 exceptions, something went wrong :/
						OnError(1);
					}
				}

				// Update Local Variables
				if (status.them != null) {
					OtherReady = status.them.ready == 1 ? true : false;
					MeReady = status.me.ready == 1 ? true : false;
				}


				// Update version
				if (status.newversion) {
					version = status.version;
					OnNewVersion();
				}

				if (status.logpos != 0) {
					logpos = status.logpos;
				}
			}
		}