void CheckTradeTimeout(Trade trade) { var now = DateTime.Now; DateTime actionTimeout = lastOtherActionTime.AddSeconds(MaxActionGapSec); int untilActionTimeout = (int)Math.Round((actionTimeout - now).TotalSeconds); DebugPrint(String.Format("{0} {1}", actionTimeout, untilActionTimeout)); DateTime tradeTimeout = tradeStartTime.AddSeconds(MaxTradeTimeSec); int untilTradeTimeout = (int)Math.Round((tradeTimeout - now).TotalSeconds); if (untilActionTimeout <= 0 || untilTradeTimeout <= 0) { // stop thread IsTradeThreadRunning = false; DebugPrint("timed out..."); if (OnTimeout != null) { OnTimeout(this, null); } trade.CancelTrade(); } else if (untilActionTimeout <= 20 && untilActionTimeout % 10 == 0) { trade.SendMessage("Are You AFK? The trade will be canceled in " + untilActionTimeout + " seconds if you don't do something."); } }
private bool CheckTradeTimeout(Trade trade) { var now = DateTime.Now; DateTime actionTimeout = lastOtherActionTime.AddSeconds(MaxActionGapSec); int untilActionTimeout = (int)Math.Round((actionTimeout - now).TotalSeconds); DebugPrint(String.Format("{0} {1}", actionTimeout, untilActionTimeout)); DateTime tradeTimeout = tradeStartTime.AddSeconds(MaxTradeTimeSec); int untilTradeTimeout = (int)Math.Round((tradeTimeout - now).TotalSeconds); double secsSinceLastTimeoutMessage = (now - lastTimeoutMessage).TotalSeconds; if (untilActionTimeout <= 0 || untilTradeTimeout <= 0) { DebugPrint("timed out..."); if (OnTimeout != null) { OnTimeout(this, null); } trade.CancelTrade(); return(true); } else if (untilActionTimeout <= 20 && secsSinceLastTimeoutMessage >= 10) { trade.SendMessage("Are You AFK? The trade will be canceled in " + untilActionTimeout + " seconds if you don't do something."); lastTimeoutMessage = now; } return(false); }
private bool CheckTradeTimeout(Trade trade) { // User has accepted the trade. Disregard time out. if (trade.OtherUserAccepted) { return(false); } var now = DateTime.Now; DateTime actionTimeout = _lastOtherActionTime.AddSeconds(MaxActionGapSec); int untilActionTimeout = (int)Math.Round((actionTimeout - now).TotalSeconds); DebugPrint(string.Format("{0} {1}", actionTimeout, untilActionTimeout)); DateTime tradeTimeout = _tradeStartTime.AddSeconds(MaxTradeTimeSec); int untilTradeTimeout = (int)Math.Round((tradeTimeout - now).TotalSeconds); double secsSinceLastTimeoutMessage = (now - _lastTimeoutMessage).TotalSeconds; if (untilActionTimeout <= 0 || untilTradeTimeout <= 0) { DebugPrint("Trade timed out..."); if (OnTimeout != null) { OnTimeout(this, null); } trade.CancelTrade(); return(true); } else if (untilActionTimeout <= 30 && secsSinceLastTimeoutMessage >= 10) { try { trade.SendMessage("Are you still there? The trade will be canceled in " + untilActionTimeout + " seconds if you do not respond."); } catch { } _lastTimeoutMessage = now; } return(false); }
private bool CheckTradeTimeout(Trade trade) { // User has accepted the trade. Disregard time out. if (trade.OtherUserAccepted) return false; var now = DateTime.Now; DateTime actionTimeout = lastOtherActionTime.AddSeconds (MaxActionGapSec); int untilActionTimeout = (int)Math.Round ((actionTimeout - now).TotalSeconds); DebugPrint (String.Format ("{0} {1}", actionTimeout, untilActionTimeout)); DateTime tradeTimeout = tradeStartTime.AddSeconds (MaxTradeTimeSec); int untilTradeTimeout = (int)Math.Round ((tradeTimeout - now).TotalSeconds); double secsSinceLastTimeoutMessage = (now - lastTimeoutMessage).TotalSeconds; if (untilActionTimeout <= 0 || untilTradeTimeout <= 0) { DebugPrint ("timed out..."); if (OnTimeout != null) { OnTimeout (this, null); } trade.CancelTrade (); return true; } else if (untilActionTimeout <= 20 && secsSinceLastTimeoutMessage >= 10) { try { trade.SendMessage("Are You AFK? The trade will be canceled in " + untilActionTimeout + " seconds if you don't do something."); } catch { } lastTimeoutMessage = now; } return false; }
private void StartTradeThread() { // initialize data to use in thread tradeStartTime = DateTime.Now; lastOtherActionTime = DateTime.Now; var pollThread = new Thread(() => { IsTradeThreadRunning = true; Console.WriteLine("Trade thread starting."); // main thread loop for polling while (IsTradeThreadRunning) { Thread.Sleep(TradePollingInterval); try { bool action = trade.Poll(); if (action) { lastOtherActionTime = DateTime.Now; } if (trade.OtherUserCancelled) { IsTradeThreadRunning = false; try { trade.CancelTrade(); } catch (Exception) { // ignore. possibly log. We don't care if the Cancel web command fails here we just want // to fire the OnClose event. DebugPrint("[TRADEMANAGER] error trying to cancel from poll thread"); } } //CheckTradeTimeout (trade); } catch (Exception ex) { // TODO: find a new way to do this w/o the trade events // if (OnError != null) // OnError ("Error Polling Trade: " + e); // ok then we should stop polling... //IsTradeThreadRunning = true; Console.WriteLine("[TRADEMANAGER] general error caught: " + ex); } } DebugPrint("Trade thread shutting down."); if (OnTradeEnded != null) { OnTradeEnded(this, null); } }); pollThread.Start(); }