Feature - Implemented Master Relay Override

Grotfang

Developer
This looks fantastic, Theraze! Nice work :)

Am I right in thinking, then, that scripts can be combined into a single relay? For example, I have attached the style I envisage, which is a combination of shore.ash (Bale), topmenu.ash (Zarqon) and woods.ash (also Bale). Is this the sort of format that can be used now?
 

Attachments

  • master_relay.ash
    2.3 KB · Views: 22

Theraze

Active member
Similar, but not quite... I think that functions still need to be top-level... in the case of those, you should be able to just import their handler files though, I think? To use the file you provided though, it would need to be like... hmm... this. Basically, I put the functions outside the switch, and that made it actually work properly. Next step... playing with import.
 

Attachments

  • grotfang_relay.ash
    2.2 KB · Views: 20
Last edited:

Theraze

Active member
Okay, making this a new post so it's easier to see the difference in the files. Including both a grotfang_relay.ash and a shore.ash in this. I've modified shore.ash to have the 3 functions used in grotfang_relay be externally to main, so they can be called by other scripts, and then putting "buffer results;" into each of the functions so that it can actually modify results. I can't actually test if this script runs properly right now, because poor Theraze hasn't unlocked the desert yet, but it's likely to happen within a day or two. ;)

What I'd really love to do is figure out a good way to combine import and get_page() so that it will import the script file automatically if it's there. Wouldn't necessarily run automatically, since most go through their 'main', but it should be easy to turn most into functions and call them if you want to keep your master file fairly clean...
 

Attachments

  • grotfang_relay.ash
    1.6 KB · Views: 20
  • shore.ash
    1.4 KB · Views: 15
Last edited:

lostcalpolydude

Developer
Staff member
Wouldn't necessarily run automatically, since most go through their 'main', but it should be easy to turn most into functions and call them if you want to keep your master file fairly clean...

It was trying to do this that originally caused shore.ash to call visit_url twice and take two shore trips whenever the form was submitted. I was probably just being stupid about how I wrote the script or something, though.
 

Theraze

Active member
Well, all I did to make them into functions was defined buffer results, I didn't put another visit_url in there... that was likely why it ran twice before. :) Though as I said, I can't actually check. Heh.

Trying to see if there's some way to actually import based on file name... I'm trying to do something like this:
Code:
        String script = get_page();
        script = script.substring( 0, script.length() - 4 ) + ".ash";
        import script;
 
Last edited:

Grotfang

Developer
It could well have been an issue with my default action in the switch, but with the script posted above and the default settings as I posted, the mall was pretty borked. Mafia was substituting +s for spaces. I assume the issue is me, but I do want to check it's not something going odd with the fact that the mall phps are being passed to the script?
 

Theraze

Active member
Could be because your default action wasn't to do no action, but to write it to a buffer? I'd suggest having your default case just break without anything changing...
 

Theraze

Active member
So, is there any good way to pull a RelayRequest or other such information on which page is getting loaded into this?

I'm seeing the importFile function in textui/Parser as the actual import system being used to bring in other files for ash... Unlike textui/RuntimeLibrary though, spawning a RelayRequest doesn't give us the page, it just gives an error per page loaded, specifically:
Unexpected error, debug log printed.
Unexpected error, debug log printed.
Unexpected error, debug log printed.
Unexpected error, debug log printed.
Unexpected error, debug log printed.
The specific debug log is:
Timestamp: Fri Sep 03 19:42:27 PDT 2010
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Unexpected error, debug log printed.
class java.lang.NullPointerException: null
java.lang.NullPointerException
at net.sourceforge.kolmafia.request.GenericRequest.getBasePath(GenericRequest.java:788)
at net.sourceforge.kolmafia.textui.Parser.importFile(Parser.java:326)
at net.sourceforge.kolmafia.textui.Parser.parseScope(Parser.java:387)
at net.sourceforge.kolmafia.textui.Parser.parse(Parser.java:184)
at net.sourceforge.kolmafia.textui.Interpreter.validate(Interpreter.java:157)
at net.sourceforge.kolmafia.KoLmafiaASH.getInterpreter(KoLmafiaASH.java:200)
at net.sourceforge.kolmafia.KoLmafiaASH.getClientHTML(KoLmafiaASH.java:99)
at net.sourceforge.kolmafia.KoLmafiaASH.getClientHTML(KoLmafiaASH.java:77)
at net.sourceforge.kolmafia.request.RelayRequest.run(RelayRequest.java:1462)
at net.sourceforge.kolmafia.LocalRelayAgent.readServerResponse(LocalRelayAgent.java:420)
at net.sourceforge.kolmafia.LocalRelayAgent.performRelay(LocalRelayAgent.java:132)
at net.sourceforge.kolmafia.LocalRelayAgent.run(LocalRelayAgent.java:109)
which, to me, suggests that it's trying to read an item that doesn't exist... there's no running RelayRequest, unlike when RuntimeLibrary calls it. So basically, I can't do anything similar during that... If anyone has suggestions on what to try, I'd love them. :)
 

StDoodle

Minion
I realize this is a bit late to the game, as it appears a lot of work has been done to make this happen, but if the original problem was with being able to keep scripts updated, why didn't bmc just import from a master script (the one that would be maintained) in each of the page-specific scripts? Then, you'd be able to release (and others could install) each of the individual page scripts only once, and only need to update the single included script, unless some very drastic changes were made. Am I missing something?
 

Theraze

Active member
Because then you still have to make a new file for each additional bit, and even people trying to keep up to date get their versions confused. Whereas, if you have a single file, it's significantly easier to know whether or not you got a single file on or after a specific date... Makes it a LOT easier for an author to make sure that people aren't using screwed up old versions.

If I can get it to load up the files if there isn't specific handling in the master relay, I'd like it to be possible for people to have their master file load up their standard overrides. That's what my post #48 is about. -_-

Anyways, here's an update to the get_page() command. This one doesn't create an additional relayrequest, it just uses the existing one... It's slightly cleaner code. Removed the earlier version above.

Edit: Okay, get_page has been renamed... it's now get_path(). There's also two more commands tied into this change... get_path_full() and get_path_variables(). All 3 will only return a string if there actually is a relay session running, else they'll return blank strings (so this should make the commands a bit safer). The explanation between the 3 is that path will return just the page, path_full will return the entire string including whatever is after the ? if there is anything, and path_variables will only include what's after the ? and return a blank string if it's run without variables. This should make relay-page-matching significantly easier... making it possible to, for example, detect which page of the inventory you're on currently.
 

Attachments

  • PageDetectionCommand.patch
    1.8 KB · Views: 22
Last edited:

Theraze

Active member
Decided to do a slightly bigger proof of concept... this bcc_relay.ash file will, if made your masterRelayOverride, apply all of the bumcheekcity relay overrides. If you peek at it, you'll notice that he'd already made them all functions (except for inventory) so they translate to a master calling system very easily. Alternatively, the functions could be put into either a single "bcc_functions" file, or included in the master file. The advantage of keeping them outside the actual master file is that this makes it easier for people to splice their own sets of overrides together.

Another benefit of using a master override is that, if I wanted to, I could call many different functions on the same page, as long as they don't have conflicting names or do things that don't work together... In this case, I just took the full bcc set and put it together, but I could put anything else in there I wanted as well.

Also, your overrides don't actually have to follow the location name. If I wanted the bcc relays to be differentiated, I could rename them like bcc_beach, bcc_campground, bcc_town_altar, and it wouldn't affect whether or not they'd work, but if the user already had some custom relay scripts, it wouldn't necessarily disrupt their usage...

Anyways, to make this work, unzip the 0.3 version of BCC relays into the relay folder (backup if you already have others you want), put bcc_relay.ash in there, and set masterRelayOverride=bcc_relay.ash and... done.
 

Attachments

  • bcc_relay.ash
    5.2 KB · Views: 25

bumcheekcity

Active member
Thanks, Theraze.

Any chance of getting this integrated into mafia soon, mafia devs? I don't know if discussion about allowing more people commit privs came to anything, or who can commit, but I'd really like this.
 

fronobulax

Developer
Staff member
Thanks, Theraze.

Any chance of getting this integrated into mafia soon, mafia devs? I don't know if discussion about allowing more people commit privs came to anything, or who can commit, but I'd really like this.

Quite frankly there is so much about this that I do not understand that I personally am reluctant to do a commit by proxy if I am the proxy.
 

Theraze

Active member
Well, speaking as the person doing the work here, at this point I think it could be included without screwing anything up. It doesn't have the ability to automatically import in an existing relay file based on the page name without adding it to the master relay as I'd hoped to do, but it does properly work without screwing up anything up. That's just functionality that I'd like if possible, not functionality that's needed.

Summary of changes:
KoLmafiaASH
- Added persistence/Preferences to the imports so it could actually read them in.
- getClientHTML checks for masterRelayOverride variable, uses getBasePath if variable length is 0.
- getScriptHTML checks for masterRelayOverride variable, uses getBasePath if variable length is 0, fixed a space/tab visible issue.
textui/RuntimeLibrary
- get_path will display getBasePath for a specific relay override. If no relayRequest currently exists, return a STRING_INIT.
- get_path_full will display getPath for a specific relay override. If no relayRequest currently exists, return a STRING_INIT.
- get_path_variables will display the opposite to getBasePath for a specific relay override, displaying getPath without the page or ? displaying variables. If no relayRequest exists or no variables have been passed, return STRING_INIT.

Edit: Added a unified version of the master relay override, with the KoLmafiaASH and RuntimeLibrary both included. Also fixed get_path_variables to return STRING_INIT and fixed a tab spot around logprint.
 

Attachments

  • Unified Master Relay.patch
    3.4 KB · Views: 21
Last edited:

bumcheekcity

Active member
I applied this patch to the latest revision of Mafia, and changed masterRelayOverride = master.ash (where master.ash existed in the /relay/ folder), making sure relay overrides were ticked in the Preferences section, but it didn't seem to work.

Then I created campground.ash and it didn't work with or without masterRelayOverride set. Was I doing something wrong?
 

Theraze

Active member
Hmm... Can't really say regarding your master.ash without seeing it. get_page() did change its name to get_path() as I said when the change happened and in the list of functions with the patch. Are you saying that with this patch applied, none of your relay overrides worked, even with the masterRelayOverride set to nothing, or that other ones were working and just that one failed to run properly?

Was just thinking about the shore.ash page and its 3 functions, and the reason they don't work properly split out is that the functions need to have Buffer results passed to it as a variable from the start, it can't just be defined inside the variable... that should make it actually work properly.
 

bumcheekcity

Active member
My master.ash contained the text:

Code:
print("test");

It was literally just a test of execution. Yes, it seemed to break the master and specific overrides. The campground.ash was the one from bUMRATS. I shall do more testing in the morning - I'm not saying it wasn't user error, just that I'm fairly sure I tried it with all combinations of things I could find and they didn't work.
 

Theraze

Active member
Try using the bcc_relay.ash I have above... If it works, it should look exactly like your normal relay patch pack is active. Drop that in your relay folder and set masterRelayOverride=bcc_relay.ash and you should be set...
 

Theraze

Active member
Hmm... when I run it with your sample bit, I got the following:
> set masterRelayOverride=master.ash

masterRelayOverride => master.ash
test
test
test
test
test
So... exactly as you wanted it to do, it appears. Not sure why the patch isn't working for you... are you using the unified patch from post 54 or earlier patches? If you're using the 54 one, I'll make myself a patch that contains all my differences and look at what's missing...
 
Top