Bug - Not A Bug Train Set cannot be configured in relay browser

Linknoid

Member
When I try to play with my train set, the Save Train Set Configuration button resets everything, discarding my changes. I tried it through a different browser (first Edge, then Firefox), and it behaved the same. I tried logging into KoL directly, and I was able to make changes to the train configuration. I'm surprised that nobody else has reported this. I'm running 26993.
 

Linknoid

Member
I figured out the source. It's not a bug in KoL, it's an ash script I have in my relay folder. I found that out creating a fresh copy of KoLmafia, and then copying files in the relay directory one by one until it broke.

To reproduce, put the following in relay/campground.php:

void main()
{
string page = visit_url();
// Do some page manipulation related to mushroom garden
write(page);
}

Any suggestions on how to avoid breaking the train set?
 

Veracity

Developer
Staff member
I already had a campground.ash relay script, but I adjusted it:
Code:
void main()
{
    if (my_path() == "Actually Ed the Undying") {
    visit_url( "place.php?whichplace=edbase", false ).writeln();
    }
    else {
    string page = visit_url();
    write(page);
    }
}

DEBUG log:

Code:
Starting relay script: campground.ash
class net.sourceforge.kolmafia.request.RelayRequest
Connecting to campground.php...

Requesting: https://www.kingdomofloathing.com/campground.php?action=workshed
Retrieved: https://www.kingdomofloathing.com/campground.php?action=workshed
Field: location = [choice.php?forceoption=0]

Starting relay script: choice.ash
class net.sourceforge.kolmafia.request.RelayRequest
Connecting to choice.php...

Retrieved: https://www.kingdomofloathing.com/choice.php?forceoption=0
Retrieving server reply
ResponseText has 39331 characters.
Processing results...
Finished relay script: choice.ash (40239 bytes)
Finished relay script: campground.ash (40239 bytes)

---------------
Moved scale models around.
That was all Javascript, so no requests were submitted.
---------------

Starting relay script: campground.ash
class net.sourceforge.kolmafia.request.RelayRequest
Connecting to campground.php...

Requesting: https://www.kingdomofloathing.com/campground.php?action=workshed&whichchoice=1485&option=1&pwd&slot[0]=2&slot[1]=7&slot[2]=19&slot[3]=16&slot[4]=14&slot[5]=1&slot[6]=8&slot[7]=3
Retrieved: https://www.kingdomofloathing.com/campground.php?action=workshed&whichchoice=1485&option=1&pwd&slot[0]=2&slot[1]=7&slot[2]=19&slot[3]=16&slot[4]=14&slot[5]=1&slot[6]=8&slot[7]=3
Field: location = [choice.php?forceoption=0]

Starting relay script: choice.ash
class net.sourceforge.kolmafia.request.RelayRequest
Connecting to choice.php...

Retrieved: https://www.kingdomofloathing.com/choice.php?forceoption=0
Retrieving server reply
ResponseText has 39331 characters.
Processing results...
Finished relay script: choice.ash (40239 bytes)
Finished relay script: campground.ash (40239 bytes)

Browser submits request for campground.php?action=workshed.
That invokes campground.ash, which does visit_url()
That redirects to choice.php?forceoption=0
That invokes choice.ash, which does visit_url()
It's not interested in that choice, so it does write(page)

I assume that is what campground.ash gets as its page.
campground.ash does a write(page)

I think I need to turn on browser interaction logging.
That page is really difficult to understand; the image of each model piece is there about 8 times.
 

Veracity

Developer
Staff member
I wonder if the campground.php with arguments is submitted with GET when it should be POST (or vice versa)?
 

Veracity

Developer
Staff member
There's definitely something wrong.
I have campground.ash and choice.ash
I made both of them no-ops - the return without making a request - and here is the sequence of requests sent by the browser:

Code:
-----From Browser-----
GET /campground.php HTTP/1.1
Starting relay script: campground.ash
Finished relay script: campground.ash (0 bytes)
Requesting: https://www.kingdomofloathing.com/campground.php
-----From Browser-----
GET /campground.php?action=workshed HTTP/1.1
Starting relay script: campground.ash
Finished relay script: campground.ash (0 bytes)
Requesting: https://www.kingdomofloathing.com/campground.php?action=workshed
-----From Browser-----
GET /choice.php?forceoption=0 HTTP/1.1
Starting relay script: choice.ash
Finished relay script: choice.ash (0 bytes)
Requesting: https://www.kingdomofloathing.com/choice.php?forceoption=0
-----From Browser-----
POST /choice.php?forceoption=0 HTTP/1.1
whichchoice=1485&option=1&pwd&slot%5B0%5D=2&slot%5B1%5D=7&slot%5B2%5D=19&slot%5B3%5D=16&slot%5B4%5D=14&slot%5B5%5D=0&slot%5B6%5D=8&slot%5B7%5D=0
Starting relay script: choice.ash
Finished relay script: choice.ash (0 bytes)
Requesting: https://www.kingdomofloathing.com/choice.php?forceoption=0&whichchoice=1485&option=1&pwd&slot[0]=2&slot[1]=7&slot[2]=19&slot[3]=16&slot[4]=14&slot[5]=0&slot[6]=8&slot[7]=0
-----From Browser-----
POST /choice.php?forceoption=0 HTTP/1.1
whichchoice=1485&option=1&pwd&slot%5B0%5D=2&slot%5B1%5D=7&slot%5B2%5D=19&slot%5B3%5D=16&slot%5B4%5D=14&slot%5B5%5D=3&slot%5B6%5D=8&slot%5B7%5D=1
Starting relay script: choice.ash
Finished relay script: choice.ash (0 bytes)
Requesting: https://www.kingdomofloathing.com/choice.php?forceoption=0&whichchoice=1485&option=1&pwd&slot[0]=2&slot[1]=7&slot[2]=19&slot[3]=16&slot[4]=14&slot[5]=3&slot[6]=8&slot[7]=1

Investigating.
 

Veracity

Developer
Staff member
OK.

1) The browser submits campground.php?action=workshed
2) Relay script campground.ash gets called. It submits the request to KoL.
3) KoL redirects to choice.php?forceoption=0
4) We follow the redirect and get the page.
-- KoL and KoLmafia believe/know we are in choice.php
5) Relay script returns the page and KoL sends it down to the browser
-- The browser did not see/submit the redirect to choice.php, so it believes it is in campground.php
6) When you rearrange the models and click the "Save Configuration" button, the browser appends the form fields to "campground.php?action=workshed"
-- If you had let the browser handle the redirect itself, it would append them to "choice.php?forceoption=0". Which is sort of weird, but KoL handles it fine.

You have campground.ash.
That is called when we are about to submit a request to campground.php.
Your script can do visit_url() to submit that request.
Your script knows what URL that will be:

string get_path() -> "campground.php"
string get_path_full() -> "camground.php?action=workshed"
string get_path_variables() -> "action=workshed"

You want to manipulate the mushroom garden? Only do that if get_path_full() is "campground.php". I.e., if you are looking at the whole campground. If you are not doing that, return without doing visit_url()/write()

My other conclusion is if you want a relay script that actually manipulates the train set, is has to be in choice.ash, not a campground.ash.
Or choice.1485.ash if you are using Ezandora's Choice Override framework.
 
Top