Travian3 Beyond - ML&CN

By ms99 Last update Feb 4, 2010 — Installed 6,059,682 times.

HOTFIX to travian beyond Distance Table Errors

in
Subscribe to HOTFIX to travian beyond Distance Table Errors 4 posts, 2 voices



dreamx87 User
FirefoxWindows

So everyone knows that the current script does not display time table information correctly. This is a little hotfix i added to the script that you can put to temporarily fix the problem. But before i provide you with the actual fix i would like to point out what exactly are the problems that i have found and how you can fix them yourself if you would like to delve more into the realm of programming and spend the next 4 hours like i did finding a solution to this sixteen-thousand five-hundred and sixty-two line script ^_^(worded for effect).

TECHNICAL Explanation (Advanced users):
Upon examination of the file i determined several things from the code. a) the distance function was not working properly because the village coordinates of the active village (from here on known as 'var actV') were either not being stored properly or were being overwritten. On further inspection of the code i was able to determine that on line 9712 in the function 'getActiveVillage()' a 'try()' was being called to make sure data being extracted was in the correct format to be saved into the var 'actV' via the following call 'actV = new xVillage(Vname... x, y, vHref);' however, due to the fact that upon extracting data via the call 'v[2] = getNewdidFromLink(v[5].href)' always returns an error (i don't understand exactly how this call works, all i know is it tries to pull the unique village ID from the href), the catch element was always being executed calling the function 'getActiveVillageFromCookie()'. Now while this should have corrected the information if the cookie data was correct there are several notable problems with this.

a)The way data is stored in the cookie has changed
b)Data extraction method from the cookie is outdated and provides incorrect data.

therefore, because the cookie data being extracted is wrong and invalid, and there is no test currently implemented to ensure that the cookie data is valid it assigns these values and you see them as 400|NaN.

So, to curb these errors I disabled the 'v[2]' by commenting it out as it really isn't crucial to the script execution, passed v[2] with an empty value and placed notices on the calls to the 'GetActiveVillageFromCookie()' so the user knows when the village information is being loaded from this function and why it was loaded from it. This allows the script to load as normal and retrieve village information without attempting to pull the Unique Village ID, and leaves it blank.

So the code looks like this:

//changes by dreamx87
//get the active village from the villageList
//With the new travian versions, v[2] implementation is either no longer supported or written in an invalid form
//v2 has been commented out until a fix is found, as i currently don't understand much about v2 except that it holds
//the unique village ID. For what uses in this script is to be determined by other users because i already did alot of
//searching on my freetime. Removing the v[2] Unique ID implementation seems to be a good short term fix.
function getActiveVillage() {
var aV = $xf("//td[@class='dot hl'] | //div[@id='vlist']//table[@class='vlist']//tr[@class='sel']//a | //a[@class='active_vl']/../../td/table/tbody/tr/td");
var v = ['', '', '', -1000, -1000, ''];
if (aV) {

try {
if (TB3O.M35 == 2) {
var tr = aV.parentNode;
if (tr.cells.length > 3) {
v[3] = tr.cells[2].textContent.replace("(", "");
v[4] = tr.cells[4].textContent.replace(")", "");
v[1] = xy2id(v[3], v[4]);
v[0] = tr.cells[1].textContent;
v[5] = tr.cells[1].firstChild;
//v[2] = getNewdidFromLink(v[5].href);

} else {

var tmpC = tr.cells[2].textContent.replace("(", "").replace(")", "").split("|");
v[3] = parseInt(tmpC[0]);
v[4] = parseInt(tmpC[1]);
v[1] = xy2id(v[3], v[4]);
v[0] = tr.cells[1].textContent;
v[5] = tr.cells[1].firstChild;
//v[2] = getNewdidFromLink(v[5].href);

};
} else if (TB3O.M35 == 0) {
v[3] = aV.textContent.replace("(", "");
aV = $xf('//a[@class="active_vl"]/../../td/table/tbody/tr/td[3]');
v[4] = aV.textContent.replace(")", "");
v[1] = xy2id(v[3], v[4]);
v[5] = $xf('//a[@class="active_vl"]');
if (v[5]) v[0] = v[5].textContent;
//v[2] = getNewdidFromLink(v[5].href);
} else if(TB3O.M35 == 1) {
v[3] = aV.parentNode.parentNode.cells[2].textContent.replace("(", "");
v[4] = aV.parentNode.parentNode.cells[4].textContent.replace(")", "");
v[1] = xy2id(v[3], v[4]);
v[0] = aV.textContent;
v[5] = aV;
//v[2] = getNewdidFromLink(v[5].href);

};
//this assignment statement was not executing because of faulty v[2] assignemnt and immediate catch
actV = new xVillage(v[0], v[1], v[2], v[3], v[4], v[5].href);

} catch(e) {
//this catch was always executing, as v[2] always throws an error
getActiveVillageFromCookie();
alert("@line 9762 getActiveVillageFromCookie() was called because an exception was thrown while retreiving village information and is not working properly. Village data from cookies is stored in a new format and must be updated.");
};
} else
{
getActiveVillageFromCookie();
alert("@line 9766 getActiveVillageFromCookie() was called because no village information was retrievable by normal means and is not working properly. Village data stored in cookies is in a new format and must be updated.");
}
v = null; aV = null;

//THIS FUNCTION IS ALSO CAUSING ERRORS
//when you load from the cookie the order is outdated and needs to be corrected as the information being loaded
//does not pertain to the village in any shape or form.
function getActiveVillageFromCookie() {
//this was a quick test to verify my findings. Upon printing, values irrelevant to the required fields
//were output by the system. Therefore, the way the cookie file is being stored must have been altered.
//you may remove the comments for further testing. But be sure to disable it afterwards, as the prints are
//highly annoying.
//for (var counter_temp = 0; counter_temp <= 5; counter_temp++)
//{
// alert("TB3O.U[" + counter_temp + "]: " + TB3O.U[counter_temp]);
//}
alert("getActiveVillageFromCookie() is a critical function and should not be disabled. Just be aware that the current data is invalid due to the new form in which cookies are stored.");
var xy = id2xy(TB3O.U[4]);

actV = new xVillage(TB3O.U[2], TB3O.U[4], TB3O.U[5], xy[0], xy[1], 'dorf1.php?newdid=' + TB3O.U[5]);
xy = null;
};
};

Down to Earth Explanation (The average Joe):
Each village has a uniqueID that identifies it on the server. The script attempts to extract this id from the hyperlink but fails because of changes to the way travian is implemented. Commenting out these portions in the code allows for village information to be retrieved without causing additional errors. Furthermore, the way that travian handles the cookies has been changed and since the format is different the attempts to extract information from these cookies by the script was causing errors, so I put notices on the script if you do end up loading the coords from the cookie (which isn't very common) so you can know in advance (although this should be obvious by the sight of (400|NaN) and distances not computing. See code above for actual changes, if you are familiar with editing code replace the above functions with the code you see.

 
dreamx87 User
FirefoxWindows

//here is a cleaner form. easier to see.
//get the active village from the villageList
//With the new travian versions, v[2] implementation
//is either no longer supported or written in an invalid form
//v2 has been commented out until a fix is found, as i currently
//don't understand much about v2 except that it holds
//the unique village ID. For what uses in this script is to be
//determined by other users because i already did alot of
//searching on my freetime. Removing the v[2] Unique ID
//implementation seems to be a good short term fix.
function getActiveVillage() {
var aV = $xf("//td[@class='dot hl'] | //div[@id='vlist']//table[@class='vlist']//tr[@class='sel']//a | //a[@class='active_vl']/../../td/table/tbody/tr/td");
var v = ['', '', '', -1000, -1000, ''];
if (aV) {

try {
if (TB3O.M35 == 2) {
var tr = aV.parentNode;
if (tr.cells.length > 3) {
v[3] = tr.cells[2].textContent.replace("(", "");
v[4] = tr.cells[4].textContent.replace(")", "");
v[1] = xy2id(v[3], v[4]);
v[0] = tr.cells[1].textContent;
v[5] = tr.cells[1].firstChild;
//v[2] = getNewdidFromLink(v[5].href);

} else {

var tmpC = tr.cells[2].textContent.replace("(", "").replace(")", "").split("|");
v[3] = parseInt(tmpC[0]);
v[4] = parseInt(tmpC[1]);
v[1] = xy2id(v[3], v[4]);
v[0] = tr.cells[1].textContent;
v[5] = tr.cells[1].firstChild;
//v[2] = getNewdidFromLink(v[5].href);

};
} else if (TB3O.M35 == 0) {
v[3] = aV.textContent.replace("(", "");
aV = $xf('//a[@class="active_vl"]/../../td/table/tbody/tr/td[3]');
v[4] = aV.textContent.replace(")", "");
v[1] = xy2id(v[3], v[4]);
v[5] = $xf('//a[@class="active_vl"]');
if (v[5]) v[0] = v[5].textContent;
//v[2] = getNewdidFromLink(v[5].href);
} else if(TB3O.M35 == 1) {
v[3] = aV.parentNode.parentNode.cells[2].textContent.replace("(", "");
v[4] = aV.parentNode.parentNode.cells[4].textContent.replace(")", "");
v[1] = xy2id(v[3], v[4]);
v[0] = aV.textContent;
v[5] = aV;
//v[2] = getNewdidFromLink(v[5].href);

};
//this assignment statement was not executing because of
//faulty v[2] assignemnt and immediate catch
actV = new xVillage(v[0], v[1], v[2], v[3], v[4], v[5].href);

} catch(e) {
//this catch was always executing,
//as v[2] always throws an error
getActiveVillageFromCookie();
alert("@line 9762 getActiveVillageFromCookie() was called because an exception was thrown while retreiving village information and is not working properly. Village data from cookies is stored in a new format and must be updated.");
};
} else
{
getActiveVillageFromCookie();
alert("@line 9766 getActiveVillageFromCookie() was called because no village information was retrievable by normal means and is not working properly. Village data stored in cookies is in a new format and must be updated.");
}
v = null; aV = null;

//THIS FUNCTION IS ALSO CAUSING ERRORS
//when you load from the cookie the order is outdated
//and needs to be corrected as the information being loaded
//does not pertain to the village in any shape or form.
function getActiveVillageFromCookie() {
//this was a quick test to verify my findings.
//Upon printing, values irrelevant to the required fields
//were output by the system. Therefore, the way the cookie
//file is being stored must have been altered.
//you may remove the comments for further testing. But be
//sure to disable it afterwards, as the prints are
//highly annoying.
//for (var counter_temp = 0; counter_temp <= 5; counter_temp++)
//{
// alert("TB3O.U[" + counter_temp + "]: " + TB3O.U[counter_temp]);
//}
alert("getActiveVillageFromCookie() is a critical function and should not be disabled. Just be aware that the current data is invalid due to the new form in which cookies are stored.");
var xy = id2xy(TB3O.U[4]);

actV = new xVillage(TB3O.U[2], TB3O.U[4], TB3O.U[5], xy[0], xy[1], 'dorf1.php?newdid=' + TB3O.U[5]);
xy = null;
};
};

 
dreamx87 User
FirefoxWindows

after further testing I determined that the system calls 'getActiveVillageFromCookie()' when you only have 1 village rather than going through the full set of checks. So removal of the alerts might be an alternative if you don't want to see error messages every time you click on the page.

dreamx87

 
URL User
FirefoxWindows

so..... how i fix it?