Feature - Implemented Master Relay Override

Weird. I made "main.html" as a ASH script, printing just one line of output and it doesn't seem to be being called. There were no errors.
 
The only thing I can see that they all have in common is being inside mainpane. The only other method I can think of to produce this effect would be to produce a list of php pages that the generic script would override.

Even then, how many override scripts would be desired to override adventure.php as well as, let's say, the arcade?

EDIT: Just occurred to me... what if it were possible to extract which page you were on. Could a generic override allow for the script writer to specify in ASH which pages were overwritten with the script being applied universally? Poor code would end up producing weird results, but it would mean that a script writer might only need to update a single source.


Code:
void main() {
switch (name_of_page) {
case "adventure.php" :
//do stuff for adventure.php
break;

case "arcade.php" :
//and so forth
break;
}
}

This is how I was going to use it, but with about 30 switches :D
 
That was my thinking. I'm still digging about, but I don't think the fix is simple. I'll do some more digging, but I have never looked at the relay code before, so I'm doing this from scratch.
 
Chould be. I would imagine this would come with a function name_of_the_page() (or something less stupidly named) that would return "adventure.php" or something.
 
From looking at the way the main thing gets called, it only gets called if there isn't already a specific override in place, as it only happens if relay overrides are allowed and the filename lookup fails.

Where I might be confused though, it that it's possible that it only gets called if there isn't a specific website being called... if so, then if you're hitting http://127.0.0.1:60080/, it gets called... if you're hitting http://127.0.0.1:60080/skills.php it gets skipped, because there's a specific site. Don't really know how to test besides patching those parts of the code and seeing what happens... but that's likely where I'd go to try to make a master override...

And now I look, and that part only ever gets called if it's a non-ash override... and if so, remove any server-side data from the relay. Visible because sendLocalFile is at the end of handleSimple, which gets called if the path doesn't end in php... so no normal websites, just local stuff. Sort of useless. More useful would probably be hijacking KoLmafiaASH.getClientHTML...

Edit: In here, looks like they already have your function.
Code:
String script = request.getBasePath();
From the looks of things, your relay overrides can end with .ash or .php, with ash being used first and php being acceptable as a second-best. If you wan to try forcing an override, put:
Code:
script = "testoverride.ash";
just above
Code:
  File toExecute = new File( KoLConstants.RELAY_LOCATION, script );
near the top of the file. It'll override all your current ones, but if it works as you expect, next step would be working through how to merge the requests together. :)
 
Last edited:
Interesting thing I just ran into reading up on the relay page override method...
http://jeremymanson.blogspot.com/2008/08/dont-use-stringbuffer.html

Basically, he suggests avoiding using StringBuffer completely and using StringBuilder instead, because StringBuffer is "pretend thread-safe" instead of actually thread safe...? If we did actually care, StringBuilder( is called in 110 files, 231 times. -_- No clue how much of the code could just convert StringBuffer to StringBuilder and run fine.

Anyways, not sure exactly, but I'm still staring at this in terms of actually allowing a master relay file in...

Currently thinking of either forcing the name, or setting the name as a variable that the user can set (probably GUI-less, like the between-battle, counter-checker, potion-buy, etc) eventually. master_relay.ash/php sound good for testing purposes?
 
Last edited:
Re jason: Makes sense. Eventual possible goal, but a solid reason to avoid it like a plague.

Re bumcheek: Eventually yes? I just want to see it work and with a semi-stamp of approval on it before I want to start whacking testers with new, potentially useless variables. :)

So, I think my biggest problem now is in testing... I'm fairly certain that at least some of my attempts have done... something. :) The question is, how do I actually see that both the new relay and currents are going? Considering just trying to do a name substitution script, turn my name to tester and see if the charsheet displays both tester and the daily deeds. Would I do that with something like this?
Code:
void main (){
buffer results;
results.append(visit_url());
results.replace_string(my_name(), "Tester");
results.write();
}

Okay... tested and that works. Saved as master_relay.ash temporarily on my system, when I actually get to a less laggy computer, I'll try more things to get it to work. Tested it and I can make a master relay override anything else, or potentially make a master relay override if there's no specific relay... making it go so that the master relay mutilates the page first, then hands the page over to specific other relay overrides? More difficult.
 
Last edited:
making it go so that the master relay mutilates the page first, then hands the page over to specific other relay overrides?
It CAN'T work that way. A specific relay override is under no obligation to actually load the requested page; it could modify the URL, load several pages and merge them somehow, or load nothing and generate the page entirely from scratch. The master override would either have to trigger on each page loaded by the specific override (which would prevent the master override from working on synthetic pages), or modify the text produced by the specific override (in which case problems arise in telling the master override just what page it's overriding).
 
Which was my initial reaction regarding multiple relays interacting... seemed to open up a whole can of worms.

Anyways, about the only way it seems to make it work would be to actually make it a master override... if it's on, it's loaded on every page, and if you want it to interact with current relay override scripts, you have to write that into the master... Use the master to import in the relays for whichever parts they need. Will require rewriting a lot of old relay scripts that just do void main() to actually have called functions so you can call them...
 
This is a bit of a crazy concept, but what if the main function were special, like, say, a buffer main(buffer html), where it modifies the HTML, then passes that for the relay override when visit_url() is called (i.e. it hijacks the result of visit_url())? I haven't done too much thinking, and it's a bit late here, but it sounds like it could almost work. As always, it'd be up to the script writer to avoid conflicts with other scripts.

It's also radically different from previous incarnations of relay override scripts, but it might be better than upsetting all current scripts.
 
Last edited:
It sounds like it would be a lot simpler to have a master override be just that, and not permit overrides for individual pages.
 
Ha... hoped this would work yesterday just before I stopped coding and went to sleep, tested today and it did actually function as advertised. Awesome. So, the patch attached to this adds a new command, get_page(). When it's called, it simply returns the page name (charsheet.php, for example) of the page on the server that's requesting the transaction. Not hugely useful in and of itself... chance of not knowing what page your on normally is unlikely, and in any 'normal' relay override, you'd know what its own file name is, or it wouldn't be running... BUT, this means that you can call get_page() in a master script, and have that then used to check their relay folder for a specific override. As well, you can use it to see what other functions you want to run...

Edit:
Better version of get_page() is included around post 50.
 
Last edited:
Yes/no. What I'll write up as a patch next, once someone gives me a preference name for use with set, is an override to KoLmafiaASH's page lookup functionality. If the preference is set, use that one relay script instead of trying to load up specific overrides. After we have our one relay location set, I'll try to come up with a 'master_relay.ash' file that will replicate standard functionality... use get_page() to find the page requesting the override, and return the override if it exists. Then, after that exists, master override writers can figure out how they want to piece things together. :) Sounds good?

Anyways, what I need to continue is a good preference name. relayMaster or masterRelay or overrideMaster or ...?
 
Sounds good to me... I'll try to whip up a masterRelayOverride version in a few hours. Updating 10 months of unpaid mileage right now, so it might be a bit before I get there, but... :D
 
Okay, here we go... masterRelayOverride away! This patch will read if you have a preference named "masterRelayOverride" and if the length is 0, use the existing relay scripts. If there's actually a file named, the system should try to use it.

Using this WILL stop the system from using any current overrides, because it's calling your one 'master' override for everything. Making this work took adding the ability to read preferences to KoLmafiaASH and then having it default to the masterRelayOverride as the script name with a 0 length. I did apply this to both locations with script = getBasePath, both in getClientHTML and getScriptHTML.

Sample... before:
Theraze (#2087365)
Level 8
Button Box Burglar
after:
Tester (#2087365)
Level 8
Button Box Burglar
 

Attachments

Back
Top