2008年4月14日 星期一

Travian網頁遊戲 基本分析

我們發現,可以直接下載內嵌的"unx.js"內容,如下:

var timer = new Object();
var m = new Object();
var l = new Object();
var V = A();
var O = 0;
var auto_reload = 1;
var F = new Object();
function start() {
G("l1");
G("l2");
G("l3");
G("l4");
ak();
};
function Q() {
return new Date().getTime();
};
function A() {
return Math.round(Q() / 1000);
};
function Z(c) {
p = c.innerHTML.split(":");
aY = p[0] * 3600 + p[1] * 60 + p[2] * 1;
return aY;
};
function aa(s) {
if (s > -2) {
az = Math.floor(s / 3600);
an = Math.floor(s / 60) % 60;
af = s % 60;
t = az + ":";
if (an < 10) {
t += "0";
}
t += an + ":";
if (af < 10) {
t += "0";
}
t += af;
} else {
t = "<a href=\"#\" onClick=\"Popup(2,5); return false;\"><span class=\"c0 t\">0:00:0</span>?</a>";
}
return t;
};
function ak() {
for (i = 1;; i++) {
c = document.getElementById("tp" + i);
if (c != null) {
m[i] = new Object();
m[i].ad = c;
m[i].D = Z(c);
} else {
break;
}
}
for (i = 1;; i++) {
c = document.getElementById("timer" + i);
if (c != null) {
l[i] = new Object();
l[i].ad = c;
l[i].D = Z(c);
} else {
break;
}
}
J();
};
function J() {
for (i in m) {
o = A() - V;
U = aa(m[i].D + o);
m[i].ad.innerHTML = U;
}
for (i in l) {
o = A() - V;
ae = l[i].D - o;
if (O == 0 && ae < 1) {
O = 1;
if (auto_reload == 1) {
setTimeout("document.location.reload()", 1000);
} else if (auto_reload == 0) {
setTimeout("k()", 1000);
}
} else {}
U = aa(ae);
l[i].ad.innerHTML = U;
}
if (O == 0) {
window.setTimeout("J()", 1000);
}
};
function G(f) {
c = document.getElementById(f);
if (c != null) {
F[f] = new Object();
var celm = c.innerHTML.match(/(\d+)\/(\d+)/);
am = celm[0].split("/");
R = parseInt(am[0]);
K = parseInt(am[1]);
r = c.title;
if (r != 0) {
aq = Q();
timer[f] = new Object();
timer[f].start = aq;
timer[f].ar = r;
timer[f].R = R;
timer[f].K = K;
timer[f].aM = 3600000 / r;
H = 100;
if (timer[f].aM < H) {
timer[f].aM = H;
}
timer[f].ad = c;
P(f);
} else {
timer[f] = new Object();
F[f].value = R;
}
}
};
function P(f) {
o = Q() - timer[f].start;
if (o >= 0) {
T = Math.round(timer[f].R + o * (timer[f].ar / 3600000));
if (T >= timer[f].K) {
T = timer[f].K;
} else {
window.setTimeout("P('" + f + "')", timer[f].aM);
}
F[f].value = T;
timer[f].ad.innerHTML = T + '/' + timer[f].K;
}
};
var v = new Array(0, 0, 0, 0, 0);
function add_res(B) {
C = F['l' + (5 - B)].value;
I = haendler * carry;
v[B] = ap(v[B], C, I, carry);
document.getElementById('r' + B).value = v[B];
};
function upd_res(B, max) {
C = F['l' + (5 - B)].value;
I = haendler * carry;
if (max) {
L = C;
} else {
L = parseInt(document.getElementById('r' + B).value);
}
if (isNaN(L)) {
L = 0;
}
v[B] = ap(parseInt(L), C, I, 0);
document.getElementById('r' + B).value = v[B];
};
function ap(aj, X, M, aC) {
ab = aj + aC;
if (ab > X) {
ab = X;
}
if (ab > M) {
ab = M;
}
if (ab == 0) {
ab = '';
}
return ab;
};
function ai(n, d) {
var p,
i,
x;
if (!d) d = document;
if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
d = parent.frames[n.substring(p + 1)].document;
n = n.substring(0, p);
}
if (! (x = d[n]) && d.all) x = d.all[n];
for (i = 0; ! x && i < d.forms.length; i++) x = d.forms[i][n];
for (i = 0; ! x && d.layers && i < d.layers.length; i++) x = ai(n, d.layers[i].document);
return x;
};
function btm0() {
var i,
x,
a = document.ax;
for (i = 0; a && i < a.length && (x = a[i]) && x.at; i++) x.src = x.at;
};
function btm1() {
var i,
j = 0,
x,
a = btm1.arguments;
document.ax = new Array;
for (i = 0; i < (a.length - 2); i += 3) if ((x = ai(a[i])) != null) {
document.ax[j++] = x;
if (!x.at) x.at = x.src;
x.src = a[i + 2];
}
};
function Popup(i, j) {
c = document.getElementById("ce");
if (c != null) {
var aF = "<div class=\"popup3\"><iframe frameborder=\"0\" id=\"Frame\" src=\"manual.php?s=" + i + "&typ=" + j + "\" width=\"412\" height=\"440\" border=\"0\"></iframe></div><a href=\"#\" onClick=\"Close()\"><img src=\"img/un/a/x.gif\" border=\"1\" class=\"popup4\" alt=\"Close\"></a>";
c.innerHTML = aF;
}
};
function Close() {
c = document.getElementById("ce");
if (c != null) {
c.innerHTML = '';
}
};
function Allmsg() {
for (var x = 0; x < document.msg.elements.length; x++) {
var y = document.msg.elements[x];
if (y.name != 's10') y.checked = document.msg.s10.checked;
}
};
function xy() {
aZ = screen.width + ":" + screen.height;
document.snd.w.value = aZ;
};
function my_village() {
var aU = Math.round(0);
var aD;
var e = document.snd.dname.value;
for (var i = 0; i < df.length; i++) {
if (df[i].indexOf(e) > -1) {
aU++;
aD = df[i];
}
}
if (aU == 1) {
document.snd.dname.value = aD;
}
};
function map(aO, ao, aT, au, x, y) {
document.getElementById('x').firstChild.nodeValue = x;
document.getElementById('y').firstChild.nodeValue = y;
c = document.getElementById("tb");
if (c != null) {
if (au == '') {
au = '-';
}
var aR = "<table cellspacing='1' cellpadding='2' class='tbg f8'><tr><td class='rbg f8' colspan='2'></a>" + aO + "</td></tr><tr><td width='45%' class='s7 f8'>" + text_spieler + "</td><td class='s7 f8'>" + ao + "</td></tr><tr><td class='s7 f8'>" + text_einwohner + "</td><td class='s7 f8' id='aT'>" + aT + "</td></tr><tr><td class='s7 f8'>" + text_allianz + "</td><td class='s7 f8'>" + au + "</td></tr></table>";
var aN = "<table class='f8 map_infobox_grey' cellspacing='1' cellpadding='2'><tr><td class='c b' colspan='2' align='center'></a>" + text_details + "</td></tr><tr><td width='45%' class='c s7'>" + text_spieler + "</td><td class='c s7'>-</td></tr><tr><td class='c s7'>" + text_einwohner + "</td><td class='c s7'>-</td></tr><tr><td class='c s7'>" + text_allianz + "</td><td class='c s7'>-</td></tr></table>";
if (ao != '') {
c.innerHTML = aR;
} else {
c.innerHTML = aN;
}
}
};
function x_y(x, y) {
document.getElementById('x').firstChild.nodeValue = x;
document.getElementById('y').firstChild.nodeValue = y;
};
function pop(aQ) {
as = window.open(aQ, "map", "top=100,left=25,width=975,height=550");
as.focus();
return false;
};
var aS = document.getElementById ? 1: 0;
var bd = document.all ? 1: 0;
var ba = (navigator.userAgent.indexOf("Mac") > -1) ? 1: 0;
var ac = (bd && (!ba) && (typeof(window.offscreenBuffering) != 'undefined')) ? 1: 0;
var aJ = ac;
var bc = ac && (window.navigator.userAgent.indexOf("SV1") != -1);
function changeOpacity(aL, opacity) {
if (ac) {
aL.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + (opacity * 100) + ')';
} else if (aS) {
aL.style.MozOpacity = opacity;
}
};
var g = false;
function T_Load(url, id) {
g = false;
if (window.XMLHttpRequest) {
g = new XMLHttpRequest();
if (g.overrideMimeType) {
g.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) {
try {
g = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
g = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {}
}
}
if (!g) {
alert('Can not create XMLHTTP-instance');
return false;
}
g.onreadystatechange = function() {
al(id);
};
g.open('GET', url, true);
g.send(null);
};
function al(id) {
if (g.readyState == 4) {
if (g.status == 200) {
c = document.getElementById(id);
if (c != null) {
c.innerHTML = g.responseText;
}
} else {
alert('An error has occurred during request');
}
}
};
function k() {

param = 'reload=auto';
url = window.location.href;
if (url.indexOf(param) == -1) {
if (url.indexOf('?') == -1) {
url += '?' + param;
} else {
url += '&' + param;
}
}
document.location.href = url;
}

 


開始分析:



<body onload="start()">



這段的內容是什麼呢?


function start() {
G("l1");
G("l2");
G("l3");
G("l4");
ak();
};

仔細一看,才發現

<img class="res" src="img/un/r/4.gif" title="穀物"></td>
<td id=l1 title=16>745/800</td>


是根據table此id來做點什麼事情?

function G(f) {
c = document.getElementById(f);//c=此table框格物件
if (c != null) {
F[f] = new Object();
var celm = c.innerHTML.match(/(\d+)\/(\d+)/);
/ 上式根據正規表達式(WIKI)分析,中文化的說法就是 (若干數字 "/"符號 若干數字)的格式
am = celm[0].split("/");
R = parseInt(am[0]); //目前資源
K = parseInt(am[1]); //資源上限
r = c.title; //物件的產能(被暫存在此)
if (r != 0) {
aq = Q(); //<==============================function Q() { return new Date().getTime(); }; 取得時間用的
timer[f] = new Object(); //宣告一個新物件(此ID的資源用的)
timer[f].start = aq; //設定起始時間
timer[f].ar = r;//以下三行 複製各項資料
timer[f].R = R;
timer[f].K = K;
timer[f].aM = 3600000 / r; //3600秒除以每小時產能=>此為計算顯示的產量用的
H = 100;
if (timer[f].aM < H) { //如果秒數過小 改高一點
timer[f].aM = H;
}
timer[f].ad = c; //儲存整個框格物件
P(f); //<=====================================這裡開始進行某件事情,如下
} else {
timer[f] = new Object();
F[f].value = R;
}
}
};


unction P(f) {
o = Q() - timer[f].start; //目前時間扣掉開始時間
if (o >= 0) { //為正
T = Math.round(timer[f].R + o * (timer[f].ar / 3600000)); //目前資源量+=產能/小時*經過秒數 ==> 取近似整數
if (T >= timer[f].K) { //超過最大值則還原
T = timer[f].K;
} else {
window.setTimeout("P('" + f + "')", timer[f].aM); //在aM豪秒過後重新呼叫一次資源計算
}
F[f].value = T; //底下文字方塊顯示的產量
timer[f].ad.innerHTML = T + '/' + timer[f].K; //此物件顯示新的資源量
}
};


因此可以估計,重要的部分還是寫在裡面的 >0<

不過也只剩下運算之類的吧

0 留言:

張貼留言