[原创]编写 Travian 扫田器

近期没事干,玩了一会儿网页游戏,travian,玩的是 speed 服的,因为普服的速度没意思。
里面涉及到一个话题,就是扫田。

田不象绿洲,开图即现,而是要非得点进去才能看得见,再者,对于大量造兵者,没有田就会饿死人,因此,田也就成了一个争夺的目标。

下面我们看一下如何写一个扫田器。

首先,你得在任何一个服注册一个帐号,这个要求太简单了,但是要注意,以下我们要做的就用这个帐号,这个帐号如果没有意外,肯定会在你用完之后被封。

 

1.写一个程序,登录进这个服务器。

这个要求很简单。因为我目前使用 C# 所以以 speed.travian.cn 说一下方法,

 

 

using System.Net;
using System.IO;
using System.Text.RegularExpressions;


 

这很重要,.Net 中有对网络有用的地东西,IO在操作 Stream 上提供支持,而RegularExpressions则是正则表达式的了。

然后,

 

           WebClient client = new WebClient();
            client.Encoding 
= System.Text.Encoding.UTF8;
           
string  source = client.DownloadString(@"Http://speed.travian.cn/login.php");

如此就可以得知登录页面的代码,因为里面有几处是几个随机值,要提交的,包括几个input 的 name 。

 得到的 source 就是网页的源代码。

如前面几贴提到,如果要使用代理,则

 

        WebProxy wp = new WebProxy("125.125.125.125:8080");   //当然,这个IP是假的,代理的IP网上到处都是,随便找个就有。

        wp.BypassProxyOnLocal 
= false;

         client.Proxy 
= wp;

这样就实现代理访问了。

 

得到 source 之后,即可对其进行分析。

为了方便,去掉所有的 " 号,因为这个东西处理起来很麻烦。

 

           source = source.Replace("\"","");

接下来根据正则表达式取得登录的内容。

            Regex rloginName = new Regex(@"name=login value=\w*");
            Match mloginName 
= rloginName.Match(source);
            
if (mloginName.Success)   {  loginName = mloginName.ToString().Replace(@"name=login value="""); }
            Regex rloginPassword 
= new Regex(@"type=password name=\w*");
            Match mloginPassword 
= rloginPassword.Match(source);
            
if (mloginPassword.Success) {  loginPassword = mloginPassword.ToString().Replace(@"type=password name=""");  }
            Regex rloginUsername 
= new Regex(@"input class=fm fm110 type=text name=\w*");
            Match mloginUsername 
= rloginUsername.Match(source);
            
if (mloginUsername.Success) { loginUsername = mloginUsername.ToString().Replace(@"input class=fm fm110 type=text name=",""); }
            Regex rloginRand 
= new Regex(@"<p align=center><input type=hidden name=\w*");
            Match mloginRand 
= rloginRand.Match(source);
            
if (mloginRand.Success)  { loginrand = mloginRand.ToString().Replace("<p align=center><input type=hidden name=",""); }
            
//
            postString = @"w=1024:768&login=" + loginName + "&" + loginUsername + "="+txtUserName.Text+"&" + loginPassword + "=" +txtPassword.Text+"&" + loginrand + "=&s1.x=10&s1.y=10&s1=login";
            WebRequest req
=WebRequest.Create(@"http://speed.travian.cn/dorf1.php");
            req.ContentType 
= "application/x-www-form-urlencoded";
            req.Method 
= "POST";
            
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(postString);
            req.ContentLength 
= bytes.Length;
            req.ContentLength 
= bytes.Length;
            Stream os 
= req.GetRequestStream();
            os.Write(bytes, 
0, bytes.Length);
            os.Close();
            WebResponse resp 
= req.GetResponse();
            StreamReader sr 
= new StreamReader(resp.GetResponseStream());

 

好了,提交的字符串是poststring, sr 就是登录之后的村庄主页的详细内容了。当然,还是页面源码。

其实此处有没有这个源码意义不大,因为我们此处的目的在于扫田,(我另外一个程序中有取这些信息进行一些自动建筑之类)

 

接下来,我们开始进行扫田了。

travian 的地图是一个方形地图,左上角是 (-400,400)右下解是 400,-400)每个格子一直加过去即可,构造好相应的 URL ,直接访问,得到源码后根据一个 <div id="f6"></div>类似的东西就可以得出是多少田的了,比如说, f6 是 15田的。其特点是一个字母后加一个数字,正则表达式为 <div id=\w\d></div> (我讨厌"号)
接下来没什么技术难度了,开50个线程,一个格子一个格子扫过去。


 

因为此方法将大幅影响服务器的响应,所以,就不发布这个害人的东西了。

posted on 2007-11-05 13:06  qufo  阅读(6021)  评论(18编辑  收藏  举报

导航