master relays

Before I go making a request, I just want to understand what the order of operations on relays is.
As I understand it (and I don't know that I do) if a master is set, then the master gets run for all requests from the browser that ask for a KoL page, and that's it.

When a master is set, a specific page script is ignored.

I'm having trouble understanding why it's like this. It seems to me like it would be more useful to have the master only run if there isn't already a script defined on a given page. Seems to me that if you *don't* want a script to run, then... well, you'd get rid of it.

Is there a reason it doesn't work like this, or should I go ahead and make the request?

As I see it, there is something that appears on KoL pages that I'd like to modify. It's a very small change, and it happens on a lot of pages. But there are also a bunch of other pages that I already have overrides for, that aren't necessarily developed or maintained by myself, so having to force them all into one script would require manually putting in every update.
 

Theraze

Active member
Well, if nothing else, you could (in master relay) check for specific pages you want normal overrides on and encapsulate a try/finally that saves the master relay value to a string, disables the master relay, displays the page normally (which should use the normal, non-master relay, right?) and then in the finally re-enables the master relay. It's a lot of on/off setting into the gCLI, but it means you get your chosen relays without needing to change anything else.

The reason master relays work the way they do is because it was originally designed for the BumRats master relay which went all over the place, so that people wouldn't get quite as confused as to what to do with all the different relay files, which they kept having issues with. :) Well, that, and when we asked if people wanted both master relay and other, nobody spoke up for it...
 

Veracity

Developer
Staff member
Because that is what bumcheekcity wanted when he requested that Master Relay Override scripts be implemented.

How about if you and he discuss it? Make a Feature Request that satisfies both of you, after you've done that, if it turns out that you and he agree that something needs to be changed,
 

Bale

Minion
I might actually use bumcheekcity's master relay override if my own relay scripts for certain pages would not be overridden by his omnibus script.
 
Well, if nothing else, you could (in master relay) check for specific pages you want normal overrides on and encapsulate a try/finally that saves the master relay value to a string, disables the master relay, displays the page normally (which should use the normal, non-master relay, right?) and then in the finally re-enables the master relay. It's a lot of on/off setting into the gCLI, but it means you get your chosen relays without needing to change anything else.

I'd be down for this, but... I'm not sure how to implement it. How do I check to see which pages have their own overrides at any given time? There's no ASH for looking in the file system (at least, not that I know about...). Also, while I understand the disabling/re-enabling thing, I don't think mafia runs relay scripts on URLs requested from within a script.

And as for what Veracity said, that is why I posted this here: to see if people would be okay with this sort of change. If it's really just concerning his script then, then I'll go find him and talk.
 

xKiv

Active member
Enabling both master and singular relay script for a page could get tricky. For example, iirc, visit_url() will return current page's HTML (decorated by mafia) in the master relay override ... what should it return in the other script? How do you help the other script handle changes made by the master script (alternatively, if you have both work on the same source HTML, how do you merge the changes they both made)? Or do you just invent an API for either of the scripts to indicate "I [really] do/don't want to override this page, [but only] if some other script wants it"?
 

Theraze

Active member
If both functioned, it would probably be:
a) Is there a specific relay for that page? If so, use it.
b) Is there a master relay currently active? If so, use it.
c) Show page.

Currently it's the same thing but with a and b reversed...
 

Bale

Minion
Really? Are you sure? I was under the impression that if a master relay is active, then it will not ever use specific relay scripts for any pages.
 

Theraze

Active member
Exactly... Think about the logic I've presented. :)

I didn't explicitly state it, but once you hit a match, stop there.
 

Bale

Minion
Ah. I thought you were expressing a belief that both a master relay and a secondary override could both modify the same page. You should have explicitly stated it, but I am happy to learn that our understanding is the same.
 

Theraze

Active member
That's the problem with those implicit IF statements... you never know quite where it's going to end. Anyways...[/threadjack]
 

Bale

Minion
A small programmer joke:
Wife: Honey, please go to the market and buy 1 bottle of milk. If they have eggs, bring 6.
The man came back with 6 bottles of milk.
Wife: Why did you buy 6 bottles of milk.
Man: Because they had eggs...

LoL! Yeah, I love that joke also. It is a very similar problem.
 
Enabling both master and singular relay script for a page could get tricky. For example, iirc, visit_url() will return current page's HTML (decorated by mafia) in the master relay override ... what should it return in the other script? How do you help the other script handle changes made by the master script (alternatively, if you have both work on the same source HTML, how do you merge the changes they both made)? Or do you just invent an API for either of the scripts to indicate "I [really] do/don't want to override this page, [but only] if some other script wants it"?

This wouldn't even be an option. Essentially what Theraze pointed out would be what I'm looking for. If there is a master, use it for all pages. If there is a specific page override, use it instead of the master.

Anyway, since I saw mention of, but no solution, in the original Master Relay thread, how does one get the name of the triggering URL from within the script?
 

Theraze

Active member
I believe that whole change involves taking the two spots in KoLmafiaASH and changing
Code:
			String script = Preferences.getString( "masterRelayOverride" );
			if ( script.length() == 0 || relayRequest.getPath().startsWith( "relay_" ) )
			{
				script = relayRequest.getBasePath();
			}
to
Code:
			String script = relayRequest.getBasePath();
and then changing
Code:
		File toExecute = new File( KoLConstants.RELAY_LOCATION, script );
		KoLmafiaASH.relayScriptMap.put( script, toExecute );
		return toExecute.exists() && KoLmafiaASH.getClientHTML( request, toExecute );
to
Code:
		File toExecute = new File( KoLConstants.RELAY_LOCATION, script );
		if (!toExecute.exists() && Preferences.getString( "masterRelayOverride" ).length() > 0 )
		{
			script = Preferences.getString( "masterRelayOverride" );
			toExecute = new File( KoLConstants.RELAY_LOCATION, script );
		}
		KoLmafiaASH.relayScriptMap.put( script, toExecute );
		return toExecute.exists() && KoLmafiaASH.getClientHTML( request, toExecute );
That should work, but... eh, I personally don't use a ton of relays even though they're nifty. :) Consider it untested but likely good. I can whip up a patch for people to use if they want to play with it pre-official FReq.
 

bumcheekcity

Active member
Would it be the worst idea in the world to have this as a per-user setting?

- If I have a masterOverride set, never use individual overrides.
- If I have a masterOverride set, don't use it when I have an individual override.
- If I have a masterOverride set, use both overrides if applicable.

Of course, I don't know how hard that would be to code, but it could be a good compromise.
 

Theraze

Active member
I'd consider reversing it, but wouldn't want to have another preference for it, especially because of code scattering.
 
Top