Some time ago I was planning to make a series of tutorials to explain how you can make your own bots for browser games. Now I’m finally starting with it :).
- Part 1: Understanding http requests.
- Part 2: Making http requests with C#.
- Part 3: Making your bot less detectable.
There are different ways to make a bot, in the “MyBot” tutorials I will explain how you can make a bot that uses http requests.
The first step to make when starting with a bot is playing the game in your browser and watching the http requests. There are many tools for this that you can use. The easiest method is using a Firefox plugin called Live HTTP Header. Or if you want to use a separate program you can use WireShark.
There are two types of http requests. The GET requests and the POST requests. While using one of the above tools you will see that most of the requests are a GET request.
A GET requests does nothing more then returning the data you requested. So when browsing through a site clicking some links, that will be GET requests.
A POST request does also return the data you requested just like the GET request but with a POST request you can also send data with the request. This is almost always used when you have to fill in a form. An example were this is used is by all the browser based games when you login by entering your username and password.
For an example of a GET request you can go to the following page while using one of the above tools. I’ll be using Live HTTP Headers in this tutorial. In Live HTTP headers you will see the following:
You see that the third line starts with GET. That means it’s a GET request. For a http GET request only two lines are really important and that is the GET request and the host.
GET /files/MyBotTutorial.html HTTP/1.1
The advantage of the addon Live HTTP headers is that it already combines those two lines to show the full address, see the first line. With these two lines you have all the information you need to create your own request. The other lines can also be interesting but are not needed at this point. I’ll explain some of them in later parts of the tutorial.
The second picture is a POST request. The request in the picture is from the browser game Grepolis when you try to train some units. For POST requests you will need some more information. Just like the GET requests you need information about the request itself and the host. When you use Live HTTP headers see the first line.
POST /game/building_barracks?action=build&town_id=00000&h=0CQWKifC HTTP/1.1
As explained earlier you can send data with a POST request. This is called the content. There are two lines that give information about this, the Content-Length and the content itself (last line).
The content contains a number of name-value pairs that are separated with the &-char.
This are the basics you need to know to work with http requests. In the next part of the tutorial I’ll explain how you can write C# code to make your own POST and GET requests.