Пример #1
0
        public SteamInterface()
        {
            string       user = config["username"].ToString();
            string       pass = config["password"].ToString();
            bool         shouldrememberpass = (bool)config["ShouldRememberPassword"];
            SteamBotData SteamBotLoginData  = new SteamBotData(user, pass, shouldrememberpass);

            LoginData = SteamBotLoginData.LoginData;
            ResetConnection(SteamBotLoginData);
        }
Пример #2
0
        /// <summary>
        /// Creates an instance of SteamConnectionHandler with the data given and logs in, also can be fired to reset the bot
        /// </summary>
        /// <param name="BotData"> Data involving the userhandler and what bot to load</param>
        public void ResetConnection(SteamBotData BotData)
        {
            Console.WriteLine("Loading New Connection");
            SteamBotLiteLoginData = BotData;
            pass = BotData.SavedPassword;                      //We'll save this now, so we can access it later for logging in if the loginkey fails

            LoginData = BotData.LoginData;                     //Lets save the login data

            if (!Directory.Exists(user))                       //Check if we have a settings folder for this username
            {
                Directory.CreateDirectory(LoginData.Username); //We will create the directory which will be used to store the loginkey and sentry file
            }

            SentryFile = Path.Combine(LoginData.Username, SentryFileName);             //Now that we have verified the folder exists, we will set file's path

            LoginKeyFile = Path.Combine(LoginData.Username, LoginKeyName);             //Now that we have verified the folder exists, we will set file's path

            if (File.Exists(LoginKeyFile) && LoginData.ShouldRememberPassword == true) //Lets see if a previously set login Key exists
            {
                LoginData.LoginKey = File.ReadAllText(LoginKeyFile);                   //Lets get the LoginKey and set it
                LoginData.Password = null;
            }

            // 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 steamfriends handler, which is used for communicating with users
            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

            //These callbacks are to handle thh connection
            manager.Subscribe <SteamClient.ConnectedCallback>(OnConnected);
            manager.Subscribe <SteamClient.DisconnectedCallback>(OnDisconnected);

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

            //These callbacks are to handler the bot being online/offline

            //In the future, these callbacks should be migrated over to the UserHandler to utilise instead
            manager.Subscribe <SteamUser.AccountInfoCallback>(OnAccountInfo);    //We receive this when we're logged-in, the method referenced makes us go online on community
            manager.Subscribe <SteamFriends.FriendsListCallback>(OnFriendsList); //We receive this when we go online on community

            //We will pass some down to the UserHandler instead, as these manage users not the connection
            manager.Subscribe <SteamFriends.FriendMsgCallback>(ReceivePrivateMessage);
            manager.Subscribe <SteamFriends.ChatMsgCallback>(ReceiveChatMessage);
            manager.Subscribe <SteamFriends.ChatMemberInfoCallback>(Chatmemberinfo);

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

            //We check if the user wants to remember the password, if so we set the callback up to receive login Keys
            if (BotData.ShouldRememberPassword)
            {
                manager.Subscribe <SteamUser.LoginKeyCallback>(OnLoginKey);
            }

            Console.WriteLine("Connecting User: {0}", user);

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

            SteamDirectory.Initialize().Wait(); //Gets a new server list, this is REALLY necessary.

            // initiate the connection
            Reconnect();
        }