How to script rollover?

Obeliks

Member
I want to write a chat/KMail script that handles some messages all day long, then automatically does some stuff a few minutes before rollover, then patiently waits for rollover to be over, and then does some more stuff and resumes its chat/message handling.

What's the best way to do this?
 

Pazleysox

Member
I would suggest being a little more vague in your request for starters. Second, I would write, or find a chatbot script.
 

fronobulax

Developer
Staff member
Vague or not, this is basically a chatbot.

What I can't answer is
  • How does a script detect that it is currently in rollover?
  • Is there a way, besides polling the above, to determine rollover is done?
There is an ash function rollover() but it is not documented on the wiki.

If there are no easy answers then the script is going to have to do a lot of clock arithmetic.
 

Obeliks

Member
Thanks guys, that already helps! So what happens when I call a regular action (let's say cast a skill) and it turns out it's rollover. Will it abort, or will it hang until rollover is over and then retry? If it aborts, is there some way I can "catch" the abort?

Unfortunately it's a bit hard for me to test those things because I'm usually asleep during rollover.
 

heeheehee

Developer
Staff member
There is an ash function rollover() but it is not documented on the wiki.
Some tracing through the code indicates that this is UNIX time of next rollover, populated as part of ApiRequest (as part of processing api.php).

One approach you could take with a chatbotScript is to look out for the System Announcement indicating X minutes to rollover, then just sleep "an amount of time" until you expect rollover to be done, then cli_execute("login " + my_name());

When I have run such bots in the past, I have personally preferred to set scheduled tasks (cronjobs specifically) that kill any existing Mafia instances at a certain time, then rebuild + relaunch Mafia. This picks up new Mafia changes / script updates. (Script updates are less relevant for a chatbotScript, although I seem to recall some situations with stickiness wherein I needed a tiny script to clear + rebind chatbotScript. I don't remember the exact details, but I think it had to do with trying to load a broken version of the script.)

Thanks guys, that already helps! So what happens when I call a regular action (let's say cast a skill) and it turns out it's rollover. Will it abort, or will it hang until rollover is over and then retry? If it aborts, is there some way I can "catch" the abort?
Typically this will cause an abort.

The wiki has a blurb on catching aborts in ASH. If you're writing this in JS, you... might be able to use try/catch? I don't know, I've not used much JS with Mafia.
 

heeheehee

Developer
Staff member
Regarding kmail processing: you can also trigger that via chat messages. I have an old script lying around with the following snippet:

C-like:
void main(string sender, string message, string channel) {
  if (channel == "Events" && message.index_of("New message received from") > -1) {
    // could do some parsing here

which seems like it may work for your use case.
 

Pazleysox

Member
Thanks guys, that already helps! So what happens when I call a regular action (let's say cast a skill) and it turns out it's rollover. Will it abort, or will it hang until rollover is over and then retry? If it aborts, is there some way I can "catch" the abort?

Unfortunately it's a bit hard for me to test those things because I'm usually asleep during rollover.
If your using Mafia to run your bot, and rollover hits, your bot will be logged off. It will be unable to do anything until it's logged in again. Then if there's any messages in the buffer, it will execute them upon log-in.

When I ran a chatbot, I had a second account setup to log on just before rollover was to hit, and send a command (via PM) to the bot to logoff. The bot would logoff, and log-in again after rollover was done. I used an external program that could be set to execute a (COMMAND.COM) .BAT file at a specific time. This would then close the current window, and open a new one when the bot logged in again. I think the bot is in the forums somewhere if you want a starting point. I didn't release everything I coded into my bot, but I'm willing to help with what little I know if I can.
 
Top