示例#1
0
        public Bot(Configuration.BotInfo config, string apiKey, UserHandlerCreator handlerCreator, Interface gui, bool debug = false)
        {
            while (Interface.loginClicked == false)
            {
                // Wait for user to login
            }

            logOnDetails = new SteamUser.LogOnDetails
            {
                Username = Interface.username,
                Password = Interface.password
            };
            Admins = new ulong[1];
            Admins[0] = 123456789;
            this.apiKey = apiKey;
            LogLevel = Log.LogLevel.Info;
            //log = new Log(config.LogFile, this.DisplayName, LogLevel);
            CreateHandler = handlerCreator;
            BotControlClass = config.BotControlClass;

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

            ////log.Debug("Initializing Steam Bot...");
            SteamClient = new SteamClient();
            SteamTrade = SteamClient.GetHandler<SteamTrading>();
            SteamUser = SteamClient.GetHandler<SteamUser>();
            SteamFriends = SteamClient.GetHandler<SteamFriends>();
            gui.UpdateLog("\r\nConnecting, please wait...");
            ////log.Info("Connecting...");
            SteamClient.Connect();

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

                    HandleSteamMessage(msg, gui);
                }
            });

            CallbackThread.Start();
            ////log.Success("Done Loading Bot!");
            CallbackThread.Join();
        }
示例#2
0
        public static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Welcome login = new Welcome();
            Interface mainForm = new Interface();
            Splash splash = new Splash();

            Configuration config = new Configuration();
            Configuration.BotInfo info = new Configuration.BotInfo();
            info.Admins = new ulong[1];
            info.Admins[0] = 0123456789;
            info.BotControlClass = "";
            info.ChatResponse = "";
            info.DisplayName = "";
            info.DisplayNamePrefix = "";
            info.LogFile = "";
            info.LogLevel = "Info";
            info.MaximumActionGap = 0;
            info.MaximumTradeTime = 0;
            info.Password = "";
            info.TradePollingInterval = 999;
            info.Username = "";

            splash.Show();

            new Thread(() =>
            {
                int crashes = 0;
                while (crashes < 1000)
                {
                    try
                    {
                        new Bot(info, "120F03A1543C9F22AA9BF4C7B6442154", (Bot bot, SteamID sid) => {
                            return (SteamBot.UserHandler)System.Activator.CreateInstance(Type.GetType(bot.BotControlClass), new object[] { bot, sid });
                        }, mainForm, false);

                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Error With Bot: " + e);
                        crashes++;
                    }
                }
            }).Start();

            Thread.Sleep(3000);
            splash.Close();
            splash.Dispose();
            Application.Run(login);

            while (!Welcome.trial || !Welcome.loggedIn)
            {
                if (Welcome.loggedIn || Welcome.trial)
                {
                    mainForm.Text = "SteamGrouper " + Interface.BotVersion;
                    mainForm.ShowDialog();
                    mainForm.Activate();
                    break;
                }
                else if (Application.OpenForms.Count == 0)
                {
                    Environment.Exit(0);
                }
            }
        }
示例#3
0
        void HandleSteamMessage(CallbackMsg msg, Interface gui)
        {
            //log.Debug(msg.ToString());

            #region Login
            msg.Handle<SteamClient.ConnectedCallback>(callback =>
            {
                //log.Debug("Connection Callback: " + callback.Result);

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

            });

            msg.Handle<SteamUser.LoggedOnCallback>(callback =>
            {
                //log.Debug("Logged On Callback: " + callback.Result);

                if (callback.Result != EResult.OK)
                {
                    gui.UpdateLog("\r\nLogin Error: " + callback.Result);
                    //log.Error("Login Error: " + callback.Result);
                    gui.Invoke((Action)(() => gui.text_username.Enabled = true));
                    gui.Invoke((Action)(() => gui.text_password.Enabled = true));
                    gui.Invoke((Action)(() => gui.button_login.Text = "Login"));
                }

                if (callback.Result == EResult.AccountLogonDenied)
                {
                    ////log.Interface("This account is protected by Steam Guard.  Enter the authentication code sent to the proper email: ");
                    gui.Invoke((Action)(() => gui.SteamGuard()));

                    while (Application.OpenForms.Count > 1)
                    {

                    }

                    logOnDetails.AuthCode = SteamGuard.authCode;
                }

                if (callback.Result == EResult.InvalidLoginAuthCode)
                {
                    gui.Invoke((Action)(() => gui.SteamGuard(true)));

                    while (Application.OpenForms.Count > 1)
                    {

                    }

                    logOnDetails.AuthCode = SteamGuard.authCode;
                }
            });

            msg.Handle<SteamUser.LoginKeyCallback>(callback =>
            {
                while (true)
                {
                    bool authd = SteamWeb.Authenticate(callback, SteamClient, out sessionId, out token);
                    if (authd)
                    {
                        gui.UpdateLog("\r\nUser authenticated!");
                        break;
                    }
                    else
                    {
                        gui.UpdateLog("\r\nAuthentication failed, retrying in 2s...");
                        Thread.Sleep(2000);
                    }
                }

                SteamFriends.SetPersonaState(EPersonaState.Snooze);

                gui.UpdateLog("\r\nLogged in completely!\r\n");
                gui.Invoke((Action)(() => gui.button_login.Text = "Logged in"));

                IsLoggedIn = true;

                while (true)
                {
                    Console.ReadLine();
                }
            });

            // handle a special JobCallback differently than the others
            if (msg.IsType<SteamClient.JobCallback<SteamUser.UpdateMachineAuthCallback>>())
            {
                msg.Handle<SteamClient.JobCallback<SteamUser.UpdateMachineAuthCallback>>(
                    jobCallback => OnUpdateMachineAuthCallback(jobCallback.Callback, jobCallback.JobID)
                );
            }
            #endregion

            #region Friends
            /*msg.Handle<SteamFriends.FriendsListCallback>(callback =>
            {
                foreach (SteamFriends.FriendsListCallback.Friend friend in callback.FriendList)
                {
                    if (!friends.Contains(friend.SteamID))
                    {
                        friends.Add(friend.SteamID);
                        if (friend.Relationship == EFriendRelationship.PendingInvitee &&
                            GetUserHandler(friend.SteamID).OnFriendAdd())
                        {
                            SteamFriends.AddFriend(friend.SteamID);
                        }
                    }
                }
            });*/

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

                if (callback.EntryType == EChatEntryType.ChatMsg ||
                    callback.EntryType == EChatEntryType.Emote)
                {
                    //log.Info(String.Format("Chat Message from {0}: {1}",
                                         //SteamFriends.GetFriendPersonaName(callback.Sender),
                                         //callback.Message
                                         //));
                    GetUserHandler(callback.Sender).OnMessage(callback.Message, type);
                }
            });
            #endregion

            #region Trading
            msg.Handle<SteamTrading.SessionStartCallback>(callback =>
            {
                bool started = HandleTradeSessionStart(callback.OtherClient);

                if (!started)
                    log.Error("Could not start the trade session.");
                else
                    log.Debug("SteamTrading.SessionStartCallback handled successfully. Trade Opened.");
            });

            msg.Handle<SteamTrading.TradeProposedCallback>(callback =>
            {
                try
                {
                    tradeManager.InitializeTrade(SteamUser.SteamID, callback.OtherClient);
                }
                catch
                {
                    SteamFriends.SendChatMessage(callback.OtherClient,
                                                 EChatEntryType.ChatMsg,
                                                 "Trade declined. Could not correctly fetch your backpack.");

                    SteamTrade.RespondToTrade(callback.TradeID, false);
                    return;
                }

                if (tradeManager.OtherInventory.IsPrivate)
                {
                    SteamFriends.SendChatMessage(callback.OtherClient,
                                                 EChatEntryType.ChatMsg,
                                                 "Trade declined. Your backpack cannot be private.");

                    SteamTrade.RespondToTrade(callback.TradeID, false);
                    return;
                }

                if (CurrentTrade == null && GetUserHandler(callback.OtherClient).OnTradeRequest())
                    SteamTrade.RespondToTrade(callback.TradeID, true);
                else
                    SteamTrade.RespondToTrade(callback.TradeID, false);
            });

            msg.Handle<SteamTrading.TradeResultCallback>(callback =>
            {
                //log.Debug("Trade Status: " + callback.Response);

                if (callback.Response == EEconTradeResponse.Accepted)
                {
                    //log.Info("Trade Accepted!");
                }
                if (callback.Response == EEconTradeResponse.Cancel ||
                    callback.Response == EEconTradeResponse.ConnectionFailed ||
                    callback.Response == EEconTradeResponse.Declined ||
                    callback.Response == EEconTradeResponse.Error ||
                    callback.Response == EEconTradeResponse.InitiatorAlreadyTrading ||
                    callback.Response == EEconTradeResponse.TargetAlreadyTrading ||
                    callback.Response == EEconTradeResponse.Timeout ||
                    callback.Response == EEconTradeResponse.TooSoon ||
                    callback.Response == EEconTradeResponse.VacBannedInitiator ||
                    callback.Response == EEconTradeResponse.VacBannedTarget ||
                    callback.Response == EEconTradeResponse.NotLoggedIn) // uh...
                {
                    CloseTrade();
                }

            });
            #endregion

            #region Disconnect
            msg.Handle<SteamUser.LoggedOffCallback>(callback =>
            {
                IsLoggedIn = false;
                gui.UpdateLog("\r\nLogged Off: " + callback.Result);
                //log.Warn("Logged Off: " + callback.Result);
            });

            msg.Handle<SteamClient.DisconnectedCallback>(callback =>
            {
                IsLoggedIn = false;
                CloseTrade();
                gui.UpdateLog("\r\nDisconnected from Steam Network! Trying to reconnect...");
                //log.Warn("Disconnected from Steam Network!");
                SteamClient.Connect();
            });
            #endregion
        }
示例#4
0
        public Bot(Configuration.BotInfo config, string apiKey, UserHandlerCreator handlerCreator, Interface gui, bool debug = false)
        {
            while (Interface.loginClicked == false)
            {
                // Wait for user to login
            }

            logOnDetails = new SteamUser.LogOnDetails
            {
                Username = Interface.username,
                Password = Interface.password
            };
            Admins      = new ulong[1];
            Admins[0]   = 123456789;
            this.apiKey = apiKey;
            LogLevel    = Log.LogLevel.Info;
            //log = new Log(config.LogFile, this.DisplayName, LogLevel);
            CreateHandler   = handlerCreator;
            BotControlClass = config.BotControlClass;

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

            ////log.Debug("Initializing Steam Bot...");
            SteamClient  = new SteamClient();
            SteamTrade   = SteamClient.GetHandler <SteamTrading>();
            SteamUser    = SteamClient.GetHandler <SteamUser>();
            SteamFriends = SteamClient.GetHandler <SteamFriends>();
            gui.UpdateLog("\r\nConnecting, please wait...");
            ////log.Info("Connecting...");
            SteamClient.Connect();

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

                    HandleSteamMessage(msg, gui);
                }
            });

            CallbackThread.Start();
            ////log.Success("Done Loading Bot!");
            CallbackThread.Join();
        }
示例#5
0
        public static void invite(string groupFrom, string group, TextBox text_log, Button button_invite, Label label_invite)
        {
            successfulInvite = 0;
            int    counter = 0;
            string line    = "";
            string path    = "http://steamcommunity.com/groups/" + group + "/memberslistxml/?xml=1e";

            retry = 0;
            string groupID = getGroupID(group, path);

            if (groupID != "")
            {
                Interface.AppendText(text_log, "\r\nProcessing gather list... This may take a few minutes if you have large list. Please be patient.\n");
                // Read from the gather list
                System.IO.StreamReader file = new System.IO.StreamReader("lists/gl_" + groupFrom.ToLower());
                while ((line = file.ReadLine()) != null)
                {
                    if (Interface.subExInMinutes <= 0 && !Welcome.trial)
                    {
                        Console.WriteLine("Subscription expired.");
                        break;
                    }
                    if (!Interface.inviting)
                    {
                        Console.WriteLine("Inviting cancelled.");
                        break;
                    }
                    else
                    {
                        Interface.currentSID = Convert.ToUInt64(line);
                        // Check if user has already been invited
                        bool invited = false;
                        if (!File.Exists("lists/bl_" + group.ToLower()))
                        {
                            using (StreamWriter sw = File.CreateText("lists/bl_" + group.ToLower()))
                            {
                                sw.Close();
                            }
                        }
                        System.IO.StreamReader blacklist = new System.IO.StreamReader("lists/bl_" + group.ToLower());
                        string compare;
                        while ((compare = blacklist.ReadLine()) != null)
                        {
                            if (Interface.currentSID.ToString() == compare)
                            {
                                //Console.Write("User " + currentSID + " already invited.      \r");
                                invited = true;
                                break;
                            }
                        }
                        blacklist.Close();
                        if (!invited && Interface.inviteOffline)
                        {
                            if (successfulInvite % 250 == 0 && successfulInvite != 0 && Welcome.trial)
                            {
                                MessageBox.Show("For uninterrupted inviting, please consider buying a subscription! Visit http://www.steamgrouper.com/",
                                                "Trial Mode",
                                                MessageBoxButtons.OK,
                                                MessageBoxIcon.Information,
                                                MessageBoxDefaultButton.Button1);
                            }
                            counter++;
                            Interface.AppendText(text_log, "\r\nInviting user #" + counter + ": " + Interface.currentSID);
                            DoInvite(file, Interface.currentSID, groupID, group, text_log, label_invite);
                        }
                        else if (!invited && !Interface.inviteOffline)
                        {
                            if (successfulInvite % 250 == 0 && successfulInvite != 0 && Welcome.trial)
                            {
                                MessageBox.Show("For uninterrupted inviting, please consider buying a subscription! Visit http://www.steamgrouper.com/",
                                                "Trial Mode",
                                                MessageBoxButtons.OK,
                                                MessageBoxIcon.Information,
                                                MessageBoxDefaultButton.Button1);
                            }
                            string playerURL     = "http://steamcommunity.com/profiles/" + Interface.currentSID + "?xml=1";
                            string playerProfile = SteamGrouper.Util.HTTPRequest(playerURL);
                            string status        = "online";
                            if (playerProfile != "")
                            {
                                status = SteamGrouper.Util.ParseBetween(playerProfile, "<onlineState>", "</onlineState>");
                            }
                            if (status != "offline")
                            {
                                counter++;
                                Interface.AppendText(text_log, "\r\nInviting user #" + counter + ": " + Interface.currentSID);
                                DoInvite(file, Interface.currentSID, groupID, group, text_log, label_invite);
                            }
                        }
                    }
                }
                file.Close();
                Interface.AppendText(text_log, "\r\nDone. Invited " + counter + " members to your group.");
                Interface.UpdateLabel(label_invite, "State: Idle");
                Interface.UpdateButton(button_invite, "Invite");
                if (Interface.subExInMinutes <= 0 && !Welcome.trial)
                {
                    MessageBox.Show("We're sorry, but your subscription has just expired. To continue using the full version of SteamGrouper, please add more time to your subscription at http://www.steamgrouper.com/choose-a-subscription/",
                                    "Subscription Expired",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Exclamation,
                                    MessageBoxDefaultButton.Button1);
                }
            }
            else
            {
                MessageBox.Show("Failed to get groupID. Please try again.",
                                "Warning",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation,
                                MessageBoxDefaultButton.Button1);
            }
        }
示例#6
0
        void HandleSteamMessage(CallbackMsg msg, Interface gui)
        {
            //log.Debug(msg.ToString());

            #region Login
            msg.Handle <SteamClient.ConnectedCallback>(callback =>
            {
                //log.Debug("Connection Callback: " + callback.Result);

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

            msg.Handle <SteamUser.LoggedOnCallback>(callback =>
            {
                //log.Debug("Logged On Callback: " + callback.Result);

                if (callback.Result != EResult.OK)
                {
                    gui.UpdateLog("\r\nLogin Error: " + callback.Result);
                    //log.Error("Login Error: " + callback.Result);
                    gui.Invoke((Action)(() => gui.text_username.Enabled = true));
                    gui.Invoke((Action)(() => gui.text_password.Enabled = true));
                    gui.Invoke((Action)(() => gui.button_login.Text = "Login"));
                }

                if (callback.Result == EResult.AccountLogonDenied)
                {
                    ////log.Interface("This account is protected by Steam Guard.  Enter the authentication code sent to the proper email: ");
                    gui.Invoke((Action)(() => gui.SteamGuard()));

                    while (Application.OpenForms.Count > 1)
                    {
                    }

                    logOnDetails.AuthCode = SteamGuard.authCode;
                }

                if (callback.Result == EResult.InvalidLoginAuthCode)
                {
                    gui.Invoke((Action)(() => gui.SteamGuard(true)));

                    while (Application.OpenForms.Count > 1)
                    {
                    }

                    logOnDetails.AuthCode = SteamGuard.authCode;
                }
            });

            msg.Handle <SteamUser.LoginKeyCallback>(callback =>
            {
                while (true)
                {
                    bool authd = SteamWeb.Authenticate(callback, SteamClient, out sessionId, out token);
                    if (authd)
                    {
                        gui.UpdateLog("\r\nUser authenticated!");
                        break;
                    }
                    else
                    {
                        gui.UpdateLog("\r\nAuthentication failed, retrying in 2s...");
                        Thread.Sleep(2000);
                    }
                }

                SteamFriends.SetPersonaState(EPersonaState.Snooze);

                gui.UpdateLog("\r\nLogged in completely!\r\n");
                gui.Invoke((Action)(() => gui.button_login.Text = "Logged in"));

                IsLoggedIn = true;

                while (true)
                {
                    Console.ReadLine();
                }
            });

            // handle a special JobCallback differently than the others
            if (msg.IsType <SteamClient.JobCallback <SteamUser.UpdateMachineAuthCallback> >())
            {
                msg.Handle <SteamClient.JobCallback <SteamUser.UpdateMachineAuthCallback> >(
                    jobCallback => OnUpdateMachineAuthCallback(jobCallback.Callback, jobCallback.JobID)
                    );
            }
            #endregion

            #region Friends

            /*msg.Handle<SteamFriends.FriendsListCallback>(callback =>
             * {
             *  foreach (SteamFriends.FriendsListCallback.Friend friend in callback.FriendList)
             *  {
             *      if (!friends.Contains(friend.SteamID))
             *      {
             *          friends.Add(friend.SteamID);
             *          if (friend.Relationship == EFriendRelationship.PendingInvitee &&
             *              GetUserHandler(friend.SteamID).OnFriendAdd())
             *          {
             *              SteamFriends.AddFriend(friend.SteamID);
             *          }
             *      }
             *  }
             * });*/

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

                if (callback.EntryType == EChatEntryType.ChatMsg ||
                    callback.EntryType == EChatEntryType.Emote)
                {
                    //log.Info(String.Format("Chat Message from {0}: {1}",
                    //SteamFriends.GetFriendPersonaName(callback.Sender),
                    //callback.Message
                    //));
                    GetUserHandler(callback.Sender).OnMessage(callback.Message, type);
                }
            });
            #endregion

            #region Trading
            msg.Handle <SteamTrading.SessionStartCallback>(callback =>
            {
                bool started = HandleTradeSessionStart(callback.OtherClient);

                if (!started)
                {
                    log.Error("Could not start the trade session.");
                }
                else
                {
                    log.Debug("SteamTrading.SessionStartCallback handled successfully. Trade Opened.");
                }
            });

            msg.Handle <SteamTrading.TradeProposedCallback>(callback =>
            {
                try
                {
                    tradeManager.InitializeTrade(SteamUser.SteamID, callback.OtherClient);
                }
                catch
                {
                    SteamFriends.SendChatMessage(callback.OtherClient,
                                                 EChatEntryType.ChatMsg,
                                                 "Trade declined. Could not correctly fetch your backpack.");

                    SteamTrade.RespondToTrade(callback.TradeID, false);
                    return;
                }

                if (tradeManager.OtherInventory.IsPrivate)
                {
                    SteamFriends.SendChatMessage(callback.OtherClient,
                                                 EChatEntryType.ChatMsg,
                                                 "Trade declined. Your backpack cannot be private.");

                    SteamTrade.RespondToTrade(callback.TradeID, false);
                    return;
                }

                if (CurrentTrade == null && GetUserHandler(callback.OtherClient).OnTradeRequest())
                {
                    SteamTrade.RespondToTrade(callback.TradeID, true);
                }
                else
                {
                    SteamTrade.RespondToTrade(callback.TradeID, false);
                }
            });

            msg.Handle <SteamTrading.TradeResultCallback>(callback =>
            {
                //log.Debug("Trade Status: " + callback.Response);

                if (callback.Response == EEconTradeResponse.Accepted)
                {
                    //log.Info("Trade Accepted!");
                }
                if (callback.Response == EEconTradeResponse.Cancel ||
                    callback.Response == EEconTradeResponse.ConnectionFailed ||
                    callback.Response == EEconTradeResponse.Declined ||
                    callback.Response == EEconTradeResponse.Error ||
                    callback.Response == EEconTradeResponse.InitiatorAlreadyTrading ||
                    callback.Response == EEconTradeResponse.TargetAlreadyTrading ||
                    callback.Response == EEconTradeResponse.Timeout ||
                    callback.Response == EEconTradeResponse.TooSoon ||
                    callback.Response == EEconTradeResponse.VacBannedInitiator ||
                    callback.Response == EEconTradeResponse.VacBannedTarget ||
                    callback.Response == EEconTradeResponse.NotLoggedIn) // uh...
                {
                    CloseTrade();
                }
            });
            #endregion

            #region Disconnect
            msg.Handle <SteamUser.LoggedOffCallback>(callback =>
            {
                IsLoggedIn = false;
                gui.UpdateLog("\r\nLogged Off: " + callback.Result);
                //log.Warn("Logged Off: " + callback.Result);
            });

            msg.Handle <SteamClient.DisconnectedCallback>(callback =>
            {
                IsLoggedIn = false;
                CloseTrade();
                gui.UpdateLog("\r\nDisconnected from Steam Network! Trying to reconnect...");
                //log.Warn("Disconnected from Steam Network!");
                SteamClient.Connect();
            });
            #endregion
        }