Problem with bot development (Cookies)

01/24/2010 16:31 Utharnl#1
Hey all, got a question for the other bot developers here.
Was trying to make a small bot for Grepolis (Building queue only).

I created my other bots with C#, using httpget and httppost requests. That way I can easily get the cookies from the response header (Set-Cookie).

But now comes the problem...
The developers of Grepolis found a way to set cookies without Set-Cookie. Looks like they use java script for it.

The cookie called PHPSESSID is still set using Set-Cookie but portal_tid is not.
To login on the server I need both cookies :(

Someone that can help me with it?
Or if you want to try it yourself to make a bot that can login on this game:
[Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]

Greetings Uthar
01/24/2010 16:51 jere88#2
Hey,

I think you are in the wrong section.
Maybe you can ask in the Coding Section for help

[Only registered and activated users can see links. Click Here To Register...]
01/24/2010 20:32 Atheuz#3
Quote:
Originally Posted by Utharnl View Post
Hey all, got a question for the other bot developers here.
Was trying to make a small bot for Grepolis (Building queue only).

I created my other bots with C#, using httpget and httppost requests. That way I can easily get the cookies from the response header (Set-Cookie).

But now comes the problem...
The developers of Grepolis found a way to set cookies without Set-Cookie. Looks like they use java script for it.

The cookie called PHPSESSID is still set using Set-Cookie but portal_tid is not.
To login on the server I need both cookies :(

Someone that can help me with it?
Or if you want to try it yourself to make a bot that can login on this game:
[Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]

Greetings Uthar
Login1
PHP Code:
http://de.grepolis.com/start/?action=ajax_played_worlds&name=derp&password=hurp 
This will retrieve the set of worlds the account has access to.

Login2
PHP Code:
http://de.grepolis.com/start?action=login
world=4&facebook_login=&name=derp&password=hurp 
This actually logs a player in, including the session_id in the response.

PHP Code:
http://de4.grepolis.com/game/login?session_id=1fl802syva2s 
Simply use the session id from now on you got from the response.


In my testing I was able to retrieve the session id perfectly and without to use any other part of the cookie for the rest of the requests. You have to crawl the response html though for valueable information.
01/24/2010 23:37 Utharnl#4
Thanks Atheuz, but how did you test it?
Because I'm having problems with the second login (Probably because I'm missing a cookie?)

PHP Code:
http://nl.grepolis.com/start?action=login
world=1&facebook_login=&name=Uthar&password=Utharpw 
The response I get from the second login is:
The remote server returned an error: (417) Expectation Failed.

-edit-
Previous error fixed by adding
Code:
System.Net.ServicePointManager.Expect100Continue = false;
Trying to get session_id now, will keep you updated

~Uthar
01/25/2010 16:23 Die Schnittstelle#5
#moved
01/25/2010 20:51 Utharnl#6
Thanks for moving it to the correct section Mio.

I can't get it to work with my current htmlhandler.
The location header:
Code:
Location: http://nl1.grepolis.com/game/login?session_id=d64ma2eqtts0
Is causing an auto redirect and my code can't get that response.

I'm using the class "System.Net.WebRequest" for my requests. Does anybody know if I can turn of the auto redirection?

After some research I found that the class HttpWebRequest has the option to turn auto redirection of. If it isn't possible to turn it of with "System.Net.WebRequest" I could always rewrite my code and use HttpWebRequest.


-edit-
Looks like I can just cast it to an HttpWebRequest :)
Code:
HttpWebRequest l_Req = (HttpWebRequest)WebRequest.Create(p_URI);
l_Req.AllowAutoRedirect = false;
Going to try again now to see if it works, will let you know when I'm stuck again.




//edit :


I'm almost done with the login process, stuck at the last step now.

Successfully called "http://nl1.grepolis.com/game/login?session_id=4r5anyvv32m8" and retrieved some cookies.

The final step of the login process is to visit "http://nl1.grepolis.com/game/index" but I get only a empty page as response with a Location header that contains:
"http://nl.grepolis.com/start?nosession"

I can simulate a location header with "http://nl.grepolis.com/start?nosession" in a normal browser by logging in with cookies turned off.

Does someone want to give it a try to write some code to login on this game?
I have no idea what goes wrong, any help/tips are welcome!

Greetings Uthar
01/26/2010 00:13 Cholik#7
Okay just wrote some stuff...

[Only registered and activated users can see links. Click Here To Register...]

Hope I could help you.
01/26/2010 01:19 Utharnl#8
Thanks Walter,
Used WireShark to check the http request your code send, was almost the same as my code.
Changed my code a bit so that the requests were the same, but still not working.

It looks like the Location header is causing the problem.
Because your class saves cookies automatic you can follow the Location header without any problems.
In my case I have to visit each location in the Location header manually because my cookies are lost otherwise.

Somewhere there is a small difference in how I do it manually and how your class does it automatic. No idea what ^^

But I must say it looks a lot easier to use the class WebClient like you.
I think I will give that a try tomorrow.


//edit
Thanks for the help, I have it working now.
Here is the link to the bot:
[Only registered and activated users can see links. Click Here To Register...]

~Uthar