public async Task Shutdown() { isRunning = false; while (Client.IsConnected) { callbacks.RunCallbacks(); await Task.Delay(50).ConfigureAwait(false); } }
private void BackgroundWorkerOnDoWork(object sender, DoWorkEventArgs doWorkEventArgs) { while (!botThread.CancellationPending) { try { steamCallbackManager.RunCallbacks(); if (tradeOfferManager != null) { tradeOfferManager.HandleNextPendingTradeOfferUpdate(); } Thread.Sleep(1); } catch (WebException e) { Console.WriteLine("URI: {0} >> {1}", (e.Response != null && e.Response.ResponseUri != null ? e.Response.ResponseUri.ToString() : "unknown"), e.ToString()); System.Threading.Thread.Sleep(45000);//Steam is down, retry in 45 seconds. } catch (Exception e) { Console.WriteLine("Unhandled exception occurred in bot: " + e); } } }
public async Task <bool> LoginPrompt(bool background = false, string username = null, string password = null, string authCode = null, string emailCode = null) { UserConfig.RegisterConfig("steam"); this.background = background; this.username = username; this.password = password; this.authCode = authCode; this.emailCode = emailCode; client = new SteamClient(); manager = new CallbackManager(client); user = client.GetHandler <SteamUser>(); friends = client.GetHandler <SteamFriends>(); manager.Subscribe <SteamClient.ConnectedCallback>(OnConnected); manager.Subscribe <SteamClient.DisconnectedCallback>(OnDisconnected); manager.Subscribe <SteamUser.LoggedOnCallback>(OnLoggedOn); manager.Subscribe <SteamUser.LoggedOffCallback>(OnLoggedOff); manager.Subscribe <SteamUser.LoginKeyCallback>(OnLoginKey); //manager.Subscribe<SteamFriends.FriendsListCallback>(OnFriendList); manager.Subscribe <SteamUnifiedMessages.ServiceMethodResponse>(OnMethodResponse); unifiedMessages = client.GetHandler <SteamUnifiedMessages>(); servicePlayer = unifiedMessages.CreateService <IPlayer>(); loginStatus = LOGIN_STATUS.AWAITING; Debug.WriteLine("Connecting to steam.."); client.Connect(); cancelCallbackTok = new CancellationTokenSource(); Task callbackTask = new Task(() => { while (!cancelCallbackTok.IsCancellationRequested) { try { manager.RunCallbacks(); } catch (Exception e) { Console.WriteLine("Error! : " + e.Message); } } }, cancelCallbackTok.Token); callbackTask.Start(); return(await Task <bool> .Run(() => { while (loginStatus == LOGIN_STATUS.AWAITING) { } return loginStatus == LOGIN_STATUS.SUCCESS; })); }
/// <summary> /// This method will check for any Callbacks to fire /// </summary> public override void tick() { try { manager.RunCallbacks(); } catch (Exception ex) { Console.WriteLine("Exception Handled: {0}", ex); } }
// Handler public void Handle() { if ((DateTime.Now - LastActionTime).TotalSeconds > 10 && !IsDone) { IsSuccess = false; IsDone = true; Logger.Log("Action timed out"); return; } CallbackManager.RunCallbacks(); }
public void Disconnect(bool sendLogOff = true) { if (sendLogOff) { steamUser.LogOff(); } steamClient.Disconnect(); bConnected = false; bConnecting = false; bAborted = true; // flush callbacks callbacks.RunCallbacks(); }
void PostAndRunCallback(CallbackMsg callback) { client.PostCallback(callback); mgr.RunCallbacks(); }
public void Tick(long Tick) { callbackManager.RunCallbacks(); if (Tick % 20 == 0) { lock (actions) { var to_remove = new List <AccountDelayedAction>(); foreach (var action in actions) { if (--action.SecondsRemain <= 0) { action.Action.Invoke(); to_remove.Add(action); } } to_remove.ForEach((a) => actions.Remove(a)); } } if (!LoggedIn) { return; } if (!ProcessingAction) { lock (actionQueue) { if (actionQueue.Count != 0) { if (!GameRunning) { StartGame(); } if (GameInitalized) { var action = actionQueue.Peek(); lock (sendQueue) { if (action is ReportInfo) { var report = action as ReportInfo; sendQueue.Enqueue(new SendInfo() { Type = SendInfo.SendType.SteamGameCoordinator, Packet = new ClientGCMsgProtobuf <CMsgGCCStrike15_v2_ClientReportPlayer>((uint)ECsgoGCMsg.k_EMsgGCCStrike15_v2_ClientReportPlayer) { Body = { account_id = report.SteamID.AccountID, match_id = report.MatchID, rpt_aimbot = Convert.ToUInt32(report.AimHacking), rpt_wallhack = Convert.ToUInt32(report.WallHacking), rpt_speedhack = Convert.ToUInt32(report.OtherHacking), rpt_teamharm = Convert.ToUInt32(report.Griefing), rpt_textabuse = Convert.ToUInt32(report.AbusiveText), rpt_voiceabuse = Convert.ToUInt32(report.AbusiveVoice) } } }); } else if (action is CommendInfo) { var commend = action as CommendInfo; sendQueue.Enqueue(new SendInfo() { Type = SendInfo.SendType.SteamGameCoordinator, Packet = new ClientGCMsgProtobuf <CMsgGCCStrike15_v2_ClientCommendPlayer>((uint)ECsgoGCMsg.k_EMsgGCCStrike15_v2_ClientCommendPlayer) { Body = { account_id = commend.SteamID.AccountID, match_id = commend.MatchID, commendation = new PlayerCommendationInfo { cmd_friendly = Convert.ToUInt32(commend.Friendly), cmd_teaching = Convert.ToUInt32(commend.GoodTeacher), cmd_leader = Convert.ToUInt32(commend.GoodLeader) }, tokens = 0 } } }); } else if (action is GetLiveGameInfo) { sendQueue.Enqueue(new SendInfo() { Type = SendInfo.SendType.SteamGameCoordinator, Packet = new ClientGCMsgProtobuf <CMsgGCCStrike15_v2_MatchListRequestLiveGameForUser>((uint)ECsgoGCMsg.k_EMsgGCCStrike15_v2_MatchListRequestLiveGameForUser) { Body = { accountid = action.SteamID.AccountID } } }); } } FailActionCounter = 60 * 20; ProcessingAction = true; } } else if (Program.IsOnlineTimeRange()) { if (!GameRunning) { StartGame(); } } else if (GameRunning) { StopGame(); } } } else if (FailActionCounter > -1 && --FailActionCounter <= 0) { Logger.Error(PREFIX + "No action response recieved.Dropping the failed action info."); FailActionCounter = -1; ProcessingAction = false; lock (actionQueue) { try { actionQueue.Dequeue(); } catch (Exception e) { Logger.Error(e); } } } }