Bug - Fixed Mafia being left open through dayroll without clicking anything until dayroll over

taltamir

Member
I did not notice dayroll occuring while i was writing code on my script.
30 minutes after dayroll I finished writing and ran my new script to test it.

Running the script caused a quick login, where mafia skips doing any of the login stuff:
* dayroll resetting _ settings
* checking SVN
* breakfast

Then I noticed it was past dayroll I restarted mafia, at which point it reset all the _ settings and did the other things above.
but my state became incorrect due to changes that occurred after dayroll but that mafia attributed to happening yesterday.

Also, when trying to quite mafia (manually or automatically) it should not run the on exit script if you left mafia open through dayroll
 
Last edited:

Veracity

Developer
Staff member
Timing-in is intentionally intended to be leaner than logging in or doing a full session refresh.
I agree that daily settings need to be reset.
I disagree that breakfast or svn should be run.

By "on exit", I assume you mean "On Logout"? Why in the world would you have a script that is intended to run every time you logout (potentially many times a day) that you don't want to run when you log out in this circumstance? How is this situation different than you logging in the for the first time in a new day and then immediately logging out without doing anything?

I have a patch which will reset settings if we detect rollover has happened, in the same way that logging in detects that.
I will test it at rollover tonight.
 

Veracity

Developer
Staff member
Huh. That didn't work.

Code:
Updating inventory...
Installing default certificate validation...
Sending login request...
*** slot acc1: KoL has (none) but KoLmafia has Draftsman's driving gloves
Synchronizing moon data...
Requests complete.

[color=green]> prefref _drip[/color]

Name               Value   Default  Scope
_drippyCaviarUsed  false   false    user
_drippyNuggetUsed  true    false    user
_drippyPlumUsed    false   false    user
_drippyWineUsed    true    false    user

[color=green]> get lastCounterDay[/color]

1591241397

[color=green]> get lastGlobalCounterDay[/color]

1591241402

[color=green]> ash rollover()[/color]

Returned: 1591327803

[color=green]> ash ( rollover() - get_property( "lastCounterDay" ).to_int() )[/color]

Returned: 86406
I'll have to think about this some more.

And I also think that if we have a new day, we have to reset the Cafe specials and maybe other things.
 

taltamir

Member
By "on exit", I assume you mean "On Logout"? Why in the world would you have a script that is intended to run every time you logout (potentially many times a day) that you don't want to run when you log out in this circumstance? How is this situation different than you logging in the for the first time in a new day and then immediately logging out without doing anything?
At the moment if you are doing stuff until dayroll hits, mafia detects dayroll is ongoing and will kick you back to login screen, but when doing so it will try to run your logout script which itself throws errors about currently being during dayroll.

I was assuming that this would be resolved by automatically kicking you back out to the login window if dayroll already passed you so that you can log back in formally and it can do all the needed dayroll things.
but in that case when it runs the logout script it will actually successfully run instead of erroring that we are during dayroll.
But be successfully run with yesterdays tracker and cause tracking errors
 
Last edited:

zarqon

Well-known member
I'd be happy with mafia performing no actions and simply kicking us back to the login window if it detected that rollover had passed. Would save me the trouble of closing the window and then restarting (which I do presently rather than simply "exit"ing, due to not wanting my logout script to run and inevitably have errors, as taltamir mentioned).
 

Veracity

Developer
Staff member
At the moment if you are doing stuff until dayroll hits, mafia detects dayroll is ongoing and will kick you back to login screen, but when doing so it will try to run your logout script which itself throws errors about currently being during dayroll.
So, if you are doing stuff and rollover hits, when you issue a request, KoL redirects to maint.php. That is the definition of what describe as "being during dayroll". (A word I had never heard, before you used it in this thread.)
.
You say that KoLmafia then runs the logout script? That is a KoLmafia bug; if KoLmafia detects that rollover is in progress, it should give you the login window and not run the logout script.

Which has literally nothing to do with the issue you initially reported, where you said that 30 minutes after rollover, you tried to issue a request and KoLmafia timed you in, as it does any time a request redirects to login.php - not maint.php. Therefore, you are not "during dayroll". You are "after dayroll". And the ONLY way we can distinguish that case, as opposed to any other timein, is to log you in, call api.php, and notice that the next rollover time is a day later than it was last time we looked it it.

I was assuming that this would be resolved by automatically kicking you back out to the login window if "dayroll already passed" you so that you can log back in formally and it can do all the needed "dayroll" things.
Which is to say, you are assuming that KoLmafia will log you in and detect it is the next day (i.e. "dayroll has already passed") and then, somehow, log you out and send you to the login window, so that you can then log in again.

I think that if a request redirects to maint.php, we should send you to the login window without running the logout script.
I think that if a request redirects you to login.php, we should time you in, and if we detect that "dayroll has passed", reset all the counters and such as if you had logged in to a new day, and then let you carry on from there.

I'd be happy with mafia performing no actions and simply kicking us back to the login window if it detected that rollover had passed. Would save me the trouble of closing the window and then restarting (which I do presently rather than simply "exit"ing, due to not wanting my logout script to run and inevitably have errors, as taltamir mentioned).
In other words, you want it to time you in and then immediately log you out (sans logout script) and kick you back to the login window if it detects a new day has passed.

I still have not heard about exactly what errors you get in a logout script which are not due to the properties not resetting correctly. If I time you in and reset properties for a new day - if you are on a new day - what is your logout script expecting that would make that work differently than logging you in via the login window (rather than timein) ad resetting properties?

Is the issue, literally, only that the logout script depends on the current values of properties being correct - rather than yesterday's values? Which is, specifically, the issue that my approach is attempting to solve with a single login, rather than forcing a login/logout/login, which both of you seem to want?
 

taltamir

Member
Which has literally nothing to do with the issue you initially reported
Yes, it is a separate issue entirely.

I only brought it that separate issue because it is potentially become relevant if the first issue is fixed a certain specific way.
Which happened to be the way I initially assumed it would get fixed
Which is to say, you are assuming that KoLmafia will log you in and detect it is the next day (i.e. "dayroll has already passed") and then, somehow, log you out and send you to the login window, so that you can then log in again.
Does it actually need to login to detect a day passed? couldn't you do
Code:
boolean timing_in()
{
if(dayroll_passed())
  quit_to_login_window();
else
  current_timing_in_code();
}
replacing the current timing_in() function that performs that quick login with the above one?
 
Last edited:

Veracity

Developer
Staff member
Does it actually need to login to detect a day passed?
Yes.

Whenever we call api.php?which=status, it tells us what time rollover is. We save that in what rollover() returns. If that has changed by at least an hour since the last time we saved it, a day has passed.

You have to be logged in to do api.php?what=status.

couldn't it check to see if a day passed without logging in, and if it has then switch to the login window?
I know of no way to do that.
 

taltamir

Member
Yes.

Whenever we call api.php?which=status, it tells us what time rollover is. We save that in what rollover() returns. If that has changed by at least an hour since the last time we saved it, a day has passed.

You have to be logged in to do api.php?what=status.


I know of no way to do that.
Thank you for explaining. I assumed it was being done via a date and time check (adjusted to your timezone).

As for what my logout script does.
it uses up my remaining fortune teller asks, puts my pvp stealable expensive items in my closet, and runs breakfast. Which does a bunch of daily actions which could be a problem if you just broke prism to liberate the king (thus making a bunch of iotms with daily limits that were unavailable become available).

I honestly thought I had more things there but in retrospect I put most of them in my login script.
I am going to add taking and then abandoning a platinum guzzlr delivery if in run into the logout script though. rather than the login one.
 

taltamir

Member
That all being said.

Why would it be so bad to have timein login, detect missed a rollover, then immediately halt all scripts and logout without doing anything else?

It still sounds like the best way to handle this.
so when you do log in again manually it will do the full shebang of resetting _ valueus. updating svns, doing breakfast, and running your login script.

Also an idea i had... could a threaded timer be set when you first login that is equal to the remaining time until dayroll and counts down towards dayroll? even if you are timed out the timer will continue counting down, and when it reaches zero it sends back to mafia's main window to shut down? that way the entire possibility of timing in after dayroll could be made impossible.
 

Veracity

Developer
Staff member
Thank you for explaining. I assumed it was being done via a date and time check (adjusted to your timezone).
Depending on your system clock to have a value which (even adjusting for timezone) is comparable to times that are used by the KoL servers themselves is a huge squirming bag of worms.
If you are using some sort of network time protocol to set your system clock at boot (or periodically, or whatever) and your hardware clock is accurate enough to keep you closely in-synch between updates and (any number of other assumptions) ...

The method I mentioned uses nothing but time values that KoL itself sends us and requires nothing of the accuracy of your local time. KoL itself tells us when rollover has passed and a new day has begun.

I just stayed logged in for (more than) thirty minutes after rollover had presumably finished. I clicked the "refresh" button on the inventory page, which does api.php?which=inventory.

Code:
Updating inventory...
Installing default certificate validation...
Sending login request...
*** slot acc1: KoL has (none) but KoLmafia has Draftsman's driving gloves
Loading character status...
Synchronizing moon data...
2 days until Festival of Jarlsberg, Moxie bonus tomorrow (not today)
It submitted that api.php request, got redirected to login.php, did the timin, detected that rollover had happened, reset counters and did a few more requests, and then resubmitted the inventory refresh.

Which is what I expected.

I'll sleep on it and look more tomorrow and see what it would take to make it like the first full login of the day. EVen without counting breakfast (which I do not run automatically) and SVN update (ditto), it needs to look at garden progress, and who knows how much else.
 

Veracity

Developer
Staff member
As for what my logout script does.
it uses up my remaining fortune teller asks, puts my pvp stealable expensive items in my closet, and runs breakfast. Which does a bunch of daily actions which could be a problem if you just broke prism to liberate the king (thus making a bunch of iotms with daily limits that were unavailable become available).
So, near as I can tell, your logout script is coded with the assumption that you will only ever log out once a day.
Huh.

Well, since I may log in, do stuff, log out, log in later, do more stuff, log out, log in yet again, finish doing stuff, log out, I wouldn't do that.
In fact, I can't think of anything I would want to be doing every single time I log out.
But, we do give you the opportunity to write such a script.
I think it's up to you to make it work correctly every time, whether or not you have used it earlier today and whether or not you might log in and out later and it will run again.
I don't think it is up to KoLmafia to decide the "one true way" a logout script is intended to work and make that way - and only that way - work correctly, possibly at the expense of other ways to write such a script.

What does zarqon's logout script do?
 

zarqon

Well-known member
My logout script basically attempts to use all the multifarious daily-limited resources I have remaining, under the same assumption that I am done playing for the day. It does things like use up remaining free craftings and minings, record songs, burn MP until daily-limited MP restoratives are used up (like nuns, free rests, and magical sausages), faxputty a desirable monster, improve spirits, get any un-got daily buffs, comb the remaining free beach, Solve the Detective, and use remaining daily zaps. There's more, but you get the picture. It attempts to pretty comprehensively wrap up my day by using any daily thing I didn't use already in that day's adventuring. You can probably see where I would only want that to run when I actually finish playing a character for the day.

A logout script seemed the most sensible place to put all this stuff since that will guarantee I "remember" to use everything.

I could extend the nightcap check to apply to the whole script -- so the script would do nothing unless I had spent enough turns and filled enough stomach and liver -- but I have had no need to thus far. If I leave a KoLmafia instance open and rollover happens (quite common for me), when I come back to my computer I close KoLmafia rapidly before it has a chance to execute my logout script (two ALT+F4s in quick succession on my Windows machine), then restart it. This is old, learned behavior; I have an ancient memory of my logout script firing up in these cases and doing stuff I didn't want to do yet, which I also couldn't see clearly because I was looking at the login window rather than the CLI. I guess that's what I meant by "errors". I can't recall if there were script-generated errors in addition to unwanted behavior, so my word choice was perhaps the real error here.

If I'm understanding correctly, the present behavior is:

  • When rollover is detected as ongoing, abort any actions and print a red message to the CLI.
  • When rollover is detected as having happened in the past, partially update mafia's information.
This latter bit leaves mafia in a state of dubious usefulness. To avoid said dubious state, it seems best to either 1) exit to the login screen (without calling a logout script; at this point you are in a situation practically identical to not having logged in at all) or b) re-login (as though we had just logged in from the login window). It looks like perhaps choice b) is better now since the login-out-in thing is awkward.

Might also be worth considering having mafia kick you back to the login screen if it detects rollover is ongoing. Would prevent you from ever being in this "login limbo".

I seem to have accidentally registered a horse in this race. I am fine with the way things are, honestly, but I do think eliminating that half-useful state would be an improvement. :)
 

Veracity

Developer
Staff member
Well, I have a commit ready which does this:

- When we redirect to maint.php (i.e. you submit a request during rollover) we continue to clear the session variables - session ID, password hash, etc. - since you are logged out. We don't kick you back to the login frame. You might not even be running with a GUI. But if you exit the program (closing windows, exit command, etc.) we will notice that there is no session ID and will not call your logout script.

That should solve the "errors from your logout script" issue. I assume those were all a result of every attempted request being redirected to maint.php.

- When we timein, it submits login.php (which is what it was redirected to when you tried to submit a request). The first thing it does after that is to get api.php and see if rollover has happened.

If not, it saves and reloads preferences, closes and reopens the session log (because it used to do those things. These may be unnecessary), and then learns the new password hash (since it changes every login) and visits main.php (since some things don't reset correctly in KoL if you don't do that.) And that's it. Everything else is assumed to be in the same state as when you left it. properties will not have changed. Inventory will not have changed. (Modulo PVP and kmail - but that's always the case; those can happen at any time even while you are activly doing other things.)

I tested this case. Timein worked just as before with a couple fewer server calls.

- If api.php says we have timed in on the other side of a rollover, it treats this login just like it was the first login of the day from the Login Frame: It reloads every, resets properties, refreshes session log, runs breakfast (if configured) checks SVN (if configured) and so on. I think that is what you people want - and it seems right; the purpose of timein is to allow you to continue today's session, having walked away from your computer for 15 minutes, say, just as if there had been no interruption. But as a new day, this timein is really starting a new session.

I will test this tonight after rollover. I will be checking that it correctly opens a new session log...
 

Veracity

Developer
Staff member
OK, that worked

Code:
[color=green]> debug on[/color]

[color=green]> vsg status[/color]

Installing default certificate validation...
Sending login request...
Loading character status...
*** slot acc1: KoL has (none) but KoLmafia has Draftsman's driving gloves
Initializing session for Veracity...
Loading character status...
Refreshing session data...
Synchronizing moon data...
Loading character status...
Retrieving character data...
Updating inventory...
Examining Meat in closet...
Updating closet...
Retrieving quest data...
Retrieving familiar data...
Familiar data retrieved.
Retrieving campground data...
Examining Meat and pulls in storage...
Updating storage...
Visiting The Horsery
You are currently a member of Hardcore Oxygenation
Visiting Crimbo Tree in clan VIP lounge
Visiting Hot Dog Stand in clan VIP lounge
Visiting Speakeasy in clan VIP lounge
Visiting Floundry in clan VIP lounge
Session data refreshed.
Festival of Jarlsberg tomorrow, Moxie bonus today and tomorrow.
Already updated from https://kolmafia.us/scripts/updateprices.php?action=getmap in this session.
06/05/20 05:06 PM - Now pledging your allegiance to Bonus Adventures from Hell.
06/05/20 05:07 PM - Now pledging your allegiance to Hardcore Oxygenation.
06/05/20 05:07 PM - New message received from CheeseFax
06/05/20 05:07 PM - New message received from CheeseFax
06/05/20 05:07 PM - New message received from CheeseFax
06/06/20 12:00:45 AM - New message received from Your Pen Pal.

Visiting the Spacegate Terminal
You haven't activated the Spacegate today

[color=green]> debug off[/color]
It timed me in at midnight - at least 20 minutes after rollover had completed - and recognized it was a new day, so it turned it into a regular login.

Try revision 20149.
 

zarqon

Well-known member
That sounds perfect. Thanks for yet another thoughtful and forward-thinking solution. I hadn't considered the non-GUI people.

Visiting main.php on timein might have solved another issue I was getting ready to report, too. Sometimes I'd run a script after my session had expired and that script would auto-adventure as its first server-hitting act, which would result in an infinite loop of "Unhandled redirect to main.php". If I encounter that again I'll make a bug report, but I'm hoping this fixes it.
 

Veracity

Developer
Staff member
By the way - I was curious about what you did in your logout script, because I've considered, for example, doing this:

login script - save a timestamp in a property
logout script - read time stamp, get a new one, calculate difference, and increment another property.

Net result would be a property tracking how much time I was spending logged in via KoLmafia.

Notice that no requests are involved. Just properties.

With the new "if you are kicked out by rollover, and then exit KoLmafia, no logout script is run", such a scheme would not work.

Perhaps I need a "kicked out by rollover script". :)

That would be super niche.

But, obviously, my idea of what a "login script" or a "logout script" is good for differs from yours. There is no "one true way".
 

taltamir

Member
I forgot to report that testing shows it works fine now.

Also in regards to your suggestion. My logout script assumes I am completely done for that day. while my login script checks the current state (so with the new rollover handling will work just fine for what i want to do on a new day).
So I personally do not have a need for a kicked by rollover script slot.

What is your logout script doing that would necessitate it?
 

Veracity

Developer
Staff member
I don't have a logout script.

Read the post just before yours which talks about a proposed login/logout script which would, using properties, accumulate the total time you have spent logged in to KoL via KoLmafia.
 
Top