This handler handles all user log on/log off related actions and callbacks.
Inheritance: ClientMsgHandler
Beispiel #1
0
        public SteamBot(string newUser, string newPass)
        {
            // Bot user and password
            user = newUser;
            pass = newPass;

            // create our steamclient instance
            steamClient = new SteamClient( System.Net.Sockets.ProtocolType.Tcp );
            // 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>();
            // get the steam friends handler, which is used for interacting with friends on the network after logging on
            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
            new Callback<SteamClient.ConnectedCallback>( OnConnected, manager );
            new Callback<SteamClient.DisconnectedCallback>( OnDisconnected, manager );

            new Callback<SteamUser.LoggedOnCallback>( OnLoggedOn, manager );

            // we use the following callbacks for friends related activities
            new Callback<SteamUser.AccountInfoCallback>( OnAccountInfo, manager );
            new Callback<SteamFriends.FriendsListCallback>( OnFriendsList, manager );
            new Callback<SteamFriends.FriendMsgCallback> (OnFriendMessage, manager);

            // initiate the connection
            steamClient.Connect();

            // Make sure the main loop runs
            isRunning = true;
        }
Beispiel #2
0
		public Bot(Configuration.BotInfo config, string apiKey, bool debug = false) {
			sql = new Sql();

			Username = config.Username;
			Password = config.Password;
			DisplayName = config.DisplayName;
			Admins = config.Admins;
			id = config.Id;
			this.apiKey = apiKey;

			TradeListener = new ScrapTrade(this);
			TradeListenerInternal = new ExchangeTrade(this);
			TradeListenerAdmin = new AdminTrade(this);

			List<object[]> result = sql.query("SELECT text, response FROM responses");
			foreach (object[] row in result) {
				responses.Add(((string) row[0]).ToLower(), (string) row[1]);
			}

			// Hacking around https
			ServicePointManager.ServerCertificateValidationCallback += SteamWeb.ValidateRemoteCertificate;

			SteamClient = new SteamClient();
			SteamTrade = SteamClient.GetHandler<SteamTrading>();
			SteamUser = SteamClient.GetHandler<SteamUser>();
			SteamFriends = SteamClient.GetHandler<SteamFriends>();
			queueHandler = new QueueHandler(this);

			SteamClient.Connect();

			while (true) {
				Update();
			}
		}
Beispiel #3
0
        static void LogIn()
        {
            steamClient = new SteamClient();
            callbackManager = new CallbackManager(steamClient);
            steamUser = steamClient.GetHandler<SteamUser>();
            steamFriends = steamClient.GetHandler<SteamFriends>();
            steamTrading = steamClient.GetHandler<SteamTrading>();
            new Callback<SteamClient.ConnectedCallback>(OnConnect,callbackManager);
            new Callback<SteamUser.LoggedOnCallback>(OnLoggedOn, callbackManager);
            new Callback<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth, callbackManager);
            new Callback<SteamClient.DisconnectedCallback>(OnDisconnected, callbackManager);
            new Callback<SteamUser.AccountInfoCallback>(OnAccountInfo, callbackManager);
            new Callback<SteamFriends.FriendMsgCallback>(OnChatMessage, callbackManager);
            new Callback<SteamFriends.FriendsListCallback>(OnFriendInvite, callbackManager);
            new Callback<SteamTrading.TradeProposedCallback>(OnTradeOffer, callbackManager);
            new Callback<SteamTrading.SessionStartCallback>(OnTradeWindow, callbackManager);
            new Callback<SteamTrading.TradeResultCallback>(OnTradeResult, callbackManager);

            isRunning = true;

            Console.WriteLine("Attempting to connect to steam...");

            steamClient.Connect();

            while(isRunning)
            {
                callbackManager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
            }
            Console.ReadKey();
        }
        public static void OnMarketingMessage(SteamUser.MarketingMessageCallback callback)
        {
            foreach (var message in callback.Messages)
            {
                // TODO: Move this query outside this loop
                using (MySqlDataReader Reader = DbWorker.ExecuteReader("SELECT `ID` FROM `MarketingMessages` WHERE `ID` = @ID", new MySqlParameter("ID", message.ID)))
                {
                    if (Reader.Read())
                    {
                        continue;
                    }
                }

                if (message.Flags == EMarketingMessageFlags.None)
                {
                    IRC.SendMain("New marketing message:{0} {1}", Colors.DARK_BLUE, message.URL);
                }
                else
                {
                    IRC.SendMain("New marketing message:{0} {1} {2}({3})", Colors.DARK_BLUE, message.URL, Colors.DARK_GRAY, message.Flags.ToString().Replace("Platform", string.Empty));
                }

                DbWorker.ExecuteNonQuery("INSERT INTO `MarketingMessages` (`ID`, `Flags`) VALUES (@ID, @Flags)",
                                         new MySqlParameter("@ID", message.ID),
                                         new MySqlParameter("@Flags", message.Flags)
                );
            }
        }
Beispiel #5
0
        private static void Login()
        {
            steamClient = new SteamClient();
            callBackManager = new CallbackManager(steamClient);
            steamFriends = steamClient.GetHandler<SteamFriends>();
            steamUser = steamClient.GetHandler<SteamUser>();

            callBackManager.Subscribe<SteamClient.ConnectedCallback>(OnConnected);
            callBackManager.Subscribe<SteamUser.LoggedOnCallback>(OnLoggedIn);
            callBackManager.Subscribe<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth);
            callBackManager.Subscribe<SteamClient.DisconnectedCallback>(OnDisconnected);
            callBackManager.Subscribe<SteamFriends.FriendMsgCallback>(OnMsgRecieved);
            callBackManager.Subscribe<SteamUser.AccountInfoCallback>(OnAccountInfo);
            callBackManager.Subscribe<SteamFriends.FriendsListCallback>(OnFriendsList);
            callBackManager.Subscribe<SteamFriends.FriendAddedCallback>(OnFriendAdded);
            callBackManager.Subscribe<SteamFriends.PersonaStateCallback>(OnFriendPersonaChange);

            SteamDirectory.Initialize().Wait();
            steamClient.Connect();

            isRunning = true;

            while (isRunning)
            {
                callBackManager.RunWaitCallbacks(TimeSpan.FromSeconds(0.5));
            }

            Console.ReadKey();
        }
Beispiel #6
0
        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));
                }
            });
        }
Beispiel #7
0
        /// <summary>
        ///     Setup a new bot with some details.
        /// </summary>
        /// <param name="details"></param>
        /// <param name="extensions">any extensions you want on the state machine.</param>
        public LobbyBot(SteamUser.LogOnDetails details, params IExtension<States, Events>[] extensions)
        {
            reconnect = true;
            this.details = details;

            log = LogManager.GetLogger("LobbyBot " + details.Username);
            log.Debug("Initializing a new LobbyBot, username: " + details.Username);
            reconnectTimer.Elapsed += (sender, args) =>
            {
                reconnectTimer.Stop();
                fsm.Fire(Events.AttemptReconnect);
            };
            fsm = new ActiveStateMachine<States, Events>();
            foreach (var ext in extensions) fsm.AddExtension(ext);
            fsm.DefineHierarchyOn(States.Connecting)
                .WithHistoryType(HistoryType.None);
            fsm.DefineHierarchyOn(States.Connected)
                .WithHistoryType(HistoryType.None)
                .WithInitialSubState(States.Dota);
            fsm.DefineHierarchyOn(States.Dota)
                .WithHistoryType(HistoryType.None)
                .WithInitialSubState(States.DotaConnect)
                .WithSubState(States.DotaMenu)
                .WithSubState(States.DotaLobby);
            fsm.DefineHierarchyOn(States.Disconnected)
                .WithHistoryType(HistoryType.None)
                .WithInitialSubState(States.DisconnectNoRetry)
                .WithSubState(States.DisconnectRetry);
            fsm.DefineHierarchyOn(States.DotaLobby)
                .WithHistoryType(HistoryType.None);
            fsm.In(States.Connecting)
                .ExecuteOnEntry(InitAndConnect)
                .On(Events.Connected).Goto(States.Connected)
                .On(Events.Disconnected).Goto(States.DisconnectRetry)
                .On(Events.LogonFailSteamDown).Execute(SteamIsDown)
                .On(Events.LogonFailSteamGuard).Goto(States.DisconnectNoRetry) //.Execute(() => reconnect = false)
                .On(Events.LogonFailBadCreds).Goto(States.DisconnectNoRetry);
            fsm.In(States.Connected)
                .ExecuteOnExit(DisconnectAndCleanup)
                .On(Events.Disconnected).If(ShouldReconnect).Goto(States.Connecting)
                .Otherwise().Goto(States.Disconnected);
            fsm.In(States.Disconnected)
                .ExecuteOnEntry(DisconnectAndCleanup)
                .ExecuteOnExit(ClearReconnectTimer)
                .On(Events.AttemptReconnect).Goto(States.Connecting);
            fsm.In(States.DisconnectRetry)
                .ExecuteOnEntry(StartReconnectTimer);
            fsm.In(States.Dota)
                .ExecuteOnExit(DisconnectDota);
            fsm.In(States.DotaConnect)
                .ExecuteOnEntry(ConnectDota)
                .On(Events.DotaGCReady).Goto(States.DotaMenu);
            fsm.In(States.DotaMenu)
                .ExecuteOnEntry(SetOnlinePresence);
            fsm.In(States.DotaLobby)
                .ExecuteOnEntry(EnterLobbyChat)
                .ExecuteOnEntry(EnterBroadcastChannel)
                .On(Events.DotaLeftLobby).Goto(States.DotaMenu).Execute(LeaveChatChannel);
            fsm.Initialize(States.Connecting);
        }
        private static void OnAccountInfo(SteamUser.AccountInfoCallback callback)
        {
            Steam.Instance.Friends.SetPersonaState(EPersonaState.Busy);

            foreach (var chatRoom in Settings.Current.ChatRooms)
            {
                Steam.Instance.Friends.JoinChat(chatRoom);
            }
        }
Beispiel #9
0
        public static void Initialize( bool useUdp )
        {
            Console.WriteLine ("Server now running on: ");

            SteamClient = new SteamClient( useUdp ? ProtocolType.Udp : ProtocolType.Tcp );

            SteamFriends = SteamClient.GetHandler<SteamFriends>();
            SteamUser = SteamClient.GetHandler<SteamUser>();
        }
Beispiel #10
0
        public SteamConnection(IntPtr ic)
        {
            this.ic = ic;

            client = new SteamClient();

            friends = client.GetHandler<SteamFriends>();
            user = client.GetHandler<SteamUser>();
        }
Beispiel #11
0
        static void Main( string[] args )
        {
            // install our debug listeners for this example

            // install an instance of our custom listener
            DebugLog.AddListener( new MyListener() );

            // install a listener as an anonymous method
            // this call is commented as it would be redundant to install a second listener that also displays messages to the console
            // DebugLog.AddListener( ( category, msg ) => Console.WriteLine( "AnonymousMethod - {0}: {1}", category, msg ) );
            
            // Enable DebugLog in release builds
            DebugLog.Enabled = true;

            if ( args.Length < 2 )
            {
                Console.WriteLine( "Sample4: No username and password specified!" );
                return;
            }

            // save our logon details
            user = args[ 0 ];
            pass = args[ 1 ];

            // create our steamclient instance
            steamClient = new 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>();

            // 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
            new Callback<SteamClient.ConnectedCallback>( OnConnected, manager );
            new Callback<SteamClient.DisconnectedCallback>( OnDisconnected, manager );

            new Callback<SteamUser.LoggedOnCallback>( OnLoggedOn, manager );
            new Callback<SteamUser.LoggedOffCallback>( OnLoggedOff, manager );

            isRunning = true;

            Console.WriteLine( "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 ) );
            }
        }
Beispiel #12
0
		static void Main(string[] args) {
			// Print program information.
			Console.WriteLine("SteamIdler, 'run' games without steam.\n(C) No STEAMGUARD Support");

			// Check for username and password arguments from stdin.
			if (args.Length < 3) {
				// Print usage and quit.
				Console.WriteLine("usage: <username> <password> <appID> [...]");
				return;
			}

			// Set username and password from stdin.
			Username = args[0];
			Password = args[1];

			// Add all game application IDs to list.
			foreach (string GameAppID in args) {
				int AppID;

				if (int.TryParse(GameAppID, out AppID)) {
					AppIDs.Add(Convert.ToInt32(GameAppID));
				}
			}

			// Create SteamClient interface and CallbackManager.
			steamClient = new SteamClient(System.Net.Sockets.ProtocolType.Tcp);
			manager = new CallbackManager(steamClient);

			// Get the steamuser handler, which is used for logging on after successfully connecting.
			steamUser = steamClient.GetHandler<SteamUser>();

			// Get the steam friends handler, which is used for interacting with friends on the network after logging on.
			steamFriends = steamClient.GetHandler<SteamFriends>();

			// Register Steam callbacks.
			new Callback<SteamClient.ConnectedCallback>(OnConnected, manager);
			new Callback<SteamClient.DisconnectedCallback>(OnDisconnected, manager);
			new Callback<SteamUser.LoggedOnCallback>(OnLoggedOn, manager);
			new Callback<SteamUser.LoggedOffCallback>(OnLoggedOff, manager);
			new Callback<SteamUser.AccountInfoCallback>(OnAccountInfo, manager);

			// Set the program as running.
			Console.WriteLine(":: Connecting to Steam..");
			isRunning = true;

			// Connect to Steam.
			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));
			}
		}
Beispiel #13
0
        public Bot(Configuration.BotInfo config, string apiKey, bool debug = false)
        {
            Username     = config.Username;
            Password     = config.Password;
            DisplayName  = config.DisplayName;
            ChatResponse = config.ChatResponse;
            Admins       = config.Admins;
            this.apiKey  = apiKey;
            AuthCode     = null;

            TradeListener = new TradeEnterTradeListener(this);

            // Hacking around https
            ServicePointManager.ServerCertificateValidationCallback += SteamWeb.ValidateRemoteCertificate;

            SteamClient = new SteamClient();
            SteamTrade = SteamClient.GetHandler<SteamTrading>();
            SteamUser = SteamClient.GetHandler<SteamUser>();
            SteamFriends = SteamClient.GetHandler<SteamFriends>();

            SteamClient.Connect();

            Thread CallbackThread = new Thread(() => // Callback Handling
                       {
                while (true)
                {
                    CallbackMsg msg = SteamClient.WaitForCallback (true);
                    HandleSteamMessage (msg);
                }
            });

            new Thread(() => // Trade Polling if needed
                       {
                while (true)
                {
                    Thread.Sleep (800);
                    if (CurrentTrade != null)
                    {
                        try
                        {
                            CurrentTrade.Poll ();
                        }
                        catch (Exception e)
                        {
                            Console.Write ("Error polling the trade: ");
                            Console.WriteLine (e);
                        }
                    }
                }
            }).Start ();

            CallbackThread.Start();
            CallbackThread.Join();
        }
Beispiel #14
0
        private void OnLoggedOn(SteamUser.LoggedOnCallback callback)
        {
            if (callback.Result != EResult.OK)
            {
                return;
            }

            WebAPIUserNonce = callback.WebAPIUserNonce;

            TaskManager.Run(() => AuthenticateUser());
        }
Beispiel #15
0
        static void Main( string[] args )
        {
            if ( args.Length < 2 )
            {
                Console.WriteLine( "Sample8: No username and password specified!" );
                return;
            }

            // save our logon details
            user = args[0];
            pass = args[1];

            // create our steamclient instance
            steamClient = new 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>();

            // get the steam unified messages handler, which is used for sending and receiving responses from the unified service api
            steamUnifiedMessages = steamClient.GetHandler<SteamUnifiedMessages>();

            // we also want to create our local service interface, which will help us build requests to the unified api
            playerService = steamUnifiedMessages.CreateService<IPlayer>();


            // 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<SteamClient.ConnectedCallback>( OnConnected );
            manager.Subscribe<SteamClient.DisconnectedCallback>( OnDisconnected );

            manager.Subscribe<SteamUser.LoggedOnCallback>( OnLoggedOn );
            manager.Subscribe<SteamUser.LoggedOffCallback>( OnLoggedOff );

            // we use the following callbacks for unified service responses
            manager.Subscribe<SteamUnifiedMessages.ServiceMethodResponse>( OnMethodResponse );

            isRunning = true;

            Console.WriteLine( "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 ) );
            }
        }
Beispiel #16
0
        static void Main(string[] args)
        {
            Logger.filename = "RelayBot.log";
            log = Logger.GetLogger();

            steamClient = new SteamClient(System.Net.Sockets.ProtocolType.Tcp);
            manager = new CallbackManager(steamClient);

            steamUser = steamClient.GetHandler<SteamUser>();
            steamFriends = steamClient.GetHandler<SteamFriends>();

            bot = new Bot(steamUser, steamFriends, steamClient);

            manager.Subscribe<SteamClient.ConnectedCallback>(bot.OnConnected);
            manager.Subscribe<SteamClient.DisconnectedCallback>(bot.OnDisconnected);

            manager.Subscribe<SteamUser.LoggedOnCallback>(bot.OnLoggedOn);
            manager.Subscribe<SteamUser.LoggedOffCallback>(bot.OnLoggedOff);

            manager.Subscribe<SteamUser.AccountInfoCallback>(bot.OnAccountInfo);
            manager.Subscribe<SteamFriends.FriendsListCallback>(bot.OnFriendsList);
            manager.Subscribe<SteamFriends.FriendAddedCallback>(bot.OnFriendAdded);

            manager.Subscribe<SteamFriends.ChatInviteCallback>(bot.OnChatInvite);
            manager.Subscribe<SteamFriends.ChatEnterCallback>(bot.OnChatEnter);
            manager.Subscribe<SteamFriends.FriendMsgCallback>(bot.OnFriendMessage);

            manager.Subscribe<SteamFriends.ChatMsgCallback>(bot.OnChatroomMessage);
            manager.Subscribe<SteamFriends.ChatMemberInfoCallback>(bot.OnMemberInfo);

            manager.Subscribe<SteamUser.UpdateMachineAuthCallback>(bot.OnMachineAuth);

            bot.isRunning = true;

            log.Info("Connecting to Steam...");

            steamClient.Connect();

            //callback loop

            while (bot.isRunning)
            {
                try
                {
                    manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
                }
                catch (Exception e)
                {
                    Logger.filename = "RelayBot.log";
                    log.Error(String.Format("Caught exception: {0}\nMessage: {1}\nStack trace: {2}", e.GetType().ToString(), e.Message, e.StackTrace));
                }
            }
        }
Beispiel #17
0
        public Steam3Session( SteamUser.LogOnDetails details )
        {
            this.logonDetails = details;

            this.authenticatedUser = details.Username != null;
            this.credentials = new Credentials();
            this.bConnected = false;
            this.bConnecting = false;
            this.bAborted = false;
            this.seq = 0;

            this.AppTickets = new Dictionary<uint, byte[]>();
            this.AppTokens = new Dictionary<uint, ulong>();
            this.DepotKeys = new Dictionary<uint, byte[]>();
            this.CDNAuthTokens = new Dictionary<Tuple<uint, string>, SteamApps.CDNAuthTokenCallback>();
            this.AppInfo = new Dictionary<uint, SteamApps.PICSProductInfoCallback.PICSProductInfo>();
            this.PackageInfo = new Dictionary<uint, SteamApps.PICSProductInfoCallback.PICSProductInfo>();

            this.steamClient = new SteamClient();

            this.steamUser = this.steamClient.GetHandler<SteamUser>();
            this.steamApps = this.steamClient.GetHandler<SteamApps>();

            this.callbacks = new CallbackManager(this.steamClient);

            this.callbacks.Subscribe<SteamClient.ConnectedCallback>(ConnectedCallback);
            this.callbacks.Subscribe<SteamClient.DisconnectedCallback>(DisconnectedCallback);
            this.callbacks.Subscribe<SteamUser.LoggedOnCallback>(LogOnCallback);
            this.callbacks.Subscribe<SteamUser.SessionTokenCallback>(SessionTokenCallback);
            this.callbacks.Subscribe<SteamApps.LicenseListCallback>(LicenseListCallback);
            this.callbacks.Subscribe<SteamUser.UpdateMachineAuthCallback>(UpdateMachineAuthCallback);

            Console.Write( "Connecting to Steam3..." );

            if ( authenticatedUser )
            {
                FileInfo fi = new FileInfo(String.Format("{0}.sentryFile", logonDetails.Username));
                if (ConfigStore.TheConfig.SentryData != null && ConfigStore.TheConfig.SentryData.ContainsKey(logonDetails.Username))
                {
                    logonDetails.SentryFileHash = Util.SHAHash(ConfigStore.TheConfig.SentryData[logonDetails.Username]);
                }
                else if (fi.Exists && fi.Length > 0)
                {
                    var sentryData = File.ReadAllBytes(fi.FullName);
                    logonDetails.SentryFileHash = Util.SHAHash(sentryData);
                    ConfigStore.TheConfig.SentryData[logonDetails.Username] = sentryData;
                    ConfigStore.Save();
                }
            }

            Connect();
        }
Beispiel #18
0
        static void Main( string[] args )
        {
            if ( args.Length < 2 )
            {
                Console.WriteLine( "Sample3: No username and password specified!" );
                return;
            }

            // save our logon details
            user = args[ 0 ];
            pass = args[ 1 ];

            // create our steamclient instance
            steamClient = new SteamClient();

            // add our custom handler to our steamclient
            steamClient.AddHandler( new MyHandler() );

            // 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>();
            // now get an instance of our custom handler
            myHandler = steamClient.GetHandler<MyHandler>();

            // 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
            new Callback<SteamClient.ConnectedCallback>( OnConnected, manager );
            new Callback<SteamClient.DisconnectedCallback>( OnDisconnected, manager );

            new Callback<SteamUser.LoggedOnCallback>( OnLoggedOn, manager );
            new Callback<SteamUser.LoggedOffCallback>( OnLoggedOff, manager );

            // handle our own custom callback
            new Callback<MyHandler.MyCallback>( OnMyCallback, manager );

            isRunning = true;

            Console.WriteLine( "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 ) );
            }
        }
Beispiel #19
0
        static void Main( string[] args )
        {
            if ( args.Length < 2 )
            {
                Console.WriteLine( "Sample9: No username and password specified!" );
                return;
            }

            // save our logon details
            user = args[ 0 ];
            pass = args[ 1 ];

            // create our steamclient instance
            steamClient = new 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>();

            // get our steamapps handler, we'll use this as an example of how async jobs can be handled
            steamApps = steamClient.GetHandler<SteamApps>();

            // 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<SteamClient.ConnectedCallback>( OnConnected );
            manager.Subscribe<SteamClient.DisconnectedCallback>( OnDisconnected );

            manager.Subscribe<SteamUser.LoggedOnCallback>( OnLoggedOn );
            manager.Subscribe<SteamUser.LoggedOffCallback>( OnLoggedOff );

            // notice that we're not subscribing to the SteamApps.PICSProductInfoCallback callback here (or other SteamApps callbacks)
            // since this sample is using the async job directly, we no longer need to subscribe to the callback.
            // however, if we still wish to use callbacks (or have existing code which subscribes to callbacks, they will
            // continue to operate alongside direct async job handling. (i.e.: steamclient will still post callbacks for
            // any async jobs that are completed)

            isRunning = true;

            Console.WriteLine( "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 ) );
            }
        }
Beispiel #20
0
        private void OnWebAPIUserNonce(SteamUser.WebAPIUserNonceCallback callback)
        {
            if (callback.Result != EResult.OK)
            {
                Log.WriteWarn("WebAuth", "Unable to get user nonce: {0}", callback.Result);

                // TODO: Should keep trying?

                return;
            }

            WebAPIUserNonce = callback.Nonce;
        }
        void OnLoginKey(SteamUser.LoginKeyCallback callback)
        {
            string SessionID = WebHelpers.EncodeBase64(callback.UniqueID.ToString());

            using (dynamic userAuth = WebAPI.GetInterface("ISteamUserAuth"))
            {
                // generate an AES session key
                var sessionKey = CryptoHelper.GenerateRandomBlock(32);

                // rsa encrypt it with the public key for the universe we're on
                byte[] cryptedSessionKey = null;
                using (var rsa = new RSACrypto(KeyDictionary.GetPublicKey(Client.ConnectedUniverse)))
                {
                    cryptedSessionKey = rsa.Encrypt(sessionKey);
                }

                byte[] loginKey = new byte[20];
                Array.Copy(Encoding.ASCII.GetBytes(callback.LoginKey), loginKey, callback.LoginKey.Length);

                // AES encrypt the loginkey with our session key.
                byte[] cryptedLoginKey = CryptoHelper.SymmetricEncrypt(loginKey, sessionKey);

                KeyValue authResult = null;
                EResult result = EResult.OK;

                try
                {
                    authResult = userAuth.AuthenticateUser(
                        steamid: Client.SteamID.ConvertToUInt64(),
                        sessionkey: WebHelpers.UrlEncode(cryptedSessionKey),
                        encrypted_loginkey: WebHelpers.UrlEncode(cryptedLoginKey),
                        method: "POST"
                    );
                }
                catch (Exception)
                {
                    result = EResult.Fail;
                }

                Login.SessionId = SessionID;

                if (authResult != null)
                    Login.Token = authResult["token"].AsString();

                this.Client.PostCallback(new WebLoggedOnCallback()
                {
                    Result = result,
                    Login = Login
                });
            }
        }
Beispiel #22
0
        static void Main( string[] args )
        {
            if ( args.Length < 2 )
            {
                Console.WriteLine( "Sample5: No username and password specified!" );
                return;
            }

            // save our logon details
            user = args[ 0 ];
            pass = args[ 1 ];

            // create our steamclient instance
            steamClient = new SteamClient( System.Net.Sockets.ProtocolType.Tcp );
            // 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>();
            // get the steam friends handler, which is used for interacting with friends on the network after logging on
            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
            new Callback<SteamClient.ConnectedCallback>( OnConnected, manager );
            new Callback<SteamClient.DisconnectedCallback>( OnDisconnected, manager );

            new Callback<SteamUser.LoggedOnCallback>( OnLoggedOn, manager );
            new Callback<SteamUser.LoggedOffCallback>( OnLoggedOff, manager );

            // we use the following callbacks for friends related activities
            new Callback<SteamUser.AccountInfoCallback>( OnAccountInfo, manager );
            new Callback<SteamFriends.FriendsListCallback>( OnFriendsList, manager );
            new Callback<SteamFriends.PersonaStateCallback>( OnPersonaState, manager );
            new Callback<SteamFriends.FriendAddedCallback>( OnFriendAdded, manager );

            isRunning = true;

            Console.WriteLine( "Connecting to Steam..." );

            // initiate the connection
            steamClient.Connect( false );

            // 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 ) );
            }
        }
        protected override void OnLoggedOn( SteamUser.LoggedOnCallback callback )
        {
            base.OnLoggedOn( callback );

            if ( callback.Result != EResult.OK )
            {
                Log.WriteWarn( "MasterMonitor", "Unable to logon to Steam: {0}", callback.Result );
                return;
            }

            Log.WriteInfo( "MasterMonitor", "Logged onto Steam!" );

            Connect( DateTime.Now + TimeSpan.FromMinutes( 30 ) );
        }
Beispiel #24
0
        static void Main( string[] args )
        {
            if ( args.Length < 2 )
            {
                Console.WriteLine( "Sample5: No username and password specified!" );
                return;
            }

            // save our logon details
            user = args[ 0 ];
            pass = args[ 1 ];

            // create our steamclient instance
            steamClient = new 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>();
            // get the steam friends handler, which is used for interacting with friends on the network after logging on
            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
            new Callback<SteamClient.ConnectedCallback>( OnConnected, manager );
            new Callback<SteamClient.DisconnectedCallback>( OnDisconnected, manager );

            new Callback<SteamUser.LoggedOnCallback>( OnLoggedOn, manager );
            new Callback<SteamUser.LoggedOffCallback>( OnLoggedOff, manager );

            // this callback is triggered when the steam servers wish for the client to store the sentry file
            new JobCallback<SteamUser.UpdateMachineAuthCallback>( OnMachineAuth, manager );

            isRunning = true;

            Console.WriteLine( "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 ) );
            }
        }
Beispiel #25
0
        public SteamNerd()
        {
            SteamClient = new SteamClient();

            CallbackManager = new CallbackManager(SteamClient);
            ModuleManager = new ModuleManager(this);
            UserManager = new UserManager(this, "admins.txt");
            ChatRoomManager = new ChatRoomManager(this, "chats.txt");

            SteamUser = SteamClient.GetHandler<SteamUser>();
            SteamFriends = SteamClient.GetHandler<SteamFriends>();

            SubscribeCallbacks();

            _login = new Login(this, CallbackManager);
        }
Beispiel #26
0
 public SteamInterface(String username, String password, String ssfn, SteamID channel)
 {
     lastRefresh = DateTime.Now;
     this.channel = channel;
     logon = new SteamUser.LogOnDetails() { Username = username, Password = password, SentryFileHash = SHA1.Create().ComputeHash((File.ReadAllBytes(ssfn))) };
     admins = new List<SteamID>();
     client = new SteamClient(System.Net.Sockets.ProtocolType.Tcp);
     manager = new CallbackManager(client);
     message = new Message() { MessageString = SteamInterface.NoCommand };
     user = client.GetHandler<SteamUser>();
     friends = client.GetHandler<SteamFriends>();
     new Callback<SteamClient.ConnectedCallback>(this.OnConnected, manager);
     new Callback<SteamClient.DisconnectedCallback>(this.OnDisconnected, manager);
     new Callback<SteamUser.LoggedOnCallback>(this.OnLoggedOn, manager);
     new Callback<SteamUser.LoggedOffCallback>(this.OnLoggedOff, manager);
     new Callback<SteamFriends.ChatMsgCallback>(this.OnChatMessage, manager);
 }
Beispiel #27
0
        // static string toptlb;
        // public static string steamgg(string code)
        // {
        //     return code;
        // }
        public static void Enter_(string us, string pa, ToolStripLabel tlb_)
        {
            user = us;
            pass = pa;
            tlb = tlb_;
            if ((user.Length < 2) || (pass.Length < 2))
            {
                tlb.Text = "No username and password specified!";
                return;
            }

            // create our steamclient instance
            steamClient = new 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>();

            // 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<SteamClient.ConnectedCallback>(OnConnected);
            manager.Subscribe<SteamClient.DisconnectedCallback>(OnDisconnected);

            manager.Subscribe<SteamUser.LoggedOnCallback>(OnLoggedOn);
            manager.Subscribe<SteamUser.LoggedOffCallback>(OnLoggedOff);

            // this callback is triggered when the steam servers wish for the client to store the sentry file
            //manager.Subscribe<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth);

            isRunning = true;

            tlb.Text = "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));
            }
        }
        public SteamWrappedClient()
        {
            Client = new SteamClient();
            CallbackManager = new CallbackManager(Client);

            User = Client.GetHandler<SteamUser>();
            TradingHandler = Client.GetHandler<SteamTrading>();

            CallbackManager.Subscribe<SteamClient.ConnectedCallback>(OnConnect);
            CallbackManager.Subscribe<SteamClient.DisconnectedCallback>(OnDisconnect);

            CallbackManager.Subscribe<SteamUser.LoggedOnCallback>(OnLogon);
            CallbackManager.Subscribe<SteamUser.LoggedOffCallback>(OnLogoff);

            CallbackManager.Subscribe<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth);

            RegisterOtherCallbacks();
        }
Beispiel #29
0
        public SteamKit(ARKUpdater p, AutoResetEvent r)
        {
            this._Parent = p;
            this._ResetEvent = r;

            this.Ready = false;
            this.Failed = false;
            this._ThreadRunning = true;

            this._Client = new SteamClient();
            this._CManager = new CallbackManager(this._Client);

            this._User = this._Client.GetHandler<SteamUser>();
            this._Apps = this._Client.GetHandler<SteamApps>();

            this.SubscribeCallbacks();
            this._Client.Connect();
        }
Beispiel #30
0
        public GCIdler(uint appID, string username, string password)
        {
            Username = username;
            Password = password;
            AppID = appID;

            Client = new SteamClient();
            User = Client.GetHandler<SteamUser>();
            Friends = Client.GetHandler<SteamFriends>();

            CallbackManager = new CallbackManager(Client);

            CallbackManager.Register(new Callback<SteamClient.ConnectedCallback>(OnConnected));
            CallbackManager.Register(new Callback<SteamClient.DisconnectedCallback>(OnDisconnected));
            CallbackManager.Register(new Callback<SteamUser.AccountInfoCallback>(OnAccountInfo));
            CallbackManager.Register(new Callback<SteamUser.LoggedOnCallback>(OnLoggedOn));

            GameCoordinator = new GameCoordinator(AppID, Client, CallbackManager);
        }
Beispiel #31
0
        public Steam3Session( SteamUser.LogOnDetails details )
        {
            this.logonDetails = details;

            this.authenticatedUser = details.Username != null;
            this.credentials = new Credentials();
            this.bConnected = false;
            this.bAborted = false;

            this.AppTickets = new Dictionary<uint, byte[]>();
            this.AppTokens = new Dictionary<uint, ulong>();
            this.DepotKeys = new Dictionary<uint, byte[]>();
            this.AppInfo = new Dictionary<uint, SteamApps.PICSProductInfoCallback.PICSProductInfo>();
            this.PackageInfo = new Dictionary<uint, SteamApps.PICSProductInfoCallback.PICSProductInfo>();
            this.AppInfoOverridesCDR = new Dictionary<uint, bool>();

            this.steamClient = new SteamClient();

            this.steamUser = this.steamClient.GetHandler<SteamUser>();
            this.steamApps = this.steamClient.GetHandler<SteamApps>();

            this.callbacks = new CallbackManager(this.steamClient);

            this.callbacks.Register(new Callback<SteamClient.ConnectedCallback>(ConnectedCallback));
            this.callbacks.Register(new Callback<SteamClient.DisconnectedCallback>(DisconnectedCallback));
            this.callbacks.Register(new Callback<SteamUser.LoggedOnCallback>(LogOnCallback));
            this.callbacks.Register(new Callback<SteamUser.SessionTokenCallback>(SessionTokenCallback));
            this.callbacks.Register(new Callback<SteamApps.LicenseListCallback>(LicenseListCallback));
            this.callbacks.Register(new JobCallback<SteamUser.UpdateMachineAuthCallback>(UpdateMachineAuthCallback));

            Console.Write( "Connecting to Steam3..." );

            if ( authenticatedUser )
            {
                FileInfo fi = new FileInfo(String.Format("{0}.sentryFile", logonDetails.Username));
                if (fi.Exists && fi.Length > 0)
                {
                    logonDetails.SentryFileHash = Util.SHAHash(File.ReadAllBytes(fi.FullName));
                }
            }

            Connect();
        }
Beispiel #32
0
        private void InitializeClient()
        {
            // client/manager creation
            Client  = new SteamClient();
            Manager = new CallbackManager(Client);

            _user = Client.GetHandler <SteamUser>();
            _apps = Client.GetHandler <SteamApps>();

            Client.AddHandler(new SteamTicketAuth());

            // subscriptions
            Manager.Subscribe <SteamClient.DisconnectedCallback>(OnDisconnected);
            Manager.Subscribe <SteamClient.ConnectedCallback>(OnConnected);
            Manager.Subscribe <SteamUser.UpdateMachineAuthCallback>(OnMachineAuth);
            Manager.Subscribe <SteamUser.LoggedOnCallback>(OnLoggedOn);


            // internal subs
            Manager.Subscribe <SteamApps.GameConnectTokensCallback>(OnGcTokens);
        }