visit_url() returning empty string only within relay script

zarqon

Well-known member
Am I missing something here?

I want to grab the Jarlsberg skills page for insertion into skills.php, via a skills.ash relay override script.

In the CLI it works:

> ash string page = visit_url("da.php?place=gate2"); page.length();

Returned: 13369

But when I visit skills.php, and it triggers skills.ash, which contains this:

PHP:
      case $class[avatar of jarlsberg]:
         page = visit_url("da.php?place=gate2");
         print("Jarlsberg page length: "+page.length());    // debug
         chunk.append(substring(page,index_of(page,"<body>")+6,last_index_of(page,"</body>")));
         break;

I only get this:

Jarlsberg page length: 0
Begin index 5 greater than end index -1 (skills.ash, line 39)

Any idea what's going on here? Nearly identical lines of code for Avatar of Boris (visiting da.php?place=gate1) were previously working. Using r11964.
 

Bale

Minion
zarqon, I'd very much like to see your skills.ash, especially after you get it working.

Good tip, lost.
 

zarqon

Well-known member
Thanks much lost, that was the solution. Now that it's visiting jarlskills.php, the whole skill tree thing is now in my Train Skills section.

Interesting to note that evidently visit_url() follows redirects unless called within a relay script.

@Bale: I've posted it before (more than once, if memory serves?) in the relay section of the forum. It's nothing extraordinary -- basically it just grabs the training forms from any relevant skill-trainers you can access and adds them to the page (guild, Hey Deze, Fragnk, graveyard, Boris' gate, and now Jarlsberg's gate). Nice to be able to perform skills and acquire them all from the same place.
 

Bale

Minion
Thank you. Found it. That's not really what I want though.

My desire is that when you finish this, I want to copy your code for Jarl's skills and make a kitchen.ash override that allows you to acquire and cast skills from the kitchen page. :)
 

Winterbay

Active member
Thank you. Found it. That's not really what I want though.

My desire is that when you finish this, I want to copy your code for Jarl's skills and make a kitchen.ash override that allows you to acquire and cast skills from the kitchen page. :)

Oh yes, that'd be great!
 

zarqon

Well-known member
My code for jarlsberg skills is almost nothing.

PHP:
case $class[avatar of jarlsberg]: page = visit_url("jarlskills.php");
         chunk.append(substring(page,index_of(page,"<body>")+6,last_index_of(page,"</body>")));
         break;

That grabs the entire skills-training bit, including the scripts that make it work (the entire page between the body tags, actually). I then simply insert that into the page:

PHP:
   results.append(visit_url());
   results.replace_string("<tr><td height=4></td></tr></table></center>", "<tr><td height=4></td></tr>"+chunk+"</table></center>");

Both chunk and results are buffers. I imagine the only thing you would need to change to add it to your kitchen is the string to replace with a chunk-ified version.
 

Bale

Minion
Sweet. I don't think I've got the spellcasting part of shop.php working quite right yet, but it's already helpful and maybe someone else can pick it up from here?

PHP:
void kitchen() {
	buffer page = visit_url("shop.php?whichshop=jarl");
	string jarlskills = visit_url("jarlskills.php");
	string cast = visit_url("skills.php");

	string chunk;

	// Add skill casting
	chunk = substring(cast, index_of(cast, "<body>")+6, index_of(cast, "</table><table")+8);
	page.insert(index_of(page, "<p><a href=campground.php>"), chunk);
	
	// Add jarlsberg's skill table
	chunk = substring(jarlskills, index_of(jarlskills, "<body>")+6, last_index_of(jarlskills, "</body>"));
	chunk = chunk.replace_string('<tr><td style="color: white;" align=center bgcolor=blue><b>Jarlsbergin\' Around</b></td></tr>', "");
	chunk = chunk.replace_string('<td style="padding: 5px; border: 1px solid blue;"', '<td style="padding: 5px;"');
	chunk = chunk.replace_string("<p><A href=da.php>Back to the Dungeoneer's Association</a>", "");
	page.insert(index_of(page, "<p><a href=campground.php>"), chunk);
	
	
	page.write();
}

void main() {
	if(form_field("whichshop") == "jarl" && form_field("cookbook") != "1")
		kitchen();
}
 
Last edited:

Bale

Minion
Fixed a couple of bugs in shop.ash, most notably being able to buy stuff.

PHP:
buffer visit_shop() {
	buffer url;
	url.append("shop.php?whichshop=");
	url.append(form_field("whichshop"));
	foreach name in $strings[cookbook, action, whichitem, quantity]
		if(form_field(name) != "") {
			url.append("&");
			url.append(name);
			url.append("=");
			url.append(form_field(name));
		}
	return visit_url(url);
}

void add_info(buffer page, string info) {
	page.insert(index_of(page, "<p><a href=campground.php>"), info);
}

void kitchen() {
	buffer page = visit_shop();
	string jarlskills = visit_url("jarlskills.php");
	string cast = visit_url("skills.php");

	string chunk;

	chunk = substring(cast, index_of(cast, "<body>")+6, index_of(cast, "height=4></td></tr></table>")+27);
	page.add_info(chunk);
	
	chunk = substring(jarlskills, index_of(jarlskills, "<body>")+6, last_index_of(jarlskills, "</body>"));
	chunk = chunk.replace_string('<tr><td style="color: white;" align=center bgcolor=blue><b>Jarlsbergin\' Around</b></td></tr>', "");
	chunk = chunk.replace_string('<td style="padding: 5px; border: 1px solid blue;"', '<td style="padding: 5px;"');
	chunk = chunk.replace_string("<p><A href=da.php>Back to the Dungeoneer's Association</a>", "");
	page.add_info(chunk);
	
	
	page.write();
}

void main() {
	if(form_field("whichshop") == "jarl")
		kitchen();
}

Can anyone tell me how to get the result of casting skills to respond ajax style instead of loading the skills page? Preferably right below the skill summoning box.
 

zarqon

Well-known member
In reference to my original problem: does anyone have any idea how to work around visit_url() not following redirects from a relay script? In the above case I simply used the target URL, but in cases where it can't be known beforehand, is there some way to discover the target from within ASH?

As an exercise I was adding a Wiki tab to BatMan RE which would load the Wiki page for that monster into itself when clicked. I found it impossible, however, as an all-purpose URL (based on the search form) results in redirects (page length: 0) from within a relay script, and AJAXing it in directly (without ASH as a go-between) won't work due to the same origin policy.

Any suggestions?

If there isn't a way to somehow fetch the target page, I could just include a CLI link which would trigger mafia's "wiki such-and-such" command, but I liked the idea of integrating it into the fight page a bit more.
 

Catch-22

Active member
It was already "done", just not very well. I can say that because I was the one who provided the patch :p

When I patched GenericRequest I think I assumed that RelayRequest would handle the redirects on it's own but I guess I never tried it.
 
Top