Esempio n. 1
0
		void HandleSteamMessage(CallbackMsg msg) {
			#region Login
			msg.Handle<SteamClient.ConnectedCallback>(callback => {
				Util.printConsole("Connection Status " + callback.Result, this, ConsoleColor.Magenta);

				if (callback.Result == EResult.OK) {
					SteamUser.LogOn(new SteamUser.LogOnDetails {
						Username = Username,
						Password = Password
					});
				} else {
					Util.printConsole("Failed to Connect to the steam community", this, ConsoleColor.Red);
					SteamClient.Connect();
				}

			});

			msg.Handle<SteamUser.LoggedOnCallback>(callback => {
				if (callback.Result != EResult.OK) {
					Util.printConsole("Login Failure: " + callback.Result, this, ConsoleColor.Red);
				}
			});

			msg.Handle<SteamUser.LoginKeyCallback>(callback => {
				while (true) {
					if (Authenticate(callback)) {
						Util.printConsole("Authenticated.", this, ConsoleColor.Magenta);
						break;
					} else {
						Util.printConsole("Retrying auth...", this, ConsoleColor.Red);
						Thread.Sleep(2000);
					}
				}

				SteamFriends.SetPersonaName(DisplayName);
				SteamFriends.SetPersonaState(EPersonaState.LookingToTrade);

				foreach (SteamID bot in Program.bots) {
					if (SteamFriends.GetFriendRelationship(bot) != EFriendRelationship.Friend) {
						SteamFriends.AddFriend(bot);
					}
				}
				Program.bots.Add(SteamClient.SteamID);

				IsLoggedIn = true;
				queueHandler.canTrade = true;
			});
			#endregion

			#region Friends
			msg.Handle<SteamFriends.PersonaStateCallback>(callback => {
				if (callback.FriendID == SteamUser.SteamID)
					return;

				EFriendRelationship relationship = SteamFriends.GetFriendRelationship(callback.FriendID);
				if (relationship == EFriendRelationship.Friend) {
					queueHandler.acceptedRequest(callback.FriendID);
				} else if (relationship == EFriendRelationship.PendingInvitee) {
					Util.printConsole("Friend Request Pending: " + callback.FriendID + "(" + SteamFriends.GetFriendPersonaName(callback.FriendID) + ")", this, ConsoleColor.DarkCyan, true);
					if (Program.bots.Contains(callback.FriendID) || Admins.Contains(callback.FriendID)) {
						SteamFriends.AddFriend(callback.FriendID);
					}
					//steamFriends.AddFriend(callback.FriendID);
				}
			});

			msg.Handle<SteamFriends.FriendMsgCallback>(callback => {
				//Type (emote or chat)
				EChatEntryType type = callback.EntryType;

				if (type == EChatEntryType.ChatMsg) {
					string response = "";
					if (responses.ContainsKey(callback.Message.ToLower())) {
						response = responses[callback.Message.ToLower()];
					} else {
						string[] args2 = callback.Message.Split(' ');
						string text = Util.removeArg0(callback.Message);
						string[] pArgs = text.Split(' ');

						response = Extensions.getCommand(args2[0].ToLower()).call(callback.Sender, pArgs, text, this);
					}
					SteamFriends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, response);
				}

			});
			#endregion

			#region Trading
			msg.Handle<SteamTrading.SessionStartCallback>(call => {
				Trade.TradeListener listener = TradeListener;
				if (Admins.Contains(call.OtherClient)) {
					listener = TradeListenerAdmin;
				} else if (Program.bots.Contains(call.OtherClient)) {
					listener = TradeListenerInternal;
				}
				try {
					CurrentTrade = new Trade(SteamUser.SteamID, call.OtherClient, sessionId, token, apiKey, listener);
				} catch (Exception e) {
					Util.printConsole(e.Message, this, ConsoleColor.White, true);
					CurrentTrade = null;
					Thread.Sleep(5000);
					SteamTrade.Trade(call.OtherClient);
				}
			});

			msg.Handle<SteamTrading.TradeProposedCallback>(thing => {
				Util.printConsole("Trade Proposed Callback. Other: " + thing.OtherClient, this, ConsoleColor.White, true);
				if (Program.bots.Contains(thing.OtherClient) && queueHandler.needItemsBool) {
					SteamTrade.RespondToTrade(thing.TradeID, true);
				} else {
					SteamTrade.RespondToTrade(thing.TradeID, false);
					SteamFriends.SendChatMessage(thing.OtherClient, EChatEntryType.ChatMsg, "Please wait your turn, thanks :)");
				}
			});

			msg.Handle<SteamTrading.TradeResultCallback>(thing => {
				Util.printConsole("Trade Status: " + thing.Response, this, ConsoleColor.Magenta, true);

				if (thing.Response == EEconTradeResponse.Accepted) {
					if (!Program.bots.Contains(thing.OtherClient)) {
						Util.printConsole("Trade accepted!", this, ConsoleColor.Yellow);
					}
				} else if (thing.Response == EEconTradeResponse.TargetAlreadyTrading) {
					Util.printConsole("User is already trading!", this, ConsoleColor.Magenta);
					SteamFriends.SendChatMessage(thing.OtherClient, EChatEntryType.ChatMsg, "You're at the top of the trade queue, but are in trade. We don't have all day :c");
					Thread.Sleep(10000);
					queueHandler.ignoredTrade(thing.OtherClient);
				} else if (thing.Response == EEconTradeResponse.Declined) {
					Util.printConsole("User declined trade???", this, ConsoleColor.Magenta);
					Thread.Sleep(5000);
					queueHandler.ignoredTrade(thing.OtherClient);
				} else {
					Util.printConsole("Assume User Ignored Trade Request...", this, ConsoleColor.Magenta);
					queueHandler.ignoredTrade(thing.OtherClient);
				}
			});
			#endregion

			#region Disconnect
			msg.Handle<SteamUser.LoggedOffCallback>(callback => {
				Util.printConsole("Told to log off by server (" + callback.Result + "), attemping to reconnect", this, ConsoleColor.Magenta);
				SteamClient.Connect();
			});

			msg.Handle<SteamClient.DisconnectedCallback>(callback => {
				IsLoggedIn = false;
				if (CurrentTrade != null) {
					CurrentTrade = null;
				}
				Util.printConsole("Disconnected from Steam Network, attemping to reconnect", this, ConsoleColor.Magenta);
				SteamClient.Connect();
			});
			#endregion
		}
Esempio n. 2
0
 /// <summary>
 /// Creates a new trade with the given partner.
 /// </summary>
 /// <returns>
 /// <c>true</c>, if trade was opened, 
 /// <c>false</c> if there is another trade that must be closed first.
 /// </returns>
 public bool OpenTrade(SteamID other)
 {
     if (CurrentTrade != null)
         return false;
     CurrentTrade = new Trade (SteamUser.SteamID, other, sessionId, token, apiKey, this);
     CurrentTrade.OnTimeout += CloseTrade;
     getHandler (other).SubscribeTrade (CurrentTrade);
     getHandler (other).OnTradeInit ();
     return true;
 }
Esempio n. 3
0
        void HandleSteamMessage(CallbackMsg msg)
        {
            #region Login
            msg.Handle<SteamClient.ConnectedCallback> (callback =>
            {
                //PrintConsole ("Connection Callback: " + callback.Result, ConsoleColor.Magenta);
                log.Debug ("Connection Callback: " + callback.Result);

                if (callback.Result == EResult.OK)
                {
                    SteamUser.LogOn (new SteamUser.LogOnDetails
                         {
                        Username = Username,
                        Password = Password,
                        AuthCode = AuthCode
                    });
                }
                else
                {
                    log.Error ("Failed to connect to Steam Community, trying again...");
                    //PrintConsole ("Failed to Connect to the steam community!\n", ConsoleColor.Red);
                    SteamClient.Connect ();
                }

            });

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

                if (callback.Result != EResult.OK)
                {
                    log.Error ("Login Error: " + callback.Result);
                    //PrintConsole("Login Failure: " + callback.Result, ConsoleColor.Red);
                }

                if (callback.Result == EResult.AccountLogonDenied)
                {
                    //PrintConsole("This account is protected by Steam Guard. Enter the authentication code sent to the associated email address", ConsoleColor.DarkYellow);
                    log.Interface ("This account is protected by Steam Guard.  Enter the authentication code sent to the proper email: ");
                    AuthCode = Console.ReadLine();
                }
            });

            msg.Handle<SteamUser.LoginKeyCallback> (callback =>
            {
                while (true)
                {
                    if (Authenticate (callback))
                    {
                        log.Success ("User Authenticated!");
                        //PrintConsole ("Authenticated.");
                        break;
                    }
                    else
                    {
                        log.Warn ("Authentication failed, retrying in 2s...");
                        //PrintConsole ("Retrying auth...", ConsoleColor.Red);
                        Thread.Sleep (2000);
                    }
                }

                //PrintConsole ("Downloading schema...", ConsoleColor.Magenta);
                log.Info ("Downloading Schema...");

                Trade.CurrentSchema = Schema.FetchSchema (apiKey);

                //PrintConsole ("All Done!", ConsoleColor.Magenta);
                log.Success ("Schema Downloaded!");

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

                log.Success ("Steam Bot Logged In Completely!");
                //PrintConsole ("Successfully Logged In!\nWelcome " + SteamUser.SteamID + "\n\n", ConsoleColor.Magenta);

                IsLoggedIn = true;
            });
            #endregion

            #region Friends
            msg.Handle<SteamFriends.PersonaStateCallback> (callback =>
            {
                SteamFriends.AddFriend (callback.FriendID);
            });

            msg.Handle<SteamFriends.FriendMsgCallback> (callback =>
            {
                //Type (emote or chat)
                EChatEntryType type = callback.EntryType;

                if (type == EChatEntryType.ChatMsg)
                {
                    log.Info (String.Format ("Chat Message from {0}: {1}",
                                             SteamFriends.GetFriendPersonaName (callback.Sender),
                                             callback.Message
                                             ));
                    //PrintConsole ("[Chat] " + SteamFriends.GetFriendPersonaName (callback.Sender) + ": " + callback.Message, ConsoleColor.Magenta);

                    //string message = callback.Message;

                    string response = ChatResponse;
                    SteamFriends.SendChatMessage (callback.Sender, EChatEntryType.ChatMsg, response);
                }

            });
            #endregion

            #region Trading
            msg.Handle<SteamTrading.TradeStartSessionCallback> (call =>
            {
                CurrentTrade = new Trade (SteamUser.SteamID, call.Other, sessionId, token, apiKey, this, TradeListener);
                CurrentTrade.MaximumTradeTime = MaximumTradeTime;
                CurrentTrade.MaximumActionGap = MaximiumActionGap;
                CurrentTrade.OnTimeout += () => {
                    CurrentTrade = null;
                };
            });

            msg.Handle<SteamTrading.TradeCancelRequestCallback> (call =>
            {
                log.Info ("Cancel Callback Request detected");
                CurrentTrade = null;
            });

            msg.Handle<SteamTrading.TradeProposedCallback> (thing =>
            {
                SteamTrade.RequestTrade (thing.Other);
            });

            msg.Handle<SteamTrading.TradeRequestCallback> (thing =>
            {
                log.Debug ("Trade Status: "+ thing.Status);
                //PrintConsole ("Trade Status: " + thing.Status, ConsoleColor.Magenta);

                if (thing.Status == ETradeStatus.Accepted)
                {
                    log.Info ("Trade Accepted!");
                    //PrintConsole ("Trade accepted!", ConsoleColor.Magenta);
                }

                if (thing.Status == ETradeStatus.Cancelled)
                {
                    log.Info ("Trade was cancelled");
                    CurrentTrade = null;
                }
            });
            #endregion

            #region Disconnect
            msg.Handle<SteamUser.LoggedOffCallback> (callback =>
            {
                IsLoggedIn = false;
                log.Warn ("Logged Off: " + callback.Result);
                //PrintConsole ("[SteamRE] Logged Off: " + callback.Result, ConsoleColor.Magenta);
            });

            msg.Handle<SteamClient.DisconnectedCallback> (callback =>
            {
                IsLoggedIn = false;
                if (CurrentTrade != null)
                {
                    CurrentTrade = null;
                }
                log.Warn ("Disconnected from Steam Network!");
                //PrintConsole ("[SteamRE] Disconnected from Steam Network!", ConsoleColor.Magenta);
                SteamClient.Connect ();
            });
            #endregion
        }
Esempio n. 4
0
 /// <summary>
 /// Closes the current active trade.
 /// </summary>
 public void CloseTrade()
 {
     if (CurrentTrade == null)
         return;
     getHandler (CurrentTrade.OtherSID).UnsubscribeTrade ();
     CurrentTrade = null;
 }
Esempio n. 5
0
        void HandleSteamMessage (CallbackMsg msg)
        {
            #region Login
            msg.Handle<SteamClient.ConnectedCallback> (callback =>
            {
                PrintConsole ("Connection Callback: " + callback.Result, ConsoleColor.Magenta);

                if (callback.Result == EResult.OK)
                {
                    SteamUser.LogOn (new SteamUser.LogOnDetails
                         {
                        Username = Username,
                        Password = Password,
                        AuthCode = AuthCode
                    });
                }
                else
                {
                    PrintConsole ("Failed to Connect to the steam community!\n", ConsoleColor.Red);
                    SteamClient.Connect ();
                }

            });

            msg.Handle<SteamUser.LoggedOnCallback> (callback =>
            {
                PrintConsole ("Logged on callback: " + callback.Result, ConsoleColor.Magenta);

                if (callback.Result != EResult.OK)
                {
                    PrintConsole("Login Failure: " + callback.Result, ConsoleColor.Red);
                }

                if (callback.Result == EResult.AccountLogonDenied)
                {
                    PrintConsole("This account is protected by Steam Guard. Enter the authentication code sent to the associated email address", ConsoleColor.DarkYellow);
                    AuthCode = Console.ReadLine();
                }
            });

            msg.Handle<SteamUser.LoginKeyCallback> (callback =>
            {
                while (true)
                {
                    if (Authenticate (callback))
                    {
                        PrintConsole ("Authenticated.");
                        break;
                    }
                    else
                    {
                        PrintConsole ("Retrying auth...", ConsoleColor.Red);
                        Thread.Sleep (2000);
                    }
                }

                PrintConsole ("Downloading schema...", ConsoleColor.Magenta);

                Trade.CurrentSchema = Schema.FetchSchema (apiKey);

                PrintConsole ("All Done!", ConsoleColor.Magenta);

                SteamFriends.SetPersonaName ("[SteamBot] "+DisplayName);
                SteamFriends.SetPersonaState (EPersonaState.LookingToTrade);

                PrintConsole ("Successfully Logged In!\nWelcome " + SteamUser.SteamID + "\n\n", ConsoleColor.Magenta);

                IsLoggedIn = true;
            });
            #endregion

            #region Friends
            msg.Handle<SteamFriends.PersonaStateCallback> (callback =>
            {
                SteamFriends.AddFriend (callback.FriendID);
            });

            msg.Handle<SteamFriends.FriendMsgCallback> (callback =>
            {
                //Type (emote or chat)
                EChatEntryType type = callback.EntryType;

                if (type == EChatEntryType.ChatMsg)
                {
                    PrintConsole ("[Chat] " + SteamFriends.GetFriendPersonaName (callback.Sender) + ": " + callback.Message, ConsoleColor.Magenta);

                    //string message = callback.Message;

                    string response = ChatResponse;
                    SteamFriends.SendChatMessage (callback.Sender, EChatEntryType.ChatMsg, response);
                }

            });
            #endregion

            #region Trading
            msg.Handle<SteamTrading.TradeStartSessionCallback> (call =>
            {
                CurrentTrade = new Trade (SteamUser.SteamID, call.Other, sessionId, token, apiKey, TradeListener);
            });

            msg.Handle<SteamTrading.TradeProposedCallback> (thing =>
            {
                SteamTrade.RequestTrade (thing.Other);
            });

            msg.Handle<SteamTrading.TradeRequestCallback> (thing =>
            {
                PrintConsole ("Trade Status: " + thing.Status, ConsoleColor.Magenta);

                if (thing.Status == ETradeStatus.Accepted)
                {
                    PrintConsole ("Trade accepted!", ConsoleColor.Magenta);
                }
            });
            #endregion

            #region Disconnect
            msg.Handle<SteamUser.LoggedOffCallback> (callback =>
            {
                PrintConsole ("[SteamRE] Logged Off: " + callback.Result, ConsoleColor.Magenta);
            });

            msg.Handle<SteamClient.DisconnectedCallback> (callback =>
            {
                IsLoggedIn = false;
                if (CurrentTrade != null)
                {
                    CurrentTrade = null;
                }
                PrintConsole ("[SteamRE] Disconnected from Steam Network!", ConsoleColor.Magenta);
                SteamClient.Connect ();
            });
            #endregion
        }