Jessecar96 / SteamBot

Automated bot software for interacting with Steam Trade
http://scrap.tf
MIT License
1.33k stars 910 forks source link

Adding Friends Issue. #185

Closed BOOMdeyada closed 11 years ago

BOOMdeyada commented 11 years ago

Hey, I know im missing something stupid, maybe you guys could help me out?

I am downloading a JSON string from a website and parsing it, in that string is a steamID, which according to my console output, is valid.

WebClient client = new WebClient (); 
                string s = client.DownloadString (url);
                Console.WriteLine("Downloaded JSON... Parsing..");
                int nextslot;
                nextslot = 0;
                JObject o = JObject.Parse(s);
               // JArray items = (JArray)o["ItemID"];
                SteamID = new SteamID((ulong)o["SteamID"]);
                //ItemIDList.Add((string)items[0]); 

I then call the SteamID variable in my SimpleUserHandler.cs

 if (check.OnJSONGet == true)
        {

            Console.WriteLine("Fetched The JSON.");
            //System.Threading.Thread.Sleep(5000);
            Console.WriteLine(check.ItemIDs);
            Console.WriteLine(check.SteamID.ToString());

            //int nextID;
            //nextID = 1;

                /*foreach (dynamic id in ids)
                if (string.IsNullOrEmpty(check.itemid) == false)
                {
                if (check.data.Root.ToString() == "Trade")
                    {
                    ItemstoAdd.Add (check.itemid[nextID].ToString());
                    nextID++;
                    SteamIDToAdd = check.steam.ToString();
                    }

                }*/

            Console.WriteLine(check.SteamID.ToString());
            //SteamIDint.SetFromUInt64(check.SteamID);

            Console.WriteLine("Added Succesfully.");
            return true;
        }

and here:

public override void OnMessage (string message, EChatEntryType type)
    {
        OnJSONGet ();
        if (check.SteamID.IsValid == true)
        {
            friend.AddFriend(check.SteamID);
        }
        Bot.SteamFriends.SendChatMessage(OtherSID, type, Bot.ChatResponse);

    }

And here is my console output:

    [(System) 2013-02-28 13:34:04] INFO: Launching Bot The Paint Man...
    [The Paint Man 2013-02-28 13:34:04] SUCCESS: Done Loading Bot!
    [The Paint Man 2013-02-28 13:34:25] WARN: Disconnected from Steam Network!
    [The Paint Man 2013-02-28 13:34:46] WARN: Disconnected from Steam Network!
    [The Paint Man 2013-02-28 13:35:07] WARN: Disconnected from Steam Network!
    [The Paint Man 2013-02-28 13:35:28] WARN: Disconnected from Steam Network!
    [The Paint Man 2013-02-28 13:35:30] ERROR: Login Error: AccountLogonDenied
    [The Paint Man 2013-02-28 13:35:30] INTERFACE: This account is protected by Stea
    m Guard.  Enter the authentication code sent to the proper email:
    (removed for security)
    [The Paint Man 2013-02-28 13:36:04] WARN: Disconnected from Steam Network!
    [The Paint Man 2013-02-28 13:36:07] SUCCESS: User Authenticated!
    [The Paint Man 2013-02-28 13:36:19] SUCCESS: Schema Downloaded!
    [The Paint Man 2013-02-28 13:36:19] SUCCESS: Steam Bot Logged In Completely!
    did not find the JSON.
    Downloaded JSON... Parsing..

    Unhandled Exception: System.NullReferenceException: Object reference not set to
    an instance of an object.
   at SteamBot.SimpleUserHandler.OnMessage(String message, EChatEntryType type)
in c:\Users\wesley\Documents\TfShop\SteamBot\SimpleUserHandler.cs:line 84
   at SteamBot.Bot.<HandleSteamMessage>b__9(FriendMsgCallback callback) in c:\Us
ers\wesley\Documents\TfShop\SteamBot\Bot.cs:line 294
   at SteamKit2.CallbackMsg.Handle[T](Action`1 handler) in c:\Users\wesley\Docum
ents\TfShop\Lib\SteamKit2\SteamKit2\Steam3\SteamClient\CallbackMgr\CallbackMsg.c
s:line 72
   at SteamBot.Bot.HandleSteamMessage(CallbackMsg msg) in c:\Users\wesley\Docume
nts\TfShop\SteamBot\Bot.cs:line 283
   at SteamBot.Bot.<.ctor>b__0() in c:\Users\wesley\Documents\TfShop\SteamBot\Bo
t.cs:line 120
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionCo
ntext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, C
ontextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, C
ontextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
Press any key to continue . . .

Where line 84 is AddFriend(check.SteamID) Also, when I call the AddFriend inside of my OnJSONGet, it spits our SteamIDs in the STEAM_ format, where in my json it is in the 64 bit community url format.

Any help would be great!

gamemaster1494 commented 11 years ago

Kind of hard to say since there isn't a lot of code to go off of. What does the JSON return? According to the error, an object was referenced when it wasn't initilized, like Check = new SteamID(); Maybe something to do with this line:

SteamID = new SteamID((ulong)o["SteamID"]);

You cannot have a variable be named the same as a class, or it screwed it up. Just try like SteamID x = blah blah and see if it fixes it. If so, thats what happened.