Example #1
0
        private void FireOnSteamGuardRequired(SteamGuardRequiredEventArgs e)
        {
            // Set to null in case this is another attempt
            this.AuthCode = null;

            EventHandler <SteamGuardRequiredEventArgs> handler = OnSteamGuardRequired;

            if (handler != null)
            {
                handler(this, e);
            }
            else
            {
                while (true)
                {
                    if (this.AuthCode != null)
                    {
                        e.SteamGuard = this.AuthCode;
                        break;
                    }

                    Thread.Sleep(5);
                }
            }
        }
Example #2
0
        void HandleSteamMessage(ICallbackMsg msg)
        {
            Log.Debug(msg.ToString());
            #region Login
            msg.Handle <SteamClient.ConnectedCallback>(callback =>
            {
                Log.Debug("Connection Callback: {0}", callback.Result);

                if (callback.Result == EResult.OK)
                {
                    UserLogOn();
                }
                else
                {
                    Log.Error("Failed to connect to Steam Community, trying again...");
                    SteamClient.Connect();
                }
            });

            msg.Handle <SteamUser.LoggedOnCallback>(callback =>
            {
                Log.Debug("Logged On Callback: {0}", callback.Result);

                if (callback.Result == EResult.OK)
                {
                    myUserNonce = callback.WebAPIUserNonce;
                }
                else
                {
                    Log.Error("Login Error: {0}", callback.Result);
                }

                if (callback.Result == EResult.AccountLogonDeniedNeedTwoFactorCode)
                {
                    var mobileAuthCode = GetMobileAuthCode();
                    if (string.IsNullOrEmpty(mobileAuthCode))
                    {
                        Log.Error("Failed to generate 2FA code. Make sure you have linked the authenticator via SteamBot.");
                    }
                    else
                    {
                        logOnDetails.TwoFactorCode = mobileAuthCode;
                        Log.Success("Generated 2FA code.");
                    }
                }
                else if (callback.Result == EResult.TwoFactorCodeMismatch)
                {
                    SteamAuth.TimeAligner.AlignTime();
                    logOnDetails.TwoFactorCode = SteamGuardAccount.GenerateSteamGuardCode();
                    Log.Success("Regenerated 2FA code.");
                }
                else if (callback.Result == EResult.AccountLogonDenied)
                {
                    Log.Interface("This account is SteamGuard enabled. Enter the code via the `auth' command.");

                    // try to get the steamguard auth code from the event callback
                    var eva = new SteamGuardRequiredEventArgs();
                    FireOnSteamGuardRequired(eva);
                    if (!String.IsNullOrEmpty(eva.SteamGuard))
                    {
                        logOnDetails.AuthCode = eva.SteamGuard;
                    }
                    else
                    {
                        logOnDetails.AuthCode = Console.ReadLine();
                    }
                }
                else if (callback.Result == EResult.InvalidLoginAuthCode)
                {
                    Log.Interface("The given SteamGuard code was invalid. Try again using the `auth' command.");
                    logOnDetails.AuthCode = Console.ReadLine();
                }
            });

            msg.Handle <SteamUser.LoginKeyCallback>(callback =>
            {
                myUniqueId = callback.UniqueID.ToString();

                UserWebLogOn();

                SteamFriends.SetPersonaName(DisplayNamePrefix + DisplayName);
                SteamFriends.SetPersonaState(EPersonaState.Online);

                Log.Success(string.Format("Steam Bot Logged In Completely ({0} Friends)!", SteamFriends.GetFriendCount()));

                GetUserHandler(SteamClient.SteamID).OnLoginCompleted();
            });

            msg.Handle <SteamUser.WebAPIUserNonceCallback>(webCallback =>
            {
                Log.Debug("Received new WebAPIUserNonce.");

                if (webCallback.Result == EResult.OK)
                {
                    myUserNonce = webCallback.Nonce;
                    UserWebLogOn();
                }
                else
                {
                    Log.Error("WebAPIUserNonce Error: " + webCallback.Result);
                }
            });

            msg.Handle <SteamUser.UpdateMachineAuthCallback>(
                authCallback => OnUpdateMachineAuthCallback(authCallback)
                );
            #endregion

            #region Friends
            msg.Handle <SteamFriends.FriendsListCallback>(callback =>
            {
                foreach (SteamFriends.FriendsListCallback.Friend friend in callback.FriendList)
                {
                    switch (friend.SteamID.AccountType)
                    {
                    case EAccountType.Clan:
                        if (friend.Relationship == EFriendRelationship.RequestRecipient)
                        {
                            //if (GetUserHandler(friend.SteamID).OnGroupAdd())
                            //{
                            AcceptGroupInvite(friend.SteamID);
                            //}
                            //else
                            //{
                            //    DeclineGroupInvite(friend.SteamID);
                            //}
                        }
                        break;

                    default:
                        CreateFriendsListIfNecessary();
                        if (friend.Relationship == EFriendRelationship.None)
                        {
                            friends.Remove(friend.SteamID);
                            GetUserHandler(friend.SteamID).OnFriendRemove();
                            RemoveUserHandler(friend.SteamID);
                        }
                        else if (friend.Relationship == EFriendRelationship.RequestRecipient)
                        {
                            if (GetUserHandler(friend.SteamID).OnFriendAdd())
                            {
                                if (!friends.Contains(friend.SteamID))
                                {
                                    friends.Add(friend.SteamID);
                                }
                                else
                                {
                                    Log.Error("Friend was added who was already in friends list: " + friend.SteamID);
                                }
                                AddFriend(friend.SteamID);
                                GetUserHandler(friend.SteamID).OnFriendAdded();
                            }
                            else
                            {
                                SteamFriends.RemoveFriend(friend.SteamID);
                                RemoveUserHandler(friend.SteamID);
                            }
                        }
                        break;
                    }
                }
            });


            msg.Handle <SteamFriends.FriendMsgCallback>(callback =>
            {
                EChatEntryType type = callback.EntryType;

                if (callback.EntryType == EChatEntryType.ChatMsg)
                {
                    Log.Info("Chat Message from {0}: {1}",
                             SteamFriends.GetFriendPersonaName(callback.Sender),
                             callback.Message
                             );
                    GetUserHandler(callback.Sender).OnMessageHandler(callback.Message, type);
                }
            });
            #endregion

            #region Group Chat
            msg.Handle <SteamFriends.ChatMsgCallback>(callback =>
            {
                GetUserHandler(callback.ChatterID).OnChatRoomMessage(callback.ChatRoomID, callback.ChatterID, callback.Message);
            });
            #endregion

            #region Disconnect
            msg.Handle <SteamUser.LoggedOffCallback>(callback =>
            {
                IsLoggedIn = false;
                Log.Warn("Logged off Steam.  Reason: {0}", callback.Result);
            });

            msg.Handle <SteamClient.DisconnectedCallback>(callback =>
            {
                if (IsLoggedIn)
                {
                    IsLoggedIn = false;
                    Log.Warn("Disconnected from Steam Network!");
                }

                SteamClient.Connect();
            });
            #endregion

            #region Notifications
            msg.Handle <SteamBot.SteamNotifications.NotificationCallback>(callback =>
            {
                if (callback.Notifications.Count != 0)
                {
                    foreach (var notification in callback.Notifications)
                    {
                        Log.Info(notification.UserNotificationType + " notification");
                    }
                }
            });

            msg.Handle <SteamBot.SteamNotifications.CommentNotificationCallback>(callback =>
            {
                //various types of comment notifications on profile/activity feed etc
                //Log.Info("received CommentNotificationCallback");
                //Log.Info("New Commments " + callback.CommentNotifications.CountNewComments);
                //Log.Info("New Commments Owners " + callback.CommentNotifications.CountNewCommentsOwner);
                //Log.Info("New Commments Subscriptions" + callback.CommentNotifications.CountNewCommentsSubscriptions);
            });
            #endregion
        }