public async Task <EResult> Connect() { steamClient.Connect(); isRunning = true; var result = EResult.OK; #pragma warning disable CS4014 Task.Run(() => { while (isRunning) { manager.RunWaitCallbacks(TimeSpan.FromSeconds(1)); } }); #pragma warning restore CS4014 await Task.Run(() => { onConnectedEvent.WaitOne(10000); if (onConnectedResult != EResult.OK) { isConnected = false; result = onConnectedResult; } else { isConnected = true; } }); return(result); }
public SteamClient(SteamCredentials credentials, SteamAuthenticationCodesProvider codesProvider, SteamAuthenticationFilesProvider authenticationProvider) { Credentials = credentials ?? throw new ArgumentNullException(nameof(credentials)); _codesProvider = codesProvider; _authenticationProvider = authenticationProvider; InternalClient = new SteamKit.SteamClient(); _cancellationTokenSource = new CancellationTokenSource(); CallbackManager = new SteamKit.CallbackManager(InternalClient); _steamUser = InternalClient.GetHandler <SteamKit.SteamUser>(); _steamApps = InternalClient.GetHandler <SteamKit.SteamApps>(); Task.Run(async() => await CallbackManagerHandler()); CallbackManager.Subscribe <SteamKit.SteamClient.ConnectedCallback>(OnConnected); CallbackManager.Subscribe <SteamKit.SteamClient.DisconnectedCallback>(OnDisconnected); CallbackManager.Subscribe <SteamKit.SteamUser.LoggedOnCallback>(OnLoggedOn); CallbackManager.Subscribe <SteamKit.SteamUser.LoggedOffCallback>(OnLoggedOff); CallbackManager.Subscribe <SteamKit.SteamApps.LicenseListCallback>(OnLicenseList); CallbackManager.Subscribe <SteamKit.SteamUser.UpdateMachineAuthCallback>(OnMachineAuth); CallbackManager.Subscribe <SteamKit.SteamUser.LoginKeyCallback>(OnLoginKey); InternalClient.Connect(); }
public void LogIn(string username, string password) { Username = username; Password = password; client = new SK.SteamClient(); CurrentUser = new SteamUser(); manager = new SK.CallbackManager(client); steamUser = client.GetHandler <SK.SteamUser>(); community = client.GetHandler <SK.SteamFriends>(); manager.Subscribe <SK.SteamClient.ConnectedCallback>(OnConnected); manager.Subscribe <SK.SteamClient.DisconnectedCallback>(OnDisconnected); manager.Subscribe <SK.SteamUser.LoggedOnCallback>(OnLoggedOn); manager.Subscribe <SK.SteamUser.LoggedOffCallback>(OnLoggedOff); manager.Subscribe <SK.SteamUser.AccountInfoCallback>(OnAccountInfo); manager.Subscribe <SK.SteamFriends.FriendsListCallback>(OnCommunityLoaded); manager.Subscribe <SK.SteamFriends.PersonaStateCallback>(OnPersonaState); manager.Subscribe <SK.SteamFriends.FriendAddedCallback>(OnFriendAdded); IsConnected = true; client.Connect(); Task.Run(() => { while (IsConnected) { manager.RunWaitCallbacks(TimeSpan.FromSeconds(1)); } }); }
private void OnDisconnected(SteamClient.DisconnectedCallback obj) { Console.WriteLine("[Steam] Disconnected from steam!"); // Console.WriteLine(Environment.StackTrace); Connected = false; if (!obj.UserInitiated) { Client.Connect(); } else { KeepAlive = false; } }
public void ConnectBot(BotManager managerBot) { botManager = managerBot; botManager.UpdateBotState(EBotState.Worked); waitingCallbacksCancellationSource = new CancellationTokenSource(); Task.Run(() => WaitCallbacks(), waitingCallbacksCancellationSource.Token); botActionsCancellationSource = new CancellationTokenSource(); gameConnectedTask = new TaskCompletionSource <bool>(); botActionsTaskQueue = new Queue <Task> (); botActionsTaskQueue.Enqueue(gameConnectedTask.Task); logger.Info("Connecting to SteamClient..."); steamClient.Connect(); }
public void Connect() { // create our steamclient instance _steamClient = new SteamKit2.SteamClient(); // create the callback manager which will route callbacks to function calls _manager = new CallbackManager(_steamClient); // get the steamuser handler, which is used for logging on after successfully connecting _steamUser = _steamClient.GetHandler <SteamUser>(); _steamApps = _steamClient.GetHandler <SteamApps>(); _steamFriends = _steamClient.GetHandler <SteamFriends>(); // register a few callbacks we're interested in // these are registered upon creation to a callback manager, which will then route the callbacks // to the functions specified _manager.Subscribe <SteamKit2.SteamClient.ConnectedCallback>(OnConnected); _manager.Subscribe <SteamKit2.SteamClient.DisconnectedCallback>(OnDisconnected); _manager.Subscribe <SteamUser.LoggedOnCallback>(OnLoggedOn); _manager.Subscribe <SteamUser.LoggedOffCallback>(OnLoggedOff); _manager.Subscribe <SteamApps.AppOwnershipTicketCallback>(OnAppOwnershipTicketCallback); _manager.Subscribe <SteamApps.GameConnectTokensCallback>(OnGameConnectTokens); _steamClient.AddHandler(new Handler <SteamPlayer>(OnMessage)); _isRunning = true; ConsoleSystem.Log("Connecting to Steam..."); // initiate the connection _steamClient.Connect(); // create our callback handling loop while (_isRunning) { // in order for the callbacks to get routed, they need to be handled by the manager _manager.RunWaitCallbacks(TimeSpan.FromSeconds(1)); } }