I traced the execution flow during an automated jump-into-gash in r20645. To do so, I set up some breakpoints in IntelliJ and ascended by executing the JavaScript statement
visitUrl('ascend.php?action=ascend&pwd&confirm=on&confirm2=on')
.
I discovered that KoLmafia had two places where it
could have updated the
inValhalla
flag (stored in
CharPaneRequest.inValhalla
), but did not.
First, KoLmafia called
AfterLifeRequest.parseResponse()
to parse the
ascend.php request. See the stack trace from IntelliJ debugger:
Code:
parseResponse:71, AfterLifeRequest (net.sourceforge.kolmafia.request)
parseResults:2822, GenericRequest (net.sourceforge.kolmafia.request)
processResponse:2658, GenericRequest (net.sourceforge.kolmafia.request)
retrieveServerReply:2566, GenericRequest (net.sourceforge.kolmafia.request)
retrieveServerReply:2114, GenericRequest (net.sourceforge.kolmafia.request)
externalExecute:1672, GenericRequest (net.sourceforge.kolmafia.request)
execute:1655, GenericRequest (net.sourceforge.kolmafia.request)
run:1365, GenericRequest (net.sourceforge.kolmafia.request)
postRequest:300, RequestThread (net.sourceforge.kolmafia)
postRequest:250, RequestThread (net.sourceforge.kolmafia)
visit_url:2992, RuntimeLibrary (net.sourceforge.kolmafia.textui)
visit_url:2944, RuntimeLibrary (net.sourceforge.kolmafia.textui)
However, the code at
line 78 caused it to do nothing:
Java:
// If this is our first visit to the afterlife - we are outside
// the pearly gates - refresh the charpane
if ( urlString.equals( "afterlife.php" ) )
{
return true;
}
You can see the HTML response in
response-ascend.php.txt
, attached at the bottom of this post.
Second, while parsing the
ascend.php request, KoLmafia attempted to retrieve
api.php to update the player status. I forgot to copy the stack trace from this one, but it's roughly:
Code:
updateStatus:110, ApiRequest (net.sourceforge.kolmafia.request)
processResponse:2716, GenericRequest (net.sourceforge.kolmafia.request)
retrieveServerReply:2566, GenericRequest (net.sourceforge.kolmafia.request)
retrieveServerReply:2114, GenericRequest (net.sourceforge.kolmafia.request)
externalExecute:1672, GenericRequest (net.sourceforge.kolmafia.request)
execute:1655, GenericRequest (net.sourceforge.kolmafia.request)
run:1365, GenericRequest (net.sourceforge.kolmafia.request)
postRequest:300, RequestThread (net.sourceforge.kolmafia)
postRequest:250, RequestThread (net.sourceforge.kolmafia)
visit_url:2992, RuntimeLibrary (net.sourceforge.kolmafia.textui)
visit_url:2944, RuntimeLibrary (net.sourceforge.kolmafia.textui)
Here, KoLmafia checks if it should use the charpane instead:
Java:
// api.php doesn't work at all in Valhalla
if ( CharPaneRequest.inValhalla() )
{
ApiRequest.updateStatusFromCharpane();
return "afterlife.php";
}
However, since
the inValhalla
flag has not been set yet, this statement is skipped.
In reality, we have already entered valhalla, and KoL has redirected the
api.php to
afterlife.php?realworld=1, making our ApiRequest useless.
It seems that we have a Catch-22 here.
- KoLmafia can update the
inValhalla
flag only by updating the player status from charpane.php
- However, since the
inValhalla
flag has not been updated yet, KoLmafia does not know that it should look at charpane.php
instead of api.php
This prevents KoLmafia from updating the character status when auto-ascending. It also prevents forcefully updating the character status via the
update status
gCLI command.
One possible solution would be to check if KoL redirects an
api.php
request to
afterlife.php?realworld=1
, and handle it appropriately:
Diff:
diff --git a/src/net/sourceforge/kolmafia/request/ApiRequest.java b/src/net/sourceforge/kolmafia/request/ApiRequest.java
--- a/src/net/sourceforge/kolmafia/request/ApiRequest.java (revision 20645)
+++ b/src/net/sourceforge/kolmafia/request/ApiRequest.java (date 1613790013689)
@@ -126,6 +126,13 @@
}
ApiRequest.INSTANCE.silent = silent;
ApiRequest.INSTANCE.run();
+ // Fall back to parsing charpane.php if KoL redirects us to afterlife.php.
+ // This may happen if the user entered the gash by calling visit_url(), which does not update the
+ // inValhalla flag.
+ if ( ApiRequest.INSTANCE.redirectLocation.contains( "afterlife.php?realworld=1" ) )
+ {
+ return ApiRequest.updateStatusFromCharpane();
+ }
return ApiRequest.INSTANCE.redirectLocation;
}
(patch file attached below)